]> granicus.if.org Git - postgresql/blob - contrib/tsearch2/ispell/spell.h
1 Fix bug with very short word: prefix and suffix might be overlapped,
[postgresql] / contrib / tsearch2 / ispell / spell.h
1 #ifndef __SPELL_H__
2 #define __SPELL_H__
3
4 #include <sys/types.h>
5 #include "regex/regex.h"
6 #include "c.h"
7
8 #include "regis.h"
9 #include "dict.h"
10
11 struct SPNode;
12
13
14 typedef struct
15 {
16         uint32
17                                 val:8,
18                                 isword:1,
19                                 compoundallow:1,
20                                 affix:22;
21         struct SPNode *node;
22 }       SPNodeData;
23
24 typedef struct SPNode
25 {
26         uint32          length;
27         SPNodeData      data[1];
28 }       SPNode;
29
30 #define SPNHRDSZ        (sizeof(uint32))
31
32
33 typedef struct spell_struct
34 {
35         union
36         {
37                 char            flag[16];
38                 struct
39                 {
40                         int                     affix;
41                         int                     len;
42                 }                       d;
43         }       p;
44         char    word[1];
45 }       SPELL;
46
47 #define SPELLHDRSZ      (offsetof(SPELL, word))
48
49 typedef struct aff_struct
50 {
51         uint32
52                                 flag:8,
53                                 type:2,
54                                 compile:1,
55                                 flagflags:3,
56                                 issimple:1,
57                                 isregis:1,
58                                 unused:1,
59                                 replen:16;
60         char       *mask;
61         char       *find;
62         char       *repl;
63         union
64         {
65                 regex_t         regex;
66                 Regis           regis;
67         }                       reg;
68 }       AFFIX;
69
70 #define FF_CROSSPRODUCT         0x01
71 #define FF_COMPOUNDWORD         0x02
72 #define FF_COMPOUNDONLYAFX              0x04
73 #define FF_SUFFIX                               2
74 #define FF_PREFIX                               1
75
76 struct AffixNode;
77
78 typedef struct
79 {
80         uint32
81                                 val:8,
82                                 naff:24;
83         AFFIX     **aff;
84         struct AffixNode *node;
85 }       AffixNodeData;
86
87 typedef struct AffixNode
88 {
89         uint32          isvoid:1,
90                                 length:31;
91         AffixNodeData data[1];
92 }       AffixNode;
93
94 #define ANHRDSZ            (sizeof(uint32))
95
96 typedef struct
97 {
98         char       *affix;
99         int                     len;
100 }       CMPDAffix;
101
102 typedef struct
103 {
104         int                     maffixes;
105         int                     naffixes;
106         AFFIX      *Affix;
107         char            compoundcontrol;
108
109         int                     nspell;
110         int                     mspell;
111         SPELL      **Spell;
112
113         AffixNode  *Suffix;
114         AffixNode  *Prefix;
115
116         SPNode     *Dictionary;
117         char      **AffixData;
118         CMPDAffix  *CompoundAffix;
119
120 }       IspellDict;
121
122 TSLexeme   *NINormalizeWord(IspellDict * Conf, char *word);
123 int                     NIImportAffixes(IspellDict * Conf, const char *filename);
124 int                     NIImportDictionary(IspellDict * Conf, const char *filename);
125
126 int                     NIAddSpell(IspellDict * Conf, const char *word, const char *flag);
127 int                     NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const char *find, const char *repl, int type);
128 void            NISortDictionary(IspellDict * Conf);
129 void            NISortAffixes(IspellDict * Conf);
130 void            NIFree(IspellDict * Conf);
131
132 #endif