summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-03 07:06:51 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-07-03 07:06:51 +0000
commitab801dbdb7ff8a99b5e0976516b879b27bcf3e1b (patch)
tree2657a1ca78c166beda5dfb609f9c53c5bae6f85c
parent1a2003d1f176001f4c691d14a080e722bb12fc7b (diff)
1.1b9_29
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog37
-rw-r--r--MANIFEST1
-rw-r--r--bignum.c40
-rw-r--r--configure4
-rw-r--r--configure.in4
-rw-r--r--enum.c8
-rw-r--r--eval.c19
-rw-r--r--ext/socket/socket.c2
-rw-r--r--hash.c2
-rw-r--r--io.c34
-rw-r--r--lib/mkmf.rb2
-rw-r--r--lib/readbytes.rb36
-rw-r--r--lib/tk.rb82
-rw-r--r--lib/tkafter.rb76
-rw-r--r--lib/tkcanvas.rb560
-rw-r--r--lib/tkentry.rb24
-rw-r--r--lib/tktext.rb242
-rw-r--r--marshal.c23
-rw-r--r--missing/nt.h2
-rw-r--r--numeric.c130
-rw-r--r--object.c2
-rw-r--r--process.c31
-rw-r--r--sample/test.rb14
-rw-r--r--sprintf.c9
-rw-r--r--version.h4
25 files changed, 1037 insertions, 351 deletions
diff --git a/ChangeLog b/ChangeLog
index b9fbf551b4..53ec606730 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+Fri Jul 3 16:05:11 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * experimental release 1.1b9_29.
+
+Fri Jul 3 11:20:46 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * marshal.c (r_byte): byte should not extend sign bit.
+
+ * numeric.c (fix_mul): use FIX2LONG() instead of FIX2INT() for
+ 64bit architectures.
+
+ * marshal.c (r_bytes): use weird casting bwetween pointer and int.
+
+ * process.c (proc_setsid): new method Process#setsid().
+
+Thu Jul 2 12:49:21 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * marshal.c (w_object): remove `write_bignum' label for 64bit
+ architectures.
+
+ * marshal.c (r_bytes): needs int, not long.
+
+Wed Jul 1 14:21:06 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * numeric.c (flo_plus): should not allow addition with strings.
+
+Wed Jul 1 13:09:01 1998 Keiju ISHITSUKA <keiju@rational.com>
+
+ * numeric.c (num_uminus): wrong coerce direction.
+
+Tue Jun 30 10:13:44 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * io.c (f_p): accepts arbitrary number of arguments.
+
+ * eval.c (rb_yield_0): there's some case that iterator_p() returns
+ true even if the_block was not set. check added.
+
Tue Jun 30 01:05:20 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (BEGIN_CALLARGS): adjust the_block before evaluating the
diff --git a/MANIFEST b/MANIFEST
index 5863d5db70..199e11af99 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -115,6 +115,7 @@ lib/parsedate.rb
lib/ping.rb
lib/pstore.rb
lib/rational.rb
+lib/readbytes.rb
lib/shellwords.rb
lib/sync.rb
lib/telnet.rb
diff --git a/bignum.c b/bignum.c
index dc0c5492d1..ec16c991ea 100644
--- a/bignum.c
+++ b/bignum.c
@@ -20,7 +20,7 @@ typedef unsigned short USHORT;
#define BIGRAD (1L << BITSPERDIG)
#define DIGSPERINT ((unsigned int)(sizeof(long)/sizeof(short)))
#define BIGUP(x) ((unsigned int)(x) << BITSPERDIG)
-#define BIGDN(x) RSHIFT((x),BITSPERDIG)
+#define BIGDN(x) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>>BITSPERDIG)
#define BIGLO(x) ((x) & (BIGRAD-1))
static VALUE
@@ -61,7 +61,7 @@ big_2comp(x) /* get 2's complement */
while (i--) ds[i] = ~ds[i];
i = 0; num = 1;
do {
- num += (long)ds[i];
+ num += ds[i];
ds[i++] = BIGLO(num);
num = BIGDN(num);
} while (i < RBIGNUM(x)->len);
@@ -441,7 +441,7 @@ big_cmp(x, y)
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
break;
case T_BIGNUM:
@@ -585,7 +585,7 @@ bigadd(x, y, sign)
len = RBIGNUM(x)->len;
for (i = 0, num = 0; i < len; i++) {
- num += (long)(BDIGITS(x)[i] + BDIGITS(y)[i]);
+ num += BDIGITS(x)[i] + BDIGITS(y)[i];
BDIGITS(z)[i] = BIGLO(num);
num = BIGDN(num);
}
@@ -610,7 +610,7 @@ big_plus(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
/* fall through */
case T_BIGNUM:
return bigadd(x, y, 1);
@@ -629,7 +629,7 @@ big_minus(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
/* fall through */
case T_BIGNUM:
return bigadd(x, y, 0);
@@ -651,10 +651,10 @@ big_mul(x, y)
VALUE z;
USHORT *zds;
- if (FIXNUM_P(x)) x = int2big(FIX2INT(x));
+ if (FIXNUM_P(x)) x = int2big(FIX2LONG(x));
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
break;
case T_BIGNUM:
@@ -737,7 +737,7 @@ bigdivmod(x, y, div, mod, modulo)
j = 0;
num = 0;
while (j<ny) {
- num += (unsigned long)yds[j]*dd;
+ num += (long)yds[j]*dd;
tds[j++] = BIGLO(num);
num = BIGDN(num);
}
@@ -745,7 +745,7 @@ bigdivmod(x, y, div, mod, modulo)
j = 0;
num = 0;
while (j<nx) {
- num += (unsigned long)xds[j]*dd;
+ num += (long)xds[j]*dd;
zds[j++] = BIGLO(num);
num = BIGDN(num);
}
@@ -764,7 +764,7 @@ bigdivmod(x, y, div, mod, modulo)
i = 0; num = 0; t2 = 0;
do { /* multiply and subtract */
int ee;
- t2 += (unsigned long)yds[i] * q;
+ t2 += (long)yds[i] * q;
ee = num - BIGLO(t2);
num = zds[j - ny + i] + ee;
if (ee) zds[j - ny + i] = BIGLO(num);
@@ -827,7 +827,7 @@ big_div(x, y)
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
break;
case T_BIGNUM:
@@ -854,7 +854,7 @@ big_modulo(x, y, modulo)
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
break;
case T_BIGNUM:
@@ -894,7 +894,7 @@ big_divmod(x, y)
switch (TYPE(y)) {
case T_FIXNUM:
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
break;
case T_FLOAT:
@@ -931,8 +931,8 @@ big_pow(x, y)
break;
case T_FIXNUM:
- if (FIX2INT(y) > 0) goto pos_big;
- d = (double)FIX2INT(y);
+ if (FIX2LONG(y) > 0) goto pos_big;
+ d = (double)FIX2LONG(y);
break;
default:
@@ -964,7 +964,7 @@ big_and(x, y)
char sign;
if (FIXNUM_P(y)) {
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
}
else {
Check_Type(y, T_BIGNUM);
@@ -1015,7 +1015,7 @@ big_or(x, y)
char sign;
if (FIXNUM_P(y)) {
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
}
else {
Check_Type(y, T_BIGNUM);
@@ -1067,7 +1067,7 @@ big_xor(x, y)
char sign;
if (FIXNUM_P(y)) {
- y = int2big(FIX2INT(y));
+ y = int2big(FIX2LONG(y));
}
else {
Check_Type(y, T_BIGNUM);
@@ -1219,7 +1219,7 @@ big_coerce(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- return assoc_new(int2big(FIX2INT(y)), x);
+ return assoc_new(int2big(FIX2LONG(y)), x);
}
else {
TypeError("can't coerce %s to Bignum", rb_class2name(CLASS_OF(y)));
diff --git a/configure b/configure
index a8233bb955..00befc12b2 100644
--- a/configure
+++ b/configure
@@ -2694,7 +2694,7 @@ for ac_func in fmod killpg drand48 random wait4 waitpid syscall getcwd\
truncate chsize times utimes fcntl lockf setitimer\
setruid seteuid setreuid setrgid setegid setregid\
setpgrp2 getpgid getgroups getpriority\
- dlopen sigprocmask sigaction _setjmp setpgrp
+ dlopen sigprocmask sigaction _setjmp setpgrp setsid
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:2701: checking for $ac_func" >&5
@@ -3181,7 +3181,7 @@ else
int
main()
{
- if (-1==((-1)>>1))
+ if (-1==(-1>>1))
return 0;
return 1;
}
diff --git a/configure.in b/configure.in
index 9d5c4ccb5c..f1f7bd00fb 100644
--- a/configure.in
+++ b/configure.in
@@ -164,7 +164,7 @@ AC_CHECK_FUNCS(fmod killpg drand48 random wait4 waitpid syscall getcwd\
truncate chsize times utimes fcntl lockf setitimer\
setruid seteuid setreuid setrgid setegid setregid\
setpgrp2 getpgid getgroups getpriority\
- dlopen sigprocmask sigaction _setjmp setpgrp)
+ dlopen sigprocmask sigaction _setjmp setpgrp setsid)
if test "$ac_cv_func_strftime" = no; then
AC_STRUCT_TIMEZONE
AC_TRY_LINK([],
@@ -237,7 +237,7 @@ AC_CACHE_VAL(rb_cv_rshift_sign,
int
main()
{
- if (-1==((-1)>>1))
+ if (-1==(-1>>1))
return 0;
return 1;
}
diff --git a/enum.c b/enum.c
index 1e0ec9c30d..4cf490e4ca 100644
--- a/enum.c
+++ b/enum.c
@@ -198,7 +198,7 @@ min_i(i, min)
*min = i;
else {
cmp = rb_funcall(i, id_cmp, 1, *min);
- if (FIX2INT(cmp) < 0)
+ if (FIX2LONG(cmp) < 0)
*min = i;
}
return Qnil;
@@ -214,7 +214,7 @@ min_ii(i, min)
*min = i;
else {
cmp = rb_yield(assoc_new(i, *min));
- if (FIX2INT(cmp) < 0)
+ if (FIX2LONG(cmp) < 0)
*min = i;
}
return Qnil;
@@ -240,7 +240,7 @@ max_i(i, max)
*max = i;
else {
cmp = rb_funcall(i, id_cmp, 1, *max);
- if (FIX2INT(cmp) > 0)
+ if (FIX2LONG(cmp) > 0)
*max = i;
}
return Qnil;
@@ -256,7 +256,7 @@ max_ii(i, max)
*max = i;
else {
cmp = rb_yield(assoc_new(i, *max));
- if (FIX2INT(cmp) > 0)
+ if (FIX2LONG(cmp) > 0)
*max = i;
}
return Qnil;
diff --git a/eval.c b/eval.c
index f7852cbefb..a24ffc5872 100644
--- a/eval.c
+++ b/eval.c
@@ -981,27 +981,27 @@ ruby_run()
case TAG_RETURN:
error_pos();
- fprintf(stderr, "unexpected return\n");
+ fprintf(stderr, ": unexpected return\n");
exit(1);
break;
case TAG_NEXT:
error_pos();
- fprintf(stderr, "unexpected next\n");
+ fprintf(stderr, ": unexpected next\n");
exit(1);
break;
case TAG_BREAK:
error_pos();
- fprintf(stderr, "unexpected break\n");
+ fprintf(stderr, ": unexpected break\n");
exit(1);
break;
case TAG_REDO:
error_pos();
- fprintf(stderr, "unexpected redo\n");
+ fprintf(stderr, ": unexpected redo\n");
exit(1);
break;
case TAG_RETRY:
error_pos();
- fprintf(stderr, "retry outside of rescue clause\n");
+ fprintf(stderr, ": retry outside of rescue clause\n");
exit(1);
break;
case TAG_RAISE:
@@ -2340,6 +2340,9 @@ rb_eval(self, node)
VALUE origin;
int noex;
+ if (the_class == cObject && node->nd_mid == init) {
+ Warn("re-defining Object#initialize may cause infinite loop");
+ }
body = search_method(the_class, node->nd_mid, &origin);
if (body) {
if (origin == the_class) {
@@ -2844,7 +2847,7 @@ rb_yield_0(val, self)
int state;
static unsigned serial = 1;
- if (!iterator_p()) {
+ if (!iterator_p() || !the_block) {
Raise(eLocalJumpError, "yield called out of iterator");
}
@@ -6220,12 +6223,12 @@ thread_create(fn, arg)
tval.it_interval.tv_usec = 100000;
tval.it_value = tval.it_interval;
setitimer(ITIMER_VIRTUAL, &tval, NULL);
-
+#if 1
tval.it_interval.tv_sec = 2; /* unblock system calls */
tval.it_interval.tv_usec = 0;
tval.it_value = tval.it_interval;
setitimer(ITIMER_REAL, &tval, NULL);
-
+#endif
init = 1;
}
#endif
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 18ab8bc9f6..d235da1b83 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -1367,7 +1367,7 @@ sock_s_gethostbyaddr(argc, argv)
int alen;
struct hostent *h;
- rb_scan_args(argc, argv, "11", &addr, &vtype);
+ rb_scan_args(argc, argv, "11", &vaddr, &vtype);
addr = str2cstr(vaddr, &alen);
if (!NIL_P(vtype)) {
type = NUM2INT(vtype);
diff --git a/hash.c b/hash.c
index a1da061bd8..2c4616f2f0 100644
--- a/hash.c
+++ b/hash.c
@@ -103,7 +103,7 @@ any_hash(a, mod)
hval = rb_funcall(hval, '%', 1, INT2FIX(65439));
}
ENABLE_INTS;
- hval = FIX2INT(hval);
+ hval = FIX2LONG(hval);
}
return hval % mod;
}
diff --git a/io.c b/io.c
index 8349da0be8..826c0f0238 100644
--- a/io.c
+++ b/io.c
@@ -512,7 +512,10 @@ io_gets_method(argc, argv, io)
TRAP_BEG;
c = getc(f);
TRAP_END;
- if (c == EOF) break;
+ if (c == EOF) {
+ if (errno == EINTR) continue;
+ break;
+ }
if ((*bp++ = c) == newline) break;
if (bp == bpe) break;
}
@@ -599,7 +602,10 @@ io_gets(io)
TRAP_BEG;
c = getc(f);
TRAP_END;
- if (c == EOF) break;
+ if (c == EOF) {
+ if (errno == EINTR) continue;
+ break;
+ }
if ((*bp++ = c) == '\n') break;
if (bp == bpe) break;
}
@@ -1599,21 +1605,25 @@ f_puts(argc, argv)
return Qnil;
}
-static VALUE
-f_p(self, obj)
- VALUE self, obj;
+void
+rb_p(obj) /* for debug print within C code */
+ VALUE obj;
{
io_write(rb_defout, rb_inspect(obj));
io_write(rb_defout, RS_default);
-
- return Qnil;
}
-void
-rb_p(obj) /* for debug print within C code */
- VALUE obj;
+static VALUE
+f_p(argc, argv)
+ int argc;
+ VALUE *argv;
{
- f_p(0, obj);
+ int i;
+
+ for (i=0; i<argc; i++) {
+ rb_p(argv[i]);
+ }
+ return Qnil;
}
static VALUE
@@ -2607,7 +2617,7 @@ Init_IO()
rb_define_global_function("`", f_backquote, 1);
rb_define_global_function("pipe", io_s_pipe, 0);
- rb_define_global_function("p", f_p, 1);
+ rb_define_global_function("p", f_p, -1);
rb_define_method(mKernel, "display", obj_display, -1);
cIO = rb_define_class("IO", cObject);
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 306f23905b..c650b497df 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -263,7 +263,7 @@ hdrdir = #{$hdrdir}
CC = #{CONFIG["CC"]}
prefix = #{CONFIG["prefix"]}
-CFLAGS = #{CONFIG["CCDLFLAGS"]} -I#{$hdrdir} -I#{CONFIG["includedir"]} #{CFLAGS} #{$CFLAGS} #{$defs.join(" ")}
+CFLAGS = #{CONFIG["CCDLFLAGS"]} -I$(hdrdir) -I#{CONFIG["includedir"]} #{CFLAGS} #{$CFLAGS} #{$defs.join(" ")}
DLDFLAGS = #{$DLDFLAGS} #{$LDFLAGS}
LDSHARED = #{CONFIG["LDSHARED"]}
diff --git a/lib/readbytes.rb b/lib/readbytes.rb
new file mode 100644
index 0000000000..d6a3b10afe
--- /dev/null
+++ b/lib/readbytes.rb
@@ -0,0 +1,36 @@
+# readbytes.rb
+#
+# add IO#readbytes, which reads fixed sized data.
+# it guarantees read data size.
+
+class TruncatedDataError<IOError
+ def initialize(mesg, data)
+ @data = data
+ super(mesg)
+ end
+ attr_reader :data
+end
+
+class IO
+ def readbytes(n)
+ str = read(n)
+ if str == nil
+ raise EOFError, "End of file reached"
+ end
+ if str.size < n
+ raise TruncatedDataError.new("data truncated", str)
+ end
+ str
+ end
+end
+
+if __FILE__ == $0
+ begin
+ loop do
+ print STDIN.readbytes(6)
+ end
+ rescue TruncatedDataError
+ p $!.data
+ raise
+ end
+end
diff --git a/lib/tk.rb b/lib/tk.rb
index 204e22ac37..287bda62af 100644
--- a/lib/tk.rb
+++ b/lib/tk.rb
@@ -284,29 +284,6 @@ module TkComm
TkGrid.configure *args
end
- def after(ms, cmd=Proc.new)
- myid = _curr_cmd_id
- INTERP._eval('after '+ms+' '+_get_eval_string(install_cmd(proc{
- TkUtil.eval_cmd cmd
- uninstall_cmd myid
- })))
- return
- if false #defined? Thread
- Thread.start do
- ms = Float(ms)/1000
- ms = 10 if ms == 0
- sleep ms/1000
- cmd.call
- end
- else
- myid = _curr_cmd_id
- INTERP._eval('after '+ms+' '+_get_eval_string(install_cmd(proc{
- TkUtil.eval_cmd cmd
- uninstall_cmd myid
- })))
- end
- end
-
def update(idle=nil)
if idle
tk_call 'update', 'idletasks'
@@ -324,6 +301,24 @@ module TkCore
INTERP = TclTkIp.new
INTERP._invoke("proc", "rb_out", "args", "ruby [format \"TkCore.callback %%Q!%s!\" $args]")
+ def after(ms, cmd=Proc.new)
+ myid = _curr_cmd_id
+ cmdid = install_cmd(cmd)
+ tk_call("after",ms,cmdid)
+ return
+ if false #defined? Thread
+ Thread.start do
+ ms = Float(ms)/1000
+ ms = 10 if ms == 0
+ sleep ms/1000
+ cmd.call
+ end
+ else
+ cmdid = install_cmd(cmd)
+ tk_call("after",ms,cmdid)
+ end
+ end
+
def TkCore.callback(arg)
arg = Array(tk_split_list(arg))
_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg))
@@ -1029,13 +1024,12 @@ class TkObject<TkKernel
tk_tcl2ruby tk_call path, 'cget', "-#{slot}"
end
- def configure(slot, value)
- if value == FALSE
- value = "0"
- elsif value.kind_of? Proc
- value = install_cmd(value)
- end
- tk_call path, 'configure', "-#{slot}", value
+ def configure(slot, value=None)
+ if slot.kind_of? Hash
+ tk_call path, 'configure', *hash_kv(slot)
+ else
+ tk_call path, 'configure', "-#{slot}", value
+ end
end
def configure_cmd(slot, value)
@@ -1500,19 +1494,23 @@ module TkComposite
end
end
- def configure(slot, value)
- if @delegates and @delegates[slot]
- for i in @delegates[slot]
- if not i
- i = @delegates['DEFALUT']
- redo
- else
- last = i.configure(slot, value)
+ def configure(slot, value=None)
+ if slot.kind_of? Hash
+ slot.each{|slot,value| configure slot, value}
+ else
+ if @delegates and @delegates[slot]
+ for i in @delegates[slot]
+ if not i
+ i = @delegates['DEFALUT']
+ redo
+ else
+ last = i.configure(slot, value)
+ end
end
+ last
+ else
+ super
end
- last
- else
- super
end
end
end
@@ -1550,3 +1548,5 @@ autoload :TkEntry, 'tkentry'
autoload :TkText, 'tktext'
autoload :TkDialog, 'tkdialog'
autoload :TkMenubar, 'tkmenubar'
+autoload :TkAfter, 'tkafter'
+autoload :TkPalette, 'tkpalette'
diff --git a/lib/tkafter.rb b/lib/tkafter.rb
index 708d051002..23fc87dedb 100644
--- a/lib/tkafter.rb
+++ b/lib/tkafter.rb
@@ -1,6 +1,6 @@
#
# tkafter.rb : methods for Tcl/Tk after command
-# 1998/06/23 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
+# 1998/07/02 by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
#
require 'tk'
@@ -20,10 +20,9 @@ class TkAfter
@after_id = nil
arg = Array(tk_split_list(arg))
obj_id = arg.shift
- return nil if Tk_CBTBL[obj_id] == nil; # canceled
- ret = _get_eval_string(Tk_CBTBL[obj_id].do_callback(*arg))
- Tk_CBTBL[obj_id].set_next_callback(*arg)
- ret
+ ex_obj = Tk_CBTBL[obj_id]
+ return nil if ex_obj == nil; # canceled
+ _get_eval_string(ex_obj.do_callback(*arg))
end
def TkAfter.info
@@ -37,7 +36,15 @@ class TkAfter
# instance methods
###############################
def do_callback(*args)
- @current_proc.call(*args)
+ @in_callback = true
+ ret = @current_proc.call(*args)
+ if @set_next
+ set_next_callback(*args)
+ else
+ @set_next = true
+ end
+ @in_callback = false
+ ret
end
def set_callback(sleep, args=nil)
@@ -49,6 +56,7 @@ class TkAfter
def set_next_callback(*args)
if @running == false || @proc_max == 0 || @do_loop == 0
Tk_CBTBL[@id] = nil ;# for GC
+ @running = false
return
end
if @current_pos >= @proc_max
@@ -56,6 +64,7 @@ class TkAfter
@current_pos = 0
else
Tk_CBTBL[@id] = nil ;# for GC
+ @running = false
return
end
end
@@ -88,9 +97,11 @@ class TkAfter
@id = format("a%.4d", Tk_CBID[0])
Tk_CBID[0] += 1
- @init_sleep=0
- @init_proc=nil
- @init_args=[]
+ @set_next = true
+
+ @init_sleep = 0
+ @init_proc = nil
+ @init_args = []
@current_script = []
@current_proc = nil
@@ -188,37 +199,56 @@ class TkAfter
self
end
- def start(sleep=0, init_proc=nil, *init_args)
+ def set_start_proc(sleep, init_proc, *init_args)
+ if !sleep == 'idle' && !sleep.kind_of?(Integer)
+ fail format("%s need to be Integer", sleep.inspect)
+ end
+ @init_proc = init_proc
+ @init_args = init_args
+ self
+ end
+
+ def start(*init_args)
return nil if @running
Tk_CBTBL[@id] = self
@do_loop = @loop_exec
@current_pos = 0
- if !sleep == 'idle' && !sleep.kind_of?(Integer)
- fail format("%s need to be Integer", sleep.inspect)
+ argc = init_args.size
+ if argc > 0
+ sleep = init_args.shift
+ if !sleep == 'idle' && !sleep.kind_of?(Integer)
+ fail format("%s need to be Integer", sleep.inspect)
+ end
+ @init_sleep = sleep
end
+ @init_proc = init_args.shift if argc > 1
+ @init_args = init_args if argc > 0
- @init_proc = init_proc
- @init_args = init_args
- @current_sleep = @init_sleep = sleep
+ @current_sleep = @init_sleep
@running = true
- if init_proc
- if not init_proc.kind_of? Proc
- fail format("%s need to be Proc", init_proc.inspect)
+ if @init_proc
+ if not @init_proc.kind_of? Proc
+ fail format("%s need to be Proc", @init_proc.inspect)
end
- @current_proc = init_proc
- set_callback(sleep, init_args)
+ @current_proc = @init_proc
+ set_callback(sleep, @init_args)
+ @set_next = false if @in_callback
else
- set_next_callback(*init_args)
+ set_next_callback(*@init_args)
end
self
end
- def restart
+ def restart(*restart_args)
cancel if @running
- start(@init_sleep, @init_proc, @init_args)
+ if restart_args == []
+ start(@init_sleep, @init_proc, *@init_args)
+ else
+ start(*restart_args)
+ end
end
def cancel
diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb
index a02db097fd..1d4c4c583a 100644
--- a/lib/tkcanvas.rb
+++ b/lib/tkcanvas.rb
@@ -2,6 +2,8 @@
# tkcanvas.rb - Tk canvas classes
# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
+# $Date$
+# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
require "tk"
@@ -9,107 +11,224 @@ class TkCanvas<TkWindow
def create_self
tk_call 'canvas', path
end
+
def tagid(tag)
- if tag.kind_of?(TkcItem)
+ if tag.kind_of?(TkcItem) || tag.kind_of?(TkcTag)
tag.id
else
tag
end
end
private :tagid
- def addtag(tag, *args)
- tk_send 'addtag', tagid(tag), *args
+
+ def addtag(tag, mode, *args)
+ tk_send 'addtag', tagid(tag), mode, *args
end
- def addtag_above(tagOrId)
- addtag('above', tagOrId)
+ def addtag_above(tagOrId, target)
+ addtag(tagOrId, 'above', tagid(target))
end
- def addtag_all
- addtag('all')
+ def addtag_all(tagOrId)
+ addtag(tagOrId, 'all')
end
- def addtag_below(tagOrId)
- addtag('below', tagOrId)
+ def addtag_below(tagOrId, target)
+ addtag(tagOrId, 'below', tagid(target))
end
- def addtag_closest(x, y, halo=None, start=None)
- addtag('closest', x, y, halo, start)
+ def addtag_closest(tagOrId, x, y, halo=None, start=None)
+ addtag(tagOrId, 'closest', x, y, halo, start)
end
- def addtag_enclosed(x1, y1, x2, y2)
- addtag('enclosed', x1, y1, x2, y2)
+ def addtag_enclosed(tagOrId, x1, y1, x2, y2)
+ addtag(tagOrId, 'enclosed', x1, y1, x2, y2)
end
- def addtag_overlapping(x1, y1, x2, y2)
- addtag('overlapping', x1, y1, x2, y2)
+ def addtag_overlapping(tagOrId, x1, y1, x2, y2)
+ addtag(tagOrId, 'overlapping', x1, y1, x2, y2)
end
- def addtag_withtag(tagOrId)
- addtag('withtag', tagOrId)
+ def addtag_withtag(tagOrId, tag)
+ addtag(tagOrId, 'withtag', tagid(tag))
end
- def bbox(tag)
- list(tk_send('bbox', tagid(tag)))
+
+ def bbox(tagOrId, *tags)
+ list(tk_send('bbox', tagid(tagOrId), *tags))
end
- def itembind(tag, seq, cmd=Proc.new)
- id = install_cmd(cmd)
- tk_send 'bind', tagid(tag), "<#{seq}>", id
- @cmdtbl.push id
+
+ def itembind(tag, context, cmd=Proc.new, args=nil)
+ context = context.join("><") if context.kind_of? Array
+ if /,/ =~ context
+ context = context.split(/\s*,\s*/).join("><")
+ end
+ id = install_bind(cmd, args)
+ begin
+ tk_send 'bind', tagid(tag), "<#{context}>", id
+ rescue
+ uninstall_cmd(cmd)
+ fail
+ end
+ # @cmdtbl.push id
end
+
def canvasx(x, *args)
- tk_send 'canvasx', x, *args
+ tk_tcl2ruby(tk_send 'canvasx', x, *args)
end
def canvasy(y, *args)
- tk_send 'canvasy', y, *args
+ tk_tcl2ruby(tk_send 'canvasy', y, *args)
end
+
def coords(tag, *args)
- tk_send 'coords', tagid(tag), *args
+ if args == []
+ tk_split_list(tk_send('coords', tagid(tag)))
+ else
+ tk_send('coords', tagid(tag), *args)
+ end
end
+
def dchars(tag, first, last=None)
tk_send 'dchars', tagid(tag), first, last
end
+
def delete(*args)
tk_send 'delete', *args
end
alias remove delete
+
def dtag(tag, tag_to_del=None)
tk_send 'dtag', tagid(tag), tag_to_del
end
- def find(*args)
- tk_send 'find', *args
+
+ def find(mode, *args)
+ list(tk_send 'find', mode, *args).filter{|id|
+ TkcItem.id2obj(id)
+ }
+ end
+ def find_above(target)
+ find('above', tagid(target))
+ end
+ def find_all
+ find('all')
+ end
+ def find_below(target)
+ find('below', tagid(target))
+ end
+ def find_closest(x, y, halo=None, start=None)
+ find('closest', x, y, halo, start)
+ end
+ def find_enclosed(x1, y1, x2, y2)
+ find('enclosed', x1, y1, x2, y2)
+ end
+ def find_overlapping(x1, y1, x2, y2)
+ find('overlapping', x1, y1, x2, y2)
+ end
+ def find_withtag(tag)
+ find('withtag', tag)
+ end
+
+ def itemfocus(tagOrId=nil)
+ if tagOrId
+ tk_send 'focus', tagid(tagOrId)
+ else
+ ret = tk_send('focus')
+ if ret == ""
+ nil
+ else
+ TkcItem.id2obj(ret)
+ end
+ end
+ end
+
+ def gettags(tagOrId)
+ list(tk_send('gettags', tagid(tagOrId))).collect{|tag|
+ TkcTag.id2obj(tag)
+ }
+ end
+
+ def icursor(tagOrId, index)
+ tk_send 'icursor', tagid(tagOrId), index
+ end
+
+ def index(tagOrId, index)
+ tk_send 'index', tagid(tagOrId), index
end
- def itemfocus(tag)
- tk_send 'find', tagid(tag)
+
+ def insert(tagOrId, index, string)
+ tk_send 'insert', tagid(tagOrId), index, string
end
- def gettags(tag)
- tk_send 'gettags', tagid(tag)
+
+ def itemcget(tagOrId, option)
+ tk_send 'itemcget', tagid(tagOrId), option
end
- def icursor(tag, index)
- tk_send 'icursor', tagid(tag), index
+
+ 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 index(tag)
- tk_send 'index', tagid(tag), index
+# def itemconfigure(tagOrId, keys)
+# tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys)
+# end
+
+ def itemconfiginfo(tagOrId, key=nil)
+ if key
+ conf = tk_split_list(tk_send 'itemconfigure', tagid(tagOrId), "-#{key}")
+ conf[0] = conf[0][1..-1]
+ conf
+ else
+ tk_split_list(tk_send 'itemconfigure', tagid(tagOrId)).collect{|conf|
+ conf[0] = conf[0][1..-1]
+ conf
+ }
+ end
end
- def lower(tag, below=None)
+
+ def lower(tag, below=None)
tk_send 'lower', tagid(tag), below
end
+
def move(tag, x, y)
tk_send 'move', tagid(tag), x, y
end
- def itemtype(tag)
- tk_send 'type', tagid(tag)
- end
+
def postscript(keys)
tk_send "postscript", *hash_kv(keys)
end
+
def raise(tag, above=None)
tk_send 'raise', tagid(tag), above
end
+
def scale(tag, x, y, xs, ys)
tk_send 'scale', tagid(tag), x, y, xs, ys
end
+
def scan_mark(x, y)
tk_send 'scan', 'mark', x, y
end
def scan_dragto(x, y)
tk_send 'scan', 'dragto', x, y
end
- def select(*args)
- tk_send 'select', *args
+
+ def select(mode, *args)
+ tk_send 'select', mode, *args
+ end
+ def select_adjust(tagOrId, index)
+ select('adjust', tagid(tagOrId), index)
+ end
+ def select_clear
+ select('clear')
+ end
+ def select_from(tagOrId, index)
+ select('from', tagid(tagOrId), index)
+ end
+ def select_item
+ select('item')
end
+ def select_to(tagOrId, index)
+ select('to', tagid(tagOrId), index)
+ end
+
+ def itemtype(tag)
+ TkcItem.type2class(tk_send 'type', tagid(tag))
+ end
+
def xview(*index)
tk_send 'xview', *index
end
@@ -118,168 +237,337 @@ class TkCanvas<TkWindow
end
end
-class TkcItem<TkObject
- def initialize(parent, *args)
- if not parent.kind_of?(TkCanvas)
- fail format("%s need to be TkCanvas", parent.inspect)
- end
- @c = parent
- @path = parent.path
- if args[-1].kind_of? Hash
- keys = args.pop
- end
- @id = create_self(*args)
- if keys
- tk_call @path, 'itemconfigure', @id, *hash_kv(keys)
- end
+module TkcTagAccess
+ include TkComm
+
+ def addtag(tag)
+ @c.addtag(tag, 'with', @id)
end
- def create_self(*args) end
- private :create_self
- def id
- return @id
+
+ def bbox
+ @c.bbox(@id)
end
- def configure(slot, value)
- tk_call path, 'itemconfigure', @id, "-#{slot}", value
+ def bind(seq, cmd=Proc.new, args=nil)
+ @c.itembind @id, seq, cmd, args
end
- def addtag(tag)
- @c.addtag(tag, 'withtag', @id)
+ def cget(option)
+ @c.itemcget @id, option
end
- def bbox
- @c.bbox(@id)
+
+ def configure(key, value=None)
+ @c.itemconfigure @id, key, value
end
- def bind(seq, cmd=Proc.new)
- @c.itembind @id, seq, cmd
+# def configure(keys)
+# @c.itemconfigure @id, keys
+# end
+
+ def configinfo
+ @c.itemconfigure @id
end
+
def coords(*args)
@c.coords @id, *args
end
+
def dchars(first, last=None)
@c.dchars @id, first, last
end
- def dtag(ttd)
- @c.dtag @id, ttd
+
+ def dtag(tag_to_del=None)
+ @c.dtag @id, tag_to_del
+ end
+
+ def find
+ @c.find 'withtag', @id
end
+ alias list find
+
def focus
- @c.focus @id
+ @c.itemfocus @id
end
+
def gettags
@c.gettags @id
end
- def icursor
- @c.icursor @id
+
+ def icursor(index)
+ @c.icursor @id, index
end
- def index
- @c.index @id
+
+ def index(index)
+ @c.index @id, index
end
+
def insert(beforethis, string)
@c.insert @id, beforethis, string
end
+
def lower(belowthis=None)
@c.lower @id, belowthis
end
+
def move(xamount, yamount)
@c.move @id, xamount, yamount
end
+
def raise(abovethis=None)
@c.raise @id, abovethis
end
+
def scale(xorigin, yorigin, xscale, yscale)
@c.scale @id, xorigin, yorigin, xscale, yscale
end
+
+ def select_adjust(index)
+ @c.select('adjust', @id, index)
+ end
+ def select_from(index)
+ @c.select('from', @id, index)
+ end
+ def select_to(index)
+ @c.select('to', @id, index)
+ end
+
def itemtype
@c.itemtype @id
end
- def destroy
- tk_call path, 'delete', @id
+end
+
+class TkcTag<TkObject
+ include TkcTagAccess
+
+ CTagID_TBL = {}
+
+ def TkcTag.id2obj(id)
+ CTagID_TBL[id]? CTagID_TBL[id]: id
+ end
+
+ $tk_canvas_tag = 'ctag0000'
+ def initialize(parent, mode=nil, *args)
+ if not parent.kind_of?(TkCanvas)
+ fail format("%s need to be TkCanvas", parent.inspect)
+ end
+ @c = parent
+ @path = @id = $tk_canvas_tag
+ CTagID_TBL[@id] = self
+ $tk_canvas_tag = $tk_canvas_tag.succ
+ if mode
+ tk_call @c.path, "addtag", @id, mode, *args
+ end
end
+ def id
+ return @id
+ end
+
+ def delete
+ @c.delete @id
+ CTagID_TBL[@id] = nil
+ end
+ alias remove delete
+ alias destroy delete
+
+ def set_to_above(target)
+ @c.addtag_above(@id, target)
+ end
+ alias above set_to_above
+
+ def set_to_all
+ @c.addtag_all(@id)
+ end
+ alias all set_to_all
+
+ def set_to_below(target)
+ @c.addtag_below(@id, target)
+ end
+ alias below set_to_below
+
+ def set_to_closest(x, y, halo=None, start=None)
+ @c.addtag_closest(@id, x, y, halo, start)
+ end
+ alias closest set_to_closest
+
+ def set_to_enclosed(x1, y1, x2, y2)
+ @c.addtag_enclosest(@id, x1, y1, x2, y2)
+ end
+ alias enclosed set_to_enclosed
+
+ def set_to_overlapping(x1, y1, x2, y2)
+ @c.addtag_overlapping(@id, x1, y1, x2, y2)
+ end
+ alias overlapping set_to_overlapping
+
+ def set_to_withtag(target)
+ @c.addtag_withtag(@id, target)
+ end
+ alias withtag set_to_withtag
+end
+
+class TkcTagAll<TkcTag
+ def initialize(parent)
+ if not parent.kind_of?(TkCanvas)
+ fail format("%s need to be TkCanvas", parent.inspect)
+ end
+ @c = parent
+ @path = @id = 'all'
+ CTagID_TBL[@id] = self
+ end
+end
+
+class TkcTagCurrent<TkcTag
+ def initialize(parent)
+ if not parent.kind_of?(TkCanvas)
+ fail format("%s need to be TkCanvas", parent.inspect)
+ end
+ @c = parent
+ @path = @id = 'current'
+ CTagID_TBL[@id] = self
+ end
+end
+
+class TkcGroup<TkcTag
+ $tk_group_id = 'tkg00000'
+ def create_self(parent, *args)
+ if not parent.kind_of?(TkCanvas)
+ fail format("%s need to be TkCanvas", parent.inspect)
+ end
+ @c = parent
+ @path = @id = $tk_group_id
+ CTagID_TBL[@id] = self
+ $tk_group_id = $tk_group_id.succ
+ add(*args) if args != []
+ end
+
+ def include(*tags)
+ for i in tags
+ i.addtag @id
+ end
+ end
+
+ def exclude(*tags)
+ for i in tags
+ i.delete @id
+ end
+ end
+end
+
+
+class TkcItem<TkObject
+ include TkcTagAccess
+
+ CItemTypeToClass = {}
+ CItemID_TBL = {}
+
+ def TkcItem.type2class(type)
+ CItemTypeToClass[type]
+ end
+
+ def TkcItem.id2obj(id)
+ CItemID_TBL[id]? CItemID_TBL[id]: id
+ end
+
+ def initialize(parent, *args)
+ if not parent.kind_of?(TkCanvas)
+ fail format("%s need to be TkCanvas", parent.inspect)
+ end
+ @c = parent
+ @path = parent.path
+ if args[-1].kind_of? Hash
+ keys = args.pop
+ end
+ @id = create_self(*args).to_i ;# 'canvas item id' is integer number
+ CItemID_TBL[@id] = self
+ if keys
+ tk_call @path, 'itemconfigure', @id, *hash_kv(keys)
+ end
+ end
+ def create_self(*args); end
+ private :create_self
+ def id
+ return @id
+ end
+
+ def delete
+ @c.delete @id
+ CItemID_TBL[@id] = nil
+ end
+ alias remove delete
+ alias destroy delete
end
class TkcArc<TkcItem
+ CItemTypeToClass['arc'] = self
def create_self(*args)
tk_call(@path, 'create', 'arc', *args)
end
end
class TkcBitmap<TkcItem
+ CItemTypeToClass['bitmap'] = self
def create_self(*args)
tk_call(@path, 'create', 'bitmap', *args)
end
end
class TkcImage<TkcItem
+ CItemTypeToClass['image'] = self
def create_self(*args)
tk_call(@path, 'create', 'image', *args)
end
end
class TkcLine<TkcItem
+ CItemTypeToClass['line'] = self
def create_self(*args)
tk_call(@path, 'create', 'line', *args)
end
end
class TkcOval<TkcItem
+ CItemTypeToClass['oval'] = self
def create_self(*args)
tk_call(@path, 'create', 'oval', *args)
end
end
class TkcPolygon<TkcItem
+ CItemTypeToClass['polygon'] = self
def create_self(*args)
tk_call(@path, 'create', 'polygon', *args)
end
end
class TkcRectangle<TkcItem
+ CItemTypeToClass['rectangle'] = self
def create_self(*args)
tk_call(@path, 'create', 'rectangle', *args)
end
end
class TkcText<TkcItem
+ CItemTypeToClass['text'] = self
def create_self(*args)
tk_call(@path, 'create', 'text', *args)
end
end
class TkcWindow<TkcItem
+ CItemTypeToClass['window'] = self
def create_self(*args)
tk_call(@path, 'create', 'window', *args)
end
end
-class TkcGroup<TkcItem
- $tk_group_id = 'tkg00000'
- def create_self(*args)
- @id = $tk_group_id
- $tk_group_id = $tk_group_id.succ
- end
-
- def add(*tags)
- for i in tags
- i.addtag @id
- end
- end
- def add(*tags)
- for i in tags
- i.addtag @id
- end
- end
- def delete(*tags)
- for i in tags
- i.delete @id
- end
- end
- def list
- @c.find 'withtag', @id
- end
- alias remove delete
-end
-
class TkImage<TkObject
include Tk
+ Tk_IMGTBL = {}
+
$tk_image_id = 'i00000'
def initialize(keys=nil)
@path = $tk_image_id
$tk_image_id = $tk_image_id.succ
tk_call 'image', 'create', @type, @path, *hash_kv(keys)
+ Tk_IMGTBL[@path] = self
end
+ def delete
+ Tk_IMGTBL[@id] = nil if @id
+ tk_call('image', 'delete', @path)
+ end
def height
number(tk_call('image', 'height', @path))
end
@@ -291,10 +579,13 @@ class TkImage<TkObject
end
def TkImage.names
- tk_call('image', 'names', @path).split
+ Tk.tk_call('image', 'names').split.filter{|id|
+ (Tk_IMGTBL[id])? Tk_IMGTBL[id] : id
+ }
end
+
def TkImage.types
- tk_call('image', 'types', @path).split
+ Tk.tk_call('image', 'types').split
end
end
@@ -314,13 +605,60 @@ class TkPhotoImage<TkImage
def blank
tk_send 'blank'
end
- def cget
- tk_send 'cget'
+
+ def cget(option)
+ tk_send 'cget', option
end
+
+ def copy(source, *opts)
+ args = opts.collect{|term|
+ if term.kind_of?(String) && term.include?(?\s)
+ term.split
+ else
+ term
+ end
+ }.flatten
+
+ tk_send 'copy', source, *args
+ end
+
def get(x, y)
tk_send 'get', x, y
end
- def put(data, to=None)
- tk_send 'put', data, to
+
+ def put(data, *to)
+ if to == []
+ tk_send 'put', data
+ else
+ tk_send 'put', data, '-to', *to
+ end
+ end
+
+ def read(file, *opts)
+ args = opts.collect{|term|
+ if term.kind_of?(String) && term.include?(?\s)
+ term.split
+ else
+ term
+ end
+ }.flatten
+
+ tk_send 'read', file, *args
+ end
+
+ def redither
+ tk_send 'redither'
+ end
+
+ def write(file, *opts)
+ args = opts.collect{|term|
+ if term.kind_of?(String) && term.include?(?\s)
+ term.split
+ else
+ term
+ end
+ }.flatten
+
+ tk_send 'write', file, *args
end
end
diff --git a/lib/tkentry.rb b/lib/tkentry.rb
index bcf092a15c..645fc997b1 100644
--- a/lib/tkentry.rb
+++ b/lib/tkentry.rb
@@ -35,23 +35,23 @@ class TkEntry<TkLabel
def dragto(pos)
tk_send 'scan', 'dragto', pos
end
- def select_adjust(index)
- tk_send 'select', 'adjust', index
+ def selection_adjust(index)
+ tk_send 'selection', 'adjust', index
end
- def select_clear
- tk_send 'select', 'clear', 'end'
+ def selection_clear
+ tk_send 'selection', 'clear', 'end'
end
- def select_from(index)
- tk_send 'select', 'from', index
+ def selection_from(index)
+ tk_send 'selection', 'from', index
end
- def select_present()
- tk_send('select', 'present') == 1
+ def selection_present()
+ tk_send('selection', 'present') == 1
end
- def select_range(s, e)
- tk_send 'select', 'range', s, e
+ def selection_range(s, e)
+ tk_send 'selection', 'range', s, e
end
- def select_to(index)
- tk_send 'select', 'to', index
+ def selection_to(index)
+ tk_send 'selection', 'to', index
end
def xview(*index)
tk_send 'xview', *index
diff --git a/lib/tktext.rb b/lib/tktext.rb
index 146944dde7..74fec8c953 100644
--- a/lib/tktext.rb
+++ b/lib/tktext.rb
@@ -15,19 +15,19 @@ class TkText<TkTextWin
tk_send 'index', index
end
def value
- tk_send 'get', "1.0", "end"
+ tk_send 'get', "1.0", "end - 1 char"
end
def value= (val)
tk_send 'delete', "1.0", 'end'
tk_send 'insert', "1.0", val
end
def _addcmd(cmd)
- @cmdtbl.push id
+ @cmdtbl.push cmd
end
def _addtag(name, obj)
@tags[name] = obj
end
- def tag_names(index=nil)
+ def tag_names(index=None)
tk_split_list(tk_send('tag', 'names', index)).collect{|elt|
if not @tags[elt]
elt
@@ -110,6 +110,168 @@ class TkText<TkTextWin
def xview_pickplace(*what)
tk_send 'xview', '-pickplace', *what
end
+
+ def tag_add(tag,index1,index2=None)
+ tk_send 'tag', 'add', tag, index1, index2
+ end
+
+ def tag_bind(tag, seq, cmd=Proc.new, args=nil)
+ seq = context.join("><") if seq.kind_of? Array
+ if /,/ =~ seq
+ seq = seq.split(/\s*,\s*/).join("><")
+ end
+ id = install_bind(cmd, args)
+ tk_send 'tag', 'bind', tag, "<#{seq}>", id
+ # _addcmd cmd
+ end
+
+ def tag_bindinfo(tag)
+ tk_split_list(tk_send('tag', 'bind', tag)).filter{|seq|
+ seq.tr('<>',' ').strip.gsub(/\s+/,',')
+ }
+ end
+
+ def tag_cget(tag, key)
+ tk_call @t.path, 'tag', 'cget', tag, "-#{key}"
+ end
+
+ def tag_configure(tag, key, val=None)
+ if key.kind_of? Hash
+ tk_send 'tag', 'configure', tag, *hash_kv(key)
+ else
+ tk_send 'tag', 'configure', tag, "-#{key}", val
+ end
+ end
+
+ def configinfo(tag, key=nil)
+ if key
+ conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}"))
+ conf[0] = conf[0][1..-1]
+ conf
+ else
+ tk_split_list(tk_send('tag', 'configure', tag)).collect{|conf|
+ conf[0] = conf[0][1..-1]
+ conf
+ }
+ end
+ end
+
+ def tag_raise(tag, above=None)
+ tk_send 'tag', 'raise', tag, above
+ end
+
+ def tag_lower(tag, below=None)
+ tk_send 'tag', 'lower', tag, below
+ end
+
+ def tag_remove(tag, *index)
+ tk_send 'tag', 'remove', tag, *index
+ end
+
+ def tag_ranges(tag)
+ l = tk_split_list(tk_send('tag', 'ranges', tag))
+ r = []
+ while key=l.shift
+ r.push [key, l.shift]
+ end
+ r
+ end
+
+ def tag_nextrange(tag, first, last=None)
+ tk_split_list(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))
+ end
+
+ def search_with_length(pat,start,stop=None)
+ pat = pat.char if pat.kind_of? Integer
+ if stop != None
+ return ["", 0] if compare(start,'>=',stop)
+ txt = get(start,stop)
+ if (pos = txt.index(pat))
+ pos = txt[0..(pos-1)].split('').length if pos > 0
+ if pat.kind_of? String
+ return [index(start + " + #{pos} chars"), pat.split('').length]
+ else
+ return [index(start + " + #{pos} chars"), $&.split('').length]
+ end
+ else
+ return ["", 0]
+ end
+ else
+ txt = get(start,'end - 1 char')
+ if (pos = txt.index(pat))
+ pos = txt[0..(pos-1)].split('').length if pos > 0
+ if pat.kind_of? String
+ return [index(start + " + #{pos} chars"), pat.split('').length]
+ else
+ return [index(start + " + #{pos} chars"), $&.split('').length]
+ end
+ else
+ txt = get('1.0','end - 1 char')
+ if (pos = txt.index(pat))
+ pos = txt[0..(pos-1)].split('').length if pos > 0
+ if pat.kind_of? String
+ return [index("1.0 + #{pos} chars"), pat.split('').length]
+ else
+ return [index("1.0 + #{pos} chars"), $&.split('').length]
+ end
+ else
+ return ["", 0]
+ end
+ end
+ end
+ end
+
+ def search(pat,start,stop=None)
+ search_with_length(pat,start,stop)[0]
+ end
+
+ def rsearch_with_length(pat,start,stop=None)
+ pat = pat.char if pat.kind_of? Integer
+ if stop != None
+ return ["", 0] if compare(start,'<=',stop)
+ txt = get(stop,start)
+ if (pos = txt.rindex(pat))
+ pos = txt[0..(pos-1)].split('').length if pos > 0
+ if pat.kind_of? String
+ return [index(stop + " + #{pos} chars"), pat.split('').length]
+ else
+ return [index(stop + " + #{pos} chars"), $&.split('').length]
+ end
+ else
+ return ["", 0]
+ end
+ else
+ txt = get('1.0',start)
+ if (pos = txt.rindex(pat))
+ pos = txt[0..(pos-1)].split('').length if pos > 0
+ if pat.kind_of? String
+ return [index("1.0 + #{pos} chars"), pat.split('').length]
+ else
+ return [index("1.0 + #{pos} chars"), $&.split('').length]
+ end
+ else
+ txt = get('1.0','end - 1 char')
+ if (pos = txt.rindex(pat))
+ pos = txt[0..(pos-1)].split('').length if pos > 0
+ if pat.kind_of? String
+ return [index("1.0 + #{pos} chars"), pat.split('').length]
+ else
+ return [index("1.0 + #{pos} chars"), $&.split('').length]
+ end
+ else
+ return ["", 0]
+ end
+ end
+ end
+ end
+
+ def rsearch(pat,start,stop=None)
+ rsearch_with_length(pat,start,stop)[0]
+ end
end
class TkTextTag<TkObject
@@ -145,13 +307,12 @@ class TkTextTag<TkObject
r
end
- def nextrange(first, last=nil)
+ def nextrange(first, last=None)
tk_split_list(tk_call(@t.path, 'tag', 'nextrange', @id, first, last))
end
- def prevrange(first, last=nil)
+ def prevrange(first, last=None)
tk_split_list(tk_call(@t.path, 'tag', 'prevrange', @id, first, last))
- l = tk_split_list(tk_call(@t.path, 'tag', 'prevrange', @id, first, last))
end
def [](key)
@@ -166,22 +327,49 @@ class TkTextTag<TkObject
tk_call @t.path, 'tag', 'cget', @id, "-#{key}"
end
- def configure(key, val=nil)
+ def configure(key, val=None)
if key.kind_of? Hash
tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key)
else
tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val
end
end
-
- def configinfo
- tk_split_list(tk_call(@t.path, 'tag', 'configure', @id))
+# def configure(key, value)
+# if value == FALSE
+# value = "0"
+# elsif value.kind_of? Proc
+# value = install_cmd(value)
+# end
+# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", value
+# end
+
+ def configinfo(key=nil)
+ if key
+ conf = tk_split_list(tk_call(@t.path, 'tag','configure',@id,"-#{key}"))
+ conf[0] = conf[0][1..-1]
+ conf
+ else
+ tk_split_list(tk_call(@t.path, 'tag', 'configure', @id)).collect{|conf|
+ conf[0] = conf[0][1..-1]
+ conf
+ }
+ end
end
def bind(seq, cmd=Proc.new, args=nil)
+ seq = context.join("><") if seq.kind_of? Array
+ if /,/ =~ seq
+ seq = seq.split(/\s*,\s*/).join("><")
+ end
id = install_bind(cmd, args)
tk_call @t.path, 'tag', 'bind', @id, "<#{seq}>", id
- @t._addcmd cmd
+ # @t._addcmd cmd
+ end
+
+ def bindinfo
+ tk_split_list(tk_call(@t.path, 'tag', 'bind', @id)).filter{|seq|
+ seq.tr('<>',' ').strip.gsub(/\s+/,',')
+ }
end
def raise(above=None)
@@ -307,12 +495,23 @@ class TkTextWindow<TkObject
tk_call @t.path, 'window', 'cget', @index, "-#{slot}"
end
- def configure(slot, value)
- @id = value if slot == 'window'
- if slot == 'create'
- self.create=value
+ def configure(slot, value=None)
+ if slot.kind_of? Hash
+ @id = slot['window'] if slot['window']
+ if slot['create']
+ self.create=value
+ slot['create']=nil
+ end
+ if slot.size > 0
+ tk_call @t.path, 'window', 'configure', @index, *hash_kv(slot)
+ end
else
- tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value
+ @id = value if slot == 'window'
+ if slot == 'create'
+ self.create=value
+ else
+ tk_call @t.path, 'window', 'configure', @index, "-#{slot}", value
+ end
end
end
@@ -386,9 +585,16 @@ class TkTextImage<TkObject
tk_call @t.path, 'image', 'cget', @index, "-#{slot}"
end
- def configure(slot, value)
- tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value
+ def configure(slot, value=None)
+ if slot.kind_of? Hash
+ tk_call @t.path, 'image', 'configure', @index, *hash_kv(slot)
+ else
+ tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value
+ end
end
+# def configure(slot, value)
+# tk_call @t.path, 'image', 'configure', @index, "-#{slot}", value
+# end
def image
tk_call @t.path, 'image', 'configure', @index, '-image'
diff --git a/marshal.c b/marshal.c
index 73ae8a69f8..4234c98981 100644
--- a/marshal.c
+++ b/marshal.c
@@ -207,10 +207,6 @@ w_object(obj, arg, limit)
if (limit == 0) {
Fail("exceed depth limit");
}
- limit--;
- c_arg.limit = limit;
- c_arg.arg = arg;
-
if (obj == Qnil) {
w_byte(TYPE_NIL, arg);
}
@@ -225,19 +221,23 @@ w_object(obj, arg, limit)
w_byte(TYPE_FIXNUM, arg);
w_long(FIX2INT(obj), arg);
#else
- if (RSHIFT(obj, 32) == 0 || RSHIFT(obj, 32) == -1) {
+ if (RSHIFT((long)obj, 32) == 0 || RSHIFT((long)obj, 32) == -1) {
w_byte(TYPE_FIXNUM, arg);
- w_long(FIX2INT(obj), arg);
+ w_long(FIX2LONG(obj), arg);
}
else {
- obj = int2big(FIX2INT(obj));
- goto write_bignum;
+ w_object(int2big(FIX2LONG(obj)), arg, limit);
+ return;
}
#endif
}
else {
int num;
+ limit--;
+ c_arg.limit = limit;
+ c_arg.arg = arg;
+
if (st_lookup(arg->data, obj, &num)) {
w_byte(TYPE_LINK, arg);
w_long(num, arg);
@@ -339,7 +339,7 @@ w_object(obj, arg, limit)
Fatal("non-initialized struct");
}
for (i=0; i<len; i++) {
- w_symbol(FIX2INT(RARRAY(mem)->ptr[i]), arg);
+ w_symbol(FIX2LONG(RARRAY(mem)->ptr[i]), arg);
w_object(RSTRUCT(obj)->ptr[i], arg, limit);
}
}
@@ -456,7 +456,7 @@ r_byte(arg)
struct load_arg *arg;
{
if (arg->fp) return getc(arg->fp);
- if (arg->ptr < arg->end) return *arg->ptr++;
+ if (arg->ptr < arg->end) return *(unsigned char*)arg->ptr++;
return EOF;
}
@@ -511,8 +511,9 @@ r_long(arg)
return x;
}
+static long blen; /* hidden length register */
#define r_bytes(s, arg) \
- (s = (char*)r_long(arg), r_bytes0(&s,ALLOCA_N(char,(long)s),(long)s,arg))
+ (blen = r_long(arg), r_bytes0(&s,ALLOCA_N(char,blen),blen,arg))
static int
r_bytes0(sp, s, len, arg)
diff --git a/missing/nt.h b/missing/nt.h
index a571570c43..be8d61fc41 100644
--- a/missing/nt.h
+++ b/missing/nt.h
@@ -221,7 +221,7 @@ extern char *mystrerror(int);
#define EWOULDBLOCK 10035 /* EBASEERR + 35 (winsock.h) */
#endif
-#define O_BINMODE 0x8000
+#define O_BINARY 0x8000
#ifdef popen
#undef popen
diff --git a/numeric.c b/numeric.c
index 58dbfe3742..58c3eaab80 100644
--- a/numeric.c
+++ b/numeric.c
@@ -100,7 +100,7 @@ num_uminus(num)
VALUE zero;
zero = INT2FIX(0);
- do_coerce(&num, &zero);
+ do_coerce(&zero, &num);
return rb_funcall(zero, '-', 1, num);
}
@@ -227,13 +227,11 @@ flo_plus(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- return float_new(RFLOAT(x)->value + (double)FIX2INT(y));
+ return float_new(RFLOAT(x)->value + (double)FIX2LONG(y));
case T_BIGNUM:
return float_new(RFLOAT(x)->value + big2dbl(y));
case T_FLOAT:
return float_new(RFLOAT(x)->value + RFLOAT(y)->value);
- case T_STRING:
- return str_plus(obj_as_string(x), y);
default:
return num_coerce_bin(x, y);
}
@@ -245,7 +243,7 @@ flo_minus(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- return float_new(RFLOAT(x)->value - (double)FIX2INT(y));
+ return float_new(RFLOAT(x)->value - (double)FIX2LONG(y));
case T_BIGNUM:
return float_new(RFLOAT(x)->value - big2dbl(y));
case T_FLOAT:
@@ -261,13 +259,11 @@ flo_mul(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- return float_new(RFLOAT(x)->value * (double)FIX2INT(y));
+ return float_new(RFLOAT(x)->value * (double)FIX2LONG(y));
case T_BIGNUM:
return float_new(RFLOAT(x)->value * big2dbl(y));
case T_FLOAT:
return float_new(RFLOAT(x)->value * RFLOAT(y)->value);
- case T_STRING:
- return str_times(y, INT2FIX((int)RFLOAT(x)->value));
default:
return num_coerce_bin(x, y);
}
@@ -282,7 +278,7 @@ flo_div(x, y)
switch (TYPE(y)) {
case T_FIXNUM:
- f_y = FIX2INT(y);
+ f_y = FIX2LONG(y);
if (f_y == 0) num_zerodiv();
return float_new(RFLOAT(x)->value / (double)f_y);
case T_BIGNUM:
@@ -306,7 +302,7 @@ flo_modulo(x, y, modulo)
switch (TYPE(y)) {
case T_FIXNUM:
- value = (double)FIX2INT(y);
+ value = (double)FIX2LONG(y);
break;
case T_BIGNUM:
value = big2dbl(y);
@@ -356,7 +352,7 @@ flo_pow(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- return float_new(pow(RFLOAT(x)->value, (double)FIX2INT(y)));
+ return float_new(pow(RFLOAT(x)->value, (double)FIX2LONG(y)));
case T_BIGNUM:
return float_new(pow(RFLOAT(x)->value, big2dbl(y)));
case T_FLOAT:
@@ -389,7 +385,7 @@ flo_eq(x, y)
{
switch (TYPE(y)) {
case T_FIXNUM:
- if (RFLOAT(x)->value == FIX2INT(y)) return TRUE;
+ if (RFLOAT(x)->value == FIX2LONG(y)) return TRUE;
return FALSE;
case T_BIGNUM:
return (RFLOAT(x)->value == big2dbl(y))?TRUE:FALSE;
@@ -426,7 +422,7 @@ flo_cmp(x, y)
a = RFLOAT(x)->value;
switch (TYPE(y)) {
case T_FIXNUM:
- b = (double)FIX2INT(y);
+ b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
@@ -454,7 +450,7 @@ flo_gt(x, y)
a = RFLOAT(x)->value;
switch (TYPE(y)) {
case T_FIXNUM:
- b = (double)FIX2INT(y);
+ b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
@@ -480,7 +476,7 @@ flo_ge(x, y)
a = RFLOAT(x)->value;
switch (TYPE(y)) {
case T_FIXNUM:
- b = (double)FIX2INT(y);
+ b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
@@ -506,7 +502,7 @@ flo_lt(x, y)
a = RFLOAT(x)->value;
switch (TYPE(y)) {
case T_FIXNUM:
- b = (double)FIX2INT(y);
+ b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
@@ -532,7 +528,7 @@ flo_le(x, y)
a = RFLOAT(x)->value;
switch (TYPE(y)) {
case T_FIXNUM:
- b = (double)FIX2INT(y);
+ b = (double)FIX2LONG(y);
break;
case T_BIGNUM:
@@ -668,7 +664,7 @@ num2long(val)
switch (TYPE(val)) {
case T_FIXNUM:
- return FIX2INT(val);
+ return FIX2LONG(val);
case T_FLOAT:
if (RFLOAT(val)->value <= (double)LONG_MAX
@@ -777,7 +773,7 @@ static VALUE
fix_uminus(num)
VALUE num;
{
- return int2inum(-FIX2INT(num));
+ return int2inum(-FIX2LONG(num));
}
VALUE
@@ -814,18 +810,18 @@ fix_plus(x, y)
long a, b, c;
VALUE r;
- a = FIX2INT(x);
- b = FIX2INT(y);
+ a = FIX2LONG(x);
+ b = FIX2LONG(y);
c = a + b;
r = INT2FIX(c);
- if (FIX2INT(r) != c) {
+ if (FIX2LONG(r) != c) {
r = big_plus(int2big(a), int2big(b));
}
return r;
}
case T_FLOAT:
- return float_new((double)FIX2INT(x) + RFLOAT(y)->value);
+ return float_new((double)FIX2LONG(x) + RFLOAT(y)->value);
default:
return num_coerce_bin(x, y);
}
@@ -841,18 +837,18 @@ fix_minus(x, y)
long a, b, c;
VALUE r;
- a = FIX2INT(x);
- b = FIX2INT(y);
+ a = FIX2LONG(x);
+ b = FIX2LONG(y);
c = a - b;
r = INT2FIX(c);
- if (FIX2INT(r) != c) {
+ if (FIX2LONG(r) != c) {
r = big_minus(int2big(a), int2big(b));
}
return r;
}
case T_FLOAT:
- return float_new((double)FIX2INT(x) - RFLOAT(y)->value);
+ return float_new((double)FIX2LONG(x) - RFLOAT(y)->value);
default:
return num_coerce_bin(x, y);
}
@@ -868,20 +864,20 @@ fix_mul(x, y)
long a, b, c;
VALUE r;
- a = FIX2INT(x);
+ a = FIX2LONG(x);
if (a == 0) return x;
- b = FIX2INT(y);
+ b = FIX2LONG(y);
c = a * b;
r = INT2FIX(c);
- if (FIX2INT(r) != c || c/a != b) {
+ if (FIX2LONG(r) != c || c/a != b) {
r = big_mul(int2big(a), int2big(b));
}
return r;
}
case T_FLOAT:
- return float_new((double)FIX2INT(x) * RFLOAT(y)->value);
+ return float_new((double)FIX2LONG(x) * RFLOAT(y)->value);
default:
return num_coerce_bin(x, y);
}
@@ -894,9 +890,9 @@ fix_div(x, y)
long i;
if (TYPE(y) == T_FIXNUM) {
- i = FIX2INT(y);
+ i = FIX2LONG(y);
if (i == 0) num_zerodiv();
- i = FIX2INT(x)/i;
+ i = FIX2LONG(x)/i;
return INT2FIX(i);
}
return num_coerce_bin(x, y);
@@ -909,13 +905,13 @@ fix_modulo(x, y, modulo)
long i;
if (TYPE(y) == T_FIXNUM) {
- i = FIX2INT(y);
+ i = FIX2LONG(y);
if (i == 0) num_zerodiv();
- i = FIX2INT(x)%i;
+ i = FIX2LONG(x)%i;
if (modulo &&
- (FIX2INT(x) < 0) != (FIX2INT(y) < 0) &&
+ (FIX2LONG(x) < 0) != (FIX2LONG(y) < 0) &&
i != 0) {
- i += FIX2INT(y);
+ i += FIX2LONG(y);
}
return INT2FIX(i);
}
@@ -943,9 +939,9 @@ fix_pow(x, y)
if (FIXNUM_P(y)) {
long a, b;
- b = FIX2INT(y);
+ b = FIX2LONG(y);
if (b == 0) return INT2FIX(1);
- a = FIX2INT(x);
+ a = FIX2LONG(x);
if (b > 0) {
return big_pow(int2big(a), y);
}
@@ -962,7 +958,7 @@ fix_equal(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- return (FIX2INT(x) == FIX2INT(y))?TRUE:FALSE;
+ return (FIX2LONG(x) == FIX2LONG(y))?TRUE:FALSE;
}
else {
return num_equal(x, y);
@@ -974,7 +970,7 @@ fix_cmp(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- long a = FIX2INT(x), b = FIX2INT(y);
+ long a = FIX2LONG(x), b = FIX2LONG(y);
if (a == b) return INT2FIX(0);
if (a > b) return INT2FIX(1);
@@ -990,7 +986,7 @@ fix_gt(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- long a = FIX2INT(x), b = FIX2INT(y);
+ long a = FIX2LONG(x), b = FIX2LONG(y);
if (a > b) return TRUE;
return FALSE;
@@ -1005,7 +1001,7 @@ fix_ge(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- long a = FIX2INT(x), b = FIX2INT(y);
+ long a = FIX2LONG(x), b = FIX2LONG(y);
if (a >= b) return TRUE;
return FALSE;
@@ -1020,7 +1016,7 @@ fix_lt(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- long a = FIX2INT(x), b = FIX2INT(y);
+ long a = FIX2LONG(x), b = FIX2LONG(y);
if (a < b) return TRUE;
return FALSE;
@@ -1035,7 +1031,7 @@ fix_le(x, y)
VALUE x, y;
{
if (FIXNUM_P(y)) {
- long a = FIX2INT(x), b = FIX2INT(y);
+ long a = FIX2LONG(x), b = FIX2LONG(y);
if (a <= b) return TRUE;
return FALSE;
@@ -1064,7 +1060,7 @@ fix_and(x, y)
if (TYPE(y) == T_BIGNUM) {
return big_and(y, x);
}
- val = FIX2INT(x) & NUM2INT(y);
+ val = FIX2LONG(x) & NUM2LONG(y);
return int2inum(val);
}
@@ -1077,7 +1073,7 @@ fix_or(x, y)
if (TYPE(y) == T_BIGNUM) {
return big_or(y, x);
}
- val = FIX2INT(x) | NUM2INT(y);
+ val = FIX2LONG(x) | NUM2LONG(y);
return int2inum(val);
}
@@ -1090,7 +1086,7 @@ fix_xor(x, y)
if (TYPE(y) == T_BIGNUM) {
return big_xor(y, x);
}
- val = FIX2INT(x) ^ NUM2INT(y);
+ val = FIX2LONG(x) ^ NUM2LONG(y);
return int2inum(val);
}
@@ -1100,8 +1096,8 @@ fix_lshift(x, y)
{
long val, width;
- val = NUM2INT(x);
- width = NUM2INT(y);
+ val = NUM2LONG(x);
+ width = NUM2LONG(y);
if (width > (sizeof(VALUE)*CHAR_BIT-1)
|| (unsigned)val>>(sizeof(VALUE)*CHAR_BIT-1-width) > 0) {
return big_lshift(int2big(val), y);
@@ -1116,9 +1112,9 @@ fix_rshift(x, y)
{
long i, val;
- i = NUM2INT(y);
+ i = NUM2LONG(y);
if (i < sizeof(long) * 8) {
- val = RSHIFT(FIX2INT(x), i);
+ val = RSHIFT(FIX2LONG(x), i);
return INT2FIX(val);
}
@@ -1129,8 +1125,8 @@ static VALUE
fix_aref(fix, idx)
VALUE fix, idx;
{
- unsigned long val = FIX2INT(fix);
- int i = FIX2INT(idx);
+ unsigned long val = FIX2LONG(fix);
+ int i = FIX2LONG(idx);
if (i < 0 || sizeof(VALUE)*CHAR_BIT-1 < i)
return INT2FIX(0);
@@ -1152,7 +1148,7 @@ fix_to_f(num)
{
double val;
- val = (double)FIX2INT(num);
+ val = (double)FIX2LONG(num);
return float_new(val);
}
@@ -1168,7 +1164,7 @@ static VALUE
fix_abs(fix)
VALUE fix;
{
- long i = FIX2INT(fix);
+ long i = FIX2LONG(fix);
if (i < 0) i = -i;
@@ -1188,7 +1184,7 @@ static VALUE
fix_succ(fix)
VALUE fix;
{
- long i = FIX2INT(fix) + 1;
+ long i = FIX2LONG(fix) + 1;
return int2inum(i);
}
@@ -1274,8 +1270,8 @@ fix_upto(from, to)
long i, end;
if (!FIXNUM_P(to)) return num_upto(from, to);
- end = FIX2INT(to);
- for (i = FIX2INT(from); i <= end; i++) {
+ end = FIX2LONG(to);
+ for (i = FIX2LONG(from); i <= end; i++) {
rb_yield(INT2FIX(i));
}
@@ -1289,8 +1285,8 @@ fix_downto(from, to)
long i, end;
if (!FIXNUM_P(to)) return num_downto(from, to);
- end = FIX2INT(to);
- for (i=FIX2INT(from); i >= end; i--) {
+ end = FIX2LONG(to);
+ for (i=FIX2LONG(from); i >= end; i--) {
rb_yield(INT2FIX(i));
}
@@ -1306,19 +1302,19 @@ fix_step(from, to, step)
if (!FIXNUM_P(to) || !FIXNUM_P(step))
return num_step(from, to, step);
- end = FIX2INT(to);
- diff = FIX2INT(step);
+ end = FIX2LONG(to);
+ diff = FIX2LONG(step);
if (diff == 0) {
ArgError("step cannot be 0");
}
else if (diff > 0) {
- for (i=FIX2INT(from); i <= end; i+=diff) {
+ for (i=FIX2LONG(from); i <= end; i+=diff) {
rb_yield(INT2FIX(i));
}
}
else {
- for (i=FIX2INT(from); i >= end; i+=diff) {
+ for (i=FIX2LONG(from); i >= end; i+=diff) {
rb_yield(INT2FIX(i));
}
}
@@ -1331,7 +1327,7 @@ fix_dotimes(num)
{
long i, end;
- end = FIX2INT(num);
+ end = FIX2LONG(num);
for (i=0; i<end; i++) {
rb_yield(INT2FIX(i));
}
@@ -1342,7 +1338,7 @@ static VALUE
fix_zero_p(num)
VALUE num;
{
- if (FIX2INT(num) == 0) {
+ if (FIX2LONG(num) == 0) {
return TRUE;
}
return FALSE;
diff --git a/object.c b/object.c
index fc3960dffc..6bfa10335b 100644
--- a/object.c
+++ b/object.c
@@ -798,7 +798,7 @@ f_float(obj, arg)
{
switch (TYPE(arg)) {
case T_FIXNUM:
- return float_new((double)FIX2INT(arg));
+ return float_new((double)FIX2LONG(arg));
case T_FLOAT:
return arg;
diff --git a/process.c b/process.c
index ffb1fdf3b3..0066733934 100644
--- a/process.c
+++ b/process.c
@@ -809,12 +809,12 @@ proc_getpgrp(argc, argv)
return INT2FIX(pgrp);
}
-#ifdef HAVE_SETPGRP
static VALUE
proc_setpgrp(argc, argv)
int argc;
VALUE *argv;
{
+#ifdef HAVE_SETPGRP
#ifdef BSD_SETPGRP
VALUE pid, pgrp;
int ipid, ipgrp;
@@ -829,14 +829,16 @@ proc_setpgrp(argc, argv)
if (setpgrp() < 0) rb_sys_fail(0);
#endif
return Qnil;
-}
+#else
+ rb_notimplement();
#endif
+}
-#ifdef HAVE_SETPGID
static VALUE
proc_setpgid(obj, pid, pgrp)
VALUE obj, pid, pgrp;
{
+#ifdef HAVE_SETPGID
int ipid, ipgrp;
ipid = NUM2INT(pid);
@@ -844,8 +846,23 @@ proc_setpgid(obj, pid, pgrp)
if (setpgid(ipid, ipgrp) < 0) rb_sys_fail(0);
return Qnil;
+#else
+ rb_notimplement();
+#endif
}
+
+static VALUE
+proc_setsid()
+{
+#ifdef HAVE_SETSID
+ int pid = setsid();
+
+ if (pid < 0) rb_sys_fail(0);
+ return NUM2INT(pid);
+#else
+ rb_notimplement();
#endif
+}
static VALUE
proc_getpriority(obj, which, who)
@@ -1062,17 +1079,15 @@ Init_process()
#if !defined(NT) && !defined(DJGPP) && !defined(__human68k__) && !defined(USE_CWGUSI)
rb_define_module_function(mProcess, "getpgrp", proc_getpgrp, -1);
-#ifdef HAVE_SETPGRP
rb_define_module_function(mProcess, "setpgrp", proc_setpgrp, -1);
-#endif
-#ifdef HAVE_SETPGID
rb_define_module_function(mProcess, "setpgid", proc_setpgid, 2);
-#endif
-#ifdef HAVE_GETPRIORITY
+ rb_define_module_function(mProcess, "setsid", proc_setsid, 0);
+
rb_define_module_function(mProcess, "getpriority", proc_getpriority, 2);
rb_define_module_function(mProcess, "setpriority", proc_setpriority, 3);
+#ifdef PRIO_PROCESS
rb_define_const(mProcess, "PRIO_PROCESS", INT2FIX(PRIO_PROCESS));
rb_define_const(mProcess, "PRIO_PGRP", INT2FIX(PRIO_PGRP));
rb_define_const(mProcess, "PRIO_USER", INT2FIX(PRIO_USER));
diff --git a/sample/test.rb b/sample/test.rb
index e3ca832e0f..9f1a92a0eb 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -517,7 +517,12 @@ ok($good)
$good = true;
for i in 4000..4096
n1 = 1 << i;
- $good = false if ((n1**2-1) / (n1+1) != (n1-1))
+ if (n1**2-1) / (n1+1) != (n1-1)
+ p i
+ p (n1**2-1)/(n1+1)
+ p (n1-1)
+ $good = false
+ end
end
ok($good)
@@ -897,6 +902,13 @@ rescue
ok true
end
+check "marshal"
+$x = [1,2,3,[4,5,"foo"],{1=>"bar"},2.5,fact(30)]
+$y = Marshal.dump($x)
+p $x
+p Marshal.load($y)
+ok($x == Marshal.load($y))
+
check "pack"
$format = "c2x5CCxsdila6";
diff --git a/sprintf.c b/sprintf.c
index dac3659525..5bc530377c 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -311,13 +311,14 @@ f_sprintf(argc, argv)
{
volatile VALUE val = GETARG();
char fbuf[32], nbuf[64], *s, *t;
- int v, base, bignum = 0;
+ long v;
+ int base, bignum = 0;
int len, slen, pos;
bin_retry:
switch (TYPE(val)) {
case T_FIXNUM:
- v = FIX2INT(val);
+ v = FIX2LONG(val);
break;
case T_FLOAT:
val = dbl2big(RFLOAT(val)->value);
@@ -471,7 +472,7 @@ f_sprintf(argc, argv)
int_retry:
switch (TYPE(val)) {
case T_FIXNUM:
- v = FIX2INT(val);
+ v = FIX2LONG(val);
break;
case T_FLOAT:
v = RFLOAT(val)->value;
@@ -567,7 +568,7 @@ f_sprintf(argc, argv)
switch (TYPE(val)) {
case T_FIXNUM:
- fval = FIX2INT(val);
+ fval = (double)FIX2LONG(val);
break;
case T_FLOAT:
fval = RFLOAT(val)->value;
diff --git a/version.h b/version.h
index 39d4f69dcf..a4eeb9bd9b 100644
--- a/version.h
+++ b/version.h
@@ -1,2 +1,2 @@
-#define RUBY_VERSION "1.1b9_28"
-#define VERSION_DATE "98/06/26"
+#define RUBY_VERSION "1.1b9_29"
+#define VERSION_DATE "98/07/03"