2 * bsfilt.c - a colcrt-like processor for cawf(1)
6 * Copyright (c) 1991 Purdue University Research Foundation,
7 * West Lafayette, Indiana 47907. All rights reserved.
9 * Written by Victor A. Abell <abe@mace.cc.purdue.edu>, Purdue
10 * University Computing Center. Not derived from licensed software;
11 * derived from awf(1) by Henry Spencer of the University of Toronto.
13 * Permission is granted to anyone to use this software for any
14 * purpose on any computer system, and to alter it and redistribute
15 * it freely, subject to the following restrictions:
17 * 1. The author is not responsible for any consequences of use of
18 * this software, even if they arise from flaws in it.
20 * 2. The origin of this software must not be misrepresented, either
21 * by explicit claim or by omission. Credits must appear in the
24 * 3. Altered versions must be plainly marked as such, and must not
25 * be misrepresented as being the original software. Credits must
26 * appear in the documentation.
28 * 4. This notice may not be removed or altered.
44 #include <sys/types.h>
47 #define MAXLL 2048 /* ridiculous maximum line length */
49 int Dash
= 1; /* underline with dashes */
50 int Dp
= 0; /* dash pending */
51 int Lc
= 0; /* line count */
52 char *Pname
; /* program name */
53 unsigned char Ulb
[MAXLL
]; /* underline buffer */
54 int Ulx
= 0; /* underline buffer index */
58 int main(int argc
, char *argv
[]) {
59 int ax
= 1; /* argument index */
60 unsigned char c
; /* character buffer */
61 FILE *fs
; /* file stream */
62 int nf
= 0; /* number of files processed */
63 unsigned char pc
; /* previous character */
64 int under
= 0; /* underline */
68 if ((Pname
= strrchr(argv
[0], '/')) != NULL
)
70 else if ((Pname
= strrchr(argv
[0], '\\')) != NULL
)
77 if (argc
> 1 && argv
[1][0] == '-') {
80 * "-U" - underline with dashes.
87 * "-" - do no underlining at all.
93 (void) fprintf(stderr
,
94 "%s usage: [-] [-U] [file]\n", Pname
);
100 * Process files. Read standard input if no files names.
103 while (ax
< argc
|| nf
== 0) {
108 if ((fs
= fopen(argv
[ax
], "r")) == NULL
)
110 if ((fs
= fopen(argv
[ax
], "rt")) == NULL
)
113 (void) fprintf(stderr
, "%s: can't open %s\n",
121 * Read input a character at a time.
124 c
= (unsigned char)fgetc(fs
);
163 * Putchar(ch) - put a character with possible underlining
166 void Putchar(int ch
) {
167 int i
; /* temporary index */
169 if ((unsigned char)ch
== '\n') {
171 * Handle end of line.
175 while (Ulx
&& Ulb
[Ulx
-1] == ' ')
178 for (i
= 0; i
< Ulx
; i
++)
188 * Put "normal" character.
190 putchar((unsigned char)ch
);
194 * Handle dash-type underlining.
197 (void) fprintf(stderr
,
198 "%s: underline for line %d > %d characters\n",
202 Ulb
[Ulx
++] = Dp
? '-' : ' ';