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