PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
spell.h File Reference
#include "regex/regex.h"
#include "tsearch/dicts/regis.h"
#include "tsearch/ts_public.h"
Include dependency graph for spell.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SPNodeData
 
struct  SPNode
 
struct  spell_struct
 
struct  aff_struct
 
struct  AffixNodeData
 
struct  AffixNode
 
struct  CMPDAffix
 
struct  CompoundAffixFlag
 
struct  IspellDict
 

Macros

#define FF_COMPOUNDONLY   0x01
 
#define FF_COMPOUNDBEGIN   0x02
 
#define FF_COMPOUNDMIDDLE   0x04
 
#define FF_COMPOUNDLAST   0x08
 
#define FF_COMPOUNDFLAG
 
#define FF_COMPOUNDFLAGMASK   0x0f
 
#define SPNHDRSZ   (offsetof(SPNode,data))
 
#define SPELLHDRSZ   (offsetof(SPELL, word))
 
#define FF_COMPOUNDPERMITFLAG   0x10
 
#define FF_COMPOUNDFORBIDFLAG   0x20
 
#define FF_CROSSPRODUCT   0x40
 
#define FF_SUFFIX   1
 
#define FF_PREFIX   0
 
#define ANHRDSZ   (offsetof(AffixNode, data))
 
#define FLAGNUM_MAXSIZE   (1 << 16)
 

Typedefs

typedef struct SPNode SPNode
 
typedef struct spell_struct SPELL
 
typedef struct aff_struct AFFIX
 
typedef struct AffixNode AffixNode
 
typedef struct CompoundAffixFlag CompoundAffixFlag
 

Enumerations

enum  FlagMode { FM_CHAR , FM_LONG , FM_NUM }
 

Functions

TSLexemeNINormalizeWord (IspellDict *Conf, const char *word)
 
void NIStartBuild (IspellDict *Conf)
 
void NIImportAffixes (IspellDict *Conf, const char *filename)
 
void NIImportDictionary (IspellDict *Conf, const char *filename)
 
void NISortDictionary (IspellDict *Conf)
 
void NISortAffixes (IspellDict *Conf)
 
void NIFinishBuild (IspellDict *Conf)
 

Macro Definition Documentation

◆ ANHRDSZ

#define ANHRDSZ   (offsetof(AffixNode, data))

Definition at line 145 of file spell.h.

◆ FF_COMPOUNDBEGIN

#define FF_COMPOUNDBEGIN   0x02

Definition at line 43 of file spell.h.

◆ FF_COMPOUNDFLAG

#define FF_COMPOUNDFLAG
Value:
FF_COMPOUNDLAST )
#define FF_COMPOUNDBEGIN
Definition: spell.h:43
#define FF_COMPOUNDMIDDLE
Definition: spell.h:44

Definition at line 46 of file spell.h.

◆ FF_COMPOUNDFLAGMASK

#define FF_COMPOUNDFLAGMASK   0x0f

Definition at line 48 of file spell.h.

◆ FF_COMPOUNDFORBIDFLAG

#define FF_COMPOUNDFORBIDFLAG   0x20

Definition at line 114 of file spell.h.

◆ FF_COMPOUNDLAST

#define FF_COMPOUNDLAST   0x08

Definition at line 45 of file spell.h.

◆ FF_COMPOUNDMIDDLE

#define FF_COMPOUNDMIDDLE   0x04

Definition at line 44 of file spell.h.

◆ FF_COMPOUNDONLY

#define FF_COMPOUNDONLY   0x01

Definition at line 42 of file spell.h.

◆ FF_COMPOUNDPERMITFLAG

#define FF_COMPOUNDPERMITFLAG   0x10

Definition at line 113 of file spell.h.

◆ FF_CROSSPRODUCT

#define FF_CROSSPRODUCT   0x40

Definition at line 115 of file spell.h.

◆ FF_PREFIX

#define FF_PREFIX   0

Definition at line 122 of file spell.h.

◆ FF_SUFFIX

#define FF_SUFFIX   1

Definition at line 121 of file spell.h.

◆ FLAGNUM_MAXSIZE

