1*113f4232Sakaplan /*
2*113f4232Sakaplan * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*113f4232Sakaplan * Use is subject to license terms.
4*113f4232Sakaplan */
5*113f4232Sakaplan
67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
77c478bd9Sstevel@tonic-gate /* All Rights Reserved */
87c478bd9Sstevel@tonic-gate
97c478bd9Sstevel@tonic-gate
107c478bd9Sstevel@tonic-gate /*
117c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
127c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
137c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
147c478bd9Sstevel@tonic-gate */
157c478bd9Sstevel@tonic-gate
16*113f4232Sakaplan #pragma ident "%Z%%M% %I% %E% SMI"
177c478bd9Sstevel@tonic-gate
187c478bd9Sstevel@tonic-gate #include <stdio.h>
197c478bd9Sstevel@tonic-gate /*
207c478bd9Sstevel@tonic-gate * soelim - a filter to process n/troff input eliminating .so's
217c478bd9Sstevel@tonic-gate *
227c478bd9Sstevel@tonic-gate * Author: Bill Joy UCB July 8, 1977
237c478bd9Sstevel@tonic-gate *
247c478bd9Sstevel@tonic-gate * This program eliminates .so's from a n/troff input stream.
257c478bd9Sstevel@tonic-gate * It can be used to prepare safe input for submission to the
267c478bd9Sstevel@tonic-gate * phototypesetter since the software supporting the operator
277c478bd9Sstevel@tonic-gate * doesn't let him do chdir.
287c478bd9Sstevel@tonic-gate *
297c478bd9Sstevel@tonic-gate * This is a kludge and the operator should be given the
307c478bd9Sstevel@tonic-gate * ability to do chdir.
317c478bd9Sstevel@tonic-gate *
327c478bd9Sstevel@tonic-gate * This program is more generally useful, it turns out, because
337c478bd9Sstevel@tonic-gate * the program tbl doesn't understand ".so" directives.
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate #define STDIN_NAME "-"
367c478bd9Sstevel@tonic-gate
37*113f4232Sakaplan int
main(int argc,char * argv[])38*113f4232Sakaplan main(int argc, char *argv[])
397c478bd9Sstevel@tonic-gate {
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate argc--;
427c478bd9Sstevel@tonic-gate argv++;
437c478bd9Sstevel@tonic-gate if (argc == 0) {
447c478bd9Sstevel@tonic-gate (void)process(STDIN_NAME);
457c478bd9Sstevel@tonic-gate exit(0);
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate do {
487c478bd9Sstevel@tonic-gate (void)process(argv[0]);
497c478bd9Sstevel@tonic-gate argv++;
507c478bd9Sstevel@tonic-gate argc--;
517c478bd9Sstevel@tonic-gate } while (argc > 0);
52*113f4232Sakaplan return (0);
537c478bd9Sstevel@tonic-gate }
547c478bd9Sstevel@tonic-gate
process(file)557c478bd9Sstevel@tonic-gate int process(file)
567c478bd9Sstevel@tonic-gate char *file;
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate register char *cp;
597c478bd9Sstevel@tonic-gate register int c;
607c478bd9Sstevel@tonic-gate char fname[BUFSIZ];
617c478bd9Sstevel@tonic-gate FILE *soee;
627c478bd9Sstevel@tonic-gate int isfile;
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate if (!strcmp(file, STDIN_NAME)) {
657c478bd9Sstevel@tonic-gate soee = stdin;
667c478bd9Sstevel@tonic-gate } else {
677c478bd9Sstevel@tonic-gate soee = fopen(file, "r");
687c478bd9Sstevel@tonic-gate if (soee == NULL) {
697c478bd9Sstevel@tonic-gate perror(file);
707c478bd9Sstevel@tonic-gate return(-1);
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate }
737c478bd9Sstevel@tonic-gate for (;;) {
747c478bd9Sstevel@tonic-gate c = getc(soee);
757c478bd9Sstevel@tonic-gate if (c == EOF)
767c478bd9Sstevel@tonic-gate break;
777c478bd9Sstevel@tonic-gate if (c != '.')
787c478bd9Sstevel@tonic-gate goto simple;
797c478bd9Sstevel@tonic-gate c = getc(soee);
807c478bd9Sstevel@tonic-gate if (c != 's') {
817c478bd9Sstevel@tonic-gate putchar('.');
827c478bd9Sstevel@tonic-gate goto simple;
837c478bd9Sstevel@tonic-gate }
847c478bd9Sstevel@tonic-gate c = getc(soee);
857c478bd9Sstevel@tonic-gate if (c != 'o') {
867c478bd9Sstevel@tonic-gate printf(".s");
877c478bd9Sstevel@tonic-gate goto simple;
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate do
907c478bd9Sstevel@tonic-gate c = getc(soee);
917c478bd9Sstevel@tonic-gate while (c == ' ' || c == '\t');
927c478bd9Sstevel@tonic-gate cp = fname;
937c478bd9Sstevel@tonic-gate isfile = 0;
947c478bd9Sstevel@tonic-gate for (;;) {
957c478bd9Sstevel@tonic-gate switch (c) {
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate case ' ':
987c478bd9Sstevel@tonic-gate case '\t':
997c478bd9Sstevel@tonic-gate case '\n':
1007c478bd9Sstevel@tonic-gate case EOF:
1017c478bd9Sstevel@tonic-gate goto donename;
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate default:
1047c478bd9Sstevel@tonic-gate *cp++ = c;
1057c478bd9Sstevel@tonic-gate c = getc(soee);
1067c478bd9Sstevel@tonic-gate isfile++;
1077c478bd9Sstevel@tonic-gate continue;
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate donename:
1117c478bd9Sstevel@tonic-gate if (cp == fname) {
1127c478bd9Sstevel@tonic-gate printf(".so");
1137c478bd9Sstevel@tonic-gate goto simple;
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate *cp = 0;
1167c478bd9Sstevel@tonic-gate if (process(fname) < 0)
1177c478bd9Sstevel@tonic-gate if (isfile)
1187c478bd9Sstevel@tonic-gate printf(".so %s\n", fname);
1197c478bd9Sstevel@tonic-gate continue;
1207c478bd9Sstevel@tonic-gate simple:
1217c478bd9Sstevel@tonic-gate if (c == EOF)
1227c478bd9Sstevel@tonic-gate break;
1237c478bd9Sstevel@tonic-gate putchar(c);
1247c478bd9Sstevel@tonic-gate if (c != '\n') {
1257c478bd9Sstevel@tonic-gate c = getc(soee);
1267c478bd9Sstevel@tonic-gate goto simple;
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate if (soee != stdin) {
1307c478bd9Sstevel@tonic-gate fclose(soee);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate return(0);
1337c478bd9Sstevel@tonic-gate }
134