PostgreSQL Source Code  git master
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_regex_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_regex_struct aff_regex_struct
 
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, 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 151 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 120 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 119 of file spell.h.

◆ FF_CROSSPRODUCT

#define FF_CROSSPRODUCT   0x40

Definition at line 121 of file spell.h.

◆ FF_PREFIX

#define FF_PREFIX   0

Definition at line 128 of file spell.h.

◆ FF_SUFFIX

#define FF_SUFFIX   1

Definition at line 127 of file spell.h.

◆ FLAGNUM_MAXSIZE

#define FLAGNUM_MAXSIZE   (1 << 16)

Definition at line 188 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

◆ aff_regex_struct

◆ 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 163 of file spell.h.

164 {
165  FM_CHAR, /* one character (like ispell) */
166  FM_LONG, /* two characters */
167  FM_NUM /* number, >= 0 and < 65536 */
168 } FlagMode;
FlagMode
Definition: spell.h:164
@ FM_LONG
Definition: spell.h:166
@ FM_CHAR
Definition: spell.h:165
@ FM_NUM
Definition: spell.h:167

Function Documentation

◆ NIFinishBuild()

void NIFinishBuild ( IspellDict Conf)

Definition at line 102 of file spell.c.

103 {
104  /* Release no-longer-needed temp memory */
106  /* Just for cleanliness, zero the now-dangling pointers */
107  Conf->buildCxt = NULL;
108  Conf->Spell = NULL;
109  Conf->firstfree = NULL;
110  Conf->CompoundAffixFlags = NULL;
111 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
MemoryContext buildCxt
Definition: spell.h:226
CompoundAffixFlag * CompoundAffixFlags
Definition: spell.h:216
char * firstfree
Definition: spell.h:234
SPELL ** Spell
Definition: spell.h:229

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 1444 of file spell.c.

1445 {
1446  char *pstr = NULL;
1447  char flag[BUFSIZ];
1448  char mask[BUFSIZ];
1449  char find[BUFSIZ];
1450  char repl[BUFSIZ];
1451  char *s;
1452  bool suffixes = false;
1453  bool prefixes = false;
1454  char flagflags = 0;
1456  bool oldformat = false;
1457  char *recoded = NULL;
1458 
1459  if (!tsearch_readline_begin(&trst, filename))
1460  ereport(ERROR,
1461  (errcode(ERRCODE_CONFIG_FILE_ERROR),
1462  errmsg("could not open affix file \"%s\": %m",
1463  filename)));
1464 
1465  Conf->usecompound = false;
1466  Conf->useFlagAliases = false;
1467  Conf->flagMode = FM_CHAR;
1468 
1469  while ((recoded = tsearch_readline(&trst)) != NULL)
1470  {
1471  pstr = lowerstr(recoded);
1472 
1473  /* Skip comments and empty lines */
1474  if (*pstr == '#' || *pstr == '\n')
1475  goto nextline;
1476 
1477  if (STRNCMP(pstr, "compoundwords") == 0)
1478  {
1479  /* Find case-insensitive L flag in non-lowercased string */
1480  s = findchar2(recoded, 'l', 'L');
1481  if (s)
1482  {
1483  while (*s && !t_isspace(s))
1484  s += pg_mblen(s);
1485  while (*s && t_isspace(s))
1486  s += pg_mblen(s);
1487 
1488  if (*s && pg_mblen(s) == 1)
1489  {
1491  Conf->usecompound = true;
1492  }
1493  oldformat = true;
1494  goto nextline;
1495  }
1496  }
1497  if (STRNCMP(pstr, "suffixes") == 0)
1498  {
1499  suffixes = true;
1500  prefixes = false;
1501  oldformat = true;
1502  goto nextline;
1503  }
1504  if (STRNCMP(pstr, "prefixes") == 0)
1505  {
1506  suffixes = false;
1507  prefixes = true;
1508  oldformat = true;
1509  goto nextline;
1510  }
1511  if (STRNCMP(pstr, "flag") == 0)
1512  {
1513  s = recoded + 4; /* we need non-lowercased string */
1514  flagflags = 0;
1515 
1516  while (*s && t_isspace(s))
1517  s += pg_mblen(s);
1518 
1519  if (*s == '*')
1520  {
1521  flagflags |= FF_CROSSPRODUCT;
1522  s++;
1523  }
1524  else if (*s == '~')
1525  {
1526  flagflags |= FF_COMPOUNDONLY;
1527  s++;
1528  }
1529 
1530  if (*s == '\\')
1531  s++;
1532 
1533  /*
1534  * An old-format flag is a single ASCII character; we expect it to
1535  * be followed by EOL, whitespace, or ':'. Otherwise this is a
1536  * new-format flag command.
1537  */
1538  if (*s && pg_mblen(s) == 1)
1539  {
1540  COPYCHAR(flag, s);
1541  flag[1] = '\0';
1542 
1543  s++;
1544  if (*s == '\0' || *s == '#' || *s == '\n' || *s == ':' ||
1545  t_isspace(s))
1546  {
1547  oldformat = true;
1548  goto nextline;
1549  }
1550  }
1551  goto isnewformat;
1552  }
1553  if (STRNCMP(recoded, "COMPOUNDFLAG") == 0 ||
1554  STRNCMP(recoded, "COMPOUNDMIN") == 0 ||
1555  STRNCMP(recoded, "PFX") == 0 ||
1556  STRNCMP(recoded, "SFX") == 0)
1557  goto isnewformat;
1558 
1559  if ((!suffixes) && (!prefixes))
1560  goto nextline;
1561 
1562  if (!parse_affentry(pstr, mask, find, repl))
1563  goto nextline;
1564 
1565  NIAddAffix(Conf, flag, flagflags, mask, find, repl, suffixes ? FF_SUFFIX : FF_PREFIX);
1566 
1567 nextline:
1568  pfree(recoded);
1569  pfree(pstr);
1570  }
1571  tsearch_readline_end(&trst);
1572  return;
1573 
1574 isnewformat:
1575  if (oldformat)
1576  ereport(ERROR,
1577  (errcode(ERRCODE_CONFIG_FILE_ERROR),
1578  errmsg("affix file contains both old-style and new-style commands")));
1579  tsearch_readline_end(&trst);
1580 
1581  NIImportOOAffixes(Conf, filename);
1582 }
int errcode(int sqlerrcode)
Definition: elog.c:698
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
int pg_mblen(const char *mbstr)
Definition: mbutils.c:966
void pfree(void *pointer)
Definition: mcxt.c:1169
static char * filename
Definition: pg_dumpall.c:92
static void prefixes(struct vars *v)
Definition: regc_lex.c:99
static int find(struct vars *, struct cnfa *, struct colormap *)
Definition: regexec.c:410
static char * findchar2(char *str, int c1, int c2)
Definition: spell.c:241
static void NIImportOOAffixes(IspellDict *Conf, const char *filename)
Definition: spell.c:1215
static void NIAddAffix(IspellDict *Conf, const char *flag, char flagflags, const char *mask, const char *find, const char *repl, int type)
Definition: spell.c:687
#define STRNCMP(s, p)
Definition: spell.c:189
static bool parse_affentry(char *str, char *mask, char *find, char *repl)
Definition: spell.c:932
static void addCompoundAffixFlagValue(IspellDict *Conf, char *s, uint32 val)
Definition: spell.c:1085
#define FF_SUFFIX
Definition: spell.h:127
#define FF_COMPOUNDFLAG
Definition: spell.h:46
#define FF_PREFIX
Definition: spell.h:128
#define FF_CROSSPRODUCT
Definition: spell.h:121
#define FF_COMPOUNDONLY
Definition: spell.h:42
bool usecompound
Definition: spell.h:208
bool useFlagAliases
Definition: spell.h:204
FlagMode flagMode
Definition: spell.h:209
char * flag(int b)
Definition: test-ctype.c:33
bool tsearch_readline_begin(tsearch_readline_state *stp, const char *filename)
Definition: ts_locale.c:125
char * tsearch_readline(tsearch_readline_state *stp)
Definition: ts_locale.c:148
int t_isspace(const char *ptr)
Definition: ts_locale.c:53
void tsearch_readline_end(tsearch_readline_state *stp)
Definition: ts_locale.c:193
char * lowerstr(const char *str)
Definition: ts_locale.c:244
#define COPYCHAR(d, s)
Definition: ts_locale.h:48

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, lowerstr(), NIAddAffix(), NIImportOOAffixes(), parse_affentry(), pfree(), pg_mblen(), prefixes(), STRNCMP, t_isspace(), 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 516 of file spell.c.

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

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

Referenced by dispell_init().

◆ NINormalizeWord()

TSLexeme* NINormalizeWord ( IspellDict Conf,
char *  word 
)

Definition at line 2552 of file spell.c.

2553 {
2554  char **res;
2555  TSLexeme *lcur = NULL,
2556  *lres = NULL;
2557  uint16 NVariant = 1;
2558 
2559  res = NormalizeSubWord(Conf, word, 0);
2560 
2561  if (res)
2562  {
2563  char **ptr = res;
2564 
2565  while (*ptr && (lcur - lres) < MAX_NORM)
2566  {
2567  addNorm(&lres, &lcur, *ptr, 0, NVariant++);
2568  ptr++;
2569  }
2570  pfree(res);
2571  }
2572 
2573  if (Conf->usecompound)
2574  {
2575  int wordlen = strlen(word);
2576  SplitVar *ptr,
2577  *var = SplitToVariants(Conf, NULL, NULL, word, wordlen, 0, -1);
2578  int i;
2579 
2580  while (var)
2581  {
2582  if (var->nstem > 1)
2583  {
2584  char **subres = NormalizeSubWord(Conf, var->stem[var->nstem - 1], FF_COMPOUNDLAST);
2585 
2586  if (subres)
2587  {
2588  char **subptr = subres;
2589 
2590  while (*subptr)
2591  {
2592  for (i = 0; i < var->nstem - 1; i++)
2593  {
2594  addNorm(&lres, &lcur, (subptr == subres) ? var->stem[i] : pstrdup(var->stem[i]), 0, NVariant);
2595  }
2596 
2597  addNorm(&lres, &lcur, *subptr, 0, NVariant);
2598  subptr++;
2599  NVariant++;
2600  }
2601 
2602  pfree(subres);
2603  var->stem[0] = NULL;
2604  pfree(var->stem[var->nstem - 1]);
2605  }
2606  }
2607 
2608  for (i = 0; i < var->nstem && var->stem[i]; i++)
2609  pfree(var->stem[i]);
2610  ptr = var->next;
2611  pfree(var->stem);
2612  pfree(var);
2613  var = ptr;
2614  }
2615  }
2616 
2617  return lres;
2618 }
unsigned short uint16
Definition: c.h:440
int i
Definition: isn.c:73
char * pstrdup(const char *in)
Definition: mcxt.c:1299
static void word(struct vars *, int, struct state *, struct state *)
Definition: regcomp.c:1432
static SplitVar * SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, char *word, int wordlen, int startpos, int minpos)
Definition: spell.c:2389
#define MAX_NORM
Definition: spell.c:186
static void addNorm(TSLexeme **lres, TSLexeme **lcur, char *word, int flags, uint16 NVariant)
Definition: spell.c:2536
static char ** NormalizeSubWord(IspellDict *Conf, char *word, int flag)
Definition: spell.c:2191
#define FF_COMPOUNDLAST
Definition: spell.h:45
int nstem
Definition: spell.c:2302
struct SplitVar * next
Definition: spell.c:2305
char ** stem
Definition: spell.c:2304

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

