[BACK]Return to soelim.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / soelim

Annotation of src/usr.bin/soelim/soelim.c, Revision 1.6

1.6     ! millert     1: /*     $OpenBSD: soelim.c,v 1.5 2002/02/16 21:27:52 millert Exp $      */
1.1       deraadt     2: /*     $NetBSD: soelim.c,v 1.3 1994/12/21 08:11:26 jtc Exp $   */
                      3:
                      4: /*
                      5:  * Copyright (c) 1980, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
1.6     ! millert    16:  * 3. Neither the name of the University nor the names of its contributors
1.1       deraadt    17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  */
                     32:
                     33: #ifndef lint
                     34: static char copyright[] =
                     35: "@(#) Copyright (c) 1980, 1993\n\
                     36:        The Regents of the University of California.  All rights reserved.\n";
                     37: #endif /* not lint */
                     38:
                     39: #ifndef lint
                     40: #if 0
                     41: static char sccsid[] = "@(#)soelim.c   8.1 (Berkeley) 6/6/93";
                     42: #endif
1.6     ! millert    43: static char rcsid[] = "$OpenBSD: soelim.c,v 1.5 2002/02/16 21:27:52 millert Exp $";
1.1       deraadt    44: #endif /* not lint */
                     45:
                     46: #include <stdio.h>
                     47: /*
                     48:  * soelim - a filter to process n/troff input eliminating .so's
                     49:  *
                     50:  * Author: Bill Joy UCB July 8, 1977
                     51:  *
                     52:  * This program eliminates .so's from a n/troff input stream.
                     53:  * It can be used to prepare safe input for submission to the
                     54:  * phototypesetter since the software supporting the operator
                     55:  * doesn't let him do chdir.
                     56:  *
                     57:  * This is a kludge and the operator should be given the
                     58:  * ability to do chdir.
                     59:  *
                     60:  * This program is more generally useful, it turns out, because
                     61:  * the program tbl doesn't understand ".so" directives.
                     62:  */
                     63: #define        STDIN_NAME      "-"
                     64:
1.5       millert    65: int process(char *file);
1.3       deraadt    66:
                     67: int
1.1       deraadt    68: main(argc, argv)
                     69:        int argc;
                     70:        char *argv[];
                     71: {
                     72:
                     73:        argc--;
                     74:        argv++;
                     75:        if (argc == 0) {
                     76:                (void)process(STDIN_NAME);
                     77:                exit(0);
                     78:        }
                     79:        do {
                     80:                (void)process(argv[0]);
                     81:                argv++;
                     82:                argc--;
                     83:        } while (argc > 0);
                     84:        exit(0);
                     85: }
                     86:
                     87: int process(file)
                     88:        char *file;
                     89: {
1.4       mpech      90:        char *cp;
                     91:        int c;
1.1       deraadt    92:        char fname[BUFSIZ];
                     93:        FILE *soee;
                     94:        int isfile;
                     95:
                     96:        if (!strcmp(file, STDIN_NAME)) {
                     97:                soee = stdin;
                     98:        } else {
                     99:                soee = fopen(file, "r");
                    100:                if (soee == NULL) {
                    101:                        perror(file);
                    102:                        return(-1);
                    103:                }
                    104:        }
                    105:        for (;;) {
                    106:                c = getc(soee);
                    107:                if (c == EOF)
                    108:                        break;
                    109:                if (c != '.')
                    110:                        goto simple;
                    111:                c = getc(soee);
                    112:                if (c != 's') {
                    113:                        putchar('.');
                    114:                        goto simple;
                    115:                }
                    116:                c = getc(soee);
                    117:                if (c != 'o') {
                    118:                        printf(".s");
                    119:                        goto simple;
                    120:                }
                    121:                do
                    122:                        c = getc(soee);
                    123:                while (c == ' ' || c == '\t');
                    124:                cp = fname;
                    125:                isfile = 0;
                    126:                for (;;) {
                    127:                        switch (c) {
                    128:
                    129:                        case ' ':
                    130:                        case '\t':
                    131:                        case '\n':
                    132:                        case EOF:
                    133:                                goto donename;
                    134:
                    135:                        default:
                    136:                                *cp++ = c;
                    137:                                c = getc(soee);
                    138:                                isfile++;
                    139:                                continue;
                    140:                        }
                    141:                }
                    142: donename:
                    143:                if (cp == fname) {
                    144:                        printf(".so");
                    145:                        goto simple;
                    146:                }
                    147:                *cp = 0;
                    148:                if (process(fname) < 0)
                    149:                        if (isfile)
                    150:                                printf(".so %s\n", fname);
                    151:                continue;
                    152: simple:
                    153:                if (c == EOF)
                    154:                        break;
                    155:                putchar(c);
                    156:                if (c != '\n') {
                    157:                        c = getc(soee);
                    158:                        goto simple;
                    159:                }
                    160:        }
                    161:        if (soee != stdin) {
                    162:                fclose(soee);
                    163:        }
                    164:        return(0);
                    165: }