Text-Aspell-0.09/0000755000175000017500000000000010674607332013530 5ustar moseleymoseleyText-Aspell-0.09/t/0000755000175000017500000000000010674607332013773 5ustar moseleymoseleyText-Aspell-0.09/t/02-pod.t0000644000175000017500000000031410616265424015155 0ustar moseleymoseley# Thanks sri use Test::More; eval "use Test::Pod 1.14"; plan skip_all => 'Test::Pod 1.14 required' if $@; plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; all_pod_files_ok(); Text-Aspell-0.09/t/05-core.t0000644000175000017500000001030310674607250015326 0ustar moseleymoseley#!perl -w use strict; use Test::More tests => 19; use Text::Aspell; BEGIN { use_ok( 'Text::Aspell' ); } # Always passes, but returns true or false for so can show diag sub ok_to_fail { my ( $ok, $message ) = @_; pass( $message ); return $ok; } my $speller = Text::Aspell->new; ok( $speller, 'Create Speller object' ); ok( $speller->set_option('sug-mode','fast'), 'Set option sug-mode to "fast"' ) or diag( "Error: " . $speller->errstr ); #print defined $speller->create_speller ? "ok 4\n" : "not ok 4 " . $speller->errstr . "\n"; ok( $speller->set_option( 'lang', 'en_US' ), 'Set language to en_US' ) or diag( "Error: " . $speller->errstr ); my $language = $speller->get_option('lang'); is ( $language, 'en_US', "check that 'lang' option is en_US" ) or diag( "Really need the en_US dictionary installed!" ); ok( $speller->check('test'), 'Make sure word "test" is in dictionary' ) or do { my $err = $speller->errstr; diag(<<""); ******************************************************************** * Error: $err * * Are you sure you have the Aspell en_US dictionary installed? * ********************************************************************* }; my $new_word = 'testt'; # make sure $new_word does NOT exist in the dictionary ok( !$speller->check( $new_word ), "Word '$new_word' should NOT be in dictionary" ); ok( $speller->suggest($new_word), "suggest for word '$new_word'" ) or diag( 'Error: ' . $speller->errstr ); my @s_words = $speller->suggest($new_word); ok( @s_words > 2, "search for testt returned more than 2 [@s_words]" ); # Now add $new_word to session so it will be returned in suggestions ok ( $speller->add_to_session($new_word), "add '$new_word' to the aspell session") or diag( 'Error: ' . $speller->errstr ); @s_words = $speller->suggest($new_word); ok( grep(/$new_word/, @s_words), "'$new_word' added to session now is returned in suggest" ); ok_to_fail( $speller->store_replacement( 'foo', 'bar' ), 'Store replacement "foo" for "bar"' ) or diag( 'See README for more info on store_replacemnt' ); ok( grep( /bar/, $speller->suggest('foo')), 'Searching for "foo" found replacement "bar"' ); ok_to_fail( $speller->clear_session, 'Clear the aspell session' ) or diag("clear_session may fail like store_replacement. See README" ); @s_words = $speller->suggest($new_word); ok( !grep(/$new_word/, @s_words), "'$new_word' should not be a suggestion after clearing the session") or diag( "suggested words were [@s_words]" ); my @dicts = $speller->list_dictionaries; ok( @dicts, scalar @dicts . ' dictionaries listed' ); @dicts = $speller->dictionary_info; ok( @dicts, scalar @dicts . ' dictionaries found with dictionary_info' ); use Data::Dumper; print Dumper \@dicts; my @list = $speller->get_option_as_list('sug-split-char'); SKIP: { skip "option 'sug-split-char' not in your version of Aspell", 1 if $speller->errstr =~ m/is unknown/; cmp_ok( scalar @list, '>', 1, 'Found more than one list item for "sug-split-char"') or diag('Maybe option "sug-split-char" not in your version of Aspell or modified by config. ' . $speller->errstr); } # Display option keys my $options = $speller->fetch_option_keys; my $keys_count = ref $options eq 'HASH' ? keys %$options : 0; if ( $keys_count ) { for my $option ( sort keys %$options ) { my $detail = $options->{$option}; for ( qw/ desc default type / ) { $detail->{$_} = '(*not defined*)' unless defined $detail->{$_}; } my $current; if ( $detail->{type} == 3 ) { $current = join ', ', map { "'$_'" } $speller->get_option_as_list( $option ); $current = "($current)" if defined $current; } else { $current = $speller->get_option( $option ); } $current = '(* not defined *)' unless defined $current; print <<""; $option: Description: $detail->{desc} Default: $detail->{default} Option type: $detail->{type} Current Val: $current } } ok( $keys_count, "Found $keys_count option keys from fetch_option_keys()" ); Text-Aspell-0.09/t/01-use.t0000644000175000017500000000006410616265424015170 0ustar moseleymoseleyuse Test::More tests => 1; use_ok('Text::Aspell'); Text-Aspell-0.09/META.yml0000644000175000017500000000052110674607332014777 0ustar moseleymoseley# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Text-Aspell version: 0.09 version_from: Aspell.pm installdirs: site requires: Test::More: 0 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.30_01 Text-Aspell-0.09/Aspell.pm0000644000175000017500000002560310674606173015316 0ustar moseleymoseleypackage Text::Aspell; require DynaLoader; use vars qw/ @ISA $VERSION /; @ISA = 'DynaLoader'; $VERSION = '0.09'; bootstrap Text::Aspell $VERSION; # Preloaded methods go here. 1; __END__ =head1 NAME Text::Aspell - Perl interface to the GNU Aspell library =head1 SYNOPSIS use Text::Aspell; my $speller = Text::Aspell->new; die unless $speller; # Set some options $speller->set_option('lang','en_US'); $speller->set_option('sug-mode','fast'); # check a word print $speller->check( $word ) ? "$word found\n" : "$word not found!\n"; # lookup up words my @suggestions = $speller->suggest( $misspelled ); # lookup config options my $language = $speller->get_option('lang'); print $speller->errstr unless defined $language; # fetch a config item that is a list my @sgml_extensions = $speller->get_option_as_list('sgml-extension'); # fetch the configuration keys and their default settings my $options = $speller->fetch_option_keys; # or dump config settings to STDOUT $speller->print_config || $speller->errstr; # What dictionaries are installed as simple strings my @dicts = $speller->list_dictionaries; # or as an array of hashes @dicts = $speller->dictionary_info; print Data::Dumper::Dumper( \@dicts ); Here's an example how to create and use your own word list Create a dictionary: $ aspell --lang=en create master ./dictionary.local < space_separated_word_list Then in your code: use Text::Aspell; my $speller = Text::Aspell->new; die unless $speller; $speller->set_option('master','./dictionary.local'); # check a word print $speller->check( $word ) ? "$word found\n" : "$word not found!\n"; =head1 DESCRIPTION This module provides a Perl interface to the GNU Aspell library. This module is to meet the need of looking up many words, one at a time, in a single session, such as spell-checking a document in memory. The GNU C interface is described at: http://aspell.net/man-html/Through-the-C-API.html#Through-the-C-API It's worth looking over the way config and speller (manager) objects are created when using the Aspell C API as some of that is hidden in the Text::Aspell module. For example, with Text::Aspell you do not have to explicitly create a speller object. The speller (manager) object is created automatically the first time you call suggest() or check(). Note also that once the speller object is created some (all?) config options cannot be changed. For example, setting configuration options such as "lang" are what determine what dictionary Aspell will use. Once the speller object is created that dictionary will be used. I.e. setting "lang" after the speller object is created will have no effect. =head1 DEPENDENCIES You MUST have installed GNU Aspell library version 0.50.1 or higher on your system before installing this Text::Aspell Perl module. If installing Aspell using your operating system's package management system, you may need to install the Aspell development package (for example, on Debian libaspell-dev). Aspell can source can be downloaded from: http://aspell.net There have been a number of bug reports because people failed to install aspell before installing this module. This is an interface to the aspell library installed on your system, not a replacement for aspell. You must also have the English dictionary installed when running the module's test suite. Also, please see the README and Changes files. README may have specific information about your platform. =head1 METHODS The following methods are available: =over 4 =item $speller = Text::Aspell->new; Creates a new speller object. New does not take any parameters (future version may allow options set by passing in a hash reference of options and value pairs). Returns C if the object could not be created, which is unlikely. Internally, new() creates an object to store Aspell structures (AspellConfig, AspellSpeller, and a space for an error string and then calls new_aspell_config(); =item $speller->set_option($option_name, $value); Sets the configuration option C<$option_name> to the value of C<$value>. Returns C on error, and the error message can be printed with $speller->errstr. You should set configuration options before calling the $speller->create_speller method. See the GNU Aspell documentation for the available configuration settings and how (and when) they may be used. =item $speller->remove_option($option_name); Removes (sets to the default value) the configuration option specified by C<$option_name>. Returns C on error, and the error message can be printed with $speller->errstr. You may only set configuration options before calling the $speller->create_speller method. =item $string = $speller->get_option($option_name); Returns the current setting for the given configuration option. The values are strings. For configuration options that are lists used the C method. Returns C on error, and the error message can be printed with $speller->errstr. Note that this may return different results depending on if it's called before or after $speller->create_speller is called. =item @list = $speller->get_option_as_list($option_name); Returns an array of list items for the given option. Use this method to fetch configuration values that are of type I. Returns C on error, and the error message can be printed with $speller->errstr. Note that this may return different results depending on if it's called before or after $speller->create_speller is called. =item $options = $speller->fetch_option_keys; Returns a hash of hashes. The keys are the possible configuration options and the values is a hash with keys of: desc : A short description of the option default : The default value for this option type : The data type of option (see aspell.h) =item $speller->print_config; Prints the current configuration to STDOUT. Useful for debugging. Note that this will return different results depending on if it's called before or after $speller->create_speller is called. =item $speller->errstr; Returns the error string from the last error. Check the previous call for an C return value before calling this method =item $errnum = $speller->errnum; Returns the error number from the last error. Some errors may only set the error string ($speller->errstr) on errors, so it's best to check use the errstr method over this method. This method is deprecated. =item $found = $speller->check($word); Checks if a word is found in the dictionary. Returns true if the word is found in the dictionary, false but defined if the word is not in the dictionary. Returns C on error, and the error message can be printed with $speller->errstr. This calls $speller->create_speller if the speller has not been created by an explicit call to $speller->create_speller. =item @suggestions = $speller->suggest($word) Returns an array of word suggestions for the specified word. The words are returned with the best guesses at the start of the list. =item $speller->create_speller; This method is normally not called by your program. It is called automatically the first time $speller->check() or $speller->suggest() is called to create a spelling "speller". You might want to call this when your program first starts up to make the first access a bit faster, or if you need to read back configuration settings before looking up words. The creation of the speller builds a configuration profile in the speller structure. Results from calling print_config() and get_option() will change after calling create_speller(). In general, it's best to read config settings back after calling create_speller() or after calling spell() or suggest(). Returns C on error, and the error message can be printed with $speller->errstr. =item $speller->add_to_session($word) =item $speller->add_to_personal($word) Adds a word to the session or personal word lists. Words added will be offered as suggestions. =item $speller->store_replacement($word, $replacement); This method can be used to instruct the speller which word you used as a replacement for a misspelled word. This allows the speller to offer up the replacement next time the word is misspelled. See section 6.3 of the GNU Aspell documentation for a better description. (July 2005 note: best to ignore any return value for now) =item $speller->save_all_word_lists; Writes any pending word lists to disk. =item $speller->clear_session; Clears the current session word list. =item @dicts = $speller->list_dictionaries; This returns an array of installed dictionary files. Each is a single string formatted as: [name]:[code]:[jargon]:[size]:[module] Name and code will often be the same, but name is the complete name of the dictionary which can be used to directly select a dictionary, and code is the language/region code only. =item $array_ref = $speller->$speller->dictionary_info; Like the C method, this method returns an array of hash references. For example, an entry for a dictionary might have the following hash reference: { 'module' => 'default', 'code' => 'en_US', 'size' => 60, 'jargon' => 'w-accents', 'name' => 'en_US-w-accents' }, Not all hash keys will be available for every dictionary (e.g. the dictionary may not have a "jargon" key). =back =head1 Upgrading from Text::Pspell Text::Aspell works with GNU Aspell and is a replacement for the module Text::Pspell. Text::Pspell is no longer supported. Upgrading should be a simple process. Only one method name has changed: C is now called C. Code designed to use the old Text::Pspell module may not even call the C method so this may not be an issue. The C configuration setting is now called C. Diffs for code that uses Text::Pspell might look like: - use Text::Pspell; + use Text::Aspell; - $speller = Text::Pspell->new; + $speller = Text::Aspell->new; - $speller->create_manager || die "Failed to create speller: " . $speller->errstr; + $speller->create_speller || die "Failed to create speller: " . $speller->errstr; If you used a custom dictionary installed in non-standard location and indexed the dictionary with Aspell/Pspell .pwli files you will need to change how you access your dictionary (e.g. by setting the "master" configuration setting with the path to the dictionary). See the GNU Aspell documentation for details. =head1 BUGS Probably. =head1 COPYRIGHT This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Bill Moseley moseley@hank.org. This module is based on a perl module written by Doru Theodor Petrescu . Aspell is written and maintained by Kevin Atkinson. Please see: http://aspell.net =cut Text-Aspell-0.09/Changes0000644000175000017500000000771410674606150015031 0ustar moseleymoseleyRevision history for Perl extension Text::Aspell. 0.09 Fri Sep 21 00:02:55 UTC 2007 - Updated test due to changes in Test::More v0.71 0.08 Thu May 3 04:59:31 UTC 2007 - Added explicit set_lang for en_US - TODO fix Makefile.PL to make sure aspell installed and en_US installed. 0.07 Tue Apr 3 20:18:11 UTC 2007 - Added patch provided by Peter Karman: "Here's a patch to skip that funny test in 05-core.t if the sug-split-char feature is not present." 0.06 Wed May 31 13:51:58 UTC 2006 - Replaced the PUSHs with XPUSHs as suggested by AWKAY in bug #15060 - Removed a comment that was left in the O_OBJECT typemap. Alex Kapranoff reported that it was confusing xsubpp on some versions of perl. - Changed from testing return values to calling aspell_*_error. In some cases the Aspell API was inconsistent with the code. http://lists.gnu.org/archive/html/aspell-devel/2005-07/msg00028.html 0.05 Wed Jul 27 10:34:55 PDT 2005 - Removed a number of const * casts. Also changed a few int returns to void to prevent XS creating RETVAL when not needed -- clears up all warnings when compiling the module with -Wall (on gcc 3.3.6). - Fixed get_option_as_list() to fetch the error message from the config object instead of the speller object. Reported by Gary Setter. - Made _create_speller() static - closes 8635 Thanks to Alexey Tourbin - gt_option_as_list now checks for valid speller object and generates internal message if not valid - closes 8633 Thanks to Alexey Tourbin - replaced the config list test from 'sgml-extension' to 'sug-split-char'. smgl-extension seems to not be available anymore as a number of people reported this test failing. - Ignore the return value in store_replacement() -- seems the return value cannot be trusted from aspell. - Updated typemap to use INT2PTR to quiet the following: cast to pointer from integer of different size - Updated the README file to included suggestions for building on various platforms. - Moved to using Test::More. Sorry if that causes you pain. Just trying to keep up with the times. 0.04 Sat Nov 1 22:10:03 UTC 2003 - Updated README for Windows instructions 0.03 Sun Aug 3 00:45:32 UTC 2003 - Fixed a bug reported in Debian bug 203467 An invalid config setting (such as Lang = "xx") was causing a segfault. Was freeing the config option between creating the speller and checking for errors. The free was clearing the error status. - Fixed Debian bug 203516 Was not correctly extending arg stack when pusing suggesions onto an array. - Closed Debian bug 203517 User was trying to modify the config settings (specifically the "lang" setting) after creating a speller object. That doesn't work because creating a speller object is what maps the config options to a given dictionary file. Documentation updated to clear up this point. 0.02 Sat Aug 31 14:58:31 UTC 2002 - Added new method: @dicts = $speller->dictionary_info; returns hash ref instead of a : joined string - Added new method: @option_list = $speller->get_option_as_list( $option_name ); returns the option setting as a list (since some options are lists) - Added new method: $options = $speller->fetch_option_keys; returns the available config options and their defaults - Removed option_list array. 0.01 Thu Aug 29 19:49:51 UTC 2002 - Updated and renamed from Text::Pspell to use GNU Aspell 0.50. Update to GNU Aspell provided by T.J. Mather, Aug 24, 2002. - Updated config options displayed in print_config() method. - Added list_dictionaries() method to list available dictionaries and added test. Text-Aspell-0.09/MANIFEST0000644000175000017500000000026110616265424014656 0ustar moseleymoseleyChanges MANIFEST README Makefile.PL Aspell.pm Aspell.xs typemap t/01-use.t t/02-pod.t t/05-core.t META.yml Module meta-data (added by MakeMaker) Text-Aspell-0.09/Aspell.xs0000644000175000017500000003070610616265424015330 0ustar moseleymoseley#include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include #define MAX_ERRSTR_LEN 1000 typedef struct { AspellCanHaveError *ret; AspellSpeller *speller; AspellConfig *config; char lastError[MAX_ERRSTR_LEN+1]; int errnum; /* Deprecated - only returns 0/1 */ } Aspell_object; static int _create_speller(Aspell_object *self) { AspellCanHaveError *ret; ret = new_aspell_speller(self->config); if ( (self->errnum = aspell_error_number(ret) ) ) { strncpy(self->lastError, aspell_error_message(ret), MAX_ERRSTR_LEN); return 0; } /* The config is no longer needed (check for errors here?) */ delete_aspell_config(self->config); self->config = NULL; self->speller = to_aspell_speller(ret); self->config = aspell_speller_config(self->speller); return 1; } MODULE = Text::Aspell PACKAGE = Text::Aspell # Make sure that we have at least xsubpp version 1.922. REQUIRE: 1.922 Aspell_object * new(CLASS) char *CLASS CODE: RETVAL = (Aspell_object*)safemalloc( sizeof( Aspell_object ) ); if( RETVAL == NULL ){ warn("unable to malloc Aspell_object"); XSRETURN_UNDEF; } memset( RETVAL, 0, sizeof( Aspell_object ) ); /* create the configuration */ RETVAL->config = new_aspell_config(); /* Set initial default */ /* * aspell_config_replace(RETVAL->config, "language-tag", "en"); * default language is 'EN' */ OUTPUT: RETVAL void DESTROY(self) Aspell_object *self CODE: if ( self->speller ) delete_aspell_speller(self->speller); safefree( (char*)self ); int create_speller(self) Aspell_object *self CODE: if ( !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = 1; OUTPUT: RETVAL int print_config(self) Aspell_object *self PREINIT: AspellKeyInfoEnumeration * key_list; const AspellKeyInfo * entry; CODE: key_list = aspell_config_possible_elements( self->config, 0 ); while ( (entry = aspell_key_info_enumeration_next(key_list) ) ) PerlIO_printf(PerlIO_stdout(),"%20s: %s\n", entry->name, aspell_config_retrieve(self->config, entry->name) ); delete_aspell_key_info_enumeration(key_list); RETVAL = 1; OUTPUT: RETVAL int set_option(self, tag, val ) Aspell_object *self char *tag char *val CODE: self->lastError[0] = '\0'; aspell_config_replace(self->config, tag, val ); if ( (self->errnum = aspell_config_error_number( self->config) ) ) { strcpy(self->lastError, aspell_config_error_message( self->config ) ); XSRETURN_UNDEF; } RETVAL = 1; OUTPUT: RETVAL int remove_option(self, tag ) Aspell_object *self char *tag CODE: self->lastError[0] = '\0'; aspell_config_remove(self->config, tag ); if ( (self->errnum = aspell_config_error_number( self->config) ) ) { strcpy(self->lastError, aspell_config_error_message( self->config ) ); XSRETURN_UNDEF; } RETVAL = 1; OUTPUT: RETVAL char * get_option(self, val) Aspell_object *self char *val CODE: self->lastError[0] = '\0'; RETVAL = (char *)aspell_config_retrieve(self->config, val); if ( (self->errnum = aspell_config_error_number( self->config) ) ) { strcpy(self->lastError, aspell_config_error_message( self->config ) ); XSRETURN_UNDEF; } OUTPUT: RETVAL void get_option_as_list(self, val) Aspell_object *self char * val PREINIT: AspellStringList * lst = new_aspell_string_list(); AspellMutableContainer * lst0 = aspell_string_list_to_mutable_container(lst); AspellStringEnumeration * els; const char *option_value; PPCODE: if (!self->config ) XSRETURN_UNDEF; aspell_config_retrieve_list(self->config, val, lst0); if ( (self->errnum = aspell_config_error_number( self->config) ) ) { strncpy(self->lastError, aspell_config_error_message( self->config ), MAX_ERRSTR_LEN); delete_aspell_string_list(lst); XSRETURN_UNDEF; } els = aspell_string_list_elements(lst); while ( (option_value = aspell_string_enumeration_next(els)) != 0) XPUSHs(sv_2mortal(newSVpv( option_value ,0 ))); delete_aspell_string_enumeration(els); delete_aspell_string_list(lst); char * errstr(self) Aspell_object *self CODE: RETVAL = (char*) self->lastError; OUTPUT: RETVAL int errnum(self) Aspell_object *self CODE: RETVAL = self->errnum; OUTPUT: RETVAL int check(self,word) Aspell_object *self char * word CODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = aspell_speller_check(self->speller, word, -1); if ( aspell_speller_error( self->speller ) ) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message( self->speller ), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } OUTPUT: RETVAL void suggest(self, word) Aspell_object *self char * word PREINIT: const AspellWordList *wl; AspellStringEnumeration *els; const char *suggestion; PPCODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; wl = aspell_speller_suggest(self->speller, word, -1); if (!wl) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } els = aspell_word_list_elements(wl); while ( (suggestion = aspell_string_enumeration_next(els)) ) XPUSHs(sv_2mortal(newSVpv( suggestion ,0 ))); delete_aspell_string_enumeration(els); int add_to_personal(self,word) Aspell_object *self char * word CODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = aspell_speller_add_to_personal(self->speller, word, -1); if ( aspell_speller_error( self->speller ) ) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } OUTPUT: RETVAL int add_to_session(self,word) Aspell_object *self char * word CODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = aspell_speller_add_to_session(self->speller, word, -1); if ( aspell_speller_error( self->speller ) ) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } OUTPUT: RETVAL int store_replacement(self,word,replacement) Aspell_object *self char * word char * replacement CODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = aspell_speller_store_replacement(self->speller, word, -1, replacement, -1); if ( aspell_speller_error( self->speller ) ) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } OUTPUT: RETVAL int save_all_word_lists(self) Aspell_object *self CODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = aspell_speller_save_all_word_lists(self->speller); if ( aspell_speller_error( self->speller ) ) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } OUTPUT: RETVAL int clear_session(self) Aspell_object *self CODE: self->lastError[0] = '\0'; self->errnum = 0; if (!self->speller && !_create_speller(self) ) XSRETURN_UNDEF; RETVAL = aspell_speller_clear_session(self->speller); if ( aspell_speller_error( self->speller ) ) { self->errnum = aspell_speller_error_number( self->speller ); strncpy(self->lastError, aspell_speller_error_message(self->speller), MAX_ERRSTR_LEN); XSRETURN_UNDEF; } OUTPUT: RETVAL void list_dictionaries(self) Aspell_object *self PREINIT: AspellDictInfoList * dlist; AspellDictInfoEnumeration * dels; const AspellDictInfo * entry; PPCODE: if (!self->config ) XSRETURN_UNDEF; dlist = get_aspell_dict_info_list(self->config); dels = aspell_dict_info_list_elements(dlist); while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0) { int len; char *dictname; len = strlen( entry->name ) + strlen( entry->jargon ) + strlen( entry->code ) + strlen( entry->size_str ) + strlen( entry->module->name ) + 4; dictname = (char *)safemalloc( len + 1 ); sprintf( dictname, "%s:%s:%s:%s:%s", entry->name, entry->code, entry->jargon, entry->size_str, entry->module->name ); PUSHs(sv_2mortal(newSVpv( dictname ,0 ))); safefree( dictname ); } delete_aspell_dict_info_enumeration(dels); void dictionary_info(self) Aspell_object *self; PREINIT: AspellDictInfoList *dlist; AspellDictInfoEnumeration *dels; const AspellDictInfo *entry; PPCODE: if (!self->config ) /* type map should catch this error, I'd think */ XSRETURN_UNDEF; dlist = get_aspell_dict_info_list(self->config); dels = aspell_dict_info_list_elements(dlist); while ( (entry = aspell_dict_info_enumeration_next(dels)) != 0) { HV * dict_entry = newHV(); if ( entry->name[0] ) hv_store(dict_entry, "name", 4, newSVpv(entry->name,0),0); if ( entry->jargon[0] ) hv_store(dict_entry, "jargon",6, newSVpv(entry->jargon,0),0); if ( entry->code[0] ) hv_store(dict_entry, "code", 4, newSVpv(entry->code,0),0); if ( entry->code ) hv_store(dict_entry, "size", 4, newSViv(entry->size),0); if ( entry->module->name[0] ) hv_store(dict_entry, "module",6, newSVpv(entry->module->name,0),0); XPUSHs(sv_2mortal(newRV_noinc((SV*)dict_entry))); } delete_aspell_dict_info_enumeration(dels); SV * fetch_option_keys(self) Aspell_object *self; PREINIT: AspellKeyInfoEnumeration * key_list; const AspellKeyInfo * entry; HV * option_hash; CODE: key_list = aspell_config_possible_elements( self->config, 0 ); option_hash = newHV(); while ( (entry = aspell_key_info_enumeration_next(key_list) ) ) { HV * KeyInfo = newHV(); hv_store(KeyInfo, "type", 4, newSViv((int)entry->type),0); if ( entry->def && entry->def[0] ) hv_store(KeyInfo, "default", 7, newSVpv(entry->def,0),0); if ( entry->desc && entry->desc[0] ) hv_store(KeyInfo, "desc",4, newSVpv(entry->desc,0),0); hv_store(option_hash, entry->name, strlen(entry->name), newRV_noinc((SV *)KeyInfo),0); } delete_aspell_key_info_enumeration(key_list); RETVAL = newRV_noinc((SV *)option_hash); OUTPUT: RETVAL Text-Aspell-0.09/typemap0000644000175000017500000000130010616265424015122 0ustar moseleymoseley# $Id: typemap,v 1.3 2002/08/26 02:40:25 moseley Exp $ TYPEMAP Aspell_object * O_OBJECT # From: "perlobject.map" Dean Roehrich, version 19960302 # O_OBJECT -> link an opaque C or C++ object to a blessed Perl object. OUTPUT # The Perl object is blessed into 'CLASS', which should be a # char* having the name of the package for the blessing. O_OBJECT sv_setref_pv( $arg, CLASS, (void*)$var ); INPUT O_OBJECT if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) $var = INT2PTR ($type, SvIV (SvRV ($arg))); else{ warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" ); XSRETURN_UNDEF; } Text-Aspell-0.09/README0000644000175000017500000002372410616265424014416 0ustar moseleymoseleyText::Aspell - Perl interface to the Aspell library DESCRIPTION Text::Aspell is an interface to the GNU Aspell library. GNU Aspell is a Free and Open Source spell checker. The Text::Aspell module is a thin XS wrapper around the Aspell C Library. REQUIREMENTS Hopefully this is obvious, but you MUST have the Aspell library installed on your system before installing this module. You also MUST have the en_US dictionary installed for "make test" to pass. For example, if you are running Debian you would have done this first: # apt-get install aspell-en libaspell-dev which would install the aspell binary and dictionary, plus also the aspell library and header file which are needed to link this module against. If you installed GNU Aspell from source then you should have the the aspell.h and aspell library on your system. Take a look at the bug reports for Aspell: http://cpantesters.perl.org/show/Text-Aspell.html#Text-Aspell-0.05 Note how many either say: Aspell.xs:7: aspell.h: No such file or directory or: # Failed test (t/05-core.t at line 33) # got: 'en_GB' # expected: 'en_US' # Really need the en_US dictionary installed! Makefile.PL does not do any checking of of Aspell before building. I would welcome any help updating the build process to do more checking up front. See BUILD NOTES and CURRENT ISSUES below before reporting any bugs. This module has been built and passed all tests on the following platforms: perl 5.6.1 on Linux, gcc version 2.95.3 20010315 (release) perl 5.8.0 on Linux gcc version 2.95.4 20011002 (Debian prerelease) perl 5.00503 on FreeBSD 4.6-STABLE gcc version 2.95.4 20020320 [FreeBSD] (these require at least aspell-0.50.1) perl 5.00503 on Solaris 5.8 sparc SUNW,Ultra-60 gcc version 2.95.2 19991024 (release) perl 5.00503 on Solaris 2.6, gcc version 2.95.1 19990816 (release) And on Wed Jul 27 10:36:12 PDT 2005: perl 5.8.7, Aspell 0.60.3, gcc 3.3.6 Debian Sid perl 5.8.7 Aspell 0.60.3, gcc 3.4.2 FreeBSD 5.4-STABLE i386 And on Fri May 26 18:59:51 UTC 2006 with Text-Aspell-0.06 perl 5.8.8, Aspell 0.60.4, aspell6-en-6.0.0 Debian Sid gcc 4.0.3 (all from source) perl 5.8.4, Aspell 0.60.4, aspell6-en-6.0-0, Debian GNU/Linux 3.1 gcc 3.3.5 (all from source) perl 5.8.8, Aspell 0.60.4, FreeBSD 6.1-RELEASE #0, gcc 3.4.4 (Aspell from ports) Please read SUPPORT below if you have trouble building Text::Aspell. INSTALLATION Windows users see below. 1) Install Aspell and a Dictionary Make sure you have a current version of GNU Aspell installed. You must install both the Aspell program and a dictionary. They are distributed as separate packages. (Look at all the FAILED reports on CPAN from people that don't have Aspell installed!) Aspell and the dictionary files can be downloaded from: http://aspell.net/ Note: The Text::Aspell module's test suite ("make test") requires that the English dictionary is installed. This module has been tested with the following version of Aspell and dictionary: aspell-0.50 Aspell program (ftp://ftp.gnu.org/gnu/aspell/aspell-0.50.tar.gz) aspell-en-0.50-1 English Dictionary (ftp://ftp.gnu.org/gnu/aspell/aspell-en-0.50-1.tar.bz2) NOTE: URLs for reference only -- use the most current version of each available. Aspell and the dictionary packages contain README files that include installation instructions. Here's a basic overview: Aspell must be installed first, then install the dictionary file and finally install the Text::Aspell module. Aspell installation example: $ wget ftp://ftp.gnu.org/gnu/aspell/aspell-0.50.tar.gz $ tar zxof aspell-0.50.tar.gz # or gzip -dc aspell-0.50.tar.gz | tar xof - $ cd aspell-0.50 $ ./configure ( ./configure --help for options ) $ make # make install If you used a --prefix option to install Aspell in a non-standard location you will need to adjust your path to include $PREFIX/bin. The configure script for the dictionary needs to find programs installed in the previous step. Dictionary installation example: $ wget ftp://ftp.gnu.org/gnu/aspell/aspell-en-0.50-1.tar.bz2 $ tar jxof aspell-en-0.50-1.tar.bz2 # or bunzip2 < aspell-en-0.50-1.tar.bz2 | tar xof - $ cd aspell-en-0.50-1 $ ./configure $ make # make install At this point you should be able to run Aspell in interactive mode. For example: $ aspell -a @(#) International Ispell Version 3.1.20 (but really Aspell 0.50) speler & speler 30 0: speller, speer, spiller, spoiler, ... 2) Build and install this Text::Aspell module. $ perl Makefile.PL $ make $ make test # make install If you installed Apsell in a non-standard location (for example, if you don't have root access) then you will need to tell Makefile.PL where to find the library. For example, if Apsell was installed in $HOME/local (--prefix=$HOME/local) and the perl module should be installed in the perl library $HOME/perl_lib: $ perl Makefile.PL PREFIX=$HOME/perl_lib \ CCFLAGS=-I$HOME/local/include \ LIBS="-L$HOME/local/lib -laspell" $ LD_RUN_PATH=$HOME/local/lib make $ make test $ make install WINDOWS USERS Randy Kobes has provided a PPM and the following instructions for installing Text::Aspell on Windows. Thanks very much Randy. For installing on Win32, first get and install the "Full installer" executable at http://aspell.net/win32/ this will install Aspell into a location such as C:\Program Files\Aspell. You will also need to fetch and install at least one of the precompiled dictionaries found on the same page. Make sure that the path to the Aspell bin directory (e.g. C:\Program Files\Aspell\bin\) is in your PATH environment variable. For help with setting your path see "set environment variables" in the Windows Help Utility. You may need to reboot or open a new shell window after setting your path. The Aspell .dll file must be located in the PATH before using Text::Aspell. Then, to install Text::Aspell, type at a DOS prompt (all on one line) C:\> ppm install http://theoryx5.uwinnipeg.ca/ppms/Text-Aspell.ppd for an ActivePerl 8xx version, or C:\> ppm install http://theoryx5.uwinnipeg.ca/ppmpackages/Text-Aspell.ppd for an ActivePerl 6xx version. If you wish to build Text::Aspell from source: If you want to build Text::Aspell yourself, you'll need a C compiler, which must be the same one that your Perl is built with (for ActivePerl, this means VC++ 6). Assuming you have that, in addition to the "Full installer" binary package at http://aspell.net/win32/, you'll also need to get and install the aspell-dev package (also located at http://aspell.net/win32/), which contains the necessary .lib and .h files needed to compile the Perl module. Like above, make sure the PATH environment variable points to the location of the installed Aspell .dll file before building Text::Aspell. Installation then proceeds as described for the Unix version: perl Makefile.PL nmake nmake test nmake install with the additional requirement of passing to 'perl Makefile.PL' the necessary arguments (e.g. INC and LIBS) to specify the locations of the lib and header files, if these were installed in a non-standard location. Make sure that if a non-standard location was used that this is added to your PATH environment variable before running the tests. SUPPORT Before contacting me with problems building Text::Aspell please try and debug as much as possible. For example, if "make test" fails, then run in verbose mode: make test TEST_VERBOSE=1 That may show at what test is failing. It's easy to run the test script manually -- and you can even edit and add a few print statements to aid in debugging. For example: perl -Iblib/lib -Iblib/arch t/test.t | less Use of LD_RUN_PATH, CCFLAGS and LIBS as above may also help if the build process fails. Remember that you *must* have the English dictionary installed for tests to pass (sorry, have to check against some dictionary). Also, you may need to set your LANG variable to "en_US" so that the English dictionary is selected. If all else fails, use the request tracker at: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Text-Aspell BUILD NOTES / CURRENT ISSUES A number of people have reported the $speller->store_replacement() test failing on some platforms. I don't know why. Search google to find out why I don't know why. The code (from what I can tell) looks like it should be returning an error value, but fails on some platforms. Until I can get a better answer I'm going to assume Aspell is broken and ignore the return value in t/test.t. So don't test the return value in your code, either. Update May 2006: Changed from checking return values to calling aspell_*_error method to test for errors. Some users of OS X have reported the test failing after calling clear_session(). The test is suppose to see if a word added to the session is removed after calling clear_session(). It's another error I have not been able to reproduce on the machines I tested on. "Pax" provided these notes: I just got Text::Aspell to build and work under OpenBSD 3.7 and thought you might like a tiny suggestion: in the README, you might note that under this operating system you need to add -lstdc++ to the list of libraries you link against, e.g.: $ perl Makefile.PL \ PREFIX=/usr/local INSTALLDIRS=site \ CCFLAGS=-I/usr/local/include \ LIBS="-L/usr/local/lib -laspell -lstdc++" If you don't do this, then any attempt to use Text::Aspell will throw thousands of unresolved symbol errors trying to load your shared object. This is against libaspell in /usr/local/lib installed from the aspell port in the OpenBSD 3.7 ports tree, FWIW. A number of Solaris uses have reported the need to set: LDFLAGS='-L/usr/local/lib -R/usr/local/lib' and also having to copy libstdc++* to /usr/lib. YMMV. Text-Aspell-0.09/Makefile.PL0000644000175000017500000000037110616265424015501 0ustar moseleymoseleyuse ExtUtils::MakeMaker; WriteMakefile( NAME => 'Text::Aspell', VERSION_FROM => 'Aspell.pm', LIBS => ['-laspell'], XSPROTOARG => '-noprototypes', PREREQ_PM => { 'Test::More' => 0, }, );