1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Remove #ifdef MULTIBYTE per hackers list discussion.

This commit is contained in:
Tatsuo Ishii
2002-08-29 07:22:30 +00:00
parent 8e80dbb849
commit ed7baeaf4d
31 changed files with 81 additions and 761 deletions

View File

@ -108,13 +108,8 @@ static states step(struct re_guts * g, sopno start,
#define EOW (BOL+5)
#define CODEMAX (BOL+5) /* highest code used */
#ifdef MULTIBYTE
#define NONCHAR(c) ((c) > 16777216) /* 16777216 == 2^24 == 3 bytes */
#define NNONCHAR (CODEMAX-16777216)
#else
#define NONCHAR(c) ((c) > CHAR_MAX)
#define NNONCHAR (CODEMAX-CHAR_MAX)
#endif
#ifdef REDEBUG
static void print(struct match * m, pg_wchar *caption, states st, int ch,
@ -168,11 +163,7 @@ matcher(struct re_guts * g, pg_wchar *string, size_t nmatch,
else
{
start = string;
#ifdef MULTIBYTE
stop = start + pg_wchar_strlen(start);
#else
stop = start + strlen(start);
#endif
}
if (stop < start)
return REG_INVARG;
@ -182,11 +173,7 @@ matcher(struct re_guts * g, pg_wchar *string, size_t nmatch,
{
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
#else
memcmp(dp, g->must, (size_t) g->mlen) == 0
#endif
)
break;
if (dp == stop) /* we didn't find g->must */
@ -1090,11 +1077,7 @@ pchar(int ch)
static int
pg_isprint(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isprint((unsigned char) c));
#else
return (isprint((unsigned char) c));
#endif
}
#endif
#endif

View File

@ -91,13 +91,7 @@ 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
static unsigned char othercase(int ch);
#else
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);
@ -184,10 +178,7 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
struct parse *p = &pa;
int i;
size_t len;
#ifdef MULTIBYTE
pg_wchar *wcp;
#endif
if ( cclasses == NULL )
cclasses = cclass_init();
@ -204,29 +195,19 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
if (cflags & REG_PEND)
{
#ifdef MULTIBYTE
wcp = preg->patsave;
if (preg->re_endp < wcp)
return REG_INVARG;
len = preg->re_endp - wcp;
#else
if (preg->re_endp < pattern)
return REG_INVARG;
len = preg->re_endp - pattern;
#endif
}
else
{
#ifdef MULTIBYTE
wcp = (pg_wchar *) malloc((strlen(pattern) + 1) * sizeof(pg_wchar));
if (wcp == NULL)
return REG_ESPACE;
preg->patsave = wcp;
(void) pg_mb2wchar((unsigned char *) pattern, wcp);
len = pg_wchar_strlen(wcp);
#else
len = strlen((char *) pattern);
#endif
}
/* do the mallocs early so failure handling is easy */
@ -246,12 +227,7 @@ pg_regcomp(regex_t *preg, const char *pattern, int cflags)
/* set things up */
p->g = g;
#ifdef MULTIBYTE
p->next = wcp;
#else
p->next = (pg_wchar *) pattern; /* convenience; we do not modify
* it */
#endif
p->end = p->next + len;
p->error = 0;
p->ncsalloc = 0;
@ -591,11 +567,7 @@ p_simp_re(struct parse * p,
if (c == '\\')
{
REQUIRE(MORE(), REG_EESCAPE);
#ifdef MULTIBYTE
c = BACKSL | (pg_wchar) GETNEXT();
#else
c = BACKSL | (unsigned char) GETNEXT();
#endif
}
switch (c)
{
@ -736,27 +708,17 @@ p_bracket(struct parse * p)
cset *cs = allocset(p);
int invert = 0;
#ifdef MULTIBYTE
pg_wchar sp1[] = {'[', ':', '<', ':', ']', ']'};
pg_wchar sp2[] = {'[', ':', '>', ':', ']', ']'};
#endif
/* Dept of Truly Sickening Special-Case Kludges */
#ifdef MULTIBYTE
if (p->next + 5 < p->end && pg_wchar_strncmp(p->next, sp1, 6) == 0)
#else
if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0)
#endif
{
EMIT(OBOW, 0);
NEXTn(6);
return;
}
#ifdef MULTIBYTE
if (p->next + 5 < p->end && pg_wchar_strncmp(p->next, sp2, 6) == 0)
#else
if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0)
#endif
{
EMIT(OEOW, 0);
NEXTn(6);
@ -881,10 +843,10 @@ p_b_term(struct parse * p, cset *cs)
finish = start;
/* xxx what about signed chars here... */
REQUIRE(start <= finish, REG_ERANGE);
#ifdef MULTIBYTE
if (CHlc(start) != CHlc(finish))
SETERROR(REG_ERANGE);
#endif
for (i = start; i <= finish; i++)
CHadd(cs, i);
break;
@ -906,13 +868,11 @@ p_b_cclass(struct parse * p, cset *cs)
while (MORE() && pg_isalpha(PEEK()))
NEXT();
len = p->next - sp;
for (cp = cclasses; cp->name != NULL; cp++)
#ifdef MULTIBYTE
if (pg_char_and_wchar_strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
#else
if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
#endif
break;
if (cp->name == NULL)
{
/* oops, didn't find it */
@ -977,13 +937,11 @@ p_b_coll_elem(struct parse * p, int endc)
return 0;
}
len = p->next - sp;
for (cp = cnames; cp->name != NULL; cp++)
#ifdef MULTIBYTE
if (pg_char_and_wchar_strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
#else
if (strncmp(cp->name, sp, len) == 0 && cp->name[len] == '\0')
#endif
return cp->code; /* known name */
if (len == 1)
return *sp; /* single character */
SETERROR(REG_ECOLLATE); /* neither */
@ -993,33 +951,17 @@ p_b_coll_elem(struct parse * p, int endc)
/*
* othercase - return the case counterpart of an alphabetic
*/
#ifdef MULTIBYTE
static unsigned char /* if no counterpart, return ch */
#else
static char /* if no counterpart, return ch */
#endif
othercase(int ch)
{
assert(pg_isalpha(ch));
if (pg_isupper(ch))
#ifdef MULTIBYTE
return (unsigned char) tolower((unsigned char) ch);
#else
return tolower((unsigned char) ch);
#endif
else if (pg_islower(ch))
#ifdef MULTIBYTE
return (unsigned char) toupper((unsigned char) ch);
#else
return toupper((unsigned char) ch);
#endif
else
/* peculiar, but could happen */
#ifdef MULTIBYTE
return (unsigned char) ch;
#else
return ch;
#endif
}
/*
@ -1058,11 +1000,7 @@ ordinary(struct parse * p, int ch)
bothcases(p, ch);
else
{
#ifdef MULTIBYTE
EMIT(OCHAR, (pg_wchar) ch);
#else
EMIT(OCHAR, (unsigned char) ch);
#endif
if (ch >= CHAR_MIN && ch <= CHAR_MAX && cap[ch] == 0)
cap[ch] = p->g->ncategories++;
}
@ -1633,11 +1571,7 @@ findmust(struct parse * p, struct re_guts * g)
return;
/* turn it into a character string */
#ifdef MULTIBYTE
g->must = (pg_wchar *) malloc((size_t) (g->mlen + 1) * sizeof(pg_wchar));
#else
g->must = malloc((size_t) g->mlen + 1);
#endif
if (g->must == NULL)
{ /* argh; just forget it */
g->mlen = 0;
@ -1697,91 +1631,55 @@ pluscount(struct parse * p, struct re_guts * g)
static int
pg_isdigit(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isdigit((unsigned char) c));
#else
return (isdigit((unsigned char) c));
#endif
}
static int
pg_isalpha(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isalpha((unsigned char) c));
#else
return (isalpha((unsigned char) c));
#endif
}
static int
pg_isalnum(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isalnum((unsigned char) c));
#else
return (isalnum((unsigned char) c));
#endif
}
static int
pg_isupper(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isupper((unsigned char) c));
#else
return (isupper((unsigned char) c));
#endif
}
static int
pg_islower(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && islower((unsigned char) c));
#else
return (islower((unsigned char) c));
#endif
}
static int
pg_iscntrl(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && iscntrl((unsigned char) c));
#else
return (iscntrl((unsigned char) c));
#endif
}
static int
pg_isgraph(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isgraph((unsigned char) c));
#else
return (isgraph((unsigned char) c));
#endif
}
static int
pg_isprint(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && isprint((unsigned char) c));
#else
return (isprint((unsigned char) c));
#endif
}
static int
pg_ispunct(int c)
{
#ifdef MULTIBYTE
return (c >= 0 && c <= UCHAR_MAX && ispunct((unsigned char) c));
#else
return (ispunct((unsigned char) c));
#endif
}
static struct cclass *

