mirror of https://github.com/postgres/postgres
Win32 related patch by Darko Prenosil. Small correct by teodor
This commit is contained in:
parent
9b178555fc
commit
11864ab657
|
@ -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++)
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
#define __SPELL_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
#include "regex/regex.h"
|
||||
#include "c.h"
|
||||
|
||||
|
||||
struct SPNode;
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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++)
|
||||
|
|
Loading…
Reference in New Issue