5 #include "include/anthy.h"
12 %define OUTPUT_TYPEMAP(type, klass)
13 %typemap(in,numinputs=0) type *OUTPUT(VALUE temp)
15 temp = rb_funcall(klass, rb_intern("new"), 0);
16 Data_Get_Struct(temp, $*ltype, $1);
19 %typemap(argout) type *OUTPUT
24 $result = temp$argnum;
28 OUTPUT_TYPEMAP(struct anthy_conv_stat, cConvStat.klass);
29 OUTPUT_TYPEMAP(struct anthy_segment_stat, cSegmentStat.klass);
30 OUTPUT_TYPEMAP(struct anthy_prediction_stat, cPredictionStat.klass);
34 %rename(ConvStat) anthy_conv_stat;
35 %rename(SegmentStat) anthy_segment_stat;
36 %rename(PredictionStat) anthy_prediction_stat;
38 %rename(COMPILED_ENCODING) ANTHY_COMPILED_ENCODING;
39 %rename(EUC_JP_ENCODING) ANTHY_EUC_JP_ENCODING;
40 %rename(UTF8_ENCODING) ANTHY_UTF8_ENCODING;
42 %rename(init) anthy_init;
43 %rename(quit) anthy_quit;
44 %rename(conf_override) anthy_conf_override;
45 %rename(set_personality) anthy_set_personality;
47 %ignore anthy_create_context;
48 %ignore anthy_reset_context;
49 %ignore anthy_release_context;
51 %ignore anthy_set_string;
52 %ignore anthy_resize_segment;
53 %ignore anthy_get_stat;
54 %ignore anthy_get_segment_stat;
55 %ignore anthy_get_segment;
56 %ignore anthy_commit_segment;
58 %ignore anthy_set_prediction_string;
59 %ignore anthy_get_prediction_stat;
60 %ignore anthy_get_prediction;
62 %ignore anthy_print_context;
63 %ignore anthy_context_set_encoding;
66 #define anthy_context_set_string anthy_set_string
67 #define anthy_context_resize_segment anthy_resize_segment
68 #define anthy_context_get_stat anthy_get_stat
69 #define anthy_context_get_segment_stat anthy_get_segment_stat
70 /* #define anthy_context_get_segment anthy_get_segment */
71 /* #define anthy_context_commit_segment anthy_commit_segment */
72 #define anthy_context_print anthy_print_context
74 #define anthy_context_set_prediction_string anthy_set_prediction_string
75 #define anthy_context_get_prediction_stat anthy_get_prediction_stat
76 /* #define anthy_context_get_prediction anthy_get_prediction */
79 %rename(Context) anthy_context;
81 %rename(get_version_string) anthy_get_version_string;
82 /* SWIG says "Segmentation fault" */
83 /* %alias anthy_get_version_string "version_string"; */
88 return anthy_get_version_string();
93 %ignore anthy_set_logger;
96 static VALUE logger = Qnil;
100 rb_gc_register_address(&logger);
105 } /* for c-mode indentation */
108 typedef struct logger_info
115 invoke_logger(VALUE data)
117 logger_info_t *info = (logger_info_t *)data;
118 return rb_funcall(logger, rb_intern("call"), 2, info->level, info->message);
122 rb_logger(int lv, const char *str)
127 info.level = INT2NUM(lv);
128 info.message = rb_str_new2(str);
129 rb_protect(invoke_logger, (VALUE)&info, &state);
130 if (state && !NIL_P(ruby_errinfo)) {
131 VALUE klass, message, backtrace;
134 klass = rb_funcall(rb_funcall(ruby_errinfo, rb_intern("class"), 0),
135 rb_intern("to_s"), 0);
136 message = rb_funcall(ruby_errinfo, rb_intern("message"), 0);
137 backtrace = rb_funcall(ruby_errinfo, rb_intern("backtrace"), 0);
138 rb_warning("%s: %s\n", StringValueCStr(klass), StringValueCStr(message));
140 len = RARRAY(backtrace)->len;
141 for (i = 0; i < len; i++) {
142 rb_warning("%s\n", StringValueCStr(RARRAY(backtrace)->ptr[i]));
148 { /* for c-mode indentation */
154 } /* for c-mode indentation */
158 set_logger(int level)
160 if (rb_block_given_p()) {
162 anthy_set_logger(NULL, level);
164 logger = rb_block_proc();
165 anthy_set_logger(rb_logger, level);
170 { /* for c-mode indentation */
174 %include include/anthy.h
177 %freefunc anthy_context "anthy_release_context";
185 return anthy_create_context();
190 anthy_reset_context(self);
193 %alias set_string "string=";
194 int set_string(char *);
196 void resize_segment(int, int);
198 %alias get_stat "stat";
199 int get_stat(struct anthy_conv_stat *OUTPUT);
201 %alias get_segment_stat "segment_stat";
202 int get_segment_stat(int, struct anthy_segment_stat *OUTPUT);
204 %alias get_segment "segment";
205 VALUE get_segment(int nth_seg, int nth_cand)
209 len = anthy_get_segment(self, nth_seg, nth_cand, NULL, 0);
210 buffer = alloca(len + 1);
211 len = anthy_get_segment(self, nth_seg, nth_cand, buffer, len + 1);
215 return rb_str_new2(buffer);
219 VALUE commit_segment(int s, int c)
221 return (anthy_commit_segment(self, s, c) < 0) ? Qfalse : Qtrue;
224 %alias set_prediction_string "prediction_string=";
225 int set_prediction_string(const char *);
227 %alias get_prediction_stat "prediction_stat";
228 int get_prediction_stat(struct anthy_prediction_stat *OUTPUT);
230 %alias get_prediction "prediction";
231 int get_prediction(int nth_pre)
235 len = anthy_get_prediction(self, nth_pre, NULL, 0);
236 buffer = alloca(len + 1);
237 len = anthy_get_prediction(self, nth_pre, buffer, len + 1);
241 return rb_str_new2(buffer);
248 %alias set_encoding "encoding=";
249 void set_encoding(int encoding);