9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

grep.h (2224B)


      1 #include	<u.h>
      2 #include	<libc.h>
      3 #include	<bio.h>
      4 
      5 #ifndef	EXTERN
      6 #define	EXTERN	extern
      7 #endif
      8 
      9 typedef	struct	Re	Re;
     10 typedef	struct	Re2	Re2;
     11 typedef	struct	State	State;
     12 
     13 struct	State
     14 {
     15 	int	count;
     16 	int	match;
     17 	Re**	re;
     18 	State*	linkleft;
     19 	State*	linkright;
     20 	State*	next[256];
     21 };
     22 struct	Re2
     23 {
     24 	Re*	beg;
     25 	Re*	end;
     26 };
     27 struct	Re
     28 {
     29 	uchar	type;
     30 	ushort	gen;
     31 	union
     32 	{
     33 		Re*	alt;	/* Talt */
     34 		Re**	cases;	/* case */
     35 		struct		/* class */
     36 		{
     37 			Rune	lo;
     38 			Rune	hi;
     39 		} x;	
     40 		Rune	val;	/* char */
     41 	} u;
     42 	Re*	next;
     43 };
     44 
     45 enum
     46 {
     47 	Talt		= 1,
     48 	Tbegin,
     49 	Tcase,
     50 	Tclass,
     51 	Tend,
     52 	Tor,
     53 
     54 	Caselim		= 7,
     55 	Nhunk		= 1<<16,
     56 	Cbegin		= 0x10000,
     57 	Flshcnt		= (1<<9)-1,
     58 
     59 	Cflag		= 1<<0,
     60 	Hflag		= 1<<1,
     61 	Iflag		= 1<<2,
     62 	Llflag		= 1<<3,
     63 	LLflag		= 1<<4,
     64 	Nflag		= 1<<5,
     65 	Sflag		= 1<<6,
     66 	Vflag		= 1<<7,
     67 	Bflag		= 1<<8
     68 };
     69 
     70 EXTERN	union
     71 {
     72 	char	string[16*1024];
     73 	struct
     74 	{
     75 		/*
     76 		 * if a line requires multiple reads, we keep shifting
     77 		 * buf down into pre and then do another read into
     78 		 * buf.  so you'll get the last 16-32k of the matching line.
     79 		 * if h were smaller than buf you'd get a suffix of the
     80 		 * line with a hole cut out.
     81 		 */
     82 		uchar	pre[16*1024];	/* to save to previous '\n' */
     83 		uchar	buf[16*1024];	/* input buffer */
     84 	} u;
     85 } u;
     86 
     87 EXTERN	char	*filename;
     88 EXTERN	Biobuf	bout;
     89 EXTERN	char	flags[256];
     90 EXTERN	Re**	follow;
     91 EXTERN	ushort	gen;
     92 EXTERN	char*	input;
     93 EXTERN	long	lineno;
     94 EXTERN	int	literal;
     95 EXTERN	int	matched;
     96 EXTERN	long	maxfollow;
     97 EXTERN	long	nfollow;
     98 EXTERN	int	peekc;
     99 EXTERN	Biobuf*	rein;
    100 EXTERN	State*	state0;
    101 EXTERN	Re2	topre;
    102 
    103 extern	Re*	addcase(Re*);
    104 extern	void	appendnext(Re*, Re*);
    105 extern	void	error(char*);
    106 extern	int	fcmp(const void*, const void*); 	/* (Re**, Re**) */
    107 extern	void	fol1(Re*, int);
    108 extern	int	getrec(void);
    109 extern	void	increment(State*, int);
    110 #define initstate grepinitstate
    111 extern	State*	initstate(Re*);
    112 extern	void*	mal(int);
    113 extern	void	patchnext(Re*, Re*);
    114 extern	Re*	ral(int);
    115 extern	Re2	re2cat(Re2, Re2);
    116 extern	Re2	re2class(char*);
    117 extern	Re2	re2or(Re2, Re2);
    118 extern	Re2	re2char(int, int);
    119 extern	Re2	re2star(Re2);
    120 extern	State*	sal(int);
    121 extern	int	search(char*, int);
    122 extern	void	str2top(char*);
    123 extern	int	yyparse(void);
    124 extern	void	reprint(char*, Re*);
    125 extern	void	yyerror(char*, ...);