80#define tmpalloc(sz) MemoryContextAlloc(Conf->buildCxt, (sz))
81#define tmpalloc0(sz) MemoryContextAllocZero(Conf->buildCxt, (sz))
96 "Ispell dictionary init context",
127#define COMPACT_ALLOC_CHUNK 8192
128#define COMPACT_MAX_REQ 1024
146 if (size >
Conf->avail)
152 result =
Conf->firstfree;
153 Conf->firstfree += size;
159#define cpalloc(size) compact_palloc0(Conf, size)
160#define cpalloc0(size) compact_palloc0(Conf, size)
189#define MAXNORMLEN 256
191#define STRNCMP(s,p) strncmp( (s), (p), strlen(p) )
192#define GETWCHAR(W,L,N,T) ( ((const uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] )
193#define GETCHAR(A,N,T) GETWCHAR( (A)->repl, (A)->replen, N, T )
207 (*(
SPELL *
const *)
s2)->p.flag);
220 if (
fv1->flag.i ==
fv2->flag.i)
223 return (
fv1->flag.i >
fv2->flag.i) ? 1 : -1;
260 int l1 =
strlen((
const char *)
s1) - 1,
263 while (l1 >= 0 && l2 >= 0)
281strbncmp(
const unsigned char *
s1,
const unsigned char *
s2,
size_t count)
283 int l1 =
strlen((
const char *)
s1) - 1,
287 while (l1 >= 0 && l2 >= 0 && l > 0)
317 if (
a1->type <
a2->type)
319 if (
a1->type >
a2->type)
324 return strbcmp((
const unsigned char *)
a1->repl,
325 (
const unsigned char *)
a2->repl);
364 switch (
Conf->flagMode)
388 errmsg(
"affix flag \"%s\" is out of range",
401 errmsg(
"invalid affix flag \"%s\"",
410 errmsg(
"invalid affix flag \"%s\"",
418 errmsg(
"invalid character in affix flag \"%s\"",
427 elog(
ERROR,
"unrecognized type of Conf->flagMode: %d",
438 errmsg(
"invalid affix flag \"%s\" with \"long\" flag value",
500 Conf->mspell = 1024 * 20;
528 errmsg(
"could not open dictionary file \"%s\": %m",
564 if (
isspace((
unsigned char) *s))
681 const char *
find,
const char *repl,
int type)
685 if (
Conf->naffixes >=
Conf->maffixes)
699 Affix =
Conf->Affix +
Conf->naffixes;
702 if (
strcmp(mask,
".") == 0 || *mask ==
'\0')
774#define PAE_WAIT_MASK 0
776#define PAE_WAIT_FIND 2
778#define PAE_WAIT_REPL 4
780#define PAE_WAIT_TYPE 6
781#define PAE_WAIT_FLAG 7
859 char *repl,
char *mask)
892 elog(
ERROR,
"unrecognized state in parse_ooaffentry: %d",
921 *mask = *
find = *repl =
'\0';
1011 errmsg(
"syntax error")));
1021 return (*mask && (*
find || *repl));
1041 errmsg(
"invalid affix flag \"%s\"", s)));
1045 errmsg(
"affix flag \"%s\" is out of range", s)));
1070 while (*s &&
isspace((
unsigned char) *s))
1076 errmsg(
"syntax error")));
1080 while (*s && !
isspace((
unsigned char) *s) && *s !=
'\n')
1090 if (
Conf->nCompoundAffixFlag >=
Conf->mCompoundAffixFlag)
1092 if (
Conf->mCompoundAffixFlag)
1094 Conf->mCompoundAffixFlag *= 2;
1101 Conf->mCompoundAffixFlag = 10;
1111 Conf->usecompound =
true;
1112 Conf->nCompoundAffixFlag++;
1128 if (
Conf->nCompoundAffixFlag == 0)
1158 if (
Conf->useFlagAliases && *s !=
'\0')
1168 errmsg(
"invalid affix alias \"%s\"", s)));
1180 errmsg(
"invalid affix alias \"%s\"", s)));
1214 Conf->usecompound =
false;
1215 Conf->useFlagAliases =
false;
1221 errmsg(
"could not open affix file \"%s\": %m",
1263 while (*s &&
isspace((
unsigned char) *s))
1270 else if (
STRNCMP(s,
"num") == 0)
1272 else if (
STRNCMP(s,
"default") != 0)
1275 errmsg(
"Ispell dictionary supports only "
1276 "\"default\", \"long\", "
1277 "and \"num\" flag values")));
1285 if (
Conf->nCompoundAffixFlag > 1)
1292 errmsg(
"could not open affix file \"%s\": %m",
1309 if (
STRNCMP(ptype,
"af") == 0)
1312 if (!
Conf->useFlagAliases)
1314 Conf->useFlagAliases =
true;
1319 errmsg(
"invalid number of flag vector aliases")));
1342 errmsg(
"number of aliases exceeds specified number %d",
1435 bool oldformat =
false;
1441 errmsg(
"could not open affix file \"%s\": %m",
1444 Conf->usecompound =
false;
1445 Conf->useFlagAliases =
false;
1462 while (*s && !
isspace((
unsigned char) *s))
1464 while (*s &&
isspace((
unsigned char) *s))
1470 Conf->usecompound =
true;
1495 while (*s &&
isspace((
unsigned char) *s))
1522 if (*s ==
'\0' || *s ==
'#' || *s ==
'\n' || *s ==
':' ||
1556 errmsg(
"affix file contains both old-style and new-style commands")));
1576 if (*
Conf->AffixData[
a1] ==
'\0')
1578 else if (*
Conf->AffixData[
a2] ==
'\0')
1582 if (
Conf->nAffixData + 1 >=
Conf->lenAffixData)
1584 Conf->lenAffixData *= 2;
1586 sizeof(
char *) *
Conf->lenAffixData);
1589 ptr =
Conf->AffixData +
Conf->nAffixData;
1612 return Conf->nAffixData - 1;
1646 for (
i = low;
i < high;
i++)
1661 for (
i = low;
i < high;
i++)
1662 if (
Conf->Spell[
i]->p.d.len > level)
1676 if (
Conf->Spell[
i]->p.d.len == level + 1)
1680 if (
data->isword &&
data->affix !=
Conf->Spell[
i]->p.d.affix)
1694 data->affix =
Conf->Spell[
i]->p.d.affix;
1731 if (
Conf->useFlagAliases)
1733 for (
i = 0;
i <
Conf->nspell;
i++)
1737 if (*
Conf->Spell[
i]->p.flag !=
'\0')
1744 errmsg(
"invalid affix alias \"%s\"",
1745 Conf->Spell[
i]->p.flag)));
1749 errmsg(
"invalid affix alias \"%s\"",
1750 Conf->Spell[
i]->p.flag)));
1751 if (*end !=
'\0' && !
isdigit((
unsigned char) *end) && !
isspace((
unsigned char) *end))
1754 errmsg(
"invalid affix alias \"%s\"",
1755 Conf->Spell[
i]->p.flag)));
1778 for (
i = 0;
i <
Conf->nspell;
i++)
1793 for (
i = 0;
i <
Conf->nspell;
i++)
1801 Conf->Spell[
i]->p.flag);
1839 for (
i = low;
i < high;
i++)
1857 for (
i = low;
i < high;
i++)
1858 if (
Conf->Affix[
i].replen > level)
1879 if (
Conf->Affix[
i].replen == level + 1)
1881 aff[naff++] =
Conf->Affix +
i;
1919 Conf->Suffix = Affix;
1924 Conf->Prefix = Affix;
1929 if (
Conf->Affix[
i].replen == 0)
1941 if (
Conf->Affix[
i].replen == 0)
1963 for (
i = 0;
i <
Conf->nAffixData;
i++)
1981 if (
Conf->naffixes == 0)
1985 if (
Conf->naffixes > 1)
1990 for (
i = 0;
i <
Conf->naffixes;
i++)
2001 if (ptr ==
Conf->CompoundAffix ||
2003 strbncmp((
const unsigned char *) (ptr - 1)->affix,
2004 (
const unsigned char *) Affix->
repl,
2040 while (node && *level <
wrdlen)
2213 for (
j = 0;
j < prefix->naff;
j++)
2222 pnode = prefix->node;
2238 for (
i = 0;
i < suffix->
naff;
i++)
2255 for (
j = 0;
j < prefix->naff;
j++)
2267 pnode = prefix->node;
2302 while ((*ptr)->affix)
2304 if (
len > (*ptr)->len &&
strncmp((*ptr)->affix,
word, (*ptr)->len) == 0)
2307 issuffix = (*ptr)->issuffix;
2309 return (issuffix) ?
len : 0;
2318 while ((*ptr)->affix)
2323 issuffix = (*ptr)->issuffix;
2325 return (issuffix) ?
len : 0;
2384 int compoundflag = 0;
2393 while (level < wordlen)
2421 else if (level == wordlen - 1)
2471 else if (level == wordlen - 1)
2485 if (wordlen == level + 1)
2503 node =
Conf->Dictionary;
2529 (*lcur)->lexeme =
word;
2530 (*lcur)->flags = flags;
2533 (*lcur)->lexeme =
NULL;
2559 if (
Conf->usecompound)
2578 for (
i = 0;
i < var->
nstem - 1;
i++)
#define Assert(condition)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void err(int eval, const char *fmt,...)
#define palloc_object(type)
#define palloc_array(type, count)
#define palloc0_array(type, count)
static const FormData_pg_attribute a1
static const FormData_pg_attribute a2
int pg_mblen_cstr(const char *mbstr)
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurTransactionContext
char * pnstrdup(const char *in, Size len)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static XLogRecPtr startpos
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define qsort(a, b, c, d)
static void prefixes(struct vars *v)
int pg_regcomp(regex_t *re, const chr *string, size_t len, int flags, Oid collation)
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
static int find(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
int pg_regexec(regex_t *re, const chr *string, size_t len, size_t search_start, rm_detail_t *details, size_t nmatch, regmatch_t pmatch[], int flags)
void RS_compile(Regis *r, bool issuffix, const char *str)
bool RS_execute(Regis *r, char *str)
bool RS_isRegis(const char *str)
void NIStartBuild(IspellDict *Conf)
#define GETWCHAR(W, L, N, T)
static int strbcmp(const unsigned char *s1, const unsigned char *s2)
void NIFinishBuild(IspellDict *Conf)
void NIImportAffixes(IspellDict *Conf, const char *filename)
static char * cpstrdup(IspellDict *Conf, const char *str)
static int parse_ooaffentry(char *str, char *type, char *flag, char *find, char *repl, char *mask)
static const char * getAffixFlagSet(IspellDict *Conf, char *s)
static SPNode * mkSPNode(IspellDict *Conf, int low, int high, int level)
static int cmpspell(const void *s1, const void *s2)
static bool get_nextfield(char **str, char *next)
void NISortDictionary(IspellDict *Conf)
static int FindWord(IspellDict *Conf, const char *word, const char *affixflag, int flag)
static AffixNodeData * FindAffixes(AffixNode *node, const char *word, int wrdlen, int *level, int type)
static char * CheckAffix(const char *word, size_t len, AFFIX *Affix, int flagflags, char *newword, int *baselen)
static SplitVar * CopyVar(SplitVar *s, int makedup)
static void NIAddSpell(IspellDict *Conf, const char *word, const char *flag)
static void NIImportOOAffixes(IspellDict *Conf, const char *filename)
#define COMPACT_ALLOC_CHUNK
static void addNorm(TSLexeme **lres, TSLexeme **lcur, char *word, int flags, uint16 NVariant)
static void NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask, const char *find, const char *repl, int type)
static char * findchar(char *str, int c)
static const char * VoidString
static char ** NormalizeSubWord(IspellDict *Conf, const char *word, int flag)
static int CheckCompoundAffixes(CMPDAffix **ptr, const char *word, int len, bool CheckInPlace)
static void getNextFlagFromString(IspellDict *Conf, const char **sflagset, char *sflag)
void NISortAffixes(IspellDict *Conf)
static int cmpcmdflag(const void *f1, const void *f2)
static char * findchar2(char *str, int c1, int c2)
static void setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry, char *s, uint32 val)
void NIImportDictionary(IspellDict *Conf, const char *filename)
static AffixNode * mkANode(IspellDict *Conf, int low, int high, int level, int type)
static bool IsAffixFlagInUse(IspellDict *Conf, int affix, const char *affixflag)
static bool parse_affentry(char *str, char *mask, char *find, char *repl)
static SplitVar * SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, const char *word, int wordlen, int startpos, int minpos)
static uint32 makeCompoundFlags(IspellDict *Conf, int affix)
static int cmpspellaffix(const void *s1, const void *s2)
static int strbncmp(const unsigned char *s1, const unsigned char *s2, size_t count)
TSLexeme * NINormalizeWord(IspellDict *Conf, const char *word)
static int MergeAffix(IspellDict *Conf, int a1, int a2)
static void * compact_palloc0(IspellDict *Conf, size_t size)
static int getCompoundAffixFlagValue(IspellDict *Conf, const char *s)
static void AddStem(SplitVar *v, char *word)
static int addToResult(char **forms, char **cur, char *word)
static void mkVoidAffix(IspellDict *Conf, bool issuffix, int startsuffix)
static bool isAffixInUse(IspellDict *Conf, const char *affixflag)
static void addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
static char * lowerstr_ctx(IspellDict *Conf, const char *src)
static int cmpaffix(const void *s1, const void *s2)
#define FF_COMPOUNDFLAGMASK
#define FF_COMPOUNDFORBIDFLAG
#define FF_COMPOUNDPERMITFLAG
#define FF_COMPOUNDMIDDLE
void check_stack_depth(void)
AffixNodeData data[FLEXIBLE_ARRAY_MEMBER]
union CompoundAffixFlag::@143 flag
SPNodeData data[FLEXIBLE_ARRAY_MEMBER]
union aff_struct::@142 reg
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
char * tsearch_readline(tsearch_readline_state *stp)
void tsearch_readline_end(tsearch_readline_state *stp)
static int ts_copychar_with_len(void *dest, const void *src, int length)
static int ts_copychar_cstr(void *dest, const void *src)