#define FLAGNUM_MAXSIZE   (1 << 16)

Definition at line 182 of file spell.h.

◆ SPELLHDRSZ

#define SPELLHDRSZ   (offsetof(SPELL, word))

Definition at line 82 of file spell.h.

◆ SPNHDRSZ

#define SPNHDRSZ   (offsetof(SPNode,data))

Definition at line 56 of file spell.h.

Typedef Documentation

◆ AFFIX

typedef struct aff_struct AFFIX

◆ AffixNode

typedef struct AffixNode AffixNode

◆ CompoundAffixFlag

◆ SPELL

typedef struct spell_struct SPELL

◆ SPNode

typedef struct SPNode SPNode

Enumeration Type Documentation

◆ FlagMode

enum FlagMode
Enumerator
FM_CHAR 
FM_LONG 
FM_NUM 

Definition at line 157 of file spell.h.

158{
159 FM_CHAR, /* one character (like ispell) */
160 FM_LONG, /* two characters */
161 FM_NUM, /* number, >= 0 and < 65536 */
162} FlagMode;
FlagMode
Definition: spell.h:158
@ FM_LONG
Definition: spell.h:160
@ FM_CHAR
Definition: spell.h:159
@ FM_NUM
Definition: spell.h:161

Function Documentation

◆ NIFinishBuild()

void NIFinishBuild ( IspellDict Conf)

Definition at line 104 of file spell.c.

105{
106 /* Release no-longer-needed temp memory */
108 /* Just for cleanliness, zero the now-dangling pointers */
109 Conf->buildCxt = NULL;
110 Conf->Spell = NULL;
111 Conf->firstfree = NULL;
112 Conf->CompoundAffixFlags = NULL;
113}
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
MemoryContext buildCxt
Definition: spell.h:220
CompoundAffixFlag * CompoundAffixFlags
Definition: spell.h:210
char * firstfree
Definition: spell.h:228
SPELL ** Spell
Definition: spell.h:223

References IspellDict::buildCxt, IspellDict::CompoundAffixFlags, IspellDict::firstfree, MemoryContextDelete(), and IspellDict::Spell.

Referenced by dispell_init().

◆ NIImportAffixes()

void NIImportAffixes ( IspellDict Conf,
const char *  filename 
)

Definition at line 1429 of file spell.c.

