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

Annotation of src/usr.bin/grep/grep.c, Revision 1.49

1.49    ! tedu        1: /*     $OpenBSD: grep.c,v 1.48 2014/12/01 06:36:04 deraadt Exp $       */
1.6       deraadt     2:
1.1       deraadt     3: /*-
1.3       deraadt     4:  * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
                      5:  * All rights reserved.
1.1       deraadt     6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     17:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     18:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     19:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     20:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     21:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     22:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     23:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     24:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     25:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     26:  * SUCH DAMAGE.
                     27:  */
                     28:
1.3       deraadt    29: #include <sys/types.h>
1.9       tedu       30: #include <sys/limits.h>
1.3       deraadt    31: #include <sys/stat.h>
1.33      jaredy     32: #include <sys/queue.h>
1.1       deraadt    33:
1.18      millert    34: #include <ctype.h>
1.3       deraadt    35: #include <err.h>
                     36: #include <errno.h>
                     37: #include <getopt.h>
                     38: #include <regex.h>
1.1       deraadt    39: #include <stdio.h>
                     40: #include <stdlib.h>
1.3       deraadt    41: #include <string.h>
1.1       deraadt    42: #include <unistd.h>
                     43:
1.3       deraadt    44: #include "grep.h"
                     45:
                     46: /* Flags passed to regcomp() and regexec() */
                     47: int     cflags;
                     48: int     eflags = REG_STARTEND;
                     49:
                     50: int     matchall;      /* shortcut */
                     51: int     patterns, pattern_sz;
                     52: char   **pattern;
                     53: regex_t        *r_pattern;
1.13      tedu       54: fastgrep_t *fg_pattern;
1.3       deraadt    55:
                     56: /* For regex errors  */
                     57: char    re_error[RE_ERROR_BUF + 1];
                     58:
                     59: /* Command-line flags */
                     60: int     Aflag;         /* -A x: print x lines trailing each match */
                     61: int     Bflag;         /* -B x: print x lines leading each match */
                     62: int     Eflag;         /* -E: interpret pattern as extended regexp */
                     63: int     Fflag;         /* -F: interpret pattern as list of fixed strings */
1.43      tedu       64: int     Hflag;         /* -H: always print filename header */
1.3       deraadt    65: int     Lflag;         /* -L: only show names of files with no matches */
                     66: int     Rflag;         /* -R: recursively search directory trees */
1.5       deraadt    67: #ifndef NOZ
1.3       deraadt    68: int     Zflag;         /* -Z: decompress input before processing */
1.5       deraadt    69: #endif
1.3       deraadt    70: int     bflag;         /* -b: show block numbers for each match */
                     71: int     cflag;         /* -c: only show a count of matching lines */
                     72: int     hflag;         /* -h: don't print filename headers */
                     73: int     iflag;         /* -i: ignore case */
                     74: int     lflag;         /* -l: only show names of files with matches */
                     75: int     nflag;         /* -n: show line numbers in front of matching lines */
1.44      tedu       76: int     oflag;         /* -o: print each match */
1.3       deraadt    77: int     qflag;         /* -q: quiet mode (don't output anything) */
                     78: int     sflag;         /* -s: silent mode (ignore errors) */
                     79: int     vflag;         /* -v: only show non-matching lines */
                     80: int     wflag;         /* -w: pattern must start and end on word boundaries */
                     81: int     xflag;         /* -x: pattern must match entire line */
1.27      otto       82: int     lbflag;        /* --line-buffered */
1.3       deraadt    83:
1.9       tedu       84: int binbehave = BIN_FILE_BIN;
                     85:
                     86: enum {
                     87:        BIN_OPT = CHAR_MAX + 1,
                     88:        HELP_OPT,
1.27      otto       89:        MMAP_OPT,
                     90:        LINEBUF_OPT
1.9       tedu       91: };
                     92:
