121210Sdist /* 221210Sdist * Copyright (c) 1980 Regents of the University of California. 3*33485Sbostic * All rights reserved. 4*33485Sbostic * 5*33485Sbostic * Redistribution and use in source and binary forms are permitted 6*33485Sbostic * provided that this notice is preserved and that due credit is given 7*33485Sbostic * to the University of California at Berkeley. The name of the University 8*33485Sbostic * may not be used to endorse or promote products derived from this 9*33485Sbostic * software without specific prior written permission. This software 10*33485Sbostic * is provided ``as is'' without express or implied warranty. 1121210Sdist */ 126758Srrh 1321210Sdist #ifndef lint 14*33485Sbostic static char sccsid[] = "@(#)fancy.c 5.3 (Berkeley) 02/16/88"; 15*33485Sbostic #endif /* not lint */ 1621210Sdist 176758Srrh #include "back.h" 186758Srrh 196758Srrh char PC; /* padding character */ 206758Srrh char *BC; /* backspace sequence */ 216758Srrh char *CD; /* clear to end of screen sequence */ 226758Srrh char *CE; /* clear to end of line sequence */ 236758Srrh char *CL; /* clear screen sequence */ 246758Srrh char *CM; /* cursor movement instructions */ 256758Srrh char *HO; /* home cursor sequence */ 266758Srrh char *MC; /* column cursor movement map */ 276758Srrh char *ML; /* row cursor movement map */ 286758Srrh char *ND; /* forward cursor sequence */ 296758Srrh char *UP; /* up cursor sequence */ 306758Srrh 316758Srrh int lHO; /* length of HO */ 326758Srrh int lBC; /* length of BC */ 336758Srrh int lND; /* length of ND */ 346758Srrh int lUP; /* length of UP */ 356758Srrh int CO; /* number of columns */ 366758Srrh int LI; /* number of lines */ 376758Srrh int *linect; /* array of lengths of lines on screen 386758Srrh (the actual screen is not stored) */ 396758Srrh 406758Srrh /* two letter codes */ 416758Srrh char tcap[] = "bccdceclcmhomcmlndup"; 426758Srrh /* corresponding strings */ 436758Srrh char **tstr[] = { &BC, &CD, &CE, &CL, &CM, &HO, &MC, &ML, &ND, &UP }; 446758Srrh 456758Srrh int buffnum; /* pointer to output buffer */ 466758Srrh 476758Srrh char tbuf[1024]; /* buffer for decoded termcap entries */ 486758Srrh 496758Srrh int oldb[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; 506758Srrh 516758Srrh int oldr; 526758Srrh int oldw; 536758Srrh /* "real" cursor positions, so 546758Srrh * it knows when to reposition. 556758Srrh * These are -1 if curr and curc 566758Srrh * are accurate */ 576758Srrh int realr; 586758Srrh int realc; 596758Srrh 6033145Sbostic void addbuf(); 6133145Sbostic 626758Srrh fboard () { 636758Srrh register int i, j, l; 646758Srrh 656758Srrh curmove (0,0); /* do top line */ 666758Srrh for (i = 0; i < 53; i++) 676758Srrh fancyc ('_'); 686758Srrh 696758Srrh curmove (15,0); /* do botttom line */ 706758Srrh for (i = 0; i < 53; i++) 716758Srrh fancyc ('_'); 726758Srrh 736758Srrh l = 1; /* do vertical lines */ 746758Srrh for (i = 52; i > -1; i -= 28) { 756758Srrh curmove ( (l == 1? 1: 15) ,i); 766758Srrh fancyc ('|'); 776758Srrh for (j = 0; j < 14; j++) { 786758Srrh curmove (curr+l,curc-1); 796758Srrh fancyc ('|'); 806758Srrh } 816758Srrh if (i == 24) 826758Srrh i += 32; 836758Srrh l = -l; /* alternate directions */ 846758Srrh } 856758Srrh 866758Srrh curmove (2,1); /* label positions 13-18 */ 876758Srrh for (i = 13; i < 18; i++) { 886758Srrh fancyc ('1'); 896758Srrh fancyc ((i % 10)+'0'); 906758Srrh curmove (curr,curc+2); 916758Srrh } 926758Srrh fancyc ('1'); 936758Srrh fancyc ('8'); 946758Srrh 956758Srrh curmove (2,29); /* label positions 19-24 */ 966758Srrh fancyc ('1'); 976758Srrh fancyc ('9'); 986758Srrh for (i = 20; i < 25; i++) { 996758Srrh curmove (curr,curc+2); 1006758Srrh fancyc ('2'); 1016758Srrh fancyc ((i % 10)+'0'); 1026758Srrh } 1036758Srrh 1046758Srrh curmove (14,1); /* label positions 12-7 */ 1056758Srrh fancyc ('1'); 1066758Srrh fancyc ('2'); 1076758Srrh for (i = 11; i > 6; i--) { 1086758Srrh curmove (curr,curc+2); 1096758Srrh fancyc (i > 9? '1': ' '); 1106758Srrh fancyc ((i % 10)+'0'); 1116758Srrh } 1126758Srrh 1136758Srrh curmove (14,30); /* label positions 6-1 */ 1146758Srrh fancyc ('6'); 1156758Srrh for (i = 5; i > 0; i--) { 1166758Srrh curmove (curr,curc+3); 1176758Srrh fancyc (i+'0'); 1186758Srrh } 1196758Srrh 1206758Srrh for (i = 12; i > 6; i--) /* print positions 12-7 */ 1216758Srrh if (board[i]) 1226758Srrh bsect (board[i],13,1+4*(12-i),-1); 1236758Srrh 1246758Srrh if (board[0]) /* print red men on bar */ 1256758Srrh bsect (board[0],13,25,-1); 1266758Srrh 1276758Srrh for (i = 6; i > 0; i--) /* print positions 6-1 */ 1286758Srrh if (board[i]) 1296758Srrh bsect (board[i],13,29+4*(6-i),-1); 1306758Srrh 1316758Srrh l = (off[1] < 0? off[1]+15: off[1]); /* print white's home */ 1326758Srrh bsect (l,3,54,1); 1336758Srrh 1346758Srrh curmove (8,25); /* print the word BAR */ 1356758Srrh fancyc ('B'); 1366758Srrh fancyc ('A'); 1376758Srrh fancyc ('R'); 1386758Srrh 1396758Srrh for (i = 13; i < 19; i++) /* print positions 13-18 */ 1406758Srrh if (board[i]) 1416758Srrh bsect (board[i],3,1+4*(i-13),1); 1426758Srrh 1436758Srrh if (board[25]) /* print white's men on bar */ 1446758Srrh bsect (board[25],3,25,1); 1456758Srrh 1466758Srrh for (i = 19; i < 25; i++) /* print positions 19-24 */ 1476758Srrh if (board[i]) 1486758Srrh bsect (board[i],3,29+4*(i-19),1); 1496758Srrh 1506758Srrh l = (off[0] < 0? off[0]+15: off[0]); /* print red's home */ 1516758Srrh bsect (-l,13,54,-1); 1526758Srrh 1536758Srrh for (i = 0; i < 26; i++) /* save board position 1546758Srrh * for refresh later */ 1556758Srrh oldb[i] = board[i]; 1566758Srrh oldr = (off[1] < 0? off[1]+15: off[1]); 1576758Srrh oldw = -(off[0] < 0? off[0]+15: off[0]); 1586758Srrh } 1596758Srrh 1606758Srrh /* 1616758Srrh * bsect (b,rpos,cpos,cnext) 1626758Srrh * Print the contents of a board position. "b" has the value of the 1636758Srrh * position, "rpos" is the row to start printing, "cpos" is the column to 1646758Srrh * start printing, and "cnext" is positive if the position starts at the top 1656758Srrh * and negative if it starts at the bottom. The value of "cpos" is checked 1666758Srrh * to see if the position is a player's home, since those are printed 1676758Srrh * differently. 1686758Srrh */ 1696758Srrh 1706758Srrh bsect (b,rpos,cpos,cnext) 1716758Srrh int b; /* contents of position */ 1726758Srrh int rpos; /* row of position */ 1736758Srrh int cpos; /* column of position */ 1746758Srrh int cnext; /* direction of position */ 1756758Srrh 1766758Srrh { 1776758Srrh register int j; /* index */ 1786758Srrh register int n; /* number of men on position */ 1796758Srrh register int bct; /* counter */ 1806758Srrh int k; /* index */ 1816758Srrh char pc; /* color of men on position */ 1826758Srrh 1836758Srrh n = abs(b); /* initialize n and pc */ 1846758Srrh pc = (b > 0? 'r': 'w'); 1856758Srrh 1866758Srrh if (n < 6 && cpos < 54) /* position cursor at start */ 1876758Srrh curmove (rpos,cpos+1); 1886758Srrh else 1896758Srrh curmove (rpos,cpos); 1906758Srrh 1916758Srrh for (j = 0; j < 5; j++) { /* print position row by row */ 1926758Srrh 1936758Srrh for (k = 0; k < 15; k += 5) /* print men */ 1946758Srrh if (n > j+k) 1956758Srrh fancyc (pc); 1966758Srrh 1976758Srrh if (j < 4) { /* figure how far to 1986758Srrh * back up for next 1996758Srrh * row */ 2006758Srrh if (n < 6) { /* stop if none left */ 2016758Srrh if (j+1 == n) 2026758Srrh break; 2036758Srrh bct = 1; /* single column */ 2046758Srrh } else { 2056758Srrh if (n < 11) { /* two columns */ 2066758Srrh if (cpos == 54) { /* home pos */ 2076758Srrh if (j+5 >= n) 2086758Srrh bct = 1; 2096758Srrh else 2106758Srrh bct = 2; 2116758Srrh } 2126758Srrh if (cpos < 54) { /* not home */ 2136758Srrh if (j+6 >= n) 2146758Srrh bct = 1; 2156758Srrh else 2166758Srrh bct = 2; 2176758Srrh } 2186758Srrh } else { /* three columns */ 2196758Srrh if (j+10 >= n) 2206758Srrh bct = 2; 2216758Srrh else 2226758Srrh bct = 3; 2236758Srrh } 2246758Srrh } 2256758Srrh curmove (curr+cnext,curc-bct); /* reposition cursor */ 2266758Srrh } 2276758Srrh } 2286758Srrh } 2296758Srrh 2306758Srrh refresh() { 2316758Srrh register int i, r, c; 2326758Srrh 2336758Srrh r = curr; /* save current position */ 2346758Srrh c = curc; 2356758Srrh 2366758Srrh for (i = 12; i > 6; i--) /* fix positions 12-7 */ 2376758Srrh if (board[i] != oldb[i]) { 2386758Srrh fixpos (oldb[i],board[i],13,1+(12-i)*4,-1); 2396758Srrh oldb[i] = board[i]; 2406758Srrh } 2416758Srrh 2426758Srrh if (board[0] != oldb[0]) { /* fix red men on bar */ 2436758Srrh fixpos (oldb[0],board[0],13,25,-1); 2446758Srrh oldb[0] = board[0]; 2456758Srrh } 2466758Srrh 2476758Srrh for (i = 6; i > 0; i--) /* fix positions 6-1 */ 2486758Srrh if (board[i] != oldb[i]) { 2496758Srrh fixpos (oldb[i],board[i],13,29+(6-i)*4,-1); 2506758Srrh oldb[i] = board[i]; 2516758Srrh } 2526758Srrh 2536758Srrh i = -(off[0] < 0? off[0]+15: off[0]); /* fix white's home */ 2546758Srrh if (oldw != i) { 2556758Srrh fixpos (oldw,i,13,54,-1); 2566758Srrh oldw = i; 2576758Srrh } 2586758Srrh 2596758Srrh for (i = 13; i < 19; i++) /* fix positions 13-18 */ 2606758Srrh if (board[i] != oldb[i]) { 2616758Srrh fixpos (oldb[i],board[i],3,1+(i-13)*4,1); 2626758Srrh oldb[i] = board[i]; 2636758Srrh } 2646758Srrh 2656758Srrh if (board[25] != oldb[25]) { /* fix white men on bar */ 2666758Srrh fixpos (oldb[25],board[25],3,25,1); 2676758Srrh oldb[25] = board[25]; 2686758Srrh } 2696758Srrh 2706758Srrh for (i = 19; i < 25; i++) /* fix positions 19-24 */ 2716758Srrh if (board[i] != oldb[i]) { 2726758Srrh fixpos (oldb[i],board[i],3,29+(i-19)*4,1); 2736758Srrh oldb[i] = board[i]; 2746758Srrh } 2756758Srrh 2766758Srrh i = (off[1] < 0? off[1]+15: off[1]); /* fix red's home */ 2776758Srrh if (oldr != i) { 2786758Srrh fixpos (oldr,i,3,54,1); 2796758Srrh oldr = i; 2806758Srrh } 2816758Srrh 2826758Srrh curmove (r,c); /* return to saved position */ 2836758Srrh newpos(); 2846758Srrh buflush(); 2856758Srrh } 2866758Srrh 2876758Srrh fixpos (old,new,r,c,inc) 2886758Srrh int old, new, r, c, inc; 2896758Srrh 2906758Srrh { 2916758Srrh register int o, n, nv; 2926758Srrh int ov, nc; 2936758Srrh char col; 2946758Srrh 2956758Srrh if (old*new >= 0) { 2966758Srrh ov = abs(old); 2976758Srrh nv = abs(new); 2986758Srrh col = (old+new > 0? 'r': 'w'); 2996758Srrh o = (ov-1)/5; 3006758Srrh n = (nv-1)/5; 3016758Srrh if (o == n) { 3026758Srrh if (o == 2) 3036758Srrh nc = c+2; 3046758Srrh if (o == 1) 3056758Srrh nc = c < 54? c: c+1; 3066758Srrh if (o == 0) 3076758Srrh nc = c < 54? c+1: c; 3086758Srrh if (ov > nv) 3096758Srrh fixcol (r+inc*(nv-n*5),nc,abs(ov-nv),' ',inc); 3106758Srrh else 3116758Srrh fixcol (r+inc*(ov-o*5),nc,abs(ov-nv),col,inc); 3126758Srrh return; 3136758Srrh } else { 3146758Srrh if (c < 54) { 3156758Srrh if (o+n == 1) { 3166758Srrh if (n) { 3176758Srrh fixcol (r,c,abs(nv-5),col,inc); 3186758Srrh if (ov != 5) 3196758Srrh fixcol (r+inc*ov,c+1,abs(ov-5),col,inc); 3206758Srrh } else { 3216758Srrh fixcol (r,c,abs(ov-5),' ',inc); 3226758Srrh if (nv != 5) 3236758Srrh fixcol (r+inc*nv,c+1,abs(nv-5),' ',inc); 3246758Srrh } 3256758Srrh return; 3266758Srrh } 3276758Srrh if (n == 2) { 3286758Srrh if (ov != 10) 3296758Srrh fixcol (r+inc*(ov-5),c,abs(ov-10),col,inc); 3306758Srrh fixcol (r,c+2,abs(nv-10),col,inc); 3316758Srrh } else { 3326758Srrh if (nv != 10) 3336758Srrh fixcol (r+inc*(nv-5),c,abs(nv-10),' ',inc); 3346758Srrh fixcol (r,c+2,abs(ov-10),' ',inc); 3356758Srrh } 3366758Srrh return; 3376758Srrh } 3386758Srrh if (n > o) { 3396758Srrh fixcol (r+inc*(ov%5),c+o,abs(5*n-ov),col,inc); 3406758Srrh if (nv != 5*n) 3416758Srrh fixcol (r,c+n,abs(5*n-nv),col,inc); 3426758Srrh } else { 3436758Srrh fixcol (r+inc*(nv%5),c+n,abs(5*n-nv),' ',inc); 3446758Srrh if (ov != 5*o) 3456758Srrh fixcol (r,c+o,abs(5*o-ov),' ',inc); 3466758Srrh } 3476758Srrh return; 3486758Srrh } 3496758Srrh } 3506758Srrh nv = abs(new); 3516758Srrh fixcol (r,c+1,nv,new > 0? 'r': 'w',inc); 3526758Srrh if (abs(old) <= abs(new)) 3536758Srrh return; 3546758Srrh fixcol (r+inc*new,c+1,abs(old+new),' ',inc); 3556758Srrh } 3566758Srrh 3576758Srrh fixcol (r,c,l,ch,inc) 3586758Srrh register int l, ch; 3596758Srrh int r, c, inc; 3606758Srrh 3616758Srrh { 3626758Srrh register int i; 3636758Srrh 3646758Srrh curmove (r,c); 3656758Srrh fancyc (ch); 3666758Srrh for (i = 1; i < l; i++) { 3676758Srrh curmove (curr+inc,curc-1); 3686758Srrh fancyc (ch); 3696758Srrh } 3706758Srrh } 3716758Srrh 3726758Srrh curmove (r,c) 3736758Srrh register int r, c; 3746758Srrh 3756758Srrh { 3766758Srrh if (curr == r && curc == c) 3776758Srrh return; 3786758Srrh if (realr == -1) { 3796758Srrh realr = curr; 3806758Srrh realc = curc; 3816758Srrh } 3826758Srrh curr = r; 3836758Srrh curc = c; 3846758Srrh } 3856758Srrh 3866758Srrh newpos () { 3876758Srrh register int r; /* destination row */ 3886758Srrh register int c; /* destination column */ 3896758Srrh register int mode = -1; /* mode of movement */ 3906758Srrh 3916758Srrh int count = 1000; /* character count */ 3926758Srrh int i; /* index */ 3936758Srrh int j; /* index */ 3946758Srrh int n; /* temporary variable */ 3956758Srrh char *m; /* string containing CM movement */ 3966758Srrh 3976758Srrh 3986758Srrh if (realr == -1) /* see if already there */ 3996758Srrh return; 4006758Srrh 4016758Srrh r = curr; /* set current and dest. positions */ 4026758Srrh c = curc; 4036758Srrh curr = realr; 4046758Srrh curc = realc; 4056758Srrh 4066758Srrh /* double check position */ 4076758Srrh if (curr == r && curc == c) { 4086758Srrh realr = realc = -1; 4096758Srrh return; 4106758Srrh } 4116758Srrh 4126758Srrh if (CM) { /* try CM to get there */ 4136758Srrh mode = 0; 414*33485Sbostic m = (char *)tgoto (CM,c,r); 4156758Srrh count = strlen (m); 4166758Srrh } 4176758Srrh 4186758Srrh /* try HO and local movement */ 4196758Srrh if (HO && (n = r+c*lND+lHO) < count) { 4206758Srrh mode = 1; 4216758Srrh count = n; 4226758Srrh } 4236758Srrh 4246758Srrh /* try various LF combinations */ 4256758Srrh if (r >= curr) { 4266758Srrh /* CR, LF, and ND */ 4276758Srrh if ((n = (r-curr)+c*lND+1) < count) { 4286758Srrh mode = 2; 4296758Srrh count = n; 4306758Srrh } 4316758Srrh /* LF, ND */ 4326758Srrh if (c >= curc && (n = (r-curr)+(c-curc)*lND) < count) { 4336758Srrh mode = 3; 4346758Srrh count = n; 4356758Srrh } 4366758Srrh /* LF, BS */ 4376758Srrh if (c < curc && (n = (r-curr)+(curc-c)*lBC) < count) { 4386758Srrh mode = 4; 4396758Srrh count = n; 4406758Srrh } 4416758Srrh } 4426758Srrh 4436758Srrh /* try corresponding UP combinations */ 4446758Srrh if (r < curr) { 4456758Srrh /* CR, UP, and ND */ 4466758Srrh if ((n = (curr-r)*lUP+c*lND+1) < count) { 4476758Srrh mode = 5; 4486758Srrh count = n; 4496758Srrh } 4506758Srrh /* UP and ND */ 4516758Srrh if (c >= curc && (n = (curr-r)*lUP+(c-curc)*lND) < count) { 4526758Srrh mode = 6; 4536758Srrh count = n; 4546758Srrh } 4556758Srrh /* UP and BS */ 4566758Srrh if (c < curc && (n = (curr-r)*lUP+(curc-c)*lBC) < count) { 4576758Srrh mode = 7; 4586758Srrh count = n; 4596758Srrh } 4606758Srrh } 4616758Srrh 4626758Srrh /* space over */ 4636758Srrh if (curr == r && c > curc && linect[r] < curc && c-curc < count) 4646758Srrh mode = 8; 4656758Srrh 4666758Srrh switch (mode) { 4676758Srrh 4686758Srrh case -1: /* error! */ 4696758Srrh write (2,"\r\nInternal cursor error.\r\n",26); 4706758Srrh getout(); 4716758Srrh 4726758Srrh /* direct cursor motion */ 4736758Srrh case 0: 4746758Srrh tputs (m,abs(curr-r),addbuf); 4756758Srrh break; 4766758Srrh 4776758Srrh /* relative to "home" */ 4786758Srrh case 1: 4796758Srrh tputs (HO,r,addbuf); 4806758Srrh for (i = 0; i < r; i++) 4816758Srrh addbuf ('\012'); 4826758Srrh for (i = 0; i < c; i++) 4836758Srrh tputs (ND,1,addbuf); 4846758Srrh break; 4856758Srrh 4866758Srrh /* CR and down and over */ 4876758Srrh case 2: 4886758Srrh addbuf ('\015'); 4896758Srrh for (i = 0; i < r-curr; i++) 4906758Srrh addbuf ('\012'); 4916758Srrh for (i = 0; i < c; i++) 4926758Srrh tputs (ND,1,addbuf); 4936758Srrh break; 4946758Srrh 4956758Srrh /* down and over */ 4966758Srrh case 3: 4976758Srrh for (i = 0; i < r-curr; i++) 4986758Srrh addbuf ('\012'); 4996758Srrh for (i = 0; i < c-curc; i++) 5006758Srrh tputs (ND,1,addbuf); 5016758Srrh break; 5026758Srrh 5036758Srrh /* down and back */ 5046758Srrh case 4: 5056758Srrh for (i = 0; i < r-curr; i++) 5066758Srrh addbuf ('\012'); 5076758Srrh for (i = 0; i < curc-c; i++) 5086758Srrh addbuf ('\010'); 5096758Srrh break; 5106758Srrh 5116758Srrh /* CR and up and over */ 5126758Srrh case 5: 5136758Srrh addbuf ('\015'); 5146758Srrh for (i = 0; i < curr-r; i++) 5156758Srrh tputs (UP,1,addbuf); 5166758Srrh for (i = 0; i < c; i++) 5176758Srrh tputs (ND,1,addbuf); 5186758Srrh break; 5196758Srrh 5206758Srrh /* up and over */ 5216758Srrh case 6: 5226758Srrh for (i = 0; i < curr-r; i++) 5236758Srrh tputs (UP,1,addbuf); 5246758Srrh for (i = 0; i < c-curc; i++) 5256758Srrh tputs (ND,1,addbuf); 5266758Srrh break; 5276758Srrh 5286758Srrh /* up and back */ 5296758Srrh case 7: 5306758Srrh for (i = 0; i < curr-r; i++) 5316758Srrh tputs (UP,1,addbuf); 5326758Srrh for (i = 0; i < curc-c; i++) { 5336758Srrh if (BC) 5346758Srrh tputs (BC,1,addbuf); 5356758Srrh else 5366758Srrh addbuf ('\010'); 5376758Srrh } 5386758Srrh break; 5396758Srrh 5406758Srrh /* safe space */ 5416758Srrh case 8: 5426758Srrh for (i = 0; i < c-curc; i++) 5436758Srrh addbuf (' '); 5446758Srrh } 5456758Srrh 5466758Srrh /* fix positions */ 5476758Srrh curr = r; 5486758Srrh curc = c; 5496758Srrh realr = -1; 5506758Srrh realc = -1; 5516758Srrh } 5526758Srrh 5536758Srrh clear () { 5546758Srrh register int i; 5556758Srrh 5566758Srrh /* double space if can't clear */ 5576758Srrh if (CL == 0) { 5586758Srrh writel ("\n\n"); 5596758Srrh return; 5606758Srrh } 5616758Srrh 5626758Srrh curr = curc = 0; /* fix position markers */ 5636758Srrh realr = realc = -1; 5646758Srrh for (i = 0; i < 24; i++) /* clear line counts */ 5656758Srrh linect[i] = -1; 5666758Srrh buffnum = -1; /* ignore leftover buffer contents */ 5676758Srrh tputs (CL,CO,addbuf); /* put CL in buffer */ 5686758Srrh } 5696758Srrh 5706758Srrh tos () { /* home cursor */ 5716758Srrh curmove (0,0); 5726758Srrh } 5736758Srrh 5746758Srrh fancyc (c) 5756758Srrh register char c; /* character to output */ 5766758Srrh { 5776758Srrh register int sp; /* counts spaces in a tab */ 5786758Srrh 5796758Srrh if (c == '\007') { /* bells go in blindly */ 5806758Srrh addbuf (c); 5816758Srrh return; 5826758Srrh } 5836758Srrh 5846758Srrh /* process tabs, use spaces if the 5856758Srrh * the tab should be erasing things, 5866758Srrh * otherwise use cursor movement 5876758Srrh * routines. Note this does not use 5886758Srrh * hardware tabs at all. */ 5896758Srrh if (c == '\t') { 5906758Srrh sp = (curc+8) & (~ 7); /* compute spaces */ 5916758Srrh /* check line length */ 5926758Srrh if (linect[curr] >= curc || sp < 4) { 5936758Srrh for (; sp > curc; sp--) 5946758Srrh addbuf (' '); 5956758Srrh curc = sp; /* fix curc */ 5966758Srrh } else 5976758Srrh curmove (curr,sp); 5986758Srrh return; 5996758Srrh } 6006758Srrh 6016758Srrh /* do newline be calling newline */ 6026758Srrh if (c == '\n') { 6036758Srrh newline(); 6046758Srrh return; 6056758Srrh } 6066758Srrh 6076758Srrh /* ignore any other control chars */ 6086758Srrh if (c < ' ') 6096758Srrh return; 6106758Srrh 6116758Srrh /* if an erasing space or non-space, 6126758Srrh * just add it to buffer. Otherwise 6136758Srrh * use cursor movement routine, so that 6146758Srrh * multiple spaces will be grouped 6156758Srrh * together */ 6166758Srrh if (c > ' ' || linect[curr] >= curc) { 6176758Srrh newpos (); /* make sure position correct */ 6186758Srrh addbuf (c); /* add character to buffer */ 6196758Srrh /* fix line length */ 6206758Srrh if (c == ' ' && linect[curr] == curc) 6216758Srrh linect[curr]--; 6226758Srrh else if (linect[curr] < curc) 6236758Srrh linect[curr] = curc; 6246758Srrh curc++; /* fix curc */ 6256758Srrh } else 6266758Srrh /* use cursor movement routine */ 6276758Srrh curmove (curr,curc+1); 6286758Srrh } 6296758Srrh 6306758Srrh clend() { 6316758Srrh register int i; 6326758Srrh register char *s; 6336758Srrh 6346758Srrh 6356758Srrh if (CD) { 6366758Srrh tputs (CD,CO-curr,addbuf); 6376758Srrh for (i = curr; i < LI; i++) 6386758Srrh linect[i] = -1; 6396758Srrh return; 6406758Srrh } 6416758Srrh 6426758Srrh curmove (i = curr,0); 6436758Srrh cline(); 6446758Srrh while (curr < LI-1) { 6456758Srrh curmove (curr+1,0); 6466758Srrh if (linect[curr] > -1) 6476758Srrh cline (); 6486758Srrh } 6496758Srrh curmove (i,0); 6506758Srrh } 6516758Srrh 6526758Srrh cline () { 6536758Srrh register int i; 6546758Srrh register int c; 6556758Srrh register char *s; 6566758Srrh 6576758Srrh if (curc > linect[curr]) 6586758Srrh return; 6596758Srrh newpos (); 6606758Srrh if (CE) { 6616758Srrh tputs (CE,1,addbuf); 6626758Srrh linect[curr] = curc-1; 6636758Srrh } else { 6646758Srrh c = curc-1; 6656758Srrh while (linect[curr] > c) { 6666758Srrh addbuf (' '); 6676758Srrh curc++; 6686758Srrh linect[curr]--; 6696758Srrh } 6706758Srrh curmove (curr,c+1); 6716758Srrh } 6726758Srrh } 6736758Srrh 6746758Srrh newline () { 6756758Srrh cline(); 6766758Srrh if (curr == LI-1) 6776758Srrh curmove (begscr,0); 6786758Srrh else 6796758Srrh curmove (curr+1,0); 6806758Srrh } 6816758Srrh 6826758Srrh getcaps (s) 6836758Srrh register char *s; 6846758Srrh 6856758Srrh { 6866758Srrh register char *code; /* two letter code */ 6876758Srrh register char ***cap; /* pointer to cap string */ 6886758Srrh char *bufp; /* pointer to cap buffer */ 6896758Srrh char tentry[1024]; /* temporary uncoded caps buffer */ 6906758Srrh 6916758Srrh tgetent (tentry,s); /* get uncoded termcap entry */ 6926758Srrh 6936758Srrh LI = tgetnum ("li"); /* get number of lines */ 6946758Srrh if (LI == -1) 6956758Srrh LI = 12; 6966758Srrh CO = tgetnum ("co"); /* get number of columns */ 6976758Srrh if (CO == -1) 6986758Srrh CO = 65; 6996758Srrh 7006758Srrh bufp = tbuf; /* get padding character */ 7016758Srrh tgetstr ("pc",&bufp); 7026758Srrh if (bufp != tbuf) 7036758Srrh PC = *tbuf; 7046758Srrh else 7056758Srrh PC = 0; 7066758Srrh 7076758Srrh bufp = tbuf; /* get string entries */ 7086758Srrh cap = tstr; 7096758Srrh for (code = tcap; *code; code += 2) 710*33485Sbostic **cap++ = (char *)tgetstr (code,&bufp); 7116758Srrh 7126758Srrh /* get pertinent lengths */ 7136758Srrh if (HO) 7146758Srrh lHO = strlen (HO); 7156758Srrh if (BC) 7166758Srrh lBC = strlen (BC); 7176758Srrh else 7186758Srrh lBC = 1; 7196758Srrh if (UP) 7206758Srrh lUP = strlen (UP); 7216758Srrh if (ND) 7226758Srrh lND = strlen (ND); 7236758Srrh if (LI < 24 || CO < 72 || !(CL && UP && ND)) 7246758Srrh return (0); 725*33485Sbostic linect = (int *)calloc (LI+1,sizeof(int)); 7266758Srrh return (1); 7276758Srrh } 728