1430{
1431 char *pstr = NULL;
1432 char flag[BUFSIZ];
1433 char mask[BUFSIZ];
1434 char find[BUFSIZ];
1435 char repl[BUFSIZ];
1436 char *s;
1437 bool suffixes = false;
1438 bool prefixes = false;
1439 char flagflags = 0;
1441 bool oldformat = false;
1442 char *recoded = NULL;
1443
1444 if (!tsearch_readline_begin(&trst, filename))
1445 ereport(ERROR,
1446 (errcode(ERRCODE_CONFIG_FILE_ERROR),
1447 errmsg("could not open affix file \"%s\": %m",
1448 filename)));
1449
1450 Conf->usecompound = false;
1451 Conf->useFlagAliases = false;
1452 Conf->flagMode = FM_CHAR;
1453
1454 while ((recoded = tsearch_readline(&trst)) != NULL)
1455 {
1456 pstr = str_tolower(recoded, strlen(recoded), DEFAULT_COLLATION_OID);
1457
1458 /* Skip comments and empty lines */
1459 if (*pstr == '#' || *pstr == '\n')
1460 goto nextline;
1461
1462 if (STRNCMP(pstr, "compoundwords") == 0)
1463 {
1464 /* Find case-insensitive L flag in non-lowercased string */
1465 s = findchar2(recoded, 'l', 'L');
1466 if (s)
1467 {
1468 while (*s && !isspace((unsigned char) *s))
1469 s += pg_mblen(s);
1470 while (*s && isspace((unsigned char) *s))
1471 s += pg_mblen(s);
1472
1473 if (*s && pg_mblen(s) == 1)
1474 {
1476 Conf->usecompound = true;
1477 }
1478 oldformat = true;
1479 goto nextline;
1480 }
1481 }
1482 if (STRNCMP(pstr, "suffixes") == 0)
1483 {
1484 suffixes = true;
1485 prefixes = false;
1486 oldformat = true;
1487 goto nextline;
1488 }
1489 if (STRNCMP(pstr, "prefixes") == 0)
1490 {
1491 suffixes = false;
1492 prefixes = true;
1493 oldformat = true;
1494 goto nextline;
1495 }
1496 if (STRNCMP(pstr, "flag") == 0)
1497 {
1498 s = recoded + 4; /* we need non-lowercased string */
1499 flagflags = 0;
1500
1501 while (*s && isspace((unsigned char) *s))
1502 s += pg_mblen(s);
1503
1504 if (*s == '*')
1505 {
1506 flagflags |= FF_CROSSPRODUCT;
1507 s++;
1508 }
1509 else if (*s == '~')
1510 {
1511 flagflags |= FF_COMPOUNDONLY;
1512 s++;
1513 }
1514
1515 if (*s == '\\')
1516 s++;
1517
1518 /*
1519 * An old-format flag is a single ASCII character; we expect it to
1520 * be followed by EOL, whitespace, or ':'. Otherwise this is a
1521 * new-format flag command.
1522 */
1523 if (*s && pg_mblen(s) == 1)
1524 {
1525 COPYCHAR(flag, s);
1526 flag[1] = '\0';
1527
1528 s++;
1529 if (*s == '\0' || *s == '#' || *s == '\n' || *s == ':' ||
1530 isspace((unsigned char) *s))
1531 {
1532 oldformat = true;
1533 goto nextline;
1534 }
1535 }
1536 goto isnewformat;
1537 }
1538 if (STRNCMP(recoded, "COMPOUNDFLAG") == 0 ||
1539 STRNCMP(recoded, "COMPOUNDMIN") == 0 ||
1540 STRNCMP(recoded, "PFX") == 0 ||
1541 STRNCMP(recoded, "SFX") == 0)
1542 goto isnewformat;
1543
1544 if ((!suffixes) && (!prefixes))
1545 goto nextline;
1546
1547 if (!parse_affentry(pstr, mask, find, repl))
1548 goto nextline;
1549
1550 NIAddAffix(Conf, flag, flagflags, mask, find, repl, suffixes ? FF_SUFFIX : FF_PREFIX);
1551
1552nextline:
1553 pfree(recoded);
1554 pfree(pstr);
1555 }
1556 tsearch_readline_end(&trst);
1557 return;
1558
1559isnewformat:
1560 if (oldformat)
1561 ereport(ERROR,
1562 (errcode(ERRCODE_CONFIG_FILE_ERROR),
1563 errmsg("affix file contains both old-style and new-style commands")));
1564 tsearch_readline_end(&trst);
1565
1567}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
char * str_tolower(const char *buff, size_t nbytes, Oid collid)
Definition: formatting.c:1637
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1023
void pfree(void *pointer)
Definition: mcxt.c:1524
static char * filename
Definition: pg_dumpall.c:123
static void prefixes(struct vars *v)
Definition: regc_lex.c:99
static int find(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
Definition: regexec.c:419
static void NIImportOOAffixes(IspellDict *Conf, const char *filename)
Definition: spell.c:1200
static void NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask, const char *find, const char *repl, int type)
Definition: spell.c:679
#define STRNCMP(s, p)
Definition: spell.c:191
static char * findchar2(char *str, int c1, int c2)
Definition: spell.c:243
static bool parse_affentry(char *str, char *mask, char *find, char *repl)
Definition: spell.c:915
static void addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
Definition: spell.c:1069
#define FF_SUFFIX
Definition: spell.h:121
#define FF_COMPOUNDFLAG
Definition: spell.h:46
#define FF_PREFIX
Definition: spell.h:122
#define FF_CROSSPRODUCT
Definition: spell.h:115
#define FF_COMPOUNDONLY
Definition: spell.h:42
bool usecompound
Definition: spell.h:202
bool useFlagAliases
Definition: spell.h:198
FlagMode flagMode
Definition: spell.h:203
char * flag(int b)
Definition: test-ctype.c:33
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
Definition: ts_locale.c:89
char * tsearch_readline(tsearch_readline_state *stp)
Definition: ts_locale.c:112
void tsearch_readline_end(tsearch_readline_state *stp)
Definition: ts_locale.c:157
#define COPYCHAR(d, s)
Definition: ts_locale.h:40

