This source file includes following definitions.
- API_EXPORT
1
2
3
4
5
6
7
8 #include <sys/types.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <limits.h>
13 #include <ctype.h>
14
15 #include "regex.h"
16 #include "utils.h"
17 #include "regex2.h"
18
19 #define PHP_REGEX_NOPE 0;
20
21
22 #define states unsigned
23 #define states1 unsigned
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
31 #define STATESETUP(m, n)
32 #define STATETEARDOWN(m)
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
39
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)))
43
44 #define SNAMES
45
46 #include "engine.c"
47
48
49 #undef states
50 #undef CLEAR
51 #undef SET0
52 #undef SET1
53 #undef ISSET
54 #undef ASSIGN
55 #undef EQ
56 #undef STATEVARS
57 #undef STATESETUP
58 #undef STATETEARDOWN
59 #undef SETUP
60 #undef onestate
61 #undef INIT
62 #undef INC
63 #undef ISSTATEIN
64 #undef FWD
65 #undef BACK
66 #undef ISSETBACK
67 #undef SNAMES
68
69
70 #define states unsigned char *
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; unsigned char *space
78 #define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
79 if ((m)->space == NULL) return(REG_ESPACE); \
80 (m)->vn = 0; }
81 #define STATETEARDOWN(m) { free((m)->space); }
82 #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
83 #define onestate int
84 #define INIT(o, n) ((o) = (n))
85 #define INC(o) ((o)++)
86 #define ISSTATEIN(v, o) ((v)[o])
87
88
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)])
92
93 #define LNAMES
94
95 #include "engine.c"
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 API_EXPORT(int)
113 regexec(preg, string, nmatch, pmatch, eflags)
114 const regex_t *preg;
115 const char *string;
116 size_t nmatch;
117 regmatch_t pmatch[];
118 int eflags;
119 {
120 register struct re_guts *g = preg->re_g;
121 #ifdef REDEBUG
122 # define GOODFLAGS(f) (f)
123 #else
124 # define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
125 #endif
126
127 if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
128 return(REG_BADPAT);
129 assert(!(g->iflags&BAD));
130 if (g->iflags&BAD)
131 return(REG_BADPAT);
132 eflags = GOODFLAGS(eflags);
133
134 if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
135 return(smatcher(g, (unsigned char *)string, nmatch, pmatch, eflags));
136 else
137 return(lmatcher(g, (unsigned char *)string, nmatch, pmatch, eflags));
138 }