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