References addCompoundAffixFlagValue(), COPYCHAR, ereport, errcode(), errmsg(), ERROR, FF_COMPOUNDFLAG, FF_COMPOUNDONLY, FF_CROSSPRODUCT, FF_PREFIX, FF_SUFFIX, filename, find(), findchar2(), flag(), IspellDict::flagMode, FM_CHAR, NIAddAffix(), NIImportOOAffixes(), parse_affentry(), pfree(), pg_mblen(), prefixes(), str_tolower(), STRNCMP, tsearch_readline(), tsearch_readline_begin(), tsearch_readline_end(), IspellDict::usecompound, and IspellDict::useFlagAliases.

Referenced by dispell_init().

◆ NIImportDictionary()

void NIImportDictionary ( IspellDict Conf,
const char *  filename 
)

Definition at line 519 of file spell.c.

520{
522 char *line;
523
524 if (!tsearch_readline_begin(&trst, filename))
526 (errcode(ERRCODE_CONFIG_FILE_ERROR),
527 errmsg("could not open dictionary file \"%s\": %m",
528 filename)));
529
530 while ((line = tsearch_readline(&trst)) != NULL)
531 {
532 char *s,
533 *pstr;
534
535 /* Set of affix flags */
536 const char *flag;
537
538 /* Extract flag from the line */
539 flag = NULL;
540 if ((s = findchar(line, '/')))
541 {
542 *s++ = '\0';
543 flag = s;
544 while (*s)
545 {
546 /* we allow only single encoded flags for faster works */
547 if (pg_mblen(s) == 1 && isprint((unsigned char) *s) && !isspace((unsigned char) *s))
548 s++;
549 else
550 {
551 *s = '\0';
552 break;
553 }
554 }
555 }
556 else
557 flag = "";
558
559 /* Remove trailing spaces */
560 s = line;
561 while (*s)
562 {
563 if (isspace((unsigned char) *s))
564 {
565 *s = '\0';
566 break;
567 }
568 s += pg_mblen(s);
569 }
570 pstr = lowerstr_ctx(Conf, line);
571
572 NIAddSpell(Conf, pstr, flag);
573 pfree(pstr);
574
575 pfree(line);
576 }
578}
static void NIAddSpell(IspellDict *Conf, const char *word, const char *flag)
Definition: spell.c:488
static char * findchar(char *str, int c)
Definition: spell.c:230
static char * lowerstr_ctx(IspellDict *Conf, const char *src)
Definition: spell.c:176

References ereport, errcode(), errmsg(), ERROR, filename, findchar(), flag(), lowerstr_ctx(), NIAddSpell(), pfree(), pg_mblen(), tsearch_readline(), tsearch_readline_begin(), and tsearch_readline_end().

Referenced by dispell_init().

◆ NINormalizeWord()

TSLexeme * NINormalizeWord ( IspellDict Conf,
const char *  word 
)

Definition at line 2545 of file spell.c.

