ispell_checker.h

00001 /* vim: set sw=8: -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
00002 /* kspell2 - adopted from Enchant
00003  * Copyright (C) 2003 Dom Lachowicz
00004  * Copyright (C) 2004 Zack Rusin <zack@kde.org>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * In addition, as a special exception, Dom Lachowicz
00022  * gives permission to link the code of this program with
00023  * non-LGPL Spelling Provider libraries (eg: a MSFT Office
00024  * spell checker backend) and distribute linked combinations including
00025  * the two.  You must obey the GNU Lesser General Public License in all
00026  * respects for all of the code used other than said providers.  If you modify
00027  * this file, you may extend this exception to your version of the
00028  * file, but you are not obligated to do so.  If you do not wish to
00029  * do so, delete this exception statement from your version.
00030  */
00031 
00032 #ifndef ISPELL_CHECKER_H
00033 #define ISPELL_CHECKER_H
00034 
00035 #include "ispell.h"
00036 
00037 #include <qstringlist.h>
00038 #include <qvaluelist.h>
00039 #include <qtextcodec.h>
00040 #include <qstring.h>
00041 
00042 
00043 class ISpellChecker
00044 {
00045 public:
00046     ISpellChecker();
00047     ~ISpellChecker();
00048 
00049     bool checkWord(const QString& word);
00050     QStringList suggestWord(const QString& word);
00051 
00052     bool requestDictionary (const char * szLang);
00053     static QValueList<QString> allDics();
00054 private:
00055     ISpellChecker(const ISpellChecker&);    // no impl
00056     void operator=(const ISpellChecker&);   // no impl
00057 
00058     QString loadDictionary (const char * szLang );
00059     bool   loadDictionaryForLanguage ( const char * szLang );
00060     void   setDictionaryEncoding ( const QString& hashname, const char * enc );
00061 
00062     //
00063     // The member functions after this point were formerly global functions
00064     //  passed a context structure pointer...
00065     //
00066 
00067     void try_autodetect_charset(const char * inEncoding);
00068 
00069     //
00070     // From ispell correct.c
00071     //
00072 
00073     int     casecmp P ((char * a, char * b, int canonical));
00074     void        makepossibilities P ((ichar_t * word));
00075     int insert P ((ichar_t * word));
00076 #ifndef NO_CAPITALIZATION_SUPPORT
00077     void    wrongcapital P ((ichar_t * word));
00078 #endif /* NO_CAPITALIZATION_SUPPORT */
00079     void    wrongletter P ((ichar_t * word));
00080     void    extraletter P ((ichar_t * word));
00081     void    missingletter P ((ichar_t * word));
00082     void    missingspace P ((ichar_t * word));
00083     int     compoundgood P ((ichar_t * word, int pfxopts));
00084     void    transposedletter P ((ichar_t * word));
00085     int ins_cap P ((ichar_t * word, ichar_t * pattern));
00086     int save_cap P ((ichar_t * word, ichar_t * pattern,
00087               ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN]));
00088     int     ins_root_cap P ((ichar_t * word, ichar_t * pattern,
00089               int prestrip, int preadd, int sufstrip, int sufadd,
00090               struct dent * firstdent, struct flagent * pfxent,
00091               struct flagent * sufent));
00092     void    save_root_cap P ((ichar_t * word, ichar_t * pattern,
00093               int prestrip, int preadd, int sufstrip, int sufadd,
00094               struct dent * firstdent, struct flagent * pfxent,
00095               struct flagent * sufent,
00096               ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN],
00097               int * nsaved));
00098 
00099     //
00100     // From ispell good.c
00101     //
00102 
00103     int good (ichar_t* w, int ignoreflagbits, int allhits, int pfxopts, int sfxopts);
00104     void chk_aff (ichar_t* word, ichar_t* ucword, int len, int ignoreflagbits, int allhits, int pfxopts, int sfxopts);
00105     int linit(char*);
00106     struct dent * ispell_lookup (ichar_t* s, int dotree);
00107     int strtoichar (ichar_t* out, char* in, int outlen, int canonical);
00108     int ichartostr (char* out, ichar_t* in, int outlen, int canonical);
00109     char * ichartosstr (ichar_t* in, int canonical);
00110     int findfiletype (const char * name, int searchnames, int * deformatter);
00111     long whatcap (ichar_t* word);
00112 
00113     /*
00114         HACK: macros replaced with function implementations
00115         so we could do a side-effect-free check for unicode
00116         characters which aren't in hashheader
00117     */
00118     char myupper(ichar_t c);
00119     char mylower(ichar_t c);
00120     int myspace(ichar_t c);
00121     char iswordch(ichar_t c);
00122     char isboundarych(ichar_t c);
00123     char isstringstart(ichar_t c);
00124     ichar_t mytolower(ichar_t c);
00125     ichar_t mytoupper(ichar_t c);
00126 
00127 #ifndef ICHAR_IS_CHAR
00128     int cap_ok (ichar_t* word, struct success* hit, int len);
00129 
00130     int hash (ichar_t* s, int hashtblsize);
00131 #endif
00132 
00133     //
00134     // From ispell lookup.c
00135     //
00136 
00137     void    clearindex P ((struct flagptr * indexp));
00138     void     initckch P ((char *));
00139 
00140     void alloc_ispell_struct();
00141     void free_ispell_struct();
00142 
00143     //
00144     // From ispell makedent.c
00145     //
00146 
00147     int     addvheader P ((struct dent * ent));
00148     void        upcase P ((ichar_t * string));
00149     void        lowcase P ((ichar_t * string));
00150     void        chupcase P ((char * s));
00151 
00152     int     stringcharlen P ((char * bufp, int canonical));
00153     ichar_t *   strtosichar P ((char * in, int canonical));
00154     char *      printichar P ((int in));
00155 
00156     //
00157     // From ispell tgood.c
00158     //
00159 
00160     void    pfx_list_chk P ((ichar_t * word, ichar_t * ucword,
00161               int len, int optflags, int sfxopts, struct flagptr * ind,
00162               int ignoreflagbits, int allhits));
00163     void    chk_suf P ((ichar_t * word, ichar_t * ucword, int len,
00164               int optflags, struct flagent * pfxent, int ignoreflagbits,
00165               int allhits));
00166     void    suf_list_chk P ((ichar_t * word, ichar_t * ucword, int len,
00167               struct flagptr * ind, int optflags, struct flagent * pfxent,
00168               int ignoreflagbits, int allhits));
00169     int     expand_pre P ((char * croot, ichar_t * rootword,
00170               MASKTYPE mask[], int option, char * extra));
00171     int pr_pre_expansion P ((char * croot, ichar_t * rootword,
00172               struct flagent * flent, MASKTYPE mask[], int option,
00173               char * extra));
00174     int     expand_suf P ((char * croot, ichar_t * rootword,
00175               MASKTYPE mask[], int optflags, int option, char * extra));
00176     int pr_suf_expansion P ((char * croot, ichar_t * rootword,
00177               struct flagent * flent, int option, char * extra));
00178     void    forcelc P ((ichar_t * dst, int len));
00179 
00180     /* this is used for converting form unsigned short to UCS-4 */
00181 
00182     int deftflag;              /* NZ for TeX mode by default */
00183     int prefstringchar;        /* Preferred string character type */
00184     bool m_bSuccessfulInit;
00185 
00186     //
00187     // The members after this point were formerly global variables
00188     //  in the original ispell code
00189     //
00190 
00191     char *  m_BC;   /* backspace if not ^H */
00192     char *  m_cd;   /* clear to end of display */
00193     char *  m_cl;   /* clear display */
00194     char *  m_cm;   /* cursor movement */
00195     char *  m_ho;   /* home */
00196     char *  m_nd;   /* non-destructive space */
00197     char *  m_so;   /* standout */
00198     char *  m_se;   /* standout end */
00199     int m_sg;   /* space taken by so/se */
00200     char *  m_ti;   /* terminal initialization sequence */
00201     char *  m_te;   /* terminal termination sequence */
00202     int m_li;   /* lines */
00203     int m_co;   /* columns */
00204 
00205     char    m_ctoken[INPUTWORDLEN + MAXAFFIXLEN]; /* Current token as char */
00206     ichar_t m_itoken[INPUTWORDLEN + MAXAFFIXLEN]; /* Ctoken as ichar_t str */
00207 
00208     int m_numhits;  /* number of hits in dictionary lookups */
00209     struct success
00210             m_hits[MAX_HITS]; /* table of hits gotten in lookup */
00211 
00212     char *  m_hashstrings;  /* Strings in hash table */
00213     struct hashheader
00214             m_hashheader;   /* Header of hash table */
00215     struct dent *
00216             m_hashtbl;  /* Main hash table, for dictionary */
00217     int m_hashsize; /* Size of main hash table */
00218 
00219     char    m_hashname[MAXPATHLEN]; /* Name of hash table file */
00220 
00221     int m_aflag;        /* NZ if -a or -A option specified */
00222     int m_cflag;        /* NZ if -c (crunch) option */
00223     int m_lflag;        /* NZ if -l (list) option */
00224     int m_incfileflag;  /* whether xgets() acts exactly like gets() */
00225     int m_nodictflag;   /* NZ if dictionary not needed */
00226 
00227     int m_uerasechar;   /* User's erase character, from stty */
00228     int m_ukillchar;    /* User's kill character */
00229 
00230     unsigned int m_laststringch; /* Number of last string character */
00231     int m_defdupchar;   /* Default duplicate string type */
00232 
00233     int m_numpflags;        /* Number of prefix flags in table */
00234     int m_numsflags;        /* Number of suffix flags in table */
00235     struct flagptr m_pflagindex[SET_SIZE + MAXSTRINGCHARS];
00236                         /* Fast index to pflaglist */
00237     struct flagent *    m_pflaglist;    /* Prefix flag control list */
00238     struct flagptr m_sflagindex[SET_SIZE + MAXSTRINGCHARS];
00239                         /* Fast index to sflaglist */
00240     struct flagent *    m_sflaglist;    /* Suffix flag control list */
00241 
00242     struct strchartype *        /* String character type collection */
00243             m_chartypes;
00244 
00245     FILE *  m_infile;           /* File being corrected */
00246     FILE *  m_outfile;      /* Corrected copy of infile */
00247 
00248     char *  m_askfilename;      /* File specified in -f option */
00249 
00250     int m_changes;      /* NZ if changes made to cur. file */
00251     int m_readonly;     /* NZ if current file is readonly */
00252     int m_quit;         /* NZ if we're done with this file */
00253 
00254 #define MAXPOSSIBLE 100 /* Max no. of possibilities to generate */
00255 
00256     char    m_possibilities[MAXPOSSIBLE][INPUTWORDLEN + MAXAFFIXLEN];
00257                     /* Table of possible corrections */
00258     int m_pcount;       /* Count of possibilities generated */
00259     int m_maxposslen;   /* Length of longest possibility */
00260     int m_easypossibilities; /* Number of "easy" corrections found */
00261                     /* ..(defined as those using legal affixes) */
00262 
00263     /*
00264      * The following array contains a list of characters that should be tried
00265      * in "missingletter."  Note that lowercase characters are omitted.
00266      */
00267     int m_Trynum;       /* Size of "Try" array */
00268     ichar_t m_Try[SET_SIZE + MAXSTRINGCHARS];
00269 
00270     QTextCodec   *m_translate_in; /* Selected translation from/to Unicode */
00271 };
00272 
00273 #endif /* ISPELL_CHECKER_H */
KDE Home | KDE Accessibility Home | Description of Access Keys