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