mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Standard pgindent run for 8.1.
This commit is contained in:
@ -91,9 +91,9 @@ reset_dict(void)
|
||||
static int
|
||||
comparedict(const void *a, const void *b)
|
||||
{
|
||||
if ( ((DictInfo *) a)->dict_id == ((DictInfo *) b)->dict_id )
|
||||
if (((DictInfo *) a)->dict_id == ((DictInfo *) b)->dict_id)
|
||||
return 0;
|
||||
return ( ((DictInfo *) a)->dict_id < ((DictInfo *) b)->dict_id ) ? -1 : 1;
|
||||
return (((DictInfo *) a)->dict_id < ((DictInfo *) b)->dict_id) ? -1 : 1;
|
||||
}
|
||||
|
||||
DictInfo *
|
||||
@ -184,8 +184,8 @@ lexize(PG_FUNCTION_ARGS)
|
||||
{
|
||||
text *in = PG_GETARG_TEXT_P(1);
|
||||
DictInfo *dict;
|
||||
TSLexeme *res,
|
||||
*ptr;
|
||||
TSLexeme *res,
|
||||
*ptr;
|
||||
Datum *da;
|
||||
ArrayType *a;
|
||||
|
||||
@ -193,11 +193,11 @@ lexize(PG_FUNCTION_ARGS)
|
||||
dict = finddict(PG_GETARG_OID(0));
|
||||
|
||||
ptr = res = (TSLexeme *) DatumGetPointer(
|
||||
FunctionCall3(&(dict->lexize_info),
|
||||
PointerGetDatum(dict->dictionary),
|
||||
PointerGetDatum(VARDATA(in)),
|
||||
Int32GetDatum(VARSIZE(in) - VARHDRSZ)
|
||||
)
|
||||
FunctionCall3(&(dict->lexize_info),
|
||||
PointerGetDatum(dict->dictionary),
|
||||
PointerGetDatum(VARDATA(in)),
|
||||
Int32GetDatum(VARSIZE(in) - VARHDRSZ)
|
||||
)
|
||||
);
|
||||
PG_FREE_IF_COPY(in, 1);
|
||||
if (!res)
|
||||
|
@ -39,26 +39,22 @@ typedef struct
|
||||
void parse_cfgdict(text *in, Map ** m);
|
||||
|
||||
/* return struct for any lexize function */
|
||||
typedef struct {
|
||||
/* number of variant of split word , for example
|
||||
Word 'fotballklubber' (norwegian) has two varian to split:
|
||||
( fotball, klubb ) and ( fot, ball, klubb ). So, dictionary
|
||||
should return:
|
||||
nvariant lexeme
|
||||
1 fotball
|
||||
1 klubb
|
||||
2 fot
|
||||
2 ball
|
||||
2 klubb
|
||||
|
||||
*/
|
||||
uint16 nvariant;
|
||||
typedef struct
|
||||
{
|
||||
/*
|
||||
* number of variant of split word , for example Word 'fotballklubber'
|
||||
* (norwegian) has two varian to split: ( fotball, klubb ) and ( fot,
|
||||
* ball, klubb ). So, dictionary should return: nvariant lexeme 1
|
||||
* fotball 1 klubb 2 fot 2 ball 2 klubb
|
||||
*
|
||||
*/
|
||||
uint16 nvariant;
|
||||
|
||||
/* currently unused */
|
||||
uint16 flags;
|
||||
uint16 flags;
|
||||
|
||||
/* C-string */
|
||||
char *lexeme;
|
||||
} TSLexeme;
|
||||
char *lexeme;
|
||||
} TSLexeme;
|
||||
|
||||
#endif
|
||||
|
@ -52,7 +52,7 @@ dex_lexize(PG_FUNCTION_ARGS)
|
||||
char *txt = pnstrdup(in, PG_GETARG_INT32(2));
|
||||
TSLexeme *res = palloc(sizeof(TSLexeme) * 2);
|
||||
|
||||
memset(res,0,sizeof(TSLexeme) * 2);
|
||||
memset(res, 0, sizeof(TSLexeme) * 2);
|
||||
|
||||
if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
|
||||
{
|
||||
|
@ -66,8 +66,8 @@ spell_init(PG_FUNCTION_ARGS)
|
||||
{
|
||||
freeDictISpell(d);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("dictionary already loaded")));
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("dictionary already loaded")));
|
||||
}
|
||||
if (NIImportDictionary(&(d->obj), pcfg->value))
|
||||
{
|
||||
@ -85,8 +85,8 @@ spell_init(PG_FUNCTION_ARGS)
|
||||
{
|
||||
freeDictISpell(d);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("affixes already loaded")));
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("affixes already loaded")));
|
||||
}
|
||||
if (NIImportAffixes(&(d->obj), pcfg->value))
|
||||
{
|
||||
@ -106,8 +106,8 @@ spell_init(PG_FUNCTION_ARGS)
|
||||
{
|
||||
freeDictISpell(d);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("stop words already loaded")));
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("stop words already loaded")));
|
||||
}
|
||||
readstoplist(tmp, &(d->stoplist));
|
||||
sortstoplist(&(d->stoplist));
|
||||
@ -157,9 +157,9 @@ spell_lexize(PG_FUNCTION_ARGS)
|
||||
DictISpell *d = (DictISpell *) PG_GETARG_POINTER(0);
|
||||
char *in = (char *) PG_GETARG_POINTER(1);
|
||||
char *txt;
|
||||
TSLexeme *res;
|
||||
TSLexeme *ptr,
|
||||
*cptr;
|
||||
TSLexeme *res;
|
||||
TSLexeme *ptr,
|
||||
*cptr;
|
||||
|
||||
if (!PG_GETARG_INT32(2))
|
||||
PG_RETURN_POINTER(NULL);
|
||||
|
@ -102,7 +102,7 @@ snb_lexize(PG_FUNCTION_ARGS)
|
||||
DictSnowball *d = (DictSnowball *) PG_GETARG_POINTER(0);
|
||||
char *in = (char *) PG_GETARG_POINTER(1);
|
||||
char *txt = pnstrdup(in, PG_GETARG_INT32(2));
|
||||
TSLexeme *res = palloc(sizeof(TSLexeme) * 2);
|
||||
TSLexeme *res = palloc(sizeof(TSLexeme) * 2);
|
||||
|
||||
memset(res, 0, sizeof(TSLexeme) * 2);
|
||||
if (*txt == '\0' || searchstoplist(&(d->stoplist), txt))
|
||||
|
@ -159,7 +159,7 @@ syn_lexize(PG_FUNCTION_ARGS)
|
||||
char *in = (char *) PG_GETARG_POINTER(1);
|
||||
Syn key,
|
||||
*found;
|
||||
TSLexeme *res = NULL;
|
||||
TSLexeme *res = NULL;
|
||||
|
||||
if (!PG_GETARG_INT32(2))
|
||||
PG_RETURN_POINTER(NULL);
|
||||
@ -174,7 +174,7 @@ syn_lexize(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(NULL);
|
||||
|
||||
res = palloc(sizeof(TSLexeme) * 2);
|
||||
memset(res,0,sizeof(TSLexeme) * 2);
|
||||
memset(res, 0, sizeof(TSLexeme) * 2);
|
||||
res[0].lexeme = pstrdup(found->out);
|
||||
|
||||
PG_RETURN_POINTER(res);
|
||||
|
@ -65,30 +65,32 @@ gtsvector_in(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_DATUM(0);
|
||||
}
|
||||
|
||||
#define SINGOUTSTR "%d true bits, %d false bits"
|
||||
#define ARROUTSTR "%d unique words"
|
||||
#define SINGOUTSTR "%d true bits, %d false bits"
|
||||
#define ARROUTSTR "%d unique words"
|
||||
#define EXTRALEN ( 2*13 )
|
||||
|
||||
static int outbuf_maxlen = 0;
|
||||
static int outbuf_maxlen = 0;
|
||||
|
||||
Datum
|
||||
gtsvector_out(PG_FUNCTION_ARGS)
|
||||
{
|
||||
GISTTYPE *key = (GISTTYPE *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_POINTER(0)));
|
||||
char *outbuf;
|
||||
char *outbuf;
|
||||
|
||||
if ( outbuf_maxlen==0 )
|
||||
outbuf_maxlen = 2*EXTRALEN + Max( strlen(SINGOUTSTR), strlen(ARROUTSTR) ) + 1;
|
||||
outbuf = palloc( outbuf_maxlen );
|
||||
if (outbuf_maxlen == 0)
|
||||
outbuf_maxlen = 2 * EXTRALEN + Max(strlen(SINGOUTSTR), strlen(ARROUTSTR)) + 1;
|
||||
outbuf = palloc(outbuf_maxlen);
|
||||
|
||||
if ( ISARRKEY(key) )
|
||||
sprintf( outbuf, ARROUTSTR, (int) ARRNELEM(key) );
|
||||
else {
|
||||
int cnttrue = ( ISALLTRUE(key) ) ? SIGLENBIT : sizebitvec(GETSIGN(key));
|
||||
sprintf( outbuf, SINGOUTSTR, cnttrue, (int) SIGLENBIT - cnttrue );
|
||||
}
|
||||
if (ISARRKEY(key))
|
||||
sprintf(outbuf, ARROUTSTR, (int) ARRNELEM(key));
|
||||
else
|
||||
{
|
||||
int cnttrue = (ISALLTRUE(key)) ? SIGLENBIT : sizebitvec(GETSIGN(key));
|
||||
|
||||
PG_FREE_IF_COPY(key,0);
|
||||
sprintf(outbuf, SINGOUTSTR, cnttrue, (int) SIGLENBIT - cnttrue);
|
||||
}
|
||||
|
||||
PG_FREE_IF_COPY(key, 0);
|
||||
PG_RETURN_POINTER(outbuf);
|
||||
}
|
||||
|
||||
@ -165,8 +167,8 @@ gtsvector_compress(PG_FUNCTION_ARGS)
|
||||
if (len != val->size)
|
||||
{
|
||||
/*
|
||||
* there is a collision of hash-function; len is always less
|
||||
* than val->size
|
||||
* there is a collision of hash-function; len is always less than
|
||||
* val->size
|
||||
*/
|
||||
len = CALCGTSIZE(ARRKEY, len);
|
||||
res = (GISTTYPE *) repalloc((void *) res, len);
|
||||
@ -280,7 +282,7 @@ gtsvector_consistent(PG_FUNCTION_ARGS)
|
||||
{
|
||||
QUERYTYPE *query = (QUERYTYPE *) PG_GETARG_POINTER(1);
|
||||
GISTTYPE *key = (GISTTYPE *) DatumGetPointer(
|
||||
((GISTENTRY *) PG_GETARG_POINTER(0))->key
|
||||
((GISTENTRY *) PG_GETARG_POINTER(0))->key
|
||||
);
|
||||
|
||||
if (!query->size)
|
||||
|
@ -10,8 +10,8 @@
|
||||
*/
|
||||
|
||||
#define BITBYTE 8
|
||||
#define SIGLENINT 63 /* >121 => key will toast, so it will not
|
||||
* work !!! */
|
||||
#define SIGLENINT 63 /* >121 => key will toast, so it will not work
|
||||
* !!! */
|
||||
#define SIGLEN ( sizeof(int4) * SIGLENINT )
|
||||
#define SIGLENBIT (SIGLEN * BITBYTE)
|
||||
|
||||
@ -55,7 +55,7 @@ typedef struct
|
||||
#define ISSIGNKEY(x) ( ((GISTTYPE*)(x))->flag & SIGNKEY )
|
||||
#define ISALLTRUE(x) ( ((GISTTYPE*)(x))->flag & ALLISTRUE )
|
||||
|
||||
#define GTHDRSIZE ( sizeof(int4) * 2 )
|
||||
#define GTHDRSIZE ( sizeof(int4) * 2 )
|
||||
#define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int4)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
|
||||
|
||||
#define GETSIGN(x) ( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
|
||||
|
@ -153,7 +153,7 @@ NIImportDictionary(IspellDict * Conf, const char *filename)
|
||||
return (1);
|
||||
while (fgets(str, sizeof(str), dict))
|
||||
{
|
||||
char *s;
|
||||
char *s;
|
||||
const char *flag;
|
||||
|
||||
flag = NULL;
|
||||
@ -266,7 +266,7 @@ NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const
|
||||
{
|
||||
Conf->Affix[Conf->naffixes].issimple = 0;
|
||||
Conf->Affix[Conf->naffixes].isregis = 0;
|
||||
Conf->Affix[Conf->naffixes].mask = (char*)malloc( strlen(mask) + 2 );
|
||||
Conf->Affix[Conf->naffixes].mask = (char *) malloc(strlen(mask) + 2);
|
||||
if (type == FF_SUFFIX)
|
||||
sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask);
|
||||
else
|
||||
@ -489,8 +489,8 @@ mkSPNode(IspellDict * Conf, int low, int high, int level)
|
||||
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,
|
||||
* 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] );
|
||||
*/
|
||||
@ -806,7 +806,8 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne
|
||||
pfree(mask);
|
||||
if (err)
|
||||
{
|
||||
char regerrstr[ERRSTRSIZE];
|
||||
char regerrstr[ERRSTRSIZE];
|
||||
|
||||
pg_regerror(err, &(Affix->reg.regex), regerrstr, ERRSTRSIZE);
|
||||
elog(ERROR, "Regex error in '%s': %s", Affix->mask, regerrstr);
|
||||
}
|
||||
@ -1037,8 +1038,7 @@ SplitToVariants(IspellDict * Conf, SPNode * snode, SplitVar * orig, char *word,
|
||||
while (level > startpos && (lenaff = CheckCompoundAffixes(&caff, word + level, wordlen - level)) > 0)
|
||||
{
|
||||
/*
|
||||
* there is one of compound suffixes, so check word for
|
||||
* existings
|
||||
* there is one of compound suffixes, so check word for existings
|
||||
*/
|
||||
char buf[MAXNORMLEN];
|
||||
char **subres;
|
||||
@ -1128,20 +1128,24 @@ TSLexeme *
|
||||
NINormalizeWord(IspellDict * Conf, char *word)
|
||||
{
|
||||
char **res = NormalizeSubWord(Conf, word, 0);
|
||||
TSLexeme *lcur=NULL, *lres=NULL;
|
||||
uint16 NVariant=1;
|
||||
TSLexeme *lcur = NULL,
|
||||
*lres = NULL;
|
||||
uint16 NVariant = 1;
|
||||
|
||||
if (res) {
|
||||
char **ptr = res;
|
||||
lcur = lres = (TSLexeme*)palloc( MAX_NORM * sizeof(TSLexeme) );
|
||||
while(*ptr) {
|
||||
lcur->lexeme=*ptr;
|
||||
lcur->flags=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;
|
||||
lcur->lexeme = NULL;
|
||||
pfree(res);
|
||||
}
|
||||
|
||||
@ -1162,29 +1166,31 @@ NINormalizeWord(IspellDict * Conf, char *word)
|
||||
{
|
||||
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;
|
||||
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->lexeme = *subptr;
|
||||
lcur->flags = 0;
|
||||
lcur->nvariant = NVariant;
|
||||
lcur++;
|
||||
subptr++;
|
||||
NVariant++;
|
||||
}
|
||||
}
|
||||
|
||||
lcur->lexeme=NULL;
|
||||
lcur->lexeme = NULL;
|
||||
pfree(subres);
|
||||
var->stem[0] = NULL;
|
||||
pfree( var->stem[ var->nstem-1 ] );
|
||||
pfree(var->stem[var->nstem - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#include "regis.h"
|
||||
#include "dict.h"
|
||||
|
||||
|
||||
struct SPNode;
|
||||
|
||||
|
||||
@ -55,9 +55,9 @@ typedef struct aff_struct
|
||||
isregis:1,
|
||||
unused:1,
|
||||
replen:16;
|
||||
char *mask;
|
||||
char *find;
|
||||
char *repl;
|
||||
char *mask;
|
||||
char *find;
|
||||
char *repl;
|
||||
union
|
||||
{
|
||||
regex_t regex;
|
||||
@ -117,7 +117,7 @@ typedef struct
|
||||
|
||||
} IspellDict;
|
||||
|
||||
TSLexeme *NINormalizeWord(IspellDict * Conf, char *word);
|
||||
TSLexeme *NINormalizeWord(IspellDict * Conf, char *word);
|
||||
int NIImportAffixes(IspellDict * Conf, const char *filename);
|
||||
int NIImportDictionary(IspellDict * Conf, const char *filename);
|
||||
|
||||
|
@ -73,8 +73,8 @@ parse_cfgdict(text *in, Map ** m)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error"),
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
}
|
||||
else if (state == CS_INKEY)
|
||||
{
|
||||
@ -92,8 +92,8 @@ parse_cfgdict(text *in, Map ** m)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error"),
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
}
|
||||
else if (state == CS_WAITEQ)
|
||||
{
|
||||
@ -103,8 +103,8 @@ parse_cfgdict(text *in, Map ** m)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error"),
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
}
|
||||
else if (state == CS_WAITVALUE)
|
||||
{
|
||||
@ -149,8 +149,8 @@ parse_cfgdict(text *in, Map ** m)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error"),
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
errdetail("Syntax error in position %d near \"%c\"",
|
||||
(int) (ptr - VARDATA(in)), *ptr)));
|
||||
}
|
||||
else if (state == CS_INESC)
|
||||
state = CS_INVALUE;
|
||||
|
@ -265,7 +265,11 @@ pushval_morph(QPRS_STATE * state, int typeval, char *strval, int lenval, int2 we
|
||||
{
|
||||
int4 count = 0;
|
||||
PRSTEXT prs;
|
||||
uint32 variant, pos, cntvar=0, cntpos=0, cnt=0;
|
||||
uint32 variant,
|
||||
pos,
|
||||
cntvar = 0,
|
||||
cntpos = 0,
|
||||
cnt = 0;
|
||||
|
||||
prs.lenwords = 32;
|
||||
prs.curwords = 0;
|
||||
@ -274,39 +278,44 @@ pushval_morph(QPRS_STATE * state, int typeval, char *strval, int lenval, int2 we
|
||||
|
||||
parsetext_v2(findcfg(state->cfg_id), &prs, strval, lenval);
|
||||
|
||||
if ( prs.curwords>0 ) {
|
||||
if (prs.curwords > 0)
|
||||
{
|
||||
|
||||
while (count < prs.curwords) {
|
||||
while (count < prs.curwords)
|
||||
{
|
||||
pos = prs.words[count].pos.pos;
|
||||
cntvar=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) {
|
||||
|
||||
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 )
|
||||
if (cnt)
|
||||
pushquery(state, OPR, (int4) '&', 0, 0, 0);
|
||||
cnt++;
|
||||
count++;
|
||||
}
|
||||
|
||||
if ( cntvar )
|
||||
if (cntvar)
|
||||
pushquery(state, OPR, (int4) '|', 0, 0, 0);
|
||||
cntvar++;
|
||||
}
|
||||
|
||||
if (cntpos)
|
||||
if (cntpos)
|
||||
pushquery(state, OPR, (int4) '&', 0, 0, 0);
|
||||
|
||||
|
||||
cntpos++;
|
||||
}
|
||||
|
||||
pfree(prs.words);
|
||||
|
||||
} else
|
||||
}
|
||||
else
|
||||
pushval_asis(state, VALSTOP, NULL, 0, 0);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ static float weights[] = {0.1, 0.2, 0.4, 1.0};
|
||||
|
||||
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
|
||||
*/
|
||||
@ -115,44 +116,52 @@ find_wordentry(tsvector * t, QUERYTYPE * q, ITEM * item)
|
||||
}
|
||||
|
||||
|
||||
static char * SortAndUniqOperand=NULL;
|
||||
static char *SortAndUniqOperand = NULL;
|
||||
|
||||
static int
|
||||
compareITEM( const void * a, const void * b ) {
|
||||
if ( (*(ITEM**)a)->length == (*(ITEM**)b)->length )
|
||||
return strncmp( SortAndUniqOperand + (*(ITEM**)a)->distance,
|
||||
SortAndUniqOperand + (*(ITEM**)b)->distance,
|
||||
(*(ITEM**)b)->length );
|
||||
compareITEM(const void *a, const void *b)
|
||||
{
|
||||
if ((*(ITEM **) a)->length == (*(ITEM **) b)->length)
|
||||
return strncmp(SortAndUniqOperand + (*(ITEM **) a)->distance,
|
||||
SortAndUniqOperand + (*(ITEM **) b)->distance,
|
||||
(*(ITEM **) b)->length);
|
||||
|
||||
return ((*(ITEM**)a)->length > (*(ITEM**)b)->length) ? 1 : -1;
|
||||
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 );
|
||||
static ITEM **
|
||||
SortAndUniqItems(char *operand, ITEM * item, int *size)
|
||||
{
|
||||
ITEM **res,
|
||||
**ptr,
|
||||
**prevptr;
|
||||
|
||||
while( (*size)-- ) {
|
||||
if ( item->type == VAL ) {
|
||||
ptr = res = (ITEM **) palloc(sizeof(ITEM *) * *size);
|
||||
|
||||
while ((*size)--)
|
||||
{
|
||||
if (item->type == VAL)
|
||||
{
|
||||
*ptr = item;
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
item++;
|
||||
}
|
||||
|
||||
*size = ptr-res;
|
||||
if ( *size < 2 )
|
||||
*size = ptr - res;
|
||||
if (*size < 2)
|
||||
return res;
|
||||
|
||||
SortAndUniqOperand=operand;
|
||||
qsort( res, *size, sizeof(ITEM**), compareITEM );
|
||||
SortAndUniqOperand = operand;
|
||||
qsort(res, *size, sizeof(ITEM **), compareITEM);
|
||||
|
||||
ptr = res + 1;
|
||||
prevptr = res;
|
||||
|
||||
while( ptr - res < *size ) {
|
||||
if ( compareITEM( (void*) ptr, (void*) prevptr ) != 0 ) {
|
||||
while (ptr - res < *size)
|
||||
{
|
||||
if (compareITEM((void *) ptr, (void *) prevptr) != 0)
|
||||
{
|
||||
prevptr++;
|
||||
*prevptr = *ptr;
|
||||
}
|
||||
@ -183,18 +192,19 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q)
|
||||
lenct,
|
||||
dist;
|
||||
float res = -1.0;
|
||||
ITEM **item;
|
||||
int size = q->size;
|
||||
ITEM **item;
|
||||
int size = q->size;
|
||||
|
||||
item = SortAndUniqItems( GETOPERAND(q), GETQUERY(q), &size);
|
||||
if ( size < 2 ) {
|
||||
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);
|
||||
WEP_SETPOS(POSNULL[1], MAXENTRYPOS - 1);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
@ -220,7 +230,7 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q)
|
||||
{
|
||||
for (p = 0; p < lenct; p++)
|
||||
{
|
||||
dist = Abs((int)WEP_GETPOS(post[l]) - (int)WEP_GETPOS(ct[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;
|
||||
@ -248,11 +258,11 @@ calc_rank_or(float *w, tsvector * t, QUERYTYPE * q)
|
||||
j,
|
||||
i;
|
||||
float res = -1.0;
|
||||
ITEM **item;
|
||||
int size = q->size;
|
||||
ITEM **item;
|
||||
int size = q->size;
|
||||
|
||||
*(uint16 *) POSNULL = lengthof(POSNULL) - 1;
|
||||
item = SortAndUniqItems( GETOPERAND(q), GETQUERY(q), &size);
|
||||
item = SortAndUniqItems(GETOPERAND(q), GETQUERY(q), &size);
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
@ -279,7 +289,7 @@ calc_rank_or(float *w, tsvector * t, QUERYTYPE * q)
|
||||
res = 1.0 - (1.0 - res) * (1.0 - wpos(post[j]));
|
||||
}
|
||||
}
|
||||
pfree( item );
|
||||
pfree(item);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -288,7 +298,7 @@ calc_rank(float *w, tsvector * t, QUERYTYPE * q, int4 method)
|
||||
{
|
||||
ITEM *item = GETQUERY(q);
|
||||
float res = 0.0;
|
||||
int len;
|
||||
int len;
|
||||
|
||||
if (!t->size || !q->size)
|
||||
return 0.0;
|
||||
@ -304,11 +314,12 @@ calc_rank(float *w, tsvector * t, QUERYTYPE * q, int4 method)
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
res /= log( (float)(cnt_length(t)+1) ) / log(2.0);
|
||||
res /= log((float) (cnt_length(t) + 1)) / log(2.0);
|
||||
break;
|
||||
case 2:
|
||||
len = cnt_length(t);
|
||||
if ( len > 0 ) res /= (float)len;
|
||||
if (len > 0)
|
||||
res /= (float) len;
|
||||
break;
|
||||
default:
|
||||
/* internal error */
|
||||
@ -406,7 +417,7 @@ checkcondition_DR(void *checkval, ITEM * val)
|
||||
|
||||
while (ptr - ((ChkDocR *) checkval)->doc < ((ChkDocR *) checkval)->len)
|
||||
{
|
||||
if ( val == ptr->item || compareITEM( &val, &(ptr->item) ) == 0 )
|
||||
if (val == ptr->item || compareITEM(&val, &(ptr->item)) == 0)
|
||||
return true;
|
||||
ptr++;
|
||||
}
|
||||
@ -496,12 +507,11 @@ Cover(DocRepresentation * doc, int len, QUERYTYPE * query, int *pos, int *p, int
|
||||
ch.doc = f;
|
||||
ch.len = (doc + lastpos) - f + 1;
|
||||
*pos = f - doc + 1;
|
||||
SortAndUniqOperand = GETOPERAND(query);
|
||||
SortAndUniqOperand = GETOPERAND(query);
|
||||
if (TS_execute(GETQUERY(query), &ch, false, checkcondition_DR))
|
||||
{
|
||||
/*
|
||||
* elog(NOTICE,"OP:%d NP:%d P:%d Q:%d", *pos, lastpos, *p,
|
||||
* *q);
|
||||
* elog(NOTICE,"OP:%d NP:%d P:%d Q:%d", *pos, lastpos, *p, *q);
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
@ -611,11 +621,12 @@ rank_cd(PG_FUNCTION_ARGS)
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
res /= log( (float)(cnt_length(txt)+1) );
|
||||
res /= log((float) (cnt_length(txt) + 1));
|
||||
break;
|
||||
case 2:
|
||||
len = cnt_length(txt);
|
||||
if ( len > 0 ) res /= (float)len;
|
||||
if (len > 0)
|
||||
res /= (float) len;
|
||||
break;
|
||||
default:
|
||||
/* internal error */
|
||||
@ -638,7 +649,7 @@ rank_cd_def(PG_FUNCTION_ARGS)
|
||||
Int32GetDatum(-1),
|
||||
PG_GETARG_DATUM(0),
|
||||
PG_GETARG_DATUM(1),
|
||||
(PG_NARGS() == 3) ? PG_GETARG_DATUM(2) : Int32GetDatum(DEF_NORM_METHOD)
|
||||
(PG_NARGS() == 3) ? PG_GETARG_DATUM(2) : Int32GetDatum(DEF_NORM_METHOD)
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -1,69 +1,85 @@
|
||||
|
||||
#include <stdlib.h> /* for calloc, free */
|
||||
#include <stdlib.h> /* for calloc, free */
|
||||
#include "header.h"
|
||||
|
||||
extern struct SN_env * SN_create_env(int S_size, int I_size, int B_size)
|
||||
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;
|
||||
struct SN_env *z = (struct SN_env *) calloc(1, sizeof(struct SN_env));
|
||||
|
||||
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 (z == NULL)
|
||||
return NULL;
|
||||
z->p = create_s();
|
||||
if (z->p == NULL)
|
||||
goto error;
|
||||
if (S_size)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (I_size)
|
||||
{
|
||||
z->I = (int *) calloc(I_size, sizeof(int));
|
||||
if (z->I == NULL) goto error;
|
||||
z->I_size = I_size;
|
||||
}
|
||||
z->S = (symbol * *) calloc(S_size, sizeof(symbol *));
|
||||
if (z->S == NULL)
|
||||
goto error;
|
||||
|
||||
if (B_size)
|
||||
{
|
||||
z->B = (symbol *) calloc(B_size, sizeof(symbol));
|
||||
if (z->B == NULL) goto error;
|
||||
z->B_size = B_size;
|
||||
}
|
||||
for (i = 0; i < S_size; i++)
|
||||
{
|
||||
z->S[i] = create_s();
|
||||
if (z->S[i] == NULL)
|
||||
goto error;
|
||||
}
|
||||
z->S_size = S_size;
|
||||
}
|
||||
|
||||
return z;
|
||||
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;
|
||||
SN_close_env(z);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern void SN_close_env(struct SN_env * z)
|
||||
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);
|
||||
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)
|
||||
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;
|
||||
}
|
||||
int err = replace_s(z, 0, z->l, size, s, NULL);
|
||||
|
||||
z->c = 0;
|
||||
return err;
|
||||
}
|
||||
|
@ -11,17 +11,24 @@ typedef unsigned char symbol;
|
||||
|
||||
*/
|
||||
|
||||
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;
|
||||
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 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);
|
||||
|
||||
extern int SN_set_current(struct SN_env * z, int size, const symbol * s);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,15 +2,16 @@
|
||||
/* This file was generated automatically by the Snowball to ANSI C compiler */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
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 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);
|
||||
extern int english_ISO_8859_1_stem(struct SN_env * z);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -8,51 +8,51 @@
|
||||
|
||||
#define HEAD 2*sizeof(int)
|
||||
|
||||
#define SIZE(p) ((int *)(p))[-1]
|
||||
#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 *);
|
||||
{
|
||||
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 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 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_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 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 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 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 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 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 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);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,15 +2,16 @@
|
||||
/* This file was generated automatically by the Snowball to ANSI C compiler */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
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 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);
|
||||
extern int russian_KOI8_R_stem(struct SN_env * z);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -9,19 +9,26 @@
|
||||
|
||||
#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 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);
|
||||
extern void
|
||||
lose_s(symbol * p)
|
||||
{
|
||||
if (p == NULL)
|
||||
return;
|
||||
free((char *) p - HEAD);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -32,280 +39,435 @@ extern void lose_s(symbol * p) {
|
||||
-- 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;
|
||||
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_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;
|
||||
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_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
|
||||
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_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;
|
||||
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(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
|
||||
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(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
|
||||
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(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_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(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
|
||||
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) {
|
||||
extern int
|
||||
find_among(struct SN_env * z, struct among * v, int v_size)
|
||||
{
|
||||
|
||||
int i = 0;
|
||||
int j = v_size;
|
||||
int i = 0;
|
||||
int j = v_size;
|
||||
|
||||
int c = z->c; int l = z->l;
|
||||
symbol * q = z->p + c;
|
||||
int c = z->c;
|
||||
int l = z->l;
|
||||
symbol *q = z->p + c;
|
||||
|
||||
struct among * w;
|
||||
struct among *w;
|
||||
|
||||
int common_i = 0;
|
||||
int common_j = 0;
|
||||
int common_i = 0;
|
||||
int common_j = 0;
|
||||
|
||||
int first_key_inspected = 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 */
|
||||
while (1)
|
||||
{
|
||||
int k = i + ((j - i) >> 1);
|
||||
int diff = 0;
|
||||
int common = common_i < common_j ? common_i : common_j; /* smaller */
|
||||
|
||||
/* - but now we need to go round once more to get
|
||||
v->s inspected. This looks messy, but is actually
|
||||
the optimal approach. */
|
||||
w = v + k;
|
||||
{
|
||||
int i;
|
||||
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
extern int
|
||||
find_among_b(struct SN_env * z, struct among * v, int v_size)
|
||||
{
|
||||
|
||||
int i = 0;
|
||||
int j = v_size;
|
||||
int i = 0;
|
||||
int j = v_size;
|
||||
|
||||
int c = z->c; int lb = z->lb;
|
||||
symbol * q = z->p + c - 1;
|
||||
int c = z->c;
|
||||
int lb = z->lb;
|
||||
symbol *q = z->p + c - 1;
|
||||
|
||||
struct among * w;
|
||||
struct among *w;
|
||||
|
||||
int common_i = 0;
|
||||
int common_j = 0;
|
||||
int common_i = 0;
|
||||
int common_j = 0;
|
||||
|
||||
int first_key_inspected = 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;
|
||||
}
|
||||
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;
|
||||
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
|
||||
@ -313,134 +475,182 @@ static symbol * increase_size(symbol * p, int n) {
|
||||
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)
|
||||
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;
|
||||
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) {
|
||||
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 (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);
|
||||
fprintf(stderr, "faulty slice operation:\n");
|
||||
debug(z, -1, 0);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
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_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_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
|
||||
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_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 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 *
|
||||
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;
|
||||
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");
|
||||
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
|
||||
|
@ -58,8 +58,8 @@ readstoplist(text *in, StopList * s)
|
||||
/* if path is relative, take it as relative to share dir */
|
||||
if (!is_absolute_path(filename))
|
||||
{
|
||||
char sharepath[MAXPGPATH];
|
||||
char *absfn;
|
||||
char sharepath[MAXPGPATH];
|
||||
char *absfn;
|
||||
|
||||
get_share_path(my_exec_path, sharepath);
|
||||
absfn = palloc(strlen(sharepath) + strlen(filename) + 2);
|
||||
|
@ -185,9 +185,9 @@ reset_cfg(void)
|
||||
static int
|
||||
comparecfg(const void *a, const void *b)
|
||||
{
|
||||
if ( ((TSCfgInfo *) a)->id == ((TSCfgInfo *) b)->id )
|
||||
if (((TSCfgInfo *) a)->id == ((TSCfgInfo *) b)->id)
|
||||
return 0;
|
||||
return ( ((TSCfgInfo *) a)->id < ((TSCfgInfo *) b)->id ) ? -1 : 1;
|
||||
return (((TSCfgInfo *) a)->id < ((TSCfgInfo *) b)->id) ? -1 : 1;
|
||||
}
|
||||
|
||||
TSCfgInfo *
|
||||
@ -289,17 +289,17 @@ parsetext_v2(TSCfgInfo * cfg, PRSTEXT * prs, char *buf, int4 buflen)
|
||||
|
||||
prsobj->prs = (void *) DatumGetPointer(
|
||||
FunctionCall2(
|
||||
&(prsobj->start_info),
|
||||
PointerGetDatum(buf),
|
||||
Int32GetDatum(buflen)
|
||||
&(prsobj->start_info),
|
||||
PointerGetDatum(buf),
|
||||
Int32GetDatum(buflen)
|
||||
)
|
||||
);
|
||||
|
||||
while ((type = DatumGetInt32(FunctionCall3(
|
||||
&(prsobj->getlexeme_info),
|
||||
PointerGetDatum(prsobj->prs),
|
||||
PointerGetDatum(prsobj->prs),
|
||||
PointerGetDatum(&lemm),
|
||||
PointerGetDatum(&lenlemm)))) != 0)
|
||||
PointerGetDatum(&lenlemm)))) != 0)
|
||||
{
|
||||
|
||||
if (lenlemm >= MAXSTRLEN)
|
||||
@ -322,16 +322,16 @@ parsetext_v2(TSCfgInfo * cfg, PRSTEXT * prs, char *buf, int4 buflen)
|
||||
for (i = 0; i < cfg->map[type].len; i++)
|
||||
{
|
||||
DictInfo *dict = finddict(DatumGetObjectId(cfg->map[type].dict_id[i]));
|
||||
TSLexeme *norms,
|
||||
*ptr;
|
||||
TSLexeme *norms,
|
||||
*ptr;
|
||||
|
||||
norms = ptr = (TSLexeme *) DatumGetPointer(
|
||||
FunctionCall3(
|
||||
&(dict->lexize_info),
|
||||
PointerGetDatum(dict->dictionary),
|
||||
PointerGetDatum(lemm),
|
||||
PointerGetDatum(lenlemm)
|
||||
)
|
||||
FunctionCall3(
|
||||
&(dict->lexize_info),
|
||||
PointerGetDatum(dict->dictionary),
|
||||
PointerGetDatum(lemm),
|
||||
PointerGetDatum(lenlemm)
|
||||
)
|
||||
);
|
||||
if (!norms) /* dictionary doesn't know this lexem */
|
||||
continue;
|
||||
@ -355,8 +355,7 @@ parsetext_v2(TSCfgInfo * cfg, PRSTEXT * prs, char *buf, int4 buflen)
|
||||
prs->curwords++;
|
||||
}
|
||||
pfree(norms);
|
||||
break; /* lexem already normalized or is stop
|
||||
* word */
|
||||
break; /* lexem already normalized or is stop word */
|
||||
}
|
||||
}
|
||||
|
||||
@ -425,17 +424,17 @@ hlparsetext(TSCfgInfo * cfg, HLPRSTEXT * prs, QUERYTYPE * query, char *buf, int4
|
||||
|
||||
prsobj->prs = (void *) DatumGetPointer(
|
||||
FunctionCall2(
|
||||
&(prsobj->start_info),
|
||||
PointerGetDatum(buf),
|
||||
Int32GetDatum(buflen)
|
||||
&(prsobj->start_info),
|
||||
PointerGetDatum(buf),
|
||||
Int32GetDatum(buflen)
|
||||
)
|
||||
);
|
||||
|
||||
while ((type = DatumGetInt32(FunctionCall3(
|
||||
&(prsobj->getlexeme_info),
|
||||
PointerGetDatum(prsobj->prs),
|
||||
PointerGetDatum(prsobj->prs),
|
||||
PointerGetDatum(&lemm),
|
||||
PointerGetDatum(&lenlemm)))) != 0)
|
||||
PointerGetDatum(&lenlemm)))) != 0)
|
||||
{
|
||||
|
||||
if (lenlemm >= MAXSTRLEN)
|
||||
@ -460,16 +459,16 @@ hlparsetext(TSCfgInfo * cfg, HLPRSTEXT * prs, QUERYTYPE * query, char *buf, int4
|
||||
for (i = 0; i < cfg->map[type].len; i++)
|
||||
{
|
||||
DictInfo *dict = finddict(DatumGetObjectId(cfg->map[type].dict_id[i]));
|
||||
TSLexeme *norms,
|
||||
*ptr;
|
||||
TSLexeme *norms,
|
||||
*ptr;
|
||||
|
||||
norms = ptr = (TSLexeme *) DatumGetPointer(
|
||||
FunctionCall3(
|
||||
&(dict->lexize_info),
|
||||
PointerGetDatum(dict->dictionary),
|
||||
PointerGetDatum(lemm),
|
||||
PointerGetDatum(lenlemm)
|
||||
)
|
||||
FunctionCall3(
|
||||
&(dict->lexize_info),
|
||||
PointerGetDatum(dict->dictionary),
|
||||
PointerGetDatum(lemm),
|
||||
PointerGetDatum(lenlemm)
|
||||
)
|
||||
);
|
||||
if (!norms) /* dictionary doesn't know this lexem */
|
||||
continue;
|
||||
@ -481,8 +480,7 @@ hlparsetext(TSCfgInfo * cfg, HLPRSTEXT * prs, QUERYTYPE * query, char *buf, int4
|
||||
ptr++;
|
||||
}
|
||||
pfree(norms);
|
||||
break; /* lexem already normalized or is stop
|
||||
* word */
|
||||
break; /* lexem already normalized or is stop word */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,10 +505,10 @@ ts_stat_sql(text *txt, text *ws)
|
||||
if (!isnull)
|
||||
{
|
||||
newstat = (tsstat *) DatumGetPointer(DirectFunctionCall2(
|
||||
ts_accum,
|
||||
PointerGetDatum(stat),
|
||||
data
|
||||
));
|
||||
ts_accum,
|
||||
PointerGetDatum(stat),
|
||||
data
|
||||
));
|
||||
if (stat != newstat && stat)
|
||||
pfree(stat);
|
||||
stat = newstat;
|
||||
|
@ -52,7 +52,7 @@ comparePos(const void *a, const void *b)
|
||||
{
|
||||
if (WEP_GETPOS(*(WordEntryPos *) a) == WEP_GETPOS(*(WordEntryPos *) b))
|
||||
return 0;
|
||||
return (WEP_GETPOS(*(WordEntryPos *) a)> WEP_GETPOS(*(WordEntryPos *) b)) ? 1 : -1;
|
||||
return (WEP_GETPOS(*(WordEntryPos *) a) > WEP_GETPOS(*(WordEntryPos *) b)) ? 1 : -1;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -328,7 +328,7 @@ gettoken_tsvector(TI_IN_STATE * state)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("wrong position info")));
|
||||
WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 0 );
|
||||
WEP_SETWEIGHT(state->pos[*(uint16 *) (state->pos)], 0);
|
||||
state->state = WAITPOSDELIM;
|
||||
}
|
||||
else
|
||||
@ -342,35 +342,35 @@ gettoken_tsvector(TI_IN_STATE * state)
|
||||
state->state = INPOSINFO;
|
||||
else if (tolower(*(state->prsbuf)) == 'a' || *(state->prsbuf) == '*')
|
||||
{
|
||||
if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
|
||||
if (WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error")));
|
||||
WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 3 );
|
||||
WEP_SETWEIGHT(state->pos[*(uint16 *) (state->pos)], 3);
|
||||
}
|
||||
else if (tolower(*(state->prsbuf)) == 'b')
|
||||
{
|
||||
if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
|
||||
if (WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error")));
|
||||
WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 2 );
|
||||
WEP_SETWEIGHT(state->pos[*(uint16 *) (state->pos)], 2);
|
||||
}
|
||||
else if (tolower(*(state->prsbuf)) == 'c')
|
||||
{
|
||||
if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
|
||||
if (WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error")));
|
||||
WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 1 );
|
||||
WEP_SETWEIGHT(state->pos[*(uint16 *) (state->pos)], 1);
|
||||
}
|
||||
else if (tolower(*(state->prsbuf)) == 'd')
|
||||
{
|
||||
if ( WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]) )
|
||||
if (WEP_GETWEIGHT(state->pos[*(uint16 *) (state->pos)]))
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("syntax error")));
|
||||
WEP_SETWEIGHT( state->pos[*(uint16 *) (state->pos)], 0 );
|
||||
WEP_SETWEIGHT(state->pos[*(uint16 *) (state->pos)], 0);
|
||||
}
|
||||
else if (isspace((unsigned char) *(state->prsbuf)) ||
|
||||
*(state->prsbuf) == '\0')
|
||||
@ -906,9 +906,9 @@ tsearch2(PG_FUNCTION_ARGS)
|
||||
if (funcoid != InvalidOid)
|
||||
{
|
||||
text *txttmp = (text *) DatumGetPointer(OidFunctionCall1(
|
||||
funcoid,
|
||||
PointerGetDatum(txt_toasted)
|
||||
));
|
||||
funcoid,
|
||||
PointerGetDatum(txt_toasted)
|
||||
));
|
||||
|
||||
txt = (text *) DatumGetPointer(PG_DETOAST_DATUM(PointerGetDatum(txttmp)));
|
||||
if (txt == txttmp)
|
||||
|
@ -24,13 +24,13 @@ typedef struct
|
||||
#define MAXSTRPOS ( 1<<20 )
|
||||
|
||||
/*
|
||||
Equivalent to
|
||||
Equivalent to
|
||||
typedef struct
|
||||
{
|
||||
uint16
|
||||
weight:2,
|
||||
pos:14;
|
||||
} WordEntryPos;
|
||||
uint16
|
||||
weight:2,
|
||||
pos:14;
|
||||
} WordEntryPos;
|
||||
|
||||
*/
|
||||
|
||||
@ -39,8 +39,8 @@ typedef uint16 WordEntryPos;
|
||||
#define WEP_GETWEIGHT(x) ( (x) >> 14 )
|
||||
#define WEP_GETPOS(x) ( (x) & 0x3fff )
|
||||
|
||||
#define WEP_SETWEIGHT(x,v) (x) = ( (v) << 14 ) | ( (x) & 0x3fff )
|
||||
#define WEP_SETPOS(x,v) (x) = ( (x) & 0xc000 ) | ( (v) & 0x3fff )
|
||||
#define WEP_SETWEIGHT(x,v) (x) = ( (v) << 14 ) | ( (x) & 0x3fff )
|
||||
#define WEP_SETPOS(x,v) (x) = ( (x) & 0xc000 ) | ( (v) & 0x3fff )
|
||||
|
||||
|
||||
#define MAXENTRYPOS (1<<14)
|
||||
|
@ -106,7 +106,7 @@ setweight(PG_FUNCTION_ARGS)
|
||||
p = POSDATAPTR(out, entry);
|
||||
while (j--)
|
||||
{
|
||||
WEP_SETWEIGHT(*p,w);
|
||||
WEP_SETWEIGHT(*p, w);
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
@ -92,9 +92,9 @@ reset_prs(void)
|
||||
static int
|
||||
compareprs(const void *a, const void *b)
|
||||
{
|
||||
if ( ((WParserInfo *) a)->prs_id == ((WParserInfo *) b)->prs_id )
|
||||
if (((WParserInfo *) a)->prs_id == ((WParserInfo *) b)->prs_id)
|
||||
return 0;
|
||||
return ( ((WParserInfo *) a)->prs_id < ((WParserInfo *) b)->prs_id ) ? -1 : 1;
|
||||
return (((WParserInfo *) a)->prs_id < ((WParserInfo *) b)->prs_id) ? -1 : 1;
|
||||
}
|
||||
|
||||
WParserInfo *
|
||||
@ -194,7 +194,7 @@ setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx, Oid prsid)
|
||||
st = (TypeStorage *) palloc(sizeof(TypeStorage));
|
||||
st->cur = 0;
|
||||
st->list = (LexDescr *) DatumGetPointer(
|
||||
OidFunctionCall1(prs->lextype, PointerGetDatum(prs->prs))
|
||||
OidFunctionCall1(prs->lextype, PointerGetDatum(prs->prs))
|
||||
);
|
||||
funcctx->user_fctx = (void *) st;
|
||||
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
|
||||
@ -375,8 +375,8 @@ prs_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
|
||||
prs->prs = (void *) DatumGetPointer(
|
||||
FunctionCall2(
|
||||
&(prs->start_info),
|
||||
PointerGetDatum(VARDATA(txt)),
|
||||
Int32GetDatum(VARSIZE(txt) - VARHDRSZ)
|
||||
PointerGetDatum(VARDATA(txt)),
|
||||
Int32GetDatum(VARSIZE(txt) - VARHDRSZ)
|
||||
)
|
||||
);
|
||||
|
||||
@ -384,7 +384,7 @@ prs_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
|
||||
&(prs->getlexeme_info),
|
||||
PointerGetDatum(prs->prs),
|
||||
PointerGetDatum(&lex),
|
||||
PointerGetDatum(&llen)))) != 0)
|
||||
PointerGetDatum(&llen)))) != 0)
|
||||
{
|
||||
|
||||
if (st->cur >= st->len)
|
||||
@ -588,7 +588,7 @@ headline_byname(PG_FUNCTION_ARGS)
|
||||
ObjectIdGetDatum(name2id_cfg(cfg)),
|
||||
PG_GETARG_DATUM(1),
|
||||
PG_GETARG_DATUM(2),
|
||||
(PG_NARGS() > 3) ? PG_GETARG_DATUM(3) : PointerGetDatum(NULL)
|
||||
(PG_NARGS() > 3) ? PG_GETARG_DATUM(3) : PointerGetDatum(NULL)
|
||||
);
|
||||
|
||||
PG_FREE_IF_COPY(cfg, 0);
|
||||
@ -606,6 +606,6 @@ headline_current(PG_FUNCTION_ARGS)
|
||||
ObjectIdGetDatum(get_currcfg()),
|
||||
PG_GETARG_DATUM(0),
|
||||
PG_GETARG_DATUM(1),
|
||||
(PG_NARGS() > 2) ? PG_GETARG_DATUM(2) : PointerGetDatum(NULL)
|
||||
(PG_NARGS() > 2) ? PG_GETARG_DATUM(2) : PointerGetDatum(NULL)
|
||||
));
|
||||
}
|
||||
|
@ -242,7 +242,7 @@ prsd_headline(PG_FUNCTION_ARGS)
|
||||
if (min_words >= max_words)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("MinWords should be less than MaxWords")));
|
||||
errmsg("MinWords should be less than MaxWords")));
|
||||
if (min_words <= 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
|
Reference in New Issue
Block a user