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