~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/SpellChecker/wxspellchecker/MySpell/example.cxx

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

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