vm: restore stacktrace on SIGSEGV
[minix.git] / commands / grep / grep.h
blobbfbca2329e797f032b961a7f34f08fc7bce50510
1 /* $OpenBSD: grep.h,v 1.13 2006/02/09 09:54:47 otto Exp $ */
3 /*-
4 * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
5 * All rights reserved.
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.
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.
29 #include <sys/types.h>
31 #include <limits.h>
32 #include <regex.h>
33 #include <stdio.h>
35 #ifndef NOZ
36 #include <zlib.h>
37 #endif
39 #define VER_MAJ 1
40 #define VER_MIN 2
42 #define BIN_FILE_BIN 0
43 #define BIN_FILE_SKIP 1
44 #define BIN_FILE_TEXT 2
46 typedef struct {
47 size_t len;
48 int line_no;
49 off_t off;
50 char *file;
51 char *dat;
52 } str_t;
54 typedef struct {
55 unsigned char *pattern;
56 int patternLen;
57 int qsBc[UCHAR_MAX + 1];
58 /* flags */
59 int bol;
60 int eol;
61 int wmatch;
62 int reversedSearch;
63 } fastgrep_t;
65 /* Flags passed to regcomp() and regexec() */
66 extern int cflags, eflags;
68 /* Command line flags */
69 extern int Aflag, Bflag, Eflag, Fflag, Gflag, Hflag, Lflag, Pflag,
70 Sflag, Rflag, Zflag,
71 bflag, cflag, hflag, iflag, lflag, nflag, qflag, sflag,
72 vflag, wflag, xflag;
73 extern int binbehave;
75 extern int first, matchall, patterns, tail;
76 extern char **pattern;
77 extern fastgrep_t *fg_pattern;
78 extern regex_t *r_pattern;
80 /* For regex errors */
81 #define RE_ERROR_BUF 512
82 extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
84 /* util.c */
85 int procfile(char *fn);
86 int grep_tree(char **argv);
87 void *grep_malloc(size_t size);
88 void *grep_calloc(size_t nmemb, size_t size);
89 void *grep_realloc(void *ptr, size_t size);
90 void printline(str_t *line, int sep);
91 int fastcomp(fastgrep_t *, const char *);
92 void fgrepcomp(fastgrep_t *, const char *);
94 /* queue.c */
95 void initqueue(void);
96 void enqueue(str_t *x);
97 void printqueue(void);
98 void clearqueue(void);
100 /* mmfile.c */
101 typedef struct mmfile {
102 int fd;
103 size_t len;
104 unsigned char *base, *end, *ptr;
105 } mmf_t;
107 mmf_t *mmopen(char *fn, char *mode);
108 void mmclose(mmf_t *mmf);
109 char *mmfgetln(mmf_t *mmf, size_t *l);
111 /* file.c */
112 struct file;
113 typedef struct file file_t;
115 file_t *grep_fdopen(int fd, char *mode);
116 file_t *grep_open(char *path, char *mode);
117 int grep_bin_file(file_t *f);
118 char *grep_fgetln(file_t *f, size_t *l);
119 void grep_close(file_t *f);
121 /* binary.c */
122 int bin_file(FILE * f);
123 #ifndef NOZ
124 int gzbin_file(gzFile * f);
125 #endif
126 int mmbin_file(mmf_t *f);