https://github.com/hogelog/kakasi-ruby
ruby用のkakasiモジュールはそのままではruby1.9ではコンパイルが通りません
そこで↓を参考に修正
http://www.metareal.org/2007/06/14/ruby-extension-struct-rstring-macros/
パッチ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | diff -u kakasi-ruby-master/kakasi.c kakasi-ruby-master-1.9/kakasi.c --- kakasi-ruby-master/kakasi.c 2013-04-19 10:14:17.000000000 +0900 +++ kakasi-ruby-master-1.9/kakasi.c 2013-04-19 10:08:46.000000000 +0900 @@ -3,24 +3,28 @@ * Copyright (c) 1999-2002 GOTO Kentaro */ - #include <string.h> #include "ruby.h" #include "libkakasi.h" - #define OPTMAX 1024 #define min(x,y) ((x)<(y) ? (x) : (y)) +// 130419 for 1.9 +#ifndef RSTRING_PTR +#define RSTRING_PTR(s) (RSTRING(s)->ptr) +#endif +#ifndef RSTRING_LEN +#define RSTRING_LEN(s) (RSTRING(s)->len) +#endif + static char const rcsid[] = "$kNotwork: kakasi.c,v 1.3 2002/09/28 05:21:37 gotoken Exp $"; - static int dic_closed = 1, len = 0; static char prev_opt_ptr[OPTMAX]; - static VALUE rb_kakasi_kakasi(obj, opt, src) VALUE obj, opt, src; @@ -30,45 +34,36 @@ char *buf, *opt_ptr, *t; VALUE dst; - Check_Type(src, T_STRING); - /* return "" immediately if source str is empty */ - if (RSTRING(src)->len == 0) + if(RSTRING_LEN(src)==0) return rb_str_new2(""); - Check_Type(opt, T_STRING); - /* initialize kakasi iff opt != previous opt */ - if (0 == len || 0 != strncmp(RSTRING(opt)->ptr, prev_opt_ptr, - min(RSTRING(opt)->len, len))) { - strncpy(prev_opt_ptr, RSTRING(opt)->ptr, RSTRING(opt)->len); - len = RSTRING(opt)->len; - + if (0 == len || 0 != strncmp(RSTRING_PTR(opt), prev_opt_ptr, + min(RSTRING_LEN(opt), len))) { + strncpy(prev_opt_ptr, RSTRING_PTR(opt), RSTRING_LEN(opt)); + len = RSTRING_LEN(opt); if (len + 1 > OPTMAX) { rb_raise(rb_eArgError, "too long 1st arg (should be < 1023)"); } - if (!dic_closed) { kakasi_close_kanwadict(); dic_closed = 1; } - - argv = opts = ALLOCA_N(char*, RSTRING(opt)->len); + argv = opts = ALLOCA_N(char*, RSTRING_LEN(opt)); *opts++ = "kakasi"; argc++; - - opt_ptr = ALLOCA_N(char, 1 + RSTRING(opt)->len); - strncpy(opt_ptr, RSTRING(opt)->ptr, RSTRING(opt)->len); - opt_ptr[RSTRING(opt)->len] = '\0'; - + opt_ptr = ALLOCA_N(char, 1 + RSTRING_LEN(opt)); + strncpy(opt_ptr, RSTRING_PTR(opt), RSTRING_LEN(opt)); + opt_ptr[RSTRING_LEN(opt)] = '\0'; if (*opts++ = strtok(opt_ptr, " \t")) { argc++; @@ -77,42 +72,37 @@ argc++; } } - - + if (0 != kakasi_getopt_argv(argc, argv)) rb_raise(rb_eRuntimeError, "failed to initialize kakasi"); dic_closed = 0; } - dst = rb_str_new2(""); - while (i < RSTRING(src)->len) { - if (*(RSTRING(src)->ptr + i) != '\0') { - buf = kakasi_do((RSTRING(src)->ptr + i)); + while (i < RSTRING_LEN(src)) { + if (*(RSTRING_PTR(src) + i) != '\0') { + buf = kakasi_do((RSTRING_PTR(src) + i)); rb_str_concat(dst, rb_str_new2(buf)); if (*buf) free(buf); - while (*(RSTRING(src)->ptr + i) != '\0') { + while (*(RSTRING_PTR(src) + i) != '\0') { i++; } } - if (i == RSTRING(src)->len) { + if (i == RSTRING_LEN(src)) { break; } rb_str_concat(dst, rb_str_new("\0", 1)); i++; } - return dst; } - void Init_kakasi() { VALUE mKakasi = rb_define_module("Kakasi"); - rb_define_module_function(mKakasi, "kakasi", rb_kakasi_kakasi, 2); rb_define_const(mKakasi, "KAKASI_VERSION", rb_str_new2("2002-09-28")); } |
と思って作成していたらすでに修正している人がいました。_| ̄|○