#LyX 1.1 created this file. For more info see http://www.lyx.org/ \lyxformat 218 \textclass book \begin_preamble \usepackage{html} \newcommand{\doubledash}{-\hspace{0.1em}-} \newcommand{\doubledashb}{-\/-} \begin{htmlonly} \renewenvironment{lyxcode} {\begin{list}{}{ \setlength{\rightmargin}{\leftmargin} \raggedright \setlength{\itemsep}{0pt} \setlength{\parsep}{0pt} \ttfamily}% \item[] \begin{ttfamily}} {\end{ttfamily} \end{list} } \newenvironment{LyXParagraphIndent}[1]% {\begin{quote}} {\end{quote}} \renewcommand{\LyX}{LyX} \renewcommand{\doubledash}{\rawhtml --\endrawhtml} \renewcommand{\doubledashb}{\rawhtml --\endrawhtml} \end{htmlonly} \end_preamble \language english \inputencoding latin1 \fontscheme default \graphics default \paperfontsize default \spacing single \papersize letterpaper \paperpackage a4 \use_geometry 1 \use_amsmath 0 \paperorientation portrait \leftmargin 1.25in \topmargin 0.5in \rightmargin 1.25in \bottommargin 0.5in \secnumdepth 2 \tocdepth 2 \paragraph_separation skip \defskip medskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Title Portable Spell Checker Interface Library \layout Author Kevin Atkinson \shape italic \newline kevina at users sourceforge net \layout Date Version 0.12.2 \layout Standard \begin_inset LatexCommand \tableofcontents{} \end_inset \layout Chapter Introduction \layout Section Goal \layout Standard The goal of the library is to provide a generic interface to Spell checker libraries installed on the system. \layout Chapter Getting Started \layout Section Obtaining \layout Standard The latest version of pspell can always be found at the pspell home page at \begin_inset LatexCommand \url{http://pspell.sourceforge.net/} \end_inset \layout Section Support \layout Standard Support for Pspell can be found on the Pspell mailing lists. Instructions for joining the various mailing lists (and an archive of them) can be found off the Pspell home page at \begin_inset LatexCommand \url{http://pspell.sourceforge.net} \end_inset . \layout Section Installation \layout Subsection Generic Install Instructions \layout Standard To install the library simply type \layout LyX-Code ./configure \layout LyX-Code make \layout LyX-Code make install \layout Standard Then install at least one pspell module. You can find more information about available modules from the Pspell home page. This is all that should be required for Pspell to function properly. \layout Standard If you run into problems you can try disabling the building of shared libraries with --disable-shared and/or the ltdl library which is used for dynamically loading pspell modules with --disable-ltdl. If you do so you will then need to manually link in the necessary modules by doing the following: \layout LyX-Code cd modules \layout LyX-Code ./add-modules \layout LyX-Code cd .. \layout LyX-Code make \layout LyX-Code make install \layout Standard However this has not been known to work properly on most platforms. If you are just installing Pspell so that you can compile and use the Aspell utility then you should be okay as Aspell does not need any of Pspell modules linked in. However, if you are trying to use Pspell with an application that actually used the Pspell library such as PHP, AbiWord or the like then you will likely run into problems. \layout Standard By default a static library is also created you can turn this of by passing the parameter --disable-static to configure. You can control what C and C++ compiler is used by setting the environmental variable CC and CXX respectfully before running configure and you can control what flags are passed to the C and C++ compile via the environmental variable CFLAGS and CXXFLAGS respectfully. \layout Subsection General Problems \layout Standard Aspell does not use a released version of GNU Libtool. In previous versions of aspell this will often create problems if you inadverte ntly modify a file which causes Libtool to be called. However, as of Pspell .12.2 this so no longer be a problem and automake, autoconf, or libtool should not be called unless you specifically call them or if you configure Aspell with --enable-maintainer-mode. If you do notice any of these programs being called (and you did not configure with --enable-maintainer-mode) please let me know about it. If you have a need to modify configure.in or any of the Makefile.am's you should install the multi-language-branch of the CVS version of libtool. \layout Subsection Problems with Libltdl \layout Standard Pspell also requires libltdl, Libtool's portable \begin_inset Quotes eld \end_inset dlopen \begin_inset Quotes erd \end_inset wrapper library, in order to function properly. If configure does not find libltdl installed on your system it will generally compile it and install it with the rest of Pspell. However, this can create problems if the compile environment is different than the environment that Pspell runs under. For example if configure was able to find libltdl at compile time but libltdl is no longer visible at runtime you will run into problems. The easiest thing to do here is copy the libltdl library found when compiling Pspell into the library directly Pspell was installed in. Another potently source of problems is the fact that the version of Libltdl found in the Pspell distribution is not the same as the one found in the released version of Libtool. In fact the two, while being source code compatible, are not binary compatible. This should normally not be a problem because if configure finds libltdl already installed on your system it will use that one. However, this might cause problems if the compile environment is different than the environment that Pspell runs under. \layout Subsection Upgrading from Pspell .11.2 \layout Standard \begin_inset LatexCommand \label{new_size_parm} \end_inset Pspell .12 breaks binary and source code compatibility with Pspell .11. Many of the PspellManager functions now also have a length parameter specifying the length of the word. A length of -1 means that the string is null terminated. This unfortunately breaks source code compatibility. To upgrade to Pspell .12 either define the variable USE_ORIGINAL_MANAGER_FUNCS before pspell.h in included or simply add a length of -1 after each word passed in. Please see manager.h for the exact phototype of the functions. Defining the variable USE_ORIGINAL_MANAGER_FUNCS will allow your code to work with both Pspell .11 and .12. \layout Section Helping Out \layout Standard Right now the area I need the most help in is better shared library support and on the ispell module. If you are interested in helping out please contact me at kevina@users.sourcefor ge.net. \layout Standard If you wish to work on Pspell you will need the multi-language-branch of the CVS version of libtool. You will also need autoconf and automake. The released version of autoconf has a small bug in it which will cause it to think \begin_inset Quotes eld \end_inset .C \begin_inset Quotes erd \end_inset is the extension of executables. To fix this you need to apply the patch \begin_inset Quotes eld \end_inset autoconf-exeext.patch \begin_inset Quotes erd \end_inset which can be found in the pspell distribution. \layout Chapter Keeping in Touch \layout Standard Even though you the LGPL license gives you the right to use Pspell in your application without ever notifying me, Kevin Atkinson, the sole author of Pspell---please don't. If you are using, or planning on using, Pspell in your project please at very least send me an email at kevina at users sourceforge net. It doesn't have to me anything fancy. A simple \begin_inset Quotes eld \end_inset I am planning on using Pspell in my project X. For more information please see Y. \begin_inset Quotes erd \end_inset will suffice. I will greatly appreciate it. I put a lot of unpaid time into Pspell and Aspell and would appreciate simply knowing where it is being used. \layout Chapter Library Interface \layout Section Overview \layout Standard The Pspell library contains two main classes and several helper classes. The two main classes are PspellConfig and PspellMaster. The PspellConfig class is used to set initial defaults and to change spell checker specific options. The PspellManager class does most of the real work. It is responsible for managing the dictionaries, checking if a word is in the dictionary, and coming up with suggestions among other things. There are many helper classes the important ones are PspellWordList, PspellMuta bleWordList, Pspell*Emulation. The PspellWordList classes is used for accessing the suggestion list, as well as the personal and suggestion word list currently in use. The PspellMutableWordList is used to manage the personal, and perhaps other, word lists. The Pspell*Emulation classes are used for iterating through a list. \layout Standard A C and C++ Interface is provided. I recommend using the C interface, even if your program is in C++, to avoid some of the nasty issues associated with C++ linkage. In general one can only use C++ linkage if both the library and the program were created with the same compiler. I may eventually provide C++ wrapper classes, including a few STL like one, for the C library and remove the existing C++ interface all together. \layout Standard The mapping between the C and C++ interface is pretty straightforward and from C++ to C goes as follows: \layout Quote _([const] *, ) \layout Standard For example \begin_inset Quotes eld \end_inset PspellManager::lang_name() const \begin_inset Quotes erd \end_inset would become \begin_inset Quotes eld \end_inset pspell_manager_lang_name(const PspellManager *) \begin_inset Quotes erd \end_inset . \layout Standard Methods that return a bool will instead return an int in the C interface. \layout Section Usage \layout Standard To use pspell your application should include \begin_inset Quotes eld \end_inset pspell/pspell.h \begin_inset Quotes erd \end_inset . In order to insure that all the necessary libraries are linked in libtool should be used to perform the linking. When using libtool simply linking with \begin_inset Quotes eld \end_inset -lpspell \begin_inset Quotes erd \end_inset should be all that is necessary. When using shared libraries you might be able to simply link \begin_inset Quotes eld \end_inset -lpspell \begin_inset Quotes erd \end_inset , but this is not recommended. This version of Pspell uses the CVS version of libtool (multi-language-branch) however released versions of libtool should also work. \layout Standard When your application first starts you should get a new configuration class with the command: \layout LyX-Code PspellConfig * spell_config = new_pspell_config(); \layout Standard which will create a new PspellConfig class. It is allocated with new and it is your responsibility to delete it with delete_pspell_config. The standard C++ delete can be used if the compiler is compatible with the one used to create the Pspell library. Once you have the config class you should set some variables. The most important one is the language variable. To do so use the command: \layout LyX-Code pspell_config_replace(spell_config, "language-tag", "en_US"); \layout Standard which will set the default language to use to American English. The language is expected to be the standard two letter ISO 639 language code, with an optional two letter ISO 3166 country code after an underscore. You can set the preferred spelling via the \begin_inset Quotes eld \end_inset spelling \begin_inset Quotes erd \end_inset option, any extra info via the \begin_inset Quotes eld \end_inset jargon \begin_inset Quotes erd \end_inset option, and the encoding via the \begin_inset Quotes eld \end_inset encoding \begin_inset Quotes erd \end_inset option. Other things you might want to set is the preferred spell checker to use, the search path for dictionary's, and the like see section \begin_inset LatexCommand \ref{options} \end_inset for the available options. \layout Standard When ever a new document is created a new PspellManager class should also be created. There should be one manager class per document. To create a new manager class use the new_pspell_manager and then cast it up using to_pspell_manager like so. \layout LyX-Code PspellCanHaveError * possible_err = new_pspell_manager(spell_config); \layout LyX-Code PspellManager * spell_checker = 0; \layout LyX-Code if (pspell_error_number(possible_err) != 0) \layout LyX-Code puts(pspell_error_message(possible_err)); \layout LyX-Code else \layout LyX-Code spell_checker = to_pspell_manager(possible_err); \layout Standard which will create a new PspellManager class using the defaults found in spell_config. If C++ is being used AND the compiler is compatible with the one used to create the Pspell library a normal cast can be used instead of to_pspell_manage r. \layout Standard If for some reason you want to use different defaults simply clone spell_config and change the setting like so: \layout LyX-Code PspellConfig * spell_config2 = pspell_config_clone(spell_config); \layout LyX-Code pspell_config_replace(spell_config2, "language-tag","nl"); \layout LyX-Code possible_err = new_pspell_manager(spell_config2); \layout LyX-Code delete_pspell_config(spell_config2); \layout Standard Once again in C++ delete_pspell_config can be replaced with a simple C++ delete. Once the manager class is created you can use the check method to see if a word in the document is correct like so: \layout LyX-Code int correct = pspell_manager_check(spell_checker, , ); \layout Standard can is expected to a const char * character string. If the encoding is set to be \begin_inset Quotes eld \end_inset machine unsigned 16 \begin_inset Quotes erd \end_inset or \begin_inset Quotes eld \end_inset machine unsigned 32 \begin_inset Quotes erd \end_inset . is expected to be a cast from either const u16int * or const u32int* respectfully. U16int and u32int are generally unsigned short and unsigned int respectfully. is the length of the string or -1 if the sting is null terminated. If the string is a cast from const u16int * or const u32int * then size is the amount of space in bytes the string takes up after being casted to const char * and not the true size of the string. Pspell_manager_check will return 0 is it is not found and non-zero otherwise. \layout Standard If the word is not correct than the suggest method can be used to come up with likely replacements. \layout LyX-Code PspellWordList * suggestions = pspell_manager_suggest(spell_checker, \layout LyX-Code , ); \layout LyX-Code PspellStringEmulation * elements = pspell_word_list_elements(suggestions); \layout LyX-Code const char * word; \layout LyX-Code while ( (word = pspell_string_emulation_next(pspell_elements) != NULL ) { \layout LyX-Code // add to suggestion list \layout LyX-Code } \layout LyX-Code delete_pspell_string_emulation(elements); \layout Standard Notice how \family typewriter elements \family default is deleted but \family typewriter suggestions \family default is not. The value returned by suggestions is only valid to the next call to suggest. Once a replacement is made the store_repl method should be used to communicate the replacement pair back to the spell checker (see section \begin_inset LatexCommand \ref{storerepl} \end_inset for why). It usage is as follows: \layout LyX-Code pspell_manager_store_repl(spell_checker, \layout LyX-Code , , \layout LyX-Code , ); \layout Standard If the user decided to add the word to the session or personal dictionary the the word can be be added using the add_to_session or add_to_personal methods respectfully like so: \layout LyX-Code pspell_manager_add_to_session|personal(spell_checker, , ); \layout Standard It is better to let the spell checker manage these words rather than doing it your self so that the words have a change of appearing in the suggestion list. \layout Standard Finally, when the document is closed the PspellManager class should be deleted like so. \layout LyX-Code delete_pspell_manager(spell_checker); \layout Standard The standard C++ delete should NOT be used here because it will not unload any shared libraries pulled in my when the manager class is created. \layout Section Class Reference \layout Standard Methods that return a bool generally return false on error and true other wise. To find out what went wrong use the error_number and error_message methods. Unless otherwise stated methods that return a const char * will return null on error. The charter string returned is only valid until the next method which returns a const char * is called. \layout Standard All methods are virtual and abstract, thus these classes are really abstract base classes. Therefore you cannot simply store the object directly. In order to make copies of the objects use the clone and assign methods if they are provided. \layout Standard For the details of the various classes please see the header files. In the future I will generate class references using some automated tool. \layout Section Available Options \begin_inset LatexCommand \label{options} \end_inset \layout Standard The following options are available to control which word list Pspell selects. \layout Description language-tag\SpecialChar ~ the language code which consists of the two letter ISO 639 language code and an optional two letter ISO 3166 country code after a dash or underscore. \layout Description spelling\SpecialChar ~ the requested spelling for languages with more than one spelling such as English. Known values are \begin_inset Quotes eld \end_inset american \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset britsh \begin_inset Quotes erd \end_inset , and \begin_inset Quotes eld \end_inset canadian \begin_inset Quotes erd \end_inset . This information is normally inferred from the language-tag option. For example the language tag \begin_inset Quotes eld \end_inset en_GB \begin_inset Quotes erd \end_inset will set spelling to \begin_inset Quotes eld \end_inset british \begin_inset Quotes erd \end_inset . \layout Description jargon\SpecialChar ~ an extra information to distinguish two different words lists that have the same language-tag and spelling. \layout Description word-list-path\SpecialChar ~ search path for word list information files \layout Description module-search-order\SpecialChar ~ list of available modules, modules that come first on this list have a higher priority \layout Standard The following options control the behavior of the selected module. Not all modules support all options. \layout Description encoding\SpecialChar ~ encoding that words are expected to be in. Valid values are \begin_inset Quotes eld \end_inset utf-8 \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset iso8859-* \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset koi8-r \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset viscii \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset cp1252 \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset machine unsigned 16 \begin_inset Quotes erd \end_inset , \begin_inset Quotes eld \end_inset machine unsigned 32 \begin_inset Quotes erd \end_inset . \layout Description ignore\SpecialChar ~ ignore all words which are not at least as long as the value for this setting \layout Description personal\SpecialChar ~ file name of the personal word list to use. Start it with \begin_inset Quotes eld \end_inset ./ \begin_inset Quotes erd \end_inset to look for the file in the current directory rather than the home directory. \layout Description repl\SpecialChar ~ file name of the replacement word list to use. Start it with \begin_inset Quotes eld \end_inset ./ \begin_inset Quotes erd \end_inset to look for the file in the current directory rather than the home directory. \layout Description save-repl\SpecialChar ~ save the replacement word list on calls to save_all_word_list s. \layout Description ignore-repl\SpecialChar ~ ignore calls to Manager::store_replacement. \layout Description sug-mode\SpecialChar ~ the suggestion mode, known values are fast, normal, and bad-spellers \layout Description run-together\SpecialChar ~ consider run-together words as legal compounds. \layout Standard The following options may be examined to tell exactly what word list or module was selected \layout Description master the full path of the word list selected \layout Description master-flags any special flags that were passed on to the module \layout Description module the module selected \layout Standard The options, \series bold spelling \series default and \series bold jargon \series default can also be examined. \layout Standard options may be set to anything, including in some cases an empty string. options must be set to a valid integer string. options must be set to \begin_inset Quotes eld \end_inset true \begin_inset Quotes erd \end_inset or \begin_inset Quotes eld \end_inset false \begin_inset Quotes erd \end_inset . options can not be set directly, you must use the option add-