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.
15 /* macros for manipulating states, small version */
16 #define states unsigned long
17 #define states1 states /* for later use in regexec() decision */
18 #define CLEAR(v) (((v) = 0), (void)(v))
19 #define SET0(v, n) ((v) &= ~(MAKE_UNSIGNED_LONG(1) << (n)))
20 #define SET1(v, n) ((v) |= (MAKE_UNSIGNED_LONG(1)) << (n))
21 #define ISSET(v, n) ((v) & ((MAKE_UNSIGNED_LONG(1)) << (n)))
22 #define ASSIGN(d, s) ((d) = (s), (void)(d))
23 #define EQ(a, b) ((a) == (b))
24 #define STATEVARS int dummy /* dummy version */
25 #define STATESETUP(m, n) /* nothing */
26 #define STATETEARDOWN(m) /* nothing */
27 #define SETUP(v) ((v) = 0)
28 #define onestate sopno
29 #define INIT(o, n) ((o) = (sopno)1 << (n))
30 #define INC(o) ((o) <<= 1)
31 #define ISSTATEIN(v, o) ((v) & (o))
32 /* some abbreviations; note that some of these know variable names! */
33 /* do "if I'm here, I can also be there" etc without branches */
34 #define FWD(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) << (n))
35 #define BACK(dst, src, n) ((dst) |= ((unsigned long)(src)&(here)) >> (n))
36 #define ISSETBACK(v, n) ((v) & ((long)here >> (n)))
38 #define SNAMES /* engine.c looks after details */
63 /* macros for manipulating states, large version */
65 #define CLEAR(v) memset((v), 0, (size_t)m->g->nstates)
66 #define SET0(v, n) ((v)[n] = 0)
67 #define SET1(v, n) ((v)[n] = 1)
68 #define ISSET(v, n) ((v)[n])
69 #define ASSIGN(d, s) memcpy((d), (s), (size_t)m->g->nstates)
70 #define EQ(a, b) (memcmp((a), (b), (size_t)m->g->nstates) == 0)
71 #define STATEVARS int vn; char *space
72 #define STATESETUP(m, nv) do { \
73 (m)->space = malloc((size_t)(nv)*(size_t)(m)->g->nstates); \
74 if ((m)->space == NULL) \
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 = int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
98 = #define REG_NOTBOL 00001
99 = #define REG_NOTEOL 00002
100 = #define REG_STARTEND 00004
101 = #define REG_TRACE 00400 // tracing of execution
102 = #define REG_LARGE 01000 // force large representation
103 = #define REG_BACKR 02000 // force use of backref code
105 * We put this here so we can exploit knowledge of the state representation
106 * when choosing which matcher to call. Also, by this point the matchers
107 * have been prototyped.
109 int /* 0 success, REG_NOMATCH failure */
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)
128 assert(!(g->iflags&BAD));
129 if (g->iflags&BAD) /* backstop for no-debug case */
131 eflags = GOODFLAGS(eflags);
133 if ((g->nstates <= ((sopno)(CHAR_BIT * SIZEOF(states1))) &&
134 !(eflags & REG_LARGE)))
135 return(smatcher(g, string, nmatch, pmatch, eflags));
136 return(lmatcher(g, string, nmatch, pmatch, eflags));