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 $ */
6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8 * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
9 * Copyright (c) 2008-2009 Gabor Kovesdan <gabor@FreeBSD.org>
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #ifndef WITHOUT_FASTMATCH
42 #include "fastmatch.h"
46 #define getstr(n) errstr[n]
50 extern nl_catd catalog;
51 #define getstr(n) catgets(catalog, 1, n, errstr[n])
54 extern const char *errstr[];
56 #define VERSION "2.6.0-FreeBSD"
60 #define GREP_EXTENDED 2
62 #if !defined(REG_NOSPEC) && !defined(REG_LITERAL)
63 #define WITH_INTERNAL_NOSPEC
67 #define BINFILE_SKIP 1
68 #define BINFILE_TEXT 2
85 #define LINK_EXPLICIT 1
91 #define MAX_MATCHES 32
117 /* Flags passed to regcomp() and regexec() */
118 extern int cflags, eflags;
120 /* Command line flags */
121 extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
122 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
123 qflag, sflag, vflag, wflag, xflag;
124 extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
125 extern long long Aflag, Bflag;
126 extern long long mcount;
127 extern long long mlimit;
130 extern const char *color;
131 extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
133 extern bool file_err, matchall;
134 extern unsigned int dpatterns, fpatterns, patterns;
135 extern struct pat *pattern;
136 extern struct epat *dpattern, *fpattern;
137 extern regex_t *er_pattern, *r_pattern;
138 #ifndef WITHOUT_FASTMATCH
139 extern fastmatch_t *fg_pattern;
142 /* For regex errors */
143 #define RE_ERROR_BUF 512
144 extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
147 bool file_matching(const char *fname);
148 int procfile(const char *fn);
149 int grep_tree(char **argv);
150 void *grep_malloc(size_t size);
151 void *grep_calloc(size_t nmemb, size_t size);
152 void *grep_realloc(void *ptr, size_t size);
153 char *grep_strdup(const char *str);
154 void grep_printline(struct str *line, int sep);
157 bool enqueue(struct str *x);
158 void printqueue(void);
159 void clearqueue(void);
162 void grep_close(struct file *f);
163 struct file *grep_open(const char *path);
164 char *grep_fgetln(struct file *f, size_t *len);