if can't open the file, just (effectively) echo the line.
[unix-history] / usr / src / usr.bin / soelim / soelim.c
CommitLineData
9604f134 1static char *sccsid = "@(#)soelim.c 4.3 (Berkeley) %G%";
59c77a70 2
feec294f
BJ
3#include <stdio.h>
4/*
5 * soelim - a filter to process n/troff input eliminating .so's
6 *
7 * Author: Bill Joy UCB July 8, 1977
8 *
9 * This program eliminates .so's from a n/troff input stream.
10 * It can be used to prepare safe input for submission to the
11 * phototypesetter since the software supporting the operator
12 * doesn't let him do chdir.
13 *
14 * This is a kludge and the operator should be given the
15 * ability to do chdir.
16 *
17 * This program is more generally useful, it turns out, because
18 * the program tbl doesn't understand ".so" directives.
19 */
59c77a70 20#define STDIN_NAME "-"
feec294f
BJ
21
22main(argc, argv)
23 int argc;
24 char *argv[];
25{
26
27 argc--;
28 argv++;
29 if (argc == 0) {
9604f134 30 (void)process(STDIN_NAME);
59c77a70 31 exit(0);
feec294f
BJ
32 }
33 do {
9604f134 34 (void)process(argv[0]);
feec294f
BJ
35 argv++;
36 argc--;
37 } while (argc > 0);
38 exit(0);
39}
40
9604f134 41int process(file)
feec294f
BJ
42 char *file;
43{
44 register char *cp;
45 register int c;
46 char fname[BUFSIZ];
47 FILE *soee;
9604f134 48 int isfile;
feec294f 49
59c77a70
KM
50 if (!strcmp(file, STDIN_NAME)) {
51 soee = stdin;
52 } else {
53 soee = fopen(file, "r");
54 if (soee == NULL) {
55 perror(file);
9604f134 56 return(-1);
59c77a70 57 }
feec294f
BJ
58 }
59 for (;;) {
60 c = getc(soee);
61 if (c < 0)
62 break;
63 if (c != '.')
64 goto simple;
65 c = getc(soee);
66 if (c != 's') {
67 putchar('.');
68 goto simple;
69 }
70 c = getc(soee);
71 if (c != 'o') {
72 printf(".s");
73 goto simple;
74 }
75 do
76 c = getc(soee);
77 while (c == ' ' || c == '\t');
78 cp = fname;
9604f134 79 isfile = 0;
feec294f
BJ
80 for (;;) {
81 switch (c) {
82
83 case ' ':
84 case '\t':
85 case '\n':
86 case EOF:
87 goto donename;
88
89 default:
90 *cp++ = c;
91 c = getc(soee);
9604f134 92 isfile++;
feec294f
BJ
93 continue;
94 }
95 }
96donename:
97 if (cp == fname) {
98 printf(".so");
99 goto simple;
100 }
101 *cp++ = 0;
9604f134
KM
102 if (process(fname) < 0)
103 if (isfile)
104 printf(".so %s\n", fname);
feec294f
BJ
105 continue;
106simple:
107 if (c == EOF)
108 break;
109 putchar(c);
110 }
59c77a70
KM
111 if (soee != stdin) {
112 fclose(soee);
113 }
9604f134 114 return(0);
feec294f 115}