Annotation of 43BSDReno/usr.bin/soelim/soelim.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1980 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: char copyright[] =
                     22: "@(#) Copyright (c) 1980 The Regents of the University of California.\n\
                     23:  All rights reserved.\n";
                     24: #endif /* not lint */
                     25: 
                     26: #ifndef lint
                     27: static char sccsid[] = "@(#)soelim.c   5.3 (Berkeley) 6/1/90";
                     28: #endif /* not lint */
                     29: 
                     30: #include <stdio.h>
                     31: /*
                     32:  * soelim - a filter to process n/troff input eliminating .so's
                     33:  *
                     34:  * Author: Bill Joy UCB July 8, 1977
                     35:  *
                     36:  * This program eliminates .so's from a n/troff input stream.
                     37:  * It can be used to prepare safe input for submission to the
                     38:  * phototypesetter since the software supporting the operator
                     39:  * doesn't let him do chdir.
                     40:  *
                     41:  * This is a kludge and the operator should be given the
                     42:  * ability to do chdir.
                     43:  *
                     44:  * This program is more generally useful, it turns out, because
                     45:  * the program tbl doesn't understand ".so" directives.
                     46:  */
                     47: #define        STDIN_NAME      "-"
                     48: 
                     49: main(argc, argv)
                     50:        int argc;
                     51:        char *argv[];
                     52: {
                     53: 
                     54:        argc--;
                     55:        argv++;
                     56:        if (argc == 0) {
                     57:                (void)process(STDIN_NAME);
                     58:                exit(0);
                     59:        }
                     60:        do {
                     61:                (void)process(argv[0]);
                     62:                argv++;
                     63:                argc--;
                     64:        } while (argc > 0);
                     65:        exit(0);
                     66: }
                     67: 
                     68: int process(file)
                     69:        char *file;
                     70: {
                     71:        register char *cp;
                     72:        register int c;
                     73:        char fname[BUFSIZ];
                     74:        FILE *soee;
                     75:        int isfile;
                     76: 
                     77:        if (!strcmp(file, STDIN_NAME)) {
                     78:                soee = stdin;
                     79:        } else {
                     80:                soee = fopen(file, "r");
                     81:                if (soee == NULL) {
                     82:                        perror(file);
                     83:                        return(-1);
                     84:                }
                     85:        }
                     86:        for (;;) {
                     87:                c = getc(soee);
                     88:                if (c == EOF)
                     89:                        break;
                     90:                if (c != '.')
                     91:                        goto simple;
                     92:                c = getc(soee);
                     93:                if (c != 's') {
                     94:                        putchar('.');
                     95:                        goto simple;
                     96:                }
                     97:                c = getc(soee);
                     98:                if (c != 'o') {
                     99:                        printf(".s");
                    100:                        goto simple;
                    101:                }
                    102:                do
                    103:                        c = getc(soee);
                    104:                while (c == ' ' || c == '\t');
                    105:                cp = fname;
                    106:                isfile = 0;
                    107:                for (;;) {
                    108:                        switch (c) {
                    109: 
                    110:                        case ' ':
                    111:                        case '\t':
                    112:                        case '\n':
                    113:                        case EOF:
                    114:                                goto donename;
                    115: 
                    116:                        default:
                    117:                                *cp++ = c;
                    118:                                c = getc(soee);
                    119:                                isfile++;
                    120:                                continue;
                    121:                        }
                    122:                }
                    123: donename:
                    124:                if (cp == fname) {
                    125:                        printf(".so");
                    126:                        goto simple;
                    127:                }
                    128:                *cp = 0;
                    129:                if (process(fname) < 0)
                    130:                        if (isfile)
                    131:                                printf(".so %s\n", fname);
                    132:                continue;
                    133: simple:
                    134:                if (c == EOF)
                    135:                        break;
                    136:                putchar(c);
                    137:                if (c != '\n') {
                    138:                        c = getc(soee);
                    139:                        goto simple;
                    140:                }
                    141:        }
                    142:        if (soee != stdin) {
                    143:                fclose(soee);
                    144:        }
                    145:        return(0);
                    146: }

unix.superglobalmegacorp.com

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