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