78 #define tmpalloc(sz) MemoryContextAlloc(Conf->buildCxt, (sz))
79 #define tmpalloc0(sz) MemoryContextAllocZero(Conf->buildCxt, (sz))
94 "Ispell dictionary init context",
125 #define COMPACT_ALLOC_CHUNK 8192
126 #define COMPACT_MAX_REQ 1024
144 if (size > Conf->
avail)
157 #define cpalloc(size) compact_palloc0(Conf, size)
158 #define cpalloc0(size) compact_palloc0(Conf, size)
186 #define MAX_NORM 1024
187 #define MAXNORMLEN 256
189 #define STRNCMP(s,p) strncmp( (s), (p), strlen(p) )
190 #define GETWCHAR(W,L,N,T) ( ((const uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] )
191 #define GETCHAR(A,N,T) GETWCHAR( (A)->repl, (A)->replen, N, T )
204 return strcmp((*(
SPELL *
const *)
s1)->p.flag,
205 (*(
SPELL *
const *)
s2)->p.flag);
218 if (fv1->
flag.
i == fv2->flag.i)
221 return (fv1->
flag.
i > fv2->flag.i) ? 1 : -1;
224 return strcmp(fv1->
flag.
s, fv2->flag.s);
258 int l1 = strlen((
const char *)
s1) - 1,
259 l2 = strlen((
const char *)
s2) - 1;
261 while (l1 >= 0 && l2 >= 0)
279 strbncmp(
const unsigned char *
s1,
const unsigned char *
s2,
size_t count)
281 int l1 = strlen((
const char *)
s1) - 1,
282 l2 = strlen((
const char *)
s2) - 1,
285 while (l1 >= 0 && l2 >= 0 && l > 0)
315 if (
a1->type <
a2->type)
317 if (
a1->type >
a2->type)
320 return strcmp(
a1->repl,
a2->repl);
322 return strbcmp((
const unsigned char *)
a1->repl,
323 (
const unsigned char *)
a2->repl);
355 bool met_comma =
false;
373 stop = (maxstep == 0);
376 s = strtol(*sflagset, &
next, 10);
377 if (*sflagset ==
next || errno == ERANGE)
379 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
380 errmsg(
"invalid affix flag \"%s\"", *sflagset)));
383 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
384 errmsg(
"affix flag \"%s\" is out of range",
386 sflag +=
sprintf(sflag,
"%0d", s);
396 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
397 errmsg(
"invalid affix flag \"%s\"",
401 else if (
t_iseq(*sflagset,
','))
405 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
406 errmsg(
"invalid affix flag \"%s\"",
413 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
414 errmsg(
"invalid character in affix flag \"%s\"",
423 elog(
ERROR,
"unrecognized type of Conf->flagMode: %d",
433 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
434 errmsg(
"invalid affix flag \"%s\" with \"long\" flag value",
461 Assert(affix < Conf->nAffixData);
469 if (strcmp(
flag, affixflag) == 0)
523 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
524 errmsg(
"could not open dictionary file \"%s\": %m",
613 StopLow = node->
data;
615 while (StopLow < StopHigh)
617 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
618 if (StopMiddle->
val == *ptr)
620 if (*(ptr + 1) ==
'\0' && StopMiddle->
isword)
642 node = StopMiddle->
node;
646 else if (StopMiddle->
val < *ptr)
647 StopLow = StopMiddle + 1;
649 StopHigh = StopMiddle;
651 if (StopLow >= StopHigh)
688 const char *
find,
const char *repl,
int type)
709 if (strcmp(mask,
".") == 0 || *mask ==
'\0')
734 tmask = (
char *)
tmpalloc(strlen(mask) + 3);
740 masklen = strlen(tmask);
755 DEFAULT_COLLATION_OID);
762 (
errcode(ERRCODE_INVALID_REGULAR_EXPRESSION),
763 errmsg(
"invalid regular expression: %s", errstr)));
782 if ((Affix->
replen = strlen(repl)) > 0)
790 #define PAE_WAIT_MASK 0
792 #define PAE_WAIT_FIND 2
794 #define PAE_WAIT_REPL 4
796 #define PAE_WAIT_TYPE 6
797 #define PAE_WAIT_FLAG 7
877 char *repl,
char *mask)
910 elog(
ERROR,
"unrecognized state in parse_ooaffentry: %d",
939 *mask = *
find = *repl =
'\0';
981 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
998 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1015 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1016 errmsg(
"syntax error")));
1032 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1033 errmsg(
"syntax error")));
1041 *pmask = *pfind = *prepl =
'\0';
1043 return (*mask && (*
find || *repl));
1058 i = strtol(s, &
next, 10);
1059 if (s ==
next || errno == ERANGE)
1061 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1062 errmsg(
"invalid affix flag \"%s\"", s)));
1065 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1066 errmsg(
"affix flag \"%s\" is out of range", s)));
1097 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1098 errmsg(
"syntax error")));
1102 while (*s && !
t_isspace(s) && *s !=
'\n')
1185 curaffix = strtol(s, &end, 10);
1186 if (s == end || errno == ERANGE)
1188 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1189 errmsg(
"invalid affix alias \"%s\"", s)));
1191 if (curaffix > 0 && curaffix < Conf->nAffixData)
1200 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1201 errmsg(
"invalid affix alias \"%s\"", s)));
1226 bool isSuffix =
false;
1241 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1242 errmsg(
"could not open affix file \"%s\": %m",
1253 if (
STRNCMP(recoded,
"COMPOUNDFLAG") == 0)
1256 else if (
STRNCMP(recoded,
"COMPOUNDBEGIN") == 0)
1259 else if (
STRNCMP(recoded,
"COMPOUNDLAST") == 0)
1263 else if (
STRNCMP(recoded,
"COMPOUNDEND") == 0)
1266 else if (
STRNCMP(recoded,
"COMPOUNDMIDDLE") == 0)
1269 else if (
STRNCMP(recoded,
"ONLYINCOMPOUND") == 0)
1272 else if (
STRNCMP(recoded,
"COMPOUNDPERMITFLAG") == 0)
1274 recoded + strlen(
"COMPOUNDPERMITFLAG"),
1276 else if (
STRNCMP(recoded,
"COMPOUNDFORBIDFLAG") == 0)
1278 recoded + strlen(
"COMPOUNDFORBIDFLAG"),
1280 else if (
STRNCMP(recoded,
"FLAG") == 0)
1282 char *s = recoded + strlen(
"FLAG");
1291 else if (
STRNCMP(s,
"num") == 0)
1293 else if (
STRNCMP(s,
"default") != 0)
1295 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1296 errmsg(
"Ispell dictionary supports only "
1297 "\"default\", \"long\", "
1298 "and \"num\" flag values")));
1312 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1313 errmsg(
"could not open affix file \"%s\": %m",
1330 if (
STRNCMP(ptype,
"af") == 0)
1336 naffix = atoi(sflag);
1339 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1340 errmsg(
"invalid number of flag vector aliases")));
1355 if (curaffix < naffix)
1362 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1363 errmsg(
"number of aliases exceeds specified number %d",
1369 if (fields_read < 4 ||
1373 sflaglen = strlen(sflag);
1384 if (fields_read == 4)
1386 isSuffix = (
STRNCMP(ptype,
"sfx") == 0);
1403 if ((ptr = strchr(repl,
'/')) != NULL)
1409 if ((ptr = strchr(prepl,
'/')) != NULL)
1418 NIAddAffix(Conf, sflag, flagflags | aflg, pmask, pfind, prepl,
1452 bool suffixes =
false;
1456 bool oldformat =
false;
1457 char *recoded = NULL;
1461 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1462 errmsg(
"could not open affix file \"%s\": %m",
1474 if (*pstr ==
'#' || *pstr ==
'\n')
1477 if (
STRNCMP(pstr,
"compoundwords") == 0)
1497 if (
STRNCMP(pstr,
"suffixes") == 0)
1504 if (
STRNCMP(pstr,
"prefixes") == 0)
1511 if (
STRNCMP(pstr,
"flag") == 0)
1544 if (*s ==
'\0' || *s ==
'#' || *s ==
'\n' || *s ==
':' ||
1553 if (
STRNCMP(recoded,
"COMPOUNDFLAG") == 0 ||
1554 STRNCMP(recoded,
"COMPOUNDMIN") == 0 ||
1555 STRNCMP(recoded,
"PFX") == 0 ||
1577 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1578 errmsg(
"affix file contains both old-style and new-style commands")));
1595 Assert(a1 < Conf->nAffixData && a2 < Conf->nAffixData);
1640 Assert(affix < Conf->nAffixData);
1659 char lastchar =
'\0';
1664 for (
i = low;
i < high;
i++)
1679 for (
i = low;
i < high;
i++)
1680 if (Conf->
Spell[
i]->
p.
d.len > level)
1694 if (Conf->
Spell[
i]->
p.
d.len == level + 1)
1696 bool clearCompoundOnly =
false;
1721 if (clearCompoundOnly)
1757 curaffix = strtol(Conf->
Spell[
i]->
p.
flag, &end, 10);
1758 if (Conf->
Spell[
i]->
p.
flag == end || errno == ERANGE)
1760 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1761 errmsg(
"invalid affix alias \"%s\"",
1763 if (curaffix < 0 || curaffix >= Conf->
nAffixData)
1765 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1766 errmsg(
"invalid affix alias \"%s\"",
1770 (
errcode(ERRCODE_CONFIG_FILE_ERROR),
1771 errmsg(
"invalid affix alias \"%s\"",
1783 Conf->
Spell[
i]->
p.
d.affix = curaffix;
1816 Assert(curaffix < naffix);
1821 Conf->
Spell[
i]->
p.
d.affix = curaffix;
1849 uint8 lastchar =
'\0';
1856 for (
i = low;
i < high;
i++)
1874 for (
i = low;
i < high;
i++)
1887 memcpy(
data->aff, aff,
sizeof(
AFFIX *) * naff);
1898 aff[naff++] = Conf->
Affix +
i;
1908 memcpy(
data->aff, aff,
sizeof(
AFFIX *) * naff);
1926 int start = (issuffix) ? startsuffix : 0;
1927 int end = (issuffix) ? Conf->
naffixes : startsuffix;
1935 Affix->data->node = Conf->
Suffix;
1945 for (
i = start;
i < end;
i++)
1954 Affix->data->naff = (
uint32) cnt;
1957 for (
i = start;
i < end;
i++)
1960 Affix->data->aff[cnt] = Conf->
Affix +
i;
2020 strbncmp((
const unsigned char *) (ptr - 1)->affix,
2021 (
const unsigned char *) Affix->
repl,
2057 while (node && *level < wrdlen)
2059 StopLow = node->
data;
2061 while (StopLow < StopHigh)
2063 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
2069 if (StopMiddle->
naff)
2071 node = StopMiddle->
node;
2075 StopLow = StopMiddle + 1;
2077 StopHigh = StopMiddle;
2079 if (StopLow >= StopHigh)
2125 strcpy(newword,
word);
2136 if (baselen && *baselen + strlen(Affix->
find) <= Affix->
replen)
2138 strcpy(newword, Affix->
find);
2159 newword_len = strlen(newword);
2180 if (forms ==
cur || strcmp(
word, *(
cur - 1)) != 0)
2197 int wrdlen = strlen(
word),
2230 for (
j = 0;
j < prefix->naff;
j++)
2239 pnode = prefix->node;
2255 for (
i = 0;
i < suffix->
naff;
i++)
2266 swrdlen = strlen(newword);
2272 for (
j = 0;
j < prefix->naff;
j++)
2274 if (
CheckAffix(newword, swrdlen, prefix->aff[
j],
flag, pnewword, &baselen))
2284 pnode = prefix->node;
2289 snode = suffix->
node;
2319 while ((*ptr)->affix)
2321 if (
len > (*ptr)->len && strncmp((*ptr)->affix,
word, (*ptr)->len) == 0)
2324 issuffix = (*ptr)->issuffix;
2326 return (issuffix) ?
len : 0;
2335 while ((*ptr)->affix)
2337 if (
len > (*ptr)->len && (affbegin = strstr(
word, (*ptr)->affix)) != NULL)
2339 len = (*ptr)->len + (affbegin -
word);
2340 issuffix = (*ptr)->issuffix;
2342 return (issuffix) ?
len : 0;
2396 int level = (snode) ? minpos :
startpos;
2401 int compoundflag = 0;
2403 notprobed = (
char *)
palloc(wordlen);
2404 memset(notprobed, 1, wordlen);
2407 while (level < wordlen)
2419 lenaff = level -
startpos + lenaff;
2421 if (!notprobed[
startpos + lenaff - 1])
2424 if (level + lenaff - 1 <= minpos)
2435 else if (level == wordlen - 1)
2445 char **sptr = subres;
2447 notprobed[
startpos + lenaff - 1] = 0;
2468 StopLow = node->
data;
2470 while (StopLow < StopHigh)
2472 StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
2476 StopLow = StopMiddle + 1;
2478 StopHigh = StopMiddle;
2481 if (StopLow < StopHigh)
2485 else if (level == wordlen - 1)
2491 if (StopMiddle->
isword &&
2499 if (wordlen == level + 1)
2523 node = StopMiddle->
node;
2543 (*lcur)->lexeme =
word;
2544 (*lcur)->flags = flags;
2545 (*lcur)->nvariant = NVariant;
2547 (*lcur)->lexeme = NULL;
2565 while (*ptr && (lcur - lres) <
MAX_NORM)
2567 addNorm(&lres, &lcur, *ptr, 0, NVariant++);
2575 int wordlen = strlen(
word);
2588 char **subptr = subres;
2592 for (
i = 0;
i < var->
nstem - 1;
i++)
2597 addNorm(&lres, &lcur, *subptr, 0, NVariant);
2603 var->
stem[0] = NULL;
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
static const FormData_pg_attribute a1
static const FormData_pg_attribute a2
Assert(fmt[strlen(fmt) - 1] !='\n')
int pg_mb2wchar_with_len(const char *from, pg_wchar *to, int len)
int pg_mblen(const char *mbstr)
char * pnstrdup(const char *in, Size len)
void MemoryContextRegisterResetCallback(MemoryContext context, MemoryContextCallback *cb)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurTransactionContext
MemoryContext CurrentMemoryContext
void * repalloc(void *pointer, Size size)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static XLogRecPtr startpos
#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 *, int, struct state *, struct state *)
size_t pg_regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size)
static int find(struct vars *, struct cnfa *, struct colormap *)
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 pg_regfree(regex_t *re)
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 * findchar2(char *str, int c1, int c2)
static SplitVar * SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, char *word, int wordlen, int startpos, int minpos)
static int parse_ooaffentry(char *str, char *type, char *flag, char *find, char *repl, char *mask)
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 char * cpstrdup(IspellDict *Conf, const char *str)
static void NIAddSpell(IspellDict *Conf, const char *word, const char *flag)
static SPNode * mkSPNode(IspellDict *Conf, int low, int high, int level)
static char * lowerstr_ctx(IspellDict *Conf, const char *src)
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 AffixNodeData * FindAffixes(AffixNode *node, const char *word, int wrdlen, int *level, int type)
static void NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask, const char *find, const char *repl, int type)
static AffixNode * mkANode(IspellDict *Conf, int low, int high, int level, int type)
static void getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
void NISortAffixes(IspellDict *Conf)
static int cmpcmdflag(const void *f1, const void *f2)
static SplitVar * CopyVar(SplitVar *s, int makedup)
static void setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry, char *s, uint32 val)
static int CheckCompoundAffixes(CMPDAffix **ptr, char *word, int len, bool CheckInPlace)
void NIImportDictionary(IspellDict *Conf, const char *filename)
static bool IsAffixFlagInUse(IspellDict *Conf, int affix, const char *affixflag)
static bool parse_affentry(char *str, char *mask, char *find, char *repl)
static char * findchar(char *str, int c)
static bool isAffixInUse(IspellDict *Conf, char *affixflag)
static uint32 makeCompoundFlags(IspellDict *Conf, int affix)
static int cmpspellaffix(const void *s1, const void *s2)
TSLexeme * NINormalizeWord(IspellDict *Conf, char *word)
static int strbncmp(const unsigned char *s1, const unsigned char *s2, size_t count)
static void regex_affix_deletion_callback(void *arg)
static char ** NormalizeSubWord(IspellDict *Conf, char *word, int flag)
static int getCompoundAffixFlagValue(IspellDict *Conf, char *s)
static int MergeAffix(IspellDict *Conf, int a1, int a2)
static char * getAffixFlagSet(IspellDict *Conf, char *s)
static void AddStem(SplitVar *v, char *word)
static void * compact_palloc0(IspellDict *Conf, size_t size)
static int addToResult(char **forms, char **cur, char *word)
static char * CheckAffix(const char *word, size_t len, AFFIX *Affix, int flagflags, char *newword, int *baselen)
static void mkVoidAffix(IspellDict *Conf, bool issuffix, int startsuffix)
static void addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
static int cmpaffix(const void *s1, const void *s2)
struct CompoundAffixFlag CompoundAffixFlag
#define FF_COMPOUNDFLAGMASK
#define FF_COMPOUNDFORBIDFLAG
#define FF_COMPOUNDPERMITFLAG
#define FF_COMPOUNDMIDDLE
AffixNodeData data[FLEXIBLE_ARRAY_MEMBER]
union CompoundAffixFlag::@128 flag
CompoundAffixFlag * CompoundAffixFlags
CMPDAffix * CompoundAffix
MemoryContextCallbackFunction func
SPNodeData data[FLEXIBLE_ARRAY_MEMBER]
MemoryContextCallback mcallback
aff_regex_struct * pregex
union aff_struct::@127 reg
union spell_struct::@125 p
struct spell_struct::@125::@126 d
char word[FLEXIBLE_ARRAY_MEMBER]
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
char * tsearch_readline(tsearch_readline_state *stp)
int t_isspace(const char *ptr)
int t_isdigit(const char *ptr)
int t_isalpha(const char *ptr)
int t_isprint(const char *ptr)
void tsearch_readline_end(tsearch_readline_state *stp)
char * lowerstr(const char *str)