| OLD | NEW |
| 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 |
| 1 #include <cstdlib> | 41 #include <cstdlib> |
| 2 #include <cstring> | 42 #include <cstring> |
| 3 #include <cstdio> | 43 #include <cstdio> |
| 4 #include <ctype.h> | 44 #include <ctype.h> |
| 5 | 45 |
| 6 #include "../hunspell/csutil.hxx" | 46 #include "../hunspell/csutil.hxx" |
| 7 #include "manparser.hxx" | 47 #include "manparser.hxx" |
| 8 | 48 |
| 9 | |
| 10 #ifndef W32 | 49 #ifndef W32 |
| 11 using namespace std; | 50 using namespace std; |
| 12 #endif | 51 #endif |
| 13 | 52 |
| 14 ManParser::ManParser() { | 53 ManParser::ManParser(const char* wordchars) |
| 54 : TextParser(wordchars) { |
| 15 } | 55 } |
| 16 | 56 |
| 17 ManParser::ManParser(const char * wordchars) | 57 ManParser::ManParser(const w_char* wordchars, int len) |
| 18 { | 58 : TextParser(wordchars, len) { |
| 19 » init(wordchars); | |
| 20 } | 59 } |
| 21 | 60 |
| 22 ManParser::ManParser(unsigned short * wordchars, int len) | 61 ManParser::~ManParser() {} |
| 23 { | 62 |
| 24 » init(wordchars, len); | 63 bool ManParser::next_token(std::string& t) { |
| 64 for (;;) { |
| 65 switch (state) { |
| 66 case 1: // command arguments |
| 67 if (line[actual][head] == ' ') |
| 68 state = 2; |
| 69 break; |
| 70 case 0: // dot in begin of line |
| 71 if (line[actual][0] == '.') { |
| 72 state = 1; |
| 73 break; |
| 74 } else { |
| 75 state = 2; |
| 76 } |
| 77 // no break |
| 78 case 2: // non word chars |
| 79 if (is_wordchar(line[actual].c_str() + head)) { |
| 80 state = 3; |
| 81 token = head; |
| 82 } else if ((line[actual][head] == '\\') && |
| 83 (line[actual][head + 1] == 'f') && |
| 84 (line[actual][head + 2] != '\0')) { |
| 85 head += 2; |
| 86 } |
| 87 break; |
| 88 case 3: // wordchar |
| 89 if (!is_wordchar(line[actual].c_str() + head)) { |
| 90 state = 2; |
| 91 if (alloc_token(token, &head, t)) |
| 92 return true; |
| 93 } |
| 94 break; |
| 95 } |
| 96 if (next_char(line[actual].c_str(), &head)) { |
| 97 state = 0; |
| 98 return false; |
| 99 } |
| 100 } |
| 25 } | 101 } |
| 26 | |
| 27 ManParser::~ManParser() | |
| 28 { | |
| 29 } | |
| 30 | |
| 31 char * ManParser::next_token() | |
| 32 { | |
| 33 for (;;) { | |
| 34 switch (state) | |
| 35 { | |
| 36 case 1: // command arguments | |
| 37 if (line[actual][head] == ' ') state = 2; | |
| 38 break; | |
| 39 case 0: // dot in begin of line | |
| 40 if (line[actual][0] == '.') { | |
| 41 state = 1; | |
| 42 break; | |
| 43 } else { | |
| 44 state = 2; | |
| 45 } | |
| 46 // no break | |
| 47 case 2: // non word chars | |
| 48 if (is_wordchar(line[actual] + head)) { | |
| 49 state = 3; | |
| 50 token = head; | |
| 51 } else if ((line[actual][head] == '\\') && | |
| 52 (line[actual][head + 1] == 'f') && | |
| 53 (line[actual][head + 2] != '\0')) { | |
| 54 head += 2; | |
| 55 } | |
| 56 break; | |
| 57 case 3: // wordchar | |
| 58 if (! is_wordchar(line[actual] + head)) { | |
| 59 state = 2; | |
| 60 char * t = alloc_token(token, &head); | |
| 61 if (t) return t; | |
| 62 } | |
| 63 break; | |
| 64 } | |
| 65 if (next_char(line[actual], &head)) { | |
| 66 state = 0; | |
| 67 return NULL; | |
| 68 } | |
| 69 } | |
| 70 } | |
| 71 | |
| OLD | NEW |