Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 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
		};	
40
		Rune	val;	/* char */
41
	};
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		= Runemax+1,
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 pre 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
	};
85
} u;
86
 
87
EXTERN	char	*filename;
88
EXTERN	char	*pattern;
89
EXTERN	Biobuf	bout;
90
EXTERN	char	flags[256];
91
EXTERN	Re**	follow;
92
EXTERN	ushort	gen;
93
EXTERN	char*	input;
94
EXTERN	long	lineno;
95
EXTERN	int	literal;
96
EXTERN	int	matched;
97
EXTERN	long	maxfollow;
98
EXTERN	long	nfollow;
99
EXTERN	int	peekc;
100
EXTERN	Biobuf*	rein;
101
EXTERN	State*	state0;
102
EXTERN	Re2	topre;
103
 
104
extern	Re*	addcase(Re*);
105
extern	void	appendnext(Re*, Re*);
106
extern	void	error(char*);
107
extern	int	fcmp(void*, void*); 	/* (Re**, Re**) */
108
extern	void	fol1(Re*, int);
109
extern	int	getrec(void);
110
extern	void	increment(State*, int);
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*, ...);