+++ /dev/null
-// chise_tools.i\r
-//\r
-// Copyright (C) 2005 Koichi Kamichi.\r
-//\r
-// reference : http://www.swig.org/Doc1.3/Perl5.html\r
-// sample.c included to libchise\r
-\r
-%module chise_tools\r
-\r
-// This tells SWIG to treat char ** as a special case\r
-%typemap(in) char ** {\r
- AV *tempav;\r
- I32 len;\r
- int i;\r
- SV **tv;\r
- if (!SvROK($input))\r
- croak("Argument $argnum is not a reference.");\r
- if (SvTYPE(SvRV($input)) != SVt_PVAV)\r
- croak("Argument $argnum is not an array.");\r
- tempav = (AV*)SvRV($input);\r
- len = av_len(tempav);\r
- $1 = (char **) malloc((len+2)*sizeof(char *));\r
- for (i = 0; i <= len; i++) {\r
- tv = av_fetch(tempav, i, 0); \r
- $1[i] = (char *) SvPV(*tv,PL_na);\r
- }\r
- $1[i] = NULL;\r
-};\r
-\r
-// This cleans up the char ** array after the function call\r
-%typemap(freearg) char ** {\r
- free($1);\r
-}\r
-\r
-// Creates a new Perl array and places a NULL-terminated char ** into it\r
-%typemap(out) char ** {\r
- AV *myav;\r
- SV **svs;\r
- int i = 0,len = 0;\r
- /* Figure out how many elements we have */\r
- while ($1[len])\r
- len++;\r
- svs = (SV **) malloc(len*sizeof(SV *));\r
- for (i = 0; i < len ; i++) {\r
- svs[i] = sv_newmortal();\r
- sv_setpv((SV*)svs[i],$1[i]);\r
- };\r
- myav = av_make(len,svs);\r
- free(svs);\r
- $result = newRV((SV*)myav);\r
- sv_2mortal($result);\r
- argvi++;\r
-}\r
-\r
-%inline %{\r
-\r
-#include <chise.h>\r
-\r
-unsigned char *get_uchar(char *argv){\r
- return (unsigned char *)argv;\r
-}\r
-\r
-char *get_char(unsigned char *argv){\r
- return (char *)argv;\r
-}\r
-\r
-unsigned char buffer[1024];\r
-int buffer_size = 1024;\r
-\r
-void clear_buffer(){\r
- int i;\r
- for(i = 0; i < buffer_size; i++){\r
- buffer[i] = 0;\r
- }\r
-}\r
-\r
-unsigned char feature[10240];\r
-int feature_size = 10240;\r
-\r
-static int\r
-name_map_func (CHISE_DS *ds, unsigned char *name)\r
-{\r
- strcat((char *)feature, (char *)name);\r
- strcat((char *)feature, (char *)"\n");\r
- return 0;\r
-}\r
-\r
-void listup_feature(CHISE_DS *ds){\r
- int i;\r
- for(i = 0; i < feature_size; i++){\r
- feature[i] = 0;\r
- }\r
- chise_ds_foreach_char_feature_name (ds, &name_map_func);\r
-}\r
-\r
-%}\r
-# chiseperl.pl --- some useful funcions for using libchise with SWIG\r
-#\r
-# Copyright (C) 2005 Koichi Kamichi.\r
-#\r
-# global : $chise_ds, @chise_feature, @chise_ft, $chise_newid\r
-# function : void init_chise();\r
-# void close_chise();\r
-# void update_chise();\r
-# void search_newid();\r
-# $var get_feature_value($feature, $char_id);\r
-# $var set_feature_value($feature, $char_id, $value);\r
-# $var create_new_char($feature, $value);\r
-# $char_id decode_char($feature_char, $int);\r
-\r
-use chise_tools;\r
-use chise;\r
-\r
-sub init_chise{\r
- $chise_ds = chise::CHISE_DS_open(0, $chise::chise_system_db_dir, 0, 0755);\r
- chise_tools::listup_feature($chise_ds);\r
- @chise_feature = split(/\n/, chise_tools::get_char($chise_tools::feature));\r
- @chise_ft = ();\r
- foreach(@chise_feature){\r
- push(@chise_ft, chise::chise_ds_get_feature($chise_ds, chise_tools::get_uchar($_)));\r
- }\r
- $chise_newid = 0x0F0000;\r
-}\r
-\r
-sub get_feature_value{ # feature, char_id -> 0 or value\r
- if(scalar(@_) != 2){\r
- return 0;\r
- }\r
- my $ft = chise::chise_ds_get_feature($chise_ds, chise_tools::get_uchar($_[0]));\r
- chise_tools::clear_buffer;\r
- chise::chise_char_gets_feature_value($_[1], $ft,\r
- $chise_tools::buffer, $chise_tools::buffer_size);\r
- return chise_tools::get_char($chise_tools::buffer);\r
-}\r
-\r
-sub set_feature_value{ # feature, char_id, value -> result\r
- if(scalar(@_) != 3){\r
- return 0;\r
- }\r
- my $ft = chise::chise_ds_get_feature($chise_ds, chise_tools::get_uchar($_[0]));\r
- chise::chise_char_set_feature_value($_[1], $ft, chise_tools::get_uchar($_[2]));\r
- return 1;\r
-}\r
-\r
-sub close_chise{\r
- chise::CHISE_DS_close($chise_ds);\r
-}\r
-\r
-sub create_new_char{ # feature, value -> assinged char_id\r
- &search_newid;\r
- &set_feature_value($_[0], $chise_newid, $_[1]);\r
- $chise_newid++;\r
- return $chise_newid - 1;\r
-}\r
-\r
-sub search_newid{ # search new char_id and update $chise_newid\r
- while(1){\r
- my $found = 0;\r
- foreach(@chise_ft){\r
- chise_tools::clear_buffer;\r
- chise::chise_char_gets_feature_value($chise_newid, $_, $chise_tools::buffer, $chise_tools::buffer_size);\r
- if(length(chise_tools::get_char($chise_tools::buffer)) != 0){\r
- $found = 1;\r
- last;\r
- }\r
- }\r
- if($found == 0){\r
- last;\r
- }\r
- $chise_newid++;\r
- }\r
-}\r
-\r
-sub update_chise{ # save added data to database\r
- foreach(@chise_ft){\r
- chise::chise_feature_sync($_);\r
- }\r
-}\r
-\r
-sub decode_char{ # feature, int -> charID, 0\r
- if(scalar(@_) != 2){\r
- return 0;\r
- }\r
- return chise::chise_ds_decode_char($chise_ds, chise_tools::get_uchar($_[0]), $_[1]);\r
-}\r
-\r
-1;\r
+# chiseperl.pl --- some useful funcions for using libchise with SWIG
+#
+# Copyright (C) 2005,2006 KAMICHI Koichi.
+#
+# global : $chise_ds, @chise_feature, @chise_ft, $chise_newid
+# function : void init_chise();
+# void close_chise();
+# void update_chise();
+# void search_newid();
+# $var get_feature_value($feature, $char_id);
+# $var set_feature_value($feature, $char_id, $value);
+# $var create_new_char($feature, $value);
+# $char_id decode_char($feature_char, $int);
+
+use chise;
+
+sub init_chise{
+#$chise_ds = chise::CHISE_DS_open($chise::CHISE_DS_BERKELEY_DB, $chise::chise_system_db_dir, 0, 0755);
+ $chise_ds = chise::CHISE_DS_open(0, $chise::chise_system_db_dir, 0, 0755);
+ chise::listup_feature($chise_ds);
+ @chise_feature = split(/\n/, chise::get_char($chise::feature));
+ @chise_ft = ();
+ foreach(@chise_feature){
+ push(@chise_ft, chise::chise_ds_get_feature($chise_ds, chise::get_uchar($_)));
+ }
+ $chise_newid = 0x0F0000;
+}
+
+sub get_feature_value{ # feature, char_id -> 0 or value
+ if(scalar(@_) != 2){
+ return 0;
+ }
+ my $ft = chise::chise_ds_get_feature($chise_ds, chise::get_uchar($_[0]));
+ chise::clear_buffer;
+ chise::chise_char_gets_feature_value($_[1], $ft,
+ $chise::buffer, $chise::buffer_size);
+ return chise::get_char($chise::buffer);
+}
+
+sub set_feature_value{ # feature, char_id, value -> result
+ if(scalar(@_) != 3){
+ return 0;
+ }
+ my $ft = chise::chise_ds_get_feature($chise_ds, chise::get_uchar($_[0]));
+ chise::chise_char_set_feature_value($_[1], $ft, chise::get_uchar($_[2]));
+ return 1;
+}
+
+sub close_chise{
+ chise::CHISE_DS_close($chise_ds);
+}
+
+sub create_new_char{ # feature, value -> assinged char_id
+ &search_newid;
+ &set_feature_value($_[0], $chise_newid, $_[1]);
+ $chise_newid++;
+ return $chise_newid - 1;
+}
+
+sub search_newid{ # search new char_id and update $chise_newid
+ while(1){
+ my $found = 0;
+ foreach(@chise_ft){
+ chise::clear_buffer;
+ chise::chise_char_gets_feature_value($chise_newid, $_, $chise::buffer, $chise::buffer_size);
+ if(length(chise::get_char($chise::buffer)) != 0){
+ $found = 1;
+ last;
+ }
+ }
+ if($found == 0){
+ last;
+ }
+ $chise_newid++;
+ }
+}
+
+sub update_chise{ # save added data to database
+ foreach(@chise_ft){
+ chise::chise_feature_sync($_);
+ }
+}
+
+sub decode_char{ # feature, int -> charID, 0
+ if(scalar(@_) != 2){
+ return 0;
+ }
+ return chise::chise_ds_decode_char($chise_ds, chise::get_uchar($_[0]), $_[1]);
+}
+
+1;