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

1.3     ! tedu        1: /*     $OpenBSD: grep.h,v 1.2 2003/06/22 22:38:50 deraadt 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:
                     31: #include <regex.h>
                     32: #include <stdio.h>
                     33: #include <zlib.h>
                     34:
                     35: #define VER_MAJ 0
                     36: #define VER_MIN 9
                     37:
1.3     ! tedu       38: #define BIN_FILE_BIN   0
        !            39: #define BIN_FILE_SKIP  1
        !            40: #define BIN_FILE_TEXT  2
        !            41:
1.1       deraadt    42: typedef struct {
                     43:        size_t           len;
                     44:        int              line_no;
                     45:        int              off;
                     46:        char            *file;
                     47:        char            *dat;
                     48: } str_t;
                     49:
                     50: /* Flags passed to regcomp() and regexec() */
                     51: extern int      cflags, eflags;
                     52:
                     53: /* Command line flags */
                     54: extern int      Aflag, Bflag, Hflag, Lflag, Pflag, Sflag, Rflag, Zflag,
1.3     ! tedu       55:                 bflag, cflag, hflag, lflag, nflag, qflag, sflag,
1.1       deraadt    56:                 vflag, wflag, xflag;
1.3     ! tedu       57: extern int      binbehave;
1.1       deraadt    58:
                     59: extern int      first, lead, matchall, patterns, tail;
                     60: extern char    **pattern;
                     61: extern regex_t *r_pattern;
                     62:
                     63: /* For regex errors  */
                     64: #define RE_ERROR_BUF 512
                     65: extern char     re_error[RE_ERROR_BUF + 1];    /* Seems big enough */
                     66:
                     67: /* util.c */
                     68: int             procfile(char *fn);
                     69: int             grep_tree(char **argv);
                     70: void           *grep_malloc(size_t size);
                     71: void           *grep_realloc(void *ptr, size_t size);
                     72: void            printline(str_t *line, int sep);
                     73:
                     74: /* queue.c */
                     75: void            initqueue();
                     76: void            enqueue(str_t *x);
                     77: void            printqueue();
                     78: void            clearqueue();
                     79:
                     80: /* mmfile.c */
                     81: typedef struct mmfile {
                     82:        int      fd;
                     83:        size_t   len;
                     84:        char    *base, *end, *ptr;
                     85: } mmf_t;
                     86:
                     87: mmf_t          *mmopen(char *fn, char *mode);
                     88: void            mmclose(mmf_t *mmf);
                     89: char           *mmfgetln(mmf_t *mmf, size_t *l);
                     90: long            mmtell(mmf_t *mmf);
                     91: void            mmrewind(mmf_t *mmf);
                     92:
                     93: /* file.c */
                     94: struct file;
                     95: typedef struct file file_t;
                     96:
                     97: file_t         *grep_fdopen(int fd, char *mode);
                     98: file_t         *grep_open(char *path, char *mode);
                     99: int             grep_bin_file(file_t *f);
                    100: long            grep_tell(file_t *f);
                    101: char           *grep_fgetln(file_t *f, size_t *l);
                    102: void            grep_close(file_t *f);
                    103:
                    104: /* binary.c */
                    105: int             bin_file(FILE * f);
                    106: int             gzbin_file(gzFile * f);
                    107: int             mmbin_file(mmf_t *f);
                    108: