etc/services - sync with NetBSD-8
[minix.git] / minix / usr.bin / grep / grep.h
blob255a78fa51b6587f4b486cceb75942e4df5b86f7
1 /* $OpenBSD: grep.h,v 1.19 2013/11/26 13:21:16 deraadt 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>
30 #ifndef __minix
31 #include <sys/limits.h>
32 #else
33 #include <limits.h>
34 #endif /* __minix */
36 #include <regex.h>
37 #include <stdio.h>
38 #include <zlib.h>
40 #define VER_MAJ 0
41 #define VER_MIN 9
43 #define BIN_FILE_BIN 0
44 #define BIN_FILE_SKIP 1
45 #define BIN_FILE_TEXT 2
47 typedef struct {
48 size_t len;
49 int line_no;
50 off_t off;
51 const char *file;
52 char *dat;
53 } str_t;
55 typedef struct {
56 unsigned char *pattern;
57 int patternLen;
58 int qsBc[UCHAR_MAX + 1];
59 /* flags */
60 int bol;
61 int eol;
62 int wmatch;
63 int reversedSearch;
64 } fastgrep_t;
66 /* Flags passed to regcomp() and regexec() */
67 extern int cflags, eflags;
69 /* Command line flags */
70 extern int Aflag, Bflag, Eflag, Fflag, Gflag, Hflag, Lflag,
71 Rflag, Zflag,
72 bflag, cflag, hflag, iflag, lflag, nflag, oflag, qflag, sflag,
73 vflag, wflag, xflag;
74 extern int binbehave;
76 extern int first, matchall, patterns, tail, file_err;
77 extern char **pattern;
78 extern fastgrep_t *fg_pattern;
79 extern regex_t *r_pattern;
81 /* For regex errors */
82 #define RE_ERROR_BUF 512
83 extern char re_error[RE_ERROR_BUF + 1]; /* Seems big enough */
85 /* util.c */
86 int procfile(const char *fn);
87 int grep_tree(char **argv);
88 void *grep_malloc(size_t size);
89 void *grep_calloc(size_t nmemb, size_t size);
90 void *grep_realloc(void *ptr, size_t size);
91 void printline(str_t *line, int sep, regmatch_t *pmatch);
92 int fastcomp(fastgrep_t *, const char *);
93 void fgrepcomp(fastgrep_t *, const unsigned char *);
95 /* queue.c */
96 void initqueue(void);
97 void enqueue(str_t *x);
98 void printqueue(void);
99 void clearqueue(void);
101 /* mmfile.c */
102 typedef struct mmfile {
103 int fd;
104 size_t len;
105 char *base, *end, *ptr;
106 } mmf_t;
108 mmf_t *mmopen(const char *fn, const char *mode);
109 void mmclose(mmf_t *mmf);
110 char *mmfgetln(mmf_t *mmf, size_t *l);
112 /* file.c */
113 struct file;
114 typedef struct file file_t;
116 file_t *grep_fdopen(int fd, const char *mode);
117 file_t *grep_open(const char *path, const char *mode);
118 int grep_bin_file(file_t *f);
119 char *grep_fgetln(file_t *f, size_t *l);
120 void grep_close(file_t *f);
122 /* binary.c */
123 int bin_file(FILE * f);
124 int gzbin_file(gzFile * f);
125 int mmbin_file(mmf_t *f);