1.3       deraadt    93: /* Housekeeping */
1.10      tedu       94: int     first;         /* flag whether or not this is our first match */
1.3       deraadt    95: int     tail;          /* lines left to print */
1.45      millert    96: int     file_err;      /* file reading error */
1.3       deraadt    97:
1.33      jaredy     98: struct patfile {
                     99:        const char              *pf_file;
                    100:        SLIST_ENTRY(patfile)     pf_next;
                    101: };
                    102: SLIST_HEAD(, patfile)           patfilelh;
                    103:
1.8       tedu      104: extern char *__progname;
1.3       deraadt   105:
                    106: static void
                    107: usage(void)
                    108: {
1.5       deraadt   109:        fprintf(stderr,
                    110: #ifdef NOZ
1.44      tedu      111:            "usage: %s [-abcEFGHhIiLlnoqRsUVvwx] [-A num] [-B num] [-C[num]]\n"
1.5       deraadt   112: #else
1.44      tedu      113:            "usage: %s [-abcEFGHhIiLlnoqRsUVvwxZ] [-A num] [-B num] [-C[num]]\n"
1.5       deraadt   114: #endif
1.30      jmc       115:            "\t[-e pattern] [-f file] [--binary-files=value] [--context[=num]]\n"
                    116:            "\t[--line-buffered] [pattern] [file ...]\n", __progname);
1.3       deraadt   117:        exit(2);
                    118: }
                    119:
1.5       deraadt   120: #ifdef NOZ
1.46      millert   121: static const char optstr[] = "0123456789A:B:CEFGHILRUVabce:f:hilnoqrsuvwxy";
1.5       deraadt   122: #else
1.46      millert   123: static const char optstr[] = "0123456789A:B:CEFGHILRUVZabce:f:hilnoqrsuvwxy";
1.5       deraadt   124: #endif
1.3       deraadt   125:
1.46      millert   126: static const struct option long_options[] =
1.3       deraadt   127: {
1.19      deraadt   128:        {"binary-files",        required_argument,      NULL, BIN_OPT},
                    129:        {"help",                no_argument,            NULL, HELP_OPT},
                    130:        {"mmap",                no_argument,            NULL, MMAP_OPT},
1.27      otto      131:        {"line-buffered",       no_argument,            NULL, LINEBUF_OPT},
1.19      deraadt   132:        {"after-context",       required_argument,      NULL, 'A'},
                    133:        {"before-context",      required_argument,      NULL, 'B'},
                    134:        {"context",             optional_argument,      NULL, 'C'},
                    135:        {"devices",             required_argument,      NULL, 'D'},
                    136:        {"extended-regexp",     no_argument,            NULL, 'E'},
                    137:        {"fixed-strings",       no_argument,            NULL, 'F'},
                    138:        {"basic-regexp",        no_argument,            NULL, 'G'},
1.43      tedu      139:        {"with-filename",       no_argument,            NULL, 'H'},
1.19      deraadt   140:        {"binary",              no_argument,            NULL, 'U'},
                    141:        {"version",             no_argument,            NULL, 'V'},
                    142:        {"text",                no_argument,            NULL, 'a'},
                    143:        {"byte-offset",         no_argument,            NULL, 'b'},
                    144:        {"count",               no_argument,            NULL, 'c'},
                    145:        {"regexp",              required_argument,      NULL, 'e'},
                    146:        {"file",                required_argument,      NULL, 'f'},
                    147:        {"no-filename",         no_argument,            NULL, 'h'},
                    148:        {"ignore-case",         no_argument,            NULL, 'i'},
                    149:        {"files-without-match", no_argument,            NULL, 'L'},
                    150:        {"files-with-matches",  no_argument,            NULL, 'l'},
                    151:        {"line-number",         no_argument,            NULL, 'n'},
                    152:        {"quiet",               no_argument,            NULL, 'q'},
                    153:        {"silent",              no_argument,            NULL, 'q'},
                    154:        {"recursive",           no_argument,            NULL, 'r'},
                    155:        {"no-messages",         no_argument,            NULL, 's'},
                    156:        {"revert-match",        no_argument,            NULL, 'v'},
                    157:        {"word-regexp",         no_argument,            NULL, 'w'},
                    158:        {"line-regexp",         no_argument,            NULL, 'x'},
                    159:        {"unix-byte-offsets",   no_argument,            NULL, 'u'},
1.5       deraadt   160: #ifndef NOZ
1.19      deraadt   161:        {"decompress",          no_argument,            NULL, 'Z'},
1.5       deraadt   162: #endif
1.19      deraadt   163:        {NULL,                  no_argument,            NULL, 0}
1.3       deraadt   164: };
                    165:
