+++ /dev/null
-/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.h,v 1.8 2007/02/28 22:44:38 tgl Exp $ */
-
-#ifndef __GISTIDX_H__
-#define __GISTIDX_H__
-
-/*
-#define GISTIDX_DEBUG
-*/
-
-/*
- * signature defines
- */
-
-#define SIGLENINT 63 /* >121 => key will toast, so it will not work
- * !!! */
-#define SIGLEN ( sizeof(int4) * SIGLENINT )
-#define SIGLENBIT (SIGLEN * BITS_PER_BYTE)
-
-typedef char BITVEC[SIGLEN];
-typedef char *BITVECP;
-
-#define LOOPBYTE(a) \
- for(i=0;i
- a;\
- }
-
-#define GETBYTE(x,i) ( *( (BITVECP)(x) + (int)( (i) / BITS_PER_BYTE ) ) )
-#define GETBITBYTE(x,i) ( ((char)(x)) >> (i) & 0x01 )
-#define CLRBIT(x,i) GETBYTE(x,i) &= ~( 0x01 << ( (i) % BITS_PER_BYTE ) )
-#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITS_PER_BYTE ) )
-#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITS_PER_BYTE )) & 0x01 )
-
-#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
-#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
-
-
-/*
- * type of index key
- */
-typedef struct
-{
- int32 vl_len_; /* varlena header (do not touch directly!) */
- int4 flag;
- char data[1];
-} GISTTYPE;
-
-#define ARRKEY 0x01
-#define SIGNKEY 0x02
-#define ALLISTRUE 0x04
-
-#define ISARRKEY(x) ( ((GISTTYPE*)(x))->flag & ARRKEY )
-#define ISSIGNKEY(x) ( ((GISTTYPE*)(x))->flag & SIGNKEY )
-#define ISALLTRUE(x) ( ((GISTTYPE*)(x))->flag & ALLISTRUE )
-
-#define GTHDRSIZE ( VARHDRSZ + sizeof(int4) )
-#define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int4)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
-
-#define GETSIGN(x) ( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
-#define GETARR(x) ( (int4*)( (char*)(x)+GTHDRSIZE ) )
-#define ARRNELEM(x) ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int4) )
-
-#endif
+++ /dev/null
-# $PostgreSQL: pgsql/contrib/tsearch2/ispell/Makefile,v 1.10 2007/06/26 22:05:03 tgl Exp $
-
-SUBOBJS = spell.o regis.o
-
-EXTRA_CLEAN = SUBSYS.o $(SUBOBJS)
-
-PG_CPPFLAGS = -I$(srcdir)/..
-
-ifdef USE_PGXS
-PG_CONFIG = pg_config
-PGXS := $(shell $(PG_CONFIG) --pgxs)
-include $(PGXS)
-else
-subdir = contrib/tsearch2/ispell
-top_builddir = ../../..
-include $(top_builddir)/src/Makefile.global
-include $(top_srcdir)/contrib/contrib-global.mk
-endif
-
-override CFLAGS += $(CFLAGS_SL)
-
-all: SUBSYS.o
-
-SUBSYS.o: $(SUBOBJS)
- $(LD) $(LDREL) $(LDOUT) $@ $^
-
-
+++ /dev/null
-#include "regis.h"
-#include "ts_locale.h"
-#include "common.h"
-
-bool
-RS_isRegis(const char *str)
-{
- while (str && *str)
- {
- if (t_isalpha(str) ||
- t_iseq(str, '[') ||
- t_iseq(str, ']') ||
- t_iseq(str, '^'))
- str += pg_mblen(str);
- else
- return false;
- }
- return true;
-}
-
-#define RS_IN_ONEOF 1
-#define RS_IN_ONEOF_IN 2
-#define RS_IN_NONEOF 3
-#define RS_IN_WAIT 4
-
-static RegisNode *
-newRegisNode(RegisNode * prev, int len)
-{
- RegisNode *ptr;
-
- ptr = (RegisNode *) malloc(RNHDRSZ + len + 1);
- if (!ptr)
- ts_error(ERROR, "No memory");
- memset(ptr, 0, RNHDRSZ + len + 1);
- if (prev)
- prev->next = ptr;
- return ptr;
-}
-
-void
-RS_compile(Regis * r, bool issuffix, char *str)
-{
- int len = strlen(str);
- int state = RS_IN_WAIT;
- char *c = (char *) str;
- RegisNode *ptr = NULL;
-
- memset(r, 0, sizeof(Regis));
- r->issuffix = (issuffix) ? 1 : 0;
-
- while (*c)
- {
- if (state == RS_IN_WAIT)
- {
- if (t_isalpha(c))
- {
- if (ptr)
- ptr = newRegisNode(ptr, len);
- else
- ptr = r->node = newRegisNode(NULL, len);
- COPYCHAR(ptr->data, c);
- ptr->type = RSF_ONEOF;
- ptr->len = pg_mblen(c);
- }
- else if (t_iseq(c, '['))
- {
- if (ptr)
- ptr = newRegisNode(ptr, len);
- else
- ptr = r->node = newRegisNode(NULL, len);
- ptr->type = RSF_ONEOF;
- state = RS_IN_ONEOF;
- }
- else
- ts_error(ERROR, "Error in regis: %s", str);
- }
- else if (state == RS_IN_ONEOF)
- {
- if (t_iseq(c, '^'))
- {
- ptr->type = RSF_NONEOF;
- state = RS_IN_NONEOF;
- }
- else if (t_isalpha(c))
- {
- COPYCHAR(ptr->data, c);
- ptr->len = pg_mblen(c);
- state = RS_IN_ONEOF_IN;
- }
- else
- ts_error(ERROR, "Error in regis: %s", str);
- }
- else if (state == RS_IN_ONEOF_IN || state == RS_IN_NONEOF)
- {
- if (t_isalpha(c))
- {
- COPYCHAR(ptr->data + ptr->len, c);
- ptr->len += pg_mblen(c);
- }
- else if (t_iseq(c, ']'))
- state = RS_IN_WAIT;
- else
- ts_error(ERROR, "Error in regis: %s", str);
- }
- else
- ts_error(ERROR, "Internal error in RS_compile: %d", state);
- c += pg_mblen(c);
- }
-
- ptr = r->node;
- while (ptr)
- {
- r->nchar++;
- ptr = ptr->next;
- }
-}
-
-void
-RS_free(Regis * r)
-{
- RegisNode *ptr = r->node,
- *tmp;
-
- while (ptr)
- {
- tmp = ptr->next;
- free(ptr);
- ptr = tmp;
- }
-
- r->node = NULL;
-}
-
-#ifdef TS_USE_WIDE
-static bool
-mb_strchr(char *str, char *c)
-{
- int clen = pg_mblen(c),
- plen,
- i;
- char *ptr = str;
- bool res = false;
-
- clen = pg_mblen(c);
- while (*ptr && !res)
- {
- plen = pg_mblen(ptr);
- if (plen == clen)
- {
- i = plen;
- res = true;
- while (i--)
- if (*(ptr + i) != *(c + i))
- {
- res = false;
- break;
- }
- }
-
- ptr += plen;
- }
-
- return res;
-}
-#else
-#define mb_strchr(s,c) ( (strchr((s),*(c)) == NULL) ? false : true )
-#endif
-
-
-bool
-RS_execute(Regis * r, char *str)
-{
- RegisNode *ptr = r->node;
- char *c = str;
- int len = 0;
-
- while (*c)
- {
- len++;
- c += pg_mblen(c);
- }
-
- if (len < r->nchar)
- return false;
-
- c = str;
- if (r->issuffix)
- {
- len -= r->nchar;
- while (len-- > 0)
- c += pg_mblen(c);
- }
-
-
- while (ptr)
- {
- switch (ptr->type)
- {
- case RSF_ONEOF:
- if (mb_strchr((char *) ptr->data, c) != true)
- return false;
- break;
- case RSF_NONEOF:
- if (mb_strchr((char *) ptr->data, c) == true)
- return false;
- break;
- default:
- ts_error(ERROR, "RS_execute: Unknown type node: %d\n", ptr->type);
- }
- ptr = ptr->next;
- c += pg_mblen(c);
- }
-
- return true;
-}
+++ /dev/null
-#ifndef __REGIS_H__
-#define __REGIS_H__
-
-#include "postgres.h"
-
-typedef struct RegisNode
-{
- uint32
- type:2,
- len:16,
- unused:14;
- struct RegisNode *next;
- unsigned char data[1];
-} RegisNode;
-
-#define RNHDRSZ (offsetof(RegisNode,data))
-
-#define RSF_ONEOF 1
-#define RSF_NONEOF 2
-
-typedef struct Regis
-{
- RegisNode *node;
- uint32
- issuffix:1,
- nchar:16,
- unused:15;
-} Regis;
-
-bool RS_isRegis(const char *str);
-
-void RS_compile(Regis * r, bool issuffix, char *str);
-void RS_free(Regis * r);
-
-/*returns true if matches */
-bool RS_execute(Regis * r, char *str);
-
-#endif
+++ /dev/null
-#include "postgres.h"
-
-#include
-
-#include "spell.h"
-#include "common.h"
-#include "ts_locale.h"
-
-#define MAX_NORM 1024
-#define MAXNORMLEN 256
-
-#define ERRSTRSIZE 1024
-
-#define STRNCMP(s,p) strncmp( (s), (p), strlen(p) )
-#define GETWCHAR(W,L,N,T) ( ((uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] )
-#define GETCHAR(A,N,T) GETWCHAR( (A)->repl, (A)->replen, N, T )
-
-static char *VoidString = "";
-
-#define MEMOUT(X) if ( !(X) ) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory")))
-
-static int
-cmpspell(const void *s1, const void *s2)
-{
- return (strcmp((*(const SPELL **) s1)->word, (*(const SPELL **) s2)->word));
-}
-static int
-cmpspellaffix(const void *s1, const void *s2)
-{
- return (strcmp((*(const SPELL **) s1)->p.flag, (*(const SPELL **) s2)->p.flag));
-}
-
-static char *
-strnduplicate(char *s, int len)
-{
- char *d = (char *) palloc(len + 1);
-
- memcpy(d, s, len);
- d[len] = '\0';
- return d;
-}
-
-static char *
-findchar(char *str, int c)
-{
- while (*str)
- {
- if (t_iseq(str, c))
- return str;
- str += pg_mblen(str);
- }
-
- return NULL;
-}
-
-
-/* backward string compare for suffix tree operations */
-static int
-strbcmp(const unsigned char *s1, const unsigned char *s2)
-{
- int l1 = strlen((const char *) s1) - 1,
- l2 = strlen((const char *) s2) - 1;
-
- while (l1 >= 0 && l2 >= 0)
- {
- if (s1[l1] < s2[l2])
- return -1;
- if (s1[l1] > s2[l2])
- return 1;
- l1--;
- l2--;
- }
- if (l1 < l2)
- return -1;
- if (l1 > l2)
- return 1;
-
- return 0;
-}
-static int
-strbncmp(const unsigned char *s1, const unsigned char *s2, size_t count)
-{
- int l1 = strlen((const char *) s1) - 1,
- l2 = strlen((const char *) s2) - 1,
- l = count;
-
- while (l1 >= 0 && l2 >= 0 && l > 0)
- {
- if (s1[l1] < s2[l2])
- return -1;
- if (s1[l1] > s2[l2])
- return 1;
- l1--;
- l2--;
- l--;
- }
- if (l == 0)
- return 0;
- if (l1 < l2)
- return -1;
- if (l1 > l2)
- return 1;
- return 0;
-}
-
-static int
-cmpaffix(const void *s1, const void *s2)
-{
- const AFFIX *a1 = (const AFFIX *) s1;
- const AFFIX *a2 = (const AFFIX *) s2;
-
- if (a1->type < a2->type)
- return -1;
- if (a1->type > a2->type)
- return 1;
- if (a1->type == FF_PREFIX)
- return strcmp(a1->repl, a2->repl);
- else
- return strbcmp((const unsigned char *) a1->repl,
- (const unsigned char *) a2->repl);
-}
-
-int
-NIAddSpell(IspellDict * Conf, const char *word, const char *flag)
-{
- if (Conf->nspell >= Conf->mspell)
- {
- if (Conf->mspell)
- {
- Conf->mspell += 1024 * 20;
- Conf->Spell = (SPELL **) repalloc(Conf->Spell, Conf->mspell * sizeof(SPELL *));
- }
- else
- {
- Conf->mspell = 1024 * 20;
- Conf->Spell = (SPELL **) palloc(Conf->mspell * sizeof(SPELL *));
- }
- }
- Conf->Spell[Conf->nspell] = (SPELL *) palloc(SPELLHDRSZ + strlen(word) + 1);
- strcpy(Conf->Spell[Conf->nspell]->word, word);
- strncpy(Conf->Spell[Conf->nspell]->p.flag, flag, 16);
- Conf->nspell++;
- return (0);
-}
-
-
-int
-NIImportDictionary(IspellDict * Conf, const char *filename)
-{
- char str[BUFSIZ], *pstr;
- FILE *dict;
-
- if (!(dict = fopen(filename, "r")))
- return (1);
- while (fgets(str, sizeof(str), dict))
- {
- char *s;
- const char *flag;
-
- pg_verifymbstr(str, strlen(str), false);
-
- flag = NULL;
- if ((s = findchar(str, '/')))
- {
- *s++ = '\0';
- flag = s;
- while (*s)
- {
- /* we allow only single encoded flags for faster works */
- if (pg_mblen(s) == 1 && t_isprint(s) && !t_isspace(s))
- s++;
- else
- {
- *s = '\0';
- break;
- }
- }
- }
- else
- flag = "";
-
-
- s = str;
- while (*s)
- {
- if (t_isspace(s))
- {
- *s = '\0';
- break;
- }
- s += pg_mblen(s);
- }
- pstr = lowerstr(str);
-
- NIAddSpell(Conf, pstr, flag);
- pfree(pstr);
- }
- fclose(dict);
- return (0);
-}
-
-
-static int
-FindWord(IspellDict * Conf, const char *word, int affixflag, char compoundonly)
-{
- SPNode *node = Conf->Dictionary;
- SPNodeData *StopLow,
- *StopHigh,
- *StopMiddle;
- uint8 *ptr = (uint8 *) word;
-
- while (node && *ptr)
- {
- StopLow = node->data;
- StopHigh = node->data + node->length;
- while (StopLow < StopHigh)
- {
- StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
- if (StopMiddle->val == *ptr)
- {
- if (*(ptr + 1) == '\0' && StopMiddle->isword)
- {
- if (compoundonly && !StopMiddle->compoundallow)
- return 0;
- if ((affixflag == 0) || (strchr(Conf->AffixData[StopMiddle->affix], affixflag) != NULL))
- return 1;
- }
- node = StopMiddle->node;
- ptr++;
- break;
- }
- else if (StopMiddle->val < *ptr)
- StopLow = StopMiddle + 1;
- else
- StopHigh = StopMiddle;
- }
- if (StopLow >= StopHigh)
- break;
- }
- return 0;
-}
-
-int
-NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const char *find, const char *repl, int type)
-{
- if (Conf->naffixes >= Conf->maffixes)
- {
- if (Conf->maffixes)
- {
- Conf->maffixes += 16;
- Conf->Affix = (AFFIX *) realloc((void *) Conf->Affix, Conf->maffixes * sizeof(AFFIX));
- }
- else
- {
- Conf->maffixes = 16;
- Conf->Affix = (AFFIX *) malloc(Conf->maffixes * sizeof(AFFIX));
- }
- MEMOUT(Conf->Affix);
- }
-
- if (strcmp(mask, ".") == 0)
- {
- Conf->Affix[Conf->naffixes].issimple = 1;
- Conf->Affix[Conf->naffixes].isregis = 0;
- Conf->Affix[Conf->naffixes].mask = VoidString;
- }
- else if (RS_isRegis(mask))
- {
- Conf->Affix[Conf->naffixes].issimple = 0;
- Conf->Affix[Conf->naffixes].isregis = 1;
- Conf->Affix[Conf->naffixes].mask = (mask && *mask) ? strdup(mask) : VoidString;
- }
- else
- {
- int masklen = strlen(mask);
-
- Conf->Affix[Conf->naffixes].issimple = 0;
- Conf->Affix[Conf->naffixes].isregis = 0;
- Conf->Affix[Conf->naffixes].mask = (char *) malloc(masklen + 2);
- if (type == FF_SUFFIX)
- sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask);
- else
- sprintf(Conf->Affix[Conf->naffixes].mask, "^%s", mask);
- }
- MEMOUT(Conf->Affix[Conf->naffixes].mask);
-
- Conf->Affix[Conf->naffixes].compile = 1;
- Conf->Affix[Conf->naffixes].flagflags = flagflags;
- Conf->Affix[Conf->naffixes].flag = flag;
- Conf->Affix[Conf->naffixes].type = type;
-
- Conf->Affix[Conf->naffixes].find = (find && *find) ? strdup(find) : VoidString;
- MEMOUT(Conf->Affix[Conf->naffixes].find);
- if ((Conf->Affix[Conf->naffixes].replen = strlen(repl)) > 0)
- {
- Conf->Affix[Conf->naffixes].repl = strdup(repl);
- MEMOUT(Conf->Affix[Conf->naffixes].repl);
- }
- else
- Conf->Affix[Conf->naffixes].repl = VoidString;
- Conf->naffixes++;
- return (0);
-}
-
-#define PAE_WAIT_MASK 0
-#define PAE_INMASK 1
-#define PAE_WAIT_FIND 2
-#define PAE_INFIND 3
-#define PAE_WAIT_REPL 4
-#define PAE_INREPL 5
-
-static bool
-parse_affentry(char *str, char *mask, char *find, char *repl, int line)
-{
- int state = PAE_WAIT_MASK;
- char *pmask = mask,
- *pfind = find,
- *prepl = repl;
-
- *mask = *find = *repl = '\0';
-
- while (*str)
- {
- if (state == PAE_WAIT_MASK)
- {
- if (t_iseq(str, '#'))
- return false;
- else if (!t_isspace(str))
- {
- COPYCHAR(pmask, str);
- pmask += pg_mblen(str);
- state = PAE_INMASK;
- }
- }
- else if (state == PAE_INMASK)
- {
- if (t_iseq(str, '>'))
- {
- *pmask = '\0';
- state = PAE_WAIT_FIND;
- }
- else if (!t_isspace(str))
- {
- COPYCHAR(pmask, str);
- pmask += pg_mblen(str);
- }
- }
- else if (state == PAE_WAIT_FIND)
- {
- if (t_iseq(str, '-'))
- {
- state = PAE_INFIND;
- }
- else if (t_isalpha(str) || t_iseq(str, '\'') /* english 's */ )
- {
- COPYCHAR(prepl, str);
- prepl += pg_mblen(str);
- state = PAE_INREPL;
- }
- else if (!t_isspace(str))
- ts_error(ERROR, "Affix parse error at %d line", line);
- }
- else if (state == PAE_INFIND)
- {
- if (t_iseq(str, ','))
- {
- *pfind = '\0';
- state = PAE_WAIT_REPL;
- }
- else if (t_isalpha(str))
- {
- COPYCHAR(pfind, str);
- pfind += pg_mblen(str);
- }
- else if (!t_isspace(str))
- ts_error(ERROR, "Affix parse error at %d line", line);
- }
- else if (state == PAE_WAIT_REPL)
- {
- if (t_iseq(str, '-'))
- {
- break; /* void repl */
- }
- else if (t_isalpha(str))
- {
- COPYCHAR(prepl, str);
- prepl += pg_mblen(str);
- state = PAE_INREPL;
- }
- else if (!t_isspace(str))
- ts_error(ERROR, "Affix parse error at %d line", line);
- }
- else if (state == PAE_INREPL)
- {
- if (t_iseq(str, '#'))
- {
- *prepl = '\0';
- break;
- }
- else if (t_isalpha(str))
- {
- COPYCHAR(prepl, str);
- prepl += pg_mblen(str);
- }
- else if (!t_isspace(str))
- ts_error(ERROR, "Affix parse error at %d line", line);
- }
- else
- ts_error(ERROR, "Unknown state in parse_affentry: %d", state);
-
- str += pg_mblen(str);
- }
-
- *pmask = *pfind = *prepl = '\0';
-
- return (*mask && (*find || *repl)) ? true : false;
-}
-
-int
-NIImportAffixes(IspellDict * Conf, const char *filename)
-{
- char str[BUFSIZ], *pstr = NULL;
- char mask[BUFSIZ];
- char find[BUFSIZ];
- char repl[BUFSIZ];
- char *s;
- int suffixes = 0;
- int prefixes = 0;
- int flag = 0;
- char flagflags = 0;
- FILE *affix;
- int line = 0;
- int oldformat = 0;
-
- if (!(affix = fopen(filename, "r")))
- return (1);
- Conf->compoundcontrol = '\t';
-
- while (fgets(str, sizeof(str), affix))
- {
- line++;
- if ( *str == '#' || *str == '\n' )
- continue;
-
- pg_verifymbstr(str, strlen(str), false);
- if ( pstr )
- pfree( pstr );
- pstr = lowerstr(str);
- if (STRNCMP(pstr, "compoundwords") == 0)
- {
- s = findchar(str, 'l');
- if (s)
- {
- while (*s && !t_isspace(s))
- s++;
- while (*s && t_isspace(s))
- s++;
- if (*s && pg_mblen(s) == 1)
- Conf->compoundcontrol = *s;
- oldformat++;
- continue;
- }
- }
- if (STRNCMP(pstr, "suffixes") == 0)
- {
- suffixes = 1;
- prefixes = 0;
- oldformat++;
- continue;
- }
- if (STRNCMP(pstr, "prefixes") == 0)
- {
- suffixes = 0;
- prefixes = 1;
- oldformat++;
- continue;
- }
- if (STRNCMP(pstr, "flag") == 0)
- {
- s = str + 4;
- flagflags = 0;
-
- while (*s && t_isspace(s))
- s++;
- oldformat++;
-
- /* allow only single-encoded flags */
- if (pg_mblen(s) != 1)
- elog(ERROR, "Multiencoded flag at line %d: %s", line, s);
-
- if (*s == '*')
- {
- flagflags |= FF_CROSSPRODUCT;
- s++;
- }
- else if (*s == '~')
- {
- flagflags |= FF_COMPOUNDONLYAFX;
- s++;
- }
-
- if (*s == '\\')
- s++;
-
- /* allow only single-encoded flags */
- if (pg_mblen(s) != 1)
- {
- flagflags = 0;
- elog(ERROR, "Multiencoded flag at line %d: %s", line, s);
- }
-
- flag = (unsigned char) *s;
- continue;
- }
- if (STRNCMP(str, "COMPOUNDFLAG") == 0 || STRNCMP(str, "COMPOUNDMIN") == 0 ||
- STRNCMP(str, "PFX") == 0 || STRNCMP(str, "SFX") == 0)
- {
-
- if (oldformat)
- elog(ERROR, "Wrong affix file format");
-
- fclose(affix);
- return NIImportOOAffixes(Conf, filename);
-
- }
- if ((!suffixes) && (!prefixes))
- continue;
-
- if (!parse_affentry(pstr, mask, find, repl, line))
- continue;
-
- NIAddAffix(Conf, flag, flagflags, mask, find, repl, suffixes ? FF_SUFFIX : FF_PREFIX);
- }
- fclose(affix);
-
- if ( pstr )
- pfree( pstr );
-
- return (0);
-}
-
-int
-NIImportOOAffixes(IspellDict * Conf, const char *filename)
-{
- char str[BUFSIZ];
- char type[BUFSIZ], *ptype = NULL;
- char sflag[BUFSIZ];
- char mask[BUFSIZ], *pmask;
- char find[BUFSIZ], *pfind;
- char repl[BUFSIZ], *prepl;
- bool isSuffix = false;
- int flag = 0;
- char flagflags = 0;
- FILE *affix;
- int line = 0;
- int scanread = 0;
- char scanbuf[BUFSIZ];
-
- sprintf(scanbuf, "%%6s %%%ds %%%ds %%%ds %%%ds", BUFSIZ / 5, BUFSIZ / 5, BUFSIZ / 5, BUFSIZ / 5);
-
- if (!(affix = fopen(filename, "r")))
- return (1);
- Conf->compoundcontrol = '\t';
-
- while (fgets(str, sizeof(str), affix))
- {
- line++;
- if (*str == '\0' || t_isspace(str) || t_iseq(str, '#'))
- continue;
- pg_verifymbstr(str, strlen(str), false);
-
- if (STRNCMP(str, "COMPOUNDFLAG") == 0)
- {
- char *s = str + strlen("COMPOUNDFLAG");
-
- while (*s && t_isspace(s))
- s++;
- if (*s && pg_mblen(s) == 1)
- Conf->compoundcontrol = *s;
- continue;
- }
-
- scanread = sscanf(str, scanbuf, type, sflag, find, repl, mask);
-
- if (ptype)
- pfree(ptype);
- ptype = lowerstr(type);
- if (scanread < 4 || (STRNCMP(ptype, "sfx") && STRNCMP(ptype, "pfx")))
- continue;
-
- if (scanread == 4)
- {
- if (strlen(sflag) != 1)
- continue;
- flag = *sflag;
- isSuffix = (STRNCMP(ptype, "sfx") == 0) ? true : false;
- pfind = lowerstr(find);
- if (t_iseq(find, 'y'))
- flagflags |= FF_CROSSPRODUCT;
- else
- flagflags = 0;
- pfree(pfind);
- }
- else
- {
- if (strlen(sflag) != 1 || flag != *sflag || flag == 0)
- continue;
- prepl = lowerstr(repl);
- pfind = lowerstr(find);
- pmask = lowerstr(mask);
- if (t_iseq(find, '0'))
- *pfind = '\0';
- if (t_iseq(repl, '0'))
- *prepl = '\0';
-
- NIAddAffix(Conf, flag, flagflags, pmask, pfind, prepl, isSuffix ? FF_SUFFIX : FF_PREFIX);
- pfree(prepl);
- pfree(pfind);
- pfree(pmask);
- }
- }
-
- if (ptype)
- pfree(ptype);
- fclose(affix);
-
- return 0;
-}
-
-static int
-MergeAffix(IspellDict * Conf, int a1, int a2)
-{
- int naffix = 0;
- char **ptr = Conf->AffixData;
-
- while (*ptr)
- {
- naffix++;
- ptr++;
- }
-
- Conf->AffixData = (char **) realloc(Conf->AffixData, (naffix + 2) * sizeof(char *));
- MEMOUT(Conf->AffixData);
- ptr = Conf->AffixData + naffix;
- *ptr = malloc(strlen(Conf->AffixData[a1]) + strlen(Conf->AffixData[a2]) + 1 /* space */ + 1 /* \0 */ );
- MEMOUT(ptr);
- sprintf(*ptr, "%s %s", Conf->AffixData[a1], Conf->AffixData[a2]);
- ptr++;
- *ptr = '\0';
- return naffix;
-}
-
-
-static SPNode *
-mkSPNode(IspellDict * Conf, int low, int high, int level)
-{
- int i;
- int nchar = 0;
- char lastchar = '\0';
- SPNode *rs;
- SPNodeData *data;
- int lownew = low;
-
- for (i = low; i < high; i++)
- if (Conf->Spell[i]->p.d.len > level && lastchar != Conf->Spell[i]->word[level])
- {
- nchar++;
- lastchar = Conf->Spell[i]->word[level];
- }
-
- if (!nchar)
- return NULL;
-
- rs = (SPNode *) malloc(SPNHRDSZ + nchar * sizeof(SPNodeData));
- MEMOUT(rs);
- memset(rs, 0, SPNHRDSZ + nchar * sizeof(SPNodeData));
- rs->length = nchar;
- data = rs->data;
-
- lastchar = '\0';
- for (i = low; i < high; i++)
- if (Conf->Spell[i]->p.d.len > level)
- {
- if (lastchar != Conf->Spell[i]->word[level])
- {
- if (lastchar)
- {
- data->node = mkSPNode(Conf, lownew, i, level + 1);
- lownew = i;
- data++;
- }
- lastchar = Conf->Spell[i]->word[level];
- }
- data->val = ((uint8 *) (Conf->Spell[i]->word))[level];
- if (Conf->Spell[i]->p.d.len == level + 1)
- {
- if (data->isword && data->affix != Conf->Spell[i]->p.d.affix)
- {
- /*
- * fprintf(stderr,"Word already exists: %s (affixes: '%s'
- * and '%s')\n", Conf->Spell[i]->word,
- * Conf->AffixData[data->affix],
- * Conf->AffixData[Conf->Spell[i]->p.d.affix] );
- */
- /* MergeAffix called a few times */
- data->affix = MergeAffix(Conf, data->affix, Conf->Spell[i]->p.d.affix);
- }
- else
- data->affix = Conf->Spell[i]->p.d.affix;
- data->isword = 1;
- if (strchr(Conf->AffixData[data->affix], Conf->compoundcontrol))
- data->compoundallow = 1;
- }
- }
-
- data->node = mkSPNode(Conf, lownew, high, level + 1);
-
- return rs;
-}
-
-void
-NISortDictionary(IspellDict * Conf)
-{
- size_t i;
- int naffix = 3;
-
- /* compress affixes */
- qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL *), cmpspellaffix);
- for (i = 1; i < Conf->nspell; i++)
- if (strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag))
- naffix++;
-
- Conf->AffixData = (char **) malloc(naffix * sizeof(char *));
- MEMOUT(Conf->AffixData);
- memset(Conf->AffixData, 0, naffix * sizeof(char *));
- naffix = 1;
- Conf->AffixData[0] = strdup("");
- MEMOUT(Conf->AffixData[0]);
- Conf->AffixData[1] = strdup(Conf->Spell[0]->p.flag);
- MEMOUT(Conf->AffixData[1]);
- Conf->Spell[0]->p.d.affix = 1;
- Conf->Spell[0]->p.d.len = strlen(Conf->Spell[0]->word);
- for (i = 1; i < Conf->nspell; i++)
- {
- if (strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[naffix]))
- {
- naffix++;
- Conf->AffixData[naffix] = strdup(Conf->Spell[i]->p.flag);
- MEMOUT(Conf->AffixData[naffix]);
- }
- Conf->Spell[i]->p.d.affix = naffix;
- Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word);
- }
-
- qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL *), cmpspell);
- Conf->Dictionary = mkSPNode(Conf, 0, Conf->nspell, 0);
-
- for (i = 0; i < Conf->nspell; i++)
- pfree(Conf->Spell[i]);
- pfree(Conf->Spell);
- Conf->Spell = NULL;
-}
-
-static AffixNode *
-mkANode(IspellDict * Conf, int low, int high, int level, int type)
-{
- int i;
- int nchar = 0;
- uint8 lastchar = '\0';
- AffixNode *rs;
- AffixNodeData *data;
- int lownew = low;
-
- for (i = low; i < high; i++)
- if (Conf->Affix[i].replen > level && lastchar != GETCHAR(Conf->Affix + i, level, type))
- {
- nchar++;
- lastchar = GETCHAR(Conf->Affix + i, level, type);
- }
-
- if (!nchar)
- return NULL;
-
- rs = (AffixNode *) malloc(ANHRDSZ + nchar * sizeof(AffixNodeData));
- MEMOUT(rs);
- memset(rs, 0, ANHRDSZ + nchar * sizeof(AffixNodeData));
- rs->length = nchar;
- data = rs->data;
-
- lastchar = '\0';
- for (i = low; i < high; i++)
- if (Conf->Affix[i].replen > level)
- {
- if (lastchar != GETCHAR(Conf->Affix + i, level, type))
- {
- if (lastchar)
- {
- data->node = mkANode(Conf, lownew, i, level + 1, type);
- lownew = i;
- data++;
- }
- lastchar = GETCHAR(Conf->Affix + i, level, type);
- }
- data->val = GETCHAR(Conf->Affix + i, level, type);
- if (Conf->Affix[i].replen == level + 1)
- { /* affix stopped */
- if (!data->naff)
- {
- data->aff = (AFFIX **) malloc(sizeof(AFFIX *) * (high - i + 1));
- MEMOUT(data->aff);
- }
- data->aff[data->naff] = Conf->Affix + i;
- data->naff++;
- }
- }
-
- data->node = mkANode(Conf, lownew, high, level + 1, type);
-
- return rs;
-}
-
-static void
-mkVoidAffix(IspellDict * Conf, int issuffix, int startsuffix)
-{
- int i,
- cnt = 0;
- int start = (issuffix) ? startsuffix : 0;
- int end = (issuffix) ? Conf->naffixes : startsuffix;
- AffixNode *Affix = (AffixNode *) malloc(ANHRDSZ + sizeof(AffixNodeData));
-
- MEMOUT(Affix);
- memset(Affix, 0, ANHRDSZ + sizeof(AffixNodeData));
- Affix->length = 1;
- Affix->isvoid = 1;
-
- if (issuffix)
- {
- Affix->data->node = Conf->Suffix;
- Conf->Suffix = Affix;
- }
- else
- {
- Affix->data->node = Conf->Prefix;
- Conf->Prefix = Affix;
- }
-
-
- for (i = start; i < end; i++)
- if (Conf->Affix[i].replen == 0)
- cnt++;
-
- if (cnt == 0)
- return;
-
- Affix->data->aff = (AFFIX **) malloc(sizeof(AFFIX *) * cnt);
- MEMOUT(Affix->data->aff);
- Affix->data->naff = (uint32) cnt;
-
- cnt = 0;
- for (i = start; i < end; i++)
- if (Conf->Affix[i].replen == 0)
- {
- Affix->data->aff[cnt] = Conf->Affix + i;
- cnt++;
- }
-}
-
-void
-NISortAffixes(IspellDict * Conf)
-{
- AFFIX *Affix;
- size_t i;
- CMPDAffix *ptr;
- int firstsuffix = -1;
-
- if (Conf->naffixes == 0)
- return;
-
- if (Conf->naffixes > 1)
- qsort((void *) Conf->Affix, Conf->naffixes, sizeof(AFFIX), cmpaffix);
- Conf->CompoundAffix = ptr = (CMPDAffix *) malloc(sizeof(CMPDAffix) * Conf->naffixes);
- MEMOUT(Conf->CompoundAffix);
- ptr->affix = NULL;
-
- for (i = 0; i < Conf->naffixes; i++)
- {
- Affix = &(((AFFIX *) Conf->Affix)[i]);
- if (Affix->type == FF_SUFFIX)
- {
- if (firstsuffix < 0)
- firstsuffix = i;
- if ((Affix->flagflags & FF_COMPOUNDONLYAFX) && Affix->replen > 0)
- {
- if (ptr == Conf->CompoundAffix ||
- strbncmp((const unsigned char *) (ptr - 1)->affix,
- (const unsigned char *) Affix->repl,
- (ptr - 1)->len))
- {
- /* leave only unique and minimals suffixes */
- ptr->affix = Affix->repl;
- ptr->len = Affix->replen;
- ptr++;
- }
- }
- }
- }
- ptr->affix = NULL;
- Conf->CompoundAffix = (CMPDAffix *) realloc(Conf->CompoundAffix, sizeof(CMPDAffix) * (ptr - Conf->CompoundAffix + 1));
-
- Conf->Prefix = mkANode(Conf, 0, firstsuffix, 0, FF_PREFIX);
- Conf->Suffix = mkANode(Conf, firstsuffix, Conf->naffixes, 0, FF_SUFFIX);
- mkVoidAffix(Conf, 1, firstsuffix);
- mkVoidAffix(Conf, 0, firstsuffix);
-}
-
-static AffixNodeData *
-FinfAffixes(AffixNode * node, const char *word, int wrdlen, int *level, int type)
-{
- AffixNodeData *StopLow,
- *StopHigh,
- *StopMiddle;
- uint8 symbol;
-
- if (node->isvoid)
- { /* search void affixes */
- if (node->data->naff)
- return node->data;
- node = node->data->node;
- }
-
- while (node && *level < wrdlen)
- {
- StopLow = node->data;
- StopHigh = node->data + node->length;
- while (StopLow < StopHigh)
- {
- StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
- symbol = GETWCHAR(word, wrdlen, *level, type);
- if (StopMiddle->val == symbol)
- {
- (*level)++;
- if (StopMiddle->naff)
- return StopMiddle;
- node = StopMiddle->node;
- break;
- }
- else if (StopMiddle->val < symbol)
- StopLow = StopMiddle + 1;
- else
- StopHigh = StopMiddle;
- }
- if (StopLow >= StopHigh)
- break;
- }
- return NULL;
-}
-
-static char *
-CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *newword, int *baselen)
-{
-
- if (flagflags & FF_COMPOUNDONLYAFX)
- {
- if ((Affix->flagflags & FF_COMPOUNDONLYAFX) == 0)
- return NULL;
- }
- else
- {
- if (Affix->flagflags & FF_COMPOUNDONLYAFX)
- return NULL;
- }
-
- if (Affix->type == FF_SUFFIX)
- {
- strcpy(newword, word);
- strcpy(newword + len - Affix->replen, Affix->find);
- if (baselen) /* store length of non-changed part of word */
- *baselen = len - Affix->replen;
- }
- else
- {
- /*
- * if prefix is a all non-chaged part's length then all word contains
- * only prefix and suffix, so out
- */
- if (baselen && *baselen + strlen(Affix->find) <= Affix->replen)
- return NULL;
- strcpy(newword, Affix->find);
- strcat(newword, word + Affix->replen);
- }
-
- if (Affix->issimple)
- return newword;
- else if (Affix->isregis)
- {
- if (Affix->compile)
- {
- RS_compile(&(Affix->reg.regis), (Affix->type == FF_SUFFIX) ? true : false, Affix->mask);
- Affix->compile = 0;
- }
- if (RS_execute(&(Affix->reg.regis), newword))
- return newword;
- }
- else
- {
- int err;
- pg_wchar *data;
- size_t data_len;
- int newword_len;
-
- if (Affix->compile)
- {
- 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.regex), mask, wmasklen, REG_ADVANCED | REG_NOSUB);
- pfree(mask);
- if (err)
- {
- char regerrstr[ERRSTRSIZE];
-
- pg_regerror(err, &(Affix->reg.regex), regerrstr, ERRSTRSIZE);
- elog(ERROR, "regex error in '%s': %s", Affix->mask, regerrstr);
- }
- Affix->compile = 0;
- }
-
- /* Convert data string to wide characters */
- newword_len = strlen(newword);
- data = (pg_wchar *) palloc((newword_len + 1) * sizeof(pg_wchar));
- data_len = pg_mb2wchar_with_len(newword, data, newword_len);
-
- if (!(err = pg_regexec(&(Affix->reg.regex), data, data_len, 0, NULL, 0, NULL, 0)))
- {
- pfree(data);
- return newword;
- }
- pfree(data);
- }
-
- return NULL;
-}
-
-
-static char **
-NormalizeSubWord(IspellDict * Conf, char *word, char flag)
-{
- AffixNodeData *suffix = NULL,
- *prefix = NULL;
- int slevel = 0,
- plevel = 0;
- int wrdlen = strlen(word),
- swrdlen;
- char **forms;
- char **cur;
- char newword[2 * MAXNORMLEN] = "";
- char pnewword[2 * MAXNORMLEN] = "";
- AffixNode *snode = Conf->Suffix,
- *pnode;
- int i,
- j;
-
- if (wrdlen > MAXNORMLEN)
- return NULL;
- cur = forms = (char **) palloc(MAX_NORM * sizeof(char *));
- *cur = NULL;
-
-
- /* Check that the word itself is normal form */
- if (FindWord(Conf, word, 0, flag & FF_COMPOUNDWORD))
- {
- *cur = pstrdup(word);
- cur++;
- *cur = NULL;
- }
-
- /* Find all other NORMAL forms of the 'word' (check only prefix) */
- pnode = Conf->Prefix;
- plevel = 0;
- while (pnode)
- {
- prefix = FinfAffixes(pnode, word, wrdlen, &plevel, FF_PREFIX);
- if (!prefix)
- break;
- for (j = 0; j < prefix->naff; j++)
- {
- if (CheckAffix(word, wrdlen, prefix->aff[j], flag, newword, NULL))
- {
- /* prefix success */
- if (FindWord(Conf, newword, prefix->aff[j]->flag, flag & FF_COMPOUNDWORD) && (cur - forms) < (MAX_NORM - 1))
- {
- /* word search success */
- *cur = pstrdup(newword);
- cur++;
- *cur = NULL;
- }
- }
- }
- pnode = prefix->node;
- }
-
- /*
- * Find all other NORMAL forms of the 'word' (check suffix and then
- * prefix)
- */
- while (snode)
- {
- int baselen = 0;
-
- /* find possible suffix */
- suffix = FinfAffixes(snode, word, wrdlen, &slevel, FF_SUFFIX);
- if (!suffix)
- break;
- /* foreach suffix check affix */
- for (i = 0; i < suffix->naff; i++)
- {
- if (CheckAffix(word, wrdlen, suffix->aff[i], flag, newword, &baselen))
- {
- /* suffix success */
- if (FindWord(Conf, newword, suffix->aff[i]->flag, flag & FF_COMPOUNDWORD) && (cur - forms) < (MAX_NORM - 1))
- {
- /* word search success */
- *cur = pstrdup(newword);
- cur++;
- *cur = NULL;
- }
- /* now we will look changed word with prefixes */
- pnode = Conf->Prefix;
- plevel = 0;
- swrdlen = strlen(newword);
- while (pnode)
- {
- prefix = FinfAffixes(pnode, newword, swrdlen, &plevel, FF_PREFIX);
- if (!prefix)
- break;
- for (j = 0; j < prefix->naff; j++)
- {
- if (CheckAffix(newword, swrdlen, prefix->aff[j], flag, pnewword, &baselen))
- {
- /* prefix success */
- int ff = (prefix->aff[j]->flagflags & suffix->aff[i]->flagflags & FF_CROSSPRODUCT) ?
- 0 : prefix->aff[j]->flag;
-
- if (FindWord(Conf, pnewword, ff, flag & FF_COMPOUNDWORD) && (cur - forms) < (MAX_NORM - 1))
- {
- /* word search success */
- *cur = pstrdup(pnewword);
- cur++;
- *cur = NULL;
- }
- }
- }
- pnode = prefix->node;
- }
- }
- }
-
- snode = suffix->node;
- }
-
- if (cur == forms)
- {
- pfree(forms);
- return (NULL);
- }
- return (forms);
-}
-
-typedef struct SplitVar
-{
- int nstem;
- char **stem;
- struct SplitVar *next;
-} SplitVar;
-
-static int
-CheckCompoundAffixes(CMPDAffix ** ptr, char *word, int len, bool CheckInPlace)
-{
- if (CheckInPlace)
- {
- while ((*ptr)->affix)
- {
- if (len > (*ptr)->len && strncmp((*ptr)->affix, word, (*ptr)->len) == 0)
- {
- len = (*ptr)->len;
- (*ptr)++;
- return len;
- }
- (*ptr)++;
- }
- }
- else
- {
- char *affbegin;
-
- while ((*ptr)->affix)
- {
- if (len > (*ptr)->len && (affbegin = strstr(word, (*ptr)->affix)) != NULL)
- {
- len = (*ptr)->len + (affbegin - word);
- (*ptr)++;
- return len;
- }
- (*ptr)++;
- }
- }
- return 0;
-}
-
-static SplitVar *
-CopyVar(SplitVar * s, int makedup)
-{
- SplitVar *v = (SplitVar *) palloc(sizeof(SplitVar));
-
- v->stem = (char **) palloc(sizeof(char *) * (MAX_NORM));
- v->next = NULL;
- if (s)
- {
- int i;
-
- v->nstem = s->nstem;
- for (i = 0; i < s->nstem; i++)
- v->stem[i] = (makedup) ? pstrdup(s->stem[i]) : s->stem[i];
- }
- else
- v->nstem = 0;
- return v;
-}
-
-
-static SplitVar *
-SplitToVariants(IspellDict * Conf, SPNode * snode, SplitVar * orig, char *word, int wordlen, int startpos, int minpos)
-{
- SplitVar *var = NULL;
- SPNodeData *StopLow,
- *StopHigh,
- *StopMiddle = NULL;
- SPNode *node = (snode) ? snode : Conf->Dictionary;
- int level = (snode) ? minpos : startpos; /* recursive
- * minpos==level */
- int lenaff;
- CMPDAffix *caff;
- char *notprobed;
-
- notprobed = (char *) palloc(wordlen);
- memset(notprobed, 1, wordlen);
- var = CopyVar(orig, 1);
-
- while (level < wordlen)
- {
- /* find word with epenthetic or/and compound suffix */
- caff = Conf->CompoundAffix;
- while (level > startpos && (lenaff = CheckCompoundAffixes(&caff, word + level, wordlen - level, (node) ? true : false)) > 0)
- {
- /*
- * there is one of compound suffixes, so check word for existings
- */
- char buf[MAXNORMLEN];
- char **subres;
-
- lenaff = level - startpos + lenaff;
-
- if (!notprobed[startpos + lenaff - 1])
- continue;
-
- if (level + lenaff - 1 <= minpos)
- continue;
-
- memcpy(buf, word + startpos, lenaff);
- buf[lenaff] = '\0';
-
- subres = NormalizeSubWord(Conf, buf, FF_COMPOUNDWORD | FF_COMPOUNDONLYAFX);
- if (subres)
- {
- /* Yes, it was a word from dictionary */
- SplitVar *new = CopyVar(var, 0);
- SplitVar *ptr = var;
- char **sptr = subres;
-
- notprobed[startpos + lenaff - 1] = 0;
-
- while (*sptr)
- {
- new->stem[new->nstem] = *sptr;
- new->nstem++;
- sptr++;
- }
- pfree(subres);
-
- while (ptr->next)
- ptr = ptr->next;
- ptr->next = SplitToVariants(Conf, NULL, new, word, wordlen, startpos + lenaff, startpos + lenaff);
-
- pfree(new->stem);
- pfree(new);
- }
- }
-
- if (!node)
- break;
-
- StopLow = node->data;
- StopHigh = node->data + node->length;
- while (StopLow < StopHigh)
- {
- StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
- if (StopMiddle->val == ((uint8 *) (word))[level])
- break;
- else if (StopMiddle->val < ((uint8 *) (word))[level])
- StopLow = StopMiddle + 1;
- else
- StopHigh = StopMiddle;
- }
-
- if (StopLow < StopHigh)
- {
-
- /* find infinitive */
- if (StopMiddle->isword && StopMiddle->compoundallow && notprobed[level])
- {
- /* ok, we found full compoundallowed word */
- if (level > minpos)
- {
- /* and its length more than minimal */
- if (wordlen == level + 1)
- {
- /* well, it was last word */
- var->stem[var->nstem] = strnduplicate(word + startpos, wordlen - startpos);
- var->nstem++;
- pfree(notprobed);
- return var;
- }
- else
- {
- /* then we will search more big word at the same point */
- SplitVar *ptr = var;
-
- while (ptr->next)
- ptr = ptr->next;
- ptr->next = SplitToVariants(Conf, node, var, word, wordlen, startpos, level);
- /* we can find next word */
- level++;
- var->stem[var->nstem] = strnduplicate(word + startpos, level - startpos);
- var->nstem++;
- node = Conf->Dictionary;
- startpos = level;
- continue;
- }
- }
- }
- node = StopMiddle->node;
- }
- else
- node = NULL;
- level++;
- }
-
- var->stem[var->nstem] = strnduplicate(word + startpos, wordlen - startpos);
- var->nstem++;
- pfree(notprobed);
- return var;
-}
-
-TSLexeme *
-NINormalizeWord(IspellDict * Conf, char *uword)
-{
- char **res;
- char *word;
- TSLexeme *lcur = NULL,
- *lres = NULL;
- uint16 NVariant = 1;
-
- word = lowerstr(uword);
- res = NormalizeSubWord(Conf, word, 0);
-
- if (res)
- {
- char **ptr = res;
-
- lcur = lres = (TSLexeme *) palloc(MAX_NORM * sizeof(TSLexeme));
- while (*ptr)
- {
- lcur->lexeme = *ptr;
- lcur->flags = 0;
- lcur->nvariant = NVariant++;
- lcur++;
- ptr++;
- }
- lcur->lexeme = NULL;
- pfree(res);
- }
-
- if (Conf->compoundcontrol != '\t')
- {
- int wordlen = strlen(word);
- SplitVar *ptr,
- *var = SplitToVariants(Conf, NULL, NULL, word, wordlen, 0, -1);
- int i;
-
- while (var)
- {
- if (var->nstem > 1)
- {
- char **subres = NormalizeSubWord(Conf, var->stem[var->nstem - 1], FF_COMPOUNDWORD);
-
- if (subres)
- {
- char **subptr = subres;
-
- if (!lcur)
- lcur = lres = (TSLexeme *) palloc(MAX_NORM * sizeof(TSLexeme));
-
- while (*subptr)
- {
- for (i = 0; i < var->nstem - 1; i++)
- {
- lcur->lexeme = (subptr == subres) ? var->stem[i] : pstrdup(var->stem[i]);
- lcur->flags = 0;
- lcur->nvariant = NVariant;
- lcur++;
- }
-
- lcur->lexeme = *subptr;
- lcur->flags = 0;
- lcur->nvariant = NVariant;
- lcur++;
- subptr++;
- NVariant++;
- }
-
- lcur->lexeme = NULL;
- pfree(subres);
- var->stem[0] = NULL;
- pfree(var->stem[var->nstem - 1]);
- }
- }
-
- for (i = 0; i < var->nstem && var->stem[i]; i++)
- pfree(var->stem[i]);
- ptr = var->next;
- pfree(var->stem);
- pfree(var);
- var = ptr;
- }
- }
-
- pfree(word);
-
- return lres;
-}
-
-
-static void
-freeSPNode(SPNode * node)
-{
- SPNodeData *data;
-
- if (!node)
- return;
- data = node->data;
- while (node->length)
- {
- freeSPNode(data->node);
- data++;
- node->length--;
- }
- free(node);
-}
-
-static void
-freeANode(AffixNode * node)
-{
- AffixNodeData *data;
-
- if (!node)
- return;
- data = node->data;
- while (node->length)
- {
- freeANode(data->node);
- if (data->naff)
- free(data->aff);
- data++;
- node->length--;
- }
- free(node);
-}
-
-
-void
-NIFree(IspellDict * Conf)
-{
- int i;
- AFFIX *Affix = (AFFIX *) Conf->Affix;
- char **aff = Conf->AffixData;
-
- if (aff)
- {
- while (*aff)
- {
- free(*aff);
- aff++;
- }
- free(Conf->AffixData);
- }
-
-
- for (i = 0; i < Conf->naffixes; i++)
- {
- if (Affix[i].compile == 0)
- {
- if (Affix[i].isregis)
- RS_free(&(Affix[i].reg.regis));
- else
- pg_regfree(&(Affix[i].reg.regex));
- }
- if (Affix[i].mask != VoidString)
- free(Affix[i].mask);
- if (Affix[i].find != VoidString)
- free(Affix[i].find);
- if (Affix[i].repl != VoidString)
- free(Affix[i].repl);
- }
- if (Conf->Spell)
- {
- for (i = 0; i < Conf->nspell; i++)
- pfree(Conf->Spell[i]);
- pfree(Conf->Spell);
- }
-
- if (Conf->Affix)
- free(Conf->Affix);
- if (Conf->CompoundAffix)
- free(Conf->CompoundAffix);
- freeSPNode(Conf->Dictionary);
- freeANode(Conf->Suffix);
- freeANode(Conf->Prefix);
- memset((void *) Conf, 0, sizeof(IspellDict));
- return;
-}
+++ /dev/null
-#ifndef __SPELL_H__
-#define __SPELL_H__
-
-#include "c.h"
-
-#include
-
-#include "regex/regex.h"
-
-#include "regis.h"
-#include "dict.h"
-
-struct SPNode;
-
-
-typedef struct
-{
- uint32
- val:8,
- isword:1,
- compoundallow:1,
- affix:22;
- struct SPNode *node;
-} SPNodeData;
-
-typedef struct SPNode
-{
- uint32 length;
- SPNodeData data[1];
-} SPNode;
-
-#define SPNHRDSZ (sizeof(uint32))
-
-
-typedef struct spell_struct
-{
- union
- {
- char flag[16];
- struct
- {
- int affix;
- int len;
- } d;
- } p;
- char word[1];
-} SPELL;
-
-#define SPELLHDRSZ (offsetof(SPELL, word))
-
-typedef struct aff_struct
-{
- uint32
- flag:8,
- type:2,
- compile:1,
- flagflags:3,
- issimple:1,
- isregis:1,
- unused:1,
- replen:16;
- char *mask;
- char *find;
- char *repl;
- union
- {
- regex_t regex;
- Regis regis;
- } reg;
-} AFFIX;
-
-#define FF_CROSSPRODUCT 0x01
-#define FF_COMPOUNDWORD 0x02
-#define FF_COMPOUNDONLYAFX 0x04
-#define FF_SUFFIX 2
-#define FF_PREFIX 1
-
-struct AffixNode;
-
-typedef struct
-{
- uint32
- val:8,
- naff:24;
- AFFIX **aff;
- struct AffixNode *node;
-} AffixNodeData;
-
-typedef struct AffixNode
-{
- uint32 isvoid:1,
- length:31;
- AffixNodeData data[1];
-} AffixNode;
-
-#define ANHRDSZ (sizeof(uint32))
-
-typedef struct
-{
- char *affix;
- int len;
-} CMPDAffix;
-
-typedef struct
-{
- int maffixes;
- int naffixes;
- AFFIX *Affix;
- char compoundcontrol;
-
- int nspell;
- int mspell;
- SPELL **Spell;
-
- AffixNode *Suffix;
- AffixNode *Prefix;
-
- SPNode *Dictionary;
- char **AffixData;
- CMPDAffix *CompoundAffix;
-
-} IspellDict;
-
-TSLexeme *NINormalizeWord(IspellDict * Conf, char *word);
-int NIImportAffixes(IspellDict * Conf, const char *filename);
-int NIImportOOAffixes(IspellDict * Conf, const char *filename);
-int NIImportDictionary(IspellDict * Conf, const char *filename);
-
-int NIAddSpell(IspellDict * Conf, const char *word, const char *flag);
-int NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const char *find, const char *repl, int type);
-void NISortDictionary(IspellDict * Conf);
-void NISortAffixes(IspellDict * Conf);
-void NIFree(IspellDict * Conf);
-
-#endif
+++ /dev/null
-ZIPFILE=nb_NO
-LANGUAGE=norsk
-
-
-UNZIP=unzip -o
-
-
-all: $(LANGUAGE).dict $(LANGUAGE).aff
-
-$(ZIPFILE).aff: $(ZIPFILE).zip
- $(UNZIP) $? $@
- touch $@
-
-
-# 1 Cleanup dictionary
-# 2 remove " symbol
-# 3 add compoundwords controlled flag to word which hasn't it, but
-# has compound only suffixes
-
-$(LANGUAGE).dict: $(ZIPFILE).zip
- $(UNZIP) $? $(ZIPFILE).dic
- grep -v -E '^[[:digit:]]+$$' < $(ZIPFILE).dic \
- | grep -v '\.' \
- | sed -e 's/"//g' \
- | perl -pi -e 's|/(\S+)| $$q=$$1; ( $$q=~/[\\_`]/ && $$q!~/z/ ) ? "/$${q}z" : "/$${q}"|e' \
- | sort \
- > $@
-
-#just convert affix file
-
-$(LANGUAGE).aff: $(ZIPFILE).aff
- grep -v -i zyzyzy $(ZIPFILE).aff \
- | grep -v -i zyzyzy \
- | perl -pi \
- -e 's/^COMPOUNDFLAG\s+(\S+)/compoundwords controlled $$1/;' \
- -e 's/^COMPOUNDMIN\s+(\d+)/compoundmin $$1/;' \
- -e 's/^PFX\s+(\S+)\s+([YN])\s+\d+.*$$/ if ( !$$wasprf ) { $$wasprf=1; "prefixes\n\nflag $$1:" } else { "flag $$1:" } /e;' \
- -e 's/^PFX\s+\S+\s+(\S+)\s+(\S+)\s+(\S+)/ uc(" $$3 > $$2")/e;' \
- -e 's/^(.*)SFX\s+(\S+)\s+([YN])\s+\d+.*$$/ $$flg=($$3 eq "Y") ? "*" : ""; $$flg="~$$flg" if length $$1; $$q=$$2; $$q="\\$$q" if $$q!~m#[a-zA-Z]#; if ( !$$wassfx ) { $$wassfx=1; "suffixes\n\nflag $$flg$$q:" } else { "flag $$flg$$q:" } /e;' \
- -e 's/^.*SFX\s+\S+\s+(\S+)\s+(\S+)\s+(\S+)/ uc(" $$3 > ".( ($$1 eq "0") ? "" : "-$$1,").( ($$2 eq "0") ? "" : "$$2") )/e;' \
- -e 's/^(SET|TRY)/#$$1/' \
- > $@
-
-clean:
- rm -rf $(ZIPFILE).aff $(ZIPFILE).dic $(LANGUAGE).dict $(LANGUAGE).aff
-
-
+++ /dev/null
-Utility for convert MySpell dictionary and affix from
-myspell to ispell format.
-Utility tested on nb_NO.zip and nn_NO.zip from
-OpenOffice (http://lingucomponent.openoffice.org/download_dictionary.html)
-
-usage:
-For example, make norwegian dictionary and affix:
-% cp nb_NO.zip my2ispell
-% cd my2ispell
-% gmake ZIPFILE=nb_NO LANGUAGE=norsk
-
-Author: Teodor Sigaev
+++ /dev/null
-/*
- * Simple config parser
- * Teodor Sigaev
- */
-#include "postgres.h"
-
-#include
-
-#include "dict.h"
-#include "common.h"
-#include "ts_locale.h"
-
-#define CS_WAITKEY 0
-#define CS_INKEY 1
-#define CS_WAITEQ 2
-#define CS_WAITVALUE 3
-#define CS_INVALUE 4
-#define CS_IN2VALUE 5
-#define CS_WAITDELIM 6
-#define CS_INESC 7
-#define CS_IN2ESC 8
-
-static char *
-nstrdup(char *ptr, int len)
-{
- char *res = palloc(len + 1),
- *cptr;
-
- memcpy(res, ptr, len);
- res[len] = '\0';
- cptr = ptr = res;
- while (*ptr)
- {
- if (t_iseq(ptr, '\\'))
- ptr++;
- COPYCHAR(cptr, ptr);
- cptr += pg_mblen(ptr);
- ptr += pg_mblen(ptr);
- }
- *cptr = '\0';
-
- return res;
-}
-
-void
-parse_cfgdict(text *in, Map ** m)
-{
- Map *mptr;
- char *ptr = VARDATA(in),
- *begin = NULL;
- char num = 0;
- int state = CS_WAITKEY;
-
- while (ptr - VARDATA(in) < VARSIZE(in) - VARHDRSZ)
- {
- if (t_iseq(ptr, ','))
- num++;
- ptr += pg_mblen(ptr);
- }
-
- *m = mptr = (Map *) palloc(sizeof(Map) * (num + 2));
- memset(mptr, 0, sizeof(Map) * (num + 2));
- ptr = VARDATA(in);
- while (ptr - VARDATA(in) < VARSIZE(in) - VARHDRSZ)
- {
- if (state == CS_WAITKEY)
- {
- if (t_isalpha(ptr))
- {
- begin = ptr;
- state = CS_INKEY;
- }
- else if (!t_isspace(ptr))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error"),
- errdetail("Syntax error in position %d.",
- (int) (ptr - VARDATA(in)))));
- }
- else if (state == CS_INKEY)
- {
- if (t_isspace(ptr))
- {
- mptr->key = nstrdup(begin, ptr - begin);
- state = CS_WAITEQ;
- }
- else if (t_iseq(ptr, '='))
- {
- mptr->key = nstrdup(begin, ptr - begin);
- state = CS_WAITVALUE;
- }
- else if (!t_isalpha(ptr))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error"),
- errdetail("Syntax error in position %d.",
- (int) (ptr - VARDATA(in)))));
- }
- else if (state == CS_WAITEQ)
- {
- if (t_iseq(ptr, '='))
- state = CS_WAITVALUE;
- else if (!t_isspace(ptr))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error"),
- errdetail("Syntax error in position %d.",
- (int) (ptr - VARDATA(in)))));
- }
- else if (state == CS_WAITVALUE)
- {
- if (t_iseq(ptr, '"'))
- {
- begin = ptr + 1;
- state = CS_INVALUE;
- }
- else if (!t_isspace(ptr))
- {
- begin = ptr;
- state = CS_IN2VALUE;
- }
- }
- else if (state == CS_INVALUE)
- {
- if (t_iseq(ptr, '"'))
- {
- mptr->value = nstrdup(begin, ptr - begin);
- mptr++;
- state = CS_WAITDELIM;
- }
- else if (t_iseq(ptr, '\\'))
- state = CS_INESC;
- }
- else if (state == CS_IN2VALUE)
- {
- if (t_isspace(ptr) || t_iseq(ptr, ','))
- {
- mptr->value = nstrdup(begin, ptr - begin);
- mptr++;
- state = (t_iseq(ptr, ',')) ? CS_WAITKEY : CS_WAITDELIM;
- }
- else if (t_iseq(ptr, '\\'))
- state = CS_INESC;
- }
- else if (state == CS_WAITDELIM)
- {
- if (t_iseq(ptr, ','))
- state = CS_WAITKEY;
- else if (!t_isspace(ptr))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error"),
- errdetail("Syntax error in position %d.",
- (int) (ptr - VARDATA(in)))));
- }
- else if (state == CS_INESC)
- state = CS_INVALUE;
- else if (state == CS_IN2ESC)
- state = CS_IN2VALUE;
- else
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("bad parser state"),
- errdetail("%d at position %d.",
- state, (int) (ptr - VARDATA(in)))));
- ptr += pg_mblen(ptr);
- }
-
- if (state == CS_IN2VALUE)
- {
- mptr->value = nstrdup(begin, ptr - begin);
- mptr++;
- }
- else if (!(state == CS_WAITDELIM || state == CS_WAITKEY))
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("unexpected end of line")));
-}
+++ /dev/null
-/*
- * IO definitions for tsquery and mtsquery. This type
- * are identical, but for parsing mtsquery used parser for text
- * and also morphology is used.
- * Internal structure:
- * query tree, then string with original value.
- * Query tree with plain view. It's means that in array of nodes
- * right child is always next and left position = item+item->left
- * Teodor Sigaev
- */
-#include "postgres.h"
-
-#include
-#include
-
-#include "access/gist.h"
-#include "access/itup.h"
-#include "storage/bufpage.h"
-#include "utils/array.h"
-#include "utils/builtins.h"
-
-#include "ts_cfg.h"
-#include "tsvector.h"
-#include "crc32.h"
-#include "query.h"
-#include "query_cleanup.h"
-#include "common.h"
-#include "ts_locale.h"
-
-PG_FUNCTION_INFO_V1(tsquery_in);
-Datum tsquery_in(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(tsquery_out);
-Datum tsquery_out(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(exectsq);
-Datum exectsq(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(rexectsq);
-Datum rexectsq(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(tsquerytree);
-Datum tsquerytree(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(to_tsquery);
-Datum to_tsquery(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(to_tsquery_name);
-Datum to_tsquery_name(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(to_tsquery_current);
-Datum to_tsquery_current(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(plainto_tsquery);
-Datum plainto_tsquery(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(plainto_tsquery_name);
-Datum plainto_tsquery_name(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(plainto_tsquery_current);
-Datum plainto_tsquery_current(PG_FUNCTION_ARGS);
-
-/* parser's states */
-#define WAITOPERAND 1
-#define WAITOPERATOR 2
-#define WAITFIRSTOPERAND 3
-#define WAITSINGLEOPERAND 4
-
-/*
- * node of query tree, also used
- * for storing polish notation in parser
- */
-typedef struct NODE
-{
- int2 weight;
- int2 type;
- int4 val;
- int2 distance;
- int2 length;
- struct NODE *next;
-} NODE;
-
-typedef struct
-{
- char *buffer; /* entire string we are scanning */
- char *buf; /* current scan point */
- int4 state;
- int4 count;
- /* reverse polish notation in list (for temprorary usage) */
- NODE *str;
- /* number in str */
- int4 num;
-
- /* user-friendly operand */
- int4 lenop;
- int4 sumlen;
- char *op;
- char *curop;
-
- /* state for value's parser */
- TI_IN_STATE valstate;
-
- /* tscfg */
- int cfg_id;
-} QPRS_STATE;
-
-static char *
-get_weight(char *buf, int2 *weight)
-{
- *weight = 0;
-
- if (!t_iseq(buf, ':'))
- return buf;
-
- buf++;
- while (*buf && pg_mblen(buf) == 1)
- {
- switch (*buf)
- {
- case 'a':
- case 'A':
- *weight |= 1 << 3;
- break;
- case 'b':
- case 'B':
- *weight |= 1 << 2;
- break;
- case 'c':
- case 'C':
- *weight |= 1 << 1;
- break;
- case 'd':
- case 'D':
- *weight |= 1;
- break;
- default:
- return buf;
- }
- buf++;
- }
-
- return buf;
-}
-
-/*
- * get token from query string
- */
-static int4
-gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2 *weight)
-{
- while (1)
- {
- switch (state->state)
- {
- case WAITFIRSTOPERAND:
- case WAITOPERAND:
- if (t_iseq(state->buf, '!'))
- {
- (state->buf)++; /* can safely ++, t_iseq guarantee
- * that pg_mblen()==1 */
- *val = (int4) '!';
- state->state = WAITOPERAND;
- return OPR;
- }
- else if (t_iseq(state->buf, '('))
- {
- state->count++;
- (state->buf)++;
- state->state = WAITOPERAND;
- return OPEN;
- }
- else if (t_iseq(state->buf, ':'))
- {
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("error at start of operand in tsearch query: \"%s\"",
- state->buffer)));
- }
- else if (!t_isspace(state->buf))
- {
- state->valstate.prsbuf = state->buf;
- if (gettoken_tsvector(&(state->valstate)))
- {
- *strval = state->valstate.word;
- *lenval = state->valstate.curpos - state->valstate.word;
- state->buf = get_weight(state->valstate.prsbuf, weight);
- state->state = WAITOPERATOR;
- return VAL;
- }
- else if (state->state == WAITFIRSTOPERAND)
- return END;
- else
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("no operand in tsearch query: \"%s\"",
- state->buffer)));
- }
- break;
- case WAITOPERATOR:
- if (t_iseq(state->buf, '&') || t_iseq(state->buf, '|'))
- {
- state->state = WAITOPERAND;
- *val = (int4) *(state->buf);
- (state->buf)++;
- return OPR;
- }
- else if (t_iseq(state->buf, ')'))
- {
- (state->buf)++;
- state->count--;
- return (state->count < 0) ? ERR : CLOSE;
- }
- else if (*(state->buf) == '\0')
- return (state->count) ? ERR : END;
- else if (!t_isspace(state->buf))
- return ERR;
- break;
- case WAITSINGLEOPERAND:
- if (*(state->buf) == '\0')
- return END;
- *strval = state->buf;
- *lenval = strlen(state->buf);
- state->buf += strlen(state->buf);
- state->count++;
- return VAL;
- default:
- return ERR;
- break;
- }
- state->buf += pg_mblen(state->buf);
- }
- return END;
-}
-
-/*
- * push new one in polish notation reverse view
- */
-static void
-pushquery(QPRS_STATE * state, int4 type, int4 val, int4 distance, int4 lenval, int2 weight)
-{
- NODE *tmp = (NODE *) palloc(sizeof(NODE));
-
- tmp->weight = weight;
- tmp->type = type;
- tmp->val = val;
- if (distance >= MAXSTRPOS)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("value is too big in tsearch query: \"%s\"",
- state->buffer)));
- if (lenval >= MAXSTRLEN)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("operand is too long in tsearch query: \"%s\"",
- state->buffer)));
- tmp->distance = distance;
- tmp->length = lenval;
- tmp->next = state->str;
- state->str = tmp;
- state->num++;
-}
-
-/*
- * This function is used for tsquery parsing
- */
-static void
-pushval_asis(QPRS_STATE * state, int type, char *strval, int lenval, int2 weight)
-{
- if (lenval >= MAXSTRLEN)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("word is too long in tsearch query: \"%s\"",
- state->buffer)));
-
- pushquery(state, type, crc32_sz(strval, lenval),
- state->curop - state->op, lenval, weight);
-
- while (state->curop - state->op + lenval + 1 >= state->lenop)
- {
- int4 tmp = state->curop - state->op;
-
- state->lenop *= 2;
- state->op = (char *) repalloc((void *) state->op, state->lenop);
- state->curop = state->op + tmp;
- }
- memcpy((void *) state->curop, (void *) strval, lenval);
- state->curop += lenval;
- *(state->curop) = '\0';
- state->curop++;
- state->sumlen += lenval + 1;
- return;
-}
-
-/*
- * This function is used for morph parsing
- */
-static void
-pushval_morph(QPRS_STATE * state, int typeval, char *strval, int lenval, int2 weight)
-{
- int4 count = 0;
- PRSTEXT prs;
- uint32 variant,
- pos,
- cntvar = 0,
- cntpos = 0,
- cnt = 0;
-
- prs.lenwords = 32;
- prs.curwords = 0;
- prs.pos = 0;
- prs.words = (TSWORD *) palloc(sizeof(TSWORD) * prs.lenwords);
-
- parsetext_v2(findcfg(state->cfg_id), &prs, strval, lenval);
-
- if (prs.curwords > 0)
- {
-
- while (count < prs.curwords)
- {
- pos = prs.words[count].pos.pos;
- cntvar = 0;
- while (count < prs.curwords && pos == prs.words[count].pos.pos)
- {
- variant = prs.words[count].nvariant;
-
- cnt = 0;
- while (count < prs.curwords && pos == prs.words[count].pos.pos && variant == prs.words[count].nvariant)
- {
-
- pushval_asis(state, VAL, prs.words[count].word, prs.words[count].len, weight);
- pfree(prs.words[count].word);
- if (cnt)
- pushquery(state, OPR, (int4) '&', 0, 0, 0);
- cnt++;
- count++;
- }
-
- if (cntvar)
- pushquery(state, OPR, (int4) '|', 0, 0, 0);
- cntvar++;
- }
-
- if (cntpos)
- pushquery(state, OPR, (int4) '&', 0, 0, 0);
-
- cntpos++;
- }
-
- pfree(prs.words);
-
- }
- else
- pushval_asis(state, VALSTOP, NULL, 0, 0);
-}
-
-#define STACKDEPTH 32
-/*
- * make polish notaion of query
- */
-static int4
-makepol(QPRS_STATE * state, void (*pushval) (QPRS_STATE *, int, char *, int, int2))
-{
- int4 val = 0,
- type;
- int4 lenval = 0;
- char *strval = NULL;
- int4 stack[STACKDEPTH];
- int4 lenstack = 0;
- int2 weight = 0;
-
- while ((type = gettoken_query(state, &val, &lenval, &strval, &weight)) != END)
- {
- switch (type)
- {
- case VAL:
- (*pushval) (state, VAL, strval, lenval, weight);
- while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
- stack[lenstack - 1] == (int4) '!'))
- {
- lenstack--;
- pushquery(state, OPR, stack[lenstack], 0, 0, 0);
- }
- break;
- case OPR:
- if (lenstack && val == (int4) '|')
- pushquery(state, OPR, val, 0, 0, 0);
- else
- {
- if (lenstack == STACKDEPTH)
- /* internal error */
- elog(ERROR, "stack too short");
- stack[lenstack] = val;
- lenstack++;
- }
- break;
- case OPEN:
- if (makepol(state, pushval) == ERR)
- return ERR;
- if (lenstack && (stack[lenstack - 1] == (int4) '&' ||
- stack[lenstack - 1] == (int4) '!'))
- {
- lenstack--;
- pushquery(state, OPR, stack[lenstack], 0, 0, 0);
- }
- break;
- case CLOSE:
- while (lenstack)
- {
- lenstack--;
- pushquery(state, OPR, stack[lenstack], 0, 0, 0);
- };
- return END;
- break;
- case ERR:
- default:
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("syntax error in tsearch query: \"%s\"",
- state->buffer)));
- return ERR;
-
- }
- }
- while (lenstack)
- {
- lenstack--;
- pushquery(state, OPR, stack[lenstack], 0, 0, 0);
- };
- return END;
-}
-
-typedef struct
-{
- WordEntry *arrb;
- WordEntry *arre;
- char *values;
- char *operand;
-} CHKVAL;
-
-/*
- * compare 2 string values
- */
-static int4
-ValCompare(CHKVAL * chkval, WordEntry * ptr, ITEM * item)
-{
- if (ptr->len == item->length)
- return strncmp(
- &(chkval->values[ptr->pos]),
- &(chkval->operand[item->distance]),
- item->length);
-
- return (ptr->len > item->length) ? 1 : -1;
-}
-
-/*
- * check weight info
- */
-static bool
-checkclass_str(CHKVAL * chkval, WordEntry * val, ITEM * item)
-{
- WordEntryPos *ptr = (WordEntryPos *) (chkval->values + val->pos + SHORTALIGN(val->len) + sizeof(uint16));
- uint16 len = *((uint16 *) (chkval->values + val->pos + SHORTALIGN(val->len)));
-
- while (len--)
- {
- if (item->weight & (1 << WEP_GETWEIGHT(*ptr)))
- return true;
- ptr++;
- }
- return false;
-}
-
-/*
- * is there value 'val' in array or not ?
- */
-static bool
-checkcondition_str(void *checkval, ITEM * val)
-{
- WordEntry *StopLow = ((CHKVAL *) checkval)->arrb;
- WordEntry *StopHigh = ((CHKVAL *) checkval)->arre;
- WordEntry *StopMiddle;
- int difference;
-
- /* Loop invariant: StopLow <= val < StopHigh */
-
- while (StopLow < StopHigh)
- {
- StopMiddle = StopLow + (StopHigh - StopLow) / 2;
- difference = ValCompare((CHKVAL *) checkval, StopMiddle, val);
- if (difference == 0)
- return (val->weight && StopMiddle->haspos) ?
- checkclass_str((CHKVAL *) checkval, StopMiddle, val) : true;
- else if (difference < 0)
- StopLow = StopMiddle + 1;
- else
- StopHigh = StopMiddle;
- }
-
- return (false);
-}
-
-/*
- * check for boolean condition
- */
-bool
-TS_execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM * val))
-{
- if (curitem->type == VAL)
- return (*chkcond) (checkval, curitem);
- else if (curitem->val == (int4) '!')
- {
- return (calcnot) ?
- ((TS_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
- : true;
- }
- else if (curitem->val == (int4) '&')
- {
- if (TS_execute(curitem + curitem->left, checkval, calcnot, chkcond))
- return TS_execute(curitem + 1, checkval, calcnot, chkcond);
- else
- return false;
- }
- else
- { /* |-operator */
- if (TS_execute(curitem + curitem->left, checkval, calcnot, chkcond))
- return true;
- else
- return TS_execute(curitem + 1, checkval, calcnot, chkcond);
- }
- return false;
-}
-
-/*
- * boolean operations
- */
-Datum
-rexectsq(PG_FUNCTION_ARGS)
-{
- SET_FUNCOID();
- return DirectFunctionCall2(
- exectsq,
- PG_GETARG_DATUM(1),
- PG_GETARG_DATUM(0)
- );
-}
-
-Datum
-exectsq(PG_FUNCTION_ARGS)
-{
- tsvector *val = (tsvector *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
- CHKVAL chkval;
- bool result;
-
- SET_FUNCOID();
- if (!val->size || !query->size)
- {
- PG_FREE_IF_COPY(val, 0);
- PG_FREE_IF_COPY(query, 1);
- PG_RETURN_BOOL(false);
- }
-
- chkval.arrb = ARRPTR(val);
- chkval.arre = chkval.arrb + val->size;
- chkval.values = STRPTR(val);
- chkval.operand = GETOPERAND(query);
- result = TS_execute(
- GETQUERY(query),
- &chkval,
- true,
- checkcondition_str
- );
-
- PG_FREE_IF_COPY(val, 0);
- PG_FREE_IF_COPY(query, 1);
- PG_RETURN_BOOL(result);
-}
-
-/*
- * find left operand in polish notation view
- */
-static void
-findoprnd(ITEM * ptr, int4 *pos)
-{
-#ifdef BS_DEBUG
- elog(DEBUG3, (ptr[*pos].type == OPR) ?
- "%d %c" : "%d %d", *pos, ptr[*pos].val);
-#endif
- if (ptr[*pos].type == VAL || ptr[*pos].type == VALSTOP)
- {
- ptr[*pos].left = 0;
- (*pos)++;
- }
- else if (ptr[*pos].val == (int4) '!')
- {
- ptr[*pos].left = 1;
- (*pos)++;
- findoprnd(ptr, pos);
- }
- else
- {
- ITEM *curitem = &ptr[*pos];
- int4 tmp = *pos;
-
- (*pos)++;
- findoprnd(ptr, pos);
- curitem->left = *pos - tmp;
- findoprnd(ptr, pos);
- }
-}
-
-
-/*
- * input
- */
-static QUERYTYPE *
- queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
-{
- QPRS_STATE state;
- int4 i;
- QUERYTYPE *query;
- int4 commonlen;
- ITEM *ptr;
- NODE *tmp;
- int4 pos = 0;
-
-#ifdef BS_DEBUG
- char pbuf[16384],
- *cur;
-#endif
-
- /* init state */
- state.buffer = buf;
- state.buf = buf;
- state.state = (isplain) ? WAITSINGLEOPERAND : WAITFIRSTOPERAND;
- state.count = 0;
- state.num = 0;
- state.str = NULL;
- state.cfg_id = cfg_id;
-
- /* init value parser's state */
- state.valstate.oprisdelim = true;
- state.valstate.len = 32;
- state.valstate.word = (char *) palloc(state.valstate.len);
-
- /* init list of operand */
- state.sumlen = 0;
- state.lenop = 64;
- state.curop = state.op = (char *) palloc(state.lenop);
- *(state.curop) = '\0';
-
- /* parse query & make polish notation (postfix, but in reverse order) */
- makepol(&state, pushval);
- pfree(state.valstate.word);
- if (!state.num)
- {
- ereport(NOTICE,
- (errmsg("tsearch query doesn't contain lexeme(s): \"%s\"",
- state.buffer)));
- query = (QUERYTYPE *) palloc(HDRSIZEQT);
- SET_VARSIZE(query, HDRSIZEQT);
- query->size = 0;
- return query;
- }
-
- /* make finish struct */
- commonlen = COMPUTESIZE(state.num, state.sumlen);
- query = (QUERYTYPE *) palloc(commonlen);
- SET_VARSIZE(query, commonlen);
- query->size = state.num;
- ptr = GETQUERY(query);
-
- /* set item in polish notation */
- for (i = 0; i < state.num; i++)
- {
- ptr[i].weight = state.str->weight;
- ptr[i].type = state.str->type;
- ptr[i].val = state.str->val;
- ptr[i].distance = state.str->distance;
- ptr[i].length = state.str->length;
- tmp = state.str->next;
- pfree(state.str);
- state.str = tmp;
- }
-
- /* set user friendly-operand view */
- memcpy((void *) GETOPERAND(query), (void *) state.op, state.sumlen);
- pfree(state.op);
-
- /* set left operand's position for every operator */
- pos = 0;
- findoprnd(ptr, &pos);
-
-#ifdef BS_DEBUG
- cur = pbuf;
- *cur = '\0';
- for (i = 0; i < query->size; i++)
- {
- if (ptr[i].type == OPR)
- sprintf(cur, "%c(%d) ", ptr[i].val, ptr[i].left);
- else
- sprintf(cur, "%d(%s) ", ptr[i].val, GETOPERAND(query) + ptr[i].distance);
- cur = strchr(cur, '\0');
- }
- elog(DEBUG3, "POR: %s", pbuf);
-#endif
-
- return query;
-}
-
-/*
- * in without morphology
- */
-Datum
-tsquery_in(PG_FUNCTION_ARGS)
-{
- char *in = (char *) PG_GETARG_POINTER(0);
-
- pg_verifymbstr(in, strlen(in), false);
-
- SET_FUNCOID();
- PG_RETURN_POINTER(queryin((char *) in, pushval_asis, 0, false));
-}
-
-/*
- * out function
- */
-typedef struct
-{
- ITEM *curpol;
- char *buf;
- char *cur;
- char *op;
- int4 buflen;
-} INFIX;
-
-#define RESIZEBUF(inf,addsize) \
-while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
-{ \
- int4 len = (inf)->cur - (inf)->buf; \
- (inf)->buflen *= 2; \
- (inf)->buf = (char*) repalloc( (void*)(inf)->buf, (inf)->buflen ); \
- (inf)->cur = (inf)->buf + len; \
-}
-
-/*
- * recursive walk on tree and print it in
- * infix (human-readable) view
- */
-static void
-infix(INFIX * in, bool first)
-{
- if (in->curpol->type == VAL)
- {
- char *op = in->op + in->curpol->distance;
- int clen;
-
- RESIZEBUF(in, in->curpol->length * (pg_database_encoding_max_length() + 1) + 2 + 5);
- *(in->cur) = '\'';
- in->cur++;
- while (*op)
- {
- if (t_iseq(op, '\''))
- {
- *(in->cur) = '\'';
- in->cur++;
- }
- COPYCHAR(in->cur, op);
-
- clen = pg_mblen(op);
- op += clen;
- in->cur += clen;
- }
- *(in->cur) = '\'';
- in->cur++;
- if (in->curpol->weight)
- {
- *(in->cur) = ':';
- in->cur++;
- if (in->curpol->weight & (1 << 3))
- {
- *(in->cur) = 'A';
- in->cur++;
- }
- if (in->curpol->weight & (1 << 2))
- {
- *(in->cur) = 'B';
- in->cur++;
- }
- if (in->curpol->weight & (1 << 1))
- {
- *(in->cur) = 'C';
- in->cur++;
- }
- if (in->curpol->weight & 1)
- {
- *(in->cur) = 'D';
- in->cur++;
- }
- }
- *(in->cur) = '\0';
- in->curpol++;
- }
- else if (in->curpol->val == (int4) '!')
- {
- bool isopr = false;
-
- RESIZEBUF(in, 1);
- *(in->cur) = '!';
- in->cur++;
- *(in->cur) = '\0';
- in->curpol++;
- if (in->curpol->type == OPR)
- {
- isopr = true;
- RESIZEBUF(in, 2);
- sprintf(in->cur, "( ");
- in->cur = strchr(in->cur, '\0');
- }
- infix(in, isopr);
- if (isopr)
- {
- RESIZEBUF(in, 2);
- sprintf(in->cur, " )");
- in->cur = strchr(in->cur, '\0');
- }
- }
- else
- {
- int4 op = in->curpol->val;
- INFIX nrm;
-
- in->curpol++;
- if (op == (int4) '|' && !first)
- {
- RESIZEBUF(in, 2);
- sprintf(in->cur, "( ");
- in->cur = strchr(in->cur, '\0');
- }
-
- nrm.curpol = in->curpol;
- nrm.op = in->op;
- nrm.buflen = 16;
- nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
-
- /* get right operand */
- infix(&nrm, false);
-
- /* get & print left operand */
- in->curpol = nrm.curpol;
- infix(in, false);
-
- /* print operator & right operand */
- RESIZEBUF(in, 3 + (nrm.cur - nrm.buf));
- sprintf(in->cur, " %c %s", op, nrm.buf);
- in->cur = strchr(in->cur, '\0');
- pfree(nrm.buf);
-
- if (op == (int4) '|' && !first)
- {
- RESIZEBUF(in, 2);
- sprintf(in->cur, " )");
- in->cur = strchr(in->cur, '\0');
- }
- }
-}
-
-
-Datum
-tsquery_out(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
- INFIX nrm;
-
- if (query->size == 0)
- {
- char *b = palloc(1);
-
- *b = '\0';
- PG_RETURN_POINTER(b);
- }
- nrm.curpol = GETQUERY(query);
- nrm.buflen = 32;
- nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
- *(nrm.cur) = '\0';
- nrm.op = GETOPERAND(query);
- infix(&nrm, true);
-
- PG_FREE_IF_COPY(query, 0);
- PG_RETURN_POINTER(nrm.buf);
-}
-
-/*
- * debug function, used only for view query
- * which will be executed in non-leaf pages in index
- */
-Datum
-tsquerytree(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
- INFIX nrm;
- text *res;
- ITEM *q;
- int4 len;
-
-
- if (query->size == 0)
- {
- res = (text *) palloc(VARHDRSZ);
- SET_VARSIZE(res, VARHDRSZ);
- PG_RETURN_POINTER(res);
- }
-
- q = clean_NOT_v2(GETQUERY(query), &len);
-
- if (!q)
- {
- res = (text *) palloc(1 + VARHDRSZ);
- SET_VARSIZE(res, 1 + VARHDRSZ);
- *((char *) VARDATA(res)) = 'T';
- }
- else
- {
- nrm.curpol = q;
- nrm.buflen = 32;
- nrm.cur = nrm.buf = (char *) palloc(sizeof(char) * nrm.buflen);
- *(nrm.cur) = '\0';
- nrm.op = GETOPERAND(query);
- infix(&nrm, true);
-
- res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ);
- SET_VARSIZE(res, nrm.cur - nrm.buf + VARHDRSZ);
- memcpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
- pfree(q);
- }
-
- PG_FREE_IF_COPY(query, 0);
-
- PG_RETURN_POINTER(res);
-}
-
-Datum
-to_tsquery(PG_FUNCTION_ARGS)
-{
- text *in = PG_GETARG_TEXT_P(1);
- char *str;
- QUERYTYPE *query;
- ITEM *res;
- int4 len;
-
- SET_FUNCOID();
-
- str = text2char(in);
- PG_FREE_IF_COPY(in, 1);
-
- query = queryin(str, pushval_morph, PG_GETARG_INT32(0), false);
-
- if (query->size == 0)
- PG_RETURN_POINTER(query);
-
- res = clean_fakeval_v2(GETQUERY(query), &len);
- if (!res)
- {
- SET_VARSIZE(query, HDRSIZEQT);
- query->size = 0;
- PG_RETURN_POINTER(query);
- }
- memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(ITEM));
- pfree(res);
- PG_RETURN_POINTER(query);
-}
-
-Datum
-to_tsquery_name(PG_FUNCTION_ARGS)
-{
- text *name = PG_GETARG_TEXT_P(0);
- Datum res;
-
- SET_FUNCOID();
- res = DirectFunctionCall2(to_tsquery,
- Int32GetDatum(name2id_cfg(name)),
- PG_GETARG_DATUM(1));
-
- PG_FREE_IF_COPY(name, 0);
- PG_RETURN_DATUM(res);
-}
-
-Datum
-to_tsquery_current(PG_FUNCTION_ARGS)
-{
- SET_FUNCOID();
- PG_RETURN_DATUM(DirectFunctionCall2(to_tsquery,
- Int32GetDatum(get_currcfg()),
- PG_GETARG_DATUM(0)));
-}
-
-Datum
-plainto_tsquery(PG_FUNCTION_ARGS)
-{
- text *in = PG_GETARG_TEXT_P(1);
- char *str;
- QUERYTYPE *query;
- ITEM *res;
- int4 len;
-
- SET_FUNCOID();
-
- str = text2char(in);
- PG_FREE_IF_COPY(in, 1);
-
- query = queryin(str, pushval_morph, PG_GETARG_INT32(0), true);
-
- if (query->size == 0)
- PG_RETURN_POINTER(query);
-
- res = clean_fakeval_v2(GETQUERY(query), &len);
- if (!res)
- {
- SET_VARSIZE(query, HDRSIZEQT);
- query->size = 0;
- PG_RETURN_POINTER(query);
- }
- memcpy((void *) GETQUERY(query), (void *) res, len * sizeof(ITEM));
- pfree(res);
- PG_RETURN_POINTER(query);
-}
-
-Datum
-plainto_tsquery_name(PG_FUNCTION_ARGS)
-{
- text *name = PG_GETARG_TEXT_P(0);
- Datum res;
-
- SET_FUNCOID();
- res = DirectFunctionCall2(plainto_tsquery,
- Int32GetDatum(name2id_cfg(name)),
- PG_GETARG_DATUM(1));
-
- PG_FREE_IF_COPY(name, 0);
- PG_RETURN_DATUM(res);
-}
-
-Datum
-plainto_tsquery_current(PG_FUNCTION_ARGS)
-{
- SET_FUNCOID();
- PG_RETURN_DATUM(DirectFunctionCall2(plainto_tsquery,
- Int32GetDatum(get_currcfg()),
- PG_GETARG_DATUM(0)));
-}
+++ /dev/null
-#ifndef __QUERY_H__
-#define __QUERY_H__
-/*
-#define BS_DEBUG
-*/
-
-#include "ts_locale.h"
-/*
- * item in polish notation with back link
- * to left operand
- */
-typedef struct ITEM
-{
- int8 type;
- int8 weight;
- int2 left;
- int4 val;
- /* user-friendly value, must correlate with WordEntry */
- uint32
- istrue:1, /* use for ranking in Cover */
- length:11,
- distance:20;
-} ITEM;
-
-/*
- *Storage:
- * (len)(size)(array of ITEM)(array of operand in user-friendly form)
- */
-typedef struct
-{
- int32 vl_len_; /* varlena header (do not touch directly!) */
- int4 size;
- char data[1];
-} QUERYTYPE;
-
-#define HDRSIZEQT ( VARHDRSZ + sizeof(int4) )
-#define COMPUTESIZE(size,lenofoperand) ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )
-#define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT )
-#define GETOPERAND(x) ( (char*)GETQUERY(x) + ((QUERYTYPE*)(x))->size * sizeof(ITEM) )
-
-#define ISOPERATOR(x) ( pg_mblen(x)==1 && ( *(x)=='!' || *(x)=='&' || *(x)=='|' || *(x)=='(' || *(x)==')' ) )
-
-#define END 0
-#define ERR 1
-#define VAL 2
-#define OPR 3
-#define OPEN 4
-#define CLOSE 5
-#define VALSTOP 6 /* for stop words */
-
-bool TS_execute(ITEM * curitem, void *checkval,
- bool calcnot, bool (*chkcond) (void *checkval, ITEM * val));
-
-#endif
+++ /dev/null
-/*
- * Rewrite routines of query tree
- * Teodor Sigaev
- */
-
-#include "postgres.h"
-
-#include
-
-#include "utils/builtins.h"
-
-#include "query.h"
-#include "query_cleanup.h"
-
-typedef struct NODE
-{
- struct NODE *left;
- struct NODE *right;
- ITEM *valnode;
-} NODE;
-
-/*
- * make query tree from plain view of query
- */
-static NODE *
-maketree(ITEM * in)
-{
- NODE *node = (NODE *) palloc(sizeof(NODE));
-
- node->valnode = in;
- node->right = node->left = NULL;
- if (in->type == OPR)
- {
- node->right = maketree(in + 1);
- if (in->val != (int4) '!')
- node->left = maketree(in + in->left);
- }
- return node;
-}
-
-typedef struct
-{
- ITEM *ptr;
- int4 len;
- int4 cur;
-} PLAINTREE;
-
-static void
-plainnode(PLAINTREE * state, NODE * node)
-{
- if (state->cur == state->len)
- {
- state->len *= 2;
- state->ptr = (ITEM *) repalloc((void *) state->ptr, state->len * sizeof(ITEM));
- }
- memcpy((void *) &(state->ptr[state->cur]), (void *) node->valnode, sizeof(ITEM));
- if (node->valnode->type == VAL)
- state->cur++;
- else if (node->valnode->val == (int4) '!')
- {
- state->ptr[state->cur].left = 1;
- state->cur++;
- plainnode(state, node->right);
- }
- else
- {
- int4 cur = state->cur;
-
- state->cur++;
- plainnode(state, node->right);
- state->ptr[cur].left = state->cur - cur;
- plainnode(state, node->left);
- }
- pfree(node);
-}
-
-/*
- * make plain view of tree from 'normal' view of tree
- */
-static ITEM *
-plaintree(NODE * root, int4 *len)
-{
- PLAINTREE pl;
-
- pl.cur = 0;
- pl.len = 16;
- if (root && (root->valnode->type == VAL || root->valnode->type == OPR))
- {
- pl.ptr = (ITEM *) palloc(pl.len * sizeof(ITEM));
- plainnode(&pl, root);
- }
- else
- pl.ptr = NULL;
- *len = pl.cur;
- return pl.ptr;
-}
-
-static void
-freetree(NODE * node)
-{
- if (!node)
- return;
- if (node->left)
- freetree(node->left);
- if (node->right)
- freetree(node->right);
- pfree(node);
-}
-
-/*
- * clean tree for ! operator.
- * It's usefull for debug, but in
- * other case, such view is used with search in index.
- * Operator ! always return TRUE
- */
-static NODE *
-clean_NOT_intree(NODE * node)
-{
- if (node->valnode->type == VAL)
- return node;
-
- if (node->valnode->val == (int4) '!')
- {
- freetree(node);
- return NULL;
- }
-
- /* operator & or | */
- if (node->valnode->val == (int4) '|')
- {
- if ((node->left = clean_NOT_intree(node->left)) == NULL ||
- (node->right = clean_NOT_intree(node->right)) == NULL)
- {
- freetree(node);
- return NULL;
- }
- }
- else
- {
- NODE *res = node;
-
- node->left = clean_NOT_intree(node->left);
- node->right = clean_NOT_intree(node->right);
- if (node->left == NULL && node->right == NULL)
- {
- pfree(node);
- res = NULL;
- }
- else if (node->left == NULL)
- {
- res = node->right;
- pfree(node);
- }
- else if (node->right == NULL)
- {
- res = node->left;
- pfree(node);
- }
- return res;
- }
- return node;
-}
-
-ITEM *
-clean_NOT_v2(ITEM * ptr, int4 *len)
-{
- NODE *root = maketree(ptr);
-
- return plaintree(clean_NOT_intree(root), len);
-}
-
-
-#ifdef V_UNKNOWN /* exists in Windows headers */
-#undef V_UNKNOWN
-#endif
-#ifdef V_FALSE /* exists in Solaris headers */
-#undef V_FALSE
-#endif
-
-#define V_UNKNOWN 0
-#define V_TRUE 1
-#define V_FALSE 2
-#define V_STOP 3
-
-/*
- * Clean query tree from values which is always in
- * text (stopword)
- */
-static NODE *
-clean_fakeval_intree(NODE * node, char *result)
-{
- char lresult = V_UNKNOWN,
- rresult = V_UNKNOWN;
-
- if (node->valnode->type == VAL)
- return node;
- else if (node->valnode->type == VALSTOP)
- {
- pfree(node);
- *result = V_STOP;
- return NULL;
- }
-
-
- if (node->valnode->val == (int4) '!')
- {
- node->right = clean_fakeval_intree(node->right, &rresult);
- if (!node->right)
- {
- *result = V_STOP;
- freetree(node);
- return NULL;
- }
- }
- else
- {
- NODE *res = node;
-
- node->left = clean_fakeval_intree(node->left, &lresult);
- node->right = clean_fakeval_intree(node->right, &rresult);
- if (lresult == V_STOP && rresult == V_STOP)
- {
- freetree(node);
- *result = V_STOP;
- return NULL;
- }
- else if (lresult == V_STOP)
- {
- res = node->right;
- pfree(node);
- }
- else if (rresult == V_STOP)
- {
- res = node->left;
- pfree(node);
- }
- return res;
- }
- return node;
-}
-
-ITEM *
-clean_fakeval_v2(ITEM * ptr, int4 *len)
-{
- NODE *root = maketree(ptr);
- char result = V_UNKNOWN;
- NODE *resroot;
-
- resroot = clean_fakeval_intree(root, &result);
- if (result != V_UNKNOWN)
- {
- elog(NOTICE, "query contains only stopword(s) or doesn't contain lexeme(s), ignored");
- *len = 0;
- return NULL;
- }
-
- return plaintree(resroot, len);
-}
+++ /dev/null
-#ifndef __REWRITE_H__
-#define __REWRITE_H__
-
-#include "query.h"
-
-ITEM *clean_NOT_v2(ITEM * ptr, int4 *len);
-ITEM *clean_fakeval_v2(ITEM * ptr, int4 *len);
-
-#endif
+++ /dev/null
-#include "postgres.h"
-
-#include "access/skey.h"
-#include "storage/bufpage.h"
-#include "access/gist.h"
-
-#include "query.h"
-
-typedef uint64 TPQTGist;
-
-#define SIGLEN (sizeof(TPQTGist)*BITS_PER_BYTE)
-
-
-#define GETENTRY(vec,pos) ((TPQTGist *) DatumGetPointer((vec)->vector[(pos)].key))
-
-PG_FUNCTION_INFO_V1(tsq_mcontains);
-Datum tsq_mcontains(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(tsq_mcontained);
-Datum tsq_mcontained(PG_FUNCTION_ARGS);
-
-static TPQTGist
-makesign(QUERYTYPE * a)
-{
- int i;
- ITEM *ptr = GETQUERY(a);
- TPQTGist sign = 0;
-
- for (i = 0; i < a->size; i++)
- {
- if (ptr->type == VAL)
- sign |= ((TPQTGist) 1) << (ptr->val % SIGLEN);
- ptr++;
- }
-
- return sign;
-}
-
-Datum
-tsq_mcontains(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(0)));
- QUERYTYPE *ex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
- TPQTGist sq,
- se;
- int i,
- j;
- ITEM *iq,
- *ie;
-
- if (query->size < ex->size)
- {
- PG_FREE_IF_COPY(query, 0);
- PG_FREE_IF_COPY(ex, 1);
-
- PG_RETURN_BOOL(false);
- }
-
- sq = makesign(query);
- se = makesign(ex);
-
- if ((sq & se) != se)
- {
- PG_FREE_IF_COPY(query, 0);
- PG_FREE_IF_COPY(ex, 1);
-
- PG_RETURN_BOOL(false);
- }
-
- ie = GETQUERY(ex);
-
- for (i = 0; i < ex->size; i++)
- {
- iq = GETQUERY(query);
- if (ie[i].type != VAL)
- continue;
- for (j = 0; j < query->size; j++)
- if (iq[j].type == VAL && ie[i].val == iq[j].val)
- {
- j = query->size + 1;
- break;
- }
- if (j == query->size)
- {
- PG_FREE_IF_COPY(query, 0);
- PG_FREE_IF_COPY(ex, 1);
-
- PG_RETURN_BOOL(false);
- }
- }
-
- PG_FREE_IF_COPY(query, 0);
- PG_FREE_IF_COPY(ex, 1);
-
- PG_RETURN_BOOL(true);
-}
-
-Datum
-tsq_mcontained(PG_FUNCTION_ARGS)
-{
- PG_RETURN_DATUM(
- DirectFunctionCall2(
- tsq_mcontains,
- PG_GETARG_DATUM(1),
- PG_GETARG_DATUM(0)
- )
- );
-}
-
-PG_FUNCTION_INFO_V1(gtsq_in);
-Datum gtsq_in(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_out);
-Datum gtsq_out(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_compress);
-Datum gtsq_compress(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_decompress);
-Datum gtsq_decompress(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_consistent);
-Datum gtsq_consistent(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_union);
-Datum gtsq_union(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_same);
-Datum gtsq_same(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_penalty);
-Datum gtsq_penalty(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(gtsq_picksplit);
-Datum gtsq_picksplit(PG_FUNCTION_ARGS);
-
-
-Datum
-gtsq_in(PG_FUNCTION_ARGS)
-{
- elog(ERROR, "not implemented");
- PG_RETURN_DATUM(0);
-}
-
-Datum
-gtsq_out(PG_FUNCTION_ARGS)
-{
- elog(ERROR, "not implemented");
- PG_RETURN_DATUM(0);
-}
-
-Datum
-gtsq_compress(PG_FUNCTION_ARGS)
-{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- GISTENTRY *retval = entry;
-
- if (entry->leafkey)
- {
- TPQTGist *sign = (TPQTGist *) palloc(sizeof(TPQTGist));
-
- retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
- *sign = makesign((QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)));
-
- gistentryinit(*retval, PointerGetDatum(sign),
- entry->rel, entry->page,
- entry->offset, FALSE);
- }
-
- PG_RETURN_POINTER(retval);
-}
-
-Datum
-gtsq_decompress(PG_FUNCTION_ARGS)
-{
- PG_RETURN_DATUM(PG_GETARG_DATUM(0));
-}
-
-Datum
-gtsq_consistent(PG_FUNCTION_ARGS)
-{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- TPQTGist *key = (TPQTGist *) DatumGetPointer(entry->key);
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- TPQTGist sq = makesign(query);
- bool retval;
-
- switch (strategy)
- {
- case RTContainsStrategyNumber:
- case RTOldContainsStrategyNumber:
- if (GIST_LEAF(entry))
- retval = (*key & sq) == sq;
- else
- retval = (*key & sq) != 0;
- break;
- case RTContainedByStrategyNumber:
- case RTOldContainedByStrategyNumber:
- if (GIST_LEAF(entry))
- retval = (*key & sq) == *key;
- else
- retval = (*key & sq) != 0;
- break;
- default:
- retval = FALSE;
- }
- PG_RETURN_BOOL(retval);
-}
-
-Datum
-gtsq_union(PG_FUNCTION_ARGS)
-{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- TPQTGist *sign = (TPQTGist *) palloc(sizeof(TPQTGist));
- int i;
- int *size = (int *) PG_GETARG_POINTER(1);
-
- memset(sign, 0, sizeof(TPQTGist));
-
- for (i = 0; i < entryvec->n; i++)
- *sign |= *GETENTRY(entryvec, i);
-
- *size = sizeof(TPQTGist);
-
- PG_RETURN_POINTER(sign);
-}
-
-Datum
-gtsq_same(PG_FUNCTION_ARGS)
-{
- TPQTGist *a = (TPQTGist *) PG_GETARG_POINTER(0);
- TPQTGist *b = (TPQTGist *) PG_GETARG_POINTER(1);
-
- PG_RETURN_POINTER(*a == *b);
-}
-
-static int
-sizebitvec(TPQTGist sign)
-{
- int size = 0,
- i;
-
- for (i = 0; i < SIGLEN; i++)
- size += 0x01 & (sign >> i);
-
- return size;
-}
-
-static int
-hemdist(TPQTGist a, TPQTGist b)
-{
- TPQTGist res = a ^ b;
-
- return sizebitvec(res);
-}
-
-Datum
-gtsq_penalty(PG_FUNCTION_ARGS)
-{
- TPQTGist *origval = (TPQTGist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
- TPQTGist *newval = (TPQTGist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
- float *penalty = (float *) PG_GETARG_POINTER(2);
-
- *penalty = hemdist(*origval, *newval);
-
- PG_RETURN_POINTER(penalty);
-}
-
-
-typedef struct
-{
- OffsetNumber pos;
- int4 cost;
-} SPLITCOST;
-
-static int
-comparecost(const void *a, const void *b)
-{
- if (((SPLITCOST *) a)->cost == ((SPLITCOST *) b)->cost)
- return 0;
- else
- return (((SPLITCOST *) a)->cost > ((SPLITCOST *) b)->cost) ? 1 : -1;
-}
-
-#define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
-
-Datum
-gtsq_picksplit(PG_FUNCTION_ARGS)
-{
- GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
- GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
- OffsetNumber maxoff = entryvec->n - 2;
- OffsetNumber k,
- j;
-
- TPQTGist *datum_l,
- *datum_r;
- int4 size_alpha,
- size_beta;
- int4 size_waste,
- waste = -1;
- int4 nbytes;
- OffsetNumber seed_1 = 0,
- seed_2 = 0;
- OffsetNumber *left,
- *right;
-
- SPLITCOST *costvector;
-
- nbytes = (maxoff + 2) * sizeof(OffsetNumber);
- left = v->spl_left = (OffsetNumber *) palloc(nbytes);
- right = v->spl_right = (OffsetNumber *) palloc(nbytes);
- v->spl_nleft = v->spl_nright = 0;
-
- for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
- for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
- {
- size_waste = hemdist(*GETENTRY(entryvec, j), *GETENTRY(entryvec, k));
- if (size_waste > waste)
- {
- waste = size_waste;
- seed_1 = k;
- seed_2 = j;
- }
- }
-
-
- if (seed_1 == 0 || seed_2 == 0)
- {
- seed_1 = 1;
- seed_2 = 2;
- }
-
- datum_l = (TPQTGist *) palloc(sizeof(TPQTGist));
- *datum_l = *GETENTRY(entryvec, seed_1);
- datum_r = (TPQTGist *) palloc(sizeof(TPQTGist));
- *datum_r = *GETENTRY(entryvec, seed_2);
-
-
- maxoff = OffsetNumberNext(maxoff);
- costvector = (SPLITCOST *) palloc(sizeof(SPLITCOST) * maxoff);
- for (j = FirstOffsetNumber; j <= maxoff; j = OffsetNumberNext(j))
- {
- costvector[j - 1].pos = j;
- size_alpha = hemdist(*GETENTRY(entryvec, seed_1), *GETENTRY(entryvec, j));
- size_beta = hemdist(*GETENTRY(entryvec, seed_2), *GETENTRY(entryvec, j));
- costvector[j - 1].cost = abs(size_alpha - size_beta);
- }
- qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
-
- for (k = 0; k < maxoff; k++)
- {
- j = costvector[k].pos;
- if (j == seed_1)
- {
- *left++ = j;
- v->spl_nleft++;
- continue;
- }
- else if (j == seed_2)
- {
- *right++ = j;
- v->spl_nright++;
- continue;
- }
- size_alpha = hemdist(*datum_l, *GETENTRY(entryvec, j));
- size_beta = hemdist(*datum_r, *GETENTRY(entryvec, j));
-
- if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.05))
- {
- *datum_l |= *GETENTRY(entryvec, j);
- *left++ = j;
- v->spl_nleft++;
- }
- else
- {
- *datum_r |= *GETENTRY(entryvec, j);
- *right++ = j;
- v->spl_nright++;
- }
- }
-
- *right = *left = FirstOffsetNumber;
- v->spl_ldatum = PointerGetDatum(datum_l);
- v->spl_rdatum = PointerGetDatum(datum_r);
-
- PG_RETURN_POINTER(v);
-}
+++ /dev/null
-#include "postgres.h"
-#include "executor/spi.h"
-
-#include "query_util.h"
-
-MemoryContext AggregateContext = NULL;
-
-static int
-addone(int *counters, int last, int total)
-{
- counters[last]++;
- if (counters[last] >= total)
- {
- if (last == 0)
- return 0;
- if (addone(counters, last - 1, total - 1) == 0)
- return 0;
- counters[last] = counters[last - 1] + 1;
- }
- return 1;
-}
-
-static QTNode *
-findeq(QTNode * node, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind)
-{
-
- if ((node->sign & ex->sign) != ex->sign || node->valnode->type != ex->valnode->type || node->valnode->val != ex->valnode->val)
- return node;
-
- if (node->flags & QTN_NOCHANGE)
- return node;
-
- if (node->valnode->type == OPR)
- {
- if (node->nchild == ex->nchild)
- {
- if (QTNEq(node, ex))
- {
- QTNFree(node);
- if (subs)
- {
- node = QTNCopy(subs, memtype);
- node->flags |= QTN_NOCHANGE;
- }
- else
- node = NULL;
- *isfind = true;
- }
- }
- else if (node->nchild > ex->nchild)
- {
- int *counters = (int *) palloc(sizeof(int) * node->nchild);
- int i;
- QTNode *tnode = (QTNode *) MEMALLOC(memtype, sizeof(QTNode));
-
- memset(tnode, 0, sizeof(QTNode));
- tnode->child = (QTNode **) MEMALLOC(memtype, sizeof(QTNode *) * ex->nchild);
- tnode->nchild = ex->nchild;
- tnode->valnode = (ITEM *) MEMALLOC(memtype, sizeof(ITEM));
- *(tnode->valnode) = *(ex->valnode);
-
- for (i = 0; i < ex->nchild; i++)
- counters[i] = i;
-
- do
- {
- tnode->sign = 0;
- for (i = 0; i < ex->nchild; i++)
- {
- tnode->child[i] = node->child[counters[i]];
- tnode->sign |= tnode->child[i]->sign;
- }
-
- if (QTNEq(tnode, ex))
- {
- int j = 0;
-
- MEMFREE(memtype, tnode->valnode);
- MEMFREE(memtype, tnode->child);
- MEMFREE(memtype, tnode);
- if (subs)
- {
- tnode = QTNCopy(subs, memtype);
- tnode->flags = QTN_NOCHANGE | QTN_NEEDFREE;
- }
- else
- tnode = NULL;
-
- node->child[counters[0]] = tnode;
-
- for (i = 1; i < ex->nchild; i++)
- node->child[counters[i]] = NULL;
- for (i = 0; i < node->nchild; i++)
- {
- if (node->child[i])
- {
- node->child[j] = node->child[i];
- j++;
- }
- }
-
- node->nchild = j;
-
- *isfind = true;
-
- break;
- }
- } while (addone(counters, ex->nchild - 1, node->nchild));
- if (tnode && (tnode->flags & QTN_NOCHANGE) == 0)
- {
- MEMFREE(memtype, tnode->valnode);
- MEMFREE(memtype, tnode->child);
- MEMFREE(memtype, tnode);
- }
- else
- QTNSort(node);
- pfree(counters);
- }
- }
- else if (QTNEq(node, ex))
- {
- QTNFree(node);
- if (subs)
- {
- node = QTNCopy(subs, memtype);
- node->flags |= QTN_NOCHANGE;
- }
- else
- {
- node = NULL;
- }
- *isfind = true;
- }
-
- return node;
-}
-
-static QTNode *
-dofindsubquery(QTNode * root, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind)
-{
- root = findeq(root, ex, memtype, subs, isfind);
-
- if (root && (root->flags & QTN_NOCHANGE) == 0 && root->valnode->type == OPR)
- {
- int i;
-
- for (i = 0; i < root->nchild; i++)
- root->child[i] = dofindsubquery(root->child[i], ex, memtype, subs, isfind);
- }
-
- return root;
-}
-
-static QTNode *
-dropvoidsubtree(QTNode * root)
-{
-
- if (!root)
- return NULL;
-
- if (root->valnode->type == OPR)
- {
- int i,
- j = 0;
-
- for (i = 0; i < root->nchild; i++)
- {
- if (root->child[i])
- {
- root->child[j] = root->child[i];
- j++;
- }
- }
-
- root->nchild = j;
-
- if (root->valnode->val == (int4) '!' && root->nchild == 0)
- {
- QTNFree(root);
- root = NULL;
- }
- else if (root->nchild == 1)
- {
- QTNode *nroot = root->child[0];
-
- pfree(root);
- root = nroot;
- }
- }
-
- return root;
-}
-
-static QTNode *
-findsubquery(QTNode * root, QTNode * ex, MemoryType memtype, QTNode * subs, bool *isfind)
-{
- bool DidFind = false;
-
- root = dofindsubquery(root, ex, memtype, subs, &DidFind);
-
- if (!subs && DidFind)
- root = dropvoidsubtree(root);
-
- if (isfind)
- *isfind = DidFind;
-
- return root;
-}
-
-static Oid tsqOid = InvalidOid;
-static void
-get_tsq_Oid(void)
-{
- int ret;
- bool isnull;
-
- if ((ret = SPI_exec("select oid from pg_type where typname='tsquery'", 1)) < 0)
- /* internal error */
- elog(ERROR, "SPI_exec to get tsquery oid returns %d", ret);
-
- if (SPI_processed < 1)
- /* internal error */
- elog(ERROR, "there is no tsvector type");
- tsqOid = DatumGetObjectId(SPI_getbinval(SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1, &isnull));
- if (tsqOid == InvalidOid)
- /* internal error */
- elog(ERROR, "tsquery type has InvalidOid");
-}
-
-
-PG_FUNCTION_INFO_V1(tsquery_rewrite);
-PG_FUNCTION_INFO_V1(rewrite_accum);
-Datum rewrite_accum(PG_FUNCTION_ARGS);
-
-Datum
-rewrite_accum(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0);
- ArrayType *qa = (ArrayType *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1)));
- QUERYTYPE *q;
- QTNode *qex,
- *subs = NULL,
- *acctree;
- bool isfind = false;
- Datum *elemsp;
- int nelemsp;
-
- AggregateContext = ((AggState *) fcinfo->context)->aggcontext;
-
- if (acc == NULL || PG_ARGISNULL(0))
- {
- acc = (QUERYTYPE *) MEMALLOC(AggMemory, sizeof(QUERYTYPE));
- SET_VARSIZE(acc, HDRSIZEQT);
- acc->size = 0;
- }
-
- if (qa == NULL || PG_ARGISNULL(1))
- {
- PG_FREE_IF_COPY(qa, 1);
- PG_RETURN_POINTER(acc);
- }
-
- if (ARR_NDIM(qa) != 1)
- elog(ERROR, "array must be one-dimensional, not %d dimension", ARR_NDIM(qa));
-
- if (ArrayGetNItems(ARR_NDIM(qa), ARR_DIMS(qa)) != 3)
- elog(ERROR, "array should have only three elements");
-
- if (tsqOid == InvalidOid)
- {
- SPI_connect();
- get_tsq_Oid();
- SPI_finish();
- }
-
- if (ARR_ELEMTYPE(qa) != tsqOid)
- elog(ERROR, "array should contain tsquery type");
-
- deconstruct_array(qa, tsqOid, -1, false, 'i', &elemsp, NULL, &nelemsp);
-
- q = (QUERYTYPE *) DatumGetPointer(elemsp[0]);
- if (q->size == 0)
- {
- pfree(elemsp);
- PG_RETURN_POINTER(acc);
- }
-
- if (!acc->size)
- {
- if (VARSIZE(acc) > HDRSIZEQT)
- {
- pfree(elemsp);
- PG_RETURN_POINTER(acc);
- }
- else
- acctree = QT2QTN(GETQUERY(q), GETOPERAND(q));
- }
- else
- acctree = QT2QTN(GETQUERY(acc), GETOPERAND(acc));
-
- QTNTernary(acctree);
- QTNSort(acctree);
-
- q = (QUERYTYPE *) DatumGetPointer(elemsp[1]);
- if (q->size == 0)
- {
- pfree(elemsp);
- PG_RETURN_POINTER(acc);
- }
- qex = QT2QTN(GETQUERY(q), GETOPERAND(q));
- QTNTernary(qex);
- QTNSort(qex);
-
- q = (QUERYTYPE *) DatumGetPointer(elemsp[2]);
- if (q->size)
- subs = QT2QTN(GETQUERY(q), GETOPERAND(q));
-
- acctree = findsubquery(acctree, qex, PlainMemory, subs, &isfind);
-
- if (isfind || !acc->size)
- {
- /* pfree( acc ); do not pfree(p), because nodeAgg.c will */
- if (acctree)
- {
- QTNBinary(acctree);
- acc = QTN2QT(acctree, AggMemory);
- }
- else
- {
- acc = (QUERYTYPE *) MEMALLOC(AggMemory, HDRSIZEQT * 2);
- SET_VARSIZE(acc, HDRSIZEQT * 2);
- acc->size = 0;
- }
- }
-
- pfree(elemsp);
- QTNFree(qex);
- QTNFree(subs);
- QTNFree(acctree);
-
- PG_RETURN_POINTER(acc);
-}
-
-PG_FUNCTION_INFO_V1(rewrite_finish);
-Datum rewrite_finish(PG_FUNCTION_ARGS);
-
-Datum
-rewrite_finish(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *acc = (QUERYTYPE *) PG_GETARG_POINTER(0);
- QUERYTYPE *rewrited;
-
- if (acc == NULL || PG_ARGISNULL(0) || acc->size == 0)
- {
- acc = (QUERYTYPE *) palloc(sizeof(QUERYTYPE));
- SET_VARSIZE(acc, HDRSIZEQT);
- acc->size = 0;
- }
-
- rewrited = (QUERYTYPE *) palloc(VARSIZE(acc));
- memcpy(rewrited, acc, VARSIZE(acc));
- pfree(acc);
-
- PG_RETURN_POINTER(rewrited);
-}
-
-Datum tsquery_rewrite(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_rewrite(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- text *in = PG_GETARG_TEXT_P(1);
- QUERYTYPE *rewrited = query;
- QTNode *tree;
- char *buf;
- void *plan;
- Portal portal;
- bool isnull;
- int i;
-
- if (query->size == 0)
- {
- PG_FREE_IF_COPY(in, 1);
- PG_RETURN_POINTER(rewrited);
- }
-
- tree = QT2QTN(GETQUERY(query), GETOPERAND(query));
- QTNTernary(tree);
- QTNSort(tree);
-
- buf = (char *) palloc(VARSIZE(in));
- memcpy(buf, VARDATA(in), VARSIZE(in) - VARHDRSZ);
- buf[VARSIZE(in) - VARHDRSZ] = '\0';
-
- SPI_connect();
-
- if (tsqOid == InvalidOid)
- get_tsq_Oid();
-
- if ((plan = SPI_prepare(buf, 0, NULL)) == NULL)
- elog(ERROR, "SPI_prepare('%s') returns NULL", buf);
-
- if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, false)) == NULL)
- elog(ERROR, "SPI_cursor_open('%s') returns NULL", buf);
-
- SPI_cursor_fetch(portal, true, 100);
-
- if (SPI_tuptable->tupdesc->natts != 2)
- elog(ERROR, "number of fields doesn't equal to 2");
-
- if (SPI_gettypeid(SPI_tuptable->tupdesc, 1) != tsqOid)
- elog(ERROR, "column #1 isn't of tsquery type");
-
- if (SPI_gettypeid(SPI_tuptable->tupdesc, 2) != tsqOid)
- elog(ERROR, "column #2 isn't of tsquery type");
-
- while (SPI_processed > 0 && tree)
- {
- for (i = 0; i < SPI_processed && tree; i++)
- {
- Datum qdata = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 1, &isnull);
- Datum sdata;
-
- if (isnull)
- continue;
-
- sdata = SPI_getbinval(SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 2, &isnull);
-
- if (!isnull)
- {
- QUERYTYPE *qtex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(qdata));
- QUERYTYPE *qtsubs = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(sdata));
- QTNode *qex,
- *qsubs = NULL;
-
- if (qtex->size == 0)
- {
- if (qtex != (QUERYTYPE *) DatumGetPointer(qdata))
- pfree(qtex);
- if (qtsubs != (QUERYTYPE *) DatumGetPointer(sdata))
- pfree(qtsubs);
- continue;
- }
-
- qex = QT2QTN(GETQUERY(qtex), GETOPERAND(qtex));
-
- QTNTernary(qex);
- QTNSort(qex);
-
- if (qtsubs->size)
- qsubs = QT2QTN(GETQUERY(qtsubs), GETOPERAND(qtsubs));
-
- tree = findsubquery(tree, qex, SPIMemory, qsubs, NULL);
-
- QTNFree(qex);
- if (qtex != (QUERYTYPE *) DatumGetPointer(qdata))
- pfree(qtex);
- QTNFree(qsubs);
- if (qtsubs != (QUERYTYPE *) DatumGetPointer(sdata))
- pfree(qtsubs);
- }
- }
-
- SPI_freetuptable(SPI_tuptable);
- SPI_cursor_fetch(portal, true, 100);
- }
-
- SPI_freetuptable(SPI_tuptable);
- SPI_cursor_close(portal);
- SPI_freeplan(plan);
- SPI_finish();
-
-
- if (tree)
- {
- QTNBinary(tree);
- rewrited = QTN2QT(tree, PlainMemory);
- QTNFree(tree);
- PG_FREE_IF_COPY(query, 0);
- }
- else
- {
- SET_VARSIZE(rewrited, HDRSIZEQT);
- rewrited->size = 0;
- }
-
- pfree(buf);
- PG_FREE_IF_COPY(in, 1);
- PG_RETURN_POINTER(rewrited);
-}
-
-
-PG_FUNCTION_INFO_V1(tsquery_rewrite_query);
-Datum tsquery_rewrite_query(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_rewrite_query(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- QUERYTYPE *ex = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
- QUERYTYPE *subst = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(2)));
- QUERYTYPE *rewrited = query;
- QTNode *tree,
- *qex,
- *subs = NULL;
-
- if (query->size == 0 || ex->size == 0)
- {
- PG_FREE_IF_COPY(ex, 1);
- PG_FREE_IF_COPY(subst, 2);
- PG_RETURN_POINTER(rewrited);
- }
-
- tree = QT2QTN(GETQUERY(query), GETOPERAND(query));
- QTNTernary(tree);
- QTNSort(tree);
-
- qex = QT2QTN(GETQUERY(ex), GETOPERAND(ex));
- QTNTernary(qex);
- QTNSort(qex);
-
- if (subst->size)
- subs = QT2QTN(GETQUERY(subst), GETOPERAND(subst));
-
- tree = findsubquery(tree, qex, PlainMemory, subs, NULL);
- QTNFree(qex);
- QTNFree(subs);
-
- if (!tree)
- {
- SET_VARSIZE(rewrited, HDRSIZEQT);
- rewrited->size = 0;
- PG_FREE_IF_COPY(ex, 1);
- PG_FREE_IF_COPY(subst, 2);
- PG_RETURN_POINTER(rewrited);
- }
- else
- {
- QTNBinary(tree);
- rewrited = QTN2QT(tree, PlainMemory);
- QTNFree(tree);
- }
-
- PG_FREE_IF_COPY(query, 0);
- PG_FREE_IF_COPY(ex, 1);
- PG_FREE_IF_COPY(subst, 2);
- PG_RETURN_POINTER(rewrited);
-}
+++ /dev/null
-#include "postgres.h"
-#include "fmgr.h"
-
-#include "query_util.h"
-
-PG_FUNCTION_INFO_V1(tsquery_numnode);
-Datum tsquery_numnode(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_numnode(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *query = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- int nnode = query->size;
-
- PG_FREE_IF_COPY(query, 0);
- PG_RETURN_INT32(nnode);
-}
-
-static QTNode *
-join_tsqueries(QUERYTYPE * a, QUERYTYPE * b)
-{
- QTNode *res = (QTNode *) palloc0(sizeof(QTNode));
-
- res->flags |= QTN_NEEDFREE;
-
- res->valnode = (ITEM *) palloc0(sizeof(ITEM));
- res->valnode->type = OPR;
-
- res->child = (QTNode **) palloc0(sizeof(QTNode *) * 2);
- res->child[0] = QT2QTN(GETQUERY(b), GETOPERAND(b));
- res->child[1] = QT2QTN(GETQUERY(a), GETOPERAND(a));
- res->nchild = 2;
-
- return res;
-}
-
-PG_FUNCTION_INFO_V1(tsquery_and);
-Datum tsquery_and(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_and(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1)));
- QTNode *res;
- QUERYTYPE *query;
-
- if (a->size == 0)
- {
- PG_FREE_IF_COPY(a, 1);
- PG_RETURN_POINTER(b);
- }
- else if (b->size == 0)
- {
- PG_FREE_IF_COPY(b, 1);
- PG_RETURN_POINTER(a);
- }
-
- res = join_tsqueries(a, b);
-
- res->valnode->val = '&';
-
- query = QTN2QT(res, PlainMemory);
-
- QTNFree(res);
- PG_FREE_IF_COPY(a, 0);
- PG_FREE_IF_COPY(b, 1);
-
- PG_RETURN_POINTER(query);
-}
-
-PG_FUNCTION_INFO_V1(tsquery_or);
-Datum tsquery_or(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_or(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1)));
- QTNode *res;
- QUERYTYPE *query;
-
- if (a->size == 0)
- {
- PG_FREE_IF_COPY(a, 1);
- PG_RETURN_POINTER(b);
- }
- else if (b->size == 0)
- {
- PG_FREE_IF_COPY(b, 1);
- PG_RETURN_POINTER(a);
- }
-
- res = join_tsqueries(a, b);
-
- res->valnode->val = '|';
-
- query = QTN2QT(res, PlainMemory);
-
- QTNFree(res);
- PG_FREE_IF_COPY(a, 0);
- PG_FREE_IF_COPY(b, 1);
-
- PG_RETURN_POINTER(query);
-}
-
-PG_FUNCTION_INFO_V1(tsquery_not);
-Datum tsquery_not(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_not(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- QTNode *res;
- QUERYTYPE *query;
-
- if (a->size == 0)
- PG_RETURN_POINTER(a);
-
- res = (QTNode *) palloc0(sizeof(QTNode));
-
- res->flags |= QTN_NEEDFREE;
-
- res->valnode = (ITEM *) palloc0(sizeof(ITEM));
- res->valnode->type = OPR;
- res->valnode->val = '!';
-
- res->child = (QTNode **) palloc0(sizeof(QTNode *));
- res->child[0] = QT2QTN(GETQUERY(a), GETOPERAND(a));
- res->nchild = 1;
-
- query = QTN2QT(res, PlainMemory);
-
- QTNFree(res);
- PG_FREE_IF_COPY(a, 0);
-
- PG_RETURN_POINTER(query);
-}
-
-static int
-CompareTSQ(QUERYTYPE * a, QUERYTYPE * b)
-{
- if (a->size != b->size)
- {
- return (a->size < b->size) ? -1 : 1;
- }
- else if (VARSIZE(a) != VARSIZE(b))
- {
- return (VARSIZE(a) < VARSIZE(b)) ? -1 : 1;
- }
- else
- {
- QTNode *an = QT2QTN(GETQUERY(a), GETOPERAND(a));
- QTNode *bn = QT2QTN(GETQUERY(b), GETOPERAND(b));
- int res = QTNodeCompare(an, bn);
-
- QTNFree(an);
- QTNFree(bn);
-
- return res;
- }
-
- return 0;
-}
-
-PG_FUNCTION_INFO_V1(tsquery_cmp);
-\
-Datum tsquery_cmp(PG_FUNCTION_ARGS);
-
-Datum
-tsquery_cmp(PG_FUNCTION_ARGS)
-{
- QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0)));
- QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1)));
- int res = CompareTSQ(a, b);
-
- PG_FREE_IF_COPY(a, 0);
- PG_FREE_IF_COPY(b, 1);
-
- PG_RETURN_INT32(res);
-}
-
-#define CMPFUNC( NAME, ACTION ) \
-Datum NAME(PG_FUNCTION_ARGS); \
- \
-Datum \
-NAME(PG_FUNCTION_ARGS) { \
- QUERYTYPE *a = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(0))); \
- QUERYTYPE *b = (QUERYTYPE *) DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1))); \
- int res = CompareTSQ(a,b); \
- \
- PG_FREE_IF_COPY(a,0); \
- PG_FREE_IF_COPY(b,1); \
- \
- PG_RETURN_BOOL( ACTION ); \
-} \
- \
-PG_FUNCTION_INFO_V1(NAME)
-
-CMPFUNC(tsquery_lt, res < 0);
-CMPFUNC(tsquery_le, res <= 0);
-CMPFUNC(tsquery_eq, res == 0);
-CMPFUNC(tsquery_ge, res >= 0);
-CMPFUNC(tsquery_gt, res > 0);
-CMPFUNC(tsquery_ne, res != 0);
+++ /dev/null
-#include "postgres.h"
-#include "executor/spi.h"
-#include "query_util.h"
-
-QTNode *
-QT2QTN(ITEM * in, char *operand)
-{
- QTNode *node = (QTNode *) palloc0(sizeof(QTNode));
-
- node->valnode = in;
-
- if (in->type == OPR)
- {
- node->child = (QTNode **) palloc0(sizeof(QTNode *) * 2);
- node->child[0] = QT2QTN(in + 1, operand);
- node->sign = node->child[0]->sign;
- if (in->val == (int4) '!')
- node->nchild = 1;
- else
- {
- node->nchild = 2;
- node->child[1] = QT2QTN(in + in->left, operand);
- node->sign |= node->child[1]->sign;
- }
- }
- else if (operand)
- {
- node->word = operand + in->distance;
- node->sign = 1 << (in->val % 32);
- }
-
- return node;
-}
-
-void
-QTNFree(QTNode * in)
-{
- if (!in)
- return;
-
- if (in->valnode->type == VAL && in->word && (in->flags & QTN_WORDFREE) != 0)
- pfree(in->word);
-
- if (in->child)
- {
- if (in->valnode)
- {
- if (in->valnode->type == OPR && in->nchild > 0)
- {
- int i;
-
- for (i = 0; i < in->nchild; i++)
- QTNFree(in->child[i]);
- }
- if (in->flags & QTN_NEEDFREE)
- pfree(in->valnode);
- }
- pfree(in->child);
- }
-
- pfree(in);
-}
-
-int
-QTNodeCompare(QTNode * an, QTNode * bn)
-{
- if (an->valnode->type != bn->valnode->type)
- return (an->valnode->type > bn->valnode->type) ? -1 : 1;
- else if (an->valnode->val != bn->valnode->val)
- return (an->valnode->val > bn->valnode->val) ? -1 : 1;
- else if (an->valnode->type == VAL)
- {
- if (an->valnode->length == bn->valnode->length)
- return strncmp(an->word, bn->word, an->valnode->length);
- else
- return (an->valnode->length > bn->valnode->length) ? -1 : 1;
- }
- else if (an->nchild != bn->nchild)
- {
- return (an->nchild > bn->nchild) ? -1 : 1;
- }
- else
- {
- int i,
- res;
-
- for (i = 0; i < an->nchild; i++)
- if ((res = QTNodeCompare(an->child[i], bn->child[i])) != 0)
- return res;
- }
-
- return 0;
-}
-
-static int
-cmpQTN(const void *a, const void *b)
-{
- return QTNodeCompare(*(QTNode **) a, *(QTNode **) b);
-}
-
-void
-QTNSort(QTNode * in)
-{
- int i;
-
- if (in->valnode->type != OPR)
- return;
-
- for (i = 0; i < in->nchild; i++)
- QTNSort(in->child[i]);
- if (in->nchild > 1)
- qsort((void *) in->child, in->nchild, sizeof(QTNode *), cmpQTN);
-}
-
-bool
-QTNEq(QTNode * a, QTNode * b)
-{
- uint32 sign = a->sign & b->sign;
-
- if (!(sign == a->sign && sign == b->sign))
- return 0;
-
- return (QTNodeCompare(a, b) == 0) ? true : false;
-}
-
-void
-QTNTernary(QTNode * in)
-{
- int i;
-
- if (in->valnode->type != OPR)
- return;
-
- for (i = 0; i < in->nchild; i++)
- QTNTernary(in->child[i]);
-
- for (i = 0; i < in->nchild; i++)
- {
- if (in->valnode->type == in->child[i]->valnode->type && in->valnode->val == in->child[i]->valnode->val)
- {
- QTNode *cc = in->child[i];
- int oldnchild = in->nchild;
-
- in->nchild += cc->nchild - 1;
- in->child = (QTNode **) repalloc(in->child, in->nchild * sizeof(QTNode *));
-
- if (i + 1 != oldnchild)
- memmove(in->child + i + cc->nchild, in->child + i + 1,
- (oldnchild - i - 1) * sizeof(QTNode *));
-
- memcpy(in->child + i, cc->child, cc->nchild * sizeof(QTNode *));
- i += cc->nchild - 1;
-
- pfree(cc);
- }
- }
-}
-
-void
-QTNBinary(QTNode * in)
-{
- int i;
-
- if (in->valnode->type != OPR)
- return;
-
- for (i = 0; i < in->nchild; i++)
- QTNBinary(in->child[i]);
-
- if (in->nchild <= 2)
- return;
-
- while (in->nchild > 2)
- {
- QTNode *nn = (QTNode *) palloc0(sizeof(QTNode));
-
- nn->valnode = (ITEM *) palloc0(sizeof(ITEM));
- nn->child = (QTNode **) palloc0(sizeof(QTNode *) * 2);
-
- nn->nchild = 2;
- nn->flags = QTN_NEEDFREE;
-
- nn->child[0] = in->child[0];
- nn->child[1] = in->child[1];
- nn->sign = nn->child[0]->sign | nn->child[1]->sign;
-
- nn->valnode->type = in->valnode->type;
- nn->valnode->val = in->valnode->val;
-
- in->child[0] = nn;
- in->child[1] = in->child[in->nchild - 1];
- in->nchild--;
- }
-}
-
-static void
-cntsize(QTNode * in, int4 *sumlen, int4 *nnode)
-{
- *nnode += 1;
- if (in->valnode->type == OPR)
- {
- int i;
-
- for (i = 0; i < in->nchild; i++)
- cntsize(in->child[i], sumlen, nnode);
- }
- else
- {
- *sumlen += in->valnode->length + 1;
- }
-}
-
-typedef struct
-{
- ITEM *curitem;
- char *operand;
- char *curoperand;
-} QTN2QTState;
-
-static void
-fillQT(QTN2QTState * state, QTNode * in)
-{
- *(state->curitem) = *(in->valnode);
-
- if (in->valnode->type == VAL)
- {
- memcpy(state->curoperand, in->word, in->valnode->length);
- state->curitem->distance = state->curoperand - state->operand;
- state->curoperand[in->valnode->length] = '\0';
- state->curoperand += in->valnode->length + 1;
- state->curitem++;
- }
- else
- {
- ITEM *curitem = state->curitem;
-
- Assert(in->nchild <= 2);
- state->curitem++;
-
- fillQT(state, in->child[0]);
-
- if (in->nchild == 2)
- {
- curitem->left = state->curitem - curitem;
- fillQT(state, in->child[1]);
- }
- }
-}
-
-QUERYTYPE *
-QTN2QT(QTNode * in, MemoryType memtype)
-{
- QUERYTYPE *out;
- int len;
- int sumlen = 0,
- nnode = 0;
- QTN2QTState state;
-
- cntsize(in, &sumlen, &nnode);
- len = COMPUTESIZE(nnode, sumlen);
-
- out = (QUERYTYPE *) MEMALLOC(memtype, len);
- SET_VARSIZE(out, len);
- out->size = nnode;
-
- state.curitem = GETQUERY(out);
- state.operand = state.curoperand = GETOPERAND(out);
-
- fillQT(&state, in);
- return out;
-}
-
-QTNode *
-QTNCopy(QTNode * in, MemoryType memtype)
-{
- QTNode *out = (QTNode *) MEMALLOC(memtype, sizeof(QTNode));
-
- *out = *in;
- out->valnode = (ITEM *) MEMALLOC(memtype, sizeof(ITEM));
- *(out->valnode) = *(in->valnode);
- out->flags |= QTN_NEEDFREE;
-
- if (in->valnode->type == VAL)
- {
- out->word = MEMALLOC(memtype, in->valnode->length + 1);
- memcpy(out->word, in->word, in->valnode->length);
- out->word[in->valnode->length] = '\0';
- out->flags |= QTN_WORDFREE;
- }
- else
- {
- int i;
-
- out->child = (QTNode **) MEMALLOC(memtype, sizeof(QTNode *) * in->nchild);
-
- for (i = 0; i < in->nchild; i++)
- out->child[i] = QTNCopy(in->child[i], memtype);
- }
-
- return out;
-}
+++ /dev/null
-#ifndef __QUERY_UTIL_H__
-#define __QUERY_UTIL_H__
-
-#include "postgres.h"
-#include "utils/memutils.h"
-
-#include "query.h"
-#include "executor/spi.h"
-
-typedef struct QTNode
-{
- ITEM *valnode;
- uint32 flags;
- int4 nchild;
- char *word;
- uint32 sign;
- struct QTNode **child;
-} QTNode;
-
-#define QTN_NEEDFREE 0x01
-#define QTN_NOCHANGE 0x02
-#define QTN_WORDFREE 0x04
-
-typedef enum
-{
- PlainMemory,
- SPIMemory,
- AggMemory
-} MemoryType;
-
-QTNode *QT2QTN(ITEM * in, char *operand);
-QUERYTYPE *QTN2QT(QTNode * in, MemoryType memtype);
-void QTNFree(QTNode * in);
-void QTNSort(QTNode * in);
-void QTNTernary(QTNode * in);
-void QTNBinary(QTNode * in);
-int QTNodeCompare(QTNode * an, QTNode * bn);
-QTNode *QTNCopy(QTNode * in, MemoryType memtype);
-bool QTNEq(QTNode * a, QTNode * b);
-
-
-extern MemoryContext AggregateContext;
-
-#define MEMALLOC(us, s) ( ((us)==SPIMemory) ? SPI_palloc(s) : ( ( (us)==PlainMemory ) ? palloc(s) : MemoryContextAlloc(AggregateContext, (s)) ) )
-#define MEMFREE(us, p) ( ((us)==SPIMemory) ? SPI_pfree(p) : pfree(p) )
-
-#endif
+++ /dev/null
-/*
- * Relevation
- * Teodor Sigaev
- */
-#include "postgres.h"
-
-#include
-
-#include "access/gist.h"
-#include "access/itup.h"
-#include "catalog/namespace.h"
-#include "commands/trigger.h"
-#include "executor/spi.h"
-#include "fmgr.h"
-#include "funcapi.h"
-#include "nodes/pg_list.h"
-#include "storage/bufpage.h"
-#include "utils/array.h"
-#include "utils/builtins.h"
-
-#include "tsvector.h"
-#include "query.h"
-#include "common.h"
-
-PG_FUNCTION_INFO_V1(rank);
-Datum rank(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(rank_def);
-Datum rank_def(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(rank_cd);
-Datum rank_cd(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(rank_cd_def);
-Datum rank_cd_def(PG_FUNCTION_ARGS);
-
-PG_FUNCTION_INFO_V1(get_covers);
-Datum get_covers(PG_FUNCTION_ARGS);
-
-static float weights[] = {0.1f, 0.2f, 0.4f, 1.0f};
-
-#define wpos(wep) ( w[ WEP_GETWEIGHT(wep) ] )
-
-#define RANK_NO_NORM 0x00
-#define RANK_NORM_LOGLENGTH 0x01
-#define RANK_NORM_LENGTH 0x02
-#define RANK_NORM_EXTDIST 0x04
-#define RANK_NORM_UNIQ 0x08
-#define RANK_NORM_LOGUNIQ 0x10
-#define DEF_NORM_METHOD RANK_NO_NORM
-
-static float calc_rank_or(float *w, tsvector * t, QUERYTYPE * q);
-static float calc_rank_and(float *w, tsvector * t, QUERYTYPE * q);
-
-/*
- * Returns a weight of a word collocation
- */
-static float4
-word_distance(int4 w)
-{
- if (w > 100)
- return (float4)1e-30;
-
- return 1.0 / (1.005 + 0.05 * exp(((float4) w) / 1.5 - 2));
-}
-
-static int
-cnt_length(tsvector * t)
-{
- WordEntry *ptr = ARRPTR(t),
- *end = (WordEntry *) STRPTR(t);
- int len = 0,
- clen;
-
- while (ptr < end)
- {
- if ((clen = POSDATALEN(t, ptr)) == 0)
- len += 1;
- else
- len += clen;
- ptr++;
- }
-
- return len;
-}
-
-static int4
-WordECompareITEM(char *eval, char *qval, WordEntry * ptr, ITEM * item)
-{
- if (ptr->len == item->length)
- return strncmp(
- eval + ptr->pos,
- qval + item->distance,
- item->length);
-
- return (ptr->len > item->length) ? 1 : -1;
-}
-
-static WordEntry *
-find_wordentry(tsvector * t, QUERYTYPE * q, ITEM * item)
-{
- WordEntry *StopLow = ARRPTR(t);
- WordEntry *StopHigh = (WordEntry *) STRPTR(t);
- WordEntry *StopMiddle;
- int difference;
-
- /* Loop invariant: StopLow <= item < StopHigh */
-
- while (StopLow < StopHigh)
- {
- StopMiddle = StopLow + (StopHigh - StopLow) / 2;
- difference = WordECompareITEM(STRPTR(t), GETOPERAND(q), StopMiddle, item);
- if (difference == 0)
- return StopMiddle;
- else if (difference < 0)
- StopLow = StopMiddle + 1;
- else
- StopHigh = StopMiddle;
- }
-
- return NULL;
-}
-
-
-static int
-compareITEM(const void *a, const void *b, void *arg)
-{
- char *operand = (char *) arg;
-
- if ((*(ITEM **) a)->length == (*(ITEM **) b)->length)
- return strncmp(operand + (*(ITEM **) a)->distance,
- operand + (*(ITEM **) b)->distance,
- (*(ITEM **) b)->length);
-
- return ((*(ITEM **) a)->length > (*(ITEM **) b)->length) ? 1 : -1;
-}
-
-static ITEM **
-SortAndUniqItems(char *operand, ITEM * item, int *size)
-{
- ITEM **res,
- **ptr,
- **prevptr;
-
- ptr = res = (ITEM **) palloc(sizeof(ITEM *) * *size);
-
- while ((*size)--)
- {
- if (item->type == VAL)
- {
- *ptr = item;
- ptr++;
- }
- item++;
- }
-
- *size = ptr - res;
- if (*size < 2)
- return res;
-
- qsort_arg(res, *size, sizeof(ITEM **), compareITEM, (void *) operand);
-
- ptr = res + 1;
- prevptr = res;
-
- while (ptr - res < *size)
- {
- if (compareITEM((void *) ptr, (void *) prevptr, (void *) operand) != 0)
- {
- prevptr++;
- *prevptr = *ptr;
- }
- ptr++;
- }
-
- *size = prevptr + 1 - res;
- return res;
-}
-
-static WordEntryPos POSNULL[] = {
- 0,
- 0
-};
-
-static float
-calc_rank_and(float *w, tsvector * t, QUERYTYPE * q)
-{
- uint16 **pos;
- int i,
- k,
- l,
- p;
- WordEntry *entry;
- WordEntryPos *post,
- *ct;
- int4 dimt,
- lenct,
- dist;
- float res = -1.0;
- ITEM **item;
- int size = q->size;
-
- item = SortAndUniqItems(GETOPERAND(q), GETQUERY(q), &size);
- if (size < 2)
- {
- pfree(item);
- return calc_rank_or(w, t, q);
- }
- pos = (uint16 **) palloc(sizeof(uint16 *) * q->size);
- memset(pos, 0, sizeof(uint16 *) * q->size);
- *(uint16 *) POSNULL = lengthof(POSNULL) - 1;
- WEP_SETPOS(POSNULL[1], MAXENTRYPOS - 1);
-
- for (i = 0; i < size; i++)
- {
- entry = find_wordentry(t, q, item[i]);
- if (!entry)
- continue;
-
- if (entry->haspos)
- pos[i] = (uint16 *) _POSDATAPTR(t, entry);
- else
- pos[i] = (uint16 *) POSNULL;
-
-
- dimt = *(uint16 *) (pos[i]);
- post = (WordEntryPos *) (pos[i] + 1);
- for (k = 0; k < i; k++)
- {
- if (!pos[k])
- continue;
- lenct = *(uint16 *) (pos[k]);
- ct = (WordEntryPos *) (pos[k] + 1);
- for (l = 0; l < dimt; l++)
- {
- for (p = 0; p < lenct; p++)
- {
- dist = Abs((int) WEP_GETPOS(post[l]) - (int) WEP_GETPOS(ct[p]));
- if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL)))
- {
- float curw;
-
- if (!dist)
- dist = MAXENTRYPOS;
- curw = sqrt(wpos(post[l]) * wpos(ct[p]) * word_distance(dist));
- res = (res < 0) ? curw : 1.0 - (1.0 - res) * (1.0 - curw);
- }
- }
- }
- }
- }
- pfree(pos);
- pfree(item);
- return res;
-}
-
-static float
-calc_rank_or(float *w, tsvector * t, QUERYTYPE * q)
-{
- WordEntry *entry;
- WordEntryPos *post;
- int4 dimt,
- j,
- i;
- float res = 0.0;
- ITEM **item;
- int size = q->size;
-
- *(uint16 *) POSNULL = lengthof(POSNULL) - 1;
- item = SortAndUniqItems(GETOPERAND(q), GETQUERY(q), &size);
-
- for (i = 0; i < size; i++)
- {
- float resj,
- wjm;
- int4 jm;
-
- entry = find_wordentry(t, q, item[i]);
- if (!entry)
- continue;
-
- if (entry->haspos)
- {
- dimt = POSDATALEN(t, entry);
- post = POSDATAPTR(t, entry);
- }
- else
- {
- dimt = *(uint16 *) POSNULL;
- post = POSNULL + 1;
- }
-
- resj = 0.0;
- wjm = -1.0;
- jm = 0;
- for (j = 0; j < dimt; j++)
- {
- resj = resj + wpos(post[j]) / ((j + 1) * (j + 1));
- if (wpos(post[j]) > wjm)
- {
- wjm = wpos(post[j]);
- jm = j;
- }
- }
-/*
- limit (sum(i/i^2),i->inf) = pi^2/6
- resj = sum(wi/i^2),i=1,noccurence,
- wi - should be sorted desc,
- don't sort for now, just choose maximum weight. This should be corrected
- Oleg Bartunov
-*/
- res = res + (wjm + resj - wjm / ((jm + 1) * (jm + 1))) / 1.64493406685;
- }
- if (size > 0)
- res = res / size;
- pfree(item);
- return res;
-}
-
-static float
-calc_rank(float *w, tsvector * t, QUERYTYPE * q, int4 method)
-{
- ITEM *item = GETQUERY(q);
- float res = 0.0;
- int len;
-
- if (!t->size || !q->size)
- return 0.0;
-
- res = (item->type != VAL && item->val == (int4) '&') ?
- calc_rank_and(w, t, q) : calc_rank_or(w, t, q);
-
- if (res < 0)
- res = (float)1e-20;
-
- if ((method & RANK_NORM_LOGLENGTH) && t->size > 0)
- res /= log((double) (cnt_length(t) + 1)) / log(2.0);
-
- if (method & RANK_NORM_LENGTH)
- {
- len = cnt_length(t);
- if (len > 0)
- res /= (float) len;
- }
-
- if ((method & RANK_NORM_UNIQ) && t->size > 0)
- res /= (float) (t->size);
-
- if ((method & RANK_NORM_LOGUNIQ) && t->size > 0)
- res /= log((double) (t->size + 1)) / log(2.0);
-
- return res;
-}
-
-Datum
-rank(PG_FUNCTION_ARGS)
-{
- ArrayType *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- tsvector *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
- QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
- int method = DEF_NORM_METHOD;
- float res = 0.0;
- float ws[lengthof(weights)];
- float4 *arrdata;
- int i;
-
- if (ARR_NDIM(win) != 1)
- ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("array of weight must be one-dimensional")));
-
- if (ARRNELEMS(win) < lengthof(weights))
- ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("array of weight is too short")));
-
- if (ARR_HASNULL(win))
- ereport(ERROR,
- (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("array of weight must not contain nulls")));
-
- arrdata = (float4 *) ARR_DATA_PTR(win);
- for (i = 0; i < lengthof(weights); i++)
- {
- ws[i] = (arrdata[i] >= 0) ? arrdata[i] : weights[i];
- if (ws[i] > 1.0)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("weight out of range")));
- }
-
- if (PG_NARGS() == 4)
- method = PG_GETARG_INT32(3);
-
- res = calc_rank(ws, txt, query, method);
-
- PG_FREE_IF_COPY(win, 0);
- PG_FREE_IF_COPY(txt, 1);
- PG_FREE_IF_COPY(query, 2);
- PG_RETURN_FLOAT4(res);
-}
-
-Datum
-rank_def(PG_FUNCTION_ARGS)
-{
- tsvector *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
- float res = 0.0;
- int method = DEF_NORM_METHOD;
-
- if (PG_NARGS() == 3)
- method = PG_GETARG_INT32(2);
-
- res = calc_rank(weights, txt, query, method);
-
- PG_FREE_IF_COPY(txt, 0);
- PG_FREE_IF_COPY(query, 1);
- PG_RETURN_FLOAT4(res);
-}
-
-
-typedef struct
-{
- ITEM **item;
- int16 nitem;
- bool needfree;
- uint8 wclass;
- int32 pos;
-} DocRepresentation;
-
-static int
-compareDocR(const void *a, const void *b)
-{
- if (((DocRepresentation *) a)->pos == ((DocRepresentation *) b)->pos)
- return 0;
- return (((DocRepresentation *) a)->pos > ((DocRepresentation *) b)->pos) ? 1 : -1;
-}
-
-static bool
-checkcondition_ITEM(void *checkval, ITEM * val)
-{
- return (bool) (val->istrue);
-}
-
-static void
-reset_istrue_flag(QUERYTYPE * query)
-{
- ITEM *item = GETQUERY(query);
- int i;
-
- /* reset istrue flag */
- for (i = 0; i < query->size; i++)
- {
- if (item->type == VAL)
- item->istrue = 0;
- item++;
- }
-}
-
-typedef struct
-{
- int pos;
- int p;
- int q;
- DocRepresentation *begin;
- DocRepresentation *end;
-} Extention;
-
-
-static bool
-Cover(DocRepresentation * doc, int len, QUERYTYPE * query, Extention * ext)
-{
- DocRepresentation *ptr;
- int lastpos = ext->pos;
- int i;
- bool found = false;
-
- reset_istrue_flag(query);
-
- ext->p = 0x7fffffff;
- ext->q = 0;
- ptr = doc + ext->pos;
-
- /* find upper bound of cover from current position, move up */
- while (ptr - doc < len)
- {
- for (i = 0; i < ptr->nitem; i++)
- ptr->item[i]->istrue = 1;
- if (TS_execute(GETQUERY(query), NULL, false, checkcondition_ITEM))
- {
- if (ptr->pos > ext->q)
- {
- ext->q = ptr->pos;
- ext->end = ptr;
- lastpos = ptr - doc;
- found = true;
- }
- break;
- }
- ptr++;
- }
-
- if (!found)
- return false;
-
- reset_istrue_flag(query);
-
- ptr = doc + lastpos;
-
- /* find lower bound of cover from founded upper bound, move down */
- while (ptr >= doc)
- {
- for (i = 0; i < ptr->nitem; i++)
- ptr->item[i]->istrue = 1;
- if (TS_execute(GETQUERY(query), NULL, true, checkcondition_ITEM))
- {
- if (ptr->pos < ext->p)
- {
- ext->begin = ptr;
- ext->p = ptr->pos;
- }
- break;
- }
- ptr--;
- }
-
- if (ext->p <= ext->q)
- {
- /*
- * set position for next try to next lexeme after begining of founded
- * cover
- */
- ext->pos = (ptr - doc) + 1;
- return true;
- }
-
- ext->pos++;
- return Cover(doc, len, query, ext);
-}
-
-static DocRepresentation *
-get_docrep(tsvector * txt, QUERYTYPE * query, int *doclen)
-{
- ITEM *item = GETQUERY(query);
- WordEntry *entry;
- WordEntryPos *post;
- int4 dimt,
- j,
- i;
- int len = query->size * 4,
- cur = 0;
- DocRepresentation *doc;
- char *operand;
-
- *(uint16 *) POSNULL = lengthof(POSNULL) - 1;
- doc = (DocRepresentation *) palloc(sizeof(DocRepresentation) * len);
- operand = GETOPERAND(query);
- reset_istrue_flag(query);
-
- for (i = 0; i < query->size; i++)
- {
- if (item[i].type != VAL || item[i].istrue)
- continue;
-
- entry = find_wordentry(txt, query, &(item[i]));
- if (!entry)
- continue;
-
- if (entry->haspos)
- {
- dimt = POSDATALEN(txt, entry);
- post = POSDATAPTR(txt, entry);
- }
- else
- {
- dimt = *(uint16 *) POSNULL;
- post = POSNULL + 1;
- }
-
- while (cur + dimt >= len)
- {
- len *= 2;
- doc = (DocRepresentation *) repalloc(doc, sizeof(DocRepresentation) * len);
- }
-
- for (j = 0; j < dimt; j++)
- {
- if (j == 0)
- {
- ITEM *kptr,
- *iptr = item + i;
- int k;
-
- doc[cur].needfree = false;
- doc[cur].nitem = 0;
- doc[cur].item = (ITEM **) palloc(sizeof(ITEM *) * query->size);
-
- for (k = 0; k < query->size; k++)
- {
- kptr = item + k;
- if (k == i ||
- (item[k].type == VAL &&
- compareITEM(&kptr, &iptr, operand) == 0))
- {
- doc[cur].item[doc[cur].nitem] = item + k;
- doc[cur].nitem++;
- kptr->istrue = 1;
- }
- }
- }
- else
- {
- doc[cur].needfree = false;
- doc[cur].nitem = doc[cur - 1].nitem;
- doc[cur].item = doc[cur - 1].item;
- }
- doc[cur].pos = WEP_GETPOS(post[j]);
- doc[cur].wclass = WEP_GETWEIGHT(post[j]);
- cur++;
- }
- }
-
- *doclen = cur;
-
- if (cur > 0)
- {
- if (cur > 1)
- qsort((void *) doc, cur, sizeof(DocRepresentation), compareDocR);
- return doc;
- }
-
- pfree(doc);
- return NULL;
-}
-
-static float4
-calc_rank_cd(float4 *arrdata, tsvector * txt, QUERYTYPE * query, int method)
-{
- DocRepresentation *doc;
- int len,
- i,
- doclen = 0;
- Extention ext;
- double Wdoc = 0.0;
- double invws[lengthof(weights)];
- double SumDist = 0.0,
- PrevExtPos = 0.0,
- CurExtPos = 0.0;
- int NExtent = 0;
-
- for (i = 0; i < lengthof(weights); i++)
- {
- invws[i] = ((double) ((arrdata[i] >= 0) ? arrdata[i] : weights[i]));
- if (invws[i] > 1.0)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("weight out of range")));
- invws[i] = 1.0 / invws[i];
- }
-
- doc = get_docrep(txt, query, &doclen);
- if (!doc)
- return 0.0;
-
- MemSet(&ext, 0, sizeof(Extention));
- while (Cover(doc, doclen, query, &ext))
- {
- double Cpos = 0.0;
- double InvSum = 0.0;
- int nNoise;
- DocRepresentation *ptr = ext.begin;
-
- while (ptr <= ext.end)
- {
- InvSum += invws[ptr->wclass];
- ptr++;
- }
-
- Cpos = ((double) (ext.end - ext.begin + 1)) / InvSum;
- /*
- * if doc are big enough then ext.q may be equal to ext.p
- * due to limit of posional information. In this case we
- * approximate number of noise word as half cover's
- * length
- */
- nNoise = (ext.q - ext.p) - (ext.end - ext.begin);
- if ( nNoise < 0 )
- nNoise = (ext.end - ext.begin) / 2;
- Wdoc += Cpos / ((double) (1 + nNoise));
-
- CurExtPos = ((double) (ext.q + ext.p)) / 2.0;
- if (NExtent > 0 && CurExtPos > PrevExtPos /* prevent devision by
- * zero in a case of
- multiple lexize */ )
- SumDist += 1.0 / (CurExtPos - PrevExtPos);
-
- PrevExtPos = CurExtPos;
- NExtent++;
- }
-
- if ((method & RANK_NORM_LOGLENGTH) && txt->size > 0)
- Wdoc /= log((double) (cnt_length(txt) + 1));
-
- if (method & RANK_NORM_LENGTH)
- {
- len = cnt_length(txt);
- if (len > 0)
- Wdoc /= (double) len;
- }
-
- if ((method & RANK_NORM_EXTDIST) && SumDist > 0)
- Wdoc /= ((double) NExtent) / SumDist;
-
- if ((method & RANK_NORM_UNIQ) && txt->size > 0)
- Wdoc /= (double) (txt->size);
-
- if ((method & RANK_NORM_LOGUNIQ) && txt->size > 0)
- Wdoc /= log((double) (txt->size + 1)) / log(2.0);
-
- for (i = 0; i < doclen; i++)
- if (doc[i].needfree)
- pfree(doc[i].item);
- pfree(doc);
-
- return (float4) Wdoc;
-}
-
-Datum
-rank_cd(PG_FUNCTION_ARGS)
-{
- ArrayType *win;
- tsvector *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
- QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(2));
- int method = DEF_NORM_METHOD;
- float4 res;
-
- /*
- * Pre-8.2, rank_cd took just a plain int as its first argument.
- * It was a mistake to keep the same C function name while changing the
- * signature, but it's too late to fix that. Instead, do a runtime test
- * to make sure the expected datatype has been passed. This is needed
- * to prevent core dumps if tsearch2 function definitions from an old
- * database are loaded into an 8.2 server.
- */
- if (get_fn_expr_argtype(fcinfo->flinfo, 0) != FLOAT4ARRAYOID)
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
- errmsg("rank_cd() now takes real[] as its first argument, not integer")));
-
- /* now safe to dereference the first arg */
- win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-
- if (ARR_NDIM(win) != 1)
- ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("array of weight must be one-dimensional")));
-
- if (ARRNELEMS(win) < lengthof(weights))
- ereport(ERROR,
- (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
- errmsg("array of weight is too short")));
-
- if (ARR_HASNULL(win))
- ereport(ERROR,
- (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("array of weight must not contain nulls")));
-
- if (PG_NARGS() == 4)
- method = PG_GETARG_INT32(3);
-
- res = calc_rank_cd((float4 *) ARR_DATA_PTR(win), txt, query, method);
-
- PG_FREE_IF_COPY(win, 0);
- PG_FREE_IF_COPY(txt, 1);
- PG_FREE_IF_COPY(query, 2);
-
- PG_RETURN_FLOAT4(res);
-}
-
-
-Datum
-rank_cd_def(PG_FUNCTION_ARGS)
-{
- tsvector *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1));
- float4 res;
-
- res = calc_rank_cd(weights, txt, query, (PG_NARGS() == 3) ? PG_GETARG_DATUM(2) : DEF_NORM_METHOD);
-
- PG_FREE_IF_COPY(txt, 0);
- PG_FREE_IF_COPY(query, 1);
-
- PG_RETURN_FLOAT4(res);
-}
-
-/**************debug*************/
-
-typedef struct
-{
- char *w;
- int2 len;
- int2 pos;
- int2 start;
- int2 finish;
-} DocWord;
-
-static int
-compareDocWord(const void *a, const void *b)
-{
- if (((DocWord *) a)->pos == ((DocWord *) b)->pos)
- return 0;
- return (((DocWord *) a)->pos > ((DocWord *) b)->pos) ? 1 : -1;
-}
-
-
-Datum
-get_covers(PG_FUNCTION_ARGS)
-{
- tsvector *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
- QUERYTYPE *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1));
- WordEntry *pptr = ARRPTR(txt);
- int i,
- dlen = 0,
- j,
- cur = 0,
- len = 0,
- rlen;
- DocWord *dw,
- *dwptr;
- text *out;
- char *cptr;
- DocRepresentation *doc;
- int olddwpos = 0;
- int ncover = 1;
- Extention ext;
-
- doc = get_docrep(txt, query, &rlen);
-
- if (!doc)
- {
- out = palloc(VARHDRSZ);
- SET_VARSIZE(out, VARHDRSZ);
- PG_FREE_IF_COPY(txt, 0);
- PG_FREE_IF_COPY(query, 1);
- PG_RETURN_POINTER(out);
- }
-
- for (i = 0; i < txt->size; i++)
- {
- if (!pptr[i].haspos)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("no pos info")));
- dlen += POSDATALEN(txt, &(pptr[i]));
- }
-
- dwptr = dw = palloc(sizeof(DocWord) * dlen);
- memset(dw, 0, sizeof(DocWord) * dlen);
-
- for (i = 0; i < txt->size; i++)
- {
- WordEntryPos *posdata = POSDATAPTR(txt, &(pptr[i]));
-
- for (j = 0; j < POSDATALEN(txt, &(pptr[i])); j++)
- {
- dw[cur].w = STRPTR(txt) + pptr[i].pos;
- dw[cur].len = pptr[i].len;
- dw[cur].pos = WEP_GETPOS(posdata[j]);
- cur++;
- }
- len += (pptr[i].len + 1) * (int) POSDATALEN(txt, &(pptr[i]));
- }
- qsort((void *) dw, dlen, sizeof(DocWord), compareDocWord);
-
- MemSet(&ext, 0, sizeof(Extention));
- while (Cover(doc, rlen, query, &ext))
- {
- dwptr = dw + olddwpos;
- while (dwptr->pos < ext.p && dwptr - dw < dlen)
- dwptr++;
- olddwpos = dwptr - dw;
- dwptr->start = ncover;
- while (dwptr->pos < ext.q + 1 && dwptr - dw < dlen)
- dwptr++;
- (dwptr - 1)->finish = ncover;
- len += 4 /* {}+two spaces */ + 2 * 16 /* numbers */ ;
- ncover++;
- }
-
- out = palloc(VARHDRSZ + len);
- cptr = ((char *) out) + VARHDRSZ;
- dwptr = dw;
-
- while (dwptr - dw < dlen)
- {
- if (dwptr->start)
- {
- sprintf(cptr, "{%d ", dwptr->start);
- cptr = strchr(cptr, '\0');
- }
- memcpy(cptr, dwptr->w, dwptr->len);
- cptr += dwptr->len;
- *cptr = ' ';
- cptr++;
- if (dwptr->finish)
- {
- sprintf(cptr, "}%d ", dwptr->finish);
- cptr = strchr(cptr, '\0');
- }
- dwptr++;
- }
-
- SET_VARSIZE(out, cptr - ((char *) out));
-
- pfree(dw);
- for (i = 0; i < rlen; i++)
- if (doc[i].needfree)
- pfree(doc[i].item);
- pfree(doc);
-
- PG_FREE_IF_COPY(txt, 0);
- PG_FREE_IF_COPY(query, 1);
- PG_RETURN_POINTER(out);
-}
+++ /dev/null
-/*
- * simple but fast map from str to Oid
- * Teodor Sigaev
- */
-#include "postgres.h"
-
-#include "snmap.h"
-#include "common.h"
-
-static int
-compareSNMapEntry(const void *a, const void *b)
-{
- if (((SNMapEntry *) a)->nsp < ((SNMapEntry *) b)->nsp)
- return -1;
- else if (((SNMapEntry *) a)->nsp > ((SNMapEntry *) b)->nsp)
- return 1;
- else
- return strcmp(((SNMapEntry *) a)->key, ((SNMapEntry *) b)->key);
-}
-
-void
-addSNMap(SNMap * map, char *key, Oid value)
-{
- if (map->len >= map->reallen)
- {
- SNMapEntry *tmp;
- int len = (map->reallen) ? 2 * map->reallen : 16;
-
- tmp = (SNMapEntry *) realloc(map->list, sizeof(SNMapEntry) * len);
- if (!tmp)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
- map->reallen = len;
- map->list = tmp;
- }
- map->list[map->len].key = strdup(key);
- if (!map->list[map->len].key)
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
- map->list[map->len].nsp = get_oidnamespace(TSNSP_FunctionOid);
- map->list[map->len].value = value;
- map->len++;
- if (map->len > 1)
- qsort(map->list, map->len, sizeof(SNMapEntry), compareSNMapEntry);
-}
-
-void
-addSNMap_t(SNMap * map, text *key, Oid value)
-{
- char *k = text2char(key);
-
- addSNMap(map, k, value);
- pfree(k);
-}
-
-Oid
-findSNMap(SNMap * map, char *key)
-{
- SNMapEntry *ptr;
- SNMapEntry ks;
-
- ks.key = key;
- ks.nsp = get_oidnamespace(TSNSP_FunctionOid);
- ks.value = 0;
-
- if (map->len == 0 || !map->list)
- return 0;
- ptr = (SNMapEntry *) bsearch(&ks, map->list, map->len, sizeof(SNMapEntry), compareSNMapEntry);
- return (ptr) ? ptr->value : 0;
-}
-
-Oid
-findSNMap_t(SNMap * map, text *key)
-{
- char *k = text2char(key);
- int res;
-
- res = findSNMap(map, k);
- pfree(k);
- return res;
-}
-
-void
-freeSNMap(SNMap * map)
-{
- SNMapEntry *entry = map->list;
-
- if (map->list)
- {
- while (map->len)
- {
- if (entry->key)
- free(entry->key);
- entry++;
- map->len--;
- }
- free(map->list);
- }
- memset(map, 0, sizeof(SNMap));
-}
+++ /dev/null
-#ifndef __SNMAP_H__
-#define __SNMAP_H__
-
-#include "postgres.h"
-
-typedef struct
-{
- char *key;
- Oid value;
- Oid nsp;
-} SNMapEntry;
-
-typedef struct
-{
- int len;
- int reallen;
- SNMapEntry *list;
-} SNMap;
-
-void addSNMap(SNMap * map, char *key, Oid value);
-void addSNMap_t(SNMap * map, text *key, Oid value);
-Oid findSNMap(SNMap * map, char *key);
-Oid findSNMap_t(SNMap * map, text *key);
-void freeSNMap(SNMap * map);
-
-#endif
+++ /dev/null
-# $PostgreSQL: pgsql/contrib/tsearch2/snowball/Makefile,v 1.10 2007/06/26 22:05:03 tgl Exp $
-
-SUBOBJS = english_stem.o api.o russian_stem.o russian_stem_UTF8.o utilities.o
-
-EXTRA_CLEAN = SUBSYS.o $(SUBOBJS)
-
-PG_CPPFLAGS = -I$(srcdir)/..
-
-ifdef USE_PGXS
-PG_CONFIG = pg_config
-PGXS := $(shell $(PG_CONFIG) --pgxs)
-include $(PGXS)
-else
-subdir = contrib/tsearch2/snowball
-top_builddir = ../../..
-include $(top_builddir)/src/Makefile.global
-include $(top_srcdir)/contrib/contrib-global.mk
-endif
-
-override CFLAGS += $(CFLAGS_SL)
-
-all: SUBSYS.o
-
-SUBSYS.o: $(SUBOBJS)
- $(LD) $(LDREL) $(LDOUT) $@ $^
-
-
+++ /dev/null
-
-#include /* for calloc, free */
-#include "header.h"
-
-extern struct SN_env *
-SN_create_env(int S_size, int I_size, int B_size)
-{
- struct SN_env *z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
-
- if (z == NULL)
- return NULL;
- z->p = create_s();
- if (z->p == NULL)
- goto error;
- if (S_size)
- {
- int i;
-
- z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
- if (z->S == NULL)
- goto error;
-
- for (i = 0; i < S_size; i++)
- {
- z->S[i] = create_s();
- if (z->S[i] == NULL)
- goto error;
- }
- z->S_size = S_size;
- }
-
- if (I_size)
- {
- z->I = (int *) calloc(I_size, sizeof(int));
- if (z->I == NULL)
- goto error;
- z->I_size = I_size;
- }
-
- if (B_size)
- {
- z->B = (symbol *) calloc(B_size, sizeof(symbol));
- if (z->B == NULL)
- goto error;
- z->B_size = B_size;
- }
-
- return z;
-error:
- SN_close_env(z);
- return NULL;
-}
-
-extern void
-SN_close_env(struct SN_env * z)
-{
- if (z == NULL)
- return;
- if (z->S_size)
- {
- int i;
-
- for (i = 0; i < z->S_size; i++)
- {
- lose_s(z->S[i]);
- }
- free(z->S);
- }
- if (z->I_size)
- free(z->I);
- if (z->B_size)
- free(z->B);
- if (z->p)
- lose_s(z->p);
- free(z);
-}
-
-extern int
-SN_set_current(struct SN_env * z, int size, const symbol * s)
-{
- int err = replace_s(z, 0, z->l, size, s, NULL);
-
- z->c = 0;
- return err;
-}
+++ /dev/null
-
-typedef unsigned char symbol;
-
-/* Or replace 'char' above with 'short' for 16 bit characters.
-
- More precisely, replace 'char' with whatever type guarantees the
- character width you need. Note however that sizeof(symbol) should divide
- HEAD, defined in header.h as 2*sizeof(int), without remainder, otherwise
- there is an alignment problem. In the unlikely event of a problem here,
- consult Martin Porter.
-
-*/
-
-struct SN_env
-{
- symbol *p;
- int c;
- int a;
- int l;
- int lb;
- int bra;
- int ket;
- int S_size;
- int I_size;
- int B_size;
- symbol **S;
- int *I;
- symbol *B;
-};
-
-extern struct SN_env *SN_create_env(int S_size, int I_size, int B_size);
-extern void SN_close_env(struct SN_env * z);
-
-extern int SN_set_current(struct SN_env * z, int size, const symbol * s);
+++ /dev/null
-/* $PostgreSQL: pgsql/contrib/tsearch2/snowball/english_stem.c,v 1.8 2006/03/11 04:38:30 momjian Exp $ */
-
-/* This file was generated automatically by the Snowball to ANSI C compiler */
-
-#include "header.h"
-
-extern int english_ISO_8859_1_stem(struct SN_env * z);
-static int r_exception2(struct SN_env * z);
-static int r_exception1(struct SN_env * z);
-static int r_Step_5(struct SN_env * z);
-static int r_Step_4(struct SN_env * z);
-static int r_Step_3(struct SN_env * z);
-static int r_Step_2(struct SN_env * z);
-static int r_Step_1c(struct SN_env * z);
-static int r_Step_1b(struct SN_env * z);
-static int r_Step_1a(struct SN_env * z);
-static int r_R2(struct SN_env * z);
-static int r_R1(struct SN_env * z);
-static int r_shortv(struct SN_env * z);
-static int r_mark_regions(struct SN_env * z);
-static int r_postlude(struct SN_env * z);
-static int r_prelude(struct SN_env * z);
-
-extern struct SN_env *english_ISO_8859_1_create_env(void);
-extern void english_ISO_8859_1_close_env(struct SN_env * z);
-
-static symbol s_0_0[6] = {'c', 'o', 'm', 'm', 'u', 'n'};
-static symbol s_0_1[5] = {'g', 'e', 'n', 'e', 'r'};
-
-static struct among a_0[2] =
-{
- /* 0 */ {6, s_0_0, -1, -1, 0},
- /* 1 */ {5, s_0_1, -1, -1, 0}
-};
-
-static symbol s_1_0[1] = {'\''};
-static symbol s_1_1[3] = {'\'', 's', '\''};
-static symbol s_1_2[2] = {'\'', 's'};
-
-static struct among a_1[3] =
-{
- /* 0 */ {1, s_1_0, -1, 1, 0},
- /* 1 */ {3, s_1_1, 0, 1, 0},
- /* 2 */ {2, s_1_2, -1, 1, 0}
-};
-
-static symbol s_2_0[3] = {'i', 'e', 'd'};
-static symbol s_2_1[1] = {'s'};
-static symbol s_2_2[3] = {'i', 'e', 's'};
-static symbol s_2_3[4] = {'s', 's', 'e', 's'};
-static symbol s_2_4[2] = {'s', 's'};
-static symbol s_2_5[2] = {'u', 's'};
-
-static struct among a_2[6] =
-{
- /* 0 */ {3, s_2_0, -1, 2, 0},
- /* 1 */ {1, s_2_1, -1, 3, 0},
- /* 2 */ {3, s_2_2, 1, 2, 0},
- /* 3 */ {4, s_2_3, 1, 1, 0},
- /* 4 */ {2, s_2_4, 1, -1, 0},
- /* 5 */ {2, s_2_5, 1, -1, 0}
-};
-
-static symbol s_3_1[2] = {'b', 'b'};
-static symbol s_3_2[2] = {'d', 'd'};
-static symbol s_3_3[2] = {'f', 'f'};
-static symbol s_3_4[2] = {'g', 'g'};
-static symbol s_3_5[2] = {'b', 'l'};
-static symbol s_3_6[2] = {'m', 'm'};
-static symbol s_3_7[2] = {'n', 'n'};
-static symbol s_3_8[2] = {'p', 'p'};
-static symbol s_3_9[2] = {'r', 'r'};
-static symbol s_3_10[2] = {'a', 't'};
-static symbol s_3_11[2] = {'t', 't'};
-static symbol s_3_12[2] = {'i', 'z'};
-
-static struct among a_3[13] =
-{
- /* 0 */ {0, 0, -1, 3, 0},
- /* 1 */ {2, s_3_1, 0, 2, 0},
- /* 2 */ {2, s_3_2, 0, 2, 0},
- /* 3 */ {2, s_3_3, 0, 2, 0},
- /* 4 */ {2, s_3_4, 0, 2, 0},
- /* 5 */ {2, s_3_5, 0, 1, 0},
- /* 6 */ {2, s_3_6, 0, 2, 0},
- /* 7 */ {2, s_3_7, 0, 2, 0},
- /* 8 */ {2, s_3_8, 0, 2, 0},
- /* 9 */ {2, s_3_9, 0, 2, 0},
- /* 10 */ {2, s_3_10, 0, 1, 0},
- /* 11 */ {2, s_3_11, 0, 2, 0},
- /* 12 */ {2, s_3_12, 0, 1, 0}
-};
-
-static symbol s_4_0[2] = {'e', 'd'};
-static symbol s_4_1[3] = {'e', 'e', 'd'};
-static symbol s_4_2[3] = {'i', 'n', 'g'};
-static symbol s_4_3[4] = {'e', 'd', 'l', 'y'};
-static symbol s_4_4[5] = {'e', 'e', 'd', 'l', 'y'};
-static symbol s_4_5[5] = {'i', 'n', 'g', 'l', 'y'};
-
-static struct among a_4[6] =
-{
- /* 0 */ {2, s_4_0, -1, 2, 0},
- /* 1 */ {3, s_4_1, 0, 1, 0},
- /* 2 */ {3, s_4_2, -1, 2, 0},
- /* 3 */ {4, s_4_3, -1, 2, 0},
- /* 4 */ {5, s_4_4, 3, 1, 0},
- /* 5 */ {5, s_4_5, -1, 2, 0}
-};
-
-static symbol s_5_0[4] = {'a', 'n', 'c', 'i'};
-static symbol s_5_1[4] = {'e', 'n', 'c', 'i'};
-static symbol s_5_2[3] = {'o', 'g', 'i'};
-static symbol s_5_3[2] = {'l', 'i'};
-static symbol s_5_4[3] = {'b', 'l', 'i'};
-static symbol s_5_5[4] = {'a', 'b', 'l', 'i'};
-static symbol s_5_6[4] = {'a', 'l', 'l', 'i'};
-static symbol s_5_7[5] = {'f', 'u', 'l', 'l', 'i'};
-static symbol s_5_8[6] = {'l', 'e', 's', 's', 'l', 'i'};
-static symbol s_5_9[5] = {'o', 'u', 's', 'l', 'i'};
-static symbol s_5_10[5] = {'e', 'n', 't', 'l', 'i'};
-static symbol s_5_11[5] = {'a', 'l', 'i', 't', 'i'};
-static symbol s_5_12[6] = {'b', 'i', 'l', 'i', 't', 'i'};
-static symbol s_5_13[5] = {'i', 'v', 'i', 't', 'i'};
-static symbol s_5_14[6] = {'t', 'i', 'o', 'n', 'a', 'l'};
-static symbol s_5_15[7] = {'a', 't', 'i', 'o', 'n', 'a', 'l'};
-static symbol s_5_16[5] = {'a', 'l', 'i', 's', 'm'};
-static symbol s_5_17[5] = {'a', 't', 'i', 'o', 'n'};
-static symbol s_5_18[7] = {'i', 'z', 'a', 't', 'i', 'o', 'n'};
-static symbol s_5_19[4] = {'i', 'z', 'e', 'r'};
-static symbol s_5_20[4] = {'a', 't', 'o', 'r'};
-static symbol s_5_21[7] = {'i', 'v', 'e', 'n', 'e', 's', 's'};
-static symbol s_5_22[7] = {'f', 'u', 'l', 'n', 'e', 's', 's'};
-static symbol s_5_23[7] = {'o', 'u', 's', 'n', 'e', 's', 's'};
-
-static struct among a_5[24] =
-{
- /* 0 */ {4, s_5_0, -1, 3, 0},
- /* 1 */ {4, s_5_1, -1, 2, 0},
- /* 2 */ {3, s_5_2, -1, 13, 0},
- /* 3 */ {2, s_5_3, -1, 16, 0},
- /* 4 */ {3, s_5_4, 3, 12, 0},
- /* 5 */ {4, s_5_5, 4, 4, 0},
- /* 6 */ {4, s_5_6, 3, 8, 0},
- /* 7 */ {5, s_5_7, 3, 14, 0},
- /* 8 */ {6, s_5_8, 3, 15, 0},
- /* 9 */ {5, s_5_9, 3, 10, 0},
- /* 10 */ {5, s_5_10, 3, 5, 0},
- /* 11 */ {5, s_5_11, -1, 8, 0},
- /* 12 */ {6, s_5_12, -1, 12, 0},
- /* 13 */ {5, s_5_13, -1, 11, 0},
- /* 14 */ {6, s_5_14, -1, 1, 0},
- /* 15 */ {7, s_5_15, 14, 7, 0},
- /* 16 */ {5, s_5_16, -1, 8, 0},
- /* 17 */ {5, s_5_17, -1, 7, 0},
- /* 18 */ {7, s_5_18, 17, 6, 0},
- /* 19 */ {4, s_5_19, -1, 6, 0},
- /* 20 */ {4, s_5_20, -1, 7, 0},
- /* 21 */ {7, s_5_21, -1, 11, 0},
- /* 22 */ {7, s_5_22, -1, 9, 0},
- /* 23 */ {7, s_5_23, -1, 10, 0}
-};
-
-static symbol s_6_0[5] = {'i', 'c', 'a', 't', 'e'};
-static symbol s_6_1[5] = {'a', 't', 'i', 'v', 'e'};
-static symbol s_6_2[5] = {'a', 'l', 'i', 'z', 'e'};
-static symbol s_6_3[5] = {'i', 'c', 'i', 't', 'i'};
-static symbol s_6_4[4] = {'i', 'c', 'a', 'l'};
-static symbol s_6_5[6] = {'t', 'i', 'o', 'n', 'a', 'l'};
-static symbol s_6_6[7] = {'a', 't', 'i', 'o', 'n', 'a', 'l'};
-static symbol s_6_7[3] = {'f', 'u', 'l'};
-static symbol s_6_8[4] = {'n', 'e', 's', 's'};
-
-static struct among a_6[9] =
-{
- /* 0 */ {5, s_6_0, -1, 4, 0},
- /* 1 */ {5, s_6_1, -1, 6, 0},
- /* 2 */ {5, s_6_2, -1, 3, 0},
- /* 3 */ {5, s_6_3, -1, 4, 0},
- /* 4 */ {4, s_6_4, -1, 4, 0},
- /* 5 */ {6, s_6_5, -1, 1, 0},
- /* 6 */ {7, s_6_6, 5, 2, 0},
- /* 7 */ {3, s_6_7, -1, 5, 0},
- /* 8 */ {4, s_6_8, -1, 5, 0}
-};
-
-static symbol s_7_0[2] = {'i', 'c'};
-static symbol s_7_1[4] = {'a', 'n', 'c', 'e'};
-static symbol s_7_2[4] = {'e', 'n', 'c', 'e'};
-static symbol s_7_3[4] = {'a', 'b', 'l', 'e'};
-static symbol s_7_4[4] = {'i', 'b', 'l', 'e'};
-static symbol s_7_5[3] = {'a', 't', 'e'};
-static symbol s_7_6[3] = {'i', 'v', 'e'};
-static symbol s_7_7[3] = {'i', 'z', 'e'};
-static symbol s_7_8[3] = {'i', 't', 'i'};
-static symbol s_7_9[2] = {'a', 'l'};
-static symbol s_7_10[3] = {'i', 's', 'm'};
-static symbol s_7_11[3] = {'i', 'o', 'n'};
-static symbol s_7_12[2] = {'e', 'r'};
-static symbol s_7_13[3] = {'o', 'u', 's'};
-static symbol s_7_14[3] = {'a', 'n', 't'};
-static symbol s_7_15[3] = {'e', 'n', 't'};
-static symbol s_7_16[4] = {'m', 'e', 'n', 't'};
-static symbol s_7_17[5] = {'e', 'm', 'e', 'n', 't'};
-
-static struct among a_7[18] =
-{
- /* 0 */ {2, s_7_0, -1, 1, 0},
- /* 1 */ {4, s_7_1, -1, 1, 0},
- /* 2 */ {4, s_7_2, -1, 1, 0},
- /* 3 */ {4, s_7_3, -1, 1, 0},
- /* 4 */ {4, s_7_4, -1, 1, 0},
- /* 5 */ {3, s_7_5, -1, 1, 0},
- /* 6 */ {3, s_7_6, -1, 1, 0},
- /* 7 */ {3, s_7_7, -1, 1, 0},
- /* 8 */ {3, s_7_8, -1, 1, 0},
- /* 9 */ {2, s_7_9, -1, 1, 0},
- /* 10 */ {3, s_7_10, -1, 1, 0},
- /* 11 */ {3, s_7_11, -1, 2, 0},
- /* 12 */ {2, s_7_12, -1, 1, 0},
- /* 13 */ {3, s_7_13, -1, 1, 0},
- /* 14 */ {3, s_7_14, -1, 1, 0},
- /* 15 */ {3, s_7_15, -1, 1, 0},
- /* 16 */ {4, s_7_16, 15, 1, 0},
- /* 17 */ {5, s_7_17, 16, 1, 0}
-};
-
-static symbol s_8_0[1] = {'e'};
-static symbol s_8_1[1] = {'l'};
-
-static struct among a_8[2] =
-{
- /* 0 */ {1, s_8_0, -1, 1, 0},
- /* 1 */ {1, s_8_1, -1, 2, 0}
-};
-
-static symbol s_9_0[7] = {'s', 'u', 'c', 'c', 'e', 'e', 'd'};
-static symbol s_9_1[7] = {'p', 'r', 'o', 'c', 'e', 'e', 'd'};
-static symbol s_9_2[6] = {'e', 'x', 'c', 'e', 'e', 'd'};
-static symbol s_9_3[7] = {'c', 'a', 'n', 'n', 'i', 'n', 'g'};
-static symbol s_9_4[6] = {'i', 'n', 'n', 'i', 'n', 'g'};
-static symbol s_9_5[7] = {'e', 'a', 'r', 'r', 'i', 'n', 'g'};
-static symbol s_9_6[7] = {'h', 'e', 'r', 'r', 'i', 'n', 'g'};
-static symbol s_9_7[6] = {'o', 'u', 't', 'i', 'n', 'g'};
-
-static struct among a_9[8] =
-{
- /* 0 */ {7, s_9_0, -1, -1, 0},
- /* 1 */ {7, s_9_1, -1, -1, 0},
- /* 2 */ {6, s_9_2, -1, -1, 0},
- /* 3 */ {7, s_9_3, -1, -1, 0},
- /* 4 */ {6, s_9_4, -1, -1, 0},
- /* 5 */ {7, s_9_5, -1, -1, 0},
- /* 6 */ {7, s_9_6, -1, -1, 0},
- /* 7 */ {6, s_9_7, -1, -1, 0}
-};
-
-static symbol s_10_0[5] = {'a', 'n', 'd', 'e', 's'};
-static symbol s_10_1[5] = {'a', 't', 'l', 'a', 's'};
-static symbol s_10_2[4] = {'b', 'i', 'a', 's'};
-static symbol s_10_3[6] = {'c', 'o', 's', 'm', 'o', 's'};
-static symbol s_10_4[5] = {'d', 'y', 'i', 'n', 'g'};
-static symbol s_10_5[5] = {'e', 'a', 'r', 'l', 'y'};
-static symbol s_10_6[6] = {'g', 'e', 'n', 't', 'l', 'y'};
-static symbol s_10_7[4] = {'h', 'o', 'w', 'e'};
-static symbol s_10_8[4] = {'i', 'd', 'l', 'y'};
-static symbol s_10_9[5] = {'l', 'y', 'i', 'n', 'g'};
-static symbol s_10_10[4] = {'n', 'e', 'w', 's'};
-static symbol s_10_11[4] = {'o', 'n', 'l', 'y'};
-static symbol s_10_12[6] = {'s', 'i', 'n', 'g', 'l', 'y'};
-static symbol s_10_13[5] = {'s', 'k', 'i', 'e', 's'};
-static symbol s_10_14[4] = {'s', 'k', 'i', 's'};
-static symbol s_10_15[3] = {'s', 'k', 'y'};
-static symbol s_10_16[5] = {'t', 'y', 'i', 'n', 'g'};
-static symbol s_10_17[4] = {'u', 'g', 'l', 'y'};
-
-static struct among a_10[18] =
-{
- /* 0 */ {5, s_10_0, -1, -1, 0},
- /* 1 */ {5, s_10_1, -1, -1, 0},
- /* 2 */ {4, s_10_2, -1, -1, 0},
- /* 3 */ {6, s_10_3, -1, -1, 0},
- /* 4 */ {5, s_10_4, -1, 3, 0},
- /* 5 */ {5, s_10_5, -1, 9, 0},
- /* 6 */ {6, s_10_6, -1, 7, 0},
- /* 7 */ {4, s_10_7, -1, -1, 0},
- /* 8 */ {4, s_10_8, -1, 6, 0},
- /* 9 */ {5, s_10_9, -1, 4, 0},
- /* 10 */ {4, s_10_10, -1, -1, 0},
- /* 11 */ {4, s_10_11, -1, 10, 0},
- /* 12 */ {6, s_10_12, -1, 11, 0},
- /* 13 */ {5, s_10_13, -1, 2, 0},
- /* 14 */ {4, s_10_14, -1, 1, 0},
- /* 15 */ {3, s_10_15, -1, -1, 0},
- /* 16 */ {5, s_10_16, -1, 5, 0},
- /* 17 */ {4, s_10_17, -1, 8, 0}
-};
-
-static unsigned char g_v[] = {17, 65, 16, 1};
-
-static unsigned char g_v_WXY[] = {1, 17, 65, 208, 1};
-
-static unsigned char g_valid_LI[] = {55, 141, 2};
-
-static symbol s_0[] = {'\''};
-static symbol s_1[] = {'y'};
-static symbol s_2[] = {'Y'};
-static symbol s_3[] = {'y'};
-static symbol s_4[] = {'Y'};
-static symbol s_5[] = {'s', 's'};
-static symbol s_6[] = {'i', 'e'};
-static symbol s_7[] = {'i'};
-static symbol s_8[] = {'e', 'e'};
-static symbol s_9[] = {'e'};
-static symbol s_10[] = {'e'};
-static symbol s_11[] = {'y'};
-static symbol s_12[] = {'Y'};
-static symbol s_13[] = {'i'};
-static symbol s_14[] = {'t', 'i', 'o', 'n'};
-static symbol s_15[] = {'e', 'n', 'c', 'e'};
-static symbol s_16[] = {'a', 'n', 'c', 'e'};
-static symbol s_17[] = {'a', 'b', 'l', 'e'};
-static symbol s_18[] = {'e', 'n', 't'};
-static symbol s_19[] = {'i', 'z', 'e'};
-static symbol s_20[] = {'a', 't', 'e'};
-static symbol s_21[] = {'a', 'l'};
-static symbol s_22[] = {'f', 'u', 'l'};
-static symbol s_23[] = {'o', 'u', 's'};
-static symbol s_24[] = {'i', 'v', 'e'};
-static symbol s_25[] = {'b', 'l', 'e'};
-static symbol s_26[] = {'l'};
-static symbol s_27[] = {'o', 'g'};
-static symbol s_28[] = {'f', 'u', 'l'};
-static symbol s_29[] = {'l', 'e', 's', 's'};
-static symbol s_30[] = {'t', 'i', 'o', 'n'};
-static symbol s_31[] = {'a', 't', 'e'};
-static symbol s_32[] = {'a', 'l'};
-static symbol s_33[] = {'i', 'c'};
-static symbol s_34[] = {'s'};
-static symbol s_35[] = {'t'};
-static symbol s_36[] = {'l'};
-static symbol s_37[] = {'s', 'k', 'i'};
-static symbol s_38[] = {'s', 'k', 'y'};
-static symbol s_39[] = {'d', 'i', 'e'};
-static symbol s_40[] = {'l', 'i', 'e'};
-static symbol s_41[] = {'t', 'i', 'e'};
-static symbol s_42[] = {'i', 'd', 'l'};
-static symbol s_43[] = {'g', 'e', 'n', 't', 'l'};
-static symbol s_44[] = {'u', 'g', 'l', 'i'};
-static symbol s_45[] = {'e', 'a', 'r', 'l', 'i'};
-static symbol s_46[] = {'o', 'n', 'l', 'i'};
-static symbol s_47[] = {'s', 'i', 'n', 'g', 'l'};
-static symbol s_48[] = {'Y'};
-static symbol s_49[] = {'y'};
-
-static int
-r_prelude(struct SN_env * z)
-{
- z->B[0] = 0; /* unset Y_found, line 26 */
- {
- int c = z->c; /* do, line 27 */
-
- z->bra = z->c; /* [, line 27 */
- if (!(eq_s(z, 1, s_0)))
- goto lab0;
- z->ket = z->c; /* ], line 27 */
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 27 */
- if (ret < 0)
- return ret;
- }
-lab0:
- z->c = c;
- }
- {
- int c = z->c; /* do, line 28 */
-
- z->bra = z->c; /* [, line 28 */
- if (!(eq_s(z, 1, s_1)))
- goto lab1;
- z->ket = z->c; /* ], line 28 */
- if (!(in_grouping(z, g_v, 97, 121)))
- goto lab1;
- {
- int ret;
-
- ret = slice_from_s(z, 1, s_2); /* <-, line 28 */
- if (ret < 0)
- return ret;
- }
- z->B[0] = 1; /* set Y_found, line 28 */
-lab1:
- z->c = c;
- }
- {
- int c = z->c; /* do, line 29 */
-
- while (1)
- { /* repeat, line 29 */
- int c = z->c;
-
- while (1)
- { /* goto, line 29 */
- int c = z->c;
-
- if (!(in_grouping(z, g_v, 97, 121)))
- goto lab4;
- z->bra = z->c; /* [, line 29 */
- if (!(eq_s(z, 1, s_3)))
- goto lab4;
- z->ket = z->c; /* ], line 29 */
- z->c = c;
- break;
- lab4:
- z->c = c;
- if (z->c >= z->l)
- goto lab3;
- z->c++; /* goto, line 29 */
- }
- {
- int ret;
-
- ret = slice_from_s(z, 1, s_4); /* <-, line 29 */
- if (ret < 0)
- return ret;
- }
- z->B[0] = 1; /* set Y_found, line 29 */
- continue;
- lab3:
- z->c = c;
- break;
- }
- z->c = c;
- }
- return 1;
-}
-
-static int
-r_mark_regions(struct SN_env * z)
-{
- z->I[0] = z->l;
- z->I[1] = z->l;
- {
- int c = z->c; /* do, line 35 */
-
- {
- int c = z->c; /* or, line 40 */
-
- if (!(find_among(z, a_0, 2)))
- goto lab2; /* among, line 36 */
- goto lab1;
- lab2:
- z->c = c;
- while (1)
- { /* gopast, line 40 */
- if (!(in_grouping(z, g_v, 97, 121)))
- goto lab3;
- break;
- lab3:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 40 */
- }
- while (1)
- { /* gopast, line 40 */
- if (!(out_grouping(z, g_v, 97, 121)))
- goto lab4;
- break;
- lab4:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 40 */
- }
- }
-lab1:
- z->I[0] = z->c; /* setmark p1, line 41 */
- while (1)
- { /* gopast, line 42 */
- if (!(in_grouping(z, g_v, 97, 121)))
- goto lab5;
- break;
- lab5:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 42 */
- }
- while (1)
- { /* gopast, line 42 */
- if (!(out_grouping(z, g_v, 97, 121)))
- goto lab6;
- break;
- lab6:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 42 */
- }
- z->I[1] = z->c; /* setmark p2, line 42 */
-lab0:
- z->c = c;
- }
- return 1;
-}
-
-static int
-r_shortv(struct SN_env * z)
-{
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 50 */
- if (!(out_grouping_b(z, g_v_WXY, 89, 121)))
- goto lab1;
- if (!(in_grouping_b(z, g_v, 97, 121)))
- goto lab1;
- if (!(out_grouping_b(z, g_v, 97, 121)))
- goto lab1;
- goto lab0;
-lab1:
- z->c = z->l - m;
- if (!(out_grouping_b(z, g_v, 97, 121)))
- return 0;
- if (!(in_grouping_b(z, g_v, 97, 121)))
- return 0;
- if (z->c > z->lb)
- return 0; /* atlimit, line 51 */
- }
-lab0:
- return 1;
-}
-
-static int
-r_R1(struct SN_env * z)
-{
- if (!(z->I[0] <= z->c))
- return 0;
- return 1;
-}
-
-static int
-r_R2(struct SN_env * z)
-{
- if (!(z->I[1] <= z->c))
- return 0;
- return 1;
-}
-
-static int
-r_Step_1a(struct SN_env * z)
-{
- int among_var;
-
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 58 */
- z->ket = z->c; /* [, line 59 */
- among_var = find_among_b(z, a_1, 3); /* substring, line 59 */
- if (!(among_var))
- {
- z->c = z->l - m;
- goto lab0;
- }
- z->bra = z->c; /* ], line 59 */
- switch (among_var)
- {
- case 0:
- {
- z->c = z->l - m;
- goto lab0;
- }
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 61 */
- if (ret < 0)
- return ret;
- }
- break;
- }
-lab0:
- ;
- }
- z->ket = z->c; /* [, line 64 */
- among_var = find_among_b(z, a_2, 6); /* substring, line 64 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 64 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_5); /* <-, line 65 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 67 */
- if (z->c <= z->lb)
- goto lab2;
- z->c--; /* next, line 67 */
- if (z->c > z->lb)
- goto lab2; /* atlimit, line 67 */
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_6); /* <-, line 67 */
- if (ret < 0)
- return ret;
- }
- goto lab1;
- lab2:
- z->c = z->l - m;
- {
- int ret;
-
- ret = slice_from_s(z, 1, s_7); /* <-, line 67 */
- if (ret < 0)
- return ret;
- }
- }
- lab1:
- break;
- case 3:
- if (z->c <= z->lb)
- return 0;
- z->c--; /* next, line 68 */
- while (1)
- { /* gopast, line 68 */
- if (!(in_grouping_b(z, g_v, 97, 121)))
- goto lab3;
- break;
- lab3:
- if (z->c <= z->lb)
- return 0;
- z->c--; /* gopast, line 68 */
- }
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 68 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_Step_1b(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 74 */
- among_var = find_among_b(z, a_4, 6); /* substring, line 74 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 74 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret = r_R1(z);
-
- if (ret == 0)
- return 0; /* call R1, line 76 */
- if (ret < 0)
- return ret;
- }
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_8); /* <-, line 76 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int m_test = z->l - z->c; /* test, line 79 */
-
- while (1)
- { /* gopast, line 79 */
- if (!(in_grouping_b(z, g_v, 97, 121)))
- goto lab0;
- break;
- lab0:
- if (z->c <= z->lb)
- return 0;
- z->c--; /* gopast, line 79 */
- }
- z->c = z->l - m_test;
- }
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 79 */
- if (ret < 0)
- return ret;
- }
- {
- int m_test = z->l - z->c; /* test, line 80 */
-
- among_var = find_among_b(z, a_3, 13); /* substring, line 80 */
- if (!(among_var))
- return 0;
- z->c = z->l - m_test;
- }
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- {
- int c = z->c;
-
- ret = insert_s(z, z->c, z->c, 1, s_9); /* <+, line 82 */
- z->c = c;
- }
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- z->ket = z->c; /* [, line 85 */
- if (z->c <= z->lb)
- return 0;
- z->c--; /* next, line 85 */
- z->bra = z->c; /* ], line 85 */
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 85 */
- if (ret < 0)
- return ret;
- }
- break;
- case 3:
- if (z->c != z->I[0])
- return 0; /* atmark, line 86 */
- {
- int m_test = z->l - z->c; /* test, line 86 */
-
- {
- int ret = r_shortv(z);
-
- if (ret == 0)
- return 0; /* call shortv, line 86 */
- if (ret < 0)
- return ret;
- }
- z->c = z->l - m_test;
- }
- {
- int ret;
-
- {
- int c = z->c;
-
- ret = insert_s(z, z->c, z->c, 1, s_10); /* <+, line 86 */
- z->c = c;
- }
- if (ret < 0)
- return ret;
- }
- break;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_Step_1c(struct SN_env * z)
-{
- z->ket = z->c; /* [, line 93 */
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 93 */
- if (!(eq_s_b(z, 1, s_11)))
- goto lab1;
- goto lab0;
-lab1:
- z->c = z->l - m;
- if (!(eq_s_b(z, 1, s_12)))
- return 0;
- }
-lab0:
- z->bra = z->c; /* ], line 93 */
- if (!(out_grouping_b(z, g_v, 97, 121)))
- return 0;
- {
- int m = z->l - z->c;
-
- (void) m; /* not, line 94 */
- if (z->c > z->lb)
- goto lab2; /* atlimit, line 94 */
- return 0;
-lab2:
- z->c = z->l - m;
- }
- {
- int ret;
-
- ret = slice_from_s(z, 1, s_13); /* <-, line 95 */
- if (ret < 0)
- return ret;
- }
- return 1;
-}
-
-static int
-r_Step_2(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 99 */
- among_var = find_among_b(z, a_5, 24); /* substring, line 99 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 99 */
- {
- int ret = r_R1(z);
-
- if (ret == 0)
- return 0; /* call R1, line 99 */
- if (ret < 0)
- return ret;
- }
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_14); /* <-, line 100 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_15); /* <-, line 101 */
- if (ret < 0)
- return ret;
- }
- break;
- case 3:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_16); /* <-, line 102 */
- if (ret < 0)
- return ret;
- }
- break;
- case 4:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_17); /* <-, line 103 */
- if (ret < 0)
- return ret;
- }
- break;
- case 5:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_18); /* <-, line 104 */
- if (ret < 0)
- return ret;
- }
- break;
- case 6:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_19); /* <-, line 106 */
- if (ret < 0)
- return ret;
- }
- break;
- case 7:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_20); /* <-, line 108 */
- if (ret < 0)
- return ret;
- }
- break;
- case 8:
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_21); /* <-, line 110 */
- if (ret < 0)
- return ret;
- }
- break;
- case 9:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_22); /* <-, line 111 */
- if (ret < 0)
- return ret;
- }
- break;
- case 10:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_23); /* <-, line 113 */
- if (ret < 0)
- return ret;
- }
- break;
- case 11:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_24); /* <-, line 115 */
- if (ret < 0)
- return ret;
- }
- break;
- case 12:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_25); /* <-, line 117 */
- if (ret < 0)
- return ret;
- }
- break;
- case 13:
- if (!(eq_s_b(z, 1, s_26)))
- return 0;
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_27); /* <-, line 118 */
- if (ret < 0)
- return ret;
- }
- break;
- case 14:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_28); /* <-, line 119 */
- if (ret < 0)
- return ret;
- }
- break;
- case 15:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_29); /* <-, line 120 */
- if (ret < 0)
- return ret;
- }
- break;
- case 16:
- if (!(in_grouping_b(z, g_valid_LI, 99, 116)))
- return 0;
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 121 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_Step_3(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 126 */
- among_var = find_among_b(z, a_6, 9); /* substring, line 126 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 126 */
- {
- int ret = r_R1(z);
-
- if (ret == 0)
- return 0; /* call R1, line 126 */
- if (ret < 0)
- return ret;
- }
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_30); /* <-, line 127 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_31); /* <-, line 128 */
- if (ret < 0)
- return ret;
- }
- break;
- case 3:
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_32); /* <-, line 129 */
- if (ret < 0)
- return ret;
- }
- break;
- case 4:
- {
- int ret;
-
- ret = slice_from_s(z, 2, s_33); /* <-, line 131 */
- if (ret < 0)
- return ret;
- }
- break;
- case 5:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 133 */
- if (ret < 0)
- return ret;
- }
- break;
- case 6:
- {
- int ret = r_R2(z);
-
- if (ret == 0)
- return 0; /* call R2, line 135 */
- if (ret < 0)
- return ret;
- }
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 135 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_Step_4(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 140 */
- among_var = find_among_b(z, a_7, 18); /* substring, line 140 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 140 */
- {
- int ret = r_R2(z);
-
- if (ret == 0)
- return 0; /* call R2, line 140 */
- if (ret < 0)
- return ret;
- }
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 143 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 144 */
- if (!(eq_s_b(z, 1, s_34)))
- goto lab1;
- goto lab0;
- lab1:
- z->c = z->l - m;
- if (!(eq_s_b(z, 1, s_35)))
- return 0;
- }
- lab0:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 144 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_Step_5(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 149 */
- among_var = find_among_b(z, a_8, 2); /* substring, line 149 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 149 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 150 */
- {
- int ret = r_R2(z);
-
- if (ret == 0)
- goto lab1; /* call R2, line 150 */
- if (ret < 0)
- return ret;
- }
- goto lab0;
- lab1:
- z->c = z->l - m;
- {
- int ret = r_R1(z);
-
- if (ret == 0)
- return 0; /* call R1, line 150 */
- if (ret < 0)
- return ret;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* not, line 150 */
- {
- int ret = r_shortv(z);
-
- if (ret == 0)
- goto lab2; /* call shortv, line 150 */
- if (ret < 0)
- return ret;
- }
- return 0;
- lab2:
- z->c = z->l - m;
- }
- }
- lab0:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 150 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret = r_R2(z);
-
- if (ret == 0)
- return 0; /* call R2, line 151 */
- if (ret < 0)
- return ret;
- }
- if (!(eq_s_b(z, 1, s_36)))
- return 0;
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 151 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_exception2(struct SN_env * z)
-{
- z->ket = z->c; /* [, line 157 */
- if (!(find_among_b(z, a_9, 8)))
- return 0; /* substring, line 157 */
- z->bra = z->c; /* ], line 157 */
- if (z->c > z->lb)
- return 0; /* atlimit, line 157 */
- return 1;
-}
-
-static int
-r_exception1(struct SN_env * z)
-{
- int among_var;
-
- z->bra = z->c; /* [, line 169 */
- among_var = find_among(z, a_10, 18); /* substring, line 169 */
- if (!(among_var))
- return 0;
- z->ket = z->c; /* ], line 169 */
- if (z->c < z->l)
- return 0; /* atlimit, line 169 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_37); /* <-, line 173 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_38); /* <-, line 174 */
- if (ret < 0)
- return ret;
- }
- break;
- case 3:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_39); /* <-, line 175 */
- if (ret < 0)
- return ret;
- }
- break;
- case 4:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_40); /* <-, line 176 */
- if (ret < 0)
- return ret;
- }
- break;
- case 5:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_41); /* <-, line 177 */
- if (ret < 0)
- return ret;
- }
- break;
- case 6:
- {
- int ret;
-
- ret = slice_from_s(z, 3, s_42); /* <-, line 181 */
- if (ret < 0)
- return ret;
- }
- break;
- case 7:
- {
- int ret;
-
- ret = slice_from_s(z, 5, s_43); /* <-, line 182 */
- if (ret < 0)
- return ret;
- }
- break;
- case 8:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_44); /* <-, line 183 */
- if (ret < 0)
- return ret;
- }
- break;
- case 9:
- {
- int ret;
-
- ret = slice_from_s(z, 5, s_45); /* <-, line 184 */
- if (ret < 0)
- return ret;
- }
- break;
- case 10:
- {
- int ret;
-
- ret = slice_from_s(z, 4, s_46); /* <-, line 185 */
- if (ret < 0)
- return ret;
- }
- break;
- case 11:
- {
- int ret;
-
- ret = slice_from_s(z, 5, s_47); /* <-, line 186 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_postlude(struct SN_env * z)
-{
- if (!(z->B[0]))
- return 0; /* Boolean test Y_found, line 202 */
- while (1)
- { /* repeat, line 202 */
- int c = z->c;
-
- while (1)
- { /* goto, line 202 */
- int c = z->c;
-
- z->bra = z->c; /* [, line 202 */
- if (!(eq_s(z, 1, s_48)))
- goto lab1;
- z->ket = z->c; /* ], line 202 */
- z->c = c;
- break;
- lab1:
- z->c = c;
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* goto, line 202 */
- }
- {
- int ret;
-
- ret = slice_from_s(z, 1, s_49); /* <-, line 202 */
- if (ret < 0)
- return ret;
- }
- continue;
-lab0:
- z->c = c;
- break;
- }
- return 1;
-}
-
-extern int
-english_ISO_8859_1_stem(struct SN_env * z)
-{
- {
- int c = z->c; /* or, line 206 */
-
- {
- int ret = r_exception1(z);
-
- if (ret == 0)
- goto lab1; /* call exception1, line 206 */
- if (ret < 0)
- return ret;
- }
- goto lab0;
-lab1:
- z->c = c;
- {
- int c = z->c; /* not, line 207 */
-
- {
- int c = z->c + 3;
-
- if (0 > c || c > z->l)
- goto lab3;
- z->c = c; /* hop, line 207 */
- }
- goto lab2;
- lab3:
- z->c = c;
- }
- goto lab0;
-lab2:
- z->c = c;
- {
- int c = z->c; /* do, line 208 */
-
- {
- int ret = r_prelude(z);
-
- if (ret == 0)
- goto lab4; /* call prelude, line 208 */
- if (ret < 0)
- return ret;
- }
- lab4:
- z->c = c;
- }
- {
- int c = z->c; /* do, line 209 */
-
- {
- int ret = r_mark_regions(z);
-
- if (ret == 0)
- goto lab5; /* call mark_regions, line 209 */
- if (ret < 0)
- return ret;
- }
- lab5:
- z->c = c;
- }
- z->lb = z->c;
- z->c = z->l; /* backwards, line 210 */
-
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 212 */
- {
- int ret = r_Step_1a(z);
-
- if (ret == 0)
- goto lab6; /* call Step_1a, line 212 */
- if (ret < 0)
- return ret;
- }
- lab6:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 214 */
- {
- int ret = r_exception2(z);
-
- if (ret == 0)
- goto lab8; /* call exception2, line 214 */
- if (ret < 0)
- return ret;
- }
- goto lab7;
- lab8:
- z->c = z->l - m;
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 216 */
- {
- int ret = r_Step_1b(z);
-
- if (ret == 0)
- goto lab9; /* call Step_1b, line 216 */
- if (ret < 0)
- return ret;
- }
- lab9:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 217 */
- {
- int ret = r_Step_1c(z);
-
- if (ret == 0)
- goto lab10; /* call Step_1c, line 217 */
- if (ret < 0)
- return ret;
- }
- lab10:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 219 */
- {
- int ret = r_Step_2(z);
-
- if (ret == 0)
- goto lab11; /* call Step_2, line 219 */
- if (ret < 0)
- return ret;
- }
- lab11:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 220 */
- {
- int ret = r_Step_3(z);
-
- if (ret == 0)
- goto lab12; /* call Step_3, line 220 */
- if (ret < 0)
- return ret;
- }
- lab12:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 221 */
- {
- int ret = r_Step_4(z);
-
- if (ret == 0)
- goto lab13; /* call Step_4, line 221 */
- if (ret < 0)
- return ret;
- }
- lab13:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 223 */
- {
- int ret = r_Step_5(z);
-
- if (ret == 0)
- goto lab14; /* call Step_5, line 223 */
- if (ret < 0)
- return ret;
- }
- lab14:
- z->c = z->l - m;
- }
- }
-lab7:
- z->c = z->lb;
- {
- int c = z->c; /* do, line 226 */
-
- {
- int ret = r_postlude(z);
-
- if (ret == 0)
- goto lab15; /* call postlude, line 226 */
- if (ret < 0)
- return ret;
- }
- lab15:
- z->c = c;
- }
- }
-lab0:
- return 1;
-}
-
-extern struct SN_env *
-english_ISO_8859_1_create_env(void)
-{
- return SN_create_env(0, 2, 1);
-}
-
-extern void
-english_ISO_8859_1_close_env(struct SN_env * z)
-{
- SN_close_env(z);
-}
+++ /dev/null
-/* $PostgreSQL: pgsql/contrib/tsearch2/snowball/english_stem.h,v 1.6 2006/03/11 04:38:30 momjian Exp $ */
-
-/* This file was generated automatically by the Snowball to ANSI C compiler */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-extern struct SN_env *english_ISO_8859_1_create_env(void);
-extern void english_ISO_8859_1_close_env(struct SN_env * z);
-
-extern int english_ISO_8859_1_stem(struct SN_env * z);
-
-#ifdef __cplusplus
-}
-
-#endif
+++ /dev/null
-/* $PostgreSQL: pgsql/contrib/tsearch2/snowball/header.h,v 1.8 2006/07/10 22:06:11 momjian Exp $ */
-
-#include
-
-#include "api.h"
-
-#define HEAD (2 * sizeof(int))
-
-#define SIZE(p) ((int *)(p))[-1]
-#define SET_SIZE(p, n) ((int *)(p))[-1] = n
-#define CAPACITY(p) ((int *)(p))[-2]
-
-struct among
-{
- int s_size; /* number of chars in string */
- symbol *s; /* search string */
- int substring_i; /* index to longest matching substring */
- int result; /* result of the lookup */
- int (*function) (struct SN_env *);
-};
-
-extern symbol *create_s(void);
-extern void lose_s(symbol * p);
-
-extern int skip_utf8(const symbol * p, int c, int lb, int l, int n);
-
-extern int in_grouping_U(struct SN_env * z, unsigned char *s, int min, int max);
-extern int in_grouping_b_U(struct SN_env * z, unsigned char *s, int min, int max);
-extern int out_grouping_U(struct SN_env * z, unsigned char *s, int min, int max);
-extern int out_grouping_b_U(struct SN_env * z, unsigned char *s, int min, int max);
-
-extern int in_grouping(struct SN_env * z, unsigned char *s, int min, int max);
-extern int in_grouping_b(struct SN_env * z, unsigned char *s, int min, int max);
-extern int out_grouping(struct SN_env * z, unsigned char *s, int min, int max);
-extern int out_grouping_b(struct SN_env * z, unsigned char *s, int min, int max);
-
-extern int eq_s(struct SN_env * z, int s_size, symbol * s);
-extern int eq_s_b(struct SN_env * z, int s_size, symbol * s);
-extern int eq_v(struct SN_env * z, symbol * p);
-extern int eq_v_b(struct SN_env * z, symbol * p);
-
-extern int find_among(struct SN_env * z, struct among * v, int v_size);
-extern int find_among_b(struct SN_env * z, struct among * v, int v_size);
-
-extern int replace_s(struct SN_env * z, int c_bra, int c_ket, int s_size, const symbol * s, int *adjustment);
-extern int slice_from_s(struct SN_env * z, int s_size, symbol * s);
-extern int slice_from_v(struct SN_env * z, symbol * p);
-extern int slice_del(struct SN_env * z);
-
-extern int insert_s(struct SN_env * z, int bra, int ket, int s_size, symbol * s);
-extern int insert_v(struct SN_env * z, int bra, int ket, symbol * p);
-
-extern symbol *slice_to(struct SN_env * z, symbol * p);
-extern symbol *assign_to(struct SN_env * z, symbol * p);
-
-extern void debug(struct SN_env * z, int number, int line_count);
+++ /dev/null
-
-/* This file was generated automatically by the Snowball to ANSI C compiler */
-
-#include "header.h"
-
-extern int russian_KOI8_R_stem(struct SN_env * z);
-static int r_tidy_up(struct SN_env * z);
-static int r_derivational(struct SN_env * z);
-static int r_noun(struct SN_env * z);
-static int r_verb(struct SN_env * z);
-static int r_reflexive(struct SN_env * z);
-static int r_adjectival(struct SN_env * z);
-static int r_adjective(struct SN_env * z);
-static int r_perfective_gerund(struct SN_env * z);
-static int r_R2(struct SN_env * z);
-static int r_mark_regions(struct SN_env * z);
-
-extern struct SN_env *russian_KOI8_R_create_env(void);
-extern void russian_KOI8_R_close_env(struct SN_env * z);
-
-static symbol s_0_0[3] = {0xD7, 0xDB, 0xC9};
-static symbol s_0_1[4] = {0xC9, 0xD7, 0xDB, 0xC9};
-static symbol s_0_2[4] = {0xD9, 0xD7, 0xDB, 0xC9};
-static symbol s_0_3[1] = {0xD7};
-static symbol s_0_4[2] = {0xC9, 0xD7};
-static symbol s_0_5[2] = {0xD9, 0xD7};
-static symbol s_0_6[5] = {0xD7, 0xDB, 0xC9, 0xD3, 0xD8};
-static symbol s_0_7[6] = {0xC9, 0xD7, 0xDB, 0xC9, 0xD3, 0xD8};
-static symbol s_0_8[6] = {0xD9, 0xD7, 0xDB, 0xC9, 0xD3, 0xD8};
-
-static struct among a_0[9] =
-{
- /* 0 */ {3, s_0_0, -1, 1, 0},
- /* 1 */ {4, s_0_1, 0, 2, 0},
- /* 2 */ {4, s_0_2, 0, 2, 0},
- /* 3 */ {1, s_0_3, -1, 1, 0},
- /* 4 */ {2, s_0_4, 3, 2, 0},
- /* 5 */ {2, s_0_5, 3, 2, 0},
- /* 6 */ {5, s_0_6, -1, 1, 0},
- /* 7 */ {6, s_0_7, 6, 2, 0},
- /* 8 */ {6, s_0_8, 6, 2, 0}
-};
-
-static symbol s_1_0[2] = {0xC0, 0xC0};
-static symbol s_1_1[2] = {0xC5, 0xC0};
-static symbol s_1_2[2] = {0xCF, 0xC0};
-static symbol s_1_3[2] = {0xD5, 0xC0};
-static symbol s_1_4[2] = {0xC5, 0xC5};
-static symbol s_1_5[2] = {0xC9, 0xC5};
-static symbol s_1_6[2] = {0xCF, 0xC5};
-static symbol s_1_7[2] = {0xD9, 0xC5};
-static symbol s_1_8[2] = {0xC9, 0xC8};
-static symbol s_1_9[2] = {0xD9, 0xC8};
-static symbol s_1_10[3] = {0xC9, 0xCD, 0xC9};
-static symbol s_1_11[3] = {0xD9, 0xCD, 0xC9};
-static symbol s_1_12[2] = {0xC5, 0xCA};
-static symbol s_1_13[2] = {0xC9, 0xCA};
-static symbol s_1_14[2] = {0xCF, 0xCA};
-static symbol s_1_15[2] = {0xD9, 0xCA};
-static symbol s_1_16[2] = {0xC5, 0xCD};
-static symbol s_1_17[2] = {0xC9, 0xCD};
-static symbol s_1_18[2] = {0xCF, 0xCD};
-static symbol s_1_19[2] = {0xD9, 0xCD};
-static symbol s_1_20[3] = {0xC5, 0xC7, 0xCF};
-static symbol s_1_21[3] = {0xCF, 0xC7, 0xCF};
-static symbol s_1_22[2] = {0xC1, 0xD1};
-static symbol s_1_23[2] = {0xD1, 0xD1};
-static symbol s_1_24[3] = {0xC5, 0xCD, 0xD5};
-static symbol s_1_25[3] = {0xCF, 0xCD, 0xD5};
-
-static struct among a_1[26] =
-{
- /* 0 */ {2, s_1_0, -1, 1, 0},
- /* 1 */ {2, s_1_1, -1, 1, 0},
- /* 2 */ {2, s_1_2, -1, 1, 0},
- /* 3 */ {2, s_1_3, -1, 1, 0},
- /* 4 */ {2, s_1_4, -1, 1, 0},
- /* 5 */ {2, s_1_5, -1, 1, 0},
- /* 6 */ {2, s_1_6, -1, 1, 0},
- /* 7 */ {2, s_1_7, -1, 1, 0},
- /* 8 */ {2, s_1_8, -1, 1, 0},
- /* 9 */ {2, s_1_9, -1, 1, 0},
- /* 10 */ {3, s_1_10, -1, 1, 0},
- /* 11 */ {3, s_1_11, -1, 1, 0},
- /* 12 */ {2, s_1_12, -1, 1, 0},
- /* 13 */ {2, s_1_13, -1, 1, 0},
- /* 14 */ {2, s_1_14, -1, 1, 0},
- /* 15 */ {2, s_1_15, -1, 1, 0},
- /* 16 */ {2, s_1_16, -1, 1, 0},
- /* 17 */ {2, s_1_17, -1, 1, 0},
- /* 18 */ {2, s_1_18, -1, 1, 0},
- /* 19 */ {2, s_1_19, -1, 1, 0},
- /* 20 */ {3, s_1_20, -1, 1, 0},
- /* 21 */ {3, s_1_21, -1, 1, 0},
- /* 22 */ {2, s_1_22, -1, 1, 0},
- /* 23 */ {2, s_1_23, -1, 1, 0},
- /* 24 */ {3, s_1_24, -1, 1, 0},
- /* 25 */ {3, s_1_25, -1, 1, 0}
-};
-
-static symbol s_2_0[2] = {0xC5, 0xCD};
-static symbol s_2_1[2] = {0xCE, 0xCE};
-static symbol s_2_2[2] = {0xD7, 0xDB};
-static symbol s_2_3[3] = {0xC9, 0xD7, 0xDB};
-static symbol s_2_4[3] = {0xD9, 0xD7, 0xDB};
-static symbol s_2_5[1] = {0xDD};
-static symbol s_2_6[2] = {0xC0, 0xDD};
-static symbol s_2_7[3] = {0xD5, 0xC0, 0xDD};
-
-static struct among a_2[8] =
-{
- /* 0 */ {2, s_2_0, -1, 1, 0},
- /* 1 */ {2, s_2_1, -1, 1, 0},
- /* 2 */ {2, s_2_2, -1, 1, 0},
- /* 3 */ {3, s_2_3, 2, 2, 0},
- /* 4 */ {3, s_2_4, 2, 2, 0},
- /* 5 */ {1, s_2_5, -1, 1, 0},
- /* 6 */ {2, s_2_6, 5, 1, 0},
- /* 7 */ {3, s_2_7, 6, 2, 0}
-};
-
-static symbol s_3_0[2] = {0xD3, 0xD1};
-static symbol s_3_1[2] = {0xD3, 0xD8};
-
-static struct among a_3[2] =
-{
- /* 0 */ {2, s_3_0, -1, 1, 0},
- /* 1 */ {2, s_3_1, -1, 1, 0}
-};
-
-static symbol s_4_0[1] = {0xC0};
-static symbol s_4_1[2] = {0xD5, 0xC0};
-static symbol s_4_2[2] = {0xCC, 0xC1};
-static symbol s_4_3[3] = {0xC9, 0xCC, 0xC1};
-static symbol s_4_4[3] = {0xD9, 0xCC, 0xC1};
-static symbol s_4_5[2] = {0xCE, 0xC1};
-static symbol s_4_6[3] = {0xC5, 0xCE, 0xC1};
-static symbol s_4_7[3] = {0xC5, 0xD4, 0xC5};
-static symbol s_4_8[3] = {0xC9, 0xD4, 0xC5};
-static symbol s_4_9[3] = {0xCA, 0xD4, 0xC5};
-static symbol s_4_10[4] = {0xC5, 0xCA, 0xD4, 0xC5};
-static symbol s_4_11[4] = {0xD5, 0xCA, 0xD4, 0xC5};
-static symbol s_4_12[2] = {0xCC, 0xC9};
-static symbol s_4_13[3] = {0xC9, 0xCC, 0xC9};
-static symbol s_4_14[3] = {0xD9, 0xCC, 0xC9};
-static symbol s_4_15[1] = {0xCA};
-static symbol s_4_16[2] = {0xC5, 0xCA};
-static symbol s_4_17[2] = {0xD5, 0xCA};
-static symbol s_4_18[1] = {0xCC};
-static symbol s_4_19[2] = {0xC9, 0xCC};
-static symbol s_4_20[2] = {0xD9, 0xCC};
-static symbol s_4_21[2] = {0xC5, 0xCD};
-static symbol s_4_22[2] = {0xC9, 0xCD};
-static symbol s_4_23[2] = {0xD9, 0xCD};
-static symbol s_4_24[1] = {0xCE};
-static symbol s_4_25[2] = {0xC5, 0xCE};
-static symbol s_4_26[2] = {0xCC, 0xCF};
-static symbol s_4_27[3] = {0xC9, 0xCC, 0xCF};
-static symbol s_4_28[3] = {0xD9, 0xCC, 0xCF};
-static symbol s_4_29[2] = {0xCE, 0xCF};
-static symbol s_4_30[3] = {0xC5, 0xCE, 0xCF};
-static symbol s_4_31[3] = {0xCE, 0xCE, 0xCF};
-static symbol s_4_32[2] = {0xC0, 0xD4};
-static symbol s_4_33[3] = {0xD5, 0xC0, 0xD4};
-static symbol s_4_34[2] = {0xC5, 0xD4};
-static symbol s_4_35[3] = {0xD5, 0xC5, 0xD4};
-static symbol s_4_36[2] = {0xC9, 0xD4};
-static symbol s_4_37[2] = {0xD1, 0xD4};
-static symbol s_4_38[2] = {0xD9, 0xD4};
-static symbol s_4_39[2] = {0xD4, 0xD8};
-static symbol s_4_40[3] = {0xC9, 0xD4, 0xD8};
-static symbol s_4_41[3] = {0xD9, 0xD4, 0xD8};
-static symbol s_4_42[3] = {0xC5, 0xDB, 0xD8};
-static symbol s_4_43[3] = {0xC9, 0xDB, 0xD8};
-static symbol s_4_44[2] = {0xCE, 0xD9};
-static symbol s_4_45[3] = {0xC5, 0xCE, 0xD9};
-
-static struct among a_4[46] =
-{
- /* 0 */ {1, s_4_0, -1, 2, 0},
- /* 1 */ {2, s_4_1, 0, 2, 0},
- /* 2 */ {2, s_4_2, -1, 1, 0},
- /* 3 */ {3, s_4_3, 2, 2, 0},
- /* 4 */ {3, s_4_4, 2, 2, 0},
- /* 5 */ {2, s_4_5, -1, 1, 0},
- /* 6 */ {3, s_4_6, 5, 2, 0},
- /* 7 */ {3, s_4_7, -1, 1, 0},
- /* 8 */ {3, s_4_8, -1, 2, 0},
- /* 9 */ {3, s_4_9, -1, 1, 0},
- /* 10 */ {4, s_4_10, 9, 2, 0},
- /* 11 */ {4, s_4_11, 9, 2, 0},
- /* 12 */ {2, s_4_12, -1, 1, 0},
- /* 13 */ {3, s_4_13, 12, 2, 0},
- /* 14 */ {3, s_4_14, 12, 2, 0},
- /* 15 */ {1, s_4_15, -1, 1, 0},
- /* 16 */ {2, s_4_16, 15, 2, 0},
- /* 17 */ {2, s_4_17, 15, 2, 0},
- /* 18 */ {1, s_4_18, -1, 1, 0},
- /* 19 */ {2, s_4_19, 18, 2, 0},
- /* 20 */ {2, s_4_20, 18, 2, 0},
- /* 21 */ {2, s_4_21, -1, 1, 0},
- /* 22 */ {2, s_4_22, -1, 2, 0},
- /* 23 */ {2, s_4_23, -1, 2, 0},
- /* 24 */ {1, s_4_24, -1, 1, 0},
- /* 25 */ {2, s_4_25, 24, 2, 0},
- /* 26 */ {2, s_4_26, -1, 1, 0},
- /* 27 */ {3, s_4_27, 26, 2, 0},
- /* 28 */ {3, s_4_28, 26, 2, 0},
- /* 29 */ {2, s_4_29, -1, 1, 0},
- /* 30 */ {3, s_4_30, 29, 2, 0},
- /* 31 */ {3, s_4_31, 29, 1, 0},
- /* 32 */ {2, s_4_32, -1, 1, 0},
- /* 33 */ {3, s_4_33, 32, 2, 0},
- /* 34 */ {2, s_4_34, -1, 1, 0},
- /* 35 */ {3, s_4_35, 34, 2, 0},
- /* 36 */ {2, s_4_36, -1, 2, 0},
- /* 37 */ {2, s_4_37, -1, 2, 0},
- /* 38 */ {2, s_4_38, -1, 2, 0},
- /* 39 */ {2, s_4_39, -1, 1, 0},
- /* 40 */ {3, s_4_40, 39, 2, 0},
- /* 41 */ {3, s_4_41, 39, 2, 0},
- /* 42 */ {3, s_4_42, -1, 1, 0},
- /* 43 */ {3, s_4_43, -1, 2, 0},
- /* 44 */ {2, s_4_44, -1, 1, 0},
- /* 45 */ {3, s_4_45, 44, 2, 0}
-};
-
-static symbol s_5_0[1] = {0xC0};
-static symbol s_5_1[2] = {0xC9, 0xC0};
-static symbol s_5_2[2] = {0xD8, 0xC0};
-static symbol s_5_3[1] = {0xC1};
-static symbol s_5_4[1] = {0xC5};
-static symbol s_5_5[2] = {0xC9, 0xC5};
-static symbol s_5_6[2] = {0xD8, 0xC5};
-static symbol s_5_7[2] = {0xC1, 0xC8};
-static symbol s_5_8[2] = {0xD1, 0xC8};
-static symbol s_5_9[3] = {0xC9, 0xD1, 0xC8};
-static symbol s_5_10[1] = {0xC9};
-static symbol s_5_11[2] = {0xC5, 0xC9};
-static symbol s_5_12[2] = {0xC9, 0xC9};
-static symbol s_5_13[3] = {0xC1, 0xCD, 0xC9};
-static symbol s_5_14[3] = {0xD1, 0xCD, 0xC9};
-static symbol s_5_15[4] = {0xC9, 0xD1, 0xCD, 0xC9};
-static symbol s_5_16[1] = {0xCA};
-static symbol s_5_17[2] = {0xC5, 0xCA};
-static symbol s_5_18[3] = {0xC9, 0xC5, 0xCA};
-static symbol s_5_19[2] = {0xC9, 0xCA};
-static symbol s_5_20[2] = {0xCF, 0xCA};
-static symbol s_5_21[2] = {0xC1, 0xCD};
-static symbol s_5_22[2] = {0xC5, 0xCD};
-static symbol s_5_23[3] = {0xC9, 0xC5, 0xCD};
-static symbol s_5_24[2] = {0xCF, 0xCD};
-static symbol s_5_25[2] = {0xD1, 0xCD};
-static symbol s_5_26[3] = {0xC9, 0xD1, 0xCD};
-static symbol s_5_27[1] = {0xCF};
-static symbol s_5_28[1] = {0xD1};
-static symbol s_5_29[2] = {0xC9, 0xD1};
-static symbol s_5_30[2] = {0xD8, 0xD1};
-static symbol s_5_31[1] = {0xD5};
-static symbol s_5_32[2] = {0xC5, 0xD7};
-static symbol s_5_33[2] = {0xCF, 0xD7};
-static symbol s_5_34[1] = {0xD8};
-static symbol s_5_35[1] = {0xD9};
-
-static struct among a_5[36] =
-{
- /* 0 */ {1, s_5_0, -1, 1, 0},
- /* 1 */ {2, s_5_1, 0, 1, 0},
- /* 2 */ {2, s_5_2, 0, 1, 0},
- /* 3 */ {1, s_5_3, -1, 1, 0},
- /* 4 */ {1, s_5_4, -1, 1, 0},
- /* 5 */ {2, s_5_5, 4, 1, 0},
- /* 6 */ {2, s_5_6, 4, 1, 0},
- /* 7 */ {2, s_5_7, -1, 1, 0},
- /* 8 */ {2, s_5_8, -1, 1, 0},
- /* 9 */ {3, s_5_9, 8, 1, 0},
- /* 10 */ {1, s_5_10, -1, 1, 0},
- /* 11 */ {2, s_5_11, 10, 1, 0},
- /* 12 */ {2, s_5_12, 10, 1, 0},
- /* 13 */ {3, s_5_13, 10, 1, 0},
- /* 14 */ {3, s_5_14, 10, 1, 0},
- /* 15 */ {4, s_5_15, 14, 1, 0},
- /* 16 */ {1, s_5_16, -1, 1, 0},
- /* 17 */ {2, s_5_17, 16, 1, 0},
- /* 18 */ {3, s_5_18, 17, 1, 0},
- /* 19 */ {2, s_5_19, 16, 1, 0},
- /* 20 */ {2, s_5_20, 16, 1, 0},
- /* 21 */ {2, s_5_21, -1, 1, 0},
- /* 22 */ {2, s_5_22, -1, 1, 0},
- /* 23 */ {3, s_5_23, 22, 1, 0},
- /* 24 */ {2, s_5_24, -1, 1, 0},
- /* 25 */ {2, s_5_25, -1, 1, 0},
- /* 26 */ {3, s_5_26, 25, 1, 0},
- /* 27 */ {1, s_5_27, -1, 1, 0},
- /* 28 */ {1, s_5_28, -1, 1, 0},
- /* 29 */ {2, s_5_29, 28, 1, 0},
- /* 30 */ {2, s_5_30, 28, 1, 0},
- /* 31 */ {1, s_5_31, -1, 1, 0},
- /* 32 */ {2, s_5_32, -1, 1, 0},
- /* 33 */ {2, s_5_33, -1, 1, 0},
- /* 34 */ {1, s_5_34, -1, 1, 0},
- /* 35 */ {1, s_5_35, -1, 1, 0}
-};
-
-static symbol s_6_0[3] = {0xCF, 0xD3, 0xD4};
-static symbol s_6_1[4] = {0xCF, 0xD3, 0xD4, 0xD8};
-
-static struct among a_6[2] =
-{
- /* 0 */ {3, s_6_0, -1, 1, 0},
- /* 1 */ {4, s_6_1, -1, 1, 0}
-};
-
-static symbol s_7_0[4] = {0xC5, 0xCA, 0xDB, 0xC5};
-static symbol s_7_1[1] = {0xCE};
-static symbol s_7_2[1] = {0xD8};
-static symbol s_7_3[3] = {0xC5, 0xCA, 0xDB};
-
-static struct among a_7[4] =
-{
- /* 0 */ {4, s_7_0, -1, 1, 0},
- /* 1 */ {1, s_7_1, -1, 2, 0},
- /* 2 */ {1, s_7_2, -1, 3, 0},
- /* 3 */ {3, s_7_3, -1, 1, 0}
-};
-
-static unsigned char g_v[] = {35, 130, 34, 18};
-
-static symbol s_0[] = {0xC1};
-static symbol s_1[] = {0xD1};
-static symbol s_2[] = {0xC1};
-static symbol s_3[] = {0xD1};
-static symbol s_4[] = {0xC1};
-static symbol s_5[] = {0xD1};
-static symbol s_6[] = {0xCE};
-static symbol s_7[] = {0xCE};
-static symbol s_8[] = {0xCE};
-static symbol s_9[] = {0xC9};
-
-static int
-r_mark_regions(struct SN_env * z)
-{
- z->I[0] = z->l;
- z->I[1] = z->l;
- {
- int c = z->c; /* do, line 63 */
-
- while (1)
- { /* gopast, line 64 */
- if (!(in_grouping(z, g_v, 192, 220)))
- goto lab1;
- break;
- lab1:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 64 */
- }
- z->I[0] = z->c; /* setmark pV, line 64 */
- while (1)
- { /* gopast, line 64 */
- if (!(out_grouping(z, g_v, 192, 220)))
- goto lab2;
- break;
- lab2:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 64 */
- }
- while (1)
- { /* gopast, line 65 */
- if (!(in_grouping(z, g_v, 192, 220)))
- goto lab3;
- break;
- lab3:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 65 */
- }
- while (1)
- { /* gopast, line 65 */
- if (!(out_grouping(z, g_v, 192, 220)))
- goto lab4;
- break;
- lab4:
- if (z->c >= z->l)
- goto lab0;
- z->c++; /* gopast, line 65 */
- }
- z->I[1] = z->c; /* setmark p2, line 65 */
-lab0:
- z->c = c;
- }
- return 1;
-}
-
-static int
-r_R2(struct SN_env * z)
-{
- if (!(z->I[1] <= z->c))
- return 0;
- return 1;
-}
-
-static int
-r_perfective_gerund(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 74 */
- among_var = find_among_b(z, a_0, 9); /* substring, line 74 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 74 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 78 */
- if (!(eq_s_b(z, 1, s_0)))
- goto lab1;
- goto lab0;
- lab1:
- z->c = z->l - m;
- if (!(eq_s_b(z, 1, s_1)))
- return 0;
- }
- lab0:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 78 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 85 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_adjective(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 90 */
- among_var = find_among_b(z, a_1, 26); /* substring, line 90 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 90 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 99 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_adjectival(struct SN_env * z)
-{
- int among_var;
-
- {
- int ret = r_adjective(z);
-
- if (ret == 0)
- return 0; /* call adjective, line 104 */
- if (ret < 0)
- return ret;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 111 */
- z->ket = z->c; /* [, line 112 */
- among_var = find_among_b(z, a_2, 8); /* substring, line 112 */
- if (!(among_var))
- {
- z->c = z->l - m;
- goto lab0;
- }
- z->bra = z->c; /* ], line 112 */
- switch (among_var)
- {
- case 0:
- {
- z->c = z->l - m;
- goto lab0;
- }
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 117 */
- if (!(eq_s_b(z, 1, s_2)))
- goto lab2;
- goto lab1;
- lab2:
- z->c = z->l - m;
- if (!(eq_s_b(z, 1, s_3)))
- {
- z->c = z->l - m;
- goto lab0;
- }
- }
- lab1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 117 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 124 */
- if (ret < 0)
- return ret;
- }
- break;
- }
-lab0:
- ;
- }
- return 1;
-}
-
-static int
-r_reflexive(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 131 */
- among_var = find_among_b(z, a_3, 2); /* substring, line 131 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 131 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 134 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_verb(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 139 */
- among_var = find_among_b(z, a_4, 46); /* substring, line 139 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 139 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 145 */
- if (!(eq_s_b(z, 1, s_4)))
- goto lab1;
- goto lab0;
- lab1:
- z->c = z->l - m;
- if (!(eq_s_b(z, 1, s_5)))
- return 0;
- }
- lab0:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 145 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 153 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_noun(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 162 */
- among_var = find_among_b(z, a_5, 36); /* substring, line 162 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 162 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 169 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_derivational(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 178 */
- among_var = find_among_b(z, a_6, 2); /* substring, line 178 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 178 */
- {
- int ret = r_R2(z);
-
- if (ret == 0)
- return 0; /* call R2, line 178 */
- if (ret < 0)
- return ret;
- }
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 181 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_tidy_up(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 186 */
- among_var = find_among_b(z, a_7, 4); /* substring, line 186 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 186 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 190 */
- if (ret < 0)
- return ret;
- }
- z->ket = z->c; /* [, line 191 */
- if (!(eq_s_b(z, 1, s_6)))
- return 0;
- z->bra = z->c; /* ], line 191 */
- if (!(eq_s_b(z, 1, s_7)))
- return 0;
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 191 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- if (!(eq_s_b(z, 1, s_8)))
- return 0;
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 194 */
- if (ret < 0)
- return ret;
- }
- break;
- case 3:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 196 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-extern int
-russian_KOI8_R_stem(struct SN_env * z)
-{
- {
- int c = z->c; /* do, line 203 */
-
- {
- int ret = r_mark_regions(z);
-
- if (ret == 0)
- goto lab0; /* call mark_regions, line 203 */
- if (ret < 0)
- return ret;
- }
-lab0:
- z->c = c;
- }
- z->lb = z->c;
- z->c = z->l; /* backwards, line 204 */
-
- {
- int m3; /* setlimit, line 204 */
- int m = z->l - z->c;
-
- (void) m;
- if (z->c < z->I[0])
- return 0;
- z->c = z->I[0]; /* tomark, line 204 */
- m3 = z->lb;
- z->lb = z->c;
- z->c = z->l - m;
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 205 */
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 206 */
- {
- int ret = r_perfective_gerund(z);
-
- if (ret == 0)
- goto lab3; /* call perfective_gerund, line 206 */
- if (ret < 0)
- return ret;
- }
- goto lab2;
- lab3:
- z->c = z->l - m;
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 207 */
- {
- int ret = r_reflexive(z);
-
- if (ret == 0)
- {
- z->c = z->l - m;
- goto lab4;
- } /* call reflexive, line 207 */
- if (ret < 0)
- return ret;
- }
- lab4:
- ;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 208 */
- {
- int ret = r_adjectival(z);
-
- if (ret == 0)
- goto lab6; /* call adjectival, line 208 */
- if (ret < 0)
- return ret;
- }
- goto lab5;
- lab6:
- z->c = z->l - m;
- {
- int ret = r_verb(z);
-
- if (ret == 0)
- goto lab7; /* call verb, line 208 */
- if (ret < 0)
- return ret;
- }
- goto lab5;
- lab7:
- z->c = z->l - m;
- {
- int ret = r_noun(z);
-
- if (ret == 0)
- goto lab1; /* call noun, line 208 */
- if (ret < 0)
- return ret;
- }
- }
- lab5:
- ;
- }
- lab2:
- lab1:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 211 */
- z->ket = z->c; /* [, line 211 */
- if (!(eq_s_b(z, 1, s_9)))
- {
- z->c = z->l - m;
- goto lab8;
- }
- z->bra = z->c; /* ], line 211 */
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 211 */
- if (ret < 0)
- return ret;
- }
- lab8:
- ;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 214 */
- {
- int ret = r_derivational(z);
-
- if (ret == 0)
- goto lab9; /* call derivational, line 214 */
- if (ret < 0)
- return ret;
- }
- lab9:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 215 */
- {
- int ret = r_tidy_up(z);
-
- if (ret == 0)
- goto lab10; /* call tidy_up, line 215 */
- if (ret < 0)
- return ret;
- }
- lab10:
- z->c = z->l - m;
- }
- z->lb = m3;
- }
- z->c = z->lb;
- return 1;
-}
-
-extern struct SN_env *
-russian_KOI8_R_create_env(void)
-{
- return SN_create_env(0, 2, 0);
-}
-
-extern void
-russian_KOI8_R_close_env(struct SN_env * z)
-{
- SN_close_env(z);
-}
+++ /dev/null
-
-/* This file was generated automatically by the Snowball to ANSI C compiler */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-extern struct SN_env *russian_KOI8_R_create_env(void);
-extern void russian_KOI8_R_close_env(struct SN_env * z);
-
-extern int russian_KOI8_R_stem(struct SN_env * z);
-
-#ifdef __cplusplus
-}
-
-#endif
+++ /dev/null
-
-/* This file was generated automatically by the Snowball to ANSI C compiler */
-
-#include "header.h"
-
-extern int russian_UTF_8_stem(struct SN_env * z);
-static int r_tidy_up(struct SN_env * z);
-static int r_derivational(struct SN_env * z);
-static int r_noun(struct SN_env * z);
-static int r_verb(struct SN_env * z);
-static int r_reflexive(struct SN_env * z);
-static int r_adjectival(struct SN_env * z);
-static int r_adjective(struct SN_env * z);
-static int r_perfective_gerund(struct SN_env * z);
-static int r_R2(struct SN_env * z);
-static int r_mark_regions(struct SN_env * z);
-
-extern struct SN_env *russian_UTF_8_create_env(void);
-extern void russian_UTF_8_close_env(struct SN_env * z);
-
-static symbol s_0_0[10] = {0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C};
-static symbol s_0_1[12] = {0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C};
-static symbol s_0_2[12] = {0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C};
-static symbol s_0_3[2] = {0xD0, 0xB2};
-static symbol s_0_4[4] = {0xD1, 0x8B, 0xD0, 0xB2};
-static symbol s_0_5[4] = {0xD0, 0xB8, 0xD0, 0xB2};
-static symbol s_0_6[6] = {0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8};
-static symbol s_0_7[8] = {0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8};
-static symbol s_0_8[8] = {0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8};
-
-static struct among a_0[9] =
-{
- /* 0 */ {10, s_0_0, -1, 1, 0},
- /* 1 */ {12, s_0_1, 0, 2, 0},
- /* 2 */ {12, s_0_2, 0, 2, 0},
- /* 3 */ {2, s_0_3, -1, 1, 0},
- /* 4 */ {4, s_0_4, 3, 2, 0},
- /* 5 */ {4, s_0_5, 3, 2, 0},
- /* 6 */ {6, s_0_6, -1, 1, 0},
- /* 7 */ {8, s_0_7, 6, 2, 0},
- /* 8 */ {8, s_0_8, 6, 2, 0}
-};
-
-static symbol s_1_0[6] = {0xD0, 0xB5, 0xD0, 0xBC, 0xD1, 0x83};
-static symbol s_1_1[6] = {0xD0, 0xBE, 0xD0, 0xBC, 0xD1, 0x83};
-static symbol s_1_2[4] = {0xD1, 0x8B, 0xD1, 0x85};
-static symbol s_1_3[4] = {0xD0, 0xB8, 0xD1, 0x85};
-static symbol s_1_4[4] = {0xD1, 0x83, 0xD1, 0x8E};
-static symbol s_1_5[4] = {0xD1, 0x8E, 0xD1, 0x8E};
-static symbol s_1_6[4] = {0xD0, 0xB5, 0xD1, 0x8E};
-static symbol s_1_7[4] = {0xD0, 0xBE, 0xD1, 0x8E};
-static symbol s_1_8[4] = {0xD1, 0x8F, 0xD1, 0x8F};
-static symbol s_1_9[4] = {0xD0, 0xB0, 0xD1, 0x8F};
-static symbol s_1_10[4] = {0xD1, 0x8B, 0xD0, 0xB5};
-static symbol s_1_11[4] = {0xD0, 0xB5, 0xD0, 0xB5};
-static symbol s_1_12[4] = {0xD0, 0xB8, 0xD0, 0xB5};
-static symbol s_1_13[4] = {0xD0, 0xBE, 0xD0, 0xB5};
-static symbol s_1_14[6] = {0xD1, 0x8B, 0xD0, 0xBC, 0xD0, 0xB8};
-static symbol s_1_15[6] = {0xD0, 0xB8, 0xD0, 0xBC, 0xD0, 0xB8};
-static symbol s_1_16[4] = {0xD1, 0x8B, 0xD0, 0xB9};
-static symbol s_1_17[4] = {0xD0, 0xB5, 0xD0, 0xB9};
-static symbol s_1_18[4] = {0xD0, 0xB8, 0xD0, 0xB9};
-static symbol s_1_19[4] = {0xD0, 0xBE, 0xD0, 0xB9};
-static symbol s_1_20[4] = {0xD1, 0x8B, 0xD0, 0xBC};
-static symbol s_1_21[4] = {0xD0, 0xB5, 0xD0, 0xBC};
-static symbol s_1_22[4] = {0xD0, 0xB8, 0xD0, 0xBC};
-static symbol s_1_23[4] = {0xD0, 0xBE, 0xD0, 0xBC};
-static symbol s_1_24[6] = {0xD0, 0xB5, 0xD0, 0xB3, 0xD0, 0xBE};
-static symbol s_1_25[6] = {0xD0, 0xBE, 0xD0, 0xB3, 0xD0, 0xBE};
-
-static struct among a_1[26] =
-{
- /* 0 */ {6, s_1_0, -1, 1, 0},
- /* 1 */ {6, s_1_1, -1, 1, 0},
- /* 2 */ {4, s_1_2, -1, 1, 0},
- /* 3 */ {4, s_1_3, -1, 1, 0},
- /* 4 */ {4, s_1_4, -1, 1, 0},
- /* 5 */ {4, s_1_5, -1, 1, 0},
- /* 6 */ {4, s_1_6, -1, 1, 0},
- /* 7 */ {4, s_1_7, -1, 1, 0},
- /* 8 */ {4, s_1_8, -1, 1, 0},
- /* 9 */ {4, s_1_9, -1, 1, 0},
- /* 10 */ {4, s_1_10, -1, 1, 0},
- /* 11 */ {4, s_1_11, -1, 1, 0},
- /* 12 */ {4, s_1_12, -1, 1, 0},
- /* 13 */ {4, s_1_13, -1, 1, 0},
- /* 14 */ {6, s_1_14, -1, 1, 0},
- /* 15 */ {6, s_1_15, -1, 1, 0},
- /* 16 */ {4, s_1_16, -1, 1, 0},
- /* 17 */ {4, s_1_17, -1, 1, 0},
- /* 18 */ {4, s_1_18, -1, 1, 0},
- /* 19 */ {4, s_1_19, -1, 1, 0},
- /* 20 */ {4, s_1_20, -1, 1, 0},
- /* 21 */ {4, s_1_21, -1, 1, 0},
- /* 22 */ {4, s_1_22, -1, 1, 0},
- /* 23 */ {4, s_1_23, -1, 1, 0},
- /* 24 */ {6, s_1_24, -1, 1, 0},
- /* 25 */ {6, s_1_25, -1, 1, 0}
-};
-
-static symbol s_2_0[4] = {0xD0, 0xB2, 0xD1, 0x88};
-static symbol s_2_1[6] = {0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88};
-static symbol s_2_2[6] = {0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88};
-static symbol s_2_3[2] = {0xD1, 0x89};
-static symbol s_2_4[4] = {0xD1, 0x8E, 0xD1, 0x89};
-static symbol s_2_5[6] = {0xD1, 0x83, 0xD1, 0x8E, 0xD1, 0x89};
-static symbol s_2_6[4] = {0xD0, 0xB5, 0xD0, 0xBC};
-static symbol s_2_7[4] = {0xD0, 0xBD, 0xD0, 0xBD};
-
-static struct among a_2[8] =
-{
- /* 0 */ {4, s_2_0, -1, 1, 0},
- /* 1 */ {6, s_2_1, 0, 2, 0},
- /* 2 */ {6, s_2_2, 0, 2, 0},
- /* 3 */ {2, s_2_3, -1, 1, 0},
- /* 4 */ {4, s_2_4, 3, 1, 0},
- /* 5 */ {6, s_2_5, 4, 2, 0},
- /* 6 */ {4, s_2_6, -1, 1, 0},
- /* 7 */ {4, s_2_7, -1, 1, 0}
-};
-
-static symbol s_3_0[4] = {0xD1, 0x81, 0xD1, 0x8C};
-static symbol s_3_1[4] = {0xD1, 0x81, 0xD1, 0x8F};
-
-static struct among a_3[2] =
-{
- /* 0 */ {4, s_3_0, -1, 1, 0},
- /* 1 */ {4, s_3_1, -1, 1, 0}
-};
-
-static symbol s_4_0[4] = {0xD1, 0x8B, 0xD1, 0x82};
-static symbol s_4_1[4] = {0xD1, 0x8E, 0xD1, 0x82};
-static symbol s_4_2[6] = {0xD1, 0x83, 0xD1, 0x8E, 0xD1, 0x82};
-static symbol s_4_3[4] = {0xD1, 0x8F, 0xD1, 0x82};
-static symbol s_4_4[4] = {0xD0, 0xB5, 0xD1, 0x82};
-static symbol s_4_5[6] = {0xD1, 0x83, 0xD0, 0xB5, 0xD1, 0x82};
-static symbol s_4_6[4] = {0xD0, 0xB8, 0xD1, 0x82};
-static symbol s_4_7[4] = {0xD0, 0xBD, 0xD1, 0x8B};
-static symbol s_4_8[6] = {0xD0, 0xB5, 0xD0, 0xBD, 0xD1, 0x8B};
-static symbol s_4_9[4] = {0xD1, 0x82, 0xD1, 0x8C};
-static symbol s_4_10[6] = {0xD1, 0x8B, 0xD1, 0x82, 0xD1, 0x8C};
-static symbol s_4_11[6] = {0xD0, 0xB8, 0xD1, 0x82, 0xD1, 0x8C};
-static symbol s_4_12[6] = {0xD0, 0xB5, 0xD1, 0x88, 0xD1, 0x8C};
-static symbol s_4_13[6] = {0xD0, 0xB8, 0xD1, 0x88, 0xD1, 0x8C};
-static symbol s_4_14[2] = {0xD1, 0x8E};
-static symbol s_4_15[4] = {0xD1, 0x83, 0xD1, 0x8E};
-static symbol s_4_16[4] = {0xD0, 0xBB, 0xD0, 0xB0};
-static symbol s_4_17[6] = {0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xB0};
-static symbol s_4_18[6] = {0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xB0};
-static symbol s_4_19[4] = {0xD0, 0xBD, 0xD0, 0xB0};
-static symbol s_4_20[6] = {0xD0, 0xB5, 0xD0, 0xBD, 0xD0, 0xB0};
-static symbol s_4_21[6] = {0xD0, 0xB5, 0xD1, 0x82, 0xD0, 0xB5};
-static symbol s_4_22[6] = {0xD0, 0xB8, 0xD1, 0x82, 0xD0, 0xB5};
-static symbol s_4_23[6] = {0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5};
-static symbol s_4_24[8] = {0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5};
-static symbol s_4_25[8] = {0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5};
-static symbol s_4_26[4] = {0xD0, 0xBB, 0xD0, 0xB8};
-static symbol s_4_27[6] = {0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xB8};
-static symbol s_4_28[6] = {0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xB8};
-static symbol s_4_29[2] = {0xD0, 0xB9};
-static symbol s_4_30[4] = {0xD1, 0x83, 0xD0, 0xB9};
-static symbol s_4_31[4] = {0xD0, 0xB5, 0xD0, 0xB9};
-static symbol s_4_32[2] = {0xD0, 0xBB};
-static symbol s_4_33[4] = {0xD1, 0x8B, 0xD0, 0xBB};
-static symbol s_4_34[4] = {0xD0, 0xB8, 0xD0, 0xBB};
-static symbol s_4_35[4] = {0xD1, 0x8B, 0xD0, 0xBC};
-static symbol s_4_36[4] = {0xD0, 0xB5, 0xD0, 0xBC};
-static symbol s_4_37[4] = {0xD0, 0xB8, 0xD0, 0xBC};
-static symbol s_4_38[2] = {0xD0, 0xBD};
-static symbol s_4_39[4] = {0xD0, 0xB5, 0xD0, 0xBD};
-static symbol s_4_40[4] = {0xD0, 0xBB, 0xD0, 0xBE};
-static symbol s_4_41[6] = {0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xBE};
-static symbol s_4_42[6] = {0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xBE};
-static symbol s_4_43[4] = {0xD0, 0xBD, 0xD0, 0xBE};
-static symbol s_4_44[6] = {0xD0, 0xB5, 0xD0, 0xBD, 0xD0, 0xBE};
-static symbol s_4_45[6] = {0xD0, 0xBD, 0xD0, 0xBD, 0xD0, 0xBE};
-
-static struct among a_4[46] =
-{
- /* 0 */ {4, s_4_0, -1, 2, 0},
- /* 1 */ {4, s_4_1, -1, 1, 0},
- /* 2 */ {6, s_4_2, 1, 2, 0},
- /* 3 */ {4, s_4_3, -1, 2, 0},
- /* 4 */ {4, s_4_4, -1, 1, 0},
- /* 5 */ {6, s_4_5, 4, 2, 0},
- /* 6 */ {4, s_4_6, -1, 2, 0},
- /* 7 */ {4, s_4_7, -1, 1, 0},
- /* 8 */ {6, s_4_8, 7, 2, 0},
- /* 9 */ {4, s_4_9, -1, 1, 0},
- /* 10 */ {6, s_4_10, 9, 2, 0},
- /* 11 */ {6, s_4_11, 9, 2, 0},
- /* 12 */ {6, s_4_12, -1, 1, 0},
- /* 13 */ {6, s_4_13, -1, 2, 0},
- /* 14 */ {2, s_4_14, -1, 2, 0},
- /* 15 */ {4, s_4_15, 14, 2, 0},
- /* 16 */ {4, s_4_16, -1, 1, 0},
- /* 17 */ {6, s_4_17, 16, 2, 0},
- /* 18 */ {6, s_4_18, 16, 2, 0},
- /* 19 */ {4, s_4_19, -1, 1, 0},
- /* 20 */ {6, s_4_20, 19, 2, 0},
- /* 21 */ {6, s_4_21, -1, 1, 0},
- /* 22 */ {6, s_4_22, -1, 2, 0},
- /* 23 */ {6, s_4_23, -1, 1, 0},
- /* 24 */ {8, s_4_24, 23, 2, 0},
- /* 25 */ {8, s_4_25, 23, 2, 0},
- /* 26 */ {4, s_4_26, -1, 1, 0},
- /* 27 */ {6, s_4_27, 26, 2, 0},
- /* 28 */ {6, s_4_28, 26, 2, 0},
- /* 29 */ {2, s_4_29, -1, 1, 0},
- /* 30 */ {4, s_4_30, 29, 2, 0},
- /* 31 */ {4, s_4_31, 29, 2, 0},
- /* 32 */ {2, s_4_32, -1, 1, 0},
- /* 33 */ {4, s_4_33, 32, 2, 0},
- /* 34 */ {4, s_4_34, 32, 2, 0},
- /* 35 */ {4, s_4_35, -1, 2, 0},
- /* 36 */ {4, s_4_36, -1, 1, 0},
- /* 37 */ {4, s_4_37, -1, 2, 0},
- /* 38 */ {2, s_4_38, -1, 1, 0},
- /* 39 */ {4, s_4_39, 38, 2, 0},
- /* 40 */ {4, s_4_40, -1, 1, 0},
- /* 41 */ {6, s_4_41, 40, 2, 0},
- /* 42 */ {6, s_4_42, 40, 2, 0},
- /* 43 */ {4, s_4_43, -1, 1, 0},
- /* 44 */ {6, s_4_44, 43, 2, 0},
- /* 45 */ {6, s_4_45, 43, 1, 0}
-};
-
-static symbol s_5_0[2] = {0xD1, 0x83};
-static symbol s_5_1[4] = {0xD1, 0x8F, 0xD1, 0x85};
-static symbol s_5_2[6] = {0xD0, 0xB8, 0xD1, 0x8F, 0xD1, 0x85};
-static symbol s_5_3[4] = {0xD0, 0xB0, 0xD1, 0x85};
-static symbol s_5_4[2] = {0xD1, 0x8B};
-static symbol s_5_5[2] = {0xD1, 0x8C};
-static symbol s_5_6[2] = {0xD1, 0x8E};
-static symbol s_5_7[4] = {0xD1, 0x8C, 0xD1, 0x8E};
-static symbol s_5_8[4] = {0xD0, 0xB8, 0xD1, 0x8E};
-static symbol s_5_9[2] = {0xD1, 0x8F};
-static symbol s_5_10[4] = {0xD1, 0x8C, 0xD1, 0x8F};
-static symbol s_5_11[4] = {0xD0, 0xB8, 0xD1, 0x8F};
-static symbol s_5_12[2] = {0xD0, 0xB0};
-static symbol s_5_13[4] = {0xD0, 0xB5, 0xD0, 0xB2};
-static symbol s_5_14[4] = {0xD0, 0xBE, 0xD0, 0xB2};
-static symbol s_5_15[2] = {0xD0, 0xB5};
-static symbol s_5_16[4] = {0xD1, 0x8C, 0xD0, 0xB5};
-static symbol s_5_17[4] = {0xD0, 0xB8, 0xD0, 0xB5};
-static symbol s_5_18[2] = {0xD0, 0xB8};
-static symbol s_5_19[4] = {0xD0, 0xB5, 0xD0, 0xB8};
-static symbol s_5_20[4] = {0xD0, 0xB8, 0xD0, 0xB8};
-static symbol s_5_21[6] = {0xD1, 0x8F, 0xD0, 0xBC, 0xD0, 0xB8};
-static symbol s_5_22[8] = {0xD0, 0xB8, 0xD1, 0x8F, 0xD0, 0xBC, 0xD0, 0xB8};
-static symbol s_5_23[6] = {0xD0, 0xB0, 0xD0, 0xBC, 0xD0, 0xB8};
-static symbol s_5_24[2] = {0xD0, 0xB9};
-static symbol s_5_25[4] = {0xD0, 0xB5, 0xD0, 0xB9};
-static symbol s_5_26[6] = {0xD0, 0xB8, 0xD0, 0xB5, 0xD0, 0xB9};
-static symbol s_5_27[4] = {0xD0, 0xB8, 0xD0, 0xB9};
-static symbol s_5_28[4] = {0xD0, 0xBE, 0xD0, 0xB9};
-static symbol s_5_29[4] = {0xD1, 0x8F, 0xD0, 0xBC};
-static symbol s_5_30[6] = {0xD0, 0xB8, 0xD1, 0x8F, 0xD0, 0xBC};
-static symbol s_5_31[4] = {0xD0, 0xB0, 0xD0, 0xBC};
-static symbol s_5_32[4] = {0xD0, 0xB5, 0xD0, 0xBC};
-static symbol s_5_33[6] = {0xD0, 0xB8, 0xD0, 0xB5, 0xD0, 0xBC};
-static symbol s_5_34[4] = {0xD0, 0xBE, 0xD0, 0xBC};
-static symbol s_5_35[2] = {0xD0, 0xBE};
-
-static struct among a_5[36] =
-{
- /* 0 */ {2, s_5_0, -1, 1, 0},
- /* 1 */ {4, s_5_1, -1, 1, 0},
- /* 2 */ {6, s_5_2, 1, 1, 0},
- /* 3 */ {4, s_5_3, -1, 1, 0},
- /* 4 */ {2, s_5_4, -1, 1, 0},
- /* 5 */ {2, s_5_5, -1, 1, 0},
- /* 6 */ {2, s_5_6, -1, 1, 0},
- /* 7 */ {4, s_5_7, 6, 1, 0},
- /* 8 */ {4, s_5_8, 6, 1, 0},
- /* 9 */ {2, s_5_9, -1, 1, 0},
- /* 10 */ {4, s_5_10, 9, 1, 0},
- /* 11 */ {4, s_5_11, 9, 1, 0},
- /* 12 */ {2, s_5_12, -1, 1, 0},
- /* 13 */ {4, s_5_13, -1, 1, 0},
- /* 14 */ {4, s_5_14, -1, 1, 0},
- /* 15 */ {2, s_5_15, -1, 1, 0},
- /* 16 */ {4, s_5_16, 15, 1, 0},
- /* 17 */ {4, s_5_17, 15, 1, 0},
- /* 18 */ {2, s_5_18, -1, 1, 0},
- /* 19 */ {4, s_5_19, 18, 1, 0},
- /* 20 */ {4, s_5_20, 18, 1, 0},
- /* 21 */ {6, s_5_21, 18, 1, 0},
- /* 22 */ {8, s_5_22, 21, 1, 0},
- /* 23 */ {6, s_5_23, 18, 1, 0},
- /* 24 */ {2, s_5_24, -1, 1, 0},
- /* 25 */ {4, s_5_25, 24, 1, 0},
- /* 26 */ {6, s_5_26, 25, 1, 0},
- /* 27 */ {4, s_5_27, 24, 1, 0},
- /* 28 */ {4, s_5_28, 24, 1, 0},
- /* 29 */ {4, s_5_29, -1, 1, 0},
- /* 30 */ {6, s_5_30, 29, 1, 0},
- /* 31 */ {4, s_5_31, -1, 1, 0},
- /* 32 */ {4, s_5_32, -1, 1, 0},
- /* 33 */ {6, s_5_33, 32, 1, 0},
- /* 34 */ {4, s_5_34, -1, 1, 0},
- /* 35 */ {2, s_5_35, -1, 1, 0}
-};
-
-static symbol s_6_0[6] = {0xD0, 0xBE, 0xD1, 0x81, 0xD1, 0x82};
-static symbol s_6_1[8] = {0xD0, 0xBE, 0xD1, 0x81, 0xD1, 0x82, 0xD1, 0x8C};
-
-static struct among a_6[2] =
-{
- /* 0 */ {6, s_6_0, -1, 1, 0},
- /* 1 */ {8, s_6_1, -1, 1, 0}
-};
-
-static symbol s_7_0[6] = {0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x88};
-static symbol s_7_1[2] = {0xD1, 0x8C};
-static symbol s_7_2[8] = {0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x88, 0xD0, 0xB5};
-static symbol s_7_3[2] = {0xD0, 0xBD};
-
-static struct among a_7[4] =
-{
- /* 0 */ {6, s_7_0, -1, 1, 0},
- /* 1 */ {2, s_7_1, -1, 3, 0},
- /* 2 */ {8, s_7_2, -1, 1, 0},
- /* 3 */ {2, s_7_3, -1, 2, 0}
-};
-
-static unsigned char g_v[] = {33, 65, 8, 232};
-
-static symbol s_0[] = {0xD0, 0xB0};
-static symbol s_1[] = {0xD1, 0x8F};
-static symbol s_2[] = {0xD0, 0xB0};
-static symbol s_3[] = {0xD1, 0x8F};
-static symbol s_4[] = {0xD0, 0xB0};
-static symbol s_5[] = {0xD1, 0x8F};
-static symbol s_6[] = {0xD0, 0xBD};
-static symbol s_7[] = {0xD0, 0xBD};
-static symbol s_8[] = {0xD0, 0xBD};
-static symbol s_9[] = {0xD0, 0xB8};
-
-static int
-r_mark_regions(struct SN_env * z)
-{
- z->I[0] = z->l;
- z->I[1] = z->l;
- {
- int c = z->c; /* do, line 61 */
-
- while (1)
- { /* gopast, line 62 */
- if (!(in_grouping_U(z, g_v, 1072, 1103)))
- goto lab1;
- break;
- lab1:
- {
- int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-
- if (c < 0)
- goto lab0;
- z->c = c; /* gopast, line 62 */
- }
- }
- z->I[0] = z->c; /* setmark pV, line 62 */
- while (1)
- { /* gopast, line 62 */
- if (!(out_grouping_U(z, g_v, 1072, 1103)))
- goto lab2;
- break;
- lab2:
- {
- int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-
- if (c < 0)
- goto lab0;
- z->c = c; /* gopast, line 62 */
- }
- }
- while (1)
- { /* gopast, line 63 */
- if (!(in_grouping_U(z, g_v, 1072, 1103)))
- goto lab3;
- break;
- lab3:
- {
- int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-
- if (c < 0)
- goto lab0;
- z->c = c; /* gopast, line 63 */
- }
- }
- while (1)
- { /* gopast, line 63 */
- if (!(out_grouping_U(z, g_v, 1072, 1103)))
- goto lab4;
- break;
- lab4:
- {
- int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-
- if (c < 0)
- goto lab0;
- z->c = c; /* gopast, line 63 */
- }
- }
- z->I[1] = z->c; /* setmark p2, line 63 */
-lab0:
- z->c = c;
- }
- return 1;
-}
-
-static int
-r_R2(struct SN_env * z)
-{
- if (!(z->I[1] <= z->c))
- return 0;
- return 1;
-}
-
-static int
-r_perfective_gerund(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 72 */
- among_var = find_among_b(z, a_0, 9); /* substring, line 72 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 72 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 76 */
- if (!(eq_s_b(z, 2, s_0)))
- goto lab1;
- goto lab0;
- lab1:
- z->c = z->l - m;
- if (!(eq_s_b(z, 2, s_1)))
- return 0;
- }
- lab0:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 76 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 83 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_adjective(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 88 */
- among_var = find_among_b(z, a_1, 26); /* substring, line 88 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 88 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 97 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_adjectival(struct SN_env * z)
-{
- int among_var;
-
- {
- int ret = r_adjective(z);
-
- if (ret == 0)
- return 0; /* call adjective, line 102 */
- if (ret < 0)
- return ret;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 109 */
- z->ket = z->c; /* [, line 110 */
- among_var = find_among_b(z, a_2, 8); /* substring, line 110 */
- if (!(among_var))
- {
- z->c = z->l - m;
- goto lab0;
- }
- z->bra = z->c; /* ], line 110 */
- switch (among_var)
- {
- case 0:
- {
- z->c = z->l - m;
- goto lab0;
- }
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 115 */
- if (!(eq_s_b(z, 2, s_2)))
- goto lab2;
- goto lab1;
- lab2:
- z->c = z->l - m;
- if (!(eq_s_b(z, 2, s_3)))
- {
- z->c = z->l - m;
- goto lab0;
- }
- }
- lab1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 115 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 122 */
- if (ret < 0)
- return ret;
- }
- break;
- }
-lab0:
- ;
- }
- return 1;
-}
-
-static int
-r_reflexive(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 129 */
- among_var = find_among_b(z, a_3, 2); /* substring, line 129 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 129 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 132 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_verb(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 137 */
- among_var = find_among_b(z, a_4, 46); /* substring, line 137 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 137 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 143 */
- if (!(eq_s_b(z, 2, s_4)))
- goto lab1;
- goto lab0;
- lab1:
- z->c = z->l - m;
- if (!(eq_s_b(z, 2, s_5)))
- return 0;
- }
- lab0:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 143 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 151 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_noun(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 160 */
- among_var = find_among_b(z, a_5, 36); /* substring, line 160 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 160 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 167 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_derivational(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 176 */
- among_var = find_among_b(z, a_6, 2); /* substring, line 176 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 176 */
- {
- int ret = r_R2(z);
-
- if (ret == 0)
- return 0; /* call R2, line 176 */
- if (ret < 0)
- return ret;
- }
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 179 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-static int
-r_tidy_up(struct SN_env * z)
-{
- int among_var;
-
- z->ket = z->c; /* [, line 184 */
- among_var = find_among_b(z, a_7, 4); /* substring, line 184 */
- if (!(among_var))
- return 0;
- z->bra = z->c; /* ], line 184 */
- switch (among_var)
- {
- case 0:
- return 0;
- case 1:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 188 */
- if (ret < 0)
- return ret;
- }
- z->ket = z->c; /* [, line 189 */
- if (!(eq_s_b(z, 2, s_6)))
- return 0;
- z->bra = z->c; /* ], line 189 */
- if (!(eq_s_b(z, 2, s_7)))
- return 0;
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 189 */
- if (ret < 0)
- return ret;
- }
- break;
- case 2:
- if (!(eq_s_b(z, 2, s_8)))
- return 0;
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 192 */
- if (ret < 0)
- return ret;
- }
- break;
- case 3:
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 194 */
- if (ret < 0)
- return ret;
- }
- break;
- }
- return 1;
-}
-
-extern int
-russian_UTF_8_stem(struct SN_env * z)
-{
- {
- int c = z->c; /* do, line 201 */
-
- {
- int ret = r_mark_regions(z);
-
- if (ret == 0)
- goto lab0; /* call mark_regions, line 201 */
- if (ret < 0)
- return ret;
- }
-lab0:
- z->c = c;
- }
- z->lb = z->c;
- z->c = z->l; /* backwards, line 202 */
-
- {
- int m3; /* setlimit, line 202 */
- int m = z->l - z->c;
-
- (void) m;
- if (z->c < z->I[0])
- return 0;
- z->c = z->I[0]; /* tomark, line 202 */
- m3 = z->lb;
- z->lb = z->c;
- z->c = z->l - m;
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 203 */
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 204 */
- {
- int ret = r_perfective_gerund(z);
-
- if (ret == 0)
- goto lab3; /* call perfective_gerund, line 204 */
- if (ret < 0)
- return ret;
- }
- goto lab2;
- lab3:
- z->c = z->l - m;
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 205 */
- {
- int ret = r_reflexive(z);
-
- if (ret == 0)
- {
- z->c = z->l - m;
- goto lab4;
- } /* call reflexive, line 205 */
- if (ret < 0)
- return ret;
- }
- lab4:
- ;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* or, line 206 */
- {
- int ret = r_adjectival(z);
-
- if (ret == 0)
- goto lab6; /* call adjectival, line 206 */
- if (ret < 0)
- return ret;
- }
- goto lab5;
- lab6:
- z->c = z->l - m;
- {
- int ret = r_verb(z);
-
- if (ret == 0)
- goto lab7; /* call verb, line 206 */
- if (ret < 0)
- return ret;
- }
- goto lab5;
- lab7:
- z->c = z->l - m;
- {
- int ret = r_noun(z);
-
- if (ret == 0)
- goto lab1; /* call noun, line 206 */
- if (ret < 0)
- return ret;
- }
- }
- lab5:
- ;
- }
- lab2:
- lab1:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* try, line 209 */
- z->ket = z->c; /* [, line 209 */
- if (!(eq_s_b(z, 2, s_9)))
- {
- z->c = z->l - m;
- goto lab8;
- }
- z->bra = z->c; /* ], line 209 */
- {
- int ret;
-
- ret = slice_del(z); /* delete, line 209 */
- if (ret < 0)
- return ret;
- }
- lab8:
- ;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 212 */
- {
- int ret = r_derivational(z);
-
- if (ret == 0)
- goto lab9; /* call derivational, line 212 */
- if (ret < 0)
- return ret;
- }
- lab9:
- z->c = z->l - m;
- }
- {
- int m = z->l - z->c;
-
- (void) m; /* do, line 213 */
- {
- int ret = r_tidy_up(z);
-
- if (ret == 0)
- goto lab10; /* call tidy_up, line 213 */
- if (ret < 0)
- return ret;
- }
- lab10:
- z->c = z->l - m;
- }
- z->lb = m3;
- }
- z->c = z->lb;
- return 1;
-}
-
-extern struct SN_env *russian_UTF_8_create_env(void)
-{
- return SN_create_env(0, 2, 0);
-}
-
-extern void russian_UTF_8_close_env(struct SN_env * z)
-{
- SN_close_env(z);
-}
+++ /dev/null
-
-/* This file was generated automatically by the Snowball to ANSI C compiler */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
- extern struct SN_env *russian_UTF_8_create_env(void);
- extern void russian_UTF_8_close_env(struct SN_env * z);
-
- extern int russian_UTF_8_stem(struct SN_env * z);
-
-#ifdef __cplusplus
-}
-
-#endif
+++ /dev/null
-
-#include
-#include
-#include
-
-#include "header.h"
-
-#define unless(C) if(!(C))
-
-#define CREATE_SIZE 1
-
-extern symbol *
-create_s(void)
-{
- symbol *p;
- void *mem = malloc(HEAD + (CREATE_SIZE + 1) * sizeof(symbol));
-
- if (mem == NULL)
- return NULL;
- p = (symbol *) (HEAD + (char *) mem);
- CAPACITY(p) = CREATE_SIZE;
- SET_SIZE(p, CREATE_SIZE);
- return p;
-}
-
-extern void
-lose_s(symbol * p)
-{
- if (p == NULL)
- return;
- free((char *) p - HEAD);
-}
-
-/*
- new_p = X_skip_utf8(p, c, lb, l, n); skips n characters forwards from p + c
- if n +ve, or n characters backwards from p +c - 1 if n -ve. new_p is the new
- position, or 0 on failure.
-
- -- used to implement hop and next in the utf8 case.
-*/
-
-extern int
-skip_utf8(const symbol * p, int c, int lb, int l, int n)
-{
- int b;
-
- if (n >= 0)
- {
- for (; n > 0; n--)
- {
- if (c >= l)
- return -1;
- b = p[c++];
- if (b >= 0xC0)
- { /* 1100 0000 */
- while (c < l)
- {
- b = p[c];
- if (b >= 0xC0 || b < 0x80)
- break;
- /* break unless b is 10------ */
- c++;
- }
- }
- }
- }
- else
- {
- for (; n < 0; n++)
- {
- if (c <= lb)
- return -1;
- b = p[--c];
- if (b >= 0x80)
- { /* 1000 0000 */
- while (c > lb)
- {
- b = p[c];
- if (b >= 0xC0)
- break; /* 1100 0000 */
- c--;
- }
- }
- }
- }
- return c;
-}
-
-/* Code for character groupings: utf8 cases */
-
-static int
-get_utf8(const symbol * p, int c, int l, int *slot)
-{
- int b0,
- b1;
-
- if (c >= l)
- return 0;
- b0 = p[c++];
- if (b0 < 0xC0 || c == l)
- { /* 1100 0000 */
- *slot = b0;
- return 1;
- }
- b1 = p[c++];
- if (b0 < 0xE0 || c == l)
- { /* 1110 0000 */
- *slot = (b0 & 0x1F) << 6 | (b1 & 0x3F);
- return 2;
- }
- *slot = (b0 & 0xF) << 12 | (b1 & 0x3F) << 6 | (*p & 0x3F);
- return 3;
-}
-
-static int
-get_b_utf8(const symbol * p, int c, int lb, int *slot)
-{
- int b0,
- b1;
-
- if (c <= lb)
- return 0;
- b0 = p[--c];
- if (b0 < 0x80 || c == lb)
- { /* 1000 0000 */
- *slot = b0;
- return 1;
- }
- b1 = p[--c];
- if (b1 >= 0xC0 || c == lb)
- { /* 1100 0000 */
- *slot = (b1 & 0x1F) << 6 | (b0 & 0x3F);
- return 2;
- }
- *slot = (*p & 0xF) << 12 | (b1 & 0x3F) << 6 | (b0 & 0x3F);
- return 3;
-}
-
-extern int
-in_grouping_U(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
- int w = get_utf8(z->p, z->c, z->l, &ch);
-
- unless(w) return 0;
- if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
- return 0;
- z->c += w;
- return 1;
-}
-
-extern int
-in_grouping_b_U(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
- int w = get_b_utf8(z->p, z->c, z->lb, &ch);
-
- unless(w) return 0;
- if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
- return 0;
- z->c -= w;
- return 1;
-}
-
-extern int
-out_grouping_U(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
- int w = get_utf8(z->p, z->c, z->l, &ch);
-
- unless(w) return 0;
- unless(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0) return 0;
- z->c += w;
- return 1;
-}
-
-extern int
-out_grouping_b_U(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
- int w = get_b_utf8(z->p, z->c, z->lb, &ch);
-
- unless(w) return 0;
- unless(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0) return 0;
- z->c -= w;
- return 1;
-}
-
-/* Code for character groupings: non-utf8 cases */
-
-extern int
-in_grouping(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
-
- if (z->c >= z->l)
- return 0;
- ch = z->p[z->c];
- if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
- return 0;
- z->c++;
- return 1;
-}
-
-extern int
-in_grouping_b(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
-
- if (z->c <= z->lb)
- return 0;
- ch = z->p[z->c - 1];
- if (ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0)
- return 0;
- z->c--;
- return 1;
-}
-
-extern int
-out_grouping(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
-
- if (z->c >= z->l)
- return 0;
- ch = z->p[z->c];
- unless(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0) return 0;
- z->c++;
- return 1;
-}
-
-extern int
-out_grouping_b(struct SN_env * z, unsigned char *s, int min, int max)
-{
- int ch;
-
- if (z->c <= z->lb)
- return 0;
- ch = z->p[z->c - 1];
- unless(ch > max || (ch -= min) < 0 || (s[ch >> 3] & (0X1 << (ch & 0X7))) == 0) return 0;
- z->c--;
- return 1;
-}
-
-extern int
-eq_s(struct SN_env * z, int s_size, symbol * s)
-{
- if (z->l - z->c < s_size || memcmp(z->p + z->c, s, s_size * sizeof(symbol)) != 0)
- return 0;
- z->c += s_size;
- return 1;
-}
-
-extern int
-eq_s_b(struct SN_env * z, int s_size, symbol * s)
-{
- if (z->c - z->lb < s_size || memcmp(z->p + z->c - s_size, s, s_size * sizeof(symbol)) != 0)
- return 0;
- z->c -= s_size;
- return 1;
-}
-
-extern int
-eq_v(struct SN_env * z, symbol * p)
-{
- return eq_s(z, SIZE(p), p);
-}
-
-extern int
-eq_v_b(struct SN_env * z, symbol * p)
-{
- return eq_s_b(z, SIZE(p), p);
-}
-
-extern int
-find_among(struct SN_env * z, struct among * v, int v_size)
-{
-
- int i = 0;
- int j = v_size;
-
- int c = z->c;
- int l = z->l;
- symbol *q = z->p + c;
-
- struct among *w;
-
- int common_i = 0;
- int common_j = 0;
-
- int first_key_inspected = 0;
-
- while (1)
- {
- int k = i + ((j - i) >> 1);
- int diff = 0;
- int common = common_i < common_j ? common_i : common_j; /* smaller */
-
- w = v + k;
- {
- int i;
-
- for (i = common; i < w->s_size; i++)
- {
- if (c + common == l)
- {
- diff = -1;
- break;
- }
- diff = q[common] - w->s[i];
- if (diff != 0)
- break;
- common++;
- }
- }
- if (diff < 0)
- {
- j = k;
- common_j = common;
- }
- else
- {
- i = k;
- common_i = common;
- }
- if (j - i <= 1)
- {
- if (i > 0)
- break; /* v->s has been inspected */
- if (j == i)
- break; /* only one item in v */
-
- /*
- * - but now we need to go round once more to get v->s inspected.
- * This looks messy, but is actually the optimal approach.
- */
-
- if (first_key_inspected)
- break;
- first_key_inspected = 1;
- }
- }
- while (1)
- {
- w = v + i;
- if (common_i >= w->s_size)
- {
- z->c = c + w->s_size;
- if (w->function == 0)
- return w->result;
- {
- int res = w->function(z);
-
- z->c = c + w->s_size;
- if (res)
- return w->result;
- }
- }
- i = w->substring_i;
- if (i < 0)
- return 0;
- }
-}
-
-/* find_among_b is for backwards processing. Same comments apply */
-
-extern int
-find_among_b(struct SN_env * z, struct among * v, int v_size)
-{
-
- int i = 0;
- int j = v_size;
-
- int c = z->c;
- int lb = z->lb;
- symbol *q = z->p + c - 1;
-
- struct among *w;
-
- int common_i = 0;
- int common_j = 0;
-
- int first_key_inspected = 0;
-
- while (1)
- {
- int k = i + ((j - i) >> 1);
- int diff = 0;
- int common = common_i < common_j ? common_i : common_j;
-
- w = v + k;
- {
- int i;
-
- for (i = w->s_size - 1 - common; i >= 0; i--)
- {
- if (c - common == lb)
- {
- diff = -1;
- break;
- }
- diff = q[-common] - w->s[i];
- if (diff != 0)
- break;
- common++;
- }
- }
- if (diff < 0)
- {
- j = k;
- common_j = common;
- }
- else
- {
- i = k;
- common_i = common;
- }
- if (j - i <= 1)
- {
- if (i > 0)
- break;
- if (j == i)
- break;
- if (first_key_inspected)
- break;
- first_key_inspected = 1;
- }
- }
- while (1)
- {
- w = v + i;
- if (common_i >= w->s_size)
- {
- z->c = c - w->s_size;
- if (w->function == 0)
- return w->result;
- {
- int res = w->function(z);
-
- z->c = c - w->s_size;
- if (res)
- return w->result;
- }
- }
- i = w->substring_i;
- if (i < 0)
- return 0;
- }
-}
-
-
-/* Increase the size of the buffer pointed to by p to at least n symbols.
- * If insufficient memory, returns NULL and frees the old buffer.
- */
-static symbol *
-increase_size(symbol * p, int n)
-{
- symbol *q;
- int new_size = n + 20;
- void *mem = realloc((char *) p - HEAD,
- HEAD + (new_size + 1) * sizeof(symbol));
-
- if (mem == NULL)
- {
- lose_s(p);
- return NULL;
- }
- q = (symbol *) (HEAD + (char *) mem);
- CAPACITY(q) = new_size;
- return q;
-}
-
-/* to replace symbols between c_bra and c_ket in z->p by the
- s_size symbols at s.
- Returns 0 on success, -1 on error.
- Also, frees z->p (and sets it to NULL) on error.
-*/
-extern int
-replace_s(struct SN_env * z, int c_bra, int c_ket, int s_size, const symbol * s, int *adjptr)
-{
- int adjustment;
- int len;
-
- if (z->p == NULL)
- {
- z->p = create_s();
- if (z->p == NULL)
- return -1;
- }
- adjustment = s_size - (c_ket - c_bra);
- len = SIZE(z->p);
- if (adjustment != 0)
- {
- if (adjustment + len > CAPACITY(z->p))
- {
- z->p = increase_size(z->p, adjustment + len);
- if (z->p == NULL)
- return -1;
- }
- memmove(z->p + c_ket + adjustment,
- z->p + c_ket,
- (len - c_ket) * sizeof(symbol));
- SET_SIZE(z->p, adjustment + len);
- z->l += adjustment;
- if (z->c >= c_ket)
- z->c += adjustment;
- else if (z->c > c_bra)
- z->c = c_bra;
- }
- unless(s_size == 0) memmove(z->p + c_bra, s, s_size * sizeof(symbol));
- if (adjptr != NULL)
- *adjptr = adjustment;
- return 0;
-}
-
-static int
-slice_check(struct SN_env * z)
-{
-
- if (z->bra < 0 ||
- z->bra > z->ket ||
- z->ket > z->l ||
- z->p == NULL ||
- z->l > SIZE(z->p)) /* this line could be removed */
- {
-#if 0
- fprintf(stderr, "faulty slice operation:\n");
- debug(z, -1, 0);
-#endif
- return -1;
- }
- return 0;
-}
-
-extern int
-slice_from_s(struct SN_env * z, int s_size, symbol * s)
-{
- if (slice_check(z))
- return -1;
- return replace_s(z, z->bra, z->ket, s_size, s, NULL);
-}
-
-extern int
-slice_from_v(struct SN_env * z, symbol * p)
-{
- return slice_from_s(z, SIZE(p), p);
-}
-
-extern int
-slice_del(struct SN_env * z)
-{
- return slice_from_s(z, 0, 0);
-}
-
-extern int
-insert_s(struct SN_env * z, int bra, int ket, int s_size, symbol * s)
-{
- int adjustment;
-
- if (replace_s(z, bra, ket, s_size, s, &adjustment))
- return -1;
- if (bra <= z->bra)
- z->bra += adjustment;
- if (bra <= z->ket)
- z->ket += adjustment;
- return 0;
-}
-
-extern int
-insert_v(struct SN_env * z, int bra, int ket, symbol * p)
-{
- int adjustment;
-
- if (replace_s(z, bra, ket, SIZE(p), p, &adjustment))
- return -1;
- if (bra <= z->bra)
- z->bra += adjustment;
- if (bra <= z->ket)
- z->ket += adjustment;
- return 0;
-}
-
-extern symbol *
-slice_to(struct SN_env * z, symbol * p)
-{
- if (slice_check(z))
- {
- lose_s(p);
- return NULL;
- }
- {
- int len = z->ket - z->bra;
-
- if (CAPACITY(p) < len)
- {
- p = increase_size(p, len);
- if (p == NULL)
- return NULL;
- }
- memmove(p, z->p + z->bra, len * sizeof(symbol));
- SET_SIZE(p, len);
- }
- return p;
-}
-
-extern symbol *
-assign_to(struct SN_env * z, symbol * p)
-{
- int len = z->l;
-
- if (CAPACITY(p) < len)
- {
- p = increase_size(p, len);
- if (p == NULL)
- return NULL;
- }
- memmove(p, z->p, len * sizeof(symbol));
- SET_SIZE(p, len);
- return p;
-}
-
-#if 0
-extern void
-debug(struct SN_env * z, int number, int line_count)
-{
- int i;
- int limit = SIZE(z->p);
-
- /* if (number >= 0) printf("%3d (line %4d): '", number, line_count); */
- if (number >= 0)
- printf("%3d (line %4d): [%d]'", number, line_count, limit);
- for (i = 0; i <= limit; i++)
- {
- if (z->lb == i)
- printf("{");
- if (z->bra == i)
- printf("[");
- if (z->c == i)
- printf("|");
- if (z->ket == i)
- printf("]");
- if (z->l == i)
- printf("}");
- if (i < limit)
- {
- int ch = z->p[i];
-
- if (ch == 0)
- ch = '#';
- printf("%c", ch);
- }
- }
- printf("'\n");
-}
-
-#endif
\set ECHO all
alter table test_tsquery add column keyword tsquery;
-update test_tsquery set keyword = to_tsquery('default', txtkeyword);
+update test_tsquery set keyword = to_tsquery('english', txtkeyword);
alter table test_tsquery add column sample tsquery;
-update test_tsquery set sample = to_tsquery('default', txtsample::text);
+update test_tsquery set sample = to_tsquery('english', txtsample::text);
create unique index bt_tsq on test_tsquery (keyword);
select rewrite('moscow & hotel', 'select keyword, sample from test_tsquery'::text );
select rewrite('bar & new & qq & foo & york', 'select keyword, sample from test_tsquery'::text );
-select rewrite( ARRAY['moscow', keyword, sample] ) from test_tsquery;
-select rewrite( ARRAY['moscow & hotel', keyword, sample] ) from test_tsquery;
-select rewrite( ARRAY['bar & new & qq & foo & york', keyword, sample] ) from test_tsquery;
-
-
select keyword from test_tsquery where keyword @> 'new';
select keyword from test_tsquery where keyword @> 'moscow';
select keyword from test_tsquery where keyword <@ 'new';
select keyword from test_tsquery where keyword <@ 'moscow';
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where keyword <@ query;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where keyword <@ query;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where keyword <@ query;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where query @> keyword;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where query @> keyword;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where query @> keyword;
create index qq on test_tsquery using gist (keyword gist_tp_tsquery_ops);
set enable_seqscan='off';
select keyword from test_tsquery where keyword @> 'moscow';
select keyword from test_tsquery where keyword <@ 'new';
select keyword from test_tsquery where keyword <@ 'moscow';
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where keyword <@ query;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where keyword <@ query;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where keyword <@ query;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow') as query where query @> keyword;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'moscow & hotel') as query where query @> keyword;
-select rewrite( ARRAY[query, keyword, sample] ) from test_tsquery, to_tsquery('default', 'bar & new & qq & foo & york') as query where query @> keyword;
+
set enable_seqscan='on';
select lexize('simple', 'ASD56 hsdkf');
-select lexize('en_stem', 'SKIES Problems identity');
+select lexize('english_stem', 'SKIES Problems identity');
select * from token_type('default');
select * from parse('default', '345
[email protected] '' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/? ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005
[email protected] qwe-wer asdf
qwer jf sdjk ewr1> ewri2 ">
/usr/local/fff /awdf/dwqe/4325 rewt/ewr wefjn /wqe-324/ewr gist.h gist.h.c gist.c. readline 4.2 4.2. 4.2, readline-4.2 readline-4.2. 234
wow < jqw <> qwerty');
-SELECT to_tsvector('
default', '345
[email protected] '' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/? ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005
[email protected] qwe-wer asdf
qwer jf sdjk ewr1> ewri2 ">
+SELECT to_tsvector('
english', '345
[email protected] '' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/? ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005
[email protected] qwe-wer asdf
qwer jf sdjk ewr1> ewri2 ">
/usr/local/fff /awdf/dwqe/4325 rewt/ewr wefjn /wqe-324/ewr gist.h gist.h.c gist.c. readline 4.2 4.2. 4.2, readline-4.2 readline-4.2. 234
wow < jqw <> qwerty');
-SELECT length(to_tsvector('default', '345 qw'));
+SELECT length(to_tsvector('english', '345 qw'));
-SELECT length(to_tsvector('
default', '345
[email protected] '' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/? ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005
[email protected] qwe-wer asdf
qwer jf sdjk ewr1> ewri2 ">
+SELECT length(to_tsvector('
english', '345
[email protected] '' http://www.com/ http://aew.werc.ewr/?ad=qwe&dw 1aew.werc.ewr/?ad=qwe&dw 2aew.werc.ewr http://3aew.werc.ewr/?ad=qwe&dw http://4aew.werc.ewr http://5aew.werc.ewr:8100/? ad=qwe&dw 6aew.werc.ewr:8100/?ad=qwe&dw 7aew.werc.ewr:8100/?ad=qwe&dw=%20%32 +4.0e-10 qwe qwe qwqwe 234.435 455 5.005
[email protected] qwe-wer asdf
qwer jf sdjk ewr1> ewri2 ">
/usr/local/fff /awdf/dwqe/4325 rewt/ewr wefjn /wqe-324/ewr gist.h gist.h.c gist.c. readline 4.2 4.2. 4.2, readline-4.2 readline-4.2. 234
wow < jqw <> qwerty'));
-select to_tsquery('default', 'qwe & sKies ');
+select to_tsquery('english', 'qwe & sKies ');
select to_tsquery('simple', 'qwe & sKies ');
-select to_tsquery('default', '''the wether'':dc & '' sKies '':BC ');
-select to_tsquery('default', 'asd&(and|fghj)');
-select to_tsquery('default', '(asd&and)|fghj');
-select to_tsquery('default', '(asd&!and)|fghj');
-select to_tsquery('default', '(the|and&(i&1))&fghj');
-
-select plainto_tsquery('default', 'the and z 1))& fghj');
-select plainto_tsquery('default', 'foo bar') && plainto_tsquery('default', 'asd');
-select plainto_tsquery('default', 'foo bar') || plainto_tsquery('default', 'asd fg');
-select plainto_tsquery('default', 'foo bar') || !!plainto_tsquery('default', 'asd fg');
-select plainto_tsquery('default', 'foo bar') && 'asd | fg';
+select to_tsquery('english', '''the wether'':dc & '' sKies '':BC ');
+select to_tsquery('english', 'asd&(and|fghj)');
+select to_tsquery('english', '(asd&and)|fghj');
+select to_tsquery('english', '(asd&!and)|fghj');
+select to_tsquery('english', '(the|and&(i&1))&fghj');
+
+select plainto_tsquery('english', 'the and z 1))& fghj');
+select plainto_tsquery('english', 'foo bar') && plainto_tsquery('english', 'asd');
+select plainto_tsquery('english', 'foo bar') || plainto_tsquery('english', 'asd fg');
+select plainto_tsquery('english', 'foo bar') || !!plainto_tsquery('english', 'asd fg');
+select plainto_tsquery('english', 'foo bar') && 'asd | fg';
select 'a b:89 ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca';
select 'a b:89 ca:23A,64b d:34c'::tsvector @@ 'd:AC & ca:B';
SELECT count(*) FROM test_tsvector WHERE a @@ '(eq&yt)|(wr&qh)';
SELECT count(*) FROM test_tsvector WHERE a @@ '(eq|yt)&(wr|qh)';
-select set_curcfg('default');
+select set_curcfg('english');
CREATE TRIGGER tsvectorupdate
BEFORE UPDATE OR INSERT ON test_tsvector
SELECT count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
-drop trigger tsvectorupdate on test_tsvector;
-create function wow(text) returns text as 'select $1 || '' copyright''; ' language sql;
-create trigger tsvectorupdate before update or insert on test_tsvector
-for each row execute procedure tsearch2(a, wow, t);
-insert into test_tsvector (t) values ('345 qwerty');
+insert into test_tsvector (t) values ('345 qwerty copyright');
select count(*) FROM test_tsvector WHERE a @@ to_tsquery('345&qwerty');
select count(*) FROM test_tsvector WHERE a @@ to_tsquery('copyright');
select * from stat('select a from test_tsvector','d') order by ndoc desc, nentry desc, word;
select * from stat('select a from test_tsvector','ad') order by ndoc desc, nentry desc, word;
-select reset_tsearch();
-select to_tsquery('default', 'skies & books');
+select to_tsquery('english', 'skies & books');
select rank_cd(to_tsvector('Erosion It took the sea a thousand years,
A thousand years to trace
Upon a woman s face. E. J. Pratt (1882 1964)
'), to_tsquery('sea'));
-select get_covers(to_tsvector('Erosion It took the sea a thousand years,
-A thousand years to trace
-The granite features of this cliff
-In crag and scarp and base.
-It took the sea an hour one night
-An hour of storm to place
-The sculpture of these granite seams,
-Upon a woman s face. E. J. Pratt (1882 1964)
-'), to_tsquery('sea&thousand&years'));
-
-select get_covers(to_tsvector('Erosion It took the sea a thousand years,
-A thousand years to trace
-The granite features of this cliff
-In crag and scarp and base.
-It took the sea an hour one night
-An hour of storm to place
-The sculpture of these granite seams,
-Upon a woman s face. E. J. Pratt (1882 1964)
-'), to_tsquery('granite&sea'));
-
-select get_covers(to_tsvector('Erosion It took the sea a thousand years,
-A thousand years to trace
-The granite features of this cliff
-In crag and scarp and base.
-It took the sea an hour one night
-An hour of storm to place
-The sculpture of these granite seams,
-Upon a woman s face. E. J. Pratt (1882 1964)
-'), to_tsquery('sea'));
-
select headline('Erosion It took the sea a thousand years,
A thousand years to trace
The granite features of this cliff