Win32 related patch by Darko Prenosil. Small correct by teodor
authorTeodor Sigaev <teodor@sigaev.ru>
Mon, 31 May 2004 13:29:43 +0000 (13:29 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Mon, 31 May 2004 13:29:43 +0000 (13:29 +0000)
contrib/tsearch2/ispell/spell.c
contrib/tsearch2/ispell/spell.h
contrib/tsearch2/query.c
contrib/tsearch2/ts_cfg.c
contrib/tsearch2/ts_cfg.h
contrib/tsearch2/tsvector.c

index 416acf77974b29d4bd28d040465b1974a22975b0..bdcbc588163839b846cb73f07cee39160eef3764 100644 (file)
@@ -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++)
index fd5ab7141d48f68fc6c74d27f649d20c0227ecf0..150e4166e13d3b38f171e3357e16fbb092824b18 100644 (file)
@@ -2,9 +2,10 @@
 #define __SPELL_H__
 
 #include <sys/types.h>
-#include <regex.h>
+#include "regex/regex.h"
 #include "c.h"
 
+
 struct SPNode;
 
 
index 458c55de2798b4a6e7f767a08dc14f4aa9769d9b..1cdefa76d8011b24f9ccb49763e23dc21da8bcf1 100644 (file)
@@ -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);
 
index fd5f7e1556784a4f4e3bb180316be9ba2a7558df..ded92ac1bc15469754e9d1d2f2d531b45746c840 100644 (file)
@@ -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);
index cde35ca2a6ebbaddff7e7a2e825cc9970af1a41b..9bf65144b208591b167b44869a6a5e1463ab0b2d 100644 (file)
@@ -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;
index 494663496edc28a5d4e4505356031e24f38dcc59..14bdd9ff5cf8fe8099445db67165137f277fb603 100644 (file)
@@ -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++)