2546{
2547 char **res;
2548 TSLexeme *lcur = NULL,
2549 *lres = NULL;
2550 uint16 NVariant = 1;
2551
2552 res = NormalizeSubWord(Conf, word, 0);
2553
2554 if (res)
2555 {
2556 char **ptr = res;
2557
2558 while (*ptr && (lcur - lres) < MAX_NORM)
2559 {
2560 addNorm(&lres, &lcur, *ptr, 0, NVariant++);
2561 ptr++;
2562 }
2563 pfree(res);
2564 }
2565
2566 if (Conf->usecompound)
2567 {
2568 int wordlen = strlen(word);
2569 SplitVar *ptr,
2570 *var = SplitToVariants(Conf, NULL, NULL, word, wordlen, 0, -1);
2571 int i;
2572
2573 while (var)
2574 {
2575 if (var->nstem > 1)
2576 {
2577 char **subres = NormalizeSubWord(Conf, var->stem[var->nstem - 1], FF_COMPOUNDLAST);
2578
2579 if (subres)
2580 {
2581 char **subptr = subres;
2582
2583 while (*subptr)
2584 {
2585 for (i = 0; i < var->nstem - 1; i++)
2586 {
2587 addNorm(&lres, &lcur, (subptr == subres) ? var->stem[i] : pstrdup(var->stem[i]), 0, NVariant);
2588 }
2589
2590 addNorm(&lres, &lcur, *subptr, 0, NVariant);
2591 subptr++;
2592 NVariant++;
2593 }
2594
2595 pfree(subres);
2596 var->stem[0] = NULL;
2597 pfree(var->stem[var->nstem - 1]);
2598 }
2599 }
2600
2601 for (i = 0; i < var->nstem && var->stem[i]; i++)
2602 pfree(var->stem[i]);
2603 ptr = var->next;
2604 pfree(var->stem);
2605 pfree(var);
2606 var = ptr;
2607 }
2608 }
2609
2610 return lres;
2611}
uint16_t uint16
Definition: c.h:501
int i
Definition: isn.c:72
char * pstrdup(const char *in)
Definition: mcxt.c:1699
static void word(struct vars *v, int dir, struct state *lp, struct state *rp)
Definition: regcomp.c:1476
#define MAX_NORM
Definition: spell.c:188
static void addNorm(TSLexeme **lres, TSLexeme **lcur, char *word, int flags, uint16 NVariant)
Definition: spell.c:2529
static char ** NormalizeSubWord(IspellDict *Conf, const char *word, int flag)
Definition: spell.c:2181
static SplitVar * SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, const char *word, int wordlen, int startpos, int minpos)
Definition: spell.c:2379
#define FF_COMPOUNDLAST
Definition: spell.h:45
int nstem
Definition: spell.c:2292
struct SplitVar * next
Definition: spell.c:2295
char ** stem
Definition: spell.c:2294

References addNorm(), FF_COMPOUNDLAST, i, MAX_NORM, SplitVar::next, NormalizeSubWord(), SplitVar::nstem, pfree(), pstrdup(), SplitToVariants(), SplitVar::stem, IspellDict::usecompound, and word().

Referenced by dispell_lexize().

◆ NISortAffixes()

void NISortAffixes ( IspellDict Conf)

Definition at line 1981 of file spell.c.

