From: ttate@... Date: 1998-06-27T20:18:20+09:00 Subject: [ruby-dev:3063] tcl/tk8.1 立石@JAISTです。 Tcl8.1で日本語の表示をしようと思っているの ですが、なぜかcoreを吐いて死んでしまいます。 以下に簡単な例を載せますのでなにか気づいた ことがあれば教えて下さい。 ;; 文字列の大きさなどはとりあえず気にせずに ;; 1024バイトに収まると考えて,,,,,,(^^; ------------ tcltklib.c ------------ static VALUE ip_to_utf(VALUE self, VALUE ename, VALUE str) { Tcl_Interp *interp; Tcl_Encoding encoding; Tcl_DString *dstr; struct tcltkip *ptr; char str1[1024]; Data_Get_Struct(self,struct tcltkip,ptr); interp = ptr->ip; strcpy(str1,STR2CSTR(str)); if( (encoding = Tcl_GetEncoding(interp,STR2CSTR(ename))) == NULL ) Fail("Tcl_GetEncoding"); Tcl_ExternalToUtfDString(encoding,str1,strlen(str1),dstr); strcpy(str1,Tcl_DStringValue(dstr)); return str_new2(str1); }; これを, rb_define_method(ip,"to_utf",ip_to_utf,2); として登録する。 ちなみに以下は単純なCのソースですがこちらはうまく 動きます。 ---------------------------- #include #include main() { Tcl_Interp *interp; Tcl_Encoding encoding; Tcl_DString *dstr; char str1[1024] = "button .exit -text 終了 -command exit"; char str2[1024] = "pack .exit"; interp = Tcl_CreateInterp(); if (Tcl_Init(interp) == TCL_ERROR) exit(1); if (Tk_Init(interp) == TCL_ERROR) exit(1); encoding = Tcl_GetEncoding(interp,"euc-jp"); printf("encoding : %s\n",Tcl_GetEncodingName(encoding)); Tcl_ExternalToUtfDString(encoding,str1,strlen(str1),dstr); strcpy(str1,Tcl_DStringValue(dstr)); Tcl_Eval(interp,str1); /* str1 must be writable memory in Tcl8.1 */ Tcl_Eval(interp,str2); Tk_MainLoop(); Tcl_DeleteInterp(interp); Tcl_Exit(0); } ---------------------------------------------- Name Takaaki Tateishi E-Mail ttate@jaist.ac.jp tateishi@pluto.dti.ne.jp URL http://www.pluto.dti.ne.jp/~tateishi/ Org School of Information Science Japan Advanced Institute of Science and Technology (JAIST)