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

104 {
105  /* Release no-longer-needed temp memory */
107  /* Just for cleanliness, zero the now-dangling pointers */
108  Conf->buildCxt = NULL;
109  Conf->Spell = NULL;
110  Conf->firstfree = NULL;
111  Conf->CompoundAffixFlags = NULL;
112 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:387
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 1445 of file spell.c.

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

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

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

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

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

1993 {
1994  AFFIX *Affix;
1995  size_t i;
1996  CMPDAffix *ptr;
1997  int firstsuffix = Conf->naffixes;
1998 
1999  if (Conf->naffixes == 0)
2000  return;
2001 
2002  /* Store compound affixes in the Conf->CompoundAffix array */
2003  if (Conf->naffixes > 1)
2004  qsort((void *) Conf->Affix, Conf->naffixes, sizeof(AFFIX), cmpaffix);
2005  Conf->CompoundAffix = ptr = (CMPDAffix *) palloc(sizeof(CMPDAffix) * Conf->naffixes);
2006  ptr->affix = NULL;
2007 
2008  for (i = 0; i < Conf->naffixes; i++)
2009  {
2010  Affix = &(((AFFIX *) Conf->Affix)[i]);
2011  if (Affix->type == FF_SUFFIX && i < firstsuffix)
2012  firstsuffix = i;
2013 
2014  if ((Affix->flagflags & FF_COMPOUNDFLAG) && Affix->replen > 0 &&
2015  isAffixInUse(Conf, Affix->flag))
2016  {
2017  bool issuffix = (Affix->type == FF_SUFFIX);
2018 
2019  if (ptr == Conf->CompoundAffix ||
2020  issuffix != (ptr - 1)->issuffix ||
2021  strbncmp((const unsigned char *) (ptr - 1)->affix,
2022  (const unsigned char *) Affix->repl,
2023  (ptr - 1)->len))
2024  {
2025  /* leave only unique and minimal suffixes */
2026  ptr->affix = Affix->repl;
2027  ptr->len = Affix->replen;
2028  ptr->issuffix = issuffix;
2029  ptr++;
2030  }
2031  }
2032  }
2033  ptr->affix = NULL;
2034  Conf->CompoundAffix = (CMPDAffix *) repalloc(Conf->CompoundAffix, sizeof(CMPDAffix) * (ptr - Conf->CompoundAffix + 1));
2035 
2036  /* Start build a prefix tree */
2037  Conf->Prefix = mkANode(Conf, 0, firstsuffix, 0, FF_PREFIX);
2038  Conf->Suffix = mkANode(Conf, firstsuffix, Conf->naffixes, 0, FF_SUFFIX);
2039  mkVoidAffix(Conf, true, firstsuffix);
2040  mkVoidAffix(Conf, false, firstsuffix);
2041 }
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1456
void * palloc(Size size)
Definition: mcxt.c:1210
#define qsort(a, b, c, d)
Definition: port.h:445
static AffixNode * mkANode(IspellDict *Conf, int low, int high, int level, int type)
Definition: spell.c:1846
static bool isAffixInUse(IspellDict *Conf, char *affixflag)
Definition: spell.c:1977
static int strbncmp(const unsigned char *s1, const unsigned char *s2, size_t count)
Definition: spell.c:280
static void mkVoidAffix(IspellDict *Conf, bool issuffix, int startsuffix)
Definition: spell.c:1923
static int cmpaffix(const void *s1, const void *s2)
Definition: spell.c:311
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 1738 of file spell.c.

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

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

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

Referenced by dispell_init().