#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"

#include "spell.h"

static int
not_here(char *s)
{
    croak("%s not implemented on this architecture", s);
    return -1;
}

static double
constant(char *name, int arg)
{
    errno = 0;
    switch (*name) {
    }
    errno = EINVAL;
    return 0;

not_there:
    errno = ENOENT;
    return 0;
}


MODULE = Search::OpenFTS::Morph::ISpell               PACKAGE = Search::OpenFTS::Morph::ISpell


double
constant(name,arg)
        char *          name
        int             arg

PROTOTYPES: DISABLE

IspellDict *
InitIspell ( aff_file, dict_file )
	char * aff_file
	char * dict_file
        CODE:
	do {
	IspellDict* obj;
	RETVAL = NULL;
	obj = (IspellDict*)malloc(sizeof(IspellDict));
	if ( obj ) {
		memset( (void*)obj,0,sizeof(IspellDict));
		if ( NIImportDictionary(obj,dict_file) || NIImportAffixes(obj,aff_file) ) {
			NIFree (obj);
		} else {
			NISortDictionary(obj);
			NISortAffixes(obj);
			RETVAL = obj;
		}
	}
	} while(0);
	OUTPUT:
	 RETVAL

void
DestroyIspell(obj)
	IspellDict * obj
	CODE:
	NIFree(obj);
	OUTPUT:

int
Normalize( obj, word, norms )
	IspellDict * obj
	char *	word
	SV *	norms
	CODE: 
	do {
	AV*	alids = (AV *) SvRV(norms);
	char **lemms, **ptr;

	ptr = lemms = NINormalizeWord(obj,word);

	RETVAL = 0;
	if ( lemms ) {
		while( *ptr ) {
			av_push( alids, newSVpv( *ptr, strlen(*ptr) ) );
			free( *ptr );
			ptr++; RETVAL++;
		}
		free(lemms);
	}
	} while(0);
	OUTPUT:
	 RETVAL 

