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.
43 #include <sys/types.h>
46 #define MAXLL 2048 /* ridiculous maximum line length */
48 int Dash
= 1; /* underline with dashes */
49 int Dp
= 0; /* dash pending */
50 int Lc
= 0; /* line count */
51 char *Pname
; /* program name */
52 unsigned char Ulb
[MAXLL
]; /* underline buffer */
53 int Ulx
= 0; /* underline buffer index */
61 int ax
= 1; /* argument index */
62 unsigned char c
; /* character buffer */
63 FILE *fs
; /* file stream */
64 int nf
= 0; /* number of files processed */
65 unsigned char pc
; /* previous character */
66 int under
= 0; /* underline */
70 if ((Pname
= strrchr(argv
[0], '/')) != NULL
)
72 else if ((Pname
= strrchr(argv
[0], '\\')) != NULL
)
79 if (argc
> 1 && argv
[1][0] == '-') {
82 * "-U" - underline with dashes.
89 * "-" - do no underlining at all.
95 (void) fprintf(stderr
,
96 "%s usage: [-] [-U] [file]\n", Pname
);
102 * Process files. Read standard input if no files names.
105 while (ax
< argc
|| nf
== 0) {
110 if ((fs
= fopen(argv
[ax
], "r")) == NULL
)
112 if ((fs
= fopen(argv
[ax
], "rt")) == NULL
)
115 (void) fprintf(stderr
, "%s: can't open %s\n",
123 * Read input a character at a time.
126 c
= (unsigned char)fgetc(fs
);
165 * Putchar(ch) - put a character with possible underlining
172 int i
; /* temporary index */
174 if ((unsigned char)ch
== '\n') {
176 * Handle end of line.
180 while (Ulx
&& Ulb
[Ulx
-1] == ' ')
183 for (i
= 0; i
< Ulx
; i
++)
193 * Put "normal" character.
195 putchar((unsigned char)ch
);
199 * Handle dash-type underlining.
202 (void) fprintf(stderr
,
203 "%s: underline for line %d > %d characters\n",
207 Ulb
[Ulx
++] = Dp
? '-' : ' ';