1.1       deraadt   166:
1.3       deraadt   167: static void
                    168: add_pattern(char *pat, size_t len)
                    169: {
1.36      jaredy    170:        if (!xflag && (len == 0 || matchall)) {
1.3       deraadt   171:                matchall = 1;
                    172:                return;
                    173:        }
                    174:        if (patterns == pattern_sz) {
                    175:                pattern_sz *= 2;
1.48      deraadt   176:                pattern = grep_reallocarray(pattern, ++pattern_sz, sizeof(*pattern));
1.3       deraadt   177:        }
1.37      ray       178:        if (len > 0 && pat[len - 1] == '\n')
1.3       deraadt   179:                --len;
1.15      tedu      180:        /* pat may not be NUL-terminated */
1.28      millert   181:        if (wflag && !Fflag) {
1.32      otto      182:                int bol = 0, eol = 0, extra;
1.26      millert   183:                if (pat[0] == '^')
                    184:                        bol = 1;
1.36      jaredy    185:                if (len > 0 && pat[len - 1] == '$')
1.26      millert   186:                        eol = 1;
1.32      otto      187:                extra = Eflag ? 2 : 4;
                    188:                pattern[patterns] = grep_malloc(len + 15 + extra);
                    189:                snprintf(pattern[patterns], len + 15 + extra,
                    190:                   "%s[[:<:]]%s%.*s%s[[:>:]]%s",
                    191:                    bol ? "^" : "",
                    192:                    Eflag ? "(" : "\\(",
                    193:                    (int)len - bol - eol, pat + bol,
                    194:                    Eflag ? ")" : "\\)",
1.26      millert   195:                    eol ? "$" : "");
1.32      otto      196:                len += 14 + extra;
1.25      millert   197:        } else {
                    198:                pattern[patterns] = grep_malloc(len + 1);
                    199:                memcpy(pattern[patterns], pat, len);
                    200:                pattern[patterns][len] = '\0';
                    201:        }
1.3       deraadt   202:        ++patterns;
                    203: }
1.1       deraadt   204:
1.3       deraadt   205: static void
1.35      otto      206: add_patterns(char *pats)
                    207: {
                    208:        char *nl;
                    209:
                    210:        while ((nl = strchr(pats, '\n')) != NULL) {
                    211:                add_pattern(pats, nl - pats);
                    212:                pats = nl + 1;
                    213:        }
                    214:        add_pattern(pats, strlen(pats));
                    215: }
                    216:
                    217: static void
1.33      jaredy    218: read_patterns(const char *fn)
1.3       deraadt   219: {
                    220:        FILE *f;
                    221:        char *line;
                    222:        size_t len;
                    223:
                    224:        if ((f = fopen(fn, "r")) == NULL)
1.20      millert   225:                err(2, "%s", fn);
1.38      kili      226:        while ((line = fgetln(f, &len)) != NULL)
                    227:                add_pattern(line, *line == '\n' ? 0 : len);
1.3       deraadt   228:        if (ferror(f))
1.20      millert   229:                err(2, "%s", fn);
1.3       deraadt   230:        fclose(f);
                    231: }
1.1       deraadt   232:
                    233: int
