Home | History | Annotate | Line # | Download | only in grep
grep.h revision 1.4
      1  1.4  joerg /*	$NetBSD: grep.h,v 1.4 2011/02/16 01:31:33 joerg Exp $	*/
      2  1.4  joerg /*	$OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $	*/
      3  1.4  joerg /*	$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.4  joerg  * Copyright (c) 1999 James Howard and Dag-Erling Codan Smrgrav
      7  1.4  joerg  * 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.4  joerg #include <bzlib.h>
     33  1.4  joerg #include <limits.h>
     34  1.1   cjep #include <regex.h>
     35  1.4  joerg #include <stdbool.h>
     36  1.1   cjep #include <stdio.h>
     37  1.1   cjep #include <zlib.h>
     38  1.1   cjep 
     39  1.4  joerg #ifdef WITHOUT_NLS
     40  1.4  joerg #define getstr(n)	 errstr[n]
     41  1.4  joerg #else
     42  1.4  joerg #include <nl_types.h>
     43  1.4  joerg 
     44  1.4  joerg extern nl_catd		 catalog;
     45  1.4  joerg #define getstr(n)	 catgets(catalog, 1, n, errstr[n])
     46  1.4  joerg #endif
     47  1.2   cjep 
     48  1.4  joerg extern const char		*errstr[];
     49  1.2   cjep 
     50  1.4  joerg #define VERSION		"2.5.1-FreeBSD"
     51  1.2   cjep 
     52  1.4  joerg #define GREP_FIXED	0
     53  1.4  joerg #define GREP_BASIC	1
     54  1.4  joerg #define GREP_EXTENDED	2
     55  1.1   cjep 
     56  1.4  joerg #define BINFILE_BIN	0
     57  1.4  joerg #define BINFILE_SKIP	1
     58  1.4  joerg #define BINFILE_TEXT	2
     59  1.1   cjep 
     60  1.4  joerg #define FILE_STDIO	0
     61  1.4  joerg #define FILE_GZIP	1
     62  1.4  joerg #define FILE_BZIP	2
     63  1.1   cjep 
     64  1.4  joerg #define DIR_READ	0
     65  1.4  joerg #define DIR_SKIP	1
     66  1.4  joerg #define DIR_RECURSE	2
     67  1.2   cjep 
     68  1.4  joerg #define DEV_READ	0
     69  1.4  joerg #define DEV_SKIP	1
     70  1.2   cjep 
     71  1.4  joerg #define LINK_READ	0
     72  1.4  joerg #define LINK_EXPLICIT	1
     73  1.4  joerg #define LINK_SKIP	2
     74  1.2   cjep 
     75  1.4  joerg #define EXCL_PAT	0
     76  1.4  joerg #define INCL_PAT	1
     77  1.2   cjep 
     78  1.4  joerg #define MAX_LINE_MATCHES	32
     79  1.2   cjep 
     80  1.4  joerg struct file {
     81  1.4  joerg 	int		 fd;
     82  1.4  joerg 	bool		 binary;
     83  1.4  joerg };
     84  1.4  joerg 
     85  1.4  joerg struct str {
     86  1.4  joerg 	off_t		 off;
     87  1.4  joerg 	size_t		 len;
     88  1.4  joerg 	char		*dat;
     89  1.4  joerg 	char		*file;
     90  1.4  joerg 	int		 line_no;
     91  1.4  joerg };
     92  1.4  joerg 
     93  1.4  joerg struct epat {
     94  1.4  joerg 	char		*pat;
     95  1.4  joerg 	int		 mode;
     96  1.4  joerg };
     97  1.2   cjep 
     98  1.4  joerg typedef struct {
     99  1.4  joerg 	size_t		 len;
    100  1.4  joerg 	unsigned char	*pattern;
    101  1.4  joerg 	int		 qsBc[UCHAR_MAX + 1];
    102  1.4  joerg 	/* flags */
    103  1.4  joerg 	bool		 bol;
    104  1.4  joerg 	bool		 eol;
    105  1.4  joerg 	bool		 reversed;
    106  1.4  joerg } fastgrep_t;
    107  1.2   cjep 
    108  1.4  joerg /* Flags passed to regcomp() and regexec() */
    109  1.4  joerg extern int	 cflags, eflags;
    110  1.2   cjep 
    111  1.4  joerg /* Command line flags */
    112  1.4  joerg extern bool	 Eflag, Fflag, Gflag, Hflag, Lflag,
    113  1.4  joerg 		 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
    114  1.4  joerg 		 qflag, sflag, vflag, wflag, xflag;
    115  1.4  joerg extern bool	 dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
    116  1.4  joerg extern unsigned long long Aflag, Bflag, mcount;
    117  1.4  joerg extern char	*label;
    118  1.4  joerg extern const char *color;
    119  1.4  joerg extern int	 binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
    120  1.4  joerg 
    121  1.4  joerg extern bool	 first, matchall, notfound, prev;
    122  1.4  joerg extern int	 tail;
    123  1.4  joerg extern unsigned int dpatterns, fpatterns, patterns;
    124  1.4  joerg extern char    **pattern;
    125  1.4  joerg extern struct epat *dpattern, *fpattern;
    126  1.4  joerg extern regex_t	*er_pattern, *r_pattern;
    127  1.4  joerg extern fastgrep_t *fg_pattern;
    128  1.4  joerg 
    129  1.4  joerg /* For regex errors  */
    130  1.4  joerg #define RE_ERROR_BUF	512
    131  1.4  joerg extern char	 re_error[RE_ERROR_BUF + 1];	/* Seems big enough */
    132  1.1   cjep 
    133  1.1   cjep /* util.c */
    134  1.4  joerg bool	 file_matching(const char *fname);
    135  1.4  joerg int	 procfile(const char *fn);
    136  1.4  joerg int	 grep_tree(char **argv);
    137  1.4  joerg void	*grep_malloc(size_t size);
    138  1.4  joerg void	*grep_calloc(size_t nmemb, size_t size);
    139  1.4  joerg void	*grep_realloc(void *ptr, size_t size);
    140  1.4  joerg char	*grep_strdup(const char *str);
    141  1.4  joerg void	 printline(struct str *line, int sep, regmatch_t *matches, int m);
    142  1.1   cjep 
    143  1.1   cjep /* queue.c */
    144  1.4  joerg void	 enqueue(struct str *x);
    145  1.4  joerg void	 printqueue(void);
    146  1.4  joerg void	 clearqueue(void);
    147  1.1   cjep 
    148  1.1   cjep /* file.c */
    149  1.4  joerg void		 grep_close(struct file *f);
    150  1.4  joerg struct file	*grep_open(const char *path);
    151  1.4  joerg char		*grep_fgetln(struct file *f, size_t *len);
    152  1.4  joerg 
    153  1.4  joerg /* fastgrep.c */
    154  1.4  joerg int		 fastcomp(fastgrep_t *, const char *);
    155  1.4  joerg void		 fgrepcomp(fastgrep_t *, const char *);
    156  1.4  joerg int		 grep_search(fastgrep_t *, const unsigned char *, size_t, regmatch_t *);
    157