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