|
|
1.1 ! root 1: static char *sccsid = "@(#)soelim.c 4.4 (Berkeley) 6/28/83"; ! 2: ! 3: #include <stdio.h> ! 4: /* ! 5: * soelim - a filter to process n/troff input eliminating .so's ! 6: * ! 7: * Author: Bill Joy UCB July 8, 1977 ! 8: * ! 9: * This program eliminates .so's from a n/troff input stream. ! 10: * It can be used to prepare safe input for submission to the ! 11: * phototypesetter since the software supporting the operator ! 12: * doesn't let him do chdir. ! 13: * ! 14: * This is a kludge and the operator should be given the ! 15: * ability to do chdir. ! 16: * ! 17: * This program is more generally useful, it turns out, because ! 18: * the program tbl doesn't understand ".so" directives. ! 19: */ ! 20: #define STDIN_NAME "-" ! 21: ! 22: main(argc, argv) ! 23: int argc; ! 24: char *argv[]; ! 25: { ! 26: ! 27: argc--; ! 28: argv++; ! 29: if (argc == 0) { ! 30: (void)process(STDIN_NAME); ! 31: exit(0); ! 32: } ! 33: do { ! 34: (void)process(argv[0]); ! 35: argv++; ! 36: argc--; ! 37: } while (argc > 0); ! 38: exit(0); ! 39: } ! 40: ! 41: int process(file) ! 42: char *file; ! 43: { ! 44: register char *cp; ! 45: register int c; ! 46: char fname[BUFSIZ]; ! 47: FILE *soee; ! 48: int isfile; ! 49: ! 50: if (!strcmp(file, STDIN_NAME)) { ! 51: soee = stdin; ! 52: } else { ! 53: soee = fopen(file, "r"); ! 54: if (soee == NULL) { ! 55: perror(file); ! 56: return(-1); ! 57: } ! 58: } ! 59: for (;;) { ! 60: c = getc(soee); ! 61: if (c == EOF) ! 62: break; ! 63: if (c != '.') ! 64: goto simple; ! 65: c = getc(soee); ! 66: if (c != 's') { ! 67: putchar('.'); ! 68: goto simple; ! 69: } ! 70: c = getc(soee); ! 71: if (c != 'o') { ! 72: printf(".s"); ! 73: goto simple; ! 74: } ! 75: do ! 76: c = getc(soee); ! 77: while (c == ' ' || c == '\t'); ! 78: cp = fname; ! 79: isfile = 0; ! 80: for (;;) { ! 81: switch (c) { ! 82: ! 83: case ' ': ! 84: case '\t': ! 85: case '\n': ! 86: case EOF: ! 87: goto donename; ! 88: ! 89: default: ! 90: *cp++ = c; ! 91: c = getc(soee); ! 92: isfile++; ! 93: continue; ! 94: } ! 95: } ! 96: donename: ! 97: if (cp == fname) { ! 98: printf(".so"); ! 99: goto simple; ! 100: } ! 101: *cp = 0; ! 102: if (process(fname) < 0) ! 103: if (isfile) ! 104: printf(".so %s\n", fname); ! 105: continue; ! 106: simple: ! 107: if (c == EOF) ! 108: break; ! 109: putchar(c); ! 110: if (c != '\n') { ! 111: c = getc(soee); ! 112: goto simple; ! 113: } ! 114: } ! 115: if (soee != stdin) { ! 116: fclose(soee); ! 117: } ! 118: return(0); ! 119: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.