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)
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",
927 *mask = *
find = *repl =
'\0';
1006 errmsg(
"syntax error")));
1023 errmsg(
"syntax error")));
1033 return (*mask && (*
find || *repl));
1053 errmsg(
"invalid affix flag \"%s\"", s)));
1057 errmsg(
"affix flag \"%s\" is out of range", s)));
1082 while (*s &&
isspace((
unsigned char) *s))
1088 errmsg(
"syntax error")));
1092 while (*s && !
isspace((
unsigned char) *s) && *s !=
'\n')
1104 if (
Conf->nCompoundAffixFlag >=
Conf->mCompoundAffixFlag)
1106 if (
Conf->mCompoundAffixFlag)
1108 Conf->mCompoundAffixFlag *= 2;
1115 Conf->mCompoundAffixFlag = 10;
1125 Conf->usecompound =
true;
1126 Conf->nCompoundAffixFlag++;
1142 if (
Conf->nCompoundAffixFlag == 0)
1172 if (
Conf->useFlagAliases && *s !=
'\0')
1182 errmsg(
"invalid affix alias \"%s\"", s)));
1194 errmsg(
"invalid affix alias \"%s\"", s)));
1228 Conf->usecompound =
false;
1229 Conf->useFlagAliases =
false;
1235 errmsg(
"could not open affix file \"%s\": %m",
1277 while (*s &&
isspace((
unsigned char) *s))
1284 else if (
STRNCMP(s,
"num") == 0)
1286 else if (
STRNCMP(s,
"default") != 0)
1289 errmsg(
"Ispell dictionary supports only "
1290 "\"default\", \"long\", "
1291 "and \"num\" flag values")));
1299 if (
Conf->nCompoundAffixFlag > 1)
1306 errmsg(
"could not open affix file \"%s\": %m",
1323 if (
STRNCMP(ptype,
"af") == 0)
1326 if (!
Conf->useFlagAliases)
1328 Conf->useFlagAliases =
true;
1333 errmsg(
"invalid number of flag vector aliases")));
1356 errmsg(
"number of aliases exceeds specified number %d",
1449 bool oldformat =
false;
1455 errmsg(
"could not open affix file \"%s\": %m",
1458 Conf->usecompound =
false;
1459 Conf->useFlagAliases =
false;
1476 while (*s && !
isspace((
unsigned char) *s))
1478 while (*s &&
isspace((
unsigned char) *s))
1484 Conf->usecompound =
true;
1509 while (*s &&
isspace((
unsigned char) *s))
1536 if (*s ==
'\0' || *s ==
'#' || *s ==
'\n' || *s ==
':' ||
1570 errmsg(
"affix file contains both old-style and new-style commands")));
1590 if (*
Conf->AffixData[
a1] ==
'\0')
1592 else if (*
Conf->AffixData[
a2] ==
'\0')
1596 if (
Conf->nAffixData + 1 >=
Conf->lenAffixData)
1598 Conf->lenAffixData *= 2;
1600 sizeof(
char *) *
Conf->lenAffixData);
1603 ptr =
Conf->AffixData +
Conf->nAffixData;
1626 return Conf->nAffixData - 1;
1660 for (
i = low;
i < high;
i++)
1675 for (
i = low;
i < high;
i++)
1676 if (
Conf->Spell[
i]->p.d.len > level)
1690 if (
Conf->Spell[
i]->p.d.len == level + 1)
1694 if (
data->isword &&
data->affix !=
Conf->Spell[
i]->p.d.affix)
1708 data->affix =
Conf->Spell[
i]->p.d.affix;
1745 if (
Conf->useFlagAliases)
1747 for (
i = 0;
i <
Conf->nspell;
i++)
1751 if (*
Conf->Spell[
i]->p.flag !=
'\0')
1758 errmsg(
"invalid affix alias \"%s\"",
1759 Conf->Spell[
i]->p.flag)));
1763 errmsg(
"invalid affix alias \"%s\"",
1764 Conf->Spell[
i]->p.flag)));
1765 if (*end !=
'\0' && !
isdigit((
unsigned char) *end) && !
isspace((
unsigned char) *end))
1768 errmsg(
"invalid affix alias \"%s\"",
1769 Conf->Spell[
i]->p.flag)));
1792 for (
i = 0;
i <
Conf->nspell;
i++)
1807 for (
i = 0;
i <
Conf->nspell;
i++)
1815 Conf->Spell[
i]->p.flag);
1853 for (
i = low;
i < high;
i++)
1871 for (
i = low;
i < high;
i++)
1872 if (
Conf->Affix[
i].replen > level)
1893 if (
Conf->Affix[
i].replen == level + 1)
1895 aff[naff++] =
Conf->Affix +
i;
1933 Conf->Suffix = Affix;
1938 Conf->Prefix = Affix;
1943 if (
Conf->Affix[
i].replen == 0)
1955 if (
Conf->Affix[
i].replen == 0)
1977 for (
i = 0;
i <
Conf->nAffixData;
i++)
1995 if (
Conf->naffixes == 0)
1999 if (
Conf->naffixes > 1)
2004 for (
i = 0;
i <
Conf->naffixes;
i++)
2015 if (ptr ==
Conf->CompoundAffix ||
2017 strbncmp((
const unsigned char *) (ptr - 1)->affix,
2018 (
const unsigned char *) Affix->
repl,
2054 while (node && *level <
wrdlen)
2262 for (
j = 0;
j < prefix->naff;
j++)
2271 pnode = prefix->node;
2287 for (
i = 0;
i < suffix->
naff;
i++)
2304 for (
j = 0;
j < prefix->naff;
j++)
2316 pnode = prefix->node;
2351 while ((*ptr)->affix)
2353 if (
len > (*ptr)->len &&
strncmp((*ptr)->affix,
word, (*ptr)->len) == 0)
2356 issuffix = (*ptr)->issuffix;
2358 return (issuffix) ?
len : 0;
2367 while ((*ptr)->affix)
2372 issuffix = (*ptr)->issuffix;
2374 return (issuffix) ?
len : 0;
2433 int compoundflag = 0;
2442 while (level < wordlen)
2470 else if (level == wordlen - 1)
2520 else if (level == wordlen - 1)
2534 if (wordlen == level + 1)
2552 node =
Conf->Dictionary;
2578 (*lcur)->lexeme =
word;
2579 (*lcur)->flags = flags;
2582 (*lcur)->lexeme =
NULL;
2608 if (
Conf->usecompound)
2627 for (
i = 0;
i < var->
nstem - 1;
i++)
#define Assert(condition)
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int errcode(int sqlerrcode)
#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 void addCompoundAffixFlagValue(IspellDict *Conf, const char *s, uint32 val)
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 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 bool parse_affentry(const char *str, char *mask, char *find, char *repl)
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 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::@148 flag
SPNodeData data[FLEXIBLE_ARRAY_MEMBER]
union aff_struct::@147 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)