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

Annotation of src/usr.bin/grep/grep.h, Revision 1.22

1.22    ! millert     1: /*     $OpenBSD: grep.h,v 1.21 2015/01/10 13:48:02 tedu Exp $  */
1.2       deraadt     2:
1.1       deraadt     3: /*-
                      4:  * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
                      5:  * All rights reserved.
                      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:
                     29: #include <sys/types.h>
                     30:
1.22    ! millert    31: #include <limits.h>
1.1       deraadt    32: #include <regex.h>
1.22    ! millert    33: #include <stdint.h>
1.1       deraadt    34: #include <stdio.h>
                     35: #include <zlib.h>
                     36:
                     37: #define VER_MAJ 0
                     38: #define VER_MIN 9
                     39:
1.3       tedu       40: #define BIN_FILE_BIN   0
                     41: #define BIN_FILE_SKIP  1
                     42: #define BIN_FILE_TEXT  2
                     43:
1.1       deraadt    44: typedef struct {
                     45:        size_t           len;
                     46:        int              line_no;
1.9       otto       47:        off_t            off;
1.1       deraadt    48:        char            *file;
                     49:        char            *dat;
                     50: } str_t;
                     51:
1.4       tedu       52: typedef struct {
                     53:        unsigned char   *pattern;
                     54:        int              patternLen;
                     55:        int              qsBc[UCHAR_MAX + 1];
                     56:        /* flags */
                     57:        int              bol;
                     58:        int              eol;
1.10      millert    59:        int              wmatch;
1.4       tedu       60:        int              reversedSearch;
                     61: } fastgrep_t;
                     62:
1.1       deraadt    63: /* Flags passed to regcomp() and regexec() */
                     64: extern int      cflags, eflags;
                     65:
                     66: /* Command line flags */
1.21      tedu       67: extern int      Aflag, Bflag, Eflag, Fflag, Hflag, Lflag,
1.15      tedu       68:                 Rflag, Zflag,
1.17      tedu       69:                 bflag, cflag, hflag, iflag, lflag, nflag, oflag, qflag, sflag,
1.1       deraadt    70:                 vflag, wflag, xflag;
1.12      otto       71: extern int      binbehave;
1.1       deraadt    72:
1.18      millert    73: extern int      first, matchall, patterns, tail, file_err;
1.1       deraadt    74: extern char    **pattern;
1.4       tedu       75: extern fastgrep_t *fg_pattern;
1.1       deraadt    76: extern regex_t *r_pattern;
                     77:
                     78: /* For regex errors  */
                     79: #define RE_ERROR_BUF 512
                     80: extern char     re_error[RE_ERROR_BUF + 1];    /* Seems big enough */
                     81:
                     82: /* util.c */
                     83: int             procfile(char *fn);
                     84: int             grep_tree(char **argv);
                     85: void           *grep_malloc(size_t size);
1.14      deraadt    86: void           *grep_calloc(size_t nmemb, size_t size);
1.1       deraadt    87: void           *grep_realloc(void *ptr, size_t size);
1.20      deraadt    88: void           *grep_reallocarray(void *ptr, size_t nmemb, size_t size);
1.17      tedu       89: void            printline(str_t *line, int sep, regmatch_t *pmatch);
1.4       tedu       90: int             fastcomp(fastgrep_t *, const char *);
1.19      deraadt    91: void            fgrepcomp(fastgrep_t *, const unsigned char *);
1.1       deraadt    92:
                     93: /* queue.c */
1.6       millert    94: void            initqueue(void);
1.1       deraadt    95: void            enqueue(str_t *x);
1.6       millert    96: void            printqueue(void);
                     97: void            clearqueue(void);
1.1       deraadt    98:
                     99: /* mmfile.c */
                    100: typedef struct mmfile {
                    101:        int      fd;
                    102:        size_t   len;
                    103:        char    *base, *end, *ptr;
                    104: } mmf_t;
                    105:
                    106: mmf_t          *mmopen(char *fn, char *mode);
                    107: void            mmclose(mmf_t *mmf);
                    108: char           *mmfgetln(mmf_t *mmf, size_t *l);
                    109:
                    110: /* file.c */
                    111: struct file;
                    112: typedef struct file file_t;
                    113:
                    114: file_t         *grep_fdopen(int fd, char *mode);
                    115: file_t         *grep_open(char *path, char *mode);
                    116: int             grep_bin_file(file_t *f);
                    117: char           *grep_fgetln(file_t *f, size_t *l);
                    118: void            grep_close(file_t *f);
                    119:
                    120: /* binary.c */
                    121: int             bin_file(FILE * f);
                    122: int             gzbin_file(gzFile * f);
                    123: int             mmbin_file(mmf_t *f);
                    124: