Commit f7a839bc authored by Tom Lane's avatar Tom Lane

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.
parent f4e4c729
...@@ -80,37 +80,26 @@ struct match ...@@ -80,37 +80,26 @@ struct match
pg_wchar *endp; /* end of string -- virtual NUL here */ pg_wchar *endp; /* end of string -- virtual NUL here */
pg_wchar *coldp; /* can be no match starting before here */ pg_wchar *coldp; /* can be no match starting before here */
pg_wchar **lastpos; /* [nplus+1] */ pg_wchar **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 */
states tmp; /* temporary */ states tmp; /* temporary */
states empty; /* empty set of states */ states empty; /* empty set of states */
}; };
/* ========= begin header generated by ./mkh ========= */ static int matcher(struct re_guts *g, pg_wchar *string, size_t nmatch,
#ifdef __cplusplus regmatch_t *pmatch, int eflags);
extern "C" static pg_wchar *dissect(struct match *m, pg_wchar *start, pg_wchar *stop,
{ sopno startst, sopno stopst);
#endif 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 BOL (OUT+1)
#define EOL (BOL+1) #define EOL (BOL+1)
#define BOLEOL (BOL+2) #define BOLEOL (BOL+2)
...@@ -128,24 +117,13 @@ extern "C" ...@@ -128,24 +117,13 @@ extern "C"
#endif #endif
#ifdef REDEBUG #ifdef REDEBUG
static void static void print(struct match *m, pg_wchar *caption, states st, int ch,
print(struct match * m, pg_wchar * caption, states st, int ch, FILE *d); FILE *d);
#endif static void at(struct match *m, pg_wchar *title, pg_wchar *start,
#ifdef REDEBUG pg_wchar *stop, sopno startst, sopno stopst);
static void static pg_wchar *pchar(int ch);
at(struct match * m, pg_wchar * title, pg_wchar * start, pg_wchar * stop, static int pg_isprint(int c);
sopno startst, sopno stopst);
#endif
#ifdef REDEBUG
static pg_wchar *
p_char(int ch);
#endif
#ifdef __cplusplus
}
#endif #endif
/* ========= end header generated by ./mkh ========= */
#ifdef REDEBUG #ifdef REDEBUG
#define SP(t, s, c) print(m, t, s, c, stdout) #define SP(t, s, c) print(m, t, s, c, stdout)
...@@ -158,17 +136,11 @@ extern "C" ...@@ -158,17 +136,11 @@ extern "C"
#endif #endif
/* /*
- matcher - the actual matching engine * matcher - the actual matching engine
== static int matcher(struct re_guts *g, pg_wchar *string, \
== 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, pg_wchar *string, size_t nmatch,
struct re_guts *g; regmatch_t *pmatch, int eflags)
pg_wchar *string;
size_t nmatch;
regmatch_t *pmatch;
int eflags;
{ {
pg_wchar *endp; pg_wchar *endp;
int i; int i;
...@@ -206,10 +178,11 @@ int eflags; ...@@ -206,10 +178,11 @@ int eflags;
for (dp = start; dp < stop; dp++) for (dp = start; dp < stop; dp++)
if (*dp == g->must[0] && stop - dp >= g->mlen && if (*dp == g->must[0] && stop - dp >= g->mlen &&
#ifdef MULTIBYTE #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 #else
memcmp(dp, g->must, (size_t) g->mlen) == 0) memcmp(dp, g->must, (size_t) g->mlen) == 0
#endif #endif
)
break; break;
if (dp == stop) /* we didn't find g->must */ if (dp == stop) /* we didn't find g->must */
return REG_NOMATCH; return REG_NOMATCH;
...@@ -349,17 +322,11 @@ int eflags; ...@@ -349,17 +322,11 @@ int eflags;
} }
/* /*
- 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, \
== char *stop, sopno startst, sopno stopst);
*/ */
static pg_wchar * /* == stop (success) always */ static pg_wchar * /* == stop (success) always */
dissect(m, start, stop, startst, stopst) dissect(struct match *m, pg_wchar *start, pg_wchar *stop,
struct match *m; sopno startst, sopno stopst)
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
{ {
int i; int i;
sopno ss; /* start sop of current subRE */ sopno ss; /* start sop of current subRE */
...@@ -549,18 +516,13 @@ sopno stopst; ...@@ -549,18 +516,13 @@ sopno stopst;
} }
/* /*
- 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, \ *
== char *stop, sopno startst, sopno stopst, sopno lev); * lev is PLUS nesting level
*/ */
static pg_wchar * /* == stop (success) or NULL (failure) */ static pg_wchar * /* == stop (success) or NULL (failure) */
backref(m, start, stop, startst, stopst, lev) backref(struct match *m, pg_wchar *start, pg_wchar *stop,
struct match *m; sopno startst, sopno stopst, sopno lev)
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
sopno lev; /* PLUS nesting level */
{ {
int i; int i;
sopno ss; /* start sop of current subRE */ sopno ss; /* start sop of current subRE */
...@@ -763,17 +725,11 @@ sopno lev; /* PLUS nesting level */ ...@@ -763,17 +725,11 @@ 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, \
== char *stop, sopno startst, sopno stopst);
*/ */
static pg_wchar * /* where tentative match ended, or NULL */ static pg_wchar * /* where tentative match ended, or NULL */
fast(m, start, stop, startst, stopst) fast(struct match *m, pg_wchar *start, pg_wchar *stop,
struct match *m; sopno startst, sopno stopst)
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
{ {
states st = m->st; states st = m->st;
states fresh = m->fresh; states fresh = m->fresh;
...@@ -858,17 +814,11 @@ sopno stopst; ...@@ -858,17 +814,11 @@ sopno stopst;
} }
/* /*
- slow - step through the string more deliberately * slow - step through the string more deliberately
== static char *slow(struct match *m, char *start, \
== char *stop, sopno startst, sopno stopst);
*/ */
static pg_wchar * /* where it ended */ static pg_wchar * /* where it ended */
slow(m, start, stop, startst, stopst) slow(struct match *m, pg_wchar *start, pg_wchar *stop,
struct match *m; sopno startst, sopno stopst)
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
{ {
states st = m->st; states st = m->st;
states empty = m->empty; states empty = m->empty;
...@@ -948,27 +898,15 @@ sopno stopst; ...@@ -948,27 +898,15 @@ sopno stopst;
/* /*
- step - map set of states reachable before char to set reachable after * 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)
*/ */
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;
...@@ -1082,19 +1020,11 @@ states aft; /* states already known reachable after */ ...@@ -1082,19 +1020,11 @@ states aft; /* states already known reachable after */
#ifdef REDEBUG #ifdef REDEBUG
/* /*
- print - print a set of states * 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 static void
print(m, caption, st, ch, d) print(struct match *m, pg_wchar *caption, states st,
struct match *m; int ch, FILE *d)
pg_wchar *caption;
states st;
int ch;
FILE *d;
{ {
struct re_guts *g = m->g; struct re_guts *g = m->g;
int i; int i;
...@@ -1116,20 +1046,11 @@ FILE *d; ...@@ -1116,20 +1046,11 @@ FILE *d;
} }
/* /*
- at - print current situation * 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
*/ */
static void static void
at(m, title, start, stop, startst, stopst) at(struct match *m, pg_wchar *title, pg_wchar *start, pg_wchar *stop,
struct match *m; sopno startst, sopno stopst)
pg_wchar *title;
pg_wchar *start;
pg_wchar *stop;
sopno startst;
sopno stopst;
{ {
if (!(m->eflags & REG_TRACE)) if (!(m->eflags & REG_TRACE))
return; return;
...@@ -1140,19 +1061,26 @@ sopno stopst; ...@@ -1140,19 +1061,26 @@ sopno stopst;
} }
#ifndef PCHARDONE #ifndef PCHARDONE
#define PCHARDONE /* never again */ #define PCHARDONE /* only do this once */
/* /*
- pchar - make a character printable * 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 * Is this identical to regchar() over in debug.c? Well, yes. But a
* duplicate here avoids having a debugging-capable regexec.o tied to * duplicate here avoids having a debugging-capable regexec.o tied to
* a matching debug.o, and this is convenient. It all disappears in * a matching debug.o, and this is convenient. It all disappears in
* the non-debug compilation anyway, so it doesn't matter much. * 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 static int
pg_isprint(int c) pg_isprint(int c)
...@@ -1164,19 +1092,6 @@ pg_isprint(int c) ...@@ -1164,19 +1092,6 @@ pg_isprint(int c)
#endif #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
#endif #endif
......
...@@ -37,19 +37,11 @@ ...@@ -37,19 +37,11 @@
* @(#)regcomp.c 8.5 (Berkeley) 3/20/94 * @(#)regcomp.c 8.5 (Berkeley) 3/20/94
*/ */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include "postgres.h" #include "postgres.h"
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "regex/regex.h" #include "regex/regex.h"
...@@ -78,64 +70,51 @@ struct parse ...@@ -78,64 +70,51 @@ struct parse
sopno pend[NPAREN]; /* -> ) ([0] unused) */ sopno pend[NPAREN]; /* -> ) ([0] unused) */
}; };
/* ========= begin header generated by ./mkh ========= */ static void p_ere(struct parse * p, int stop);
#ifdef __cplusplus static void p_ere_exp(struct parse * p);
extern "C" static void p_str(struct parse * p);
{ static void p_bre(struct parse * p, int end1, int end2);
#endif static int p_simp_re(struct parse * p, int starordinary);
static int p_count(struct parse * p);
/* === regcomp.c === */ static void p_bracket(struct parse * p);
static void p_ere(struct parse * p, int stop); static void p_b_term(struct parse * p, cset *cs);
static void p_ere_exp(struct parse * p); static void p_b_cclass(struct parse * p, cset *cs);
static void p_str(struct parse * p); static void p_b_eclass(struct parse * p, cset *cs);
static void p_bre(struct parse * p, int end1, int end2); static pg_wchar p_b_symbol(struct parse * p);
static int p_simp_re(struct parse * p, int starordinary); static char p_b_coll_elem(struct parse * p, int endc);
static int p_count(struct parse * p);
static void p_bracket(struct parse * p);
static void p_b_term(struct parse * p, cset *cs);
static void p_b_cclass(struct parse * p, cset *cs);
static void p_b_eclass(struct parse * p, cset *cs);
static pg_wchar p_b_symbol(struct parse * p);
static char p_b_coll_elem(struct parse * p, int endc);
#ifdef MULTIBYTE #ifdef MULTIBYTE
static unsigned char othercase(int ch); static unsigned char othercase(int ch);
#else #else
static char othercase(int ch); static char othercase(int ch);
#endif
static void bothcases(struct parse * p, int ch);
static void ordinary(struct parse * p, int ch);
static void nonnewline(struct parse * p);
static void repeat(struct parse * p, sopno start, int from, int to);
static int seterr(struct parse * p, int e);
static cset *allocset(struct parse * p);
static void freeset(struct parse * p, cset *cs);
static int freezeset(struct parse * p, cset *cs);
static int firstch(struct parse * p, cset *cs);
static int nch(struct parse * p, cset *cs);
static void mcadd(struct parse * p, cset *cs, char *cp);
static void mcinvert(struct parse * p, cset *cs);
static void mccase(struct parse * p, cset *cs);
static int isinsets(struct re_guts * g, int c);
static int samesets(struct re_guts * g, int c1, int c2);
static void categorize(struct parse * p, struct re_guts * g);
static sopno dupl(struct parse * p, sopno start, sopno finish);
static void doemit(struct parse * p, sop op, size_t opnd);
static void doinsert(struct parse * p, sop op, size_t opnd, sopno pos);
static void dofwd(struct parse * p, sopno pos, sop value);
static void enlarge(struct parse * p, sopno size);
static void stripsnug(struct parse * p, struct re_guts * g);
static void findmust(struct parse * p, struct re_guts * g);
static sopno pluscount(struct parse * p, struct re_guts * g);
static int pg_isdigit(int c);
static int pg_isalpha(int c);
static int pg_isupper(int c);
static int pg_islower(int c);
#ifdef __cplusplus
}
#endif #endif
/* ========= end header generated by ./mkh ========= */ static void bothcases(struct parse * p, int ch);
static void ordinary(struct parse * p, int ch);
static void nonnewline(struct parse * p);
static void repeat(struct parse * p, sopno start, int from, int to);
static int seterr(struct parse * p, int e);
static cset *allocset(struct parse * p);
static void freeset(struct parse * p, cset *cs);
static int freezeset(struct parse * p, cset *cs);
static int firstch(struct parse * p, cset *cs);
static int nch(struct parse * p, cset *cs);
static void mcadd(struct parse * p, cset *cs, char *cp);
static void mcinvert(struct parse * p, cset *cs);
static void mccase(struct parse * p, cset *cs);
static int isinsets(struct re_guts * g, int c);
static int samesets(struct re_guts * g, int c1, int c2);
static void categorize(struct parse * p, struct re_guts * g);
static sopno dupl(struct parse * p, sopno start, sopno finish);
static void doemit(struct parse * p, sop op, size_t opnd);
static void doinsert(struct parse * p, sop op, size_t opnd, sopno pos);
static void dofwd(struct parse * p, sopno pos, sop value);
static void enlarge(struct parse * p, sopno size);
static void stripsnug(struct parse * p, struct re_guts * g);
static void findmust(struct parse * p, struct re_guts * g);
static sopno pluscount(struct parse * p, struct re_guts * g);
static int pg_isdigit(int c);
static int pg_isalpha(int c);
static int pg_isupper(int c);
static int pg_islower(int c);
static pg_wchar nuls[10]; /* place to point scanner in event of static pg_wchar nuls[10]; /* place to point scanner in event of
* error */ * error */
...@@ -178,22 +157,10 @@ static int never = 0; /* for use in asserts; shuts lint up */ ...@@ -178,22 +157,10 @@ static int never = 0; /* for use in asserts; shuts lint up */
#endif #endif
/* /*
- regcomp - interface for parser and compilation * regcomp - interface for parser and compilation
= extern int regcomp(regex_t *, const char *, int);
= #define REG_BASIC 0000
= #define REG_EXTENDED 0001
= #define REG_ICASE 0002
= #define REG_NOSUB 0004
= #define REG_NEWLINE 0010
= #define REG_NOSPEC 0020
= #define REG_PEND 0040
= #define REG_DUMP 0200
*/ */
int /* 0 success, otherwise REG_something */ int /* 0 success, otherwise REG_something */
pg95_regcomp(preg, pattern, cflags) pg95_regcomp(regex_t *preg, const char *pattern, int cflags)
regex_t *preg;
const char *pattern;
int cflags;
{ {
struct parse pa; struct parse pa;
struct re_guts *g; struct re_guts *g;
...@@ -325,13 +292,11 @@ int cflags; ...@@ -325,13 +292,11 @@ int cflags;
} }
/* /*
- p_ere - ERE parser top level, concatenation and alternation * p_ere - ERE parser top level, concatenation and alternation
== static void p_ere(struct parse *p, int stop);
*/ */
static void static void
p_ere(p, stop) p_ere(struct parse *p,
struct parse *p; int stop) /* character this ERE should end at */
int stop; /* character this ERE should end at */
{ {
char c; char c;
sopno prevback = 0; sopno prevback = 0;
...@@ -374,12 +339,10 @@ int stop; /* character this ERE should end at */ ...@@ -374,12 +339,10 @@ int stop; /* character this ERE should end at */
} }
/* /*
- p_ere_exp - parse one subERE, an atom possibly followed by a repetition op * p_ere_exp - parse one subERE, an atom possibly followed by a repetition op
== static void p_ere_exp(struct parse *p);
*/ */
static void static void
p_ere_exp(p) p_ere_exp(struct parse *p)
struct parse *p;
{ {
pg_wchar c; pg_wchar c;
sopno pos; sopno pos;
...@@ -535,12 +498,10 @@ struct parse *p; ...@@ -535,12 +498,10 @@ struct parse *p;
} }
/* /*
- p_str - string (no metacharacters) "parser" * p_str - string (no metacharacters) "parser"
== static void p_str(struct parse *p);
*/ */
static void static void
p_str(p) p_str(struct parse *p)
struct parse *p;
{ {
REQUIRE(MORE(), REG_EMPTY); REQUIRE(MORE(), REG_EMPTY);
while (MORE()) while (MORE())
...@@ -548,9 +509,8 @@ struct parse *p; ...@@ -548,9 +509,8 @@ struct parse *p;
} }
/* /*
- p_bre - BRE parser top level, anchoring and concatenation * p_bre - BRE parser top level, anchoring and concatenation
== static void p_bre(struct parse *p, int end1, \ *
== int end2);
* Giving end1 as OUT essentially eliminates the end1/end2 check. * Giving end1 as OUT essentially eliminates the end1/end2 check.
* *
* This implementation is a bit of a kludge, in that a trailing $ is first * This implementation is a bit of a kludge, in that a trailing $ is first
...@@ -560,10 +520,9 @@ struct parse *p; ...@@ -560,10 +520,9 @@ struct parse *p;
* The amount of lookahead needed to avoid this kludge is excessive. * The amount of lookahead needed to avoid this kludge is excessive.
*/ */
static void static void
p_bre(p, end1, end2) p_bre(struct parse *p,
struct parse *p; int end1, /* first terminating character */
int end1; /* first terminating character */ int end2) /* second terminating character */
int end2; /* second terminating character */
{ {
sopno start = HERE(); sopno start = HERE();
int first = 1; /* first subexpression? */ int first = 1; /* first subexpression? */
...@@ -592,13 +551,11 @@ int end2; /* second terminating character */ ...@@ -592,13 +551,11 @@ int end2; /* second terminating character */
} }
/* /*
- p_simp_re - parse a simple RE, an atom possibly followed by a repetition * p_simp_re - parse a simple RE, an atom possibly followed by a repetition
== static int p_simp_re(struct parse *p, int starordinary);
*/ */
static int /* was the simple RE an unbackslashed $? */ static int /* was the simple RE an unbackslashed $? */
p_simp_re(p, starordinary) p_simp_re(struct parse *p,
struct parse *p; int starordinary) /* is a leading * an ordinary character? */
int starordinary; /* is a leading * an ordinary character? */
{ {
int c; int c;
int count; int count;
...@@ -731,12 +688,10 @@ int starordinary; /* is a leading * an ordinary character? */ ...@@ -731,12 +688,10 @@ int starordinary; /* is a leading * an ordinary character? */
} }
/* /*
- p_count - parse a repetition count * p_count - parse a repetition count
== static int p_count(struct parse *p);
*/ */
static int /* the value */ static int /* the value */
p_count(p) p_count(struct parse *p)
struct parse *p;
{ {
int count = 0; int count = 0;
int ndigits = 0; int ndigits = 0;
...@@ -752,15 +707,13 @@ struct parse *p; ...@@ -752,15 +707,13 @@ struct parse *p;
} }
/* /*
- p_bracket - parse a bracketed character list * p_bracket - parse a bracketed character list
== static void p_bracket(struct parse *p);
* *
* Note a significant property of this code: if the allocset() did SETERROR, * Note a significant property of this code: if the allocset() did SETERROR,
* no set operations are done. * no set operations are done.
*/ */
static void static void
p_bracket(p) p_bracket(struct parse *p)
struct parse *p;
{ {
cset *cs = allocset(p); cset *cs = allocset(p);
int invert = 0; int invert = 0;
...@@ -850,13 +803,10 @@ struct parse *p; ...@@ -850,13 +803,10 @@ struct parse *p;
} }
/* /*
- p_b_term - parse one term of a bracketed character list * p_b_term - parse one term of a bracketed character list
== static void p_b_term(struct parse *p, cset *cs);
*/ */
static void static void
p_b_term(p, cs) p_b_term(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
pg_wchar c; pg_wchar c;
pg_wchar start, pg_wchar start,
...@@ -925,13 +875,10 @@ cset *cs; ...@@ -925,13 +875,10 @@ cset *cs;
} }
/* /*
- p_b_cclass - parse a character-class name and deal with it * p_b_cclass - parse a character-class name and deal with it
== static void p_b_cclass(struct parse *p, cset *cs);
*/ */
static void static void
p_b_cclass(p, cs) p_b_cclass(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
pg_wchar *sp = p->next; pg_wchar *sp = p->next;
struct cclass *cp; struct cclass *cp;
...@@ -964,15 +911,12 @@ cset *cs; ...@@ -964,15 +911,12 @@ cset *cs;
} }
/* /*
- p_b_eclass - parse an equivalence-class name and deal with it * p_b_eclass - parse an equivalence-class name and deal with it
== static void p_b_eclass(struct parse *p, cset *cs);
* *
* This implementation is incomplete. xxx * This implementation is incomplete. xxx
*/ */
static void static void
p_b_eclass(p, cs) p_b_eclass(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
char c; char c;
...@@ -981,12 +925,10 @@ cset *cs; ...@@ -981,12 +925,10 @@ cset *cs;
} }
/* /*
- p_b_symbol - parse a character or [..]ed multicharacter collating symbol * p_b_symbol - parse a character or [..]ed multicharacter collating symbol
== static char p_b_symbol(struct parse *p);
*/ */
static pg_wchar /* value of symbol */ static pg_wchar /* value of symbol */
p_b_symbol(p) p_b_symbol(struct parse *p)
struct parse *p;
{ {
pg_wchar value; pg_wchar value;
...@@ -1001,13 +943,10 @@ struct parse *p; ...@@ -1001,13 +943,10 @@ struct parse *p;
} }
/* /*
- p_b_coll_elem - parse a collating-element name and look it up * p_b_coll_elem - parse a collating-element name and look it up
== static char p_b_coll_elem(struct parse *p, int endc);
*/ */
static char /* value of collating element */ static char /* value of collating element */
p_b_coll_elem(p, endc) p_b_coll_elem(struct parse *p, int endc)
struct parse *p;
int endc; /* name ended by endc,']' */
{ {
pg_wchar *sp = p->next; pg_wchar *sp = p->next;
struct cname *cp; struct cname *cp;
...@@ -1035,16 +974,14 @@ int endc; /* name ended by endc,']' */ ...@@ -1035,16 +974,14 @@ int endc; /* name ended by endc,']' */
} }
/* /*
- othercase - return the case counterpart of an alphabetic * othercase - return the case counterpart of an alphabetic
== static char othercase(int ch);
*/ */
#ifdef MULTIBYTE #ifdef MULTIBYTE
static unsigned char /* if no counterpart, return ch */ static unsigned char /* if no counterpart, return ch */
#else #else
static char /* if no counterpart, return ch */ static char /* if no counterpart, return ch */
#endif #endif
othercase(ch) othercase(int ch)
int ch;
{ {
assert(pg_isalpha(ch)); assert(pg_isalpha(ch));
if (pg_isupper(ch)) if (pg_isupper(ch))
...@@ -1069,15 +1006,12 @@ int ch; ...@@ -1069,15 +1006,12 @@ int ch;
} }
/* /*
- bothcases - emit a dualcase version of a two-case character * bothcases - emit a dualcase version of a two-case character
== static void bothcases(struct parse *p, int ch);
* *
* Boy, is this implementation ever a kludge... * Boy, is this implementation ever a kludge...
*/ */
static void static void
bothcases(p, ch) bothcases(struct parse *p, int ch)
struct parse *p;
int ch;
{ {
pg_wchar *oldnext = p->next; pg_wchar *oldnext = p->next;
pg_wchar *oldend = p->end; pg_wchar *oldend = p->end;
...@@ -1096,13 +1030,10 @@ int ch; ...@@ -1096,13 +1030,10 @@ int ch;
} }
/* /*
- ordinary - emit an ordinary character * ordinary - emit an ordinary character
== static void ordinary(struct parse *p, int ch);
*/ */
static void static void
ordinary(p, ch) ordinary(struct parse *p, int ch)
struct parse *p;
int ch;
{ {
cat_t *cap = p->g->categories; cat_t *cap = p->g->categories;
...@@ -1121,14 +1052,12 @@ int ch; ...@@ -1121,14 +1052,12 @@ int ch;
} }
/* /*
- nonnewline - emit REG_NEWLINE version of OANY * nonnewline - emit REG_NEWLINE version of OANY
== static void nonnewline(struct parse *p);
* *
* Boy, is this implementation ever a kludge... * Boy, is this implementation ever a kludge...
*/ */
static void static void
nonnewline(p) nonnewline(struct parse *p)
struct parse *p;
{ {
pg_wchar *oldnext = p->next; pg_wchar *oldnext = p->next;
pg_wchar *oldend = p->end; pg_wchar *oldend = p->end;
...@@ -1147,15 +1076,13 @@ struct parse *p; ...@@ -1147,15 +1076,13 @@ struct parse *p;
} }
/* /*
- repeat - generate code for a bounded repetition, recursively if needed * repeat - generate code for a bounded repetition, recursively if needed
== static void repeat(struct parse *p, sopno start, int from, int to);
*/ */
static void static void
repeat(p, start, from, to) repeat(struct parse *p,
struct parse *p; sopno start, /* operand from here to end of strip */
sopno start; /* operand from here to end of strip */ int from, /* repeated from this number */
int from; /* repeated from this number */ int to) /* to this number of times (maybe
int to; /* to this number of times (maybe
* INFINITY) */ * INFINITY) */
{ {
sopno finish = HERE(); sopno finish = HERE();
...@@ -1222,13 +1149,10 @@ int to; /* to this number of times (maybe ...@@ -1222,13 +1149,10 @@ int to; /* to this number of times (maybe
} }
/* /*
- seterr - set an error condition * seterr - set an error condition
== static int seterr(struct parse *p, int e);
*/ */
static int /* useless but makes type checking happy */ static int /* useless but makes type checking happy */
seterr(p, e) seterr(struct parse *p, int e)
struct parse *p;
int e;
{ {
if (p->error == 0) /* keep earliest error condition */ if (p->error == 0) /* keep earliest error condition */
p->error = e; p->error = e;
...@@ -1238,12 +1162,10 @@ int e; ...@@ -1238,12 +1162,10 @@ int e;
} }
/* /*
- allocset - allocate a set of characters for [] * allocset - allocate a set of characters for []
== static cset *allocset(struct parse *p);
*/ */
static cset * static cset *
allocset(p) allocset(struct parse *p)
struct parse *p;
{ {
int no = p->g->ncsets++; int no = p->g->ncsets++;
size_t nc; size_t nc;
...@@ -1296,13 +1218,10 @@ struct parse *p; ...@@ -1296,13 +1218,10 @@ struct parse *p;
} }
/* /*
- freeset - free a now-unused set * freeset - free a now-unused set
== static void freeset(struct parse *p, cset *cs);
*/ */
static void static void
freeset(p, cs) freeset(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
int i; int i;
cset *top = &p->g->sets[p->g->ncsets]; cset *top = &p->g->sets[p->g->ncsets];
...@@ -1315,8 +1234,7 @@ cset *cs; ...@@ -1315,8 +1234,7 @@ cset *cs;
} }
/* /*
- freezeset - final processing on a set of characters * freezeset - final processing on a set of characters
== static int freezeset(struct parse *p, cset *cs);
* *
* The main task here is merging identical sets. This is usually a waste * The main task here is merging identical sets. This is usually a waste
* of time (although the hash code minimizes the overhead), but can win * of time (although the hash code minimizes the overhead), but can win
...@@ -1325,9 +1243,7 @@ cset *cs; ...@@ -1325,9 +1243,7 @@ cset *cs;
* the same value! * the same value!
*/ */
static int /* set number */ static int /* set number */
freezeset(p, cs) freezeset(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
uch h = cs->hash; uch h = cs->hash;
int i; int i;
...@@ -1357,13 +1273,10 @@ cset *cs; ...@@ -1357,13 +1273,10 @@ cset *cs;
} }
/* /*
- firstch - return first character in a set (which must have at least one) * firstch - return first character in a set (which must have at least one)
== static int firstch(struct parse *p, cset *cs);
*/ */
static int /* character; there is no "none" value */ static int /* character; there is no "none" value */
firstch(p, cs) firstch(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
int i; int i;
size_t css = (size_t) p->g->csetsize; size_t css = (size_t) p->g->csetsize;
...@@ -1376,13 +1289,10 @@ cset *cs; ...@@ -1376,13 +1289,10 @@ cset *cs;
} }
/* /*
- nch - number of characters in a set * nch - number of characters in a set
== static int nch(struct parse *p, cset *cs);
*/ */
static int static int
nch(p, cs) nch(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
int i; int i;
size_t css = (size_t) p->g->csetsize; size_t css = (size_t) p->g->csetsize;
...@@ -1395,15 +1305,10 @@ cset *cs; ...@@ -1395,15 +1305,10 @@ cset *cs;
} }
/* /*
- mcadd - add a collating element to a cset * mcadd - add a collating element to a cset
== static void mcadd(struct parse *p, cset *cs, \
== char *cp);
*/ */
static void static void
mcadd(p, cs, cp) mcadd(struct parse *p, cset *cs, char *cp)
struct parse *p;
cset *cs;
char *cp;
{ {
size_t oldend = cs->smultis; size_t oldend = cs->smultis;
...@@ -1423,106 +1328,34 @@ char *cp; ...@@ -1423,106 +1328,34 @@ char *cp;
} }
/* /*
- mcsub - subtract a collating element from a cset * mcinvert - invert the list of collating elements in a cset
== static void mcsub(cset *cs, char *cp);
*/
/*
static void
mcsub(cs, cp)
cset *cs;
char *cp;
{
char *fp = mcfind(cs, cp);
size_t len = strlen(fp);
assert(fp != NULL);
memmove(fp, fp + len + 1,
cs->smultis - (fp + len + 1 - cs->multis));
cs->smultis -= len;
if (cs->smultis == 0) {
free(cs->multis);
cs->multis = NULL;
return;
}
cs->multis = realloc(cs->multis, cs->smultis);
assert(cs->multis != NULL);
}
*/
/*
- mcin - is a collating element in a cset?
== static int mcin(cset *cs, char *cp);
*/
/*
static int
mcin(cs, cp)
cset *cs;
char *cp;
{
return(mcfind(cs, cp) != NULL);
}
*/
/*
- mcfind - find a collating element in a cset
== static char *mcfind(cset *cs, char *cp);
*/
/*
static char *
mcfind(cs, cp)
cset *cs;
char *cp;
{
char *p;
if (cs->multis == NULL)
return(NULL);
for (p = cs->multis; *p != '\0'; p += strlen(p) + 1)
if (strcmp(cp, p) == 0)
return(p);
return(NULL);
}
*/
/*
- mcinvert - invert the list of collating elements in a cset
== static void mcinvert(struct parse *p, cset *cs);
* *
* This would have to know the set of possibilities. Implementation * This would have to know the set of possibilities. Implementation
* is deferred. * is deferred.
*/ */
static void static void
mcinvert(p, cs) mcinvert(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
assert(cs->multis == NULL); /* xxx */ assert(cs->multis == NULL); /* xxx */
} }
/* /*
- mccase - add case counterparts of the list of collating elements in a cset * mccase - add case counterparts of the list of collating elements in a cset
== static void mccase(struct parse *p, cset *cs);
* *
* This would have to know the set of possibilities. Implementation * This would have to know the set of possibilities. Implementation
* is deferred. * is deferred.
*/ */
static void static void
mccase(p, cs) mccase(struct parse *p, cset *cs)
struct parse *p;
cset *cs;
{ {
assert(cs->multis == NULL); /* xxx */ assert(cs->multis == NULL); /* xxx */
} }
/* /*
- isinsets - is this character in any sets? * isinsets - is this character in any sets?
== static int isinsets(struct re_guts *g, int c);
*/ */
static int /* predicate */ static int /* predicate */
isinsets(g, c) isinsets(struct re_guts *g, int c)
struct re_guts *g;
int c;
{ {
uch *col; uch *col;
int i; int i;
...@@ -1536,14 +1369,10 @@ int c; ...@@ -1536,14 +1369,10 @@ int c;
} }
/* /*
- samesets - are these two characters in exactly the same sets? * samesets - are these two characters in exactly the same sets?
== static int samesets(struct re_guts *g, int c1, int c2);
*/ */
static int /* predicate */ static int /* predicate */
samesets(g, c1, c2) samesets(struct re_guts *g, int c1, int c2)
struct re_guts *g;
int c1;
int c2;
{ {
uch *col; uch *col;
int i; int i;
...@@ -1558,13 +1387,10 @@ int c2; ...@@ -1558,13 +1387,10 @@ int c2;
} }
/* /*
- categorize - sort out character categories * categorize - sort out character categories
== static void categorize(struct parse *p, struct re_guts *g);
*/ */
static void static void
categorize(p, g) categorize(struct parse *p, struct re_guts *g)
struct parse *p;
struct re_guts *g;
{ {
cat_t *cats = g->categories; cat_t *cats = g->categories;
int c; int c;
...@@ -1587,14 +1413,12 @@ struct re_guts *g; ...@@ -1587,14 +1413,12 @@ struct re_guts *g;
} }
/* /*
- dupl - emit a duplicate of a bunch of sops * dupl - emit a duplicate of a bunch of sops
== static sopno dupl(struct parse *p, sopno start, sopno finish);
*/ */
static sopno /* start of duplicate */ static sopno /* start of duplicate */
dupl(p, start, finish) dupl(struct parse *p,
struct parse *p; sopno start, /* from here */
sopno start; /* from here */ sopno finish) /* to this less one */
sopno finish; /* to this less one */
{ {
sopno ret = HERE(); sopno ret = HERE();
sopno len = finish - start; sopno len = finish - start;
...@@ -1611,18 +1435,14 @@ sopno finish; /* to this less one */ ...@@ -1611,18 +1435,14 @@ sopno finish; /* to this less one */
} }
/* /*
- doemit - emit a strip operator * doemit - emit a strip operator
== static void doemit(struct parse *p, sop op, size_t opnd);
* *
* It might seem better to implement this as a macro with a function as * It might seem better to implement this as a macro with a function as
* hard-case backup, but it's just too big and messy unless there are * hard-case backup, but it's just too big and messy unless there are
* some changes to the data structures. Maybe later. * some changes to the data structures. Maybe later.
*/ */
static void static void
doemit(p, op, opnd) doemit(struct parse *p, sop op, size_t opnd)
struct parse *p;
sop op;
size_t opnd;
{ {
/* avoid making error situations worse */ /* avoid making error situations worse */
if (p->error != 0) if (p->error != 0)
...@@ -1641,15 +1461,10 @@ size_t opnd; ...@@ -1641,15 +1461,10 @@ size_t opnd;
} }
/* /*
- doinsert - insert a sop into the strip * doinsert - insert a sop into the strip
== static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos);
*/ */
static void static void
doinsert(p, op, opnd, pos) doinsert(struct parse *p, sop op, size_t opnd, sopno pos)
struct parse *p;
sop op;
size_t opnd;
sopno pos;
{ {
sopno sn; sopno sn;
sop s; sop s;
...@@ -1680,14 +1495,10 @@ sopno pos; ...@@ -1680,14 +1495,10 @@ sopno pos;
} }
/* /*
- dofwd - complete a forward reference * dofwd - complete a forward reference
== static void dofwd(struct parse *p, sopno pos, sop value);
*/ */
static void static void
dofwd(p, pos, value) dofwd(struct parse *p, sopno pos, sop value)
struct parse *p;
sopno pos;
sop value;
{ {
/* avoid making error situations worse */ /* avoid making error situations worse */
if (p->error != 0) if (p->error != 0)
...@@ -1698,13 +1509,10 @@ sop value; ...@@ -1698,13 +1509,10 @@ sop value;
} }
/* /*
- enlarge - enlarge the strip * enlarge - enlarge the strip
== static void enlarge(struct parse *p, sopno size);
*/ */
static void static void
enlarge(p, size) enlarge(struct parse *p, sopno size)
struct parse *p;
sopno size;
{ {
sop *sp; sop *sp;
...@@ -1722,13 +1530,10 @@ sopno size; ...@@ -1722,13 +1530,10 @@ sopno size;
} }
/* /*
- stripsnug - compact the strip * stripsnug - compact the strip
== static void stripsnug(struct parse *p, struct re_guts *g);
*/ */
static void static void
stripsnug(p, g) stripsnug(struct parse *p, struct re_guts *g)
struct parse *p;
struct re_guts *g;
{ {
g->nstates = p->slen; g->nstates = p->slen;
g->strip = (sop *) realloc((char *) p->strip, p->slen * sizeof(sop)); g->strip = (sop *) realloc((char *) p->strip, p->slen * sizeof(sop));
...@@ -1740,8 +1545,7 @@ struct re_guts *g; ...@@ -1740,8 +1545,7 @@ struct re_guts *g;
} }
/* /*
- findmust - fill in must and mlen with longest mandatory literal string * findmust - fill in must and mlen with longest mandatory literal string
== static void findmust(struct parse *p, struct re_guts *g);
* *
* This algorithm could do fancy things like analyzing the operands of | * This algorithm could do fancy things like analyzing the operands of |
* for common subsequences. Someday. This code is simple and finds most * for common subsequences. Someday. This code is simple and finds most
...@@ -1750,9 +1554,7 @@ struct re_guts *g; ...@@ -1750,9 +1554,7 @@ struct re_guts *g;
* Note that must and mlen got initialized during setup. * Note that must and mlen got initialized during setup.
*/ */
static void static void
findmust(p, g) findmust(struct parse *p, struct re_guts *g)
struct parse *p;
struct re_guts *g;
{ {
sop *scan; sop *scan;
sop *start = 0; sop *start = 0;
...@@ -1838,13 +1640,10 @@ struct re_guts *g; ...@@ -1838,13 +1640,10 @@ struct re_guts *g;
} }
/* /*
- pluscount - count + nesting * pluscount - count + nesting
== static sopno pluscount(struct parse *p, struct re_guts *g);
*/ */
static sopno /* nesting depth */ static sopno /* nesting depth */
pluscount(p, g) pluscount(struct parse *p, struct re_guts *g)
struct parse *p;
struct re_guts *g;
{ {
sop *scan; sop *scan;
sop s; sop s;
...@@ -1876,7 +1675,7 @@ struct re_guts *g; ...@@ -1876,7 +1675,7 @@ struct re_guts *g;
} }
/* /*
* some ctype functions with none-ascii-char guard * some ctype functions with non-ascii-char guard
*/ */
static int static int
pg_isdigit(int c) pg_isdigit(int c)
......
...@@ -37,59 +37,19 @@ ...@@ -37,59 +37,19 @@
* @(#)regerror.c 8.4 (Berkeley) 3/20/94 * @(#)regerror.c 8.4 (Berkeley) 3/20/94
*/ */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include "postgres.h" #include "postgres.h"
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h>
#include <assert.h> #include <assert.h>
#include "regex/regex.h" #include "regex/regex.h"
#include "regex/utils.h" #include "regex/utils.h"
#include "regex/regex2.h" #include "regex/regex2.h"
/* ========= begin header generated by ./mkh ========= */ static char *regatoi(const regex_t *preg, char *localbuf);
#ifdef __cplusplus
extern "C"
{
#endif
/* === regerror.c === */
static char *regatoi(const regex_t *preg, char *localbuf);
#ifdef __cplusplus
}
#endif
/* ========= end header generated by ./mkh ========= */
/*
= #define REG_NOMATCH 1
= #define REG_BADPAT 2
= #define REG_ECOLLATE 3
= #define REG_ECTYPE 4
= #define REG_EESCAPE 5
= #define REG_ESUBREG 6
= #define REG_EBRACK 7
= #define REG_EPAREN 8
= #define REG_EBRACE 9
= #define REG_BADBR 10
= #define REG_ERANGE 11
= #define REG_ESPACE 12
= #define REG_BADRPT 13
= #define REG_EMPTY 14
= #define REG_ASSERT 15
= #define REG_INVARG 16
= #define REG_ATOI 255 // convert name to number (!)
= #define REG_ITOA 0400 // convert number to name (!)
*/
static struct rerr static struct rerr
{ {
int code; int code;
...@@ -152,16 +112,12 @@ static struct rerr ...@@ -152,16 +112,12 @@ static struct rerr
}; };
/* /*
- regerror - the interface to error numbers * regerror - the interface to error numbers
= extern size_t regerror(int, const regex_t *, char *, size_t);
*/ */
/* ARGSUSED */ /* ARGSUSED */
size_t size_t
pg95_regerror(errcode, preg, errbuf, errbuf_size) pg95_regerror(int errcode, const regex_t *preg,
int errcode; char *errbuf, size_t errbuf_size)
const regex_t *preg;
char *errbuf;
size_t errbuf_size;
{ {
struct rerr *r; struct rerr *r;
size_t len; size_t len;
...@@ -206,13 +162,10 @@ size_t errbuf_size; ...@@ -206,13 +162,10 @@ size_t errbuf_size;
} }
/* /*
- regatoi - internal routine to implement REG_ATOI * regatoi - internal routine to implement REG_ATOI
== static char *regatoi(const regex_t *preg, char *localbuf);
*/ */
static char * static char *
regatoi(preg, localbuf) regatoi(const regex_t *preg, char *localbuf)
const regex_t *preg;
char *localbuf;
{ {
struct rerr *r; struct rerr *r;
......
...@@ -37,11 +37,6 @@ ...@@ -37,11 +37,6 @@
* @(#)regexec.c 8.3 (Berkeley) 3/20/94 * @(#)regexec.c 8.3 (Berkeley) 3/20/94
*/ */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include "postgres.h" #include "postgres.h"
/* /*
...@@ -52,9 +47,6 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94"; ...@@ -52,9 +47,6 @@ static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
* representations for state sets. * representations for state sets.
*/ */
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h> #include <limits.h>
#include <ctype.h> #include <ctype.h>
#include <assert.h> #include <assert.h>
...@@ -69,24 +61,24 @@ static int nope = 0; /* for use in asserts; shuts lint up */ ...@@ -69,24 +61,24 @@ static int nope = 0; /* for use in asserts; shuts lint up */
#define states long #define states long
#define states1 states /* for later use in regexec() decision */ #define states1 states /* for later use in regexec() decision */
#define CLEAR(v) ((v) = 0) #define CLEAR(v) ((v) = 0)
#define SET0(v, n) ((v) &= ~(1 << (n))) #define SET0(v, n) ((v) &= ~(1L << (n)))
#define SET1(v, n) ((v) |= 1 << (n)) #define SET1(v, n) ((v) |= (1L << (n)))
#define ISSET(v, n) ((v) & (1 << (n))) #define ISSET(v, n) ((v) & (1L << (n)))
#define ASSIGN(d, s) ((d) = (s)) #define ASSIGN(d, s) ((d) = (s))
#define EQ(a, b) ((a) == (b)) #define EQ(a, b) ((a) == (b))
#define STATEVARS int dummy /* dummy version */ #define STATEVARS int dummy /* dummy version */
#define STATESETUP(m, n) /* nothing */ #define STATESETUP(m, n) /* nothing */
#define STATETEARDOWN(m) /* nothing */ #define STATETEARDOWN(m) /* nothing */
#define SETUP(v) ((v) = 0) #define SETUP(v) ((v) = 0)
#define onestate int #define onestate long
#define INIT(o, n) ((o) = (unsigned)1 << (n)) #define INIT(o, n) ((o) = (1L << (n)))
#define INC(o) ((o) <<= 1) #define INC(o) ((o) <<= 1)
#define ISSTATEIN(v, o) ((v) & (o)) #define ISSTATEIN(v, o) ((v) & (o))
/* some abbreviations; note that some of these know variable names! */ /* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */ /* do "if I'm here, I can also be there" etc without branches */
#define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n)) #define FWD(dst, src, n) ((dst) |= ((src) & (here)) << (n))
#define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n)) #define BACK(dst, src, n) ((dst) |= ((src) & (here)) >> (n))
#define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n))) #define ISSETBACK(v, n) ((v) & (here >> (n)))
/* function names */ /* function names */
#define SNAMES /* engine.c looks after details */ #define SNAMES /* engine.c looks after details */
...@@ -129,7 +121,7 @@ static int nope = 0; /* for use in asserts; shuts lint up */ ...@@ -129,7 +121,7 @@ static int nope = 0; /* for use in asserts; shuts lint up */
#define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates]) #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
#define onestate int #define onestate int
#define INIT(o, n) ((o) = (n)) #define INIT(o, n) ((o) = (n))
#define INC(o) ((o)++) #define INC(o) ((o)++)
#define ISSTATEIN(v, o) ((v)[o]) #define ISSTATEIN(v, o) ((v)[o])
/* some abbreviations; note that some of these know variable names! */ /* some abbreviations; note that some of these know variable names! */
/* do "if I'm here, I can also be there" etc without branches */ /* do "if I'm here, I can also be there" etc without branches */
...@@ -142,27 +134,14 @@ static int nope = 0; /* for use in asserts; shuts lint up */ ...@@ -142,27 +134,14 @@ static int nope = 0; /* for use in asserts; shuts lint up */
#include "engine.c" #include "engine.c"
/* /*
- regexec - interface for matching * regexec - interface for matching
= extern int regexec(const regex_t *, const char *, size_t, \
= regmatch_t [], int);
= #define REG_NOTBOL 00001
= #define REG_NOTEOL 00002
= #define REG_STARTEND 00004
= #define REG_TRACE 00400 // tracing of execution
= #define REG_LARGE 01000 // force large representation
= #define REG_BACKR 02000 // force use of backref code
* *
* We put this here so we can exploit knowledge of the state representation * We put this here so we can exploit knowledge of the state representation
* when choosing which matcher to call. Also, by this point the matchers * when choosing which matcher to call.
* have been prototyped.
*/ */
int /* 0 success, REG_NOMATCH failure */ int /* 0 success, REG_NOMATCH failure */
pg95_regexec(preg, string, nmatch, pmatch, eflags) pg95_regexec(const regex_t *preg, const char *string, size_t nmatch,
const regex_t *preg; regmatch_t *pmatch, int eflags)
const char *string;
size_t nmatch;
regmatch_t *pmatch;
int eflags;
{ {
struct re_guts *g = preg->re_g; struct re_guts *g = preg->re_g;
......
...@@ -37,28 +37,19 @@ ...@@ -37,28 +37,19 @@
* @(#)regfree.c 8.3 (Berkeley) 3/20/94 * @(#)regfree.c 8.3 (Berkeley) 3/20/94
*/ */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
#endif /* LIBC_SCCS and not lint */
#include "postgres.h" #include "postgres.h"
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "regex/regex.h" #include "regex/regex.h"
#include "regex/utils.h" #include "regex/utils.h"
#include "regex/regex2.h" #include "regex/regex2.h"
/* /*
- regfree - free everything * regfree - free everything
= extern void regfree(regex_t *);
*/ */
void void
pg95_regfree(preg) pg95_regfree(regex_t *preg)
regex_t *preg;
{ {
struct re_guts *g; struct re_guts *g;
......
...@@ -94,6 +94,6 @@ static struct cclass ...@@ -94,6 +94,6 @@ static struct cclass
"" ""
}, },
{ {
NULL, 0, "" NULL, NULL, ""
} }
}; };
...@@ -102,10 +102,12 @@ typedef struct ...@@ -102,10 +102,12 @@ typedef struct
#define REG_LARGE 01000 /* force large representation */ #define REG_LARGE 01000 /* force large representation */
#define REG_BACKR 02000 /* force use of backref code */ #define REG_BACKR 02000 /* force use of backref code */
int pg95_regcomp(regex_t *, const char *, int); extern int pg95_regcomp(regex_t *preg, const char *pattern, int cflags);
size_t pg95_regerror(int, const regex_t *, char *, size_t); extern size_t pg95_regerror(int errcode, const regex_t *preg,
int pg95_regexec(const regex_t *, char *errbuf, size_t errbuf_size);
const char *, size_t, regmatch_t[], int); extern int pg95_regexec(const regex_t *preg, const char *string,
void pg95_regfree(regex_t *); size_t nmatch,
regmatch_t *pmatch, int eflags);
extern void pg95_regfree(regex_t *preg);
#endif /* !_REGEX_H_ */ #endif /* !_REGEX_H_ */
...@@ -39,22 +39,6 @@ ...@@ -39,22 +39,6 @@
#include <limits.h> #include <limits.h>
/*
* First, the stuff that ends up in the outside-world include file
*/
/*
typedef off_t regoff_t;
typedef struct {
int re_magic;
size_t re_nsub; // number of parenthesized subexpressions
const char *re_endp; // end pointer for REG_PEND
struct re_guts *re_g; // none of your business :-)
} regex_t;
typedef struct {
regoff_t rm_so; // start of match
regoff_t rm_eo; // end of match
} regmatch_t;
*/
/* /*
* internals of regex_t * internals of regex_t
*/ */
...@@ -82,8 +66,8 @@ ...@@ -82,8 +66,8 @@
typedef unsigned long sop; /* strip operator */ typedef unsigned long sop; /* strip operator */
typedef long sopno; typedef long sopno;
#define OPRMASK 0xf8000000 #define OPRMASK ((sop) 0xf8000000)
#define OPDMASK 0x07ffffff #define OPDMASK ((sop) 0x07ffffff)
#define OPSHIFT ((unsigned)27) #define OPSHIFT ((unsigned)27)
#define OP(n) ((n)&OPRMASK) #define OP(n) ((n)&OPRMASK)
#define OPND(n) ((n)&OPDMASK) #define OPND(n) ((n)&OPDMASK)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment