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