74
74
llvm_regmatch_t *pmatch; /* [nsub+1] (0 element unused) */
75
char *offp; /* offsets work from here */
76
char *beginp; /* start of string -- virtual NUL precedes */
77
char *endp; /* end of string -- virtual NUL here */
78
char *coldp; /* can be no match starting before here */
79
char **lastpos; /* [nplus+1] */
75
const char *offp; /* offsets work from here */
76
const char *beginp; /* start of string -- virtual NUL precedes */
77
const char *endp; /* end of string -- virtual NUL here */
78
const char *coldp; /* can be no match starting before here */
79
const char **lastpos; /* [nplus+1] */
81
81
states st; /* current states */
82
82
states fresh; /* states for a fresh start */
84
84
states empty; /* empty set of states */
87
static int matcher(struct re_guts *, char *, size_t, llvm_regmatch_t[], int);
88
static char *dissect(struct match *, char *, char *, sopno, sopno);
89
static char *backref(struct match *, char *, char *, sopno, sopno, sopno, int);
90
static char *fast(struct match *, char *, char *, sopno, sopno);
91
static char *slow(struct match *, char *, char *, sopno, sopno);
87
static int matcher(struct re_guts *, const char *, size_t,
88
llvm_regmatch_t[], int);
89
static const char *dissect(struct match *, const char *, const char *, sopno,
91
static const char *backref(struct match *, const char *, const char *, sopno,
93
static const char *fast(struct match *, const char *, const char *, sopno, sopno);
94
static const char *slow(struct match *, const char *, const char *, sopno, sopno);
92
95
static states step(struct re_guts *, sopno, sopno, states, int, states);
93
96
#define MAX_RECURSION 100
94
97
#define BOL (OUT+1)
125
128
- matcher - the actual matching engine
127
130
static int /* 0 success, REG_NOMATCH failure */
128
matcher(struct re_guts *g, char *string, size_t nmatch, llvm_regmatch_t pmatch[],
131
matcher(struct re_guts *g, const char *string, size_t nmatch,
132
llvm_regmatch_t pmatch[],
134
138
struct match *m = &mv;
136
140
const sopno gf = g->firststate+1; /* +1 for OEND */
137
141
const sopno gl = g->laststate;
141
145
/* simplify the situation where possible */
142
146
if (g->cflags®_NOSUB)
216
220
dp = dissect(m, m->coldp, endp, gf, gl);
218
222
if (g->nplus > 0 && m->lastpos == NULL)
219
m->lastpos = (char **)malloc((g->nplus+1) *
223
m->lastpos = (const char **)malloc((g->nplus+1) *
221
225
if (g->nplus > 0 && m->lastpos == NULL) {
288
292
- dissect - figure out what matched what, no back references
290
static char * /* == stop (success) always */
291
dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
294
static const char * /* == stop (success) always */
295
dissect(struct match *m, const char *start, const char *stop, sopno startst,
294
299
sopno ss; /* start sop of current subRE */
295
300
sopno es; /* end sop of current subRE */
296
char *sp; /* start of string matched by it */
297
char *stp; /* string matched by it cannot pass here */
298
char *rest; /* start of rest of string */
299
char *tail; /* string unmatched by rest of RE */
301
const char *sp; /* start of string matched by it */
302
const char *stp; /* string matched by it cannot pass here */
303
const char *rest; /* start of rest of string */
304
const char *tail; /* string unmatched by rest of RE */
300
305
sopno ssub; /* start sop of subsubRE */
301
306
sopno esub; /* end sop of subsubRE */
302
char *ssp; /* start of string matched by subsubRE */
303
char *sep; /* end of string matched by subsubRE */
304
char *oldssp; /* previous ssp */
307
const char *ssp; /* start of string matched by subsubRE */
308
const char *sep; /* end of string matched by subsubRE */
309
const char *oldssp; /* previous ssp */
306
311
AT("diss", start, stop, startst, stopst);
361
366
/* did innards match? */
362
367
if (slow(m, sp, rest, ssub, esub) != NULL) {
363
char *dp = dissect(m, sp, rest, ssub, esub);
368
const char *dp = dissect(m, sp, rest, ssub, esub);
364
369
(void)dp; /* avoid warning if assertions off */
365
370
assert(dp == rest);
400
405
assert(sep == rest); /* must exhaust substring */
401
406
assert(slow(m, ssp, sep, ssub, esub) == rest);
403
char *dp = dissect(m, ssp, sep, ssub, esub);
408
const char *dp = dissect(m, ssp, sep, ssub, esub);
404
409
(void)dp; /* avoid warning if assertions off */
405
410
assert(dp == sep);
438
443
assert(OP(m->g->strip[esub]) == O_CH);
441
char *dp = dissect(m, sp, rest, ssub, esub);
446
const char *dp = dissect(m, sp, rest, ssub, esub);
442
447
(void)dp; /* avoid warning if assertions off */
443
448
assert(dp == rest);
475
480
- backref - figure out what matched what, figuring in back references
477
static char * /* == stop (success) or NULL (failure) */
478
backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
479
sopno lev, int rec) /* PLUS nesting level */
482
static const char * /* == stop (success) or NULL (failure) */
483
backref(struct match *m, const char *start, const char *stop, sopno startst,
484
sopno stopst, sopno lev, int rec) /* PLUS nesting level */
482
487
sopno ss; /* start sop of current subRE */
483
char *sp; /* start of string matched by it */
488
const char *sp; /* start of string matched by it */
484
489
sopno ssub; /* start sop of subsubRE */
485
490
sopno esub; /* end sop of subsubRE */
486
char *ssp; /* start of string matched by subsubRE */
491
const char *ssp; /* start of string matched by subsubRE */
675
680
- fast - step through the string at top speed
677
static char * /* where tentative match ended, or NULL */
678
fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
682
static const char * /* where tentative match ended, or NULL */
683
fast(struct match *m, const char *start, const char *stop, sopno startst,
680
686
states st = m->st;
681
687
states fresh = m->fresh;
682
688
states tmp = m->tmp;
689
const char *p = start;
684
690
int c = (start == m->beginp) ? OUT : *(start-1);
685
691
int lastc; /* previous c */
688
char *coldp; /* last p after which no match was underway */
694
const char *coldp; /* last p after which no match was underway */
691
697
SET1(st, startst);
759
765
- slow - step through the string more deliberately
761
static char * /* where it ended */
762
slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
767
static const char * /* where it ended */
768
slow(struct match *m, const char *start, const char *stop, sopno startst,
764
771
states st = m->st;
765
772
states empty = m->empty;
766
773
states tmp = m->tmp;
774
const char *p = start;
768
775
int c = (start == m->beginp) ? OUT : *(start-1);
769
776
int lastc; /* previous c */
772
char *matchp; /* last p at which a match ended */
779
const char *matchp; /* last p at which a match ended */
774
781
AT("slow", start, stop, startst, stopst);