Tizen 2.1 base
[external/enchant.git] / src / ispell / ispell_checker.h
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef ISPELL_CHECKER_H
3 #define ISPELL_CHECKER_H
4
5 #include <glib.h> // give glib a chance to override MAXPATHLEN first before it is set in ispell.h
6 #include "ispell.h"
7 #include "enchant.h"
8
9 class ISpellChecker
10 {
11 public:
12         ISpellChecker(EnchantBroker * broker);
13         ~ISpellChecker();
14
15         bool checkWord(const char * const word, size_t len);
16         char ** suggestWord(const char * const word, size_t len, size_t * out_n_suggs);
17
18         bool requestDictionary (const char * szLang);
19
20 private:
21         EnchantBroker* m_broker;
22
23         ISpellChecker();
24         ISpellChecker(const ISpellChecker&);    // no impl
25         void operator=(const ISpellChecker&);   // no impl
26
27         char * loadDictionary (const char * szLang );
28         bool   loadDictionaryForLanguage ( const char * szLang );
29         void   setDictionaryEncoding ( const char * hashname, const char * enc );
30
31         //
32         // The member functions after this point were formerly global functions
33         //  passed a context structure pointer...
34         //
35
36         void try_autodetect_charset(const char * inEncoding);
37
38         //
39         // From ispell correct.c
40         //
41
42         int             casecmp P ((char * a, char * b, int canonical));
43         void            makepossibilities P ((ichar_t * word));
44         int     insert P ((ichar_t * word));
45 #ifndef NO_CAPITALIZATION_SUPPORT
46         void    wrongcapital P ((ichar_t * word));
47 #endif /* NO_CAPITALIZATION_SUPPORT */
48         void    wrongletter P ((ichar_t * word));
49         void    extraletter P ((ichar_t * word));
50         void    missingletter P ((ichar_t * word));
51         void    missingspace P ((ichar_t * word));
52         int             compoundgood P ((ichar_t * word, int pfxopts));
53         void    transposedletter P ((ichar_t * word));
54         int     ins_cap P ((ichar_t * word, ichar_t * pattern));
55         int     save_cap P ((ichar_t * word, ichar_t * pattern,
56                           ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN]));
57         int             ins_root_cap P ((ichar_t * word, ichar_t * pattern,
58                           int prestrip, int preadd, int sufstrip, int sufadd,
59                           struct dent * firstdent, struct flagent * pfxent,
60                           struct flagent * sufent));
61         void    save_root_cap P ((ichar_t * word, ichar_t * pattern,
62                           int prestrip, int preadd, int sufstrip, int sufadd,
63                           struct dent * firstdent, struct flagent * pfxent,
64                           struct flagent * sufent,
65                           ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN],
66                           int * nsaved));
67
68         //
69         // From ispell good.c
70         //
71
72         int good (ichar_t* w, int ignoreflagbits, int allhits, int pfxopts, int sfxopts);
73         void chk_aff (ichar_t* word, ichar_t* ucword, int len, int ignoreflagbits, int allhits, int pfxopts, int sfxopts);
74         int linit(char*);
75         struct dent * ispell_lookup (ichar_t* s, int dotree);
76         int strtoichar (ichar_t* out, char* in, int outlen, int canonical);
77         int ichartostr (char* out, ichar_t* in, int outlen, int canonical);
78         char * ichartosstr (ichar_t* in, int canonical);
79         int     findfiletype (const char * name, int searchnames, int * deformatter);
80         long whatcap (ichar_t* word);
81
82         /*
83                 HACK: macros replaced with function implementations 
84                 so we could do a side-effect-free check for unicode
85                 characters which aren't in hashheader
86         */
87         char myupper(ichar_t c);
88         char mylower(ichar_t c);
89         int myspace(ichar_t c);
90         char iswordch(ichar_t c);
91         char isboundarych(ichar_t c);
92         char isstringstart(ichar_t c);
93         ichar_t mytolower(ichar_t c);
94         ichar_t mytoupper(ichar_t c);
95
96 #ifndef ICHAR_IS_CHAR
97         int cap_ok (ichar_t* word, struct success* hit, int len);
98
99         int hash (ichar_t* s, int hashtblsize);
100 #endif
101
102         //
103         // From ispell lookup.c
104         //
105
106         void    clearindex P ((struct flagptr * indexp));
107         void     initckch P ((char *));
108
109         void alloc_ispell_struct();
110         void free_ispell_struct();
111
112         //
113         // From ispell makedent.c
114         //
115
116         int             addvheader P ((struct dent * ent));
117         void            upcase P ((ichar_t * string));
118         void            lowcase P ((ichar_t * string));
119         void            chupcase P ((char * s));
120
121         int             stringcharlen P ((char * bufp, int canonical));
122         ichar_t *       strtosichar P ((char * in, int canonical));
123         char *          printichar P ((int in));
124
125         //
126         // From ispell tgood.c
127         //
128
129         void    pfx_list_chk P ((ichar_t * word, ichar_t * ucword,
130                           int len, int optflags, int sfxopts, struct flagptr * ind,
131                           int ignoreflagbits, int allhits));
132         void    chk_suf P ((ichar_t * word, ichar_t * ucword, int len,
133                           int optflags, struct flagent * pfxent, int ignoreflagbits,
134                           int allhits));
135         void    suf_list_chk P ((ichar_t * word, ichar_t * ucword, int len,
136                           struct flagptr * ind, int optflags, struct flagent * pfxent,
137                           int ignoreflagbits, int allhits));
138         int             expand_pre P ((char * croot, ichar_t * rootword,
139                           MASKTYPE mask[], int option, char * extra));
140         int     pr_pre_expansion P ((char * croot, ichar_t * rootword,
141                           struct flagent * flent, MASKTYPE mask[], int option,
142                           char * extra));
143         int             expand_suf P ((char * croot, ichar_t * rootword,
144                           MASKTYPE mask[], int optflags, int option, char * extra));
145         int     pr_suf_expansion P ((char * croot, ichar_t * rootword,
146                           struct flagent * flent, int option, char * extra));
147         void    forcelc P ((ichar_t * dst, int len));
148
149         /* this is used for converting form unsigned short to UCS-4 */
150
151         int deftflag;              /* NZ for TeX mode by default */
152         int prefstringchar;        /* Preferred string character type */
153         bool m_bSuccessfulInit;
154
155         //
156         // The members after this point were formerly global variables
157         //  in the original ispell code
158         //
159
160         char *  m_BC;   /* backspace if not ^H */
161         char *  m_cd;   /* clear to end of display */
162         char *  m_cl;   /* clear display */
163         char *  m_cm;   /* cursor movement */
164         char *  m_ho;   /* home */
165         char *  m_nd;   /* non-destructive space */
166         char *  m_so;   /* standout */
167         char *  m_se;   /* standout end */
168         int     m_sg;   /* space taken by so/se */
169         char *  m_ti;   /* terminal initialization sequence */
170         char *  m_te;   /* terminal termination sequence */
171         int     m_li;   /* lines */
172         int     m_co;   /* columns */
173
174         char    m_ctoken[INPUTWORDLEN + MAXAFFIXLEN]; /* Current token as char */
175         ichar_t m_itoken[INPUTWORDLEN + MAXAFFIXLEN]; /* Ctoken as ichar_t str */
176
177         int     m_numhits;      /* number of hits in dictionary lookups */
178         struct success
179                         m_hits[MAX_HITS]; /* table of hits gotten in lookup */
180
181         char *  m_hashstrings;  /* Strings in hash table */
182         struct hashheader
183                         m_hashheader;   /* Header of hash table */
184         struct dent *
185                         m_hashtbl;      /* Main hash table, for dictionary */
186         int     m_hashsize;     /* Size of main hash table */
187
188         char    m_hashname[MAXPATHLEN]; /* Name of hash table file */
189
190         int     m_aflag;                /* NZ if -a or -A option specified */
191         int     m_cflag;                /* NZ if -c (crunch) option */
192         int     m_lflag;                /* NZ if -l (list) option */
193         int     m_incfileflag;  /* whether xgets() acts exactly like gets() */
194         int     m_nodictflag;   /* NZ if dictionary not needed */
195
196         int     m_uerasechar;   /* User's erase character, from stty */
197         int     m_ukillchar;    /* User's kill character */
198
199         unsigned int m_laststringch; /* Number of last string character */
200         int     m_defdupchar;   /* Default duplicate string type */
201
202         int     m_numpflags;            /* Number of prefix flags in table */
203         int     m_numsflags;            /* Number of suffix flags in table */
204         struct flagptr m_pflagindex[SET_SIZE + MAXSTRINGCHARS];
205                                                 /* Fast index to pflaglist */
206         struct flagent *        m_pflaglist;    /* Prefix flag control list */
207         struct flagptr m_sflagindex[SET_SIZE + MAXSTRINGCHARS];
208                                                 /* Fast index to sflaglist */
209         struct flagent *        m_sflaglist;    /* Suffix flag control list */
210
211         struct strchartype *            /* String character type collection */
212                         m_chartypes;
213
214         FILE *  m_infile;                       /* File being corrected */
215         FILE *  m_outfile;              /* Corrected copy of infile */
216
217         char *  m_askfilename;          /* File specified in -f option */
218
219         int     m_changes;              /* NZ if changes made to cur. file */
220         int     m_readonly;             /* NZ if current file is readonly */
221         int     m_quit;                 /* NZ if we're done with this file */
222
223 #define MAXPOSSIBLE     100     /* Max no. of possibilities to generate */
224
225         char    m_possibilities[MAXPOSSIBLE][INPUTWORDLEN + MAXAFFIXLEN];
226                                         /* Table of possible corrections */
227         int     m_pcount;               /* Count of possibilities generated */
228         int     m_maxposslen;   /* Length of longest possibility */
229         int     m_easypossibilities; /* Number of "easy" corrections found */
230                                         /* ..(defined as those using legal affixes) */
231
232         /*
233          * The following array contains a list of characters that should be tried
234          * in "missingletter."  Note that lowercase characters are omitted.
235          */
236         int     m_Trynum;               /* Size of "Try" array */
237         ichar_t m_Try[SET_SIZE + MAXSTRINGCHARS];
238
239         GIConv  m_translate_in; /* Selected translation from/to Unicode */
240         GIConv  m_translate_out;
241 };
242
243 #endif /* ISPELL_CHECKER_H */