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