grep.h revision 1.1 1 1.1 cjep /*-
2 1.1 cjep * Copyright (c) 1999 James Howard and Dag-Erling Codan Smrgrav
3 1.1 cjep * All rights reserved.
4 1.1 cjep *
5 1.1 cjep * Redistribution and use in source and binary forms, with or without
6 1.1 cjep * modification, are permitted provided that the following conditions
7 1.1 cjep * are met:
8 1.1 cjep * 1. Redistributions of source code must retain the above copyright
9 1.1 cjep * notice, this list of conditions and the following disclaimer.
10 1.1 cjep * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cjep * notice, this list of conditions and the following disclaimer in the
12 1.1 cjep * documentation and/or other materials provided with the distribution.
13 1.1 cjep *
14 1.1 cjep * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 1.1 cjep * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 1.1 cjep * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 1.1 cjep * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 1.1 cjep * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 1.1 cjep * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 1.1 cjep * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 1.1 cjep * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 1.1 cjep * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 1.1 cjep * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 1.1 cjep * SUCH DAMAGE.
25 1.1 cjep */
26 1.1 cjep
27 1.1 cjep #include <sys/types.h>
28 1.1 cjep
29 1.1 cjep #include <regex.h>
30 1.1 cjep #include <stdio.h>
31 1.1 cjep #include <zlib.h>
32 1.1 cjep
33 1.1 cjep #define VER_MAJ 0
34 1.1 cjep #define VER_MIN 9
35 1.1 cjep
36 1.1 cjep typedef struct {
37 1.1 cjep size_t len;
38 1.1 cjep int line_no;
39 1.1 cjep int off;
40 1.1 cjep char *file;
41 1.1 cjep char *dat;
42 1.1 cjep } str_t;
43 1.1 cjep
44 1.1 cjep /* Flags passed to regcomp() and regexec() */
45 1.1 cjep extern int cflags, eflags;
46 1.1 cjep
47 1.1 cjep /* Command line flags */
48 1.1 cjep extern int Aflag, Bflag, Hflag, Lflag, Pflag, Sflag, Rflag, Zflag,
49 1.1 cjep aflag, bflag, cflag, hflag, lflag, nflag, qflag, sflag,
50 1.1 cjep vflag, wflag, xflag;
51 1.1 cjep
52 1.1 cjep extern int first, lead, matchall, patterns, tail;
53 1.1 cjep extern char **pattern;
54 1.1 cjep extern regex_t *r_pattern;
55 1.1 cjep
56 1.1 cjep /* For regex errors */
57 1.1 cjep #define RE_ERROR_BUF 512
58 1.1 cjep extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
59 1.1 cjep
60 1.1 cjep /* util.c */
61 1.1 cjep int procfile(char *fn);
62 1.1 cjep int grep_tree(char **argv);
63 1.1 cjep void *grep_malloc(size_t size);
64 1.1 cjep void *grep_realloc(void *ptr, size_t size);
65 1.1 cjep void printline(str_t *line, int sep);
66 1.1 cjep
67 1.1 cjep /* queue.c */
68 1.1 cjep void initqueue();
69 1.1 cjep void enqueue(str_t *x);
70 1.1 cjep void printqueue();
71 1.1 cjep void clearqueue();
72 1.1 cjep
73 1.1 cjep /* mmfile.c */
74 1.1 cjep typedef struct mmfile {
75 1.1 cjep int fd;
76 1.1 cjep size_t len;
77 1.1 cjep char *base, *end, *ptr;
78 1.1 cjep } mmf_t;
79 1.1 cjep
80 1.1 cjep mmf_t *mmopen(char *fn, char *mode);
81 1.1 cjep void mmclose(mmf_t *mmf);
82 1.1 cjep char *mmfgetln(mmf_t *mmf, size_t *l);
83 1.1 cjep long mmtell(mmf_t *mmf);
84 1.1 cjep void mmrewind(mmf_t *mmf);
85 1.1 cjep
86 1.1 cjep /* file.c */
87 1.1 cjep struct file;
88 1.1 cjep typedef struct file file_t;
89 1.1 cjep
90 1.1 cjep file_t *grep_fdopen(int fd, char *mode);
91 1.1 cjep file_t *grep_open(char *path, char *mode);
92 1.1 cjep int grep_bin_file(file_t *f);
93 1.1 cjep long grep_tell(file_t *f);
94 1.1 cjep char *grep_fgetln(file_t *f, size_t *l);
95 1.1 cjep void grep_close(file_t *f);
96 1.1 cjep
97 1.1 cjep /* binary.c */
98 1.1 cjep int bin_file(FILE * f);
99 1.1 cjep int gzbin_file(gzFile * f);
100 1.1 cjep int mmbin_file(mmf_t *f);
101 1.1 cjep
102