diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-06-21 06:31:12 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-06-21 06:31:12 +0000 |
commit | 53838a0e58027072c1ea8617342c2137d9fa5313 (patch) | |
tree | fffefdd164a048925196a437c208c1b21f687bbb /ext | |
parent | 7e774e049258dbda55edfdac9c5022c3d8fbdcf1 (diff) |
1.2.6
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/etc/etc.c | 7 | ||||
-rw-r--r-- | ext/kconv/kconv.c | 39 | ||||
-rw-r--r-- | ext/tcltklib/extconf.rb | 4 | ||||
-rw-r--r-- | ext/tcltklib/tcltklib.c | 108 | ||||
-rw-r--r-- | ext/tk/lib/tk.rb | 3 | ||||
-rw-r--r-- | ext/tk/lib/tktext.rb | 175 |
6 files changed, 256 insertions, 80 deletions
diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 1cf06768c8..5e655980e4 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -214,10 +214,11 @@ etc_group(obj) endgrent(); return obj; } - return setup_group(getgrent()); -#else - return Qnil; + if (grp = getgrent()) { + return setup_group(grp); + } #endif + return Qnil; } static VALUE mEtc; diff --git a/ext/kconv/kconv.c b/ext/kconv/kconv.c index 0cb9b10a0b..048719b39f 100644 --- a/ext/kconv/kconv.c +++ b/ext/kconv/kconv.c @@ -165,8 +165,8 @@ static char *Patchlevel = /* MIME preprocessor */ -#define _GETC() (*inptr ? (int)(*inptr++) : EOF) -#define _UNGETC(c) (*--inptr = (c)) +#define _GETC() (inlen-- ? (int)(*inptr++) : EOF) +#define _UNGETC(c) (inlen++, *--inptr = (c)) #define PUTCHAR(c) (outlen + 1 < outsiz ? \ ((outptr[outlen++] = (c)), (outptr[outlen] = '\0')) : EOF) #define GETC() ((!mime_mode)?_GETC():mime_getc()) @@ -181,6 +181,7 @@ extern POINT _BufferSize; static unsigned char hold_buf[HOLD_SIZE*2]; static int hold_count; static unsigned char *inptr; +static int inlen; static char *outptr; static int outsiz; static int outlen; @@ -341,7 +342,7 @@ static int del_cr = FALSE; static void (*iconv) _((register int c2,register int c1)); /* s_iconv or oconv */ static void (*oconv) _((register int c2,register int c1)); /* [ejs]_oconv */ -static int do_kconv _((char *i, char *o, int siz, int out_code, int in_code)); +static int do_kconv _((VALUE, VALUE, int out_code, int in_code)); static void h_conv _((register int c2,register int c1)); static int push_hold_buf _((int c2,int c1)); static void s_iconv _((register int c2,register int c1)); @@ -580,25 +581,25 @@ main (argc, argv) #endif /* notdef */ static int -do_kconv(i, o, siz, out_code, in_code) - char *i; - char *o; - int siz, out_code, in_code; +do_kconv(in, out, out_code, in_code) + VALUE in, out; + int out_code, in_code; { - register int c1, - c2; + register int c1, c2; c2 = 0; - if (siz <= 0) { + inptr = (unsigned char *)RSTRING(in)->ptr; /* input buffer */ + inlen = RSTRING(in)->len; /* input buffer size*/ + outptr = RSTRING(out)->ptr; /* output buffer */ + outsiz = RSTRING(in)->len; /* output buffer size */ + outlen = 0; /* current length of output string */ + + if (inlen <= 0) { return 0; } - *o = '\0'; + *outptr = '\0'; - inptr = (unsigned char *)i; /* input buffer */ - outptr = o; /* output buffer */ - outsiz = siz; /* output buffer size */ - outlen = 0; /* current length of output string */ x0201_f = TRUE; /* don't assume JISX0201 kana */ rot_f = FALSE; /* rot14/43 mode */ input_f = FALSE; /* non fixed input code */ @@ -1834,7 +1835,7 @@ kconv_kconv(argc, argv) } dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */ - RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, out_code, in_code); + RSTRING(dst)->len = do_kconv(src, dst, out_code, in_code); return dst; } @@ -1848,7 +1849,7 @@ kconv_tojis(obj, src) Check_Type(src, T_STRING); dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */ - RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, _JIS, _AUTO); + RSTRING(dst)->len = do_kconv(src, dst, _JIS, _AUTO); return dst; } @@ -1862,7 +1863,7 @@ kconv_toeuc(obj, src) Check_Type(src, T_STRING); dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */ - RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, _EUC, _AUTO); + RSTRING(dst)->len = do_kconv(src, dst, _EUC, _AUTO); return (VALUE)dst; } @@ -1876,7 +1877,7 @@ kconv_tosjis(obj, src) Check_Type(src, T_STRING); dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */ - RSTRING(dst)->len = do_kconv(RSTRING(src)->ptr, RSTRING(dst)->ptr, RSTRING(dst)->len, _SJIS, _AUTO); + RSTRING(dst)->len = do_kconv(src, dst, _SJIS, _AUTO); return dst; } diff --git a/ext/tcltklib/extconf.rb b/ext/tcltklib/extconf.rb index 6f6d256604..d206bf76ab 100644 --- a/ext/tcltklib/extconf.rb +++ b/ext/tcltklib/extconf.rb @@ -59,7 +59,7 @@ def search_lib(file, func, *path) for lib in files.sort!.reverse! lib = File::basename(lib) lib.sub!(/^lib/, '') - lib.sub!(/\.(a|so)$/, '') + lib.sub!(/\.(a|so(.[0-9]+)?)$/, '') if have_library(lib, func) unless $libraries.include? path $libraries << path @@ -74,7 +74,7 @@ def search_lib(file, func, *path) end if have_header("tcl.h") && have_header("tk.h") && - search_lib("libX11.{a,so}", "XOpenDisplay", + search_lib("libX11.{a,so*}", "XOpenDisplay", "/usr/lib", "/usr/openwin/lib", "/usr/X11*/lib") && search_lib("libtcl{,8*,7*}.{a,so}", "Tcl_FindExecutable", "/usr/lib", "/usr/local/lib") && diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index 5948c8f5b0..3b464ecf28 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -27,8 +27,8 @@ fprintf(stderr, ARG1, ARG2); fprintf(stderr, "\n"); } */ /* for callback break & continue */ -VALUE eTkCallbackBreak; -VALUE eTkCallbackContinue; +static VALUE eTkCallbackBreak; +static VALUE eTkCallbackContinue; /* from tkAppInit.c */ @@ -49,15 +49,14 @@ typedef struct { } Tk_TimerData; /* timer callback */ -void _timer_for_tcl (ClientData clientData) +static void +_timer_for_tcl(clientData) + ClientData clientData; { Tk_TimerData *timer = (Tk_TimerData*)clientData; timer->flag = 0; CHECK_INTS; -#ifdef THREAD - if (!thread_critical) thread_schedule(); -#endif timer->token = Tk_CreateTimerHandler(200, _timer_for_tcl, (ClientData)timer); @@ -66,11 +65,12 @@ void _timer_for_tcl (ClientData clientData) /* execute Tk_MainLoop */ static VALUE -lib_mainloop(VALUE self) +lib_mainloop(self) + VALUE self; { Tk_TimerData *timer; - timer = (Tk_TimerData *) ckalloc(sizeof(Tk_TimerData)); + timer = (Tk_TimerData *)ALLOC(Tk_TimerData); timer->flag = 0; timer->token = Tk_CreateTimerHandler(200, _timer_for_tcl, (ClientData)timer); @@ -79,6 +79,7 @@ lib_mainloop(VALUE self) DUMP1("start Tk_Mainloop"); while (Tk_GetNumMainWindows() > 0) { Tcl_DoOneEvent(0); + CHECK_INTS; } DUMP1("stop Tk_Mainloop"); @@ -87,6 +88,7 @@ lib_mainloop(VALUE self) Tk_DeleteTimerHandler(timer->token); } #endif + free(timer); return Qnil; } @@ -99,7 +101,9 @@ struct tcltkip { /* Tcl command `ruby' */ static VALUE -ip_eval_rescue(VALUE *failed, VALUE einfo) +ip_eval_rescue(failed, einfo) + VALUE *failed; + VALUE einfo; { *failed = einfo; return Qnil; @@ -107,10 +111,17 @@ ip_eval_rescue(VALUE *failed, VALUE einfo) static int #if TCL_MAJOR_VERSION >= 8 -ip_ruby(ClientData clientData, Tcl_Interp *interp, - int argc, Tcl_Obj *CONST argv[]) +ip_ruby(clientData, interp, argc, argv) + ClientData clientData; + Tcl_Interp *interp; + int argc; + Tcl_Obj *CONST argv[]; #else -ip_ruby(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) +ip_ruby(clientData, interp, argc, argv) + ClientData clientData; + Tcl_Interp *interp; + int argc; + char *argv[]; #endif { VALUE res; @@ -167,7 +178,8 @@ ip_ruby(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[]) /* destroy interpreter */ static void -ip_free(struct tcltkip *ptr) +ip_free(ptr) + struct tcltkip *ptr; { DUMP1("Tcl_DeleteInterp"); Tcl_DeleteInterp(ptr->ip); @@ -176,7 +188,8 @@ ip_free(struct tcltkip *ptr) /* create and initialize interpreter */ static VALUE -ip_new(VALUE self) +ip_new(self) + VALUE self; { struct tcltkip *ptr; /* tcltkip data struct */ VALUE obj; /* newly created object */ @@ -218,7 +231,9 @@ ip_new(VALUE self) /* eval string in tcl by Tcl_Eval() */ static VALUE -ip_eval(VALUE self, VALUE str) +ip_eval(self, str) + VALUE self; + VALUE str; { char *s; char *buf; /* Tcl_Eval requires re-writable string region */ @@ -244,72 +259,74 @@ ip_eval(VALUE self, VALUE str) static VALUE -ip_toUTF8(VALUE self, VALUE str, VALUE encodename) +ip_toUTF8(self, str, encodename) + VALUE self; + VALUE str; + VALUE encodename; { -#ifndef TCL_UTF_MAX - return str; -#else +#ifdef TCL_UTF_MAX Tcl_Interp *interp; Tcl_Encoding encoding; Tcl_DString dstr; struct tcltkip *ptr; - char *buff1,*buff2; + char *buf; Data_Get_Struct(self,struct tcltkip, ptr); interp = ptr->ip; encoding = Tcl_GetEncoding(interp,STR2CSTR(encodename)); - buff1 = ALLOCA_N(char,strlen(STR2CSTR(str))+1); - strcpy(buff1,STR2CSTR(str)); + buf = ALLOCA_N(char,strlen(STR2CSTR(str))+1); + strcpy(buf,STR2CSTR(str)); Tcl_DStringInit(&dstr); Tcl_DStringFree(&dstr); - Tcl_ExternalToUtfDString(encoding,buff1,strlen(buff1),&dstr); - buff2 = ALLOCA_N(char,Tcl_DStringLength(&dstr)+1); - strcpy(buff2,Tcl_DStringValue(&dstr)); + Tcl_ExternalToUtfDString(encoding,buf,strlen(buf),&dstr); + str = str_new2(Tcl_DStringValue(&dstr)); Tcl_FreeEncoding(encoding); Tcl_DStringFree(&dstr); - - return str_new2(buff2); #endif + return str; } static VALUE -ip_fromUTF8(VALUE self, VALUE str, VALUE encodename) +ip_fromUTF8(self, str, encodename) + VALUE self; + VALUE str; + VALUE encodename; { -#ifndef TCL_UTF_MAX - return str; -#else +#ifdef TCL_UTF_MAX Tcl_Interp *interp; Tcl_Encoding encoding; Tcl_DString dstr; struct tcltkip *ptr; - char *buff1,*buff2; + char *buf; Data_Get_Struct(self,struct tcltkip, ptr); interp = ptr->ip; encoding = Tcl_GetEncoding(interp,STR2CSTR(encodename)); - buff1 = ALLOCA_N(char,strlen(STR2CSTR(str))+1); - strcpy(buff1,STR2CSTR(str)); + buf = ALLOCA_N(char,strlen(STR2CSTR(str))+1); + strcpy(buf,STR2CSTR(str)); Tcl_DStringInit(&dstr); Tcl_DStringFree(&dstr); - Tcl_UtfToExternalDString(encoding,buff1,strlen(buff1),&dstr); - buff2 = ALLOCA_N(char,Tcl_DStringLength(&dstr)+1); - strcpy(buff2,Tcl_DStringValue(&dstr)); + Tcl_UtfToExternalDString(encoding,buf,strlen(buf),&dstr); + str = str_new2(Tcl_DStringValue(&dstr)); Tcl_FreeEncoding(encoding); Tcl_DStringFree(&dstr); - return str_new2(buff2); #endif + return str; } static VALUE -ip_invoke(int argc, VALUE *argv, VALUE obj) +ip_invoke(argc, argv, obj) + int argc; + VALUE *argv; + VALUE obj; { struct tcltkip *ptr; /* tcltkip data struct */ int i; @@ -344,6 +361,7 @@ ip_invoke(int argc, VALUE *argv, VALUE obj) for (i = 0; i < argc; ++i) { char *s = STR2CSTR(argv[i]); ov[i] = Tcl_NewStringObj(s, strlen(s)); + Tcl_IncrRefCount(ov[i]); } ov[argc] = (Tcl_Obj *)NULL; #endif @@ -372,6 +390,10 @@ ip_invoke(int argc, VALUE *argv, VALUE obj) resultPtr = Tcl_GetObjResult(ptr->ip); Tcl_SetResult(ptr->ip, Tcl_GetStringFromObj(resultPtr, &dummy), TCL_VOLATILE); + + for (i=0; i<argc; i++) { + Tcl_DecrRefCount(ov[i]); + } #endif } else { ptr->return_value = (*info.proc)(info.clientData, @@ -383,12 +405,13 @@ ip_invoke(int argc, VALUE *argv, VALUE obj) } /* pass back the result (as string) */ - return(str_new2(ptr->ip->result)); + return str_new2(ptr->ip->result); } /* get return code from Tcl_Eval() */ static VALUE -ip_retval(VALUE self) +ip_retval(self) + VALUE self; { struct tcltkip *ptr; /* tcltkip data struct */ @@ -408,7 +431,8 @@ _macinit() #endif /*---- initialization ----*/ -void Init_tcltklib() +void +Init_tcltklib() { extern VALUE rb_argv0; /* the argv[0] */ diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index e937e51c2b..0480d647b7 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -233,6 +233,7 @@ module TkComm return format("rb_out %s", id); end def uninstall_cmd(id) + id = $1 if /rb_out (c\d+)/ Tk_CMDTBL[id] = nil end private :install_cmd, :uninstall_cmd @@ -2115,7 +2116,7 @@ class TkScrollbar<TkWindow end def get - ary1 = tk_send('get', path).split + ary1 = tk_send('get').split ary2 = [] for i in ary1 ary2.push number(i) diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index 02d5a7f3e0..8e07cf4347 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -247,11 +247,11 @@ class TkText<TkTextWin private :_tag_bind_core def tag_bind(tag, seq, cmd=Proc.new, args=nil) - _tag_bind_core('', tag, seq, cmd=Proc.new, args=nil) + _tag_bind_core('', tag, seq, cmd, args=nil) end def tag_bind_append(tag, seq, cmd=Proc.new, args=nil) - _tag_bind_core('+', tag, seq, cmd=Proc.new, args=nil) + _tag_bind_core('+', tag, seq, cmd, args=nil) end def tag_bindinfo(tag, context=nil) @@ -272,7 +272,7 @@ class TkText<TkTextWin end def tag_cget(tag, key) - tk_tcl2ruby tk_call @t.path, 'tag', 'cget', tag, "-#{key}" + tk_tcl2ruby tk_call @path, 'tag', 'cget', tag, "-#{key}" end def tag_configure(tag, key, val=None) @@ -285,11 +285,11 @@ class TkText<TkTextWin end else - if ( key == 'font' || key == 'kanjifont' \ - || key == 'latinfont' || key == 'asciifont' ) + if key == 'font' || key == 'kanjifont' || + key == 'latinfont' || key == 'asciifont' tagfont_configure({key=>val}) else - tk_call 'tag', 'configure', tag, "-#{key}", val + tk_send 'tag', 'configure', tag, "-#{key}", val end end end @@ -320,7 +320,7 @@ class TkText<TkTextWin end def tag_ranges(tag) - l = tk_split_list(tk_send('tag', 'ranges', tag)) + l = tk_split_simplelist(tk_send('tag', 'ranges', tag)) r = [] while key=l.shift r.push [key, l.shift] @@ -329,11 +329,11 @@ class TkText<TkTextWin end def tag_nextrange(tag, first, last=None) - tk_split_list(tk_send('tag', 'nextrange', tag, first, last)) + tk_split_simplelist(tk_send('tag', 'nextrange', tag, first, last)) end def tag_prevrange(tag, first, last=None) - tk_split_list(tk_send('tag', 'prevrange', tag, first, last)) + tk_split_simplelist(tk_send('tag', 'prevrange', tag, first, last)) end def search_with_length(pat,start,stop=None) @@ -437,9 +437,19 @@ class TkTextTag<TkObject @path = @id = $tk_text_tag $tk_text_tag = $tk_text_tag.succ #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) - configure(keys) if keys + if args != [] then + keys = args.pop + if keys.kind_of? Hash then + add(*args) if args != [] + configure(keys) + else + args.push keys + add(*args) + end + end @t._addtag id, self end + def id return @id end @@ -461,7 +471,7 @@ class TkTextTag<TkObject end def ranges - l = tk_split_list(tk_call(@t.path, 'tag', 'ranges', @id)) + l = tk_split_simplelist(tk_call(@t.path, 'tag', 'ranges', @id)) r = [] while key=l.shift r.push [key, l.shift] @@ -470,11 +480,11 @@ class TkTextTag<TkObject end def nextrange(first, last=None) - tk_split_list(tk_call(@t.path, 'tag', 'nextrange', @id, first, last)) + tk_split_simplelist(tk_call(@t.path, 'tag', 'nextrange', @id, first, last)) end def prevrange(first, last=None) - tk_split_list(tk_call(@t.path, 'tag', 'prevrange', @id, first, last)) + tk_split_simplelist(tk_call(@t.path, 'tag', 'prevrange', @id, first, last)) end def [](key) @@ -631,6 +641,18 @@ class TkTextMarkCurrent<TkTextMark end end +class TkTextMarkAnchor<TkTextMark + def initialize(parent,index=nil) + if not parent.kind_of?(TkText) + fail format("%s need to be TkText", parent.inspect) + end + @t = parent + @path = @id = 'anchor' + tk_call @t.path, 'mark', 'set', @id, index if index + @t._addtag id, self + end +end + class TkTextWindow<TkObject def initialize(parent, index, keys) if not parent.kind_of?(TkText) @@ -726,6 +748,133 @@ class TkTextWindow<TkObject } end end + + def _dump(type, *index) + str = tk_send('dump', type, *index) + result = [] + sel = nil + i = 0 + while i < str.size + # retrieve key + idx = str.index(/ /, i) + result.push str[i..(idx-1)] + i = idx + 1 + + # retrieve value + case result[-1] + when 'text' + if str[i] == ?{ + # text formed as {...} + val, i = _retrieve_braced_text(str, i) + result.push val + else + # text which may contain backslahes + val, i = _retrieve_backslashed_text(str, i) + result.push val + end + else + idx = str.index(/ /, i) + val = str[i..(idx-1)] + case result[-1] + when 'mark' + case val + when 'insert' + result.push TkTextMarkInsert.new(self) + when 'current' + result.push TkTextMarkCurrent.new(self) + when 'anchor' + result.push TkTextMarkAnchor.new(self) + else + result.push tk_tcl2rb(val) + end + when 'tagon' + if val == 'sel' + if sel + result.push sel + else + result.push TkTextTagSel.new(self) + end + else + result.push tk_tcl2rb val + end + when 'tagoff' + result.push tk_tcl2rb sel + when 'window' + result.push tk_tcl2rb val + end + i = idx + 1 + end + + # retrieve index + idx = str.index(/ /, i) + if idx + result.push str[i..(idx-1)] + i = idx + 1 + else + result.push str[i..-1] + break + end + end + + kvis = [] + until result.empty? + kvis.push [result.shift, result.shift, result.shift] + end + kvis # result is [[key1, value1, index1], [key2, value2, index2], ...] + end + private :_dump + + def _retrieve_braced_text(str, i) + cnt = 0 + idx = i + while idx < str.size + case str[idx] + when ?{ + cnt += 1 + when ?} + cnt -= 1 + if cnt == 0 + break + end + end + idx += 1 + end + return str[i+1..idx-1], idx + 2 + end + private :_retrieve_braced_text + + def _retrieve_backslashed_text(str, i) + j = i + idx = nil + loop { + idx = str.index(/ /, j) + if str[idx-1] == ?\\ + j += 1 + else + break + end + } + val = str[i..(idx-1)] + val.gsub!(/\\( |\{|\})/, '\1') + return val, idx + 1 + end + private :_retrieve_backslashed_text + + def dump_all(*index) + _dump('-all', *index) + end + def dump_mark(*index) + _dump('-mark', *index) + end + def dump_tag(*index) + _dump('-tag', *index) + end + def dump_text(*index) + _dump('-text', *index) + end + def dump_window(*index) + _dump('-window', *index) + end end class TkTextImage<TkObject |