version 1.18, 2004/04/03 17:00:00 |
version 1.22, 2009/02/12 05:06:54 |
|
|
struct re_guts *g; |
struct re_guts *g; |
int eflags; |
int eflags; |
regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ |
regmatch_t *pmatch; /* [nsub+1] (0 element unused) */ |
char *offp; /* offsets work from here */ |
const char *offp; /* offsets work from here */ |
char *beginp; /* start of string -- virtual NUL precedes */ |
const char *beginp; /* start of string -- virtual NUL precedes */ |
char *endp; /* end of string -- virtual NUL here */ |
const char *endp; /* end of string -- virtual NUL here */ |
char *coldp; /* can be no match starting before here */ |
const char *coldp; /* can be no match starting before here */ |
char **lastpos; /* [nplus+1] */ |
const char **lastpos; /* [nplus+1] */ |
STATEVARS; |
STATEVARS; |
states st; /* current states */ |
states st; /* current states */ |
states fresh; /* states for a fresh start */ |
states fresh; /* states for a fresh start */ |
|
|
#endif |
#endif |
|
|
/* === engine.c === */ |
/* === engine.c === */ |
static int matcher __P((struct re_guts *g, char *string, size_t nmatch, regmatch_t pmatch[], int eflags)); |
static int matcher(struct re_guts *g, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); |
static char *dissect __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); |
static const char *dissect(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); |
static char *backref __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno lev)); |
static const char *backref(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst, sopno lev); |
static char *fast __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); |
static const char *fast(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); |
static char *slow __P((struct match *m, char *start, char *stop, sopno startst, sopno stopst)); |
static const char *slow(struct match *m, const char *start, const char *stop, sopno startst, sopno stopst); |
static states step __P((struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft)); |
static states step(struct re_guts *g, sopno start, sopno stop, states bef, int ch, states aft); |
#define BOL (OUT+1) |
#define BOL (OUT+1) |
#define EOL (BOL+1) |
#define EOL (BOL+1) |
#define BOLEOL (BOL+2) |
#define BOLEOL (BOL+2) |
Line 142 static states step __P((struct re_guts * |
|
Line 142 static states step __P((struct re_guts * |
|
#define NONCHAR(c) ((c) > CHAR_MAX) |
#define NONCHAR(c) ((c) > CHAR_MAX) |
#define NNONCHAR (CODEMAX-CHAR_MAX) |
#define NNONCHAR (CODEMAX-CHAR_MAX) |
#ifdef REDEBUG |
#ifdef REDEBUG |
static void print __P((struct match *m, char *caption, states st, int ch, FILE *d)); |
static void print(struct match *m, char *caption, states st, int ch, FILE *d); |
#endif |
#endif |
#ifdef REDEBUG |
#ifdef REDEBUG |
static void at __P((struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst)); |
static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst); |
#endif |
#endif |
#ifdef REDEBUG |
#ifdef REDEBUG |
static char *pchar __P((int ch)); |
static char *pchar(int ch); |
#endif |
#endif |
|
|
#ifdef __cplusplus |
#ifdef __cplusplus |
Line 173 static int nope = 0; |
|
Line 173 static int nope = 0; |
|
== size_t nmatch, regmatch_t pmatch[], int eflags); |
== size_t nmatch, regmatch_t pmatch[], int eflags); |
*/ |
*/ |
static int /* 0 success, REG_NOMATCH failure */ |
static int /* 0 success, REG_NOMATCH failure */ |
matcher(g, string, nmatch, pmatch, eflags) |
matcher( |
struct re_guts *g; |
struct re_guts *g, |
char *string; |
const char *string, |
size_t nmatch; |
size_t nmatch, |
regmatch_t pmatch[]; |
regmatch_t pmatch[], |
int eflags; |
int eflags) |
{ |
{ |
char *endp; |
const char *endp; |
int i; |
size_t i; |
struct match mv; |
struct match mv; |
struct match *m = &mv; |
struct match *m = &mv; |
char *dp; |
const char *dp; |
const sopno gf = g->firststate+1; /* +1 for OEND */ |
const sopno gf = g->firststate+1; /* +1 for OEND */ |
const sopno gl = g->laststate; |
const sopno gl = g->laststate; |
char *start; |
const char *start; |
char *stop; |
const char *stop; |
int error = 0; |
int error = 0; |
|
|
_DIAGASSERT(g != NULL); |
_DIAGASSERT(g != NULL); |
|
|
dp = dissect(m, m->coldp, endp, gf, gl); |
dp = dissect(m, m->coldp, endp, gf, gl); |
} else { |
} else { |
if (g->nplus > 0 && m->lastpos == NULL) |
if (g->nplus > 0 && m->lastpos == NULL) |
m->lastpos = (char **)malloc((g->nplus+1) * |
m->lastpos = malloc((g->nplus+1) * |
sizeof(char *)); |
sizeof(const char *)); |
if (g->nplus > 0 && m->lastpos == NULL) { |
if (g->nplus > 0 && m->lastpos == NULL) { |
error = REG_ESPACE; |
error = REG_ESPACE; |
goto done; |
goto done; |
|
|
|
|
/* |
/* |
- dissect - figure out what matched what, no back references |
- dissect - figure out what matched what, no back references |
== static char *dissect(struct match *m, char *start, \ |
== static const char *dissect(struct match *m, const char *start, \ |
== char *stop, sopno startst, sopno stopst); |
== const char *stop, sopno startst, sopno stopst); |
*/ |
*/ |
static char * /* == stop (success) always */ |
static const char * /* == stop (success) always */ |
dissect(m, start, stop, startst, stopst) |
dissect( |
struct match *m; |
struct match *m, |
char *start; |
const char *start, |
char *stop; |
const char *stop, |
sopno startst; |
sopno startst, |
sopno stopst; |
sopno stopst) |
{ |
{ |
int i; |
int i; |
sopno ss; /* start sop of current subRE */ |
sopno ss; /* start sop of current subRE */ |
sopno es; /* end sop of current subRE */ |
sopno es; /* end sop of current subRE */ |
char *sp; /* start of string matched by it */ |
const char *sp; /* start of string matched by it */ |
char *stp; /* string matched by it cannot pass here */ |
const char *stp; /* string matched by it cannot pass here */ |
char *rest; /* start of rest of string */ |
const char *rest; /* start of rest of string */ |
char *tail; /* string unmatched by rest of RE */ |
const char *tail; /* string unmatched by rest of RE */ |
sopno ssub; /* start sop of subsubRE */ |
sopno ssub; /* start sop of subsubRE */ |
sopno esub; /* end sop of subsubRE */ |
sopno esub; /* end sop of subsubRE */ |
char *ssp; /* start of string matched by subsubRE */ |
const char *ssp; /* start of string matched by subsubRE */ |
char *sep; /* end of string matched by subsubRE */ |
const char *sep; /* end of string matched by subsubRE */ |
char *oldssp; /* previous ssp */ |
const char *oldssp; /* previous ssp */ |
#ifndef NDEBUG |
#ifndef NDEBUG |
char *dp; |
const char *dp; |
#endif |
#endif |
|
|
_DIAGASSERT(m != NULL); |
_DIAGASSERT(m != NULL); |
|
|
|
|
/* |
/* |
- backref - figure out what matched what, figuring in back references |
- backref - figure out what matched what, figuring in back references |
== static char *backref(struct match *m, char *start, \ |
== static const char *backref(struct match *m, const char *start, \ |
== char *stop, sopno startst, sopno stopst, sopno lev); |
== const char *stop, sopno startst, sopno stopst, sopno lev); |
*/ |
*/ |
static char * /* == stop (success) or NULL (failure) */ |
static const char * /* == stop (success) or NULL (failure) */ |
backref(m, start, stop, startst, stopst, lev) |
backref( |
struct match *m; |
struct match *m, |
char *start; |
const char *start, |
char *stop; |
const char *stop, |
sopno startst; |
sopno startst, |
sopno stopst; |
sopno stopst, |
sopno lev; /* PLUS nesting level */ |
sopno lev) /* PLUS nesting level */ |
{ |
{ |
int i; |
int i; |
sopno ss; /* start sop of current subRE */ |
sopno ss; /* start sop of current subRE */ |
char *sp; /* start of string matched by it */ |
const char *sp; /* start of string matched by it */ |
sopno ssub; /* start sop of subsubRE */ |
sopno ssub; /* start sop of subsubRE */ |
sopno esub; /* end sop of subsubRE */ |
sopno esub; /* end sop of subsubRE */ |
char *ssp; /* start of string matched by subsubRE */ |
const char *ssp; /* start of string matched by subsubRE */ |
char *dp; |
const char *dp; |
size_t len; |
size_t len; |
int hard; |
int hard; |
sop s; |
sop s; |
Line 765 sopno lev; /* PLUS nesting level */ |
|
Line 765 sopno lev; /* PLUS nesting level */ |
|
|
|
/* |
/* |
- fast - step through the string at top speed |
- fast - step through the string at top speed |
== static char *fast(struct match *m, char *start, \ |
== static const char *fast(struct match *m, const char *start, \ |
== char *stop, sopno startst, sopno stopst); |
== const char *stop, sopno startst, sopno stopst); |
*/ |
*/ |
static char * /* where tentative match ended, or NULL */ |
static const char * /* where tentative match ended, or NULL */ |
fast(m, start, stop, startst, stopst) |
fast( |
struct match *m; |
struct match *m, |
char *start; |
const char *start, |
char *stop; |
const char *stop, |
sopno startst; |
sopno startst, |
sopno stopst; |
sopno stopst) |
{ |
{ |
states st = m->st; |
states st = m->st; |
states fresh = m->fresh; |
states fresh = m->fresh; |
states tmp = m->tmp; |
states tmp = m->tmp; |
char *p = start; |
const char *p = start; |
int c = (start == m->beginp) ? OUT : *(start-1); |
int c = (start == m->beginp) ? OUT : *(start-1); |
int lastc; /* previous c */ |
int lastc; /* previous c */ |
int flagch; |
int flagch; |
int i; |
int i; |
char *coldp; /* last p after which no match was underway */ |
const char *coldp; /* last p after which no match was underway */ |
|
|
_DIAGASSERT(m != NULL); |
_DIAGASSERT(m != NULL); |
_DIAGASSERT(start != NULL); |
_DIAGASSERT(start != NULL); |
|
|
|
|
/* |
/* |
- slow - step through the string more deliberately |
- slow - step through the string more deliberately |
== static char *slow(struct match *m, char *start, \ |
== static const char *slow(struct match *m, const char *start, \ |
== char *stop, sopno startst, sopno stopst); |
== const char *stop, sopno startst, sopno stopst); |
*/ |
*/ |
static char * /* where it ended */ |
static const char * /* where it ended */ |
slow(m, start, stop, startst, stopst) |
slow( |
struct match *m; |
struct match *m, |
char *start; |
const char *start, |
char *stop; |
const char *stop, |
sopno startst; |
sopno startst, |
sopno stopst; |
sopno stopst) |
{ |
{ |
states st = m->st; |
states st = m->st; |
states empty = m->empty; |
states empty = m->empty; |
states tmp = m->tmp; |
states tmp = m->tmp; |
char *p = start; |
const char *p = start; |
int c = (start == m->beginp) ? OUT : *(start-1); |
int c = (start == m->beginp) ? OUT : *(start-1); |
int lastc; /* previous c */ |
int lastc; /* previous c */ |
int flagch; |
int flagch; |
int i; |
int i; |
char *matchp; /* last p at which a match ended */ |
const char *matchp; /* last p at which a match ended */ |
|
|
_DIAGASSERT(m != NULL); |
_DIAGASSERT(m != NULL); |
_DIAGASSERT(start != NULL); |
_DIAGASSERT(start != NULL); |
|
|
== #define NNONCHAR (CODEMAX-CHAR_MAX) |
== #define NNONCHAR (CODEMAX-CHAR_MAX) |
*/ |
*/ |
static states |
static states |
step(g, start, stop, bef, ch, aft) |
step( |
struct re_guts *g; |
struct re_guts *g, |
sopno start; /* start state within strip */ |
sopno start, /* start state within strip */ |
sopno stop; /* state after stop state within strip */ |
sopno stop, /* state after stop state within strip */ |
states bef; /* states reachable before */ |
states bef, /* states reachable before */ |
int ch; /* character or NONCHAR code */ |
int ch, /* character or NONCHAR code */ |
states aft; /* states already known reachable after */ |
states aft) /* states already known reachable after */ |
{ |
{ |
cset *cs; |
cset *cs; |
sop s; |
sop s; |
Line 1088 states aft; /* states already known rea |
|
Line 1088 states aft; /* states already known rea |
|
== #endif |
== #endif |
*/ |
*/ |
static void |
static void |
print(m, caption, st, ch, d) |
print( |
struct match *m; |
struct match *m, |
char *caption; |
char *caption, |
states st; |
states st, |
int ch; |
int ch, |
FILE *d; |
FILE *d) |
{ |
{ |
struct re_guts *g = m->g; |
struct re_guts *g = m->g; |
int i; |
int i; |
|
|
== #endif |
== #endif |
*/ |
*/ |
static void |
static void |
at(m, title, start, stop, startst, stopst) |
at( |
struct match *m; |
struct match *m, |
char *title; |
char *title, |
char *start; |
char *start, |
char *stop; |
char *stop, |
sopno startst; |
sopno startst, |
sopno stopst; |
sopno stopst) |
{ |
{ |
|
|
_DIAGASSERT(m != NULL); |
_DIAGASSERT(m != NULL); |
|
|
* the non-debug compilation anyway, so it doesn't matter much. |
* the non-debug compilation anyway, so it doesn't matter much. |
*/ |
*/ |
static char * /* -> representation */ |
static char * /* -> representation */ |
pchar(ch) |
pchar( |
int ch; |
int ch) |
{ |
{ |
static char pbuf[10]; |
static char pbuf[10]; |
|
|