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

Defined functions

main defined in line 43; never used
move defined in line 200; used 2 times
pflush defined in line 166; used 3 times
plus defined in line 157; used 2 times
  • in line 145(2)

Defined variables

copyright defined in line 8; never used
first defined in line 164; used 3 times
outcol defined in line 35; used 12 times
outline defined in line 34; used 12 times
page defined in line 32; used 10 times
printall defined in line 38; used 2 times
progname defined in line 40; used 2 times
sccsid defined in line 14; never used
suppresul defined in line 37; used 2 times
Last modified: 1985-05-31
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1228
Valid CSS Valid XHTML 1.0 Strict