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 $ */
5 * SPDX-License-Identifier: BSD-2-Clause
7 * Copyright (c) 1999 James Howard and Dag-Erling Smørgrav
8 * Copyright (c) 2008-2009 Gabor Kovesdan <gabor@FreeBSD.org>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 extern const char *errstr[];
42 #define VERSION "2.6.0-FreeBSD"
46 #define GREP_EXTENDED 2
48 #if !defined(REG_NOSPEC) && !defined(REG_LITERAL)
49 #define WITH_INTERNAL_NOSPEC
53 #define BINFILE_SKIP 1
54 #define BINFILE_TEXT 2
67 #define LINK_EXPLICIT 1
73 #define MAX_MATCHES 32
100 * Parsing context; used to hold things like matches made and
104 regmatch_t matches[MAX_MATCHES]; /* Matches made */
105 /* XXX TODO: This should be a chunk, not a line */
106 struct str ln; /* Current line */
107 size_t lnstart; /* Position in line */
108 size_t matchidx; /* Latest match index */
109 int printed; /* Metadata printed? */
110 bool binary; /* Binary file? */
111 bool cntlines; /* Count lines? */
114 /* Flags passed to regcomp() and regexec() */
115 extern int cflags, eflags;
117 /* Command line flags */
118 extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
119 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
120 qflag, sflag, vflag, wflag, xflag;
121 extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
122 extern long long Aflag, Bflag;
123 extern long long mcount;
124 extern long long mlimit;
127 extern const char *color;
128 extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
130 extern bool file_err, matchall;
131 extern unsigned int dpatterns, fpatterns, patterns;
132 extern struct pat *pattern;
133 extern struct epat *dpattern, *fpattern;
134 extern regex_t *er_pattern, *r_pattern;
136 /* For regex errors */
137 #define RE_ERROR_BUF 512
138 extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
141 bool file_matching(const char *fname);
142 bool procfile(const char *fn);
143 bool grep_tree(char **argv);
144 void *grep_malloc(size_t size);
145 void *grep_calloc(size_t nmemb, size_t size);
146 void *grep_realloc(void *ptr, size_t size);
147 char *grep_strdup(const char *str);
148 void grep_printline(struct str *line, int sep);
151 void initqueue(void);
152 bool enqueue(struct str *x);
153 void printqueue(void);
154 void clearqueue(void);
157 void grep_close(struct file *f);
158 struct file *grep_open(const char *path);
159 char *grep_fgetln(struct file *f, struct parsec *pc);