1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Hunspell, based on MySpell.
15  *
16  * The Initial Developers of the Original Code are
17  * Kevin Hendricks (MySpell) and Németh László (Hunspell).
18  * Portions created by the Initial Developers are Copyright (C) 2002-2005
19  * the Initial Developers. All Rights Reserved.
20  *
21  * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno,
22  * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád,
23  * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter,
24  * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls,
25  * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen
26  *
27  * Alternatively, the contents of this file may be used under the terms of
28  * either the GNU General Public License Version 2 or later (the "GPL"), or
29  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30  * in which case the provisions of the GPL or the LGPL are applicable instead
31  * of those above. If you wish to allow use of your version of this file only
32  * under the terms of either the GPL or the LGPL, and not to allow others to
33  * use your version of this file under the terms of the MPL, indicate your
34  * decision by deleting the provisions above and replace them with the notice
35  * and other provisions required by the GPL or the LGPL. If you do not delete
36  * the provisions above, a recipient may use your version of this file under
37  * the terms of any one of the MPL, the GPL or the LGPL.
38  *
39  * ***** END LICENSE BLOCK ***** */
40 /*
41  * Copyright 2002 Kevin B. Hendricks, Stratford, Ontario, Canada
42  * And Contributors.  All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  *
48  * 1. Redistributions of source code must retain the above copyright
49  *    notice, this list of conditions and the following disclaimer.
50  *
51  * 2. Redistributions in binary form must reproduce the above copyright
52  *    notice, this list of conditions and the following disclaimer in the
53  *    documentation and/or other materials provided with the distribution.
54  *
55  * 3. All modifications to the source code must be clearly marked as
56  *    such.  Binary redistributions based on modified source code
57  *    must be clearly marked as modified versions in the documentation
58  *    and/or other materials provided with the distribution.
59  *
60  * THIS SOFTWARE IS PROVIDED BY KEVIN B. HENDRICKS AND CONTRIBUTORS
61  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
62  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
63  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
64  * KEVIN B. HENDRICKS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
65  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
66  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71  * SUCH DAMAGE.
72  */
73 
74 #ifndef _AFFIX_HXX_
75 #define _AFFIX_HXX_
76 
77 #include "hunvisapi.h"
78 
79 #include "atypes.hxx"
80 #include "baseaffix.hxx"
81 #include "affixmgr.hxx"
82 
83 /* A Prefix Entry  */
84 
85 class LIBHUNSPELL_DLL_EXPORTED PfxEntry : protected AffEntry {
86  private:
87   PfxEntry(const PfxEntry&);
88   PfxEntry& operator=(const PfxEntry&);
89 
90  private:
91   AffixMgr* pmyMgr;
92 
93   PfxEntry* next;
94   PfxEntry* nexteq;
95   PfxEntry* nextne;
96   PfxEntry* flgnxt;
97 
98  public:
99   PfxEntry(AffixMgr* pmgr, affentry* dp);
100   ~PfxEntry();
101 
allowCross()102   inline bool allowCross() { return ((opts & aeXPRODUCT) != 0); }
103   struct hentry* checkword(const char* word,
104                            int len,
105                            char in_compound,
106                            const FLAG needflag = FLAG_NULL);
107 
108   struct hentry* check_twosfx(const char* word,
109                               int len,
110                               char in_compound,
111                               const FLAG needflag = FLAG_NULL);
112 
113   char* check_morph(const char* word,
114                     int len,
115                     char in_compound,
116                     const FLAG needflag = FLAG_NULL);
117 
118   char* check_twosfx_morph(const char* word,
119                            int len,
120                            char in_compound,
121                            const FLAG needflag = FLAG_NULL);
122 
getFlag()123   inline FLAG getFlag() { return aflag; }
getKey()124   inline const char* getKey() { return appnd.c_str(); }
125   char* add(const char* word, size_t len);
126 
getKeyLen()127   inline short getKeyLen() { return appnd.size(); }
128 
getMorph()129   inline const char* getMorph() { return morphcode; }
130 
getCont()131   inline const unsigned short* getCont() { return contclass; }
getContLen()132   inline short getContLen() { return contclasslen; }
133 
getNext()134   inline PfxEntry* getNext() { return next; }
getNextNE()135   inline PfxEntry* getNextNE() { return nextne; }
getNextEQ()136   inline PfxEntry* getNextEQ() { return nexteq; }
getFlgNxt()137   inline PfxEntry* getFlgNxt() { return flgnxt; }
138 
setNext(PfxEntry * ptr)139   inline void setNext(PfxEntry* ptr) { next = ptr; }
setNextNE(PfxEntry * ptr)140   inline void setNextNE(PfxEntry* ptr) { nextne = ptr; }
setNextEQ(PfxEntry * ptr)141   inline void setNextEQ(PfxEntry* ptr) { nexteq = ptr; }
setFlgNxt(PfxEntry * ptr)142   inline void setFlgNxt(PfxEntry* ptr) { flgnxt = ptr; }
143 
144   inline char* nextchar(char* p);
145   inline int test_condition(const char* st);
146 };
147 
148 /* A Suffix Entry */
149 
150 class LIBHUNSPELL_DLL_EXPORTED SfxEntry : protected AffEntry {
151  private:
152   SfxEntry(const SfxEntry&);
153   SfxEntry& operator=(const SfxEntry&);
154 
155  private:
156   AffixMgr* pmyMgr;
157   std::string rappnd;
158 
159   SfxEntry* next;
160   SfxEntry* nexteq;
161   SfxEntry* nextne;
162   SfxEntry* flgnxt;
163 
164   SfxEntry* l_morph;
165   SfxEntry* r_morph;
166   SfxEntry* eq_morph;
167 
168  public:
169   SfxEntry(AffixMgr* pmgr, affentry* dp);
170   ~SfxEntry();
171 
allowCross()172   inline bool allowCross() { return ((opts & aeXPRODUCT) != 0); }
173   struct hentry* checkword(const char* word,
174                            int len,
175                            int optflags,
176                            PfxEntry* ppfx,
177                            char** wlst,
178                            int maxSug,
179                            int* ns,
180                            const FLAG cclass = FLAG_NULL,
181                            const FLAG needflag = FLAG_NULL,
182                            const FLAG badflag = FLAG_NULL);
183 
184   struct hentry* check_twosfx(const char* word,
185                               int len,
186                               int optflags,
187                               PfxEntry* ppfx,
188                               const FLAG needflag = FLAG_NULL);
189 
190   char* check_twosfx_morph(const char* word,
191                            int len,
192                            int optflags,
193                            PfxEntry* ppfx,
194                            const FLAG needflag = FLAG_NULL);
195   struct hentry* get_next_homonym(struct hentry* he);
196   struct hentry* get_next_homonym(struct hentry* word,
197                                   int optflags,
198                                   PfxEntry* ppfx,
199                                   const FLAG cclass,
200                                   const FLAG needflag);
201 
getFlag()202   inline FLAG getFlag() { return aflag; }
getKey()203   inline const char* getKey() { return rappnd.c_str(); }
204   char* add(const char* word, size_t len);
205 
getMorph()206   inline const char* getMorph() { return morphcode; }
207 
getCont()208   inline const unsigned short* getCont() { return contclass; }
getContLen()209   inline short getContLen() { return contclasslen; }
getAffix()210   inline const char* getAffix() { return appnd.c_str(); }
211 
getKeyLen()212   inline short getKeyLen() { return appnd.size(); }
213 
getNext()214   inline SfxEntry* getNext() { return next; }
getNextNE()215   inline SfxEntry* getNextNE() { return nextne; }
getNextEQ()216   inline SfxEntry* getNextEQ() { return nexteq; }
217 
getLM()218   inline SfxEntry* getLM() { return l_morph; }
getRM()219   inline SfxEntry* getRM() { return r_morph; }
getEQM()220   inline SfxEntry* getEQM() { return eq_morph; }
getFlgNxt()221   inline SfxEntry* getFlgNxt() { return flgnxt; }
222 
setNext(SfxEntry * ptr)223   inline void setNext(SfxEntry* ptr) { next = ptr; }
setNextNE(SfxEntry * ptr)224   inline void setNextNE(SfxEntry* ptr) { nextne = ptr; }
setNextEQ(SfxEntry * ptr)225   inline void setNextEQ(SfxEntry* ptr) { nexteq = ptr; }
setFlgNxt(SfxEntry * ptr)226   inline void setFlgNxt(SfxEntry* ptr) { flgnxt = ptr; }
227 
228   inline char* nextchar(char* p);
229   inline int test_condition(const char* st, const char* begin);
230 };
231 
232 #endif
233