Deleted Added
full compact
grep.h (211364) grep.h (211463)
1/* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */
1/* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */
2/* $FreeBSD: head/usr.bin/grep/grep.h 211364 2010-08-15 22:15:04Z gabor $ */
2/* $FreeBSD: head/usr.bin/grep/grep.h 211463 2010-08-18 17:40:10Z 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 {
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 struct mmfile *mmf;
81 BZFILE *bzf;
82 FILE *f;
83 gzFile *gzf;
80 int fd;
84 bool binary;
81 bool binary;
85 bool stdin;
86};
87
88struct str {
89 off_t off;
90 size_t len;
91 char *dat;
92 char *file;
93 int line_no;
94};
95
96struct epat {
97 char *pat;
98 int mode;
99};
100
101typedef struct {
102 size_t len;
103 unsigned char *pattern;
104 int qsBc[UCHAR_MAX + 1];
105 /* flags */
106 bool bol;
107 bool eol;
108 bool reversed;
109} fastgrep_t;
110
111/* Flags passed to regcomp() and regexec() */
112extern int cflags, eflags;
113
114/* Command line flags */
115extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
116 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
117 qflag, sflag, vflag, wflag, xflag;
118extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
119extern unsigned long long Aflag, Bflag, mcount;
120extern char *label;
121extern const char *color;
122extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
123
124extern bool first, matchall, notfound, prev;
125extern int tail;
126extern unsigned int dpatterns, fpatterns, patterns;
127extern char **pattern;
128extern struct epat *dpattern, *fpattern;
129extern regex_t *er_pattern, *r_pattern;
130extern fastgrep_t *fg_pattern;
131
132/* For regex errors */
133#define RE_ERROR_BUF 512
134extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
135
136/* util.c */
137bool file_matching(const char *fname);
138int procfile(const char *fn);
139int grep_tree(char **argv);
140void *grep_malloc(size_t size);
141void *grep_calloc(size_t nmemb, size_t size);
142void *grep_realloc(void *ptr, size_t size);
143char *grep_strdup(const char *str);
144void printline(struct str *line, int sep, regmatch_t *matches, int m);
145
146/* queue.c */
147void enqueue(struct str *x);
148void printqueue(void);
149void clearqueue(void);
150
151/* file.c */
152void grep_close(struct file *f);
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} fastgrep_t;
106
107/* Flags passed to regcomp() and regexec() */
108extern int cflags, eflags;
109
110/* Command line flags */
111extern bool Eflag, Fflag, Gflag, Hflag, Lflag,
112 bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag,
113 qflag, sflag, vflag, wflag, xflag;
114extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag;
115extern unsigned long long Aflag, Bflag, mcount;
116extern char *label;
117extern const char *color;
118extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave;
119
120extern bool first, matchall, notfound, prev;
121extern int tail;
122extern unsigned int dpatterns, fpatterns, patterns;
123extern char **pattern;
124extern struct epat *dpattern, *fpattern;
125extern regex_t *er_pattern, *r_pattern;
126extern fastgrep_t *fg_pattern;
127
128/* For regex errors */
129#define RE_ERROR_BUF 512
130extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
131
132/* util.c */
133bool file_matching(const char *fname);
134int procfile(const char *fn);
135int grep_tree(char **argv);
136void *grep_malloc(size_t size);
137void *grep_calloc(size_t nmemb, size_t size);
138void *grep_realloc(void *ptr, size_t size);
139char *grep_strdup(const char *str);
140void printline(struct str *line, int sep, regmatch_t *matches, int m);
141
142/* queue.c */
143void enqueue(struct str *x);
144void printqueue(void);
145void clearqueue(void);
146
147/* file.c */
148void grep_close(struct file *f);
153struct file *grep_stdin_open(void);
154struct file *grep_open(const char *path);
155char *grep_fgetln(struct file *f, size_t *len);
156
157/* fastgrep.c */
158int fastcomp(fastgrep_t *, const char *);
159void fgrepcomp(fastgrep_t *, const char *);
149struct file *grep_open(const char *path);
150char *grep_fgetln(struct file *f, size_t *len);
151
152/* fastgrep.c */
153int fastcomp(fastgrep_t *, const char *);
154void fgrepcomp(fastgrep_t *, const char *);
160int grep_search(fastgrep_t *, unsigned char *, size_t, regmatch_t *);
155int grep_search(fastgrep_t *, const unsigned char *, size_t, regmatch_t *);