1.3       deraadt   234: main(int argc, char *argv[])
1.1       deraadt   235: {
1.41      jacekm    236:        int c, lastc, prevoptind, newarg, i, needpattern, exprs, expr_sz;
1.33      jaredy    237:        struct patfile *patfile, *pf_next;
1.21      millert   238:        long l;
1.41      jacekm    239:        char *ep, **expr;
1.3       deraadt   240:
1.33      jaredy    241:        SLIST_INIT(&patfilelh);
1.16      tedu      242:        switch (__progname[0]) {
                    243:        case 'e':
1.49    ! tedu      244:                Eflag = 1;
1.16      tedu      245:                break;
                    246:        case 'f':
1.49    ! tedu      247:                Fflag = 1;
1.16      tedu      248:                break;
                    249: #ifndef NOZ
                    250:        case 'z':
1.49    ! tedu      251:                Zflag = 1;
1.16      tedu      252:                switch(__progname[1]) {
                    253:                case 'e':
1.49    ! tedu      254:                        Eflag = 1;
1.16      tedu      255:                        break;
                    256:                case 'f':
1.49    ! tedu      257:                        Fflag = 1;
1.16      tedu      258:                        break;
                    259:                }
                    260:                break;
                    261: #endif
                    262:        }
                    263:
1.18      millert   264:        lastc = '\0';
1.23      millert   265:        newarg = 1;
                    266:        prevoptind = 1;
1.38      kili      267:        needpattern = 1;
1.41      jacekm    268:        expr_sz = exprs = 0;
                    269:        expr = NULL;
1.5       deraadt   270:        while ((c = getopt_long(argc, argv, optstr,
1.17      millert   271:                                long_options, NULL)) != -1) {
1.3       deraadt   272:                switch (c) {
                    273:                case '0': case '1': case '2': case '3': case '4':
                    274:                case '5': case '6': case '7': case '8': case '9':
1.23      millert   275:                        if (newarg || !isdigit(lastc))
                    276:                                Aflag = 0;
                    277:                        else if (Aflag > INT_MAX / 10)
                    278:                                errx(2, "context out of range");
                    279:                        Aflag = Bflag = (Aflag * 10) + (c - '0');
1.3       deraadt   280:                        break;
                    281:                case 'A':
                    282:                case 'B':
1.21      millert   283:                        l = strtol(optarg, &ep, 10);
                    284:                        if (ep == optarg || *ep != '\0' ||
                    285:                            l <= 0 || l >= INT_MAX)
                    286:                                errx(2, "context out of range");
                    287:                        if (c == 'A')
                    288:                                Aflag = (int)l;
                    289:                        else
                    290:                                Bflag = (int)l;
1.3       deraadt   291:                        break;
                    292:                case 'C':
1.5       deraadt   293:                        if (optarg == NULL)
1.3       deraadt   294:                                Aflag = Bflag = 2;
1.21      millert   295:                        else {
                    296:                                l = strtol(optarg, &ep, 10);
                    297:                                if (ep == optarg || *ep != '\0' ||
                    298:                                    l <= 0 || l >= INT_MAX)
                    299:                                        errx(2, "context out of range");
                    300:                                Aflag = Bflag = (int)l;
                    301:                        }
1.1       deraadt   302:                        break;
                    303:                case 'E':
1.49    ! tedu      304:                        Fflag = 0;
        !           305:                        Eflag = 1;
1.1       deraadt   306:                        break;
                    307:                case 'F':
1.49    ! tedu      308:                        Eflag = 0;
        !           309:                        Fflag = 1;
1.3       deraadt   310:                        break;
                    311:                case 'G':
1.16      tedu      312:                        Eflag = Fflag = 0;
1.1       deraadt   313:                        break;
1.43      tedu      314:                case 'H':
1.49    ! tedu      315:                        Hflag = 1;
1.43      tedu      316:                        break;
1.9       tedu      317:                case 'I':
                    318:                        binbehave = BIN_FILE_SKIP;
                    319:                        break;
1.1       deraadt   320:                case 'L':
1.3       deraadt   321:                        lflag = 0;
                    322:                        Lflag = qflag = 1;
1.1       deraadt   323:                        break;
                    324:                case 'R':
1.3       deraadt   325:                case 'r':
1.49    ! tedu      326:                        Rflag = 1;
1.3       deraadt   327:                        break;
                    328:                case 'U':
1.9       tedu      329:                        binbehave = BIN_FILE_BIN;
1.3       deraadt   330:                        break;
                    331:                case 'V':
                    332:                        fprintf(stderr, "grep version %u.%u\n", VER_MAJ, VER_MIN);
1.9       tedu      333:                        exit(0);
1.1       deraadt   334:                        break;
1.5       deraadt   335: #ifndef NOZ
1.3       deraadt   336:                case 'Z':
1.49    ! tedu      337:                        Zflag = 1;
1.1       deraadt   338:                        break;
1.5       deraadt   339: #endif
1.1       deraadt   340:                case 'a':
1.9       tedu      341:                        binbehave = BIN_FILE_TEXT;
1.1       deraadt   342:                        break;
                    343:                case 'b':
1.3       deraadt   344:                        bflag = 1;
1.1       deraadt   345:                        break;
                    346:                case 'c':
1.3       deraadt   347:                        cflag = 1;
1.1       deraadt   348:                        break;
                    349:                case 'e':
1.41      jacekm    350:                        /* defer adding of expressions until all arguments are parsed */
                    351:                        if (exprs == expr_sz) {
                    352:                                expr_sz *= 2;
1.48      deraadt   353:                                expr = grep_reallocarray(expr, ++expr_sz,
                    354:                                    sizeof(*expr));
1.41      jacekm    355:                        }
1.38      kili      356:                        needpattern = 0;
1.41      jacekm    357:                        expr[exprs] = optarg;
                    358:                        ++exprs;
1.1       deraadt   359:                        break;
                    360:                case 'f':
1.33      jaredy    361:                        patfile = grep_malloc(sizeof(*patfile));
                    362:                        patfile->pf_file = optarg;
                    363:                        SLIST_INSERT_HEAD(&patfilelh, patfile, pf_next);
1.38      kili      364:                        needpattern = 0;
1.1       deraadt   365:                        break;
                    366:                case 'h':
1.3       deraadt   367:                        hflag = 1;
1.1       deraadt   368:                        break;
                    369:                case 'i':
1.3       deraadt   370:                case 'y':
1.13      tedu      371:                        iflag = 1;
1.1       deraadt   372:                        cflags |= REG_ICASE;
                    373:                        break;
                    374:                case 'l':
1.3       deraadt   375:                        Lflag = 0;
                    376:                        lflag = qflag = 1;
1.1       deraadt   377:                        break;
                    378:                case 'n':
1.3       deraadt   379:                        nflag = 1;
1.44      tedu      380:                        break;
                    381:                case 'o':
                    382:                        oflag = 1;
1.3       deraadt   383:                        break;
1.1       deraadt   384:                case 'q':
1.3       deraadt   385:                        qflag = 1;
1.1       deraadt   386:                        break;
                    387:                case 's':
1.3       deraadt   388:                        sflag = 1;
1.1       deraadt   389:                        break;
                    390:                case 'v':
1.3       deraadt   391:                        vflag = 1;
1.1       deraadt   392:                        break;
                    393:                case 'w':
1.3       deraadt   394:                        wflag = 1;
1.1       deraadt   395:                        break;
                    396:                case 'x':
1.3       deraadt   397:                        xflag = 1;
1.1       deraadt   398:                        break;
1.9       tedu      399:                case BIN_OPT:
                    400:                        if (strcmp("binary", optarg) == 0)
                    401:                                binbehave = BIN_FILE_BIN;
                    402:                        else if (strcmp("without-match", optarg) == 0)
                    403:                                binbehave = BIN_FILE_SKIP;
                    404:                        else if (strcmp("text", optarg) == 0)
                    405:                                binbehave = BIN_FILE_TEXT;
                    406:                        else
                    407:                                errx(2, "Unknown binary-files option");
                    408:                        break;
                    409:                case 'u':
                    410:                case MMAP_OPT:
                    411:                        /* default, compatibility */
                    412:                        break;
1.27      otto      413:                case LINEBUF_OPT:
                    414:                        lbflag = 1;
                    415:                        break;
1.9       tedu      416:                case HELP_OPT:
1.1       deraadt   417:                default:
                    418:                        usage();
                    419:                }
1.18      millert   420:                lastc = c;
1.23      millert   421:                newarg = optind != prevoptind;
1.18      millert   422:                prevoptind = optind;
1.1       deraadt   423:        }
1.3       deraadt   424:        argc -= optind;
                    425:        argv += optind;
1.41      jacekm    426:
                    427:        for (i = 0; i < exprs; i++)
                    428:                add_patterns(expr[i]);
                    429:        free(expr);
                    430:        expr = NULL;
1.33      jaredy    431:
                    432:        for (patfile = SLIST_FIRST(&patfilelh); patfile != NULL;
                    433:            patfile = pf_next) {
                    434:                pf_next = SLIST_NEXT(patfile, pf_next);
                    435:                read_patterns(patfile->pf_file);
                    436:                free(patfile);
                    437:        }
1.3       deraadt   438:
1.38      kili      439:        if (argc == 0 && needpattern)
1.1       deraadt   440:                usage();
                    441:
1.38      kili      442:        if (argc != 0 && needpattern) {
1.35      otto      443:                add_patterns(*argv);
1.3       deraadt   444:                --argc;
                    445:                ++argv;
                    446:        }
1.5       deraadt   447:
1.16      tedu      448:        if (Eflag)
                    449:                cflags |= REG_EXTENDED;
1.42      tedu      450:        if (Fflag)
                    451:                cflags |= REG_NOSPEC;
                    452: #ifdef SMALL
                    453:        /* Sorry, this won't work */
                    454:        if (Fflag && wflag)
                    455:                errx(1, "Can't use small fgrep with -w");
                    456: #endif
1.39      deraadt   457:        fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern));
                    458:        r_pattern = grep_calloc(patterns, sizeof(*r_pattern));