1982{
1983 AFFIX *Affix;
1984 size_t i;
1985 CMPDAffix *ptr;
1986 int firstsuffix = Conf->naffixes;
1987
1988 if (Conf->naffixes == 0)
1989 return;
1990
1991 /* Store compound affixes in the Conf->CompoundAffix array */
1992 if (Conf->naffixes > 1)
1993 qsort(Conf->Affix, Conf->naffixes, sizeof(AFFIX), cmpaffix);
1994 Conf->CompoundAffix = ptr = (CMPDAffix *) palloc(sizeof(CMPDAffix) * Conf->naffixes);
1995 ptr->affix = NULL;
1996
1997 for (i = 0; i < Conf->naffixes; i++)
1998 {
1999 Affix = &(((AFFIX *) Conf->Affix)[i]);
2000 if (Affix->type == FF_SUFFIX && i < firstsuffix)
2001 firstsuffix = i;
2002
2003 if ((Affix->flagflags & FF_COMPOUNDFLAG) && Affix->replen > 0 &&
2004 isAffixInUse(Conf, Affix->flag))
2005 {
2006 bool issuffix = (Affix->type == FF_SUFFIX);
2007
2008 if (ptr == Conf->CompoundAffix ||
2009 issuffix != (ptr - 1)->issuffix ||
2010 strbncmp((const unsigned char *) (ptr - 1)->affix,
2011 (const unsigned char *) Affix->repl,
2012 (ptr - 1)->len))
2013 {
2014 /* leave only unique and minimal suffixes */
2015 ptr->affix = Affix->repl;
2016 ptr->len = Affix->replen;
2017 ptr->issuffix = issuffix;
2018 ptr++;
2019 }
2020 }
2021 }
2022 ptr->affix = NULL;
2023 Conf->CompoundAffix = (CMPDAffix *) repalloc(Conf->CompoundAffix, sizeof(CMPDAffix) * (ptr - Conf->CompoundAffix + 1));
2024
2025 /* Start build a prefix tree */
2026 Conf->Prefix = mkANode(Conf, 0, firstsuffix, 0, FF_PREFIX);
2027 Conf->Suffix = mkANode(Conf, firstsuffix, Conf->naffixes, 0, FF_SUFFIX);
2028 mkVoidAffix(Conf, true, firstsuffix);
2029 mkVoidAffix(Conf, false, firstsuffix);
2030}
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1544
void * palloc(Size size)
Definition: mcxt.c:1317
#define qsort(a, b, c, d)
Definition: port.h:475
static AffixNode * mkANode(IspellDict *Conf, int low, int high, int level, int type)
Definition: spell.c:1835
static int strbncmp(const unsigned char *s1, const unsigned char *s2, size_t count)
Definition: spell.c:281
static void mkVoidAffix(IspellDict *Conf, bool issuffix, int startsuffix)
Definition: spell.c:1912
static bool isAffixInUse(IspellDict *Conf, const char *affixflag)
Definition: spell.c:1966
static int cmpaffix(const void *s1, const void *s2)
Definition: spell.c:312
int len
Definition: spell.h:150
bool issuffix
Definition: spell.h:151
const char * affix
Definition: spell.h:149
AffixNode * Suffix
Definition: spell.h:190
int naffixes
Definition: spell.h:187
AFFIX * Affix
Definition: spell.h:188
CMPDAffix * CompoundAffix
Definition: spell.h:200
AffixNode * Prefix
Definition: spell.h:191
uint32 type
Definition: spell.h:91
const char * flag
Definition: spell.h:89
uint32 replen
Definition: spell.h:95
uint32 flagflags
Definition: spell.h:92
const char * repl
Definition: spell.h:97

References CMPDAffix::affix, IspellDict::Affix, cmpaffix(), IspellDict::CompoundAffix, FF_COMPOUNDFLAG, FF_PREFIX, FF_SUFFIX, aff_struct::flag, aff_struct::flagflags, i, isAffixInUse(), CMPDAffix::issuffix, CMPDAffix::len, mkANode(), mkVoidAffix(), IspellDict::naffixes, palloc(), IspellDict::Prefix, qsort, repalloc(), aff_struct::repl, aff_struct::replen, strbncmp(), IspellDict::Suffix, and aff_struct::type.

Referenced by dispell_init().

◆ NISortDictionary()

void NISortDictionary ( IspellDict Conf)

Definition at line 1726 of file spell.c.

