1: #ifndef lint
   2: static char *sccsid = "@(#)colcrt.c	4.2 (Berkeley) 4/3/81";
   3: #endif
   4: #include <stdio.h>
   5: /*
   6:  * colcrt - replaces col for crts with new nroff esp. when using tbl.
   7:  * Bill Joy UCB July 14, 1977
   8:  *
   9:  * This filter uses a screen buffer, 267 half-lines by 132 columns.
  10:  * It interprets the up and down sequences generated by the new
  11:  * nroff when used with tbl and by \u \d and \r.
  12:  * General overstriking doesn't work correctly.
  13:  * Underlining is split onto multiple lines, etc.
  14:  *
  15:  * Option - suppresses all underlining.
  16:  * Option -2 forces printing of all half lines.
  17:  */
  18: 
  19: char    page[267][132];
  20: 
  21: int outline = 1;
  22: int outcol;
  23: 
  24: char    buf[BUFSIZ];
  25: char    suppresul;
  26: char    printall;
  27: 
  28: char    *progname;
  29: FILE    *f;
  30: 
  31: main(argc, argv)
  32:     int argc;
  33:     char *argv[];
  34: {
  35:     register c;
  36:     register char *cp, *dp;
  37: 
  38:     argc--;
  39:     progname = *argv++;
  40:     while (argc > 0 && argv[0][0] == '-') {
  41:         switch (argv[0][1]) {
  42:             case 0:
  43:                 suppresul = 1;
  44:                 break;
  45:             case '2':
  46:                 printall = 1;
  47:                 break;
  48:             default:
  49:                 printf("usage: %s [ - ] [ -2 ] [ file ... ]\n", progname);
  50:                 fflush(stdout);
  51:                 exit(1);
  52:         }
  53:         argc--;
  54:         argv++;
  55:     }
  56:     setbuf(stdout, buf);
  57:     do {
  58:         if (argc > 0) {
  59:             close(0);
  60:             if ((f=fopen(argv[0], "r")
  61: ) < 0) {
  62:                 fflush(stdout);
  63:                 perror(argv[0]);
  64:                 fflush(stdout);
  65:                 exit (1);
  66:             }
  67:             argc--;
  68:             argv++;
  69:         }
  70:         for (;;) {
  71:             c = getc(stdin);
  72:             if (c == -1) {
  73:                 pflush(outline);
  74:                 fflush(stdout);
  75:                 break;
  76:             }
  77:             switch (c) {
  78:                 case '\n':
  79:                     if (outline >= 265)
  80:                         pflush(62);
  81:                     outline += 2;
  82:                     outcol = 0;
  83:                     continue;
  84:                 case '\016':
  85:                     case '\017':
  86:                     continue;
  87:                 case 033:
  88:                     c = getc(stdin);
  89:                     switch (c) {
  90:                         case '9':
  91:                             if (outline >= 266)
  92:                                 pflush(62);
  93:                             outline++;
  94:                             continue;
  95:                         case '8':
  96:                             if (outline >= 1)
  97:                                 outline--;
  98:                             continue;
  99:                         case '7':
 100:                             outline -= 2;
 101:                             if (outline < 0)
 102:                                 outline = 0;
 103:                             continue;
 104:                         default:
 105:                             continue;
 106:                     }
 107:                 case '\b':
 108:                     if (outcol)
 109:                         outcol--;
 110:                     continue;
 111:                 case '\t':
 112:                     outcol += 8;
 113:                     outcol &= ~7;
 114:                     outcol--;
 115:                     c = ' ';
 116:                 default:
 117:                     if (outcol >= 132) {
 118:                         outcol++;
 119:                         continue;
 120:                     }
 121:                     cp = &page[outline][outcol];
 122:                     outcol++;
 123:                     if (c == '_') {
 124:                         if (suppresul)
 125:                             continue;
 126:                         cp += 132;
 127:                         c = '-';
 128:                     }
 129:                     if (*cp == 0) {
 130:                         *cp = c;
 131:                         dp = cp - outcol;
 132:                         for (cp--; cp >= dp && *cp == 0; cp--)
 133:                             *cp = ' ';
 134:                     } else
 135:                         if (plus(c, *cp) || plus(*cp, c))
 136:                             *cp = '+';
 137:                         else if (*cp == ' ' || *cp == 0)
 138:                             *cp = c;
 139:                     continue;
 140:             }
 141:         }
 142:     } while (argc > 0);
 143:     fflush(stdout);
 144:     exit(0);
 145: }
 146: 
 147: plus(c, d)
 148:     char c, d;
 149: {
 150: 
 151:     return (c == '|' && d == '-' || d == '_');
 152: }
 153: 
 154: int first;
 155: 
 156: pflush(ol)
 157:     int ol;
 158: {
 159:     register int i;
 160:     register char *cp;
 161:     char lastomit;
 162:     register l;
 163: 
 164:     l = ol;
 165:     lastomit = 0;
 166:     if (l > 266)
 167:         l = 266;
 168:     else
 169:         l |= 1;
 170:     for (i = first | 1; i < l; i++) {
 171:         move(i, i - 1);
 172:         move(i, i + 1);
 173:     }
 174:     for (i = first; i < l; i++) {
 175:         cp = page[i];
 176:         if (printall == 0 && lastomit == 0 && *cp == 0) {
 177:             lastomit = 1;
 178:             continue;
 179:         }
 180:         lastomit = 0;
 181:         printf("%s\n", cp);
 182:     }
 183:     copy((char *) page, (char *) page[ol], (267 - ol) * 132);
 184:     clear(page[267- ol], ol * 132);
 185:     outline -= ol;
 186:     outcol = 0;
 187:     first = 1;
 188: }
 189: move(l, m)
 190:     int l, m;
 191: {
 192:     register char *cp, *dp;
 193: 
 194:     for (cp = page[l], dp = page[m]; *cp; cp++, dp++) {
 195:         switch (*cp) {
 196:             case '|':
 197:                 if (*dp != ' ' && *dp != '|' && *dp != 0)
 198:                     return;
 199:                 break;
 200:             case ' ':
 201:                 break;
 202:             default:
 203:                 return;
 204:         }
 205:     }
 206:     if (*cp == 0) {
 207:         for (cp = page[l], dp = page[m]; *cp; cp++, dp++)
 208:             if (*cp == '|')
 209:                 *dp = '|';
 210:             else if (*dp == 0)
 211:                 *dp = ' ';
 212:         page[l][0] = 0;
 213:     }
 214: }
 215: 
 216: copy(to, from, i)
 217:     register char *to, *from;
 218:     register int i;
 219: {
 220: 
 221:     if (i > 0)
 222:         do
 223:             *to++ = *from++;
 224:         while (--i);
 225: }
 226: 
 227: clear(at, cnt)
 228:     register char *at;
 229:     register int cnt;
 230: {
 231: 
 232:     if (cnt > 0)
 233:         do
 234:             *at++ = 0;
 235:         while (--cnt);
 236: }

Defined functions

clear defined in line 227; used 1 times
copy defined in line 216; used 1 times
main defined in line 31; never used
move defined in line 189; used 2 times
pflush defined in line 156; used 3 times
plus defined in line 147; used 2 times
  • in line 135(2)

Defined variables

buf defined in line 24; used 1 times
  • in line 56
first defined in line 154; used 3 times
outcol defined in line 22; used 12 times
outline defined in line 21; used 12 times
page defined in line 19; used 10 times
printall defined in line 26; used 2 times
progname defined in line 28; used 2 times
sccsid defined in line 2; never used
suppresul defined in line 25; used 2 times
Last modified: 1982-09-04
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 817
Valid CSS Valid XHTML 1.0 Strict