Unify chise_tools.i into chise.i
authorKoichi KAMICHI <kamichi@fonts.jp>
Wed, 5 Apr 2006 13:41:14 +0000 (13:41 +0000)
committerKoichi KAMICHI <kamichi@fonts.jp>
Wed, 5 Apr 2006 13:41:14 +0000 (13:41 +0000)
tools/chise.i [new file with mode: 0644]
tools/chise_wrap.cxx.diff [deleted file]

diff --git a/tools/chise.i b/tools/chise.i
new file mode 100644 (file)
index 0000000..ff6facc
--- /dev/null
@@ -0,0 +1,105 @@
+// chise.i\r
+//\r
+// Copyright (C) 2005,2006 KAMICHI Koichi.\r
+//\r
+// reference : http://www.swig.org/Doc1.3/Perl5.html\r
+//             sample.c included to libchise\r
+\r
+%module chise\r
+\r
+%{\r
+#include <concord.h>\r
+#include <chise.h>\r
+%}\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
+%include concord.h\r
+%include chise.h\r
+\r
+%inline %{\r
+\r
+#include <concord.h>\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[102400];\r
+int feature_size = 102400;\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
diff --git a/tools/chise_wrap.cxx.diff b/tools/chise_wrap.cxx.diff
deleted file mode 100644 (file)
index 3f4897f..0000000
+++ /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 <chise.h>
-+ 
-  /* ----------------------------------------------------------------------------
-   * 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) {