1727{
1728 int i;
1729 int naffix;
1730 int curaffix;
1731
1732 /* compress affixes */
1733
1734 /*
1735 * If we use flag aliases then we need to use Conf->AffixData filled in
1736 * the NIImportOOAffixes().
1737 */
1738 if (Conf->useFlagAliases)
1739 {
1740 for (i = 0; i < Conf->nspell; i++)
1741 {
1742 char *end;
1743
1744 if (*Conf->Spell[i]->p.flag != '\0')
1745 {
1746 errno = 0;
1747 curaffix = strtol(Conf->Spell[i]->p.flag, &end, 10);
1748 if (Conf->Spell[i]->p.flag == end || errno == ERANGE)
1749 ereport(ERROR,
1750 (errcode(ERRCODE_CONFIG_FILE_ERROR),
1751 errmsg("invalid affix alias \"%s\"",
1752 Conf->Spell[i]->p.flag)));
1753 if (curaffix < 0 || curaffix >= Conf->nAffixData)
1754 ereport(ERROR,
1755 (errcode(ERRCODE_CONFIG_FILE_ERROR),
1756 errmsg("invalid affix alias \"%s\"",
1757 Conf->Spell[i]->p.flag)));
1758 if (*end != '\0' && !isdigit((unsigned char) *end) && !isspace((unsigned char) *end))
1759 ereport(ERROR,
1760 (errcode(ERRCODE_CONFIG_FILE_ERROR),
1761 errmsg("invalid affix alias \"%s\"",
1762 Conf->Spell[i]->p.flag)));
1763 }
1764 else
1765 {
1766 /*
1767 * If Conf->Spell[i]->p.flag is empty, then get empty value of
1768 * Conf->AffixData (0 index).
1769 */
1770 curaffix = 0;
1771 }
1772
1773 Conf->Spell[i]->p.d.affix = curaffix;
1774 Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word);
1775 }
1776 }
1777 /* Otherwise fill Conf->AffixData here */
1778 else
1779 {
1780 /* Count the number of different flags used in the dictionary */
1781 qsort(Conf->Spell, Conf->nspell, sizeof(SPELL *),
1783
1784 naffix = 0;
1785 for (i = 0; i < Conf->nspell; i++)
1786 {
1787 if (i == 0 ||
1788 strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag) != 0)
1789 naffix++;
1790 }
1791
1792 /*
1793 * Fill in Conf->AffixData with the affixes that were used in the
1794 * dictionary. Replace textual flag-field of Conf->Spell entries with
1795 * indexes into Conf->AffixData array.
1796 */
1797 Conf->AffixData = (const char **) palloc0(naffix * sizeof(const char *));
1798
1799 curaffix = -1;
1800 for (i = 0; i < Conf->nspell; i++)
1801 {
1802 if (i == 0 ||
1803 strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix]) != 0)
1804 {
1805 curaffix++;
1806 Assert(curaffix < naffix);
1807 Conf->AffixData[curaffix] = cpstrdup(Conf,
1808 Conf->Spell[i]->p.flag);
1809 }
1810
1811 Conf->Spell[i]->p.d.affix = curaffix;
1812 Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word);
1813 }
1814
1815 Conf->lenAffixData = Conf->nAffixData = naffix;
1816 }
1817
1818 /* Start build a prefix tree */
1819 qsort(Conf->Spell, Conf->nspell, sizeof(SPELL *), cmpspell);
1820 Conf->Dictionary = mkSPNode(Conf, 0, Conf->nspell, 0);
1821}
Assert(PointerIsAligned(start, uint64))
void * palloc0(Size size)
Definition: mcxt.c:1347
static char * cpstrdup(IspellDict *Conf, const char *str)
Definition: spell.c:163
static SPNode * mkSPNode(IspellDict *Conf, int low, int high, int level)
Definition: spell.c:1644
static int cmpspell(const void *s1, const void *s2)
Definition: spell.c:198
static int cmpspellaffix(const void *s1, const void *s2)
Definition: spell.c:204
int lenAffixData
Definition: spell.h:196
int nAffixData
Definition: spell.h:197
SPNode * Dictionary
Definition: spell.h:193
int nspell
Definition: spell.h:224
const char ** AffixData
Definition: spell.h:195
int len
Definition: spell.h:76
const char * flag
Definition: spell.h:69
union spell_struct::@133 p
struct spell_struct::@133::@134 d
char word[FLEXIBLE_ARRAY_MEMBER]
Definition: spell.h:79
int affix
Definition: spell.h:74

References spell_struct::affix, IspellDict::AffixData, Assert(), cmpspell(), cmpspellaffix(), cpstrdup(), spell_struct::d, IspellDict::Dictionary, ereport, errcode(), errmsg(), ERROR, spell_struct::flag, i, spell_struct::len, IspellDict::lenAffixData, mkSPNode(), IspellDict::nAffixData, IspellDict::nspell, spell_struct::p, palloc0(), qsort, IspellDict::Spell, IspellDict::useFlagAliases, and spell_struct::word.

Referenced by dispell_init().

◆ NIStartBuild()

void NIStartBuild ( IspellDict Conf)

Definition at line 89 of file spell.c.

90{
91 /*
92 * The temp context is a child of CurTransactionContext, so that it will
93 * go away automatically on error.
94 */
96 "Ispell dictionary init context",
98}
MemoryContext CurTransactionContext
Definition: mcxt.c:155
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, IspellDict::buildCxt, and CurTransactionContext.

Referenced by dispell_init().