[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.8

1.8     ! deraadt     1: /*     $OpenBSD: soelim.c,v 1.7 2003/06/10 22:20:51 deraadt 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: #include <stdio.h>
                     34: /*
                     35:  * soelim - a filter to process n/troff input eliminating .so's
                     36:  *
                     37:  * Author: Bill Joy UCB July 8, 1977
                     38:  *
                     39:  * This program eliminates .so's from a n/troff input stream.
                     40:  * It can be used to prepare safe input for submission to the
                     41:  * phototypesetter since the software supporting the operator
                     42:  * doesn't let him do chdir.
                     43:  *
                     44:  * This is a kludge and the operator should be given the
                     45:  * ability to do chdir.
                     46:  *
                     47:  * This program is more generally useful, it turns out, because
                     48:  * the program tbl doesn't understand ".so" directives.
                     49:  */
                     50: #define        STDIN_NAME      "-"
                     51:
1.5       millert    52: int process(char *file);
1.3       deraadt    53:
                     54: int
1.7       deraadt    55: main(int argc, char *argv[])
1.1       deraadt    56: {
                     57:
                     58:        argc--;
                     59:        argv++;
                     60:        if (argc == 0) {
                     61:                (void)process(STDIN_NAME);
                     62:                exit(0);
                     63:        }
                     64:        do {
                     65:                (void)process(argv[0]);
                     66:                argv++;
                     67:                argc--;
                     68:        } while (argc > 0);
                     69:        exit(0);
                     70: }
                     71:
1.7       deraadt    72: int
                     73: process(char *file)
1.1       deraadt    74: {
1.4       mpech      75:        char *cp;
                     76:        int c;
1.1       deraadt    77:        char fname[BUFSIZ];
                     78:        FILE *soee;
                     79:        int isfile;
                     80:
                     81:        if (!strcmp(file, STDIN_NAME)) {
                     82:                soee = stdin;
                     83:        } else {
                     84:                soee = fopen(file, "r");
                     85:                if (soee == NULL) {
                     86:                        perror(file);
                     87:                        return(-1);
                     88:                }
                     89:        }
                     90:        for (;;) {
                     91:                c = getc(soee);
                     92:                if (c == EOF)
                     93:                        break;
                     94:                if (c != '.')
                     95:                        goto simple;
                     96:                c = getc(soee);
                     97:                if (c != 's') {
                     98:                        putchar('.');
                     99:                        goto simple;
                    100:                }
                    101:                c = getc(soee);
                    102:                if (c != 'o') {
                    103:                        printf(".s");
                    104:                        goto simple;
                    105:                }
                    106:                do
                    107:                        c = getc(soee);
                    108:                while (c == ' ' || c == '\t');
                    109:                cp = fname;
                    110:                isfile = 0;
                    111:                for (;;) {
                    112:                        switch (c) {
                    113:
                    114:                        case ' ':
                    115:                        case '\t':
                    116:                        case '\n':
                    117:                        case EOF:
                    118:                                goto donename;
                    119:
                    120:                        default:
                    121:                                *cp++ = c;
                    122:                                c = getc(soee);
                    123:                                isfile++;
                    124:                                continue;
                    125:                        }
                    126:                }
                    127: donename:
                    128:                if (cp == fname) {
                    129:                        printf(".so");
                    130:                        goto simple;
                    131:                }
                    132:                *cp = 0;
                    133:                if (process(fname) < 0)
                    134:                        if (isfile)
                    135:                                printf(".so %s\n", fname);
                    136:                continue;
                    137: simple:
                    138:                if (c == EOF)
                    139:                        break;
                    140:                putchar(c);
                    141:                if (c != '\n') {
                    142:                        c = getc(soee);
                    143:                        goto simple;
                    144:                }
                    145:        }
                    146:        if (soee != stdin) {
                    147:                fclose(soee);
                    148:        }
                    149:        return(0);
                    150: }