xref: /aosp_15_r20/external/libcups/vcnet/regex/regex2.h (revision 5e7646d21f1134fb0638875d812ef646c12ab91e)
1*5e7646d2SAndroid Build Coastguard Worker /*
2*5e7646d2SAndroid Build Coastguard Worker  * First, the stuff that ends up in the outside-world include file
3*5e7646d2SAndroid Build Coastguard Worker  = typedef off_t regoff_t;
4*5e7646d2SAndroid Build Coastguard Worker  = typedef struct {
5*5e7646d2SAndroid Build Coastguard Worker  = 	int re_magic;
6*5e7646d2SAndroid Build Coastguard Worker  = 	size_t re_nsub;		// number of parenthesized subexpressions
7*5e7646d2SAndroid Build Coastguard Worker  = 	const char *re_endp;	// end pointer for REG_PEND
8*5e7646d2SAndroid Build Coastguard Worker  = 	struct re_guts *re_g;	// none of your business :-)
9*5e7646d2SAndroid Build Coastguard Worker  = } regex_t;
10*5e7646d2SAndroid Build Coastguard Worker  = typedef struct {
11*5e7646d2SAndroid Build Coastguard Worker  = 	regoff_t rm_so;		// start of match
12*5e7646d2SAndroid Build Coastguard Worker  = 	regoff_t rm_eo;		// end of match
13*5e7646d2SAndroid Build Coastguard Worker  = } regmatch_t;
14*5e7646d2SAndroid Build Coastguard Worker  */
15*5e7646d2SAndroid Build Coastguard Worker /*
16*5e7646d2SAndroid Build Coastguard Worker  * internals of regex_t
17*5e7646d2SAndroid Build Coastguard Worker  */
18*5e7646d2SAndroid Build Coastguard Worker #define	MAGIC1	((('r'^0200)<<8) | 'e')
19*5e7646d2SAndroid Build Coastguard Worker 
20*5e7646d2SAndroid Build Coastguard Worker /*
21*5e7646d2SAndroid Build Coastguard Worker  * The internal representation is a *strip*, a sequence of
22*5e7646d2SAndroid Build Coastguard Worker  * operators ending with an endmarker.  (Some terminology etc. is a
23*5e7646d2SAndroid Build Coastguard Worker  * historical relic of earlier versions which used multiple strips.)
24*5e7646d2SAndroid Build Coastguard Worker  * Certain oddities in the representation are there to permit running
25*5e7646d2SAndroid Build Coastguard Worker  * the machinery backwards; in particular, any deviation from sequential
26*5e7646d2SAndroid Build Coastguard Worker  * flow must be marked at both its source and its destination.  Some
27*5e7646d2SAndroid Build Coastguard Worker  * fine points:
28*5e7646d2SAndroid Build Coastguard Worker  *
29*5e7646d2SAndroid Build Coastguard Worker  * - OPLUS_ and O_PLUS are *inside* the loop they create.
30*5e7646d2SAndroid Build Coastguard Worker  * - OQUEST_ and O_QUEST are *outside* the bypass they create.
31*5e7646d2SAndroid Build Coastguard Worker  * - OCH_ and O_CH are *outside* the multi-way branch they create, while
32*5e7646d2SAndroid Build Coastguard Worker  *   OOR1 and OOR2 are respectively the end and the beginning of one of
33*5e7646d2SAndroid Build Coastguard Worker  *   the branches.  Note that there is an implicit OOR2 following OCH_
34*5e7646d2SAndroid Build Coastguard Worker  *   and an implicit OOR1 preceding O_CH.
35*5e7646d2SAndroid Build Coastguard Worker  *
36*5e7646d2SAndroid Build Coastguard Worker  * In state representations, an operator's bit is on to signify a state
37*5e7646d2SAndroid Build Coastguard Worker  * immediately *preceding* "execution" of that operator.
38*5e7646d2SAndroid Build Coastguard Worker  */
39*5e7646d2SAndroid Build Coastguard Worker typedef long sop;		/* strip operator */
40*5e7646d2SAndroid Build Coastguard Worker typedef long sopno;
41*5e7646d2SAndroid Build Coastguard Worker #define	OPRMASK	0x7c000000
42*5e7646d2SAndroid Build Coastguard Worker #define	OPDMASK	0x03ffffff
43*5e7646d2SAndroid Build Coastguard Worker #define	OPSHIFT	(26)
44*5e7646d2SAndroid Build Coastguard Worker #define	OP(n)	((n)&OPRMASK)
45*5e7646d2SAndroid Build Coastguard Worker #define	OPND(n)	((n)&OPDMASK)
46*5e7646d2SAndroid Build Coastguard Worker #define	SOP(op, opnd)	((op)|(opnd))
47*5e7646d2SAndroid Build Coastguard Worker /* operators			   meaning	operand			*/
48*5e7646d2SAndroid Build Coastguard Worker /*						(back, fwd are offsets)	*/
49*5e7646d2SAndroid Build Coastguard Worker #define	OEND	(1<<OPSHIFT)	/* endmarker	-			*/
50*5e7646d2SAndroid Build Coastguard Worker #define	OCHAR	(2<<OPSHIFT)	/* character	unsigned char		*/
51*5e7646d2SAndroid Build Coastguard Worker #define	OBOL	(3<<OPSHIFT)	/* left anchor	-			*/
52*5e7646d2SAndroid Build Coastguard Worker #define	OEOL	(4<<OPSHIFT)	/* right anchor	-			*/
53*5e7646d2SAndroid Build Coastguard Worker #define	OANY	(5<<OPSHIFT)	/* .		-			*/
54*5e7646d2SAndroid Build Coastguard Worker #define	OANYOF	(6<<OPSHIFT)	/* [...]	set number		*/
55*5e7646d2SAndroid Build Coastguard Worker #define	OBACK_	(7<<OPSHIFT)	/* begin \d	paren number		*/
56*5e7646d2SAndroid Build Coastguard Worker #define	O_BACK	(8<<OPSHIFT)	/* end \d	paren number		*/
57*5e7646d2SAndroid Build Coastguard Worker #define	OPLUS_	(9<<OPSHIFT)	/* + prefix	fwd to suffix		*/
58*5e7646d2SAndroid Build Coastguard Worker #define	O_PLUS	(10<<OPSHIFT)	/* + suffix	back to prefix		*/
59*5e7646d2SAndroid Build Coastguard Worker #define	OQUEST_	(11<<OPSHIFT)	/* ? prefix	fwd to suffix		*/
60*5e7646d2SAndroid Build Coastguard Worker #define	O_QUEST	(12<<OPSHIFT)	/* ? suffix	back to prefix		*/
61*5e7646d2SAndroid Build Coastguard Worker #define	OLPAREN	(13<<OPSHIFT)	/* (		fwd to )		*/
62*5e7646d2SAndroid Build Coastguard Worker #define	ORPAREN	(14<<OPSHIFT)	/* )		back to (		*/
63*5e7646d2SAndroid Build Coastguard Worker #define	OCH_	(15<<OPSHIFT)	/* begin choice	fwd to OOR2		*/
64*5e7646d2SAndroid Build Coastguard Worker #define	OOR1	(16<<OPSHIFT)	/* | pt. 1	back to OOR1 or OCH_	*/
65*5e7646d2SAndroid Build Coastguard Worker #define	OOR2	(17<<OPSHIFT)	/* | pt. 2	fwd to OOR2 or O_CH	*/
66*5e7646d2SAndroid Build Coastguard Worker #define	O_CH	(18<<OPSHIFT)	/* end choice	back to OOR1		*/
67*5e7646d2SAndroid Build Coastguard Worker #define	OBOW	(19<<OPSHIFT)	/* begin word	-			*/
68*5e7646d2SAndroid Build Coastguard Worker #define	OEOW	(20<<OPSHIFT)	/* end word	-			*/
69*5e7646d2SAndroid Build Coastguard Worker 
70*5e7646d2SAndroid Build Coastguard Worker /*
71*5e7646d2SAndroid Build Coastguard Worker  * Structure for [] character-set representation.  Character sets are
72*5e7646d2SAndroid Build Coastguard Worker  * done as bit vectors, grouped 8 to a byte vector for compactness.
73*5e7646d2SAndroid Build Coastguard Worker  * The individual set therefore has both a pointer to the byte vector
74*5e7646d2SAndroid Build Coastguard Worker  * and a mask to pick out the relevant bit of each byte.  A hash code
75*5e7646d2SAndroid Build Coastguard Worker  * simplifies testing whether two sets could be identical.
76*5e7646d2SAndroid Build Coastguard Worker  *
77*5e7646d2SAndroid Build Coastguard Worker  * This will get trickier for multicharacter collating elements.  As
78*5e7646d2SAndroid Build Coastguard Worker  * preliminary hooks for dealing with such things, we also carry along
79*5e7646d2SAndroid Build Coastguard Worker  * a string of multi-character elements, and decide the size of the
80*5e7646d2SAndroid Build Coastguard Worker  * vectors at run time.
81*5e7646d2SAndroid Build Coastguard Worker  */
82*5e7646d2SAndroid Build Coastguard Worker typedef struct {
83*5e7646d2SAndroid Build Coastguard Worker 	uch *ptr;		/* -> uch [csetsize] */
84*5e7646d2SAndroid Build Coastguard Worker 	uch mask;		/* bit within array */
85*5e7646d2SAndroid Build Coastguard Worker 	uch hash;		/* hash code */
86*5e7646d2SAndroid Build Coastguard Worker 	size_t smultis;
87*5e7646d2SAndroid Build Coastguard Worker 	char *multis;		/* -> char[smulti]  ab\0cd\0ef\0\0 */
88*5e7646d2SAndroid Build Coastguard Worker } cset;
89*5e7646d2SAndroid Build Coastguard Worker /* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
90*5e7646d2SAndroid Build Coastguard Worker #define	CHadd(cs, c)	((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
91*5e7646d2SAndroid Build Coastguard Worker #define	CHsub(cs, c)	((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
92*5e7646d2SAndroid Build Coastguard Worker #define	CHIN(cs, c)	((cs)->ptr[(uch)(c)] & (cs)->mask)
93*5e7646d2SAndroid Build Coastguard Worker #define	MCadd(p, cs, cp)	mcadd(p, cs, cp)	/* regcomp() internal fns */
94*5e7646d2SAndroid Build Coastguard Worker #define	MCsub(p, cs, cp)	mcsub(p, cs, cp)
95*5e7646d2SAndroid Build Coastguard Worker #define	MCin(p, cs, cp)	mcin(p, cs, cp)
96*5e7646d2SAndroid Build Coastguard Worker 
97*5e7646d2SAndroid Build Coastguard Worker /* stuff for character categories */
98*5e7646d2SAndroid Build Coastguard Worker typedef unsigned char cat_t;
99*5e7646d2SAndroid Build Coastguard Worker 
100*5e7646d2SAndroid Build Coastguard Worker /*
101*5e7646d2SAndroid Build Coastguard Worker  * main compiled-expression structure
102*5e7646d2SAndroid Build Coastguard Worker  */
103*5e7646d2SAndroid Build Coastguard Worker struct re_guts {
104*5e7646d2SAndroid Build Coastguard Worker 	int magic;
105*5e7646d2SAndroid Build Coastguard Worker #		define	MAGIC2	((('R'^0200)<<8)|'E')
106*5e7646d2SAndroid Build Coastguard Worker 	sop *strip;		/* malloced area for strip */
107*5e7646d2SAndroid Build Coastguard Worker 	int csetsize;		/* number of bits in a cset vector */
108*5e7646d2SAndroid Build Coastguard Worker 	int ncsets;		/* number of csets in use */
109*5e7646d2SAndroid Build Coastguard Worker 	cset *sets;		/* -> cset [ncsets] */
110*5e7646d2SAndroid Build Coastguard Worker 	uch *setbits;		/* -> uch[csetsize][ncsets/CHAR_BIT] */
111*5e7646d2SAndroid Build Coastguard Worker 	int cflags;		/* copy of regcomp() cflags argument */
112*5e7646d2SAndroid Build Coastguard Worker 	sopno nstates;		/* = number of sops */
113*5e7646d2SAndroid Build Coastguard Worker 	sopno firststate;	/* the initial OEND (normally 0) */
114*5e7646d2SAndroid Build Coastguard Worker 	sopno laststate;	/* the final OEND */
115*5e7646d2SAndroid Build Coastguard Worker 	int iflags;		/* internal flags */
116*5e7646d2SAndroid Build Coastguard Worker #		define	USEBOL	01	/* used ^ */
117*5e7646d2SAndroid Build Coastguard Worker #		define	USEEOL	02	/* used $ */
118*5e7646d2SAndroid Build Coastguard Worker #		define	BAD	04	/* something wrong */
119*5e7646d2SAndroid Build Coastguard Worker 	int nbol;		/* number of ^ used */
120*5e7646d2SAndroid Build Coastguard Worker 	int neol;		/* number of $ used */
121*5e7646d2SAndroid Build Coastguard Worker 	int ncategories;	/* how many character categories */
122*5e7646d2SAndroid Build Coastguard Worker 	cat_t *categories;	/* ->catspace[-CHAR_MIN] */
123*5e7646d2SAndroid Build Coastguard Worker 	char *must;		/* match must contain this string */
124*5e7646d2SAndroid Build Coastguard Worker 	int mlen;		/* length of must */
125*5e7646d2SAndroid Build Coastguard Worker 	size_t nsub;		/* copy of re_nsub */
126*5e7646d2SAndroid Build Coastguard Worker 	int backrefs;		/* does it use back references? */
127*5e7646d2SAndroid Build Coastguard Worker 	sopno nplus;		/* how deep does it nest +s? */
128*5e7646d2SAndroid Build Coastguard Worker 	/* catspace must be last */
129*5e7646d2SAndroid Build Coastguard Worker 	cat_t catspace[1];	/* actually [NC] */
130*5e7646d2SAndroid Build Coastguard Worker };
131*5e7646d2SAndroid Build Coastguard Worker 
132*5e7646d2SAndroid Build Coastguard Worker /* misc utilities */
133*5e7646d2SAndroid Build Coastguard Worker #define	OUT	(CHAR_MAX+1)	/* a non-character value */
134*5e7646d2SAndroid Build Coastguard Worker #define	ISWORD(c)	(isalnum(c) || (c) == '_')
135