grep.h revision 1.2 1 1.2 cjep /* $NetBSD: grep.h,v 1.2 2004/05/05 15:06:33 cjep Exp $ */
2 1.2 cjep
3 1.1 cjep /*-
4 1.1 cjep * Copyright (c) 1999 James Howard and Dag-Erling Codan Smrgrav
5 1.1 cjep * All rights reserved.
6 1.1 cjep *
7 1.1 cjep * Redistribution and use in source and binary forms, with or without
8 1.1 cjep * modification, are permitted provided that the following conditions
9 1.1 cjep * are met:
10 1.1 cjep * 1. Redistributions of source code must retain the above copyright
11 1.1 cjep * notice, this list of conditions and the following disclaimer.
12 1.1 cjep * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cjep * notice, this list of conditions and the following disclaimer in the
14 1.1 cjep * documentation and/or other materials provided with the distribution.
15 1.1 cjep *
16 1.1 cjep * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 1.1 cjep * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 cjep * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 cjep * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 1.1 cjep * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 1.1 cjep * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 1.1 cjep * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 cjep * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 1.1 cjep * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 cjep * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 cjep * SUCH DAMAGE.
27 1.1 cjep */
28 1.1 cjep
29 1.1 cjep #include <sys/types.h>
30 1.1 cjep
31 1.1 cjep #include <regex.h>
32 1.1 cjep #include <stdio.h>
33 1.1 cjep #include <zlib.h>
34 1.1 cjep
35 1.2 cjep #define VERSION "20040505"
36 1.2 cjep
37 1.2 cjep #define GREP_READ 0
38 1.2 cjep #define GREP_SKIP 1
39 1.2 cjep #define GREP_RECURSE 2
40 1.2 cjep
41 1.2 cjep #define BIN_FILE_BIN 0
42 1.2 cjep #define BIN_FILE_SKIP 1
43 1.2 cjep #define BIN_FILE_TEXT 2
44 1.2 cjep
45 1.2 cjep #define LINK_EXPLICIT 0
46 1.2 cjep #define LINK_FOLLOW 1
47 1.2 cjep #define LINK_SKIP 2
48 1.2 cjep
49 1.2 cjep #define MAX_LINE_MATCHES 30
50 1.1 cjep
51 1.1 cjep typedef struct {
52 1.2 cjep size_t len;
53 1.2 cjep int line_no;
54 1.2 cjep int off;
55 1.2 cjep char *file;
56 1.2 cjep char *dat;
57 1.1 cjep } str_t;
58 1.1 cjep
59 1.1 cjep /* Flags passed to regcomp() and regexec() */
60 1.2 cjep extern int cflags, eflags;
61 1.1 cjep
62 1.1 cjep /* Command line flags */
63 1.2 cjep extern int Aflag, Bflag, Fflag, Lflag, bflag, cflag, lflag, mflag,
64 1.2 cjep nflag, oflag, qflag, sflag, vflag, wflag, xflag;
65 1.2 cjep
66 1.2 cjep extern int colours;
67 1.2 cjep extern const char *grep_colour;
68 1.2 cjep extern char fn_endchar, fn_colonchar, fn_dashchar;
69 1.2 cjep extern char line_endchar;
70 1.2 cjep
71 1.2 cjep extern int output_filenames;
72 1.2 cjep
73 1.2 cjep extern int maxcount;
74 1.2 cjep
75 1.2 cjep /* Argv[0] flags */
76 1.2 cjep extern int zgrep;
77 1.2 cjep
78 1.2 cjep extern int binbehave, dirbehave, devbehave;
79 1.2 cjep /* extern int linkbehave; */
80 1.2 cjep extern char *stdin_label;
81 1.2 cjep
82 1.2 cjep extern int first, matchall, patterns, tail;
83 1.2 cjep extern char **pattern;
84 1.2 cjep extern regex_t *r_pattern;
85 1.2 cjep
86 1.2 cjep /*
87 1.2 cjep * For regex errors, 512 seems to be big enough
88 1.2 cjep */
89 1.2 cjep #define RE_ERROR_BUF 512
90 1.2 cjep
91 1.2 cjep extern char re_error[RE_ERROR_BUF + 1];
92 1.1 cjep
93 1.1 cjep /* util.c */
94 1.2 cjep int procfile(char *fn);
95 1.2 cjep int grep_tree(char **argv);
96 1.2 cjep
97 1.2 cjep void *grep_malloc(size_t size);
98 1.2 cjep void *grep_realloc(void *ptr, size_t size);
99 1.2 cjep void printline(str_t *line, int sep, regmatch_t *matches, int m);
100 1.1 cjep
101 1.1 cjep /* queue.c */
102 1.2 cjep void initqueue(void);
103 1.2 cjep void enqueue(str_t *x);
104 1.2 cjep void printqueue(void);
105 1.2 cjep void clearqueue(void);
106 1.1 cjep
107 1.1 cjep /* mmfile.c */
108 1.1 cjep typedef struct mmfile {
109 1.2 cjep int fd;
110 1.2 cjep size_t len;
111 1.2 cjep char *base, *end, *ptr;
112 1.1 cjep } mmf_t;
113 1.1 cjep
114 1.2 cjep mmf_t *mmopen(char *fn, char *mode);
115 1.2 cjep void mmclose(mmf_t *mmf);
116 1.2 cjep char *mmfgetln(mmf_t *mmf, size_t *l);
117 1.2 cjep void mmrewind(mmf_t *mmf);
118 1.1 cjep
119 1.1 cjep /* file.c */
120 1.1 cjep struct file;
121 1.1 cjep typedef struct file file_t;
122 1.1 cjep
123 1.2 cjep file_t *grep_fdopen(int fd, char *mode);
124 1.2 cjep file_t *grep_open(char *path, char *mode);
125 1.2 cjep
126 1.2 cjep int grep_bin_file(file_t *f);
127 1.2 cjep char *grep_fgetln(file_t *f, size_t *l);
128 1.2 cjep void grep_close(file_t *f);
129 1.1 cjep
130 1.1 cjep /* binary.c */
131 1.2 cjep int bin_file(FILE * f);
132 1.2 cjep int gzbin_file(gzFile * f);
133 1.2 cjep int mmbin_file(mmf_t *f);
134 1.1 cjep
135