Referenced by dispell_lexize().

◆ NISortAffixes()

void NISortAffixes ( IspellDict Conf)

Definition at line 1991 of file spell.c.

1992 {
1993  AFFIX *Affix;
1994  size_t i;
1995  CMPDAffix *ptr;
1996  int firstsuffix = Conf->naffixes;
1997 
1998  if (Conf->naffixes == 0)
1999  return;
2000 
2001  /* Store compound affixes in the Conf->CompoundAffix array */
2002  if (Conf->naffixes > 1)
2003  qsort((void *) Conf->Affix, Conf->naffixes, sizeof(AFFIX), cmpaffix);
2004  Conf->CompoundAffix = ptr = (CMPDAffix *) palloc(sizeof(CMPDAffix) * Conf->naffixes);
2005  ptr->affix = NULL;
2006 
2007  for (i = 0; i < Conf->naffixes; i++)
2008  {
2009  Affix = &(((AFFIX *) Conf->Affix)[i]);
2010  if (Affix->type == FF_SUFFIX && i < firstsuffix)
2011  firstsuffix = i;
2012 
2013  if ((Affix->flagflags & FF_COMPOUNDFLAG) && Affix->replen > 0 &&
2014  isAffixInUse(Conf, Affix->flag))
2015  {
2016  bool issuffix = (Affix->type == FF_SUFFIX);
2017 
2018  if (ptr == Conf->CompoundAffix ||
2019  issuffix != (ptr - 1)->issuffix ||
2020  strbncmp((const unsigned char *) (ptr - 1)->affix,
2021  (const unsigned char *) Affix->repl,
2022  (ptr - 1)->len))
2023  {
2024  /* leave only unique and minimal suffixes */
2025  ptr->affix = Affix->repl;
2026  ptr->len = Affix->replen;
2027  ptr->issuffix = issuffix;
2028  ptr++;
2029  }
2030  }
2031  }
2032  ptr->affix = NULL;
2033  Conf->CompoundAffix = (CMPDAffix *) repalloc(Conf->CompoundAffix, sizeof(CMPDAffix) * (ptr - Conf->CompoundAffix + 1));
2034 
2035  /* Start build a prefix tree */
2036  Conf->Prefix = mkANode(Conf, 0, firstsuffix, 0, FF_PREFIX);
2037  Conf->Suffix = mkANode(Conf, firstsuffix, Conf->naffixes, 0, FF_SUFFIX);
2038  mkVoidAffix(Conf, true, firstsuffix);
2039  mkVoidAffix(Conf, false, firstsuffix);
2040 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
void * palloc(Size size)
Definition: mcxt.c:1062
#define qsort(a, b, c, d)
Definition: port.h:497
static AffixNode * mkANode(IspellDict *Conf, int low, int high, int level, int type)
Definition: spell.c:1845
static bool isAffixInUse(IspellDict *Conf, char *affixflag)
Definition: spell.c:1976
static int strbncmp(const unsigned char *s1, const unsigned char *s2, size_t count)
Definition: spell.c:279
static void mkVoidAffix(IspellDict *Conf, bool issuffix, int startsuffix)
Definition: spell.c:1922
static int cmpaffix(const void *s1, const void *s2)
Definition: spell.c:310
int len
Definition: spell.h:156
bool issuffix
Definition: spell.h:157
char * affix
Definition: spell.h:155
AffixNode * Suffix
Definition: spell.h:196
int naffixes
Definition: spell.h:193
AFFIX * Affix
Definition: spell.h:194
CMPDAffix * CompoundAffix
Definition: spell.h:206
AffixNode * Prefix
Definition: spell.h:197
char * flag
Definition: spell.h:100
uint32 type
Definition: spell.h:102
uint32 replen
Definition: spell.h:106
char * repl
Definition: spell.h:108
uint32 flagflags
Definition: spell.h:103

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 1737 of file spell.c.

1738 {
1739  int i;
1740  int naffix;
1741  int curaffix;
1742 
1743  /* compress affixes */
1744 
1745  /*
1746  * If we use flag aliases then we need to use Conf->AffixData filled in
1747  * the NIImportOOAffixes().
1748  */
1749  if (Conf->useFlagAliases)
1750  {
1751  for (i = 0; i < Conf->nspell; i++)
1752  {
1753  char *end;
1754 
1755  if (*Conf->Spell[i]->p.flag != '\0')
1756  {
1757  curaffix = strtol(Conf->Spell[i]->p.flag, &end, 10);
1758  if (Conf->Spell[i]->p.flag == end || errno == ERANGE)
1759  ereport(ERROR,
1760  (errcode(ERRCODE_CONFIG_FILE_ERROR),
1761  errmsg("invalid affix alias \"%s\"",
1762  Conf->Spell[i]->p.flag)));
1763  if (curaffix < 0 || curaffix >= Conf->nAffixData)
1764  ereport(ERROR,
1765  (errcode(ERRCODE_CONFIG_FILE_ERROR),
1766  errmsg("invalid affix alias \"%s\"",
1767  Conf->Spell[i]->p.flag)));
1768  if (*end != '\0' && !t_isdigit(end) && !t_isspace(end))
1769  ereport(ERROR,
1770  (errcode(ERRCODE_CONFIG_FILE_ERROR),
1771  errmsg("invalid affix alias \"%s\"",
1772  Conf->Spell[i]->p.flag)));
1773  }
1774  else
1775  {
1776  /*
1777  * If Conf->Spell[i]->p.flag is empty, then get empty value of
1778  * Conf->AffixData (0 index).
1779  */
1780  curaffix = 0;
1781  }
1782 
1783  Conf->Spell[i]->p.d.affix = curaffix;
1784  Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word);
1785  }
1786  }
1787  /* Otherwise fill Conf->AffixData here */
1788  else
1789  {
1790  /* Count the number of different flags used in the dictionary */
1791  qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL *),
1792  cmpspellaffix);
1793 
1794  naffix = 0;
1795  for (i = 0; i < Conf->nspell; i++)
1796  {
1797  if (i == 0 ||
1798  strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag) != 0)
1799  naffix++;
1800  }
1801 
1802  /*
1803  * Fill in Conf->AffixData with the affixes that were used in the
1804  * dictionary. Replace textual flag-field of Conf->Spell entries with
1805  * indexes into Conf->AffixData array.
1806  */
1807  Conf->AffixData = (char **) palloc0(naffix * sizeof(char *));
1808 
1809  curaffix = -1;
1810  for (i = 0; i < Conf->nspell; i++)
1811  {
1812  if (i == 0 ||
1813  strcmp(Conf->Spell[i]->p.flag, Conf->AffixData[curaffix]) != 0)
1814  {
1815  curaffix++;
1816  Assert(curaffix < naffix);
1817  Conf->AffixData[curaffix] = cpstrdup(Conf,
1818  Conf->Spell[i]->p.flag);
1819  }
1820 
1821  Conf->Spell[i]->p.d.affix = curaffix;
1822  Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word);
1823  }
1824 
1825  Conf->lenAffixData = Conf->nAffixData = naffix;
1826  }
1827 
1828  /* Start build a prefix tree */
1829  qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL *), cmpspell);
1830  Conf->Dictionary = mkSPNode(Conf, 0, Conf->nspell, 0);
1831 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
Definition: mcxt.c:1093
static int cmpspell(const void *s1, const void *s2)
Definition: spell.c:196
static char * cpstrdup(IspellDict *Conf, const char *str)
Definition: spell.c:161
static SPNode * mkSPNode(IspellDict *Conf, int low, int high, int level)
Definition: spell.c:1655
static int cmpspellaffix(const void *s1, const void *s2)
Definition: spell.c:202
int lenAffixData
Definition: spell.h:202
char ** AffixData
Definition: spell.h:201
int nAffixData
Definition: spell.h:203
SPNode * Dictionary
Definition: spell.h:199
int nspell
Definition: spell.h:230
struct spell_struct::@116::@117 d
char * flag
Definition: spell.h:69
char word[FLEXIBLE_ARRAY_MEMBER]
Definition: spell.h:79
union spell_struct::@116 p
int t_isdigit(const char *ptr)
Definition: ts_locale.c:37

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

Referenced by dispell_init().

◆ NIStartBuild()

void NIStartBuild ( IspellDict Conf)

Definition at line 87 of file spell.c.

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

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

Referenced by dispell_init().