From: Koichi KAMICHI Date: Wed, 5 Apr 2006 13:41:14 +0000 (+0000) Subject: Unify chise_tools.i into chise.i X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=3c3f3dbcd19e5ef4078631ec79bc105d379293ad;p=chise%2Fkage.git Unify chise_tools.i into chise.i --- diff --git a/tools/chise.i b/tools/chise.i new file mode 100644 index 0000000..ff6facc --- /dev/null +++ b/tools/chise.i @@ -0,0 +1,105 @@ +// chise.i +// +// Copyright (C) 2005,2006 KAMICHI Koichi. +// +// reference : http://www.swig.org/Doc1.3/Perl5.html +// sample.c included to libchise + +%module chise + +%{ +#include +#include +%} + +// This tells SWIG to treat char ** as a special case +%typemap(in) char ** { + AV *tempav; + I32 len; + int i; + SV **tv; + if (!SvROK($input)) + croak("Argument $argnum is not a reference."); + if (SvTYPE(SvRV($input)) != SVt_PVAV) + croak("Argument $argnum is not an array."); + tempav = (AV*)SvRV($input); + len = av_len(tempav); + $1 = (char **) malloc((len+2)*sizeof(char *)); + for (i = 0; i <= len; i++) { + tv = av_fetch(tempav, i, 0); + $1[i] = (char *) SvPV(*tv,PL_na); + } + $1[i] = NULL; +}; + +// This cleans up the char ** array after the function call +%typemap(freearg) char ** { + free($1); +} + +// Creates a new Perl array and places a NULL-terminated char ** into it +%typemap(out) char ** { + AV *myav; + SV **svs; + int i = 0,len = 0; + /* Figure out how many elements we have */ + while ($1[len]) + len++; + svs = (SV **) malloc(len*sizeof(SV *)); + for (i = 0; i < len ; i++) { + svs[i] = sv_newmortal(); + sv_setpv((SV*)svs[i],$1[i]); + }; + myav = av_make(len,svs); + free(svs); + $result = newRV((SV*)myav); + sv_2mortal($result); + argvi++; +} + +%include concord.h +%include chise.h + +%inline %{ + +#include +#include + +unsigned char *get_uchar(char *argv){ + return (unsigned char *)argv; +} + +char *get_char(unsigned char *argv){ + return (char *)argv; +} + +unsigned char buffer[1024]; +int buffer_size = 1024; + +void clear_buffer(){ + int i; + for(i = 0; i < buffer_size; i++){ + buffer[i] = 0; + } +} + +unsigned char feature[102400]; +int feature_size = 102400; + +static int +name_map_func (CHISE_DS *ds, unsigned char *name) +{ + strcat((char *)feature, (char *)name); + strcat((char *)feature, (char *)"\n"); + return 0; +} + +void listup_feature(CHISE_DS *ds){ + int i; + for(i = 0; i < feature_size; i++){ + feature[i] = 0; + } + chise_ds_foreach_char_feature_name (ds, &name_map_func); +} + +%} diff --git a/tools/chise_wrap.cxx.diff b/tools/chise_wrap.cxx.diff deleted file mode 100644 index 3f4897f..0000000 --- a/tools/chise_wrap.cxx.diff +++ /dev/null @@ -1,36 +0,0 @@ -*** chise_wrap.cxx.old 2006-04-05 17:18:47.437069040 +0900 ---- chise_wrap.cxx 2006-04-05 17:12:10.969341296 +0900 -*************** -*** 1,3 **** ---- 1,5 ---- -+ #include -+ - /* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.24 -*************** -*** 1123,1133 **** - SWIG_croak("Usage: CHISE_DS_open(type,location,subtype,modemask);"); - } - { -! CHISE_DS_Type * argp; -! if (SWIG_ConvertPtr(ST(0),(void **) &argp, SWIGTYPE_p_CONCORD_Backend_Type,0) < 0) { -! SWIG_croak("Type error in argument 1 of CHISE_DS_open. Expected _p_CONCORD_Backend_Type"); -! } -! arg1 = *argp; - } - { - if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_unsigned_char,0) < 0) { ---- 1125,1136 ---- - SWIG_croak("Usage: CHISE_DS_open(type,location,subtype,modemask);"); - } - { -! //CHISE_DS_Type * argp; -! //if (SWIG_ConvertPtr(ST(0),(void **) &argp, SWIGTYPE_p_CONCORD_Backend_Type,0) < 0) { -! //SWIG_croak("Type error in argument 1 of CHISE_DS_open. Expected _p_CONCORD_Backend_Type"); -! //} -! //arg1 = *argp; -! arg1 = CHISE_DS_Berkeley_DB; - } - { - if (SWIG_ConvertPtr(ST(1), (void **) &arg2, SWIGTYPE_p_unsigned_char,0) < 0) {