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);
363 switch (
Conf->flagMode)
387 errmsg(
"affix flag \"%s\" is out of range",
400 errmsg(
"invalid affix flag \"%s\"",
409 errmsg(
"invalid affix flag \"%s\"",
417 errmsg(
"invalid character in affix flag \"%s\"",
426 elog(
ERROR,
"unrecognized type of Conf->flagMode: %d",
437 errmsg(
"invalid affix flag \"%s\" with \"long\" flag value",
499 Conf->mspell = 1024 * 20;
527 errmsg(
"could not open dictionary file \"%s\": %m",
563 if (
isspace((
unsigned char) *s))
680 const char *
find,
const char *repl,
int type)
684 if (
Conf->naffixes >=
Conf->maffixes)
698 Affix =
Conf->Affix +
Conf->naffixes;
701 if (
strcmp(mask,
".") == 0 || *mask ==
'\0')
773#define PAE_WAIT_MASK 0
775#define PAE_WAIT_FIND 2
777#define PAE_WAIT_REPL 4
779#define PAE_WAIT_TYPE 6
780#define PAE_WAIT_FLAG 7
860 char *repl,
char *mask)
893 elog(
ERROR,
"unrecognized state in parse_ooaffentry: %d",
922 *mask = *
find = *repl =
'\0';
1016 errmsg(
"syntax error")));
1026 return (*mask && (*
find || *repl));
1046 errmsg(
"invalid affix flag \"%s\"", s)));
1050 errmsg(
"affix flag \"%s\" is out of range", s)));
1076 while (*s &&
isspace((
unsigned char) *s))
1082 errmsg(
"syntax error")));
1086 while (*s && !
isspace((
unsigned char) *s) && *s !=
'\n')
1096 if (
Conf->nCompoundAffixFlag >=
Conf->mCompoundAffixFlag)
1098 if (
Conf->mCompoundAffixFlag)
1100 Conf->mCompoundAffixFlag *= 2;
1107 Conf->mCompoundAffixFlag = 10;
1117 Conf->usecompound =
true;
1118 Conf->nCompoundAffixFlag++;
1134 if (
Conf->nCompoundAffixFlag == 0)
1164 if (
Conf->useFlagAliases && *s !=
'\0')
1174 errmsg(
"invalid affix alias \"%s\"", s)));
1186 errmsg(
"invalid affix alias \"%s\"", s)));
1220 Conf->usecompound =
false;
1221 Conf->useFlagAliases =
false;
1227 errmsg(
"could not open affix file \"%s\": %m",
1269 while (*s &&
isspace((
unsigned char) *s))
1276 else if (
STRNCMP(s,
"num") == 0)
1278 else if (
STRNCMP(s,
"default") != 0)
1281 errmsg(
"Ispell dictionary supports only "
1282 "\"default\", \"long\", "
1283 "and \"num\" flag values")));
1291 if (
Conf->nCompoundAffixFlag > 1)
1298 errmsg(
"could not open affix file \"%s\": %m",
1315 if (
STRNCMP(ptype,
"af") == 0)
1318 if (!
Conf->useFlagAliases)
1320 Conf->useFlagAliases =
true;
1325 errmsg(
"invalid number of flag vector aliases")));
1348 errmsg(
"number of aliases exceeds specified number %d",
1441 bool oldformat =
false;
1447 errmsg(
"could not open affix file \"%s\": %m",
1450 Conf->usecompound =
false;
1451 Conf->useFlagAliases =
false;
1468 while (*s && !
isspace((
unsigned char) *s))
1470 while (*s &&
isspace((
unsigned char) *s))
1476 Conf->usecompound =
true;
1501 while (*s &&
isspace((
unsigned char) *s))
1529 if (*s ==
'\0' || *s ==
'#' || *s ==
'\n' || *s ==
':' ||
1563 errmsg(
"affix file contains both old-style and new-style commands")));
1583 if (*
Conf->AffixData[
a1] ==
'\0')
1585 else if (*
Conf->AffixData[
a2] ==
'\0')
1589 if (
Conf->nAffixData + 1 >=
Conf->lenAffixData)
1591 Conf->lenAffixData *= 2;
1593 sizeof(
char *) *
Conf->lenAffixData);
1596 ptr =
Conf->AffixData +
Conf->nAffixData;
1619 return Conf->nAffixData - 1;
1653 for (
i = low;
i < high;
i++)
1668 for (
i = low;
i < high;
i++)
1669 if (
Conf->Spell[
i]->p.d.len > level)
1683 if (
Conf->Spell[
i]->p.d.len == level + 1)
1687 if (
data->isword &&
data->affix !=
Conf->Spell[
i]->p.d.affix)
1701 data->affix =
Conf->Spell[
i]->p.d.affix;
1738 if (
Conf->useFlagAliases)
1740 for (
i = 0;
i <
Conf->nspell;
i++)
1744 if (*
Conf->Spell[
i]->p.flag !=
'\0')
1751 errmsg(
"invalid affix alias \"%s\"",
1752 Conf->Spell[
i]->p.flag)));
1756 errmsg(
"invalid affix alias \"%s\"",
1757 Conf->Spell[
i]->p.flag)));
1758 if (*end !=
'\0' && !
isdigit((
unsigned char) *end) && !
isspace((
unsigned char) *end))
1761 errmsg(
"invalid affix alias \"%s\"",
1762 Conf->Spell[
i]->p.flag)));
1785 for (
i = 0;
i <
Conf->nspell;
i++)
1800 for (
i = 0;
i <
Conf->nspell;
i++)
1808 Conf->Spell[
i]->p.flag);
1846 for (
i = low;
i < high;
i++)
1864 for (
i = low;
i < high;
i++)
1865 if (
Conf->Affix[
i].replen > level)
1886 if (
Conf->Affix[
i].replen == level + 1)
1888 aff[naff++] =
Conf->Affix +
i;
1926 Conf->Suffix = Affix;
1931 Conf->Prefix = Affix;
1936 if (
Conf->Affix[
i].replen == 0)
1948 if (
Conf->Affix[
i].replen == 0)
1970 for (
i = 0;
i <
Conf->nAffixData;
i++)
1988 if (
Conf->naffixes == 0)
1992 if (
Conf->naffixes > 1)
1997 for (
i = 0;
i <
Conf->naffixes;
i++)
2008 if (ptr ==
Conf->CompoundAffix ||
2010 strbncmp((
const unsigned char *) (ptr - 1)->affix,
2011 (
const unsigned char *) Affix->
repl,
2047 while (node && *level <
wrdlen)
2220 for (
j = 0;
j < prefix->naff;
j++)
2229 pnode = prefix->node;
2245 for (
i = 0;
i < suffix->
naff;
i++)
2262 for (
j = 0;
j < prefix->naff;
j++)
2274 pnode = prefix->node;
2309 while ((*ptr)->affix)
2311 if (
len > (*ptr)->len &&
strncmp((*ptr)->affix,
word, (*ptr)->len) == 0)
2314 issuffix = (*ptr)->issuffix;
2316 return (issuffix) ?
len : 0;
2325 while ((*ptr)->affix)
2330 issuffix = (*ptr)->issuffix;
2332 return (issuffix) ?
len : 0;
2391 int compoundflag = 0;
2400 while (level < wordlen)
2428 else if (level == wordlen - 1)
2478 else if (level == wordlen - 1)
2492 if (wordlen == level + 1)
2510 node =
Conf->Dictionary;
2536 (*lcur)->lexeme =
word;
2537 (*lcur)->flags = flags;
2540 (*lcur)->lexeme =
NULL;
2566 if (
Conf->usecompound)
2585 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_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
int pg_mblen(const char *mbstr)
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)
int t_isalpha(const char *ptr)
void tsearch_readline_end(tsearch_readline_state *stp)