Debian Codegraph @

external/hunspell/tools/example.cxx

raw symbols SCIP
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 #include <cstring>
39 #include <cstdlib>
40 #include <fstream>
41
42 #include "../hunspell/hunspell.hxx"
43
44 using namespace std;
45
46 int main(int argc, char** argv) {
47
48 /* first parse the command line options */
49
50 if (argc < 4) {
51 fprintf(stderr, "example (now it works with more dictionary files):\n");
52 fprintf(stderr,
53 "example affix_file dictionary_file(s) file_of_words_to_check\n");
54 exit(1);
55 }
56
57 /* open the words to check list */
58 std::ifstream wtclst(argv[argc - 1], std::ios_base::in);
59 if (!wtclst.is_open()) {
60 fprintf(stderr, "Error - could not open file of words to check\n");
61 exit(1);
62 }
63
64 Hunspell* pMS = new Hunspell(argv[1], argv[2]);
65
66 // load extra dictionaries
67 if (argc > 4)
68 for (int k = 3; k < argc - 1; ++k)
69 pMS->add_dic(argv[k]);
70
71 std::string buf;
72 while (std::getline(wtclst, buf)) {
73 int dp = pMS->spell(buf);
74 if (dp) {
75 fprintf(stdout, "\"%s\" is okay\n", buf.c_str());
76 fprintf(stdout, "\n");
77 } else {
78 fprintf(stdout, "\"%s\" is incorrect!\n", buf.c_str());
79 fprintf(stdout, " suggestions:\n");
80 std::vector<std::string> wlst = pMS->suggest(buf.c_str());
81 for (size_t i = 0; i < wlst.size(); ++i) {
82 fprintf(stdout, " ...\"%s\"\n", wlst[i].c_str());
83 }
84 fprintf(stdout, "\n");
85 }
86 // for the same of testing this code path
87 // do an analysis here and throw away the results
88 pMS->analyze(buf);
89 }
90
91 delete pMS;
92 return 0;
93 }