[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pspell] c-API question
From: |
Kevin Atkinson |
Subject: |
Re: [pspell] c-API question |
Date: |
Sun, 11 Jun 2000 15:51:28 -0400 (EDT) |
On Sun, 11 Jun 2000, Troels Arvin wrote:
> I plan to add pspell support to PHP 4, in stead of PHP 4's aspell-module
> which doesn't work with newer versions of aspell.
>
> However, I'm still not that familiar with the pspell c-API, so I'll be
> happy if someone looks over the code pasted below to see if I'm using
> the API in a proper way. Note the questions included as comments in the
> code.
>
> Thanks in advance.
>
> /Troels Arvin, Copenhagen, Denmark
>
>
>
> /*
> spellcheck.c
>
> Is compiled by entering
> gcc -Wall -o spellcheck -lpspell spellcheck.c
You should use libtool to compile. On solaris this WILL NOT work as
Solaris requires you to list out every single library.
>
> */
>
> #include <stdio.h>
> #include "/usr/local/include/pspell/pspell.h"
>
> int main()
> {
> PspellConfig * pcon;
> PspellCanHaveError * perr;
> PspellManager * pman;
> PspellStringEmulation * psemu;
> const PspellWordList * wlist;
>
> char myWord[20]="dentistt";
> char myLang[10]="en-US";
>
> int result;
>
> printf("myWord is `%s`; myLang is `%s`\n",myWord,myLang);
>
> pcon=new_pspell_config();
> pspell_config_replace(pcon, "language-tag",myLang);
>
> perr=new_pspell_manager(pcon);
You should check for an error here before you convert.
> pman=to_pspell_manager(perr);
>
> result = pspell_manager_check(pman,myWord);
>
> if (result)
> {
> printf("The word '%s' is OK\n",myWord);
> } else {
> printf("The word '%s' is misspelled\n",myWord);
> wlist = pspell_manager_suggest(pman,myWord);
>
> if (!pspell_word_list_empty(wlist))
> {
> printf("List of suggestions:\n");
>
> psemu = pspell_word_list_elements(wlist);
>
> while (!pspell_string_emulation_at_end(psemu))
> {
> printf
> (
> "\t%s\n",
> pspell_string_emulation_next(psemu)
> );
> }
>
> delete_pspell_string_emulation(psemu);
> }
>
> /*
> delete_pspell_wordlist(wlist); // Do I need to somehow
> // destroy the wordlist?
> */
No, and you should not. I will try to make that clearer.
>
>
> /*
> delete_pspell_manager(pman); // If I do this, the
> // program will core-dump.
> // Not needed?
> */
Try removing the delete_pspell_wordlist(wlist) and see what happens?
>
> delete_pspell_can_have_error(perr);
Don't do this. pman == perr.
> delete_pspell_config(pcon);
> }
>
> return(0);
> }
--
Kevin Atkinson
address@hidden
http://metalab.unc.edu/kevina/