Fix xslt_process() to ensure that it inserts a NULL terminator after the
[PostgreSQL.git] / src / include / tsearch / dicts / spell.h
blob33cb8db770556409cbe856db9cc29b903674b637
1 /*-------------------------------------------------------------------------
3 * spell.h
5 * Declarations for ISpell dictionary
7 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
9 * $PostgreSQL$
11 *-------------------------------------------------------------------------
14 #ifndef __SPELL_H__
15 #define __SPELL_H__
17 #include "regex/regex.h"
18 #include "tsearch/dicts/regis.h"
19 #include "tsearch/ts_public.h"
22 * Max length of a flag name. Names longer than this will be truncated
23 * to the maximum.
25 #define MAXFLAGLEN 16
27 struct SPNode;
29 typedef struct
31 uint32 val:8,
32 isword:1,
33 compoundflag:4,
34 affix:19;
35 struct SPNode *node;
36 } SPNodeData;
39 * Names of FF_ are correlated with Hunspell options in affix file
40 * http://sourceforge.net/docman/display_doc.php?docid=29374&group_id=143754
42 #define FF_COMPOUNDONLY 0x01
43 #define FF_COMPOUNDBEGIN 0x02
44 #define FF_COMPOUNDMIDDLE 0x04
45 #define FF_COMPOUNDLAST 0x08
46 #define FF_COMPOUNDFLAG ( FF_COMPOUNDBEGIN | FF_COMPOUNDMIDDLE | FF_COMPOUNDLAST )
47 #define FF_DICTFLAGMASK 0x0f
49 typedef struct SPNode
51 uint32 length;
52 SPNodeData data[1];
53 } SPNode;
55 #define SPNHDRSZ (offsetof(SPNode,data))
58 typedef struct spell_struct
60 union
63 * flag is filled in by NIImportDictionary. After NISortDictionary, d
64 * is valid and flag is invalid.
66 char flag[MAXFLAGLEN];
67 struct
69 int affix;
70 int len;
71 } d;
72 } p;
73 char word[1]; /* variable length, null-terminated */
74 } SPELL;
76 #define SPELLHDRSZ (offsetof(SPELL, word))
78 typedef struct aff_struct
80 uint32 flag:8,
81 type:1,
82 flagflags:7,
83 issimple:1,
84 isregis:1,
85 replen:14;
86 char *find;
87 char *repl;
88 union
90 regex_t regex;
91 Regis regis;
92 } reg;
93 } AFFIX;
96 * affixes use dictionary flags too
98 #define FF_COMPOUNDPERMITFLAG 0x10
99 #define FF_COMPOUNDFORBIDFLAG 0x20
100 #define FF_CROSSPRODUCT 0x40
103 * Don't change the order of these. Initialization sorts by these,
104 * and expects prefixes to come first after sorting.
106 #define FF_SUFFIX 1
107 #define FF_PREFIX 0
109 struct AffixNode;
111 typedef struct
113 uint32 val:8,
114 naff:24;
115 AFFIX **aff;
116 struct AffixNode *node;
117 } AffixNodeData;
119 typedef struct AffixNode
121 uint32 isvoid:1,
122 length:31;
123 AffixNodeData data[1];
124 } AffixNode;
126 #define ANHRDSZ (offsetof(AffixNode, data))
128 typedef struct
130 char *affix;
131 int len;
132 bool issuffix;
133 } CMPDAffix;
135 typedef struct
137 int maffixes;
138 int naffixes;
139 AFFIX *Affix;
142 * Temporary array of all words in the dict file. Only used during
143 * initialization
145 SPELL **Spell;
146 int nspell; /* number of valid entries in Spell array */
147 int mspell; /* allocated length of Spell array */
149 AffixNode *Suffix;
150 AffixNode *Prefix;
152 SPNode *Dictionary;
153 char **AffixData;
154 int lenAffixData;
155 int nAffixData;
157 CMPDAffix *CompoundAffix;
159 unsigned char flagval[256];
160 bool usecompound;
161 } IspellDict;
163 extern TSLexeme *NINormalizeWord(IspellDict *Conf, char *word);
164 extern void NIImportAffixes(IspellDict *Conf, const char *filename);
165 extern void NIImportDictionary(IspellDict *Conf, const char *filename);
166 extern void NISortDictionary(IspellDict *Conf);
167 extern void NISortAffixes(IspellDict *Conf);
169 #endif