Annotation of 41BSD/cmd/soelim.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.