8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / soelim / soelim.c
blob68dbb14b8efca2bf00d9f6c7364f07d0f7328f3d
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 * Copyright (c) 2016 by Delphix. All rights reserved.
5 */
7 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
8 /* All Rights Reserved */
12 * Copyright (c) 1980 Regents of the University of California.
13 * All rights reserved. The Berkeley software License Agreement
14 * specifies the terms and conditions for redistribution.
17 #pragma ident "%Z%%M% %I% %E% SMI"
19 #include <stdio.h>
21 * soelim - a filter to process n/troff input eliminating .so's
23 * Author: Bill Joy UCB July 8, 1977
25 * This program eliminates .so's from a n/troff input stream.
26 * It can be used to prepare safe input for submission to the
27 * phototypesetter since the software supporting the operator
28 * doesn't let them do chdir.
30 * This is a kludge and the operator should be given the
31 * ability to do chdir.
33 * This program is more generally useful, it turns out, because
34 * the program tbl doesn't understand ".so" directives.
36 #define STDIN_NAME "-"
38 int
39 main(int argc, char *argv[])
42 argc--;
43 argv++;
44 if (argc == 0) {
45 (void)process(STDIN_NAME);
46 exit(0);
48 do {
49 (void)process(argv[0]);
50 argv++;
51 argc--;
52 } while (argc > 0);
53 return (0);
56 int process(file)
57 char *file;
59 register char *cp;
60 register int c;
61 char fname[BUFSIZ];
62 FILE *soee;
63 int isfile;
65 if (!strcmp(file, STDIN_NAME)) {
66 soee = stdin;
67 } else {
68 soee = fopen(file, "r");
69 if (soee == NULL) {
70 perror(file);
71 return(-1);
74 for (;;) {
75 c = getc(soee);
76 if (c == EOF)
77 break;
78 if (c != '.')
79 goto simple;
80 c = getc(soee);
81 if (c != 's') {
82 putchar('.');
83 goto simple;
85 c = getc(soee);
86 if (c != 'o') {
87 printf(".s");
88 goto simple;
91 c = getc(soee);
92 while (c == ' ' || c == '\t');
93 cp = fname;
94 isfile = 0;
95 for (;;) {
96 switch (c) {
98 case ' ':
99 case '\t':
100 case '\n':
101 case EOF:
102 goto donename;
104 default:
105 *cp++ = c;
106 c = getc(soee);
107 isfile++;
108 continue;
111 donename:
112 if (cp == fname) {
113 printf(".so");
114 goto simple;
116 *cp = 0;
117 if (process(fname) < 0)
118 if (isfile)
119 printf(".so %s\n", fname);
120 continue;
121 simple:
122 if (c == EOF)
123 break;
124 putchar(c);
125 if (c != '\n') {
126 c = getc(soee);
127 goto simple;
130 if (soee != stdin) {
131 fclose(soee);
133 return(0);