From: Teodor Sigaev Date: Mon, 31 May 2004 13:29:43 +0000 (+0000) Subject: Win32 related patch by Darko Prenosil. Small correct by teodor X-Git-Tag: REL9_0_0~12664 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=11864ab657ab2b54f4eb34a028ab76c64f3f2a9c;p=pg-rex%2Fsyncrep.git Win32 related patch by Darko Prenosil. Small correct by teodor --- diff --git a/contrib/tsearch2/ispell/spell.c b/contrib/tsearch2/ispell/spell.c index 416acf7797..bdcbc58816 100644 --- a/contrib/tsearch2/ispell/spell.c +++ b/contrib/tsearch2/ispell/spell.c @@ -619,6 +619,9 @@ static char * CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *newword) { regmatch_t subs[2]; /* workaround for apache&linux */ int err; + pg_wchar *data; + size_t data_len; + int dat_len; if ( flagflags & FF_COMPOUNDONLYAFX ) { if ( (Affix->flagflags & FF_COMPOUNDONLYAFX) == 0 ) @@ -638,17 +641,29 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne if (Affix->compile) { - err = regcomp(&(Affix->reg), Affix->mask, REG_EXTENDED | REG_ICASE | REG_NOSUB); + int wmasklen,masklen = strlen(Affix->mask); + pg_wchar *mask; + mask = (pg_wchar *) palloc((masklen + 1) * sizeof(pg_wchar)); + wmasklen = pg_mb2wchar_with_len( Affix->mask, mask, masklen); + + err = pg_regcomp(&(Affix->reg), mask, wmasklen, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (err) { /* regerror(err, &(Affix->reg), regerrstr, ERRSTRSIZE); */ - regfree(&(Affix->reg)); + pg_regfree(&(Affix->reg)); return (NULL); } Affix->compile = 0; } - if (!(err = regexec(&(Affix->reg), newword, 1, subs, 0))) + + /* Convert data string to wide characters */ + dat_len = strlen(newword); + data = (pg_wchar *) palloc((dat_len + 1) * sizeof(pg_wchar)); + data_len = pg_mb2wchar_with_len(newword, data, dat_len); + + if (!(err = pg_regexec(&(Affix->reg), data,dat_len,NULL, 1, subs, 0))) return newword; + return NULL; } @@ -995,7 +1010,7 @@ NIFree(IspellDict * Conf) for (i = 0; i < Conf->naffixes; i++) { if (Affix[i].compile == 0) - regfree(&(Affix[i].reg)); + pg_regfree(&(Affix[i].reg)); } if (Conf->Spell) { for (i = 0; i < Conf->nspell; i++) diff --git a/contrib/tsearch2/ispell/spell.h b/contrib/tsearch2/ispell/spell.h index fd5ab7141d..150e4166e1 100644 --- a/contrib/tsearch2/ispell/spell.h +++ b/contrib/tsearch2/ispell/spell.h @@ -2,9 +2,10 @@ #define __SPELL_H__ #include -#include +#include "regex/regex.h" #include "c.h" + struct SPNode; diff --git a/contrib/tsearch2/query.c b/contrib/tsearch2/query.c index 458c55de27..1cdefa76d8 100644 --- a/contrib/tsearch2/query.c +++ b/contrib/tsearch2/query.c @@ -269,7 +269,7 @@ pushval_morph(QPRS_STATE * state, int typeval, char *strval, int lenval, int2 we prs.lenwords = 32; prs.curwords = 0; prs.pos = 0; - prs.words = (WORD *) palloc(sizeof(WORD) * prs.lenwords); + prs.words = (TSWORD *) palloc(sizeof(TSWORD) * prs.lenwords); parsetext_v2(findcfg(state->cfg_id), &prs, strval, lenval); diff --git a/contrib/tsearch2/ts_cfg.c b/contrib/tsearch2/ts_cfg.c index fd5f7e1556..ded92ac1bc 100644 --- a/contrib/tsearch2/ts_cfg.c +++ b/contrib/tsearch2/ts_cfg.c @@ -338,7 +338,7 @@ parsetext_v2(TSCfgInfo * cfg, PRSTEXT * prs, char *buf, int4 buflen) if (prs->curwords == prs->lenwords) { prs->lenwords *= 2; - prs->words = (WORD *) repalloc((void *) prs->words, prs->lenwords * sizeof(WORD)); + prs->words = (TSWORD *) repalloc((void *) prs->words, prs->lenwords * sizeof(TSWORD)); } prs->words[prs->curwords].len = strlen(*ptr); diff --git a/contrib/tsearch2/ts_cfg.h b/contrib/tsearch2/ts_cfg.h index cde35ca2a6..9bf65144b2 100644 --- a/contrib/tsearch2/ts_cfg.h +++ b/contrib/tsearch2/ts_cfg.h @@ -1,8 +1,10 @@ #ifndef __TS_CFG_H__ #define __TS_CFG_H__ + #include "postgres.h" #include "query.h" + typedef struct { int len; @@ -32,11 +34,11 @@ typedef struct } pos; char *word; uint32 alen; -} WORD; +} TSWORD; typedef struct { - WORD *words; + TSWORD *words; int4 lenwords; int4 curwords; int4 pos; diff --git a/contrib/tsearch2/tsvector.c b/contrib/tsearch2/tsvector.c index 494663496e..14bdd9ff5c 100644 --- a/contrib/tsearch2/tsvector.c +++ b/contrib/tsearch2/tsvector.c @@ -573,24 +573,24 @@ tsvector_out(PG_FUNCTION_ARGS) static int compareWORD(const void *a, const void *b) { - if (((WORD *) a)->len == ((WORD *) b)->len) + if (((TSWORD *) a)->len == ((TSWORD *) b)->len) { int res = strncmp( - ((WORD *) a)->word, - ((WORD *) b)->word, - ((WORD *) b)->len); + ((TSWORD *) a)->word, + ((TSWORD *) b)->word, + ((TSWORD *) b)->len); if (res == 0) - return (((WORD *) a)->pos.pos > ((WORD *) b)->pos.pos) ? 1 : -1; + return (((TSWORD *) a)->pos.pos > ((TSWORD *) b)->pos.pos) ? 1 : -1; return res; } - return (((WORD *) a)->len > ((WORD *) b)->len) ? 1 : -1; + return (((TSWORD *) a)->len > ((TSWORD *) b)->len) ? 1 : -1; } static int -uniqueWORD(WORD * a, int4 l) +uniqueWORD(TSWORD * a, int4 l) { - WORD *ptr, + TSWORD *ptr, *res; int tmppos; @@ -607,7 +607,7 @@ uniqueWORD(WORD * a, int4 l) res = a; ptr = a + 1; - qsort((void *) a, l, sizeof(WORD), compareWORD); + qsort((void *) a, l, sizeof(TSWORD), compareWORD); tmppos = LIMITPOS(a->pos.pos); a->alen = 2; a->pos.apos = (uint16 *) palloc(sizeof(uint16) * a->alen); @@ -728,7 +728,7 @@ to_tsvector(PG_FUNCTION_ARGS) prs.lenwords = 32; prs.curwords = 0; prs.pos = 0; - prs.words = (WORD *) palloc(sizeof(WORD) * prs.lenwords); + prs.words = (TSWORD *) palloc(sizeof(TSWORD) * prs.lenwords); parsetext_v2(cfg, &prs, VARDATA(in), VARSIZE(in) - VARHDRSZ); PG_FREE_IF_COPY(in, 1); @@ -853,7 +853,7 @@ tsearch2(PG_FUNCTION_ARGS) prs.lenwords = 32; prs.curwords = 0; prs.pos = 0; - prs.words = (WORD *) palloc(sizeof(WORD) * prs.lenwords); + prs.words = (TSWORD *) palloc(sizeof(TSWORD) * prs.lenwords); /* find all words in indexable column */ for (i = 1; i < trigger->tgnargs; i++)