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 /* munch header file */ 42 43 #define MAX_LN_LEN 200 44 #define MAX_WD_LEN 200 45 #define MAX_PREFIXES 2048 46 #define MAX_SUFFIXES 2048 47 #define MAX_ROOTS 20 48 #define MAX_WORDS 5000 49 50 #define ROTATE_LEN 5 51 52 #define ROTATE(v, q) \ 53 (v) = ((v) << (q)) | (((v) >> (32 - q)) & ((1 << (q)) - 1)); 54 55 #define SET_SIZE 256 56 57 #define XPRODUCT (1 << 0) 58 59 /* the affix table entry */ 60 61 struct affent { 62 char* appnd; 63 char* strip; 64 short appndl; 65 short stripl; 66 char achar; 67 char xpflg; 68 short numconds; 69 char conds[SET_SIZE]; 70 }; 71 72 struct affixptr { 73 struct affent* aep; 74 int num; 75 }; 76 77 /* the prefix and suffix table */ 78 int numpfx; /* Number of prefixes in table */ 79 int numsfx; /* Number of suffixes in table */ 80 81 /* the prefix table */ 82 struct affixptr ptable[MAX_PREFIXES]; 83 84 /* the suffix table */ 85 struct affixptr stable[MAX_SUFFIXES]; 86 87 /* data structure to store results of lookups */ 88 struct matches { 89 struct hentry* hashent; /* hash table entry */ 90 struct affent* prefix; /* Prefix used, or NULL */ 91 struct affent* suffix; /* Suffix used, or NULL */ 92 }; 93 94 int numroots; /* number of root words found */ 95 struct matches roots[MAX_ROOTS]; /* list of root words found */ 96 97 /* hashing stuff */ 98 99 struct hentry { 100 char* word; 101 char* affstr; 102 struct hentry* next; 103 int keep; 104 }; 105 106 int tablesize; 107 struct hentry* tableptr; 108 109 /* unmunch stuff */ 110 111 int numwords; /* number of words found */ 112 struct dwords { 113 char* word; 114 int pallow; 115 }; 116 117 struct dwords wlist[MAX_WORDS]; /* list words found */ 118 119 /* the routines */ 120 121 int parse_aff_file(FILE* afflst); 122 123 void encodeit(struct affent* ptr, char* cs); 124 125 int load_tables(FILE* wrdlst); 126 127 int hash(const char*); 128 129 int add_word(char*); 130 131 struct hentry* lookup(const char*); 132 133 void aff_chk(const char* word, int len); 134 135 void pfx_chk(const char* word, int len, struct affent* ep, int num); 136 137 void suf_chk(const char* word, 138 int len, 139 struct affent* ep, 140 int num, 141 struct affent* pfxent, 142 int cpflag); 143 144 void add_affix_char(struct hentry* hent, char ac); 145 146 int expand_rootword(const char*, int, const char*); 147 148 void pfx_add(const char* word, int len, struct affent* ep, int num); 149 150 void suf_add(const char* word, int len, struct affent* ep, int num); 151 152 char* mystrsep(char** stringp, const char delim); 153 154 char* mystrdup(const char* s); 155 156 void mychomp(char* s); 157