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 * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
7 * Copyright (c) 2008-2009 Gabor Kovesdan <gabor@FreeBSD.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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
39 #ifndef WITHOUT_FASTMATCH
40 #include "fastmatch.h"
44 #define getstr(n) errstr[n]
48 extern nl_catd catalog;
49 #define getstr(n) catgets(catalog, 1, n, errstr[n])
52 extern const char *errstr[];
54 #define VERSION "2.6.0-FreeBSD"
58 #define GREP_EXTENDED 2
61 #define BINFILE_SKIP 1
62 #define BINFILE_TEXT 2
79 #define LINK_EXPLICIT 1
85 #define MAX_MATCHES 32
111 /* Flags passed to regcomp() and regexec() */
112 extern int cflags, eflags;
114 /* Command line flags */
115 extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
116 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
117 qflag, sflag, vflag, wflag, xflag;
118 extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
119 extern long long Aflag, Bflag;
120 extern long long mcount;
121 extern long long mlimit;
124 extern const char *color;
125 extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
127 extern bool file_err, matchall;
128 extern unsigned int dpatterns, fpatterns, patterns;
129 extern struct pat *pattern;
130 extern struct epat *dpattern, *fpattern;
131 extern regex_t *er_pattern, *r_pattern;
132 #ifndef WITHOUT_FASTMATCH
133 extern fastmatch_t *fg_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 int procfile(const char *fn);
143 int 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 bool enqueue(struct str *x);
152 void printqueue(void);
153 void clearqueue(void);
156 void grep_close(struct file *f);
157 struct file *grep_open(const char *path);
158 char *grep_fgetln(struct file *f, size_t *len);