Home | History | Annotate | Line # | Download | only in grep
grep.h revision 1.3.40.2
      1  1.3.40.2  bouyer /*	$NetBSD: grep.h,v 1.3.40.2 2011/03/05 15:10:59 bouyer Exp $	*/
      2  1.3.40.1  bouyer /*	$OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $	*/
      3  1.3.40.1  bouyer /*	$FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $	*/
      4       1.2    cjep 
      5       1.1    cjep /*-
      6  1.3.40.1  bouyer  * Copyright (c) 1999 James Howard and Dag-Erling Codan Smrgrav
      7  1.3.40.1  bouyer  * Copyright (c) 2008-2009 Gabor Kovesdan <gabor (at) FreeBSD.org>
      8       1.1    cjep  * All rights reserved.
      9       1.1    cjep  *
     10       1.1    cjep  * Redistribution and use in source and binary forms, with or without
     11       1.1    cjep  * modification, are permitted provided that the following conditions
     12       1.1    cjep  * are met:
     13       1.1    cjep  * 1. Redistributions of source code must retain the above copyright
     14       1.1    cjep  *    notice, this list of conditions and the following disclaimer.
     15       1.1    cjep  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1    cjep  *    notice, this list of conditions and the following disclaimer in the
     17       1.1    cjep  *    documentation and/or other materials provided with the distribution.
     18       1.1    cjep  *
     19       1.1    cjep  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     20       1.1    cjep  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21       1.1    cjep  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22       1.1    cjep  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23       1.1    cjep  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24       1.1    cjep  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25       1.1    cjep  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26       1.1    cjep  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27       1.1    cjep  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28       1.1    cjep  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29       1.1    cjep  * SUCH DAMAGE.
     30       1.1    cjep  */
     31       1.1    cjep 
     32  1.3.40.1  bouyer #include <bzlib.h>
     33  1.3.40.1  bouyer #include <limits.h>
     34       1.1    cjep #include <regex.h>
     35  1.3.40.1  bouyer #include <stdbool.h>
     36       1.1    cjep #include <stdio.h>
     37       1.1    cjep #include <zlib.h>
     38       1.1    cjep 
     39  1.3.40.1  bouyer #ifdef WITHOUT_NLS
     40  1.3.40.1  bouyer #define getstr(n)	 errstr[n]
     41  1.3.40.1  bouyer #else
     42  1.3.40.1  bouyer #include <nl_types.h>
     43       1.2    cjep 
     44  1.3.40.1  bouyer extern nl_catd		 catalog;
     45  1.3.40.1  bouyer #define getstr(n)	 catgets(catalog, 1, n, errstr[n])
     46  1.3.40.1  bouyer #endif
     47       1.2    cjep 
     48  1.3.40.1  bouyer extern const char		*errstr[];
     49       1.2    cjep 
     50  1.3.40.1  bouyer #define VERSION		"2.5.1-FreeBSD"
     51       1.1    cjep 
     52  1.3.40.1  bouyer #define GREP_FIXED	0
     53  1.3.40.1  bouyer #define GREP_BASIC	1
     54  1.3.40.1  bouyer #define GREP_EXTENDED	2
     55       1.1    cjep 
     56  1.3.40.1  bouyer #define BINFILE_BIN	0
     57  1.3.40.1  bouyer #define BINFILE_SKIP	1
     58  1.3.40.1  bouyer #define BINFILE_TEXT	2
     59       1.1    cjep 
     60  1.3.40.1  bouyer #define FILE_STDIO	0
     61  1.3.40.1  bouyer #define FILE_GZIP	1
     62  1.3.40.1  bouyer #define FILE_BZIP	2
     63       1.2    cjep 
     64  1.3.40.1  bouyer #define DIR_READ	0
     65  1.3.40.1  bouyer #define DIR_SKIP	1
     66  1.3.40.1  bouyer #define DIR_RECURSE	2
     67       1.2    cjep 
     68  1.3.40.1  bouyer #define DEV_READ	0
     69  1.3.40.1  bouyer #define DEV_SKIP	1
     70       1.2    cjep 
     71  1.3.40.1  bouyer #define LINK_READ	0
     72  1.3.40.1  bouyer #define LINK_EXPLICIT	1
     73  1.3.40.1  bouyer #define LINK_SKIP	2
     74       1.2    cjep 
     75  1.3.40.1  bouyer #define EXCL_PAT	0
     76  1.3.40.1  bouyer #define INCL_PAT	1
     77       1.2    cjep 
     78  1.3.40.1  bouyer #define MAX_LINE_MATCHES	32
     79       1.2    cjep 
     80  1.3.40.1  bouyer struct file {
     81  1.3.40.1  bouyer 	int		 fd;
     82  1.3.40.1  bouyer 	bool		 binary;
     83  1.3.40.1  bouyer };
     84  1.3.40.1  bouyer 
     85  1.3.40.1  bouyer struct str {
     86  1.3.40.1  bouyer 	off_t		 off;
     87  1.3.40.1  bouyer 	size_t		 len;
     88  1.3.40.1  bouyer 	char		*dat;
     89  1.3.40.1  bouyer 	char		*file;
     90  1.3.40.1  bouyer 	int		 line_no;
     91  1.3.40.1  bouyer };
     92  1.3.40.1  bouyer 
     93  1.3.40.1  bouyer struct epat {
     94  1.3.40.1  bouyer 	char		*pat;
     95  1.3.40.1  bouyer 	int		 mode;
     96  1.3.40.1  bouyer };
     97       1.2    cjep 
     98  1.3.40.1  bouyer typedef struct {
     99  1.3.40.1  bouyer 	size_t		 len;
    100  1.3.40.1  bouyer 	unsigned char	*pattern;
    101  1.3.40.1  bouyer 	int		 qsBc[UCHAR_MAX + 1];
    102  1.3.40.1  bouyer 	/* flags */
    103  1.3.40.1  bouyer 	bool		 bol;
    104  1.3.40.1  bouyer 	bool		 eol;
    105  1.3.40.1  bouyer 	bool		 reversed;
    106  1.3.40.2  bouyer 	bool		 word;
    107  1.3.40.1  bouyer } fastgrep_t;
    108       1.2    cjep 
    109  1.3.40.1  bouyer /* Flags passed to regcomp() and regexec() */
    110  1.3.40.1  bouyer extern int	 cflags, eflags;
    111       1.1    cjep 
    112  1.3.40.1  bouyer /* Command line flags */
    113  1.3.40.1  bouyer extern bool	 Eflag, Fflag, Gflag, Hflag, Lflag,
    114  1.3.40.1  bouyer 		 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
    115  1.3.40.1  bouyer 		 qflag, sflag, vflag, wflag, xflag;
    116  1.3.40.1  bouyer extern bool	 dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
    117  1.3.40.1  bouyer extern unsigned long long Aflag, Bflag, mcount;
    118  1.3.40.1  bouyer extern char	*label;
    119  1.3.40.1  bouyer extern const char *color;
    120  1.3.40.1  bouyer extern int	 binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
    121  1.3.40.1  bouyer 
    122  1.3.40.1  bouyer extern bool	 first, matchall, notfound, prev;
    123  1.3.40.1  bouyer extern int	 tail;
    124  1.3.40.1  bouyer extern unsigned int dpatterns, fpatterns, patterns;
    125  1.3.40.1  bouyer extern char    **pattern;
    126  1.3.40.1  bouyer extern struct epat *dpattern, *fpattern;
    127  1.3.40.1  bouyer extern regex_t	*er_pattern, *r_pattern;
    128  1.3.40.1  bouyer extern fastgrep_t *fg_pattern;
    129  1.3.40.1  bouyer 
    130  1.3.40.1  bouyer /* For regex errors  */
    131  1.3.40.1  bouyer #define RE_ERROR_BUF	512
    132  1.3.40.1  bouyer extern char	 re_error[RE_ERROR_BUF + 1];	/* Seems big enough */
    133       1.2    cjep 
    134  1.3.40.1  bouyer /* util.c */
    135  1.3.40.1  bouyer bool	 file_matching(const char *fname);
    136  1.3.40.1  bouyer int	 procfile(const char *fn);
    137  1.3.40.1  bouyer int	 grep_tree(char **argv);
    138  1.3.40.1  bouyer void	*grep_malloc(size_t size);
    139  1.3.40.1  bouyer void	*grep_calloc(size_t nmemb, size_t size);
    140  1.3.40.1  bouyer void	*grep_realloc(void *ptr, size_t size);
    141  1.3.40.1  bouyer char	*grep_strdup(const char *str);
    142  1.3.40.1  bouyer void	 printline(struct str *line, int sep, regmatch_t *matches, int m);
    143       1.1    cjep 
    144       1.1    cjep /* queue.c */
    145  1.3.40.1  bouyer void	 enqueue(struct str *x);
    146  1.3.40.1  bouyer void	 printqueue(void);
    147  1.3.40.1  bouyer void	 clearqueue(void);
    148       1.1    cjep 
    149       1.1    cjep /* file.c */
    150  1.3.40.1  bouyer void		 grep_close(struct file *f);
    151  1.3.40.1  bouyer struct file	*grep_open(const char *path);
    152  1.3.40.1  bouyer char		*grep_fgetln(struct file *f, size_t *len);
    153  1.3.40.1  bouyer 
    154  1.3.40.1  bouyer /* fastgrep.c */
    155  1.3.40.1  bouyer int		 fastcomp(fastgrep_t *, const char *);
    156  1.3.40.1  bouyer void		 fgrepcomp(fastgrep_t *, const char *);
    157  1.3.40.1  bouyer int		 grep_search(fastgrep_t *, const unsigned char *, size_t, regmatch_t *);
    158