]>
git.saurik.com Git - wxWidgets.git/blob - src/regex/regexec.c
dcb11b285c0cf99c3817394cb1d52199047ec085
2 * the outer shell of regexec()
4 * This file includes engine.c *twice*, after muchos fiddling with the
5 * macros that code uses. This lets the same code operate on two different
6 * representations for state sets.
19 static int nope
= 0; /* for use in asserts; shuts lint up */
21 /* macros for manipulating states, small version */
22 #define states unsigned
23 #define states1 unsigned /* for later use in regexec() decision */
24 #define CLEAR(v) ((v) = 0)
25 #define SET0(v, n) ((v) &= ~((unsigned)1 << (n)))
26 #define SET1(v, n) ((v) |= (unsigned)1 << (n))
27 #define ISSET(v, n) ((v) & ((unsigned)1 << (n)))
28 #define ASSIGN(d, s) ((d) = (s))
29 #define EQ(a, b) ((a) == (b))
30 #define STATEVARS int dummy /* dummy version */
31 #define STATESETUP(m, n) /* nothing */
32 #define STATETEARDOWN(m) /* nothing */
33 #define SETUP(v) ((v) = 0)
34 #define onestate unsigned
35 #define INIT(o, n) ((o) = (unsigned)1 << (n))
36 #define INC(o) ((o) <<= 1)
37 #define ISSTATEIN(v, o) ((v) & (o))
38 /* some abbreviations; note that some of these know variable names! */
39 /* do "if I'm here, I can also be there" etc without branches */
40 #define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n))
41 #define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n))
42 #define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n)))
44 #define SNAMES /* engine.c looks after details */
69 /* macros for manipulating states, large version */
71 #define CLEAR(v) memset(v, 0, m->g->nstates)
72 #define SET0(v, n) ((v)[n] = 0)
73 #define SET1(v, n) ((v)[n] = 1)
74 #define ISSET(v, n) ((v)[n])
75 #define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
76 #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
77 #define STATEVARS int vn; char *space
78 #define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
79 if ((m)->space == NULL) return(REG_ESPACE); \
81 #define STATETEARDOWN(m) { free((m)->space); }
82 #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
84 #define INIT(o, n) ((o) = (n))
85 #define INC(o) ((o)++)
86 #define ISSTATEIN(v, o) ((v)[o])
87 /* some abbreviations; note that some of these know variable names! */
88 /* do "if I'm here, I can also be there" etc without branches */
89 #define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
90 #define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
91 #define ISSETBACK(v, n) ((v)[here - (n)])
93 #define LNAMES /* flag */
98 - regexec - interface for matching
99 = extern int regexec(const regex_t *, const char *, size_t, \
100 = regmatch_t [], int);
101 = #define REG_NOTBOL 00001
102 = #define REG_NOTEOL 00002
103 = #define REG_STARTEND 00004
104 = #define REG_TRACE 00400 // tracing of execution
105 = #define REG_LARGE 01000 // force large representation
106 = #define REG_BACKR 02000 // force use of backref code
108 * We put this here so we can exploit knowledge of the state representation
109 * when choosing which matcher to call. Also, by this point the matchers
110 * have been prototyped.
112 int /* 0 success, REG_NOMATCH failure */
113 regexec(preg
, string
, nmatch
, pmatch
, eflags
)
120 register struct re_guts
*g
= preg
->re_g
;
122 # define GOODFLAGS(f) (f)
124 # define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
127 if (preg
->re_magic
!= MAGIC1
|| g
->magic
!= MAGIC2
)
129 assert(!(g
->iflags
&BAD
));
130 if (g
->iflags
&BAD
) /* backstop for no-debug case */
132 eflags
= GOODFLAGS(eflags
);
134 if (g
->nstates
<= CHAR_BIT
*sizeof(states1
) && !(eflags
®_LARGE
))
135 return(smatcher(g
, (char *)string
, nmatch
, pmatch
, eflags
));
137 return(lmatcher(g
, (char *)string
, nmatch
, pmatch
, eflags
));