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