|
|
1.1 root 1: /*
2: * Copyright (c) 1980 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: char copyright[] =
22: "@(#) Copyright (c) 1980 The Regents of the University of California.\n\
23: All rights reserved.\n";
24: #endif /* not lint */
25:
26: #ifndef lint
27: static char sccsid[] = "@(#)colcrt.c 5.4 (Berkeley) 6/1/90";
28: #endif /* not lint */
29:
30: #include <stdio.h>
31: /*
32: * colcrt - replaces col for crts with new nroff esp. when using tbl.
33: * Bill Joy UCB July 14, 1977
34: *
35: * This filter uses a screen buffer, 267 half-lines by 132 columns.
36: * It interprets the up and down sequences generated by the new
37: * nroff when used with tbl and by \u \d and \r.
38: * General overstriking doesn't work correctly.
39: * Underlining is split onto multiple lines, etc.
40: *
41: * Option - suppresses all underlining.
42: * Option -2 forces printing of all half lines.
43: */
44:
45: char page[267][132];
46:
47: int outline = 1;
48: int outcol;
49:
50: char suppresul;
51: char printall;
52:
53: char *progname;
54: FILE *f;
55:
56: main(argc, argv)
57: int argc;
58: char *argv[];
59: {
60: register c;
61: register char *cp, *dp;
62:
63: argc--;
64: progname = *argv++;
65: while (argc > 0 && argv[0][0] == '-') {
66: switch (argv[0][1]) {
67: case 0:
68: suppresul = 1;
69: break;
70: case '2':
71: printall = 1;
72: break;
73: default:
74: printf("usage: %s [ - ] [ -2 ] [ file ... ]\n", progname);
75: fflush(stdout);
76: exit(1);
77: }
78: argc--;
79: argv++;
80: }
81: do {
82: if (argc > 0) {
83: close(0);
84: if (!(f = fopen(argv[0], "r"))) {
85: fflush(stdout);
86: perror(argv[0]);
87: exit (1);
88: }
89: argc--;
90: argv++;
91: }
92: for (;;) {
93: c = getc(stdin);
94: if (c == -1) {
95: pflush(outline);
96: fflush(stdout);
97: break;
98: }
99: switch (c) {
100: case '\n':
101: if (outline >= 265)
102: pflush(62);
103: outline += 2;
104: outcol = 0;
105: continue;
106: case '\016':
107: case '\017':
108: continue;
109: case 033:
110: c = getc(stdin);
111: switch (c) {
112: case '9':
113: if (outline >= 266)
114: pflush(62);
115: outline++;
116: continue;
117: case '8':
118: if (outline >= 1)
119: outline--;
120: continue;
121: case '7':
122: outline -= 2;
123: if (outline < 0)
124: outline = 0;
125: continue;
126: default:
127: continue;
128: }
129: case '\b':
130: if (outcol)
131: outcol--;
132: continue;
133: case '\t':
134: outcol += 8;
135: outcol &= ~7;
136: outcol--;
137: c = ' ';
138: default:
139: if (outcol >= 132) {
140: outcol++;
141: continue;
142: }
143: cp = &page[outline][outcol];
144: outcol++;
145: if (c == '_') {
146: if (suppresul)
147: continue;
148: cp += 132;
149: c = '-';
150: }
151: if (*cp == 0) {
152: *cp = c;
153: dp = cp - outcol;
154: for (cp--; cp >= dp && *cp == 0; cp--)
155: *cp = ' ';
156: } else
157: if (plus(c, *cp) || plus(*cp, c))
158: *cp = '+';
159: else if (*cp == ' ' || *cp == 0)
160: *cp = c;
161: continue;
162: }
163: }
164: } while (argc > 0);
165: fflush(stdout);
166: exit(0);
167: }
168:
169: plus(c, d)
170: char c, d;
171: {
172:
173: return (c == '|' && d == '-' || d == '_');
174: }
175:
176: int first;
177:
178: pflush(ol)
179: int ol;
180: {
181: register int i, j;
182: register char *cp;
183: char lastomit;
184: int l;
185:
186: l = ol;
187: lastomit = 0;
188: if (l > 266)
189: l = 266;
190: else
191: l |= 1;
192: for (i = first | 1; i < l; i++) {
193: move(i, i - 1);
194: move(i, i + 1);
195: }
196: for (i = first; i < l; i++) {
197: cp = page[i];
198: if (printall == 0 && lastomit == 0 && *cp == 0) {
199: lastomit = 1;
200: continue;
201: }
202: lastomit = 0;
203: printf("%s\n", cp);
204: }
205: bcopy(page[ol], page, (267 - ol) * 132);
206: bzero(page[267- ol], ol * 132);
207: outline -= ol;
208: outcol = 0;
209: first = 1;
210: }
211:
212: move(l, m)
213: int l, m;
214: {
215: register char *cp, *dp;
216:
217: for (cp = page[l], dp = page[m]; *cp; cp++, dp++) {
218: switch (*cp) {
219: case '|':
220: if (*dp != ' ' && *dp != '|' && *dp != 0)
221: return;
222: break;
223: case ' ':
224: break;
225: default:
226: return;
227: }
228: }
229: if (*cp == 0) {
230: for (cp = page[l], dp = page[m]; *cp; cp++, dp++)
231: if (*cp == '|')
232: *dp = '|';
233: else if (*dp == 0)
234: *dp = ' ';
235: page[l][0] = 0;
236: }
237: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.