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