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