1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-02 09:02:37 +03:00

Clean up portability problems in regexp package: change all routine

definitions from K&R to ANSI C style, and fix broken assumption that
int and long are the same datatype.  This repairs problems observed
on Alpha with regexps having between 32 and 63 states.
This commit is contained in:
Tom Lane
2001-02-13 00:02:36 +00:00
parent f4e4c7291e
commit f7a839bc2b
8 changed files with 226 additions and 603 deletions

View File

@ -80,37 +80,26 @@ struct match
pg_wchar *endp; /* end of string -- virtual NUL here */
pg_wchar *coldp; /* can be no match starting before here */
pg_wchar **lastpos; /* [nplus+1] */
STATEVARS;
STATEVARS;
states st; /* current states */
states fresh; /* states for a fresh start */
states tmp; /* temporary */
states empty; /* empty set of states */
};
/* ========= begin header generated by ./mkh ========= */
#ifdef __cplusplus
extern "C"
{
#endif
static int matcher(struct re_guts *g, pg_wchar *string, size_t nmatch,
regmatch_t *pmatch, int eflags);
static pg_wchar *dissect(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst);
static pg_wchar *backref(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst, sopno lev);
static pg_wchar *fast(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst);
static pg_wchar *slow(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst);
static states step(struct re_guts *g, sopno start,
sopno stop, states bef, int ch, states aft);
/* === engine.c === */
static int
matcher(struct re_guts * g, pg_wchar * string, size_t nmatch,
regmatch_t *pmatch, int eflags);
static pg_wchar *
dissect(struct match * m, pg_wchar * start, pg_wchar * stop,
sopno startst, sopno stopst);
static pg_wchar *
backref(struct match * m, pg_wchar * start, pg_wchar * stop,
sopno startst, sopno stopst, sopno lev);
static pg_wchar *
fast(struct match * m, pg_wchar * start, pg_wchar * stop,
sopno startst, sopno stopst);
static pg_wchar *
slow(struct match * m, pg_wchar * start, pg_wchar * stop, sopno startst, sopno stopst);
static states
step(struct re_guts * g, sopno start,
sopno stop, states bef, int ch, states aft);
#define BOL (OUT+1)
#define EOL (BOL+1)
#define BOLEOL (BOL+2)
@ -128,24 +117,13 @@ extern "C"
#endif
#ifdef REDEBUG
static void
print(struct match * m, pg_wchar * caption, states st, int ch, FILE *d);
static void print(struct match *m, pg_wchar *caption, states st, int ch,
FILE *d);
static void at(struct match *m, pg_wchar *title, pg_wchar *start,
pg_wchar *stop, sopno startst, sopno stopst);
static pg_wchar *pchar(int ch);
static int pg_isprint(int c);
#endif
#ifdef REDEBUG
static void
at(struct match * m, pg_wchar * title, pg_wchar * start, pg_wchar * stop,
sopno startst, sopno stopst);
#endif
#ifdef REDEBUG
static pg_wchar *
p_char(int ch);
#endif
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
#ifdef REDEBUG
#define SP(t, s, c) print(m, t, s, c, stdout)
@ -158,17 +136,11 @@ extern "C"
#endif
/*
- matcher - the actual matching engine
== static int matcher(struct re_guts *g, pg_wchar *string, \
== size_t nmatch, regmatch_t *pmatch, int eflags);
* matcher - the actual matching engine
*/
static int /* 0 success, REG_NOMATCH failure */
matcher(g, string, nmatch, pmatch, eflags)
struct re_guts *g;
pg_wchar *string;
size_t nmatch;
regmatch_t *pmatch;
int eflags;
matcher(struct re_guts *g, pg_wchar *string, size_t nmatch,
regmatch_t *pmatch, int eflags)
{
pg_wchar *endp;
int i;
@ -206,10 +178,11 @@ int eflags;
for (dp = start; dp < stop; dp++)
if (*dp == g->must[0] && stop - dp >= g->mlen &&
#ifdef MULTIBYTE
memcmp(dp, g->must, (size_t) (g->mlen * sizeof(pg_wchar))) == 0)
memcmp(dp, g->must, (size_t) (g->mlen * sizeof(pg_wchar))) == 0
#else
memcmp(dp, g->must, (size_t) g->mlen) == 0)
memcmp(dp, g->must, (size_t) g->mlen) == 0
#endif
)
break;
if (dp == stop) /* we didn't find g->must */
return REG_NOMATCH;
@ -349,17 +322,11 @@ int eflags;
}
/*
- dissect - figure out what matched what, no back references
== static char *dissect(struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
* dissect - figure out what matched what, no back references
*/
static pg_wchar * /* == stop (success) always */
dissect(m, start, stop, startst, stopst)
struct match *m;
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
dissect(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst)
{
int i;
sopno ss; /* start sop of current subRE */
@ -549,18 +516,13 @@ sopno stopst;
}
/*
- backref - figure out what matched what, figuring in back references
== static char *backref(struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst, sopno lev);
* backref - figure out what matched what, figuring in back references
*
* lev is PLUS nesting level
*/
static pg_wchar * /* == stop (success) or NULL (failure) */
backref(m, start, stop, startst, stopst, lev)
struct match *m;
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
sopno lev; /* PLUS nesting level */
backref(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst, sopno lev)
{
int i;
sopno ss; /* start sop of current subRE */
@ -763,17 +725,11 @@ sopno lev; /* PLUS nesting level */
}
/*
- fast - step through the string at top speed
== static char *fast(struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
* fast - step through the string at top speed
*/
static pg_wchar * /* where tentative match ended, or NULL */
fast(m, start, stop, startst, stopst)
struct match *m;
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
fast(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst)
{
states st = m->st;
states fresh = m->fresh;
@ -858,17 +814,11 @@ sopno stopst;
}
/*
- slow - step through the string more deliberately
== static char *slow(struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
* slow - step through the string more deliberately
*/
static pg_wchar * /* where it ended */
slow(m, start, stop, startst, stopst)
struct match *m;
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
slow(struct match *m, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst)
{
states st = m->st;
states empty = m->empty;
@ -948,27 +898,15 @@ sopno stopst;
/*
- step - map set of states reachable before char to set reachable after
== static states step(struct re_guts *g, sopno start, sopno stop, \
== states bef, int ch, states aft);
== #define BOL (OUT+1)
== #define EOL (BOL+1)
== #define BOLEOL (BOL+2)
== #define NOTHING (BOL+3)
== #define BOW (BOL+4)
== #define EOW (BOL+5)
== #define CODEMAX (BOL+5) // highest code used
== #define NONCHAR(c) ((c) > CHAR_MAX)
== #define NNONCHAR (CODEMAX-CHAR_MAX)
* step - map set of states reachable before char to set reachable after
*/
static states
step(g, start, stop, bef, ch, aft)
struct re_guts *g;
sopno start; /* start state within strip */
sopno stop; /* state after stop state within strip */
states bef; /* states reachable before */
int ch; /* character or NONCHAR code */
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 ch, /* character or NONCHAR code */
states aft) /* states already known reachable after */
{
cset *cs;
sop s;
@ -1082,19 +1020,11 @@ 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
* print - print a set of states
*/
static void
print(m, caption, st, ch, d)
struct match *m;
pg_wchar *caption;
states st;
int ch;
FILE *d;
print(struct match *m, pg_wchar *caption, states st,
int ch, FILE *d)
{
struct re_guts *g = m->g;
int i;
@ -1116,20 +1046,11 @@ FILE *d;
}
/*
- at - print current situation
== #ifdef REDEBUG
== static void at(struct match *m, pg_wchar *title, pg_wchar *start, pg_wchar *stop, \
== sopno startst, sopno stopst);
== #endif
* at - print current situation
*/
static void
at(m, title, start, stop, startst, stopst)
struct match *m;
pg_wchar *title;
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
at(struct match *m, pg_wchar *title, pg_wchar *start, pg_wchar *stop,
sopno startst, sopno stopst)
{
if (!(m->eflags & REG_TRACE))
return;
@ -1140,19 +1061,26 @@ sopno stopst;
}
#ifndef PCHARDONE
#define PCHARDONE /* never again */
#define PCHARDONE /* only do this once */
/*
- pchar - make a character printable
== #ifdef REDEBUG
== static char *pchar(int ch);
== #endif
* pchar - make a character printable
*
* Is this identical to regchar() over in debug.c? Well, yes. But a
* duplicate here avoids having a debugging-capable regexec.o tied to
* a matching debug.o, and this is convenient. It all disappears in
* the non-debug compilation anyway, so it doesn't matter much.
*/
static pg_wchar * /* -> representation */
pchar(int ch)
{
static pg_wchar pbuf[10];
if (pg_isprint(ch) || ch == ' ')
sprintf(pbuf, "%c", ch);
else
sprintf(pbuf, "\\%o", ch);
return pbuf;
}
static int
pg_isprint(int c)
@ -1164,19 +1092,6 @@ pg_isprint(int c)
#endif
}
static pg_wchar * /* -> representation */
pchar(ch)
int ch;
{
static pg_wchar pbuf[10];
if (pg_isprint(ch) || ch == ' ')
sprintf(pbuf, "%c", ch);
else
sprintf(pbuf, "\\%o", ch);
return pbuf;
}
#endif
#endif