xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/regexp.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*    regexp.h
2*0Sstevel@tonic-gate  *
3*0Sstevel@tonic-gate  *    Copyright (C) 1993, 1994, 1996, 1997, 1999, 2000, 2001, 2003,
4*0Sstevel@tonic-gate  *    by Larry Wall and others
5*0Sstevel@tonic-gate  *
6*0Sstevel@tonic-gate  *    You may distribute under the terms of either the GNU General Public
7*0Sstevel@tonic-gate  *    License or the Artistic License, as specified in the README file.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate /*
12*0Sstevel@tonic-gate  * Definitions etc. for regexp(3) routines.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
15*0Sstevel@tonic-gate  * not the System V one.
16*0Sstevel@tonic-gate  */
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate 
19*0Sstevel@tonic-gate struct regnode {
20*0Sstevel@tonic-gate     U8	flags;
21*0Sstevel@tonic-gate     U8  type;
22*0Sstevel@tonic-gate     U16 next_off;
23*0Sstevel@tonic-gate };
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate typedef struct regnode regnode;
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate struct reg_substr_data;
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate struct reg_data;
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate typedef struct regexp {
32*0Sstevel@tonic-gate 	I32 *startp;
33*0Sstevel@tonic-gate 	I32 *endp;
34*0Sstevel@tonic-gate 	regnode *regstclass;
35*0Sstevel@tonic-gate         struct reg_substr_data *substrs;
36*0Sstevel@tonic-gate 	char *precomp;		/* pre-compilation regular expression */
37*0Sstevel@tonic-gate         struct reg_data *data;	/* Additional data. */
38*0Sstevel@tonic-gate 	char *subbeg;		/* saved or original string
39*0Sstevel@tonic-gate 				   so \digit works forever. */
40*0Sstevel@tonic-gate         U32 *offsets;           /* offset annotations 20001228 MJD */
41*0Sstevel@tonic-gate 	I32 sublen;		/* Length of string pointed by subbeg */
42*0Sstevel@tonic-gate 	I32 refcnt;
43*0Sstevel@tonic-gate 	I32 minlen;		/* mininum possible length of $& */
44*0Sstevel@tonic-gate 	I32 prelen;		/* length of precomp */
45*0Sstevel@tonic-gate 	U32 nparens;		/* number of parentheses */
46*0Sstevel@tonic-gate 	U32 lastparen;		/* last paren matched */
47*0Sstevel@tonic-gate 	U32 lastcloseparen;	/* last paren matched */
48*0Sstevel@tonic-gate 	U32 reganch;		/* Internal use only +
49*0Sstevel@tonic-gate 				   Tainted information used by regexec? */
50*0Sstevel@tonic-gate 	regnode program[1];	/* Unwarranted chumminess with compiler. */
51*0Sstevel@tonic-gate } regexp;
52*0Sstevel@tonic-gate 
53*0Sstevel@tonic-gate #define ROPT_ANCH		(ROPT_ANCH_BOL|ROPT_ANCH_MBOL|ROPT_ANCH_GPOS|ROPT_ANCH_SBOL)
54*0Sstevel@tonic-gate #define ROPT_ANCH_SINGLE	(ROPT_ANCH_SBOL|ROPT_ANCH_GPOS)
55*0Sstevel@tonic-gate #define ROPT_ANCH_BOL	 	0x00001
56*0Sstevel@tonic-gate #define ROPT_ANCH_MBOL	 	0x00002
57*0Sstevel@tonic-gate #define ROPT_ANCH_SBOL	 	0x00004
58*0Sstevel@tonic-gate #define ROPT_ANCH_GPOS	 	0x00008
59*0Sstevel@tonic-gate #define ROPT_SKIP		0x00010
60*0Sstevel@tonic-gate #define ROPT_IMPLICIT		0x00020	/* Converted .* to ^.* */
61*0Sstevel@tonic-gate #define ROPT_NOSCAN		0x00040	/* Check-string always at start. */
62*0Sstevel@tonic-gate #define ROPT_GPOS_SEEN		0x00080
63*0Sstevel@tonic-gate #define ROPT_CHECK_ALL		0x00100
64*0Sstevel@tonic-gate #define ROPT_LOOKBEHIND_SEEN	0x00200
65*0Sstevel@tonic-gate #define ROPT_EVAL_SEEN		0x00400
66*0Sstevel@tonic-gate #define ROPT_CANY_SEEN		0x00800
67*0Sstevel@tonic-gate #define ROPT_SANY_SEEN		ROPT_CANY_SEEN /* src bckwrd cmpt */
68*0Sstevel@tonic-gate 
69*0Sstevel@tonic-gate /* 0xf800 of reganch is used by PMf_COMPILETIME */
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate #define ROPT_UTF8		0x10000
72*0Sstevel@tonic-gate #define ROPT_NAUGHTY		0x20000 /* how exponential is this pattern? */
73*0Sstevel@tonic-gate #define ROPT_COPY_DONE		0x40000	/* subbeg is a copy of the string */
74*0Sstevel@tonic-gate #define ROPT_TAINTED_SEEN	0x80000
75*0Sstevel@tonic-gate #define ROPT_MATCH_UTF8		0x10000000 /* subbeg is utf-8 */
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate #define RE_USE_INTUIT_NOML	0x0100000 /* Best to intuit before matching */
78*0Sstevel@tonic-gate #define RE_USE_INTUIT_ML	0x0200000
79*0Sstevel@tonic-gate #define REINT_AUTORITATIVE_NOML	0x0400000 /* Can trust a positive answer */
80*0Sstevel@tonic-gate #define REINT_AUTORITATIVE_ML	0x0800000
81*0Sstevel@tonic-gate #define REINT_ONCE_NOML		0x1000000 /* Intuit can succed once only. */
82*0Sstevel@tonic-gate #define REINT_ONCE_ML		0x2000000
83*0Sstevel@tonic-gate #define RE_INTUIT_ONECHAR	0x4000000
84*0Sstevel@tonic-gate #define RE_INTUIT_TAIL		0x8000000
85*0Sstevel@tonic-gate 
86*0Sstevel@tonic-gate #define RE_USE_INTUIT		(RE_USE_INTUIT_NOML|RE_USE_INTUIT_ML)
87*0Sstevel@tonic-gate #define REINT_AUTORITATIVE	(REINT_AUTORITATIVE_NOML|REINT_AUTORITATIVE_ML)
88*0Sstevel@tonic-gate #define REINT_ONCE		(REINT_ONCE_NOML|REINT_ONCE_ML)
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate #define RX_MATCH_TAINTED(prog)	((prog)->reganch & ROPT_TAINTED_SEEN)
91*0Sstevel@tonic-gate #define RX_MATCH_TAINTED_on(prog) ((prog)->reganch |= ROPT_TAINTED_SEEN)
92*0Sstevel@tonic-gate #define RX_MATCH_TAINTED_off(prog) ((prog)->reganch &= ~ROPT_TAINTED_SEEN)
93*0Sstevel@tonic-gate #define RX_MATCH_TAINTED_set(prog, t) ((t) \
94*0Sstevel@tonic-gate 				       ? RX_MATCH_TAINTED_on(prog) \
95*0Sstevel@tonic-gate 				       : RX_MATCH_TAINTED_off(prog))
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate #define RX_MATCH_COPIED(prog)		((prog)->reganch & ROPT_COPY_DONE)
98*0Sstevel@tonic-gate #define RX_MATCH_COPIED_on(prog)	((prog)->reganch |= ROPT_COPY_DONE)
99*0Sstevel@tonic-gate #define RX_MATCH_COPIED_off(prog)	((prog)->reganch &= ~ROPT_COPY_DONE)
100*0Sstevel@tonic-gate #define RX_MATCH_COPIED_set(prog,t)	((t) \
101*0Sstevel@tonic-gate 					 ? RX_MATCH_COPIED_on(prog) \
102*0Sstevel@tonic-gate 					 : RX_MATCH_COPIED_off(prog))
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate #define RX_MATCH_UTF8(prog)		((prog)->reganch & ROPT_MATCH_UTF8)
105*0Sstevel@tonic-gate #define RX_MATCH_UTF8_on(prog)		((prog)->reganch |= ROPT_MATCH_UTF8)
106*0Sstevel@tonic-gate #define RX_MATCH_UTF8_off(prog)		((prog)->reganch &= ~ROPT_MATCH_UTF8)
107*0Sstevel@tonic-gate #define RX_MATCH_UTF8_set(prog, t)	((t) \
108*0Sstevel@tonic-gate 			? (RX_MATCH_UTF8_on(prog), (PL_reg_match_utf8 = 1)) \
109*0Sstevel@tonic-gate 			: (RX_MATCH_UTF8_off(prog), (PL_reg_match_utf8 = 0)))
110*0Sstevel@tonic-gate 
111*0Sstevel@tonic-gate #define REXEC_COPY_STR	0x01		/* Need to copy the string. */
112*0Sstevel@tonic-gate #define REXEC_CHECKED	0x02		/* check_substr already checked. */
113*0Sstevel@tonic-gate #define REXEC_SCREAM	0x04		/* use scream table. */
114*0Sstevel@tonic-gate #define REXEC_IGNOREPOS	0x08		/* \G matches at start. */
115*0Sstevel@tonic-gate #define REXEC_NOT_FIRST	0x10		/* This is another iteration of //g. */
116*0Sstevel@tonic-gate #define REXEC_ML	0x20		/* $* was set. */
117*0Sstevel@tonic-gate 
118*0Sstevel@tonic-gate #define ReREFCNT_inc(re) ((void)(re && re->refcnt++), re)
119*0Sstevel@tonic-gate #define ReREFCNT_dec(re) CALLREGFREE(aTHX_ re)
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate #define FBMcf_TAIL_DOLLAR	1
122*0Sstevel@tonic-gate #define FBMcf_TAIL_DOLLARM	2
123*0Sstevel@tonic-gate #define FBMcf_TAIL_Z		4
124*0Sstevel@tonic-gate #define FBMcf_TAIL_z		8
125*0Sstevel@tonic-gate #define FBMcf_TAIL		(FBMcf_TAIL_DOLLAR|FBMcf_TAIL_DOLLARM|FBMcf_TAIL_Z|FBMcf_TAIL_z)
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate #define FBMrf_MULTILINE	1
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate struct re_scream_pos_data_s;
130