summaryrefslogtreecommitdiff
path: root/regex/engine.c
diff options
context:
space:
mode:
Diffstat (limited to 'regex/engine.c')
-rw-r--r--regex/engine.c248
1 files changed, 91 insertions, 157 deletions
diff --git a/regex/engine.c b/regex/engine.c
index ad1c501067e3c..069a473921c57 100644
--- a/regex/engine.c
+++ b/regex/engine.c
@@ -16,11 +16,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
@@ -92,12 +88,12 @@ extern "C" {
#endif
/* === engine.c === */
-static int matcher __P((struct re_guts *g, const RCHAR_T *string, size_t nmatch, regmatch_t pmatch[], int eflags));
-static const RCHAR_T *dissect __P((struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst));
-static const RCHAR_T *backref __P((struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst, sopno lev));
-static const RCHAR_T *fast __P((struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst));
-static const RCHAR_T *slow __P((struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst));
-static states step __P((struct re_guts *g, sopno start, sopno stop, states bef, int flag, RCHAR_T ch, states aft));
+static int matcher(struct re_guts *g, const RCHAR_T *string, size_t nmatch, regmatch_t pmatch[], int eflags);
+static const RCHAR_T *dissect(struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst);
+static const RCHAR_T *backref(struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst, sopno lev);
+static const RCHAR_T *fast(struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst);
+static const RCHAR_T *slow(struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst, sopno stopst);
+static states step(struct re_guts *g, sopno start, sopno stop, states bef, int flag, RCHAR_T ch, states aft);
#define BOL (1)
#define EOL (BOL+1)
#define BOLEOL (BOL+2)
@@ -105,13 +101,13 @@ static states step __P((struct re_guts *g, sopno start, sopno stop, states bef,
#define BOW (BOL+4)
#define EOW (BOL+5)
#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
#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
#ifdef REDEBUG
-static char *pchar __P((int ch));
+static char *pchar(int ch);
#endif
#ifdef __cplusplus
@@ -131,24 +127,18 @@ static char *pchar __P((int ch));
/*
- matcher - the actual matching engine
- == static int matcher(register struct re_guts *g, const RCHAR_T *string, \
- == size_t nmatch, regmatch_t pmatch[], int eflags);
*/
static int /* 0 success, REG_NOMATCH failure */
-matcher(g, string, nmatch, pmatch, eflags)
-register struct re_guts *g;
-const RCHAR_T *string;
-size_t nmatch;
-regmatch_t pmatch[];
-int eflags;
+matcher(struct re_guts *g, const RCHAR_T *string, size_t nmatch,
+ regmatch_t pmatch[], int eflags)
{
- register const RCHAR_T *endp;
- register size_t i;
+ const RCHAR_T *endp;
+ size_t i;
struct match mv;
- register struct match *m = &mv;
- register const RCHAR_T *dp;
- register const sopno gf = g->firststate+1; /* +1 for OEND */
- register const sopno gl = g->laststate;
+ struct match *m = &mv;
+ const RCHAR_T *dp;
+ const sopno gf = g->firststate+1; /* +1 for OEND */
+ const sopno gl = g->laststate;
const RCHAR_T *start;
const RCHAR_T *stop;
@@ -297,30 +287,24 @@ int eflags;
/*
- dissect - figure out what matched what, no back references
- == static const RCHAR_T *dissect(register struct match *m, const RCHAR_T *start, \
- == const RCHAR_T *stop, sopno startst, sopno stopst);
*/
static const RCHAR_T * /* == stop (success) always */
-dissect(m, start, stop, startst, stopst)
-register struct match *m;
-const RCHAR_T *start;
-const RCHAR_T *stop;
-sopno startst;
-sopno stopst;
+dissect(struct match *m, const RCHAR_T *start, const RCHAR_T *stop,
+ sopno startst, sopno stopst)
{
- register int i;
- register sopno ss; /* start sop of current subRE */
- register sopno es; /* end sop of current subRE */
- register const RCHAR_T *sp; /* start of string matched by it */
- register const RCHAR_T *stp; /* string matched by it cannot pass here */
- register const RCHAR_T *rest; /* start of rest of string */
- register const RCHAR_T *tail; /* string unmatched by rest of RE */
- register sopno ssub; /* start sop of subsubRE */
- register sopno esub; /* end sop of subsubRE */
- register const RCHAR_T *ssp; /* start of string matched by subsubRE */
- register const RCHAR_T *sep; /* end of string matched by subsubRE */
- register const RCHAR_T *oldssp; /* previous ssp */
- register const RCHAR_T *dp;
+ int i;
+ sopno ss; /* start sop of current subRE */
+ sopno es; /* end sop of current subRE */
+ const RCHAR_T *sp; /* start of string matched by it */
+ const RCHAR_T *stp; /* string matched by it cannot pass here */
+ const RCHAR_T *rest; /* start of rest of string */
+ const RCHAR_T *tail; /* string unmatched by rest of RE */
+ sopno ssub; /* start sop of subsubRE */
+ sopno esub; /* end sop of subsubRE */
+ const RCHAR_T *ssp; /* start of string matched by subsubRE */
+ const RCHAR_T *sep; /* end of string matched by subsubRE */
+ const RCHAR_T *oldssp; /* previous ssp */
+ const RCHAR_T *dp;
AT("diss", start, stop, startst, stopst);
sp = start;
@@ -485,31 +469,24 @@ sopno stopst;
/*
- backref - figure out what matched what, figuring in back references
- == static const RCHAR_T *backref(register struct match *m, const RCHAR_T *start, \
- == const RCHAR_T *stop, sopno startst, sopno stopst, sopno lev);
*/
static const RCHAR_T * /* == stop (success) or NULL (failure) */
-backref(m, start, stop, startst, stopst, lev)
-register struct match *m;
-const RCHAR_T *start;
-const RCHAR_T *stop;
-sopno startst;
-sopno stopst;
-sopno lev; /* PLUS nesting level */
+backref(struct match *m, const RCHAR_T *start, const RCHAR_T *stop,
+ sopno startst, sopno stopst, sopno lev) /* PLUS nesting level */
{
- register int i;
- register sopno ss; /* start sop of current subRE */
- register const RCHAR_T *sp; /* start of string matched by it */
- register sopno ssub; /* start sop of subsubRE */
- register sopno esub; /* end sop of subsubRE */
- register const RCHAR_T *ssp; /* start of string matched by subsubRE */
- register const RCHAR_T *dp;
- register size_t len;
- register int hard;
- register sop s;
- register RCHAR_T d;
- register regoff_t offsave;
- register cset *cs;
+ int i;
+ sopno ss; /* start sop of current subRE */
+ const RCHAR_T *sp; /* start of string matched by it */
+ sopno ssub; /* start sop of subsubRE */
+ sopno esub; /* end sop of subsubRE */
+ const RCHAR_T *ssp; /* start of string matched by subsubRE */
+ const RCHAR_T *dp;
+ size_t len;
+ int hard;
+ sop s;
+ RCHAR_T d;
+ regoff_t offsave;
+ cset *cs;
AT("back", start, stop, startst, stopst);
sp = start;
@@ -698,26 +675,20 @@ sopno lev; /* PLUS nesting level */
/*
- fast - step through the string at top speed
- == static const RCHAR_T *fast(register struct match *m, const RCHAR_T *start, \
- == const RCHAR_T *stop, sopno startst, sopno stopst);
*/
static const RCHAR_T * /* where tentative match ended, or NULL */
-fast(m, start, stop, startst, stopst)
-register struct match *m;
-const RCHAR_T *start;
-const RCHAR_T *stop;
-sopno startst;
-sopno stopst;
+fast(struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst,
+ sopno stopst)
{
- register states st = m->st;
- register states fresh = m->fresh;
- register states tmp = m->tmp;
- register const RCHAR_T *p = start;
- register RCHAR_T c = (start == m->beginp) ? OUT : *(start-1);
- register RCHAR_T lastc; /* previous c */
- register int flag;
- register int i;
- register const RCHAR_T *coldp; /* last p after which no match was underway */
+ states st = m->st;
+ states fresh = m->fresh;
+ states tmp = m->tmp;
+ const RCHAR_T *p = start;
+ RCHAR_T c = (start == m->beginp) ? OUT : *(start-1);
+ RCHAR_T lastc; /* previous c */
+ int flag;
+ int i;
+ const RCHAR_T *coldp; /* last p after which no match was underway */
CLEAR(st);
SET1(st, startst);
@@ -789,26 +760,20 @@ sopno stopst;
/*
- slow - step through the string more deliberately
- == static const RCHAR_T *slow(register struct match *m, const RCHAR_T *start, \
- == const RCHAR_T *stop, sopno startst, sopno stopst);
*/
static const RCHAR_T * /* where it ended */
-slow(m, start, stop, startst, stopst)
-register struct match *m;
-const RCHAR_T *start;
-const RCHAR_T *stop;
-sopno startst;
-sopno stopst;
+slow(struct match *m, const RCHAR_T *start, const RCHAR_T *stop, sopno startst,
+ sopno stopst)
{
- register states st = m->st;
- register states empty = m->empty;
- register states tmp = m->tmp;
- register const RCHAR_T *p = start;
- register RCHAR_T c = (start == m->beginp) ? OUT : *(start-1);
- register RCHAR_T lastc; /* previous c */
- register int flag;
- register int i;
- register const RCHAR_T *matchp; /* last p at which a match ended */
+ states st = m->st;
+ states empty = m->empty;
+ states tmp = m->tmp;
+ const RCHAR_T *p = start;
+ RCHAR_T c = (start == m->beginp) ? OUT : *(start-1);
+ RCHAR_T lastc; /* previous c */
+ int flag;
+ int i;
+ const RCHAR_T *matchp; /* last p at which a match ended */
AT("slow", start, stop, startst, stopst);
CLEAR(st);
@@ -876,32 +841,23 @@ sopno stopst;
/*
- step - map set of states reachable before char to set reachable after
- == static states step(register struct re_guts *g, sopno start, sopno stop, \
- == register states bef, int flag, RCHAR_T ch, register states aft);
- == #define BOL (1)
- == #define EOL (BOL+1)
- == #define BOLEOL (BOL+2)
- == #define NOTHING (BOL+3)
- == #define BOW (BOL+4)
- == #define EOW (BOL+5)
*/
static states
-step(g, start, stop, bef, flag, ch, aft)
-register struct re_guts *g;
-sopno start; /* start state within strip */
-sopno stop; /* state after stop state within strip */
-register states bef; /* states reachable before */
-int flag; /* NONCHAR flag */
-RCHAR_T ch; /* character code */
-register states aft; /* states already known reachable after */
+step(struct re_guts *g,
+ sopno start, /* start state within strip */
+ sopno stop, /* state after stop state within strip */
+ states bef, /* states reachable before */
+ int flag, /* NONCHAR flag */
+ RCHAR_T ch, /* character code */
+ states aft) /* states already known reachable after */
{
- register cset *cs;
- register sop s;
- register RCHAR_T d;
- register sopno pc;
- register onestate here; /* note, macros know this name */
- register sopno look;
- register int i;
+ cset *cs;
+ sop s;
+ RCHAR_T d;
+ sopno pc;
+ onestate here; /* note, macros know this name */
+ sopno look;
+ int i;
for (pc = start, INIT(here, pc); pc != stop; pc++, INC(here)) {
s = g->strip[pc];
@@ -1008,22 +964,13 @@ register states aft; /* states already known reachable after */
#ifdef REDEBUG
/*
- print - print a set of states
- == #ifdef REDEBUG
- == static void print(struct match *m, char *caption, states st, \
- == int ch, FILE *d);
- == #endif
*/
static void
-print(m, caption, st, ch, d)
-struct match *m;
-char *caption;
-states st;
-int ch;
-FILE *d;
+print(struct match *m, char *caption, states st, int ch, FILE *d)
{
- register struct re_guts *g = m->g;
- register int i;
- register int first = 1;
+ struct re_guts *g = m->g;
+ int i;
+ int first = 1;
if (!(m->eflags&REG_TRACE))
return;
@@ -1041,19 +988,10 @@ FILE *d;
/*
- at - print current situation
- == #ifdef REDEBUG
- == static void at(struct match *m, char *title, char *start, char *stop, \
- == sopno startst, sopno stopst);
- == #endif
*/
static void
-at(m, title, start, stop, startst, stopst)
-struct match *m;
-char *title;
-char *start;
-char *stop;
-sopno startst;
-sopno stopst;
+at(struct match *m, char *title, char *start, char *stop, sopno startst,
+ sopno stopst)
{
if (!(m->eflags&REG_TRACE))
return;
@@ -1067,9 +1005,6 @@ sopno stopst;
#define PCHARDONE /* never again */
/*
- pchar - make a character printable
- == #ifdef REDEBUG
- == static char *pchar(int ch);
- == #endif
*
* Is this identical to regchar() over in debug.c? Well, yes. But a
* duplicate here avoids having a debugging-capable regexec.o tied to
@@ -1077,8 +1012,7 @@ sopno stopst;
* the non-debug compilation anyway, so it doesn't matter much.
*/
static char * /* -> representation */
-pchar(ch)
-int ch;
+pchar(int ch)
{
static char pbuf[10];