1 /* prep - prepare file for statistics Author: Andy Tanenbaum */
7 #define TROFF_CHAR '.' /* troff commands begin with this char */
8 #define EOL '\n' /* end of line char */
9 #define APOSTROPHE 047 /* single quote */
10 #define BACKSLASH '\\' /* troff code */
12 int lfread
; /* set when last char read was lf */
13 int lfwritten
= 1; /* set when last char written was lf */
15 _PROTOTYPE(int main
, (int argc
, char **argv
));
16 _PROTOTYPE(void skipline
, (void));
17 _PROTOTYPE(int backslash
, (void));
18 _PROTOTYPE(void usage
, (void));
27 if (argc
> 2) usage();
29 if (freopen(argv
[1], "r", stdin
) == NULL
) {
30 printf("prep: cannot open %s\n", argv
[1]);
34 while ((c
= getchar()) != EOF
) {
35 /* Lines beginning with "." are troff commands -- skip them. */
36 if (lfread
&& c
== TROFF_CHAR
) {
40 while (c
== BACKSLASH
) c
= backslash(); /* eat troff stuff */
54 if (c
== APOSTROPHE
) {
60 lfread
= (c
== EOL
? 1 : 0);
61 if (lfwritten
) continue;
73 while ((c
= getchar()) != EOL
);
79 /* A backslash has been seen. Eat troff stuff. */
90 case 's': /* \s7 or \s14 */
93 if (isdigit(c
)) c
= getchar();
96 case 'n': /* \na or \n(xx */
105 case '*': /* / * (XX */
114 case '(': /* troff 4-character escape sequence */
117 if (c1
== 'e' && c2
== 'm') return(' ');
118 if (c1
== 'e' && c2
== 'n') return(' ');
122 case '%': /* soft hyphen: \% */
134 printf("Usage: prep [file]\n");