Debian Codegraph @

doc/example.txt

raw
1 #include <cstring>
2 #include <cstdlib>
3 #include <cstdio>
4
5 #include "myspell.hxx"
6
7 #ifndef WINDOWS
8 using namespace std;
9 #endif
10
11 int main(int argc, char **argv)
12 {
13 FILE *wtclst;
14 int i;
15 int dp;
16 char buf[101];
17 MySpell *pMS;
18 char **wlst;
19
20 /* first parse the command line options */
21
22 for (i = 1; i < 3; i++)
23 if (!argv[i]) {
24 fprintf(stderr, "correct syntax is:\nexample affix_file");
25 fprintf(stderr, "dictionary_file file_of_words_to_check\n");
26 exit(1);
27 }
28
29 /* open the words to check list */
30
31 wtclst = fopen(argv[3], "r");
32 if (!wtclst) {
33 fprintf(stderr, "Error - could not open file to check\n");
34 exit(1);
35 }
36
37 pMS = new MySpell(argv[1], argv[2]);
38 while (fgets(buf, 100, wtclst)) {
39 *(buf + strlen(buf) - 1) = '\0';
40 dp = pMS->spell(buf);
41 if (dp) {
42 fprintf(stdout, "\"%s\" is okay\n\n", buf);
43 int ns = pMS->suggest_stems(&wlst, buf);
44 if (ns > 0) {
45 fprintf(stdout, " stems:\n");
46 for (int i = 0; i < ns; i++) {
47 fprintf(stdout, " ...\"%s\"\n", wlst[i]);
48 free(wlst[i]);
49 }
50 fprintf(stdout, "\n");
51 }
52 if (wlst) free(wlst);
53 } else {
54 fprintf(stdout, "\"%s\" is incorrect!\n", buf);
55 fprintf(stdout, " suggestions:\n");
56 int ns = pMS->suggest(&wlst, buf);
57 for (int i = 0; i < ns; i++) {
58 fprintf(stdout, " ...\"%s\"\n", wlst[i]);
59 free(wlst[i]);
60 }
61 fprintf(stdout, "\n");
62 if (wlst) free(wlst);
63
64 ns = pMS->suggest_pos_stems(&wlst, buf);
65 if (ns > 0) {
66 fprintf(stdout, " possible stems:\n");
67 for (int i = 0; i < ns; i++) {
68 fprintf(stdout, " ...\"%s\"\n", wlst[i]);
69 free(wlst[i]);
70 }
71 fprintf(stdout, "\n");
72 }
73 if (wlst) free(wlst);
74 }
75 }
76
77 delete pMS;
78 return 0;
79 }