summaryrefslogtreecommitdiff
path: root/src/backend/tsearch/spell.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/tsearch/spell.c')
-rw-r--r--src/backend/tsearch/spell.c139
1 files changed, 71 insertions, 68 deletions
diff --git a/src/backend/tsearch/spell.c b/src/backend/tsearch/spell.c
index 8b46ea5bf91..c43c206c030 100644
--- a/src/backend/tsearch/spell.c
+++ b/src/backend/tsearch/spell.c
@@ -25,23 +25,23 @@
*
* A compiled dictionary is stored in the IspellDict structure. Compilation of
* a dictionary is divided into the several steps:
- * - NIImportDictionary() - stores each word of a .dict file in the
- * temporary Spell field.
- * - NIImportAffixes() - stores affix rules of an .affix file in the
- * Affix field (not temporary) if an .affix file has the Ispell format.
- * -> NIImportOOAffixes() - stores affix rules if an .affix file has the
- * Hunspell format. The AffixData field is initialized if AF parameter
- * is defined.
- * - NISortDictionary() - builds a prefix tree (Trie) from the words list
- * and stores it in the Dictionary field. The words list is got from the
- * Spell field. The AffixData field is initialized if AF parameter is not
- * defined.
- * - NISortAffixes():
- * - builds a list of compond affixes from the affix list and stores it
- * in the CompoundAffix.
- * - builds prefix trees (Trie) from the affix list for prefixes and suffixes
- * and stores them in Suffix and Prefix fields.
- * The affix list is got from the Affix field.
+ * - NIImportDictionary() - stores each word of a .dict file in the
+ * temporary Spell field.
+ * - NIImportAffixes() - stores affix rules of an .affix file in the
+ * Affix field (not temporary) if an .affix file has the Ispell format.
+ * -> NIImportOOAffixes() - stores affix rules if an .affix file has the
+ * Hunspell format. The AffixData field is initialized if AF parameter
+ * is defined.
+ * - NISortDictionary() - builds a prefix tree (Trie) from the words list
+ * and stores it in the Dictionary field. The words list is got from the
+ * Spell field. The AffixData field is initialized if AF parameter is not
+ * defined.
+ * - NISortAffixes():
+ * - builds a list of compond affixes from the affix list and stores it
+ * in the CompoundAffix.
+ * - builds prefix trees (Trie) from the affix list for prefixes and suffixes
+ * and stores them in Suffix and Prefix fields.
+ * The affix list is got from the Affix field.
*
* Memory management
* -----------------
@@ -204,14 +204,14 @@ static int
cmpspellaffix(const void *s1, const void *s2)
{
return (strcmp((*(SPELL *const *) s1)->p.flag,
- (*(SPELL *const *) s2)->p.flag));
+ (*(SPELL *const *) s2)->p.flag));
}
static int
cmpcmdflag(const void *f1, const void *f2)
{
- CompoundAffixFlag *fv1 = (CompoundAffixFlag *) f1,
- *fv2 = (CompoundAffixFlag *) f2;
+ CompoundAffixFlag *fv1 = (CompoundAffixFlag *) f1,
+ *fv2 = (CompoundAffixFlag *) f2;
Assert(fv1->flagMode == fv2->flagMode);
@@ -335,15 +335,15 @@ cmpaffix(const void *s1, const void *s2)
*
* Depending on the flagMode an affix string can have the following format:
* - FM_CHAR: ABCD
- * Here we have 4 flags: A, B, C and D
+ * Here we have 4 flags: A, B, C and D
* - FM_LONG: ABCDE*
- * Here we have 3 flags: AB, CD and E*
+ * Here we have 3 flags: AB, CD and E*
* - FM_NUM: 200,205,50
- * Here we have 3 flags: 200, 205 and 50
+ * Here we have 3 flags: 200, 205 and 50
*
* Conf: current dictionary.
* sflagset: the set of affix flags. Returns a reference to the start of a next
- * affix flag.
+ * affix flag.
* sflag: returns an affix flag from sflagset.
*/
static void
@@ -358,7 +358,7 @@ getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
maxstep = (Conf->flagMode == FM_LONG) ? 2 : 1;
- while(**sflagset)
+ while (**sflagset)
{
switch (Conf->flagMode)
{
@@ -413,8 +413,8 @@ getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
{
ereport(ERROR,
(errcode(ERRCODE_CONFIG_FILE_ERROR),
- errmsg("invalid character in affix flag \"%s\"",
- *sflagset)));
+ errmsg("invalid character in affix flag \"%s\"",
+ *sflagset)));
}
*sflagset += pg_mblen(*sflagset);
@@ -432,8 +432,8 @@ getNextFlagFromString(IspellDict *Conf, char **sflagset, char *sflag)
if (Conf->flagMode == FM_LONG && maxstep > 0)
ereport(ERROR,
- (errcode(ERRCODE_CONFIG_FILE_ERROR),
- errmsg("invalid affix flag \"%s\" with long flag value", sbuf)));
+ (errcode(ERRCODE_CONFIG_FILE_ERROR),
+ errmsg("invalid affix flag \"%s\" with long flag value", sbuf)));
*sflag = '\0';
}
@@ -527,6 +527,7 @@ NIImportDictionary(IspellDict *Conf, const char *filename)
{
char *s,
*pstr;
+
/* Set of affix flags */
const char *flag;
@@ -581,11 +582,11 @@ NIImportDictionary(IspellDict *Conf, const char *filename)
* meter/GMD
*
* The affix rule with the flag S:
- * SFX S y ies [^aeiou]y
+ * SFX S y ies [^aeiou]y
* is not presented here.
*
* The affix rule with the flag M:
- * SFX M 0 's .
+ * SFX M 0 's .
* is presented here.
*
* Conf: current dictionary.
@@ -620,9 +621,9 @@ FindWord(IspellDict *Conf, const char *word, char *affixflag, int flag)
if (flag == 0)
{
/*
- * The word can be formed only with another word.
- * And in the flag parameter there is not a sign
- * that we search compound words.
+ * The word can be formed only with another word. And
+ * in the flag parameter there is not a sign that we
+ * search compound words.
*/
if (StopMiddle->compoundflag & FF_COMPOUNDONLY)
return 0;
@@ -658,21 +659,21 @@ FindWord(IspellDict *Conf, const char *word, char *affixflag, int flag)
* Conf: current dictionary.
* flag: affix flag ('\' in the below example).
* flagflags: set of flags from the flagval field for this affix rule. This set
- * is listed after '/' character in the added string (repl).
+ * is listed after '/' character in the added string (repl).
*
- * For example L flag in the hunspell_sample.affix:
- * SFX \ 0 Y/L [^Y]
+ * For example L flag in the hunspell_sample.affix:
+ * SFX \ 0 Y/L [^Y]
*
* mask: condition for search ('[^Y]' in the above example).
* find: stripping characters from beginning (at prefix) or end (at suffix)
- * of the word ('0' in the above example, 0 means that there is not
- * stripping character).
+ * of the word ('0' in the above example, 0 means that there is not
+ * stripping character).
* repl: adding string after stripping ('Y' in the above example).
* type: FF_SUFFIX or FF_PREFIX.
*/
static void
-NIAddAffix(IspellDict *Conf, const char* flag, char flagflags, const char *mask,
- const char *find, const char *repl, int type)
+NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask,
+ const char *find, const char *repl, int type)
{
AFFIX *Affix;
@@ -1024,8 +1025,8 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry,
{
if (Conf->flagMode == FM_NUM)
{
- char *next;
- int i;
+ char *next;
+ int i;
i = strtol(s, &next, 10);
if (s == next || errno == ERANGE)
@@ -1056,10 +1057,10 @@ setCompoundAffixFlagValue(IspellDict *Conf, CompoundAffixFlag *entry,
static void
addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
{
- CompoundAffixFlag *newValue;
- char sbuf[BUFSIZ];
- char *sflag;
- int clen;
+ CompoundAffixFlag *newValue;
+ char sbuf[BUFSIZ];
+ char *sflag;
+ int clen;
while (*s && t_isspace(s))
s += pg_mblen(s);
@@ -1088,7 +1089,7 @@ addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
Conf->mCompoundAffixFlag *= 2;
Conf->CompoundAffixFlags = (CompoundAffixFlag *)
repalloc((void *) Conf->CompoundAffixFlags,
- Conf->mCompoundAffixFlag * sizeof(CompoundAffixFlag));
+ Conf->mCompoundAffixFlag * sizeof(CompoundAffixFlag));
}
else
{
@@ -1113,11 +1114,11 @@ addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
static int
getCompoundAffixFlagValue(IspellDict *Conf, char *s)
{
- uint32 flag = 0;
+ uint32 flag = 0;
CompoundAffixFlag *found,
- key;
- char sflag[BUFSIZ];
- char *flagcur;
+ key;
+ char sflag[BUFSIZ];
+ char *flagcur;
if (Conf->nCompoundAffixFlag == 0)
return 0;
@@ -1151,8 +1152,8 @@ getAffixFlagSet(IspellDict *Conf, char *s)
{
if (Conf->useFlagAliases && *s != '\0')
{
- int curaffix;
- char *end;
+ int curaffix;
+ char *end;
curaffix = strtol(s, &end, 10);
if (s == end || errno == ERANGE)
@@ -1161,9 +1162,10 @@ getAffixFlagSet(IspellDict *Conf, char *s)
errmsg("invalid affix alias \"%s\"", s)));
if (curaffix > 0 && curaffix <= Conf->nAffixData)
+
/*
- * Do not subtract 1 from curaffix
- * because empty string was added in NIImportOOAffixes
+ * Do not subtract 1 from curaffix because empty string was added
+ * in NIImportOOAffixes
*/
return Conf->AffixData[curaffix];
else
@@ -1260,9 +1262,9 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
Conf->flagMode = FM_NUM;
else if (STRNCMP(s, "default") != 0)
ereport(ERROR,
- (errcode(ERRCODE_CONFIG_FILE_ERROR),
- errmsg("Ispell dictionary supports only default, "
- "long and num flag value")));
+ (errcode(ERRCODE_CONFIG_FILE_ERROR),
+ errmsg("Ispell dictionary supports only default, "
+ "long and num flag value")));
}
}
@@ -1303,8 +1305,8 @@ NIImportOOAffixes(IspellDict *Conf, const char *filename)
naffix = atoi(sflag);
if (naffix == 0)
ereport(ERROR,
- (errcode(ERRCODE_CONFIG_FILE_ERROR),
- errmsg("invalid number of flag vector aliases")));
+ (errcode(ERRCODE_CONFIG_FILE_ERROR),
+ errmsg("invalid number of flag vector aliases")));
/* Also reserve place for empty flag set */
naffix++;
@@ -1596,7 +1598,8 @@ MergeAffix(IspellDict *Conf, int a1, int a2)
static uint32
makeCompoundFlags(IspellDict *Conf, int affix)
{
- char *str = Conf->AffixData[affix];
+ char *str = Conf->AffixData[affix];
+
return (getCompoundAffixFlagValue(Conf, str) & FF_COMPOUNDFLAGMASK);
}
@@ -1700,14 +1703,14 @@ NISortDictionary(IspellDict *Conf)
/* compress affixes */
/*
- * If we use flag aliases then we need to use Conf->AffixData filled
- * in the NIImportOOAffixes().
+ * If we use flag aliases then we need to use Conf->AffixData filled in
+ * the NIImportOOAffixes().
*/
if (Conf->useFlagAliases)
{
for (i = 0; i < Conf->nspell; i++)
{
- char *end;
+ char *end;
if (*Conf->Spell[i]->p.flag != '\0')
{
@@ -1762,7 +1765,7 @@ NISortDictionary(IspellDict *Conf)
curaffix++;
Assert(curaffix < naffix);
Conf->AffixData[curaffix] = cpstrdup(Conf,
- Conf->Spell[i]->p.flag);
+ Conf->Spell[i]->p.flag);
}
Conf->Spell[i]->p.d.affix = curaffix;
@@ -2219,8 +2222,8 @@ NormalizeSubWord(IspellDict *Conf, char *word, int flag)
if (CheckAffix(newword, swrdlen, prefix->aff[j], flag, pnewword, &baselen))
{
/* prefix success */
- char *ff = (prefix->aff[j]->flagflags & suffix->aff[i]->flagflags & FF_CROSSPRODUCT) ?
- VoidString : prefix->aff[j]->flag;
+ char *ff = (prefix->aff[j]->flagflags & suffix->aff[i]->flagflags & FF_CROSSPRODUCT) ?
+ VoidString : prefix->aff[j]->flag;
if (FindWord(Conf, pnewword, ff, flag))
cur += addToResult(forms, cur, pnewword);