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 "atypes.hxx"
78 #include "baseaffix.hxx"
79 #include "affixmgr.hxx"
80 
81 /* A Prefix Entry  */
82 
83 class PfxEntry : public AffEntry {
84  private:
85   PfxEntry(const PfxEntry&);
86   PfxEntry& operator=(const PfxEntry&);
87 
88  private:
89   AffixMgr* pmyMgr;
90 
91   PfxEntry* next;
92   PfxEntry* nexteq;
93   PfxEntry* nextne;
94   PfxEntry* flgnxt;
95 
96  public:
97   explicit PfxEntry(AffixMgr* pmgr);
98 
allowCross() const99   bool allowCross() const { return ((opts & aeXPRODUCT) != 0); }
100   struct hentry* checkword(const char* word,
101                            int len,
102                            char in_compound,
103                            const FLAG needflag = FLAG_NULL);
104 
105   struct hentry* check_twosfx(const char* word,
106                               int len,
107                               char in_compound,
108                               const FLAG needflag = FLAG_NULL);
109 
110   std::string check_morph(const char* word,
111                           int len,
112                           char in_compound,
113                           const FLAG needflag = FLAG_NULL);
114 
115   std::string check_twosfx_morph(const char* word,
116                                  int len,
117                                  char in_compound,
118                                  const FLAG needflag = FLAG_NULL);
119 
getFlag()120   FLAG getFlag() { return aflag; }
getKey()121   const char* getKey() { return appnd.c_str(); }
122   std::string add(const char* word, size_t len);
123 
getKeyLen()124   inline short getKeyLen() { return appnd.size(); }
125 
getMorph()126   inline const char* getMorph() { return morphcode; }
127 
getCont()128   inline const unsigned short* getCont() { return contclass; }
getContLen()129   inline short getContLen() { return contclasslen; }
130 
getNext()131   inline PfxEntry* getNext() { return next; }
getNextNE()132   inline PfxEntry* getNextNE() { return nextne; }
getNextEQ()133   inline PfxEntry* getNextEQ() { return nexteq; }
getFlgNxt()134   inline PfxEntry* getFlgNxt() { return flgnxt; }
135 
setNext(PfxEntry * ptr)136   inline void setNext(PfxEntry* ptr) { next = ptr; }
setNextNE(PfxEntry * ptr)137   inline void setNextNE(PfxEntry* ptr) { nextne = ptr; }
setNextEQ(PfxEntry * ptr)138   inline void setNextEQ(PfxEntry* ptr) { nexteq = ptr; }
setFlgNxt(PfxEntry * ptr)139   inline void setFlgNxt(PfxEntry* ptr) { flgnxt = ptr; }
140 
141   inline char* nextchar(char* p);
142   inline int test_condition(const char* st);
143 };
144 
145 /* A Suffix Entry */
146 
147 class SfxEntry : public AffEntry {
148  private:
149   SfxEntry(const SfxEntry&);
150   SfxEntry& operator=(const SfxEntry&);
151 
152  private:
153   AffixMgr* pmyMgr;
154   std::string rappnd;
155 
156   SfxEntry* next;
157   SfxEntry* nexteq;
158   SfxEntry* nextne;
159   SfxEntry* flgnxt;
160 
161   SfxEntry* l_morph;
162   SfxEntry* r_morph;
163   SfxEntry* eq_morph;
164 
165  public:
166   explicit SfxEntry(AffixMgr* pmgr);
167 
allowCross() const168   bool allowCross() const { return ((opts & aeXPRODUCT) != 0); }
169   struct hentry* checkword(const char* word,
170                            int len,
171                            int optflags,
172                            PfxEntry* ppfx,
173                            const FLAG cclass,
174                            const FLAG needflag,
175                            const FLAG badflag);
176 
177   struct hentry* check_twosfx(const char* word,
178                               int len,
179                               int optflags,
180                               PfxEntry* ppfx,
181                               const FLAG needflag = FLAG_NULL);
182 
183   std::string check_twosfx_morph(const char* word,
184                                  int len,
185                                  int optflags,
186                                  PfxEntry* ppfx,
187                                  const FLAG needflag = FLAG_NULL);
188   struct hentry* get_next_homonym(struct hentry* he);
189   struct hentry* get_next_homonym(struct hentry* word,
190                                   int optflags,
191                                   PfxEntry* ppfx,
192                                   const FLAG cclass,
193                                   const FLAG needflag);
194 
getFlag()195   FLAG getFlag() { return aflag; }
getKey()196   const char* getKey() { return rappnd.c_str(); }
197   std::string add(const char* word, size_t len);
198 
getMorph()199   inline const char* getMorph() { return morphcode; }
200 
getCont()201   inline const unsigned short* getCont() { return contclass; }
getContLen()202   inline short getContLen() { return contclasslen; }
getAffix()203   inline const char* getAffix() { return appnd.c_str(); }
204 
getKeyLen()205   inline short getKeyLen() { return appnd.size(); }
206 
getNext()207   inline SfxEntry* getNext() { return next; }
getNextNE()208   inline SfxEntry* getNextNE() { return nextne; }
getNextEQ()209   inline SfxEntry* getNextEQ() { return nexteq; }
210 
getLM()211   inline SfxEntry* getLM() { return l_morph; }
getRM()212   inline SfxEntry* getRM() { return r_morph; }
getEQM()213   inline SfxEntry* getEQM() { return eq_morph; }
getFlgNxt()214   inline SfxEntry* getFlgNxt() { return flgnxt; }
215 
setNext(SfxEntry * ptr)216   inline void setNext(SfxEntry* ptr) { next = ptr; }
setNextNE(SfxEntry * ptr)217   inline void setNextNE(SfxEntry* ptr) { nextne = ptr; }
setNextEQ(SfxEntry * ptr)218   inline void setNextEQ(SfxEntry* ptr) { nexteq = ptr; }
setFlgNxt(SfxEntry * ptr)219   inline void setFlgNxt(SfxEntry* ptr) { flgnxt = ptr; }
220   void initReverseWord();
221 
222   inline char* nextchar(char* p);
223   inline int test_condition(const char* st, const char* begin);
224 };
225 
226 #endif
227