1.3       deraadt   459:        for (i = 0; i < patterns; ++i) {
1.28      millert   460:                /* Check if cheating is allowed (always is for fgrep). */
1.42      tedu      461: #ifndef SMALL
1.28      millert   462:                if (Fflag) {
                    463:                        fgrepcomp(&fg_pattern[i], pattern[i]);
1.42      tedu      464:                } else
                    465: #endif
                    466:                {
1.28      millert   467:                        if (fastcomp(&fg_pattern[i], pattern[i])) {
                    468:                                /* Fall back to full regex library */
                    469:                                c = regcomp(&r_pattern[i], pattern[i], cflags);
                    470:                                if (c != 0) {
                    471:                                        regerror(c, &r_pattern[i], re_error,
                    472:                                            RE_ERROR_BUF);
                    473:                                        errx(2, "%s", re_error);
                    474:                                }
1.13      tedu      475:                        }
1.1       deraadt   476:                }
                    477:        }
1.29      deraadt   478:
1.27      otto      479:        if (lbflag)
1.47      millert   480:                setvbuf(stdout, NULL, _IOLBF, 0);
1.1       deraadt   481:
1.43      tedu      482:        if ((argc == 0 || argc == 1) && !Rflag && !Hflag)
1.3       deraadt   483:                hflag = 1;
1.1       deraadt   484:
1.3       deraadt   485:        if (argc == 0)
                    486:                exit(!procfile(NULL));
1.5       deraadt   487:
1.3       deraadt   488:        if (Rflag)
                    489:                c = grep_tree(argv);
1.1       deraadt   490:        else
1.3       deraadt   491:                for (c = 0; argc--; ++argv)
                    492:                        c += procfile(*argv);
1.1       deraadt   493:
1.45      millert   494:        exit(c ? (file_err ? (qflag ? 0 : 2) : 0) : (file_err ? 2 : 1));
1.1       deraadt   495: }