View File

@ -171,12 +171,9 @@ regatoi(const regex_t *preg, char *localbuf)
struct rerr *r;
for (r = rerrs; r->code != 0; r++)
#ifdef MULTIBYTE
if (pg_char_and_wchar_strcmp(r->name, preg->re_endp) == 0)
#else
if (strcmp(r->name, preg->re_endp) == 0)
#endif
break;
if (r->code == 0)
return "0";

View File

@ -154,10 +154,8 @@ pg_regexec(const regex_t *preg, const char *string, size_t nmatch,
{
struct re_guts *g = preg->re_g;
#ifdef MULTIBYTE
pg_wchar *str;
int sts;
#endif
#ifdef REDEBUG
#define GOODFLAGS(f) (f)
@ -172,7 +170,6 @@ pg_regexec(const regex_t *preg, const char *string, size_t nmatch,
return REG_BADPAT;
eflags = GOODFLAGS(eflags);
#ifdef MULTIBYTE
str = (pg_wchar *) malloc((strlen(string) + 1) * sizeof(pg_wchar));
if (!str)
return (REG_ESPACE);
@ -183,12 +180,4 @@ pg_regexec(const regex_t *preg, const char *string, size_t nmatch,
sts = lmatcher(g, str, nmatch, pmatch, eflags);
free((char *) str);
return (sts);
#else
if (g->nstates <= CHAR_BIT * sizeof(states1) && !(eflags & REG_LARGE))
return smatcher(g, (pg_wchar *) string, nmatch, pmatch, eflags);
else
return lmatcher(g, (pg_wchar *) string, nmatch, pmatch, eflags);
#endif
}

View File

@ -61,10 +61,9 @@ pg_regfree(regex_t *preg)
return;
preg->re_magic = 0; /* mark it invalid */
g->magic = 0; /* mark it invalid */
#ifdef MULTIBYTE
if (preg->patsave != NULL)
free((char *) preg->patsave);
#endif
if (g->strip != NULL)
free((char *) g->strip);
if (g->sets != NULL)