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