From c30c3bffe472ee999fc722f63dd1c1984db1d1ce Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 15 Jul 1998 06:13:08 +0000 Subject: 1.1b9_31 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 20 +++ bignum.c | 14 +- eval.c | 36 ++-- ext/tcltklib/tcltklib.c | 68 ++++++++ gc.c | 10 +- lib/matrix.rb | 10 +- lib/pstore.rb | 3 + lib/tk.rb | 175 +++++++++++++++++-- lib/tkcanvas.rb | 150 +++++++++++++++- lib/tkfont.rb | 445 ++++++++++++++++++++++++++++++++++++++++-------- lib/tktext.rb | 216 +++++++++++++++++++---- lib/weakref.rb | 4 +- numeric.c | 7 +- parse.y | 2 +- sample/ruby-mode.el | 42 +++-- sprintf.c | 6 +- variable.c | 18 +- version.h | 4 +- 18 files changed, 1024 insertions(+), 206 deletions(-) diff --git a/ChangeLog b/ChangeLog index c189489aa4..731f1934dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,27 @@ +Wed Jul 15 15:11:57 1998 Yukihiro Matsumoto + + * experimental release 1.1b9_31. + +Wed Jul 15 15:05:27 1998 Yukihiro Matsumoto + + * eval.c (thread_create): exit() and abort() in threads now + forwarded to main_thread. + +Tue Jul 14 14:03:47 1998 Yukihiro Matsumoto + + * variable.c (obj_instance_variables): list names that is not + instance variables. + + * gc.c (GC_MALLOC_LIMIT): choose smaller limit value. + Mon Jul 13 12:39:38 1998 Yukihiro Matsumoto * object.c (str2cstr): should not return NULL. +Fri Jul 10 11:51:46 1998 Yukihiro Matsumoto + + * parse.y (gettable): needed to add dyna_in_block() check. + Thu Jul 9 17:38:23 1998 Yukihiro Matsumoto * experimental release 1.1b9_30. diff --git a/bignum.c b/bignum.c index 94d7095aca..4318760d74 100644 --- a/bignum.c +++ b/bignum.c @@ -19,7 +19,7 @@ typedef unsigned short USHORT; #define BITSPERDIG (sizeof(short)*CHAR_BIT) #define BIGRAD (1L << BITSPERDIG) #define DIGSPERINT ((unsigned int)(sizeof(long)/sizeof(short))) -#define BIGUP(x) ((unsigned int)(x) << BITSPERDIG) +#define BIGUP(x) ((unsigned long)(x) << BITSPERDIG) #define BIGDN(x) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>>BITSPERDIG) #define BIGLO(x) ((x) & (BIGRAD-1)) @@ -85,17 +85,17 @@ bignorm(x) while (len-- && !ds[len]) ; RBIGNUM(x)->len = ++len; - if (len*sizeof(USHORT) < sizeof(VALUE) || - (len*sizeof(USHORT) == sizeof(VALUE) && - ds[sizeof(VALUE)/sizeof(USHORT)-1] <= 0x3fff)) { + if (len*sizeof(USHORT) <= sizeof(VALUE)) { long num = 0; while (len--) { num = BIGUP(num) + ds[len]; } - if (RBIGNUM(x)->sign) { - if (POSFIXABLE(num)) return INT2FIX(num); + if (num >= 0) { + if (RBIGNUM(x)->sign) { + if (POSFIXABLE(num)) return INT2FIX(num); + } + else if (NEGFIXABLE(-num)) return INT2FIX(-num); } - else if (NEGFIXABLE(-num)) return INT2FIX(-num); } return x; } diff --git a/eval.c b/eval.c index 2ed291d0c6..80f6ffddd7 100644 --- a/eval.c +++ b/eval.c @@ -5649,7 +5649,6 @@ thread_remove() curr_thread->status = THREAD_KILLED; curr_thread->prev->next = curr_thread->next; curr_thread->next->prev = curr_thread->prev; - thread_schedule(); } static int @@ -6230,6 +6229,8 @@ catch_timer(sig) int thread_tick = THREAD_TICK; #endif +static VALUE thread_raise _((int, VALUE*, VALUE)); + VALUE thread_create(fn, arg) VALUE (*fn)(); @@ -6274,36 +6275,29 @@ thread_create(fn, arg) } } POP_TAG(); + thread_remove(); if (state && th->status != THREAD_TO_KILL && !NIL_P(errinfo)) { - if (state == TAG_FATAL || obj_is_kind_of(errinfo, eSystemExit) || - thread_abort || curr_thread->abort || RTEST(debug)) { - /* fatal error or global exit within this thread */ - /* need to stop whole script */ + if (state == TAG_FATAL) { + /* fatal error within this thread, need to stop whole script */ main_thread->errinfo = errinfo; thread_cleanup(); } -#if 0 + else if (obj_is_kind_of(errinfo, eSystemExit)) { + /* delegate exception to main_thread */ + thread_raise(1, &errinfo, main_thread->thread); + } else if (thread_abort || curr_thread->abort || RTEST(debug)) { - thread_critical = 0; - thread_ready(main_thread); - main_thread->errinfo = errinfo; - if (curr_thread == main_thread) { - rb_raise(errinfo); - } - curr_thread = main_thread; - th_raise_argc = 1; - th_raise_argv[0] = errinfo; - th_raise_file = sourcefile; - th_raise_line = sourceline; - thread_restore_context(curr_thread, 4); + VALUE err = exc_new(eSystemExit, 0, 0); + error_print(); + /* exit on main_thread */ + thread_raise(1, &err, main_thread->thread); } -#endif else { curr_thread->errinfo = errinfo; } } - thread_remove(); - return 0; + thread_schedule(); + return 0; /* not reached */ } static VALUE diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c index df242997e8..5948c8f5b0 100644 --- a/ext/tcltklib/tcltklib.c +++ b/ext/tcltklib/tcltklib.c @@ -242,6 +242,72 @@ ip_eval(VALUE self, VALUE str) return(str_new2(ptr->ip->result)); } + +static VALUE +ip_toUTF8(VALUE self, VALUE str, VALUE encodename) +{ +#ifndef TCL_UTF_MAX + return str; +#else + Tcl_Interp *interp; + Tcl_Encoding encoding; + Tcl_DString dstr; + struct tcltkip *ptr; + char *buff1,*buff2; + + 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)); + + 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_FreeEncoding(encoding); + Tcl_DStringFree(&dstr); + + return str_new2(buff2); +#endif +} + +static VALUE +ip_fromUTF8(VALUE self, VALUE str, VALUE encodename) +{ +#ifndef TCL_UTF_MAX + return str; +#else + Tcl_Interp *interp; + Tcl_Encoding encoding; + Tcl_DString dstr; + struct tcltkip *ptr; + char *buff1,*buff2; + + 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)); + + 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_FreeEncoding(encoding); + Tcl_DStringFree(&dstr); + + return str_new2(buff2); +#endif +} + + static VALUE ip_invoke(int argc, VALUE *argv, VALUE obj) { @@ -356,6 +422,8 @@ void Init_tcltklib() rb_define_singleton_method(ip, "new", ip_new, 0); rb_define_method(ip, "_eval", ip_eval, 1); + rb_define_method(ip, "_toUTF8",ip_toUTF8,2); + rb_define_method(ip, "_fromUTF8",ip_fromUTF8,2); rb_define_method(ip, "_invoke", ip_invoke, -1); rb_define_method(ip, "_return_value", ip_retval, 0); rb_define_method(ip, "mainloop", lib_mainloop, 0); diff --git a/gc.c b/gc.c index d21d58b3fd..e6b001fca1 100644 --- a/gc.c +++ b/gc.c @@ -37,9 +37,9 @@ static void run_final(); #ifndef GC_MALLOC_LIMIT #if defined(MSDOS) || defined(__human68k__) -#define GC_MALLOC_LIMIT 200000 +#define GC_MALLOC_LIMIT 100000 #else -#define GC_MALLOC_LIMIT 400000 +#define GC_MALLOC_LIMIT 200000 #endif #endif @@ -55,12 +55,10 @@ xmalloc(size) ArgError("negative allocation size (or too big)"); } if (size == 0) size = 1; -#if 0 malloc_memories += size; if (malloc_memories > GC_MALLOC_LIMIT) { gc_gc(); } -#endif mem = malloc(size); if (!mem) { gc_gc(); @@ -95,6 +93,10 @@ xrealloc(ptr, size) ArgError("negative re-allocation size"); } if (!ptr) return xmalloc(size); + malloc_memories += size; + if (malloc_memories > GC_MALLOC_LIMIT) { + gc_gc(); + } mem = realloc(ptr, size); if (!mem) { gc_gc(); diff --git a/lib/matrix.rb b/lib/matrix.rb index 6639fe72ea..3924e93ecb 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -2,8 +2,8 @@ # # matrix.rb - # $Release Version: 1.0$ -# $Revision: 1.4 $ -# $Date: 1998/07/08 06:39:13 $ +# $Revision: 1.5 $ +# $Date: 1998/07/14 14:35:18 $ # Original Version from Smalltalk-80 version # on July 23, 1985 at 8:37:17 am # by Keiju ISHITSUKA @@ -180,8 +180,8 @@ module ExceptionForMatrix end class Matrix - @RCS_ID='-$Id: matrix.rb,v 1.4 1998/07/08 06:39:13 keiju Exp keiju $-' - + @RCS_ID='-$Id: matrix.rb,v 1.5 1998/07/14 14:35:18 keiju Exp keiju $-' + include ExceptionForMatrix # instance creations @@ -857,7 +857,7 @@ class Vector end def clone - Vector.elements(@rows) + Vector.elements(@elements) end def hash diff --git a/lib/pstore.rb b/lib/pstore.rb index 3f95e8c059..743b1da5d0 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -89,6 +89,9 @@ class PStore catch(:pstore_abort_transaction) do value = yield(self) end + rescue Exception + @abort = true + raise ensure unless @abort begin diff --git a/lib/tk.rb b/lib/tk.rb index 34f42ac390..87a5cf19cf 100644 --- a/lib/tk.rb +++ b/lib/tk.rb @@ -33,6 +33,8 @@ module TkComm return val.split.collect{|v| tk_tcl2ruby(v)} end case val + when /^@font/ + TkFont.get_obj(val) when /^-?\d+$/ val.to_i when /^\./ @@ -277,11 +279,11 @@ module TkComm end def _bind(path, context, cmd, args=nil) - _bind_core('', path, context, cmd, args=nil) + _bind_core('', path, context, cmd, args) end def _bind_append(path, context, cmd, args=nil) - _bind_core('+', path, context, cmd, args=nil) + _bind_core('+', path, context, cmd, args) end private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append @@ -412,6 +414,10 @@ module TkCore TclTkLib.mainloop end + def messageBox(keys) + tk_call 'tk_messageBox', *hash_kv(keys) + end + def tk_call(*args) print args.join(" "), "\n" if $DEBUG args.filter {|x|_get_eval_string(x)} @@ -443,6 +449,7 @@ module Tk TCL_VERSION = INTERP._invoke("info", "tclversion") TK_VERSION = INTERP._invoke("set", "tk_version") + JAPANIZED_TK = (INTERP._invoke("info", "commands", "kanji") != "") def root TkRoot.new @@ -452,6 +459,14 @@ module Tk tk_call 'bell' end + def toUTF8(str,encoding) + INTERP._toUTF8(str,encoding) + end + + def fromUTF8(str,encoding) + INTERP._fromUTF8(str,encoding) + end + module Scrollable def xscrollcommand(cmd=Proc.new) configure_cmd 'xscrollcommand', cmd @@ -1312,8 +1327,109 @@ module TkOption module_function :add, :clear, :get, :readfile end +module TkTreatFont + def font_configinfo + ret = TkFont.used_on(self.path) + if ret == nil + ret = TkFont.init_widget_font(self.path, self.path, 'configure') + end + ret + end + alias fontobj font_configinfo + + def font_configure(slot) + if (fnt = slot['font']) + slot['font'] = nil + if fnt.kind_of? TkFont + return fnt.call_font_configure(self.path, self.path,'configure',slot) + else + latinfont_configure(fnt) if fnt + end + end + if (ltn = slot['latinfont']) + slot['latinfont'] = nil + latinfont_configure(ltn) if ltn + end + if (ltn = slot['asciifont']) + slot['asciifont'] = nil + latinfont_configure(ltn) if ltn + end + if (knj = slot['kanjifont']) + slot['kanjifont'] = nil + kanjifont_configure(knj) if knj + end + + tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {} + self + end + + def latinfont_configure(ltn, keys=nil) + fobj = fontobj + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end + else + fobj.latin_replace(ltn) + end + end + alias asciifont_configure latinfont_configure + + def kanjifont_configure(knj, keys=nil) + fobj = fontobj + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(cond) + end + else + fobj.kanji_replace(knj) + end + end + + def font_copy(window, tag=nil) + if tag + window.tagfontobj(tag).configinfo.each{|key,value| + fontobj.configure(key,value) + } + fontobj.replace(window.tagfontobj(tag).latin_font, + window.tagfontobj(tag).kanji_font) + else + window.fontobj.configinfo.each{|key,value| + fontobj.configure(key,value) + } + fontobj.replace(window.fontobj.latin_font, window.fontobj.kanji_font) + end + end + + def latinfont_copy(window, tag=nil) + if tag + fontobj.latin_replace(window.tagfontobj(tag).latin_font) + else + fontobj.latin_replace(window.fontobj.latin_font) + end + end + alias asciifont_copy latinfont_copy + + def kanjifont_copy(window, tag=nil) + if tag + fontobj.kanji_replace(window.tagfontobj(tag).kanji_font) + else + fontobj.kanji_replace(window.fontobj.kanji_font) + end + end +end + class TkObjectvalue}) + else + tk_call path, 'configure', "-#{slot}", value + end + end end def configure_cmd(slot, value) @@ -1369,15 +1496,27 @@ class TkObject require "tk" +require 'tkfont' + +module TkTreatCItemFont + def tagfont_configinfo(tagOrId) + if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) + pathname = self.path + ';' + tagOrId.id.to_s + else + pathname = self.path + ';' + tagOrId.to_s + end + ret = TkFont.used_on(pathname) + if ret == nil + ret = TkFont.init_widget_font(pathname, + self.path, 'itemconfigure', tagOrId) + end + ret + end + alias tagfontobj tagfont_configinfo + + def tagfont_configure(tagOrId, slot) + if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) + pathname = self.path + ';' + tagOrId.id.to_s + else + pathname = self.path + ';' + tagOrId.to_s + end + if (fnt = slot['font']) + slot['font'] = nil + if fnt.kind_of? TkFont + return fnt.call_font_configure(pathname, + self.path,'itemconfigure',tagOrId,slot) + else + latintagfont_configure(tagOrId, fnt) if fnt + end + end + if (ltn = slot['latinfont']) + slot['latinfont'] = nil + latintagfont_configure(tagOrId, ltn) if ltn + end + if (ltn = slot['asciifont']) + slot['asciifont'] = nil + latintagfont_configure(tagOrId, ltn) if ltn + end + if (knj = slot['kanjifont']) + slot['kanjifont'] = nil + kanjitagfont_configure(tagOrId, knj) if knj + end + + tk_call(self.path, 'itemconfigure', tagOrId, *hash_kv(slot)) if slot != {} + self + end + + def latintagfont_configure(tagOrId, ltn, keys=nil) + fobj = tagfontobj(tagOrId) + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end + else + fobj.latin_replace(ltn) + end + end + alias asciitagfont_configure latintagfont_configure + + def kanjitagfont_configure(tagOrId, knj, keys=nil) + fobj = tagfontobj(tagOrId) + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(conf) + end + else + fobj.kanji_replace(knj) + end + end + + def tagfont_copy(tagOrId, window, wintag=nil) + if wintag + window.tagfontobj(wintag).configinfo.each{|key,value| + tagfontobj(tagOrId).configure(key,value) + } + tagfontobj(tagOrId).replace(window.tagfontobj(wintag).latin_font, + window.tagfontobj(wintag).kanji_font) + else + window.tagfont(tagOrId).configinfo.each{|key,value| + tagfontobj(tagOrId).configure(key,value) + } + tagfontobj(tagOrId).replace(window.fontobj.latin_font, + window.fontobj.kanji_font) + end + end + + def latintagfont_copy(tagOrId, window, wintag=nil) + if wintag + tagfontobj(tagOrId).latin_replace(window.tagfontobj(wintag).latin_font) + else + tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font) + end + end + alias asciitagfont_copy latintagfont_copy + + def kanjitagfont_copy(tagOrId, window, wintag=nil) + if wintag + tagfontobj(tagOrId).kanji_replace(window.tagfontobj(wintag).kanji_font) + else + tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font) + end + end +end class TkCanvasvalue}) + else + tk_call 'itemconfigure', tagid(tagOrId), "-#{key}", value + end end end +# def itemconfigure(tagOrId, key, value=None) +# if key.kind_of? Hash +# tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) +# else +# tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value +# end +# end # def itemconfigure(tagOrId, keys) # tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys) # end @@ -258,6 +392,7 @@ end module TkcTagAccess include TkComm + include TkTreatTagFont def addtag(tag) @c.addtag(tag, 'with', @id) @@ -286,8 +421,8 @@ module TkcTagAccess # @c.itemconfigure @id, keys # end - def configinfo - @c.itemconfigure @id + def configinfo(key=nil) + @c.itemconfiginfo @id, key end def coords(*args) @@ -494,7 +629,7 @@ class TkcItem@latinfont, 'kanjifont'=>@kanjifont} + if JAPANIZED_TK + @compoundfont = [[@latinfont], [@kanjifont]] + @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont} + else + @compoundfont = @latinfont + @fontslot = {'font'=>@latinfont} + end end - def create_latinfont_tk80(font=nil) + def create_latinfont_tk8x(font) @latinfont = @id + 'l' - if font.kind_of? Hash - tk_call('font', 'create', @latinfont, *hash_kv(font)) - elsif font.kind_of? Array - tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font)) - elsif font.kind_of? TkFont - tk_call('font', 'create', @latinfont, '-copy', font.latin_font) + if JAPANIZED_TK + if font.kind_of? Hash + tk_call('font', 'create', @latinfont, *hash_kv(font)) + elsif font.kind_of? Array + tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font)) + elsif font.kind_of? TkFont + tk_call('font', 'create', @latinfont, '-copy', font.latin_font) + else + tk_call('font', 'create', @latinfont, '-copy', font) + end else - tk_call('font', 'create', @latinfont, '-copy', font) + if font.kind_of? Hash + tk_call('font', 'create', @latinfont, *hash_kv(font)) + else + keys = {} + if font.kind_of? Array + actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} + elsif font.kind_of? TkFont + actual_core(font.latin_font).each{|key,val| keys[key] = val} + else + actual_core(font).each{|key,val| keys[key] = val} + end + tk_call('font', 'create', @latinfont, *hash_kv(keys)) + end end end - def create_kanjifont_tk80(font=nil) + def create_kanjifont_tk80(font) + unless JAPANIZED_TK + @kanjifont = "" + return + end + @kanjifont = @id + 'k' if font.kind_of? Hash @@ -202,20 +288,79 @@ class TkFont end end + def create_kanjifont_tk81(font) + @kanjifont = @id + 'k' + + if font.kind_of? Hash + tk_call('font', 'create', @kanjifont, *hash_kv(font)) + else + keys = {} + if font.kind_of? Array + actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} + elsif font.kind_of? TkFont + actual_core(font.kanji_font).each{|key,val| keys[key] = val} + else + actual_core(font).each{|key,val| keys[key] = val} + end + tk_call('font', 'create', @kanjifont, *hash_kv(keys)) + end + + keys = {} + actual_core(@kanjifont).each{|key,val| keys[key] = val} + begin + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) + rescue + end + end + def create_compoundfont_tk80(keys) @compoundfont = @id + 'c' - @fontslot = {'font'=>@compoundfont} - tk_call('font', 'create', @compoundfont, - '-compound', "#{@latinfont} #{@kanjifont}", *hash_kv(keys)) + if JAPANIZED_TK + @fontslot = {'font'=>@compoundfont} + tk_call('font', 'create', @compoundfont, + '-compound', "#{@latinfont} #{@kanjifont}", *hash_kv(keys)) + else + tk_call('font', 'create', @compoundfont) + latinkeys = {} + begin + actual_core(@latinfont).each{|key,val| latinkeys[key] = val} + rescue + latinkeys {} + end + if latinkeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) + end + @fontslot = {'font'=>@compoundfont} + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) + end end - def set_font_core_tk4x(window) - Tk_FontUseTBL[window.path] = @id - window.configure(@fontslot) - end + def create_compoundfont_tk81(keys) + @compoundfont = @id + 'c' + tk_call('font', 'create', @compoundfont) - def set_font_core_tk80(window) - window.configure(@fontslot) + latinkeys = {} + begin + actual_core(@latinfont).each{|key,val| latinkeys[key] = val} + rescue + latinkeys {} + end + if latinkeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys)) + end + + kanjikeys = {} + begin + actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val} + rescue + kanjikeys {} + end + if kanjikeys != {} + tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys)) + end + + @fontslot = {'font'=>@compoundfont} + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) end def actual_core_tk4x(font, window=nil, option=nil) @@ -229,7 +374,7 @@ class TkFont end end - def actual_core_tk80(font, window=nil, option=nil) + def actual_core_tk8x(font, window=nil, option=nil) if option == 'compound' "" elsif option @@ -271,7 +416,7 @@ class TkFont end end - def configure_core_tk80(font, slot, value=None) + def configure_core_tk8x(font, slot, value=None) if slot.kind_of? Hash tk_call 'font', 'configure', font, *hash_kv(slot) else @@ -279,7 +424,7 @@ class TkFont end end - def configinfo_core_tk80(font, option=nil) + def configinfo_core_tk8x(font, option=nil) if option == 'compound' "" elsif option @@ -300,12 +445,18 @@ class TkFont def latin_replace_core_tk4x(ltn) create_latinfont_tk4x(ltn) - @compoundfont[0] = [@latinfont] + @compoundfont[0] = [@latinfont] if JAPANIZED_TK @fontslot['font'] = @latinfont - Tk_FontUseTBL.dup.each{|w, id| - if id == @id + Tk_FontUseTBL.dup.each{|w, fobj| + if self == fobj begin - w.configure('font', @latinfont) + if w.include?(';') + win, tag = w.split(';') + winobj = tk_tcl2ruby(win) + winobj.tagfont_configure(tag, {'font'=>@latinfont}) + else + tk_tcl2ruby(w).configure('font', @latinfont) + end rescue Tk_FontUseTBL[w] = nil end @@ -315,13 +466,21 @@ class TkFont end def kanji_replace_core_tk4x(knj) + return self unless JAPANIZED_TK + create_kanjifont_tk4x(knj) @compoundfont[1] = [@kanjifont] @fontslot['kanjifont'] = @kanjifont - Tk_FontUseTBL.dup.each{|w, id| - if id == @id + Tk_FontUseTBL.dup.each{|w, fobj| + if self == fobj begin - w.configure('kanjifont', @kanjifont) + if w.include?(';') + win, tag = w.split(';') + winobj = tk_tcl2ruby(win) + winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont}) + else + tk_tcl2ruby(w).configure('kanjifont', @kanjifont) + end rescue Tk_FontUseTBL[w] = nil end @@ -330,15 +489,34 @@ class TkFont self end - def latin_replace_core_tk80(ltn) + def latin_replace_core_tk8x(ltn) tk_call('font', 'delete', @latinfont) - create_latinfont_tk80(ltn) + create_latinfont(ltn) self end def kanji_replace_core_tk80(knj) + return self unless JAPANIZED_TK + tk_call('font', 'delete', @kanjifont) - create_kanjifont_tk80(knj) + create_kanjifont(knj) + self + end + + def kanji_replace_core_tk81(knj) + if font.kind_of? Hash + tk_call('font', 'configure', @compoundfont, *hash_kv(font)) + else + keys = {} + if font.kind_of? Array + actual_core(array2tk_list(font)).each{|key,val| keys[key] = val} + elsif font.kind_of? TkFont + actual_core(font.latin_font).each{|key,val| keys[key] = val} + else + actual_core(font).each{|key,val| keys[key] = val} + end + tk_call('font', 'configure', @compoundfont, *hash_kv(keys)) + end self end @@ -346,7 +524,7 @@ class TkFont 0 end - def measure_core_tk80(window, text) + def measure_core_tk8x(window, text) if window number(tk_call('font', 'measure', @compoundfont, '-displayof', window, text)) @@ -364,7 +542,7 @@ class TkFont end end - def metrics_core_tk80(font, window, option=nil) + def metrics_core_tk8x(font, window, option=nil) if option if window number(tk_call('font', 'metrics', font, "-#{option}")) @@ -390,11 +568,10 @@ class TkFont # private alias ################################### case (Tk::TK_VERSION) - when /^4.*/ + when /^4\.*/ alias create_latinfont create_latinfont_tk4x alias create_kanjifont create_kanjifont_tk4x alias create_compoundfont create_compoundfont_tk4x - alias set_font_core set_font_core_tk4x alias actual_core actual_core_tk4x alias configure_core configure_core_tk4x alias configinfo_core configinfo_core_tk4x @@ -404,25 +581,77 @@ class TkFont alias metrics_core metrics_core_tk4x when /^8\.0/ - alias create_latinfont create_latinfont_tk80 + alias create_latinfont create_latinfont_tk8x alias create_kanjifont create_kanjifont_tk80 alias create_compoundfont create_compoundfont_tk80 - alias set_font_core set_font_core_tk80 - alias actual_core actual_core_tk80 - alias configure_core configure_core_tk80 - alias configinfo_core configinfo_core_tk80 - alias latin_replace_core latin_replace_core_tk80 + alias actual_core actual_core_tk8x + alias configure_core configure_core_tk8x + alias configinfo_core configinfo_core_tk8x + alias latin_replace_core latin_replace_core_tk8x alias kanji_replace_core kanji_replace_core_tk80 - alias measure_core measure_core_tk80 - alias metrics_core metrics_core_tk80 + alias measure_core measure_core_tk8x + alias metrics_core metrics_core_tk8x + + when /^8\.1/ + alias create_latinfont create_latinfont_tk8x + alias create_kanjifont create_kanjifont_tk81 + alias create_compoundfont create_compoundfont_tk81 + alias actual_core actual_core_tk8x + alias configure_core configure_core_tk8x + alias configinfo_core configinfo_core_tk8x + alias latin_replace_core latin_replace_core_tk8x + alias kanji_replace_core kanji_replace_core_tk81 + alias measure_core measure_core_tk8x + alias metrics_core metrics_core_tk8x end ################################### public ################################### - def set_font(window) - set_font_core(window) + def call_font_configure(path, *args) + args += hash_kv(args.pop.update(@fontslot)) + tk_call *args + Tk_FontUseTBL[path] = self + self + end + + def used + ret = [] + Tk_FontUseTBL.each{|key,value| + if key.include?(';') + win, tag = key.split(';') + winobj = tk_tcl2ruby(win) + if winobj.kind_of? TkText + ret.push([winobj, winobj.tagid2obj(tag)]) + elsif winobj.kind_of? TkCanvas + if (tagobj = TkcTag.id2obj(tag)).kind_of? TkcTag + ret.push([winobj, tagobj]) + elsif (tagobj = TkcItem.id2obj(tag)).kind_of? TkcItem + ret.push([winobj, tagobj]) + else + ret.push([winobj, tag]) + end + else + ret.push([win, tag]) + end + else + ret.push(tk_tcl2ruby(key)) if value == self + end + } + ret + end + + def id + @id + end + + def to_eval + font + end + + def font + @compoundfont end def latin_font @@ -452,12 +681,22 @@ class TkFont end def kanji_actual(option=nil) - actual_core(@kanjifont, nil, option) + #if JAPANIZED_TK + if @kanjifont != "" + actual_core(@kanjifont, nil, option) + else + actual_core_tk4x(nil, nil, option) + end end def kanji_actual_displayof(window, option=nil) - window = '.' unless window - actual_core(@kanjifont, window, option) + #if JAPANIZED_TK + if @kanjifont != "" + window = '.' unless window + actual_core(@kanjifont, window, option) + else + actual_core_tk4x(nil, window, option) + end end def [](slot) @@ -477,24 +716,45 @@ class TkFont end def latin_configure(slot, value=None) - configure_core(@latinfont, slot, value) + if JAPANIZED_TK + configure_core(@latinfont, slot, value) + else + configure(slot, value) + end end def latin_configinfo(slot=nil) - configinfo_core(@latinfont, slot) + if JAPANIZED_TK + configinfo_core(@latinfont, slot) + else + configure(slot, value) + end end def kanji_configure(slot, value=None) - configure_core(@kanjifont, slot, value) + #if JAPANIZED_TK + if @kanjifont != "" + configure_core(@kanjifont, slot, value) + else + #"" + configure(slot, value) + end end def kanji_configinfo(slot=nil) - configinfo_core(@kanjifont, slot) + #if JAPANIZED_TK + if @kanjifont != "" + configinfo_core(@kanjifont, slot) + else + #[] + configinfo(slot) + end end def replace(ltn, knj) latin_replace(ltn) - kanji_replace(ltn) + kanji_replace(knj) + self end def latin_replace(ltn) @@ -533,12 +793,20 @@ class TkFont end def kanji_metrics(option=nil) - metrics_core(@kanjifont, nil, option) + if JAPANIZED_TK + metrics_core(@kanjifont, nil, option) + else + metrics_core_tk4x(nil, nil, option) + end end def kanji_metrics_displayof(window, option=nil) - window = '.' unless window - metrics_core(@kanjifont, window, option) + if JAPANIZED_TK + window = '.' unless window + metrics_core(@kanjifont, window, option) + else + metrics_core_tk4x(nil, window, option) + end end ################################### @@ -554,3 +822,36 @@ class TkFont alias ascii_metrics latin_metrics end + +module TkTreatTagFont + def font_configinfo + @parent.tagfont_configinfo(@id) + end + alias font font_configinfo + + def font_configure(slot) + @parent.tagfont_configure(@id, slot) + end + + def latinfont_configure(ltn, keys=nil) + @parent.latintagfont_configure(@id, ltn, keys) + end + alias asciifont_configure latinfont_configure + + def kanjifont_configure(knj, keys=nil) + @parent.kanjitagfont_configure(@id, ltn, keys) + end + + def font_copy(window, wintag=nil) + @parent.tagfont_copy(@id, window, wintag) + end + + def latinfont_copy(window, wintag=nil) + @parent.latintagfont_copy(@id, window, wintag) + end + alias asciifont_copy latinfont_copy + + def kanjifont_copy(window, wintag=nil) + @parent.kanjitagfont_copy(@id, window, wintag) + end +end diff --git a/lib/tktext.rb b/lib/tktext.rb index 7b5cea5c72..8ffc626046 100644 --- a/lib/tktext.rb +++ b/lib/tktext.rb @@ -4,8 +4,124 @@ # by Yukihiro Matsumoto require 'tk.rb' +require 'tkfont' + +module TkTreatTextTagFont + def tagfont_configinfo(tag) + if tag.kind_of? TkTextTag + pathname = self.path + ';' + tag.id + else + pathname = self.path + ';' + tag + end + ret = TkFont.used_on(pathname) + if ret == nil + ret = TkFont.init_widget_font(pathname, + self.path, 'tag', 'configure', tag) + end + ret + end + alias tagfontobj tagfont_configinfo + + def tagfont_configure(tag, slot) + if tag.kind_of? TkTextTag + pathname = self.path + ';' + tag.id + else + pathname = self.path + ';' + tag + end + if (fnt = slot['font']) + slot['font'] = nil + if fnt.kind_of? TkFont + return fnt.call_font_configure(pathname, + self.path,'tag','configure',tag,slot) + else + latintagfont_configure(tag, fnt) if fnt + end + end + if (ltn = slot['latinfont']) + slot['latinfont'] = nil + latintagfont_configure(tag, ltn) if ltn + end + if (ltn = slot['asciifont']) + slot['asciifont'] = nil + latintagfont_configure(tag, ltn) if ltn + end + if (knj = slot['kanjifont']) + slot['kanjifont'] = nil + kanjitagfont_configure(tag, knj) if knj + end + + tk_call(self.path, 'tag', 'configure', tag, *hash_kv(slot)) if slot != {} + self + end + + def latintagfont_configure(tag, ltn, keys=nil) + fobj = tagfontobj(tag) + if ltn.kind_of? TkFont + conf = {} + ltn.latin_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.latin_configure(conf.update(keys)) + else + fobj.latin_configure(conf) + end + else + fobj.latin_replace(ltn) + end + end + alias asciitagfont_configure latintagfont_configure + + def kanjitagfont_configure(tag, knj, keys=nil) + fobj = tagfontobj(tag) + if knj.kind_of? TkFont + conf = {} + knj.kanji_configinfo.each{|key,val| conf[key] = val} + if keys + fobj.kanji_configure(conf.update(keys)) + else + fobj.kanji_configure(conf) + end + else + fobj.kanji_replace(knj) + end + end + + def tagfont_copy(tag, window, wintag=nil) + if wintag + window.tagfontobj(wintag).configinfo.each{|key,value| + tagfontobj(tag).configure(key,value) + } + tagfontobj(tag).replace(window.tagfontobj(wintag).latin_font, + window.tagfontobj(wintag).kanji_font) + else + window.tagfont(tag).configinfo.each{|key,value| + tagfontobj(tag).configure(key,value) + } + tagfontobj(tag).replace(window.fontobj.latin_font, + window.fontobj.kanji_font) + end + end + + def latintagfont_copy(tag, window, wintag=nil) + if wintag + tagfontobj(tag).latin_replace(window.tagfontobj(wintag).latin_font) + else + tagfontobj(tag).latin_replace(window.fontobj.latin_font) + end + end + alias asciitagfont_copy latintagfont_copy + + def kanjitagfont_copy(tag, window, wintag=nil) + if wintag + tagfontobj(tag).kanji_replace(window.tagfontobj(wintag).kanji_font) + else + tagfontobj(tag).kanji_replace(window.fontobj.kanji_font) + end + end +end class TkTextval}) + else + tk_call 'tag', 'configure', tag, "-#{key}", val + end end end - def configinfo(tag, key=nil) + def tag_configinfo(tag, key=nil) if key conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}")) conf[0] = conf[0][1..-1] @@ -296,21 +420,32 @@ class TkText (sizeof(VALUE)*CHAR_BIT-1) - || (unsigned long)val>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) { + || ((unsigned long)val)>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) { return big_lshift(int2big(val), y); } val = val << width; diff --git a/parse.y b/parse.y index 13b020406e..71d2f3787d 100644 --- a/parse.y +++ b/parse.y @@ -3436,7 +3436,7 @@ gettable(id) return NEW_LIT(INT2FIX(sourceline)); } else if (is_local_id(id)) { - if (dyna_var_defined(id)) return NEW_DVAR(id); + if (dyna_in_block() && dyna_var_defined(id)) return NEW_DVAR(id); if (local_id(id)) return NEW_LVAR(id); /* method call without arguments */ return NEW_VCALL(id); diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el index bfecb51214..94ac7d1799 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -47,8 +47,11 @@ ruby-block-end-re "\\)\\>\\|\\}\\|\\]\\)") ) -(defconst ruby-operator-chars "[,.+*/%-&|^~=<>:]") -(defconst ruby-symbol-chars "[a-zA-Z0-9_]") +(defconst ruby-operator-chars ",.+*/%-&|^~=<>:") +(defconst ruby-operator-re (concat "[" ruby-operator-chars "]")) + +(defconst ruby-symbol-chars "a-zA-Z0-9_") +(defconst ruby-symbol-re (concat "[" ruby-symbol-chars "]")) (defvar ruby-mode-abbrev-table nil "Abbrev table in use in ruby-mode buffers.") @@ -184,34 +187,29 @@ The variable ruby-indent-level controls the amount of indentation. (indent-to x) (move-to-column (+ x shift)))))) -(defun ruby-expr-beg (&optional modifier) +(defun ruby-expr-beg (&optional modifier pnt) (save-excursion (if (looking-at "\\?") (progn (or (bolp) (forward-char -1)) (not (looking-at "\\sw"))) + (store-match-data nil) (skip-chars-backward " \t") (or (bolp) (forward-char -1)) - (or (looking-at ruby-operator-chars) + (or (bolp) + (looking-at ruby-operator-re) (looking-at "[\\[({]") (and (not modifier) (looking-at "[!?]")) - (bolp) - (and (looking-at ruby-symbol-chars) + (and (looking-at ruby-symbol-re) (forward-word -1) - (or - (and (not modifier) (bolp)) - (looking-at ruby-block-beg-re) - (looking-at ruby-block-op-re) - (looking-at ruby-block-mid-re) - (and modifier - (save-excursion - (forward-char -1) - (let ((c (char-after (point)))) - (or (eq c ?.) - (eq c ? ) - (eq c ?\t)))))) - (goto-char (match-end 0)) - (looking-at "[^_]")))))) + (if (and (not modifier) (bolp)) + t + (if (or (looking-at ruby-block-beg-re) + (looking-at ruby-block-op-re) + (looking-at ruby-block-mid-re)) + (progn + (goto-char (match-end 0)) + (looking-at "[^_]"))))))))) (defun ruby-parse-region (start end) (let ((indent-point end) @@ -468,13 +466,13 @@ The variable ruby-indent-level controls the amount of indentation. (skip-chars-backward " \t") (or (bobp) (forward-char -1)) (and - (or (and (looking-at ruby-symbol-chars) + (or (and (looking-at ruby-symbol-re) (skip-chars-backward ruby-symbol-chars) (looking-at ruby-block-op-re) (save-excursion (goto-char (match-end 0)) (not (looking-at "[a-z_]")))) - (and (looking-at ruby-operator-chars) + (and (looking-at ruby-operator-re) (or (not (or (eq ?/ (char-after (point))))) (null (nth 0 (ruby-parse-region parse-start (point))))) (not (eq (char-after (1- (point))) ?$)) diff --git a/sprintf.c b/sprintf.c index 5817f19224..a907d1c9a2 100644 --- a/sprintf.c +++ b/sprintf.c @@ -612,9 +612,6 @@ fmt_setup(buf, c, flags, width, prec) int flags, width, prec; { *buf++ = '%'; - if (strchr("doOXx", c)) { - *buf++ = 'l'; - } if (flags & FSHARP) *buf++ = '#'; if (flags & FPLUS) *buf++ = '+'; if (flags & FMINUS) *buf++ = '-'; @@ -630,6 +627,9 @@ fmt_setup(buf, c, flags, width, prec) buf += strlen(buf); } + if (strchr("doOXx", c)) { + *buf++ = 'l'; + } *buf++ = c; *buf = '\0'; } diff --git a/variable.c b/variable.c index 7a827ed88b..c05853899e 100644 --- a/variable.c +++ b/variable.c @@ -650,7 +650,7 @@ rb_gvar_defined(entry) } static int -var_i(key, entry, ary) +gvar_i(key, entry, ary) ID key; struct global_entry *entry; VALUE ary; @@ -666,7 +666,7 @@ f_global_variables() char buf[4]; char *s = "&`'+123456789"; - st_foreach(global_tbl, var_i, ary); + st_foreach(global_tbl, gvar_i, ary); if (!NIL_P(backref_get())) { while (*s) { sprintf(buf, "$%c", *s++); @@ -757,6 +757,18 @@ rb_ivar_defined(obj, id) return FALSE; } +static int +ivar_i(key, entry, ary) + ID key; + struct global_entry *entry; + VALUE ary; +{ + if (rb_is_instance_id(key)) { + ary_push(ary, str_new2(rb_id2name(key))); + } + return ST_CONTINUE; +} + VALUE obj_instance_variables(obj) VALUE obj; @@ -769,7 +781,7 @@ obj_instance_variables(obj) case T_MODULE: ary = ary_new(); if (ROBJECT(obj)->iv_tbl) { - st_foreach(ROBJECT(obj)->iv_tbl, var_i, ary); + st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, ary); } return ary; } diff --git a/version.h b/version.h index d75ab4c314..16b65cd994 100644 --- a/version.h +++ b/version.h @@ -1,2 +1,2 @@ -#define RUBY_VERSION "1.1b9_30" -#define VERSION_DATE "98/07/09" +#define RUBY_VERSION "1.1b9_31" +#define VERSION_DATE "98/07/15" -- cgit v1.2.3