| 1 | /* ***** BEGIN LICENSE BLOCK ***** |
| 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 3 | * |
| 4 | * Copyright (C) 2002-2017 Németh László |
| 5 | * |
| 6 | * The contents of this file are subject to the Mozilla Public License Version |
| 7 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 | * the License. You may obtain a copy of the License at |
| 9 | * http://www.mozilla.org/MPL/ |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 | * for the specific language governing rights and limitations under the |
| 14 | * License. |
| 15 | * |
| 16 | * Hunspell is based on MySpell which is Copyright (C) 2002 Kevin Hendricks. |
| 17 | * |
| 18 | * Contributor(s): David Einstein, Davide Prina, Giuseppe Modugno, |
| 19 | * Gianluca Turconi, Simon Brouwer, Noll János, Bíró Árpád, |
| 20 | * Goldman Eleonóra, Sarlós Tamás, Bencsáth Boldizsár, Halácsy Péter, |
| 21 | * Dvornik László, Gefferth András, Nagy Viktor, Varga Dániel, Chris Halls, |
| 22 | * Rene Engelhard, Bram Moolenaar, Dafydd Jones, Harri Pitkänen |
| 23 | * |
| 24 | * Alternatively, the contents of this file may be used under the terms of |
| 25 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 27 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 28 | * of those above. If you wish to allow use of your version of this file only |
| 29 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 30 | * use your version of this file under the terms of the MPL, indicate your |
| 31 | * decision by deleting the provisions above and replace them with the notice |
| 32 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 33 | * the provisions above, a recipient may use your version of this file under |
| 34 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 35 | * |
| 36 | * ***** END LICENSE BLOCK ***** */ |
| 37 | |
| 38 | /* unmunch header file */ |
| 39 | |
| 40 | #define MAX_LN_LEN 200 |
| 41 | #define MAX_WD_LEN 200 |
| 42 | #define MAX_PREFIXES 256 |
| 43 | #define MAX_SUFFIXES 256 |
| 44 | #define MAX_WORDS 500000 |
| 45 | |
| 46 | #define ROTATE_LEN 5 |
| 47 | |
| 48 | #define ROTATE(v, q) \ |
| 49 | (v) = ((v) << (q)) | (((v) >> (32 - q)) & ((1 << (q)) - 1)); |
| 50 | |
| 51 | #define SET_SIZE 256 |
| 52 | |
| 53 | #define XPRODUCT (1 << 0) |
| 54 | |
| 55 | /* the affix table entry */ |
| 56 | |
| 57 | struct affent { |
| 58 | char* appnd; |
| 59 | char* strip; |
| 60 | short appndl; |
| 61 | short stripl; |
| 62 | char achar; |
| 63 | char xpflg; |
| 64 | short numconds; |
| 65 | char conds[SET_SIZE]; |
| 66 | }; |
| 67 | |
| 68 | struct affixptr { |
| 69 | struct affent* aep; |
| 70 | int num; |
| 71 | }; |
| 72 | |
| 73 | /* the prefix and suffix table */ |
| 74 | int numpfx; /* Number of prefixes in table */ |
| 75 | int numsfx; /* Number of suffixes in table */ |
| 76 | |
| 77 | /* the prefix table */ |
| 78 | struct affixptr ptable[MAX_PREFIXES]; |
| 79 | |
| 80 | /* the suffix table */ |
| 81 | struct affixptr stable[MAX_SUFFIXES]; |
| 82 | |
| 83 | int fullstrip; |
| 84 | |
| 85 | int numwords; /* number of words found */ |
| 86 | struct dwords { |
| 87 | char* word; |
| 88 | int pallow; |
| 89 | }; |
| 90 | |
| 91 | struct dwords wlist[MAX_WORDS]; /* list words found */ |
| 92 | |
| 93 | /* the routines */ |
| 94 | |
| 95 | int parse_aff_file(FILE* afflst); |
| 96 | |
| 97 | void encodeit(struct affent* ptr, char* cs); |
| 98 | |
| 99 | int expand_rootword(const char*, int, const char*); |
| 100 | |
| 101 | void pfx_add(const char* word, int len, struct affent* ep, int num); |
| 102 | |
| 103 | void suf_add(const char* word, int len, struct affent* ep, int num); |
| 104 | |
| 105 | char* mystrsep(char** stringp, const char delim); |
| 106 | |
| 107 | char* mystrdup(const char* s); |
| 108 | |
| 109 | void mychomp(char* s); |