]> granicus.if.org Git - postgresql/blob - src/include/tsearch/dicts/spell.h
pgindent run for 8.3.
[postgresql] / src / include / tsearch / dicts / spell.h
1 /*-------------------------------------------------------------------------
2  *
3  * spell.h
4  *
5  * Declarations for ISpell dictionary
6  *
7  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
8  *
9  * $PostgreSQL: pgsql/src/include/tsearch/dicts/spell.h,v 1.4 2007/11/15 21:14:45 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13
14 #ifndef __SPELL_H__
15 #define __SPELL_H__
16
17 #include "regex/regex.h"
18 #include "tsearch/dicts/regis.h"
19 #include "tsearch/ts_public.h"
20
21 /*
22  * Max length of a flag name. Names longer than this will be truncated
23  * to the maximum.
24  */
25 #define MAXFLAGLEN 16
26
27 struct SPNode;
28
29 typedef struct
30 {
31         uint32          val:8,
32                                 isword:1,
33                                 compoundflag:4,
34                                 affix:19;
35         struct SPNode *node;
36 }       SPNodeData;
37
38 /*
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
41  */
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
48
49 typedef struct SPNode
50 {
51         uint32          length;
52         SPNodeData      data[1];
53 }       SPNode;
54
55 #define SPNHDRSZ        (offsetof(SPNode,data))
56
57
58 typedef struct spell_struct
59 {
60         union
61         {
62                 /*
63                  * flag is filled in by NIImportDictionary. After NISortDictionary, d
64                  * is valid and flag is invalid.
65                  */
66                 char            flag[MAXFLAGLEN];
67                 struct
68                 {
69                         int                     affix;
70                         int                     len;
71                 }                       d;
72         }                       p;
73         char            word[1];                /* variable length, null-terminated */
74 }       SPELL;
75
76 #define SPELLHDRSZ      (offsetof(SPELL, word))
77
78 typedef struct aff_struct
79 {
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
89         {
90                 regex_t         regex;
91                 Regis           regis;
92         }                       reg;
93 }       AFFIX;
94
95 /*
96  * affixes use dictionary flags too
97  */
98 #define FF_COMPOUNDPERMITFLAG   0x10
99 #define FF_COMPOUNDFORBIDFLAG   0x20
100 #define FF_CROSSPRODUCT                 0x40
101
102 /*
103  * Don't change the order of these. Initialization sorts by these,
104  * and expects prefixes to come first after sorting.
105  */
106 #define FF_SUFFIX                               1
107 #define FF_PREFIX                               0
108
109 struct AffixNode;
110
111 typedef struct
112 {
113         uint32          val:8,
114                                 naff:24;
115         AFFIX     **aff;
116         struct AffixNode *node;
117 }       AffixNodeData;
118
119 typedef struct AffixNode
120 {
121         uint32          isvoid:1,
122                                 length:31;
123         AffixNodeData data[1];
124 }       AffixNode;
125
126 #define ANHRDSZ            (offsetof(AffixNode, data))
127
128 typedef struct
129 {
130         char       *affix;
131         int                     len;
132         bool            issuffix;
133 }       CMPDAffix;
134
135 typedef struct
136 {
137         int                     maffixes;
138         int                     naffixes;
139         AFFIX      *Affix;
140
141         /*
142          * Temporary array of all words in the dict file. Only used during
143          * initialization
144          */
145         SPELL     **Spell;
146         int                     nspell;                 /* number of valid entries in Spell array */
147         int                     mspell;                 /* allocated length of Spell array */
148
149         AffixNode  *Suffix;
150         AffixNode  *Prefix;
151
152         SPNode     *Dictionary;
153         char      **AffixData;
154         int                     lenAffixData;
155         int                     nAffixData;
156
157         CMPDAffix  *CompoundAffix;
158
159         unsigned char flagval[256];
160         bool            usecompound;
161 }       IspellDict;
162
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);
168
169 #endif