summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog93
-rw-r--r--ToDo4
-rw-r--r--array.c40
-rw-r--r--class.c2
-rw-r--r--config.guess4
-rw-r--r--config.sub2
-rw-r--r--configure.in56
-rw-r--r--dir.c15
-rw-r--r--dln.c2
-rw-r--r--enum.c8
-rw-r--r--eval.c92
-rw-r--r--ext/dbm/dbm.c2
-rw-r--r--ext/etc/etc.c4
-rw-r--r--ext/extmk.rb.in18
-rw-r--r--ext/gdbm/gdbm.c2
-rw-r--r--ext/md5/MANIFEST1
-rw-r--r--ext/pty/pty.c2
-rw-r--r--ext/sdbm/init.c2
-rw-r--r--ext/tcltklib/extconf.rb2
-rw-r--r--ext/tk/lib/tk.rb6
-rw-r--r--ext/tk/lib/tkafter.rb2
-rw-r--r--ext/tk/lib/tkcanvas.rb11
-rw-r--r--ext/tk/lib/tktext.rb6
-rw-r--r--ext/tk/lib/tkvirtevent.rb6
-rw-r--r--ext/tk/tkutil.c2
-rw-r--r--file.c7
-rw-r--r--hash.c8
-rw-r--r--instruby.rb6
-rw-r--r--io.c162
-rw-r--r--lib/date2.rb93
-rw-r--r--lib/mkmf.rb18
-rw-r--r--marshal.c8
-rw-r--r--misc/ruby-mode.el41
-rw-r--r--node.h6
-rw-r--r--object.c22
-rw-r--r--pack.c6
-rw-r--r--parse.y2
-rw-r--r--process.c2
-rw-r--r--re.c14
-rw-r--r--regex.c197
-rw-r--r--regex.h10
-rw-r--r--ruby.14
-rw-r--r--ruby.c1
-rw-r--r--ruby.h2
-rw-r--r--sample/cal.rb149
-rw-r--r--sample/test.rb1
-rw-r--r--string.c66
-rw-r--r--struct.c6
-rw-r--r--version.h4
49 files changed, 608 insertions, 611 deletions
diff --git a/ChangeLog b/ChangeLog
index 276277e..560f838 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,40 @@
+Wed May 24 13:12:31 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * misc/ruby-mode.el (ruby-parse-region): support `while .. do' etc.
+
+Tue May 23 23:50:12 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * re.c (rb_reg_initialize_m): wrong kcode value.
+
+ * re.c (rb_reg_s_new): forgot to initialize re->ptr.
+
+Tue May 23 08:36:24 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * regex.c (re_compile_pattern): forgot to restore old option
+ status by (?ix-ix).
+
+ * regex.c (re_compile_fastmap): anychar may match newline if
+ RE_OPTION_MULTILINE or RE_OPTION_POSIXLINE is set.
+
+Mon May 22 21:56:43 2000 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * struct.c (rb_struct_getmember): should use ID2SYM, not INT2NUM.
+
+Mon May 22 15:07:37 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * file.c (rb_find_file): should check if the file really exists.
+
+Mon May 22 09:08:12 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * io.c (rb_io_popen): _exit(0) after processing block under the
+ child process.
+
+ * io.c (rb_io_popen): flush stdout/stderr before subprocess
+ termination.
+
+ * eval.c (rb_check_safe_str): insert rb_secure(4); operation
+ requires untainted string should be prohibited in level 4.
+
Sun May 21 21:17:00 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* configure.in: add Setup.dj for djgpp cross-compiling.
@@ -6,6 +43,10 @@ Sun May 21 21:17:00 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* instruby.rb: copy win32/win32.h to archlibdir on mingw32.
+Sun May 21 20:58:08 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp>
+
+ * pack.c: fix OFF16 and OFF32 definitions for Alpha and IRIX64.
+
Sun May 21 17:31:37 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* instruby.rb: support "make install" for cross-compiling.
@@ -18,6 +59,53 @@ Sun May 21 14:22:49 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* configure.in: ditto.
+Sat May 20 23:29:14 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * dir.c (dir_s_new): does not take block; "open" does.
+
+ * io.c (rb_io_s_new): ditto.
+
+Fri May 19 07:44:26 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * dir.c (dir_s_open): Dir#open does not returns closed Dir if a
+ block is given to the method.
+
+ * re.c (rb_reg_initialize_m): Regexp::new calls initialize now.
+
+ * string.c (Init_String): String#delete_at removed.
+
+ * string.c (rb_str_aset_m): should have checked argc != 2.
+
+ * eval.c (rb_thread_schedule): select(2) was called too many.
+
+ * regex.c (re_compile_pattern): a bug in (?m) support. Pointed
+ out by Dave Thomas <Dave@thomases.com>.
+
+Thu May 18 23:55:26 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp>
+
+ * dln.c (search_undef): st_lookup()'s 3rd parameter should be
+ a pointer of the variable which has the same size and alignment
+ as `char *'.
+
+ * marshal.c (w_symbol, w_object): ditto.
+
+ * parse.y (rb_intern): ditto.
+
+Thu May 18 13:34:57 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * ext/socket/socket.c (ruby_connect): should not have replaced
+ thread_write_select() by rb_thread_fd_writable().
+
+Wed May 18 09:01:25 2000 Katsuyuki Komatsu <komatsu@sarion.co.jp>
+
+ * configure.in, ext/extmk.rb.in, lib/mkmf.rb: remove BeOS R3 support.
+ Make a shared library (libruby.so) only if the --enable-shared
+ option is specified.
+
+ * instruby.rb: no longer use libruby.so.LIB and import.h.
+
+ * io.c: fix READ_DATA_PENDING definition for BeOS (PowerPC).
+
Wed May 17 14:14:23 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* re.c (rb_reg_new_1): use /m instead of /p.
@@ -71,6 +159,11 @@ Mon May 15 15:38:09 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* dir.c (glob): trailing path may be null, e.g. glob("**").
+Mon May 15 14:48:41 2000 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * io.c (rb_io_pid): new method; returns nil if no process attached
+ to the IO.
+
Mon May 15 01:18:20 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* io.c (rb_io_s_popen): _exit after Proc execution.
diff --git a/ToDo b/ToDo
index fccb09d..117582c 100644
--- a/ToDo
+++ b/ToDo
@@ -63,7 +63,7 @@ Standard Libraries
- Struct::new([name,]member,...)
- IO#reopen accepts path as well
- Kernel#scan
-- call initialize for builtin classes too (not yet: Regexp, Class, Module)
+- call initialize for builtin classes too (not yet: Class, Module)
- performance tune for String's non-bang methods.
- 'w' template for pack/unpack
* String#scanf(?)
@@ -107,6 +107,6 @@ Things To Do Before 1.6
* alternative for $! (exception? in? into? =>?)
* alternative for interator?
- * regex - /p, /m
+ - regex - /p, /m
* odd? even?
* mkmf.rb - create_makefile("net/socket")
diff --git a/array.c b/array.c
index 6793fdd..25de8b1 100644
--- a/array.c
+++ b/array.c
@@ -584,30 +584,32 @@ rb_ary_aset(argc, argv, ary)
VALUE *argv;
VALUE ary;
{
- VALUE arg1, arg2, arg3;
long offset, beg, len;
- if (rb_scan_args(argc, argv, "21", &arg1, &arg2, &arg3) == 3) {
- rb_ary_replace(ary, NUM2LONG(arg1), NUM2LONG(arg2), arg3);
- return arg3;
+ if (argc == 3) {
+ rb_ary_replace(ary, NUM2LONG(argv[0]), NUM2LONG(argv[1]), argv[2]);
+ return argv[2];
}
- else if (FIXNUM_P(arg1)) {
- offset = FIX2LONG(arg1);
+ if (argc != 2) {
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)", argc);
+ }
+ if (FIXNUM_P(argv[0])) {
+ offset = FIX2LONG(argv[0]);
goto fixnum;
}
- else if (rb_range_beg_len(arg1, &beg, &len, RARRAY(ary)->len, 1)) {
+ else if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
/* check if idx is Range */
- rb_ary_replace(ary, beg, len, arg2);
- return arg2;
+ rb_ary_replace(ary, beg, len, argv[1]);
+ return argv[1];
}
- if (TYPE(arg1) == T_BIGNUM) {
+ if (TYPE(argv[0]) == T_BIGNUM) {
rb_raise(rb_eIndexError, "index too big");
}
- offset = NUM2LONG(arg1);
+ offset = NUM2LONG(argv[0]);
fixnum:
- rb_ary_store(ary, offset, arg2);
- return arg2;
+ rb_ary_store(ary, offset, argv[1]);
+ return argv[1];
}
VALUE
@@ -957,7 +959,7 @@ sort_internal(ary)
VALUE ary;
{
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
- rb_iterator_p()?sort_1:sort_2);
+ rb_block_given_p()?sort_1:sort_2);
return ary;
}
@@ -997,7 +999,7 @@ rb_ary_collect(ary)
long len, i;
VALUE collect;
- if (!rb_iterator_p()) {
+ if (!rb_block_given_p()) {
return rb_ary_dup(ary);
}
@@ -1046,7 +1048,7 @@ rb_ary_delete(ary, item)
i2++;
}
if (RARRAY(ary)->len == i2) {
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
return rb_yield(item);
}
return Qnil;
@@ -1081,7 +1083,7 @@ rb_ary_delete_at(ary, pos)
}
static VALUE
-rb_ary_delete_at_m(argc, argv, ary)
+rb_ary_slice_bang(argc, argv, ary)
int argc;
VALUE *argv;
VALUE ary;
@@ -1627,7 +1629,7 @@ Init_Array()
rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0);
rb_define_method(rb_cArray, "filter", rb_ary_filter, 0);
rb_define_method(rb_cArray, "delete", rb_ary_delete, 1);
- rb_define_method(rb_cArray, "delete_at", rb_ary_delete_at_m, -1);
+ rb_define_method(rb_cArray, "delete_at", rb_ary_delete_at, -1);
rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0);
rb_define_method(rb_cArray, "reject!", rb_ary_delete_if, 0);
rb_define_method(rb_cArray, "replace", rb_ary_replace_m, 1);
@@ -1637,7 +1639,7 @@ Init_Array()
rb_define_method(rb_cArray, "<=>", rb_ary_cmp, 1);
rb_define_method(rb_cArray, "slice", rb_ary_aref, -1);
- rb_define_method(rb_cArray, "slice!", rb_ary_delete_at_m, -1);
+ rb_define_method(rb_cArray, "slice!", rb_ary_slice_bang, -1);
rb_define_method(rb_cArray, "assoc", rb_ary_assoc, 1);
rb_define_method(rb_cArray, "rassoc", rb_ary_rassoc, 1);
diff --git a/class.c b/class.c
index 413355f..f92ceda 100644
--- a/class.c
+++ b/class.c
@@ -662,7 +662,7 @@ rb_scan_args(argc, argv, fmt, va_alist)
if (*p == '&') {
var = va_arg(vargs, VALUE*);
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
*var = rb_f_lambda();
}
else {
diff --git a/config.guess b/config.guess
index 20ad33d..53ebbce 100644
--- a/config.guess
+++ b/config.guess
@@ -969,10 +969,6 @@ EOF
*:Rhapsody:*:*)
echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
exit 0 ;;
- *:"Mac OS":*:*)
- echo `uname -p`-apple-macos${UNAME_RELEASE}
- exit 0 ;;
-
esac
#echo '(No uname command or uname output not recognized.)' 1>&2
diff --git a/config.sub b/config.sub
index 1c351e1..3c591de 100644
--- a/config.sub
+++ b/config.sub
@@ -910,7 +910,7 @@ case $os in
| -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
| -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
| -mingw32* | -linux* | -uxpv* | -beos* | -mpeix* | -udk* \
- | -interix* | -uwin* | -rhapsody* | -openstep* | -macos | -oskit*)
+ | -interix* | -uwin* | -rhapsody* | -openstep* | -oskit*)
# Remember, each alternative MUST END IN *, to match a version number.
;;
-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
diff --git a/configure.in b/configure.in
index 4345e2b..a6e26f3 100644
--- a/configure.in
+++ b/configure.in
@@ -44,12 +44,6 @@ AC_ARG_ENABLE(fat-binary,
TARGET_ARCHS="ppc i386"
fi
;;
- macos*)
- echo -n "MacOS X : "
- if test "$TARGET_ARCHS" = "" ; then
- TARGET_ARCHS="ppc i386"
- fi
- ;;
nextstep*|openstep*)
echo -n "NeXTSTEP/OPENSTEP: "
if test "$TARGET_ARCHS" = "" ; then
@@ -161,7 +155,6 @@ case "$target_os" in
nextstep*) ;;
openstep*) ;;
rhapsody*) ;;
-macos*) ;;
human*) ac_cv_func_getpgrp_void=yes;;
beos*) ;;
cygwin*) ;;
@@ -424,9 +417,9 @@ if test "$with_dln_a_out" != yes; then
nextstep*) ;;
openstep*) ;;
rhapsody*) ;;
- macos*) ;;
human*) ;;
bsdi*) ;;
+ beos*) ;;
cygwin*) ;;
mingw*) ;;
netbsd*) CCDLFLAGS=-fpic
@@ -504,10 +497,6 @@ if test "$with_dln_a_out" != yes; then
LDFLAGS=""
DLDFLAGS="$ARCH_FLAG"
rb_cv_dlopen=yes ;;
- macos*) LDSHARED='cc -dynamic -bundle -undefined suppress'
- LDFLAGS=""
- DLDFLAGS="$ARCH_FLAG"
- rb_cv_dlopen=yes ;;
aix*) LDSHARED='/usr/ccs/bin/ld'
XLDFLAGS='-Wl,-bE:ruby.imp'
DLDFLAGS='-eInit_$(TARGET) -bI:$(topdir)/ruby.imp -bM:SRE -T512 -H512 -lc'
@@ -521,14 +510,12 @@ if test "$with_dln_a_out" != yes; then
beos*) case "$target_cpu" in
powerpc*)
LDSHARED="ld -xms"
- DLDFLAGS="-f ruby.exp -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o"
+ DLDFLAGS='-export Init_$(TARGET) -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
;;
i586*)
LDSHARED="ld -shared"
DLDFLAGS="-L/boot/develop/lib/x86 -lbe -lroot"
;;
- *)
- DLDFLAGS="ruby.def -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o"
esac
rb_cv_dlopen=yes ;;
cygwin*|mingw*) : ${LDSHARED="${DLLWRAP} --target=${target_os} --as=${AS} --dlltool-name=${DLLTOOL} --driver-name=${CC} --export-all -s"}
@@ -576,8 +563,6 @@ else
AC_DEFINE(DLEXT, ".bundle");;
rhapsody*) DLEXT=bundle
AC_DEFINE(DLEXT, ".bundle");;
- macos*) DLEXT=bundle
- AC_DEFINE(DLEXT, ".bundle");;
os2_emx*) DLEXT=dll
AC_DEFINE(DLEXT, ".dll");;
cygwin*|mingw*) DLEXT=so
@@ -605,8 +590,6 @@ case "$target_os" in
STRIP='strip -A -n';;
rhapsody*)
STRIP='strip -A -n';;
- macos*)
- STRIP='strip -A -n';;
esac
EXTSTATIC=
@@ -705,28 +688,9 @@ LIBRUBY_A='lib$(RUBY_INSTALL_NAME).a'
LIBRUBY='$(LIBRUBY_A)'
LIBRUBYARG='$(LIBRUBY_A)'
SOLIBS=
-if test "$target_os" = "beos"; then
- LIBRUBY='$(LIBRUBY_SO)'
- LIBRUBYARG='-l$(RUBY_INSTALL_NAME)'
- SOLIBS='-lnet'
- echo creating ruby.def
- case "$target_cpu" in
- powerpc*)
- cp beos/ruby.def.in ruby.exp
- CFLAGS="$CFLAGS -relax_pointers"
- ;;
- i586*)
- LDFLAGS="$LDFLAGS -L."
- ;;
- *)
- echo EXPORTS > ruby.def
- cat beos/ruby.def.in >> ruby.def
- ;;
- esac
-fi
case "$target_os" in
- cygwin*|mingw*|beos*|openstep*|nextstep*|rhapsody*|macos*|os2_emx*)
+ cygwin*|mingw*|beos*|openstep*|nextstep*|rhapsody*|os2_emx*)
DLDLIBS=""
;;
*)
@@ -787,6 +751,13 @@ if test "$enable_shared" = 'yes'; then
LIBRUBYARG='-L${prefix}/lib -Wl,lib$(RUBY_INSTALL_NAME).so'
SOLIBS='-lm -lc'
;;
+ beos*)
+ case "$target_cpu" in
+ powerpc*)
+ LIBRUBY_DLDFLAGS='-f ruby.exp -lnet -lbe -lroot glue-noinit.a init_term_dyn.o start_dyn.o'
+ ;;
+ esac
+ ;;
cygwin*|mingw*)
LIBRUBY_SO='lib$(RUBY_INSTALL_NAME).a'
LIBRUBY_ALIASES=''
@@ -834,6 +805,13 @@ case "$target_os" in
CFLAGS="$CFLAGS -std"
fi
;;
+ beos*)
+ case "$target_cpu" in
+ powerpc*)
+ CFLAGS="$CFLAGS -relax_pointers"
+ ;;
+ esac
+ ;;
cygwin*)
LIBOBJS="$LIBOBJS strftime.o"
;;
diff --git a/dir.c b/dir.c
index 5b95fcd..cfc9904 100644
--- a/dir.c
+++ b/dir.c
@@ -241,10 +241,6 @@ dir_s_new(argc, argv, klass)
rb_obj_call_init(obj, argc, argv);
- if (rb_iterator_p()) {
- rb_ensure(rb_yield, obj, dir_close, obj);
- }
-
return obj;
}
@@ -268,6 +264,7 @@ dir_initialize(dir, dirname)
}
}
DATA_PTR(dir) = dirp;
+
return dir;
}
@@ -275,7 +272,13 @@ static VALUE
dir_s_open(klass, dirname)
VALUE klass, dirname;
{
- return dir_s_new(1, &dirname, klass);
+ VALUE dir = dir_s_new(1, &dirname, klass);
+ if (rb_block_given_p()) {
+ rb_ensure(rb_yield, dir, dir_close, dir);
+ return Qnil;
+ }
+
+ return dir;
}
static void
@@ -760,7 +763,7 @@ dir_s_glob(dir, str)
}
if (buf != buffer)
free(buf);
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
long len = RARRAY(ary)->len;
VALUE *ptr = RARRAY(ary)->ptr;
diff --git a/dln.c b/dln.c
index be0aca4..90dcc90 100644
--- a/dln.c
+++ b/dln.c
@@ -881,7 +881,7 @@ search_undef(key, value, lib_tbl)
int value;
st_table *lib_tbl;
{
- int offset;
+ long offset;
if (st_lookup(lib_tbl, key, &offset) == 0) return ST_CONTINUE;
target_offset = offset;
diff --git a/enum.c b/enum.c
index 3eec1fd..4a97811 100644
--- a/enum.c
+++ b/enum.c
@@ -50,7 +50,7 @@ enum_grep(obj, pat)
VALUE tmp, arg[2];
arg[0] = pat; arg[1] = tmp = rb_ary_new();
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
rb_iterate(rb_each, obj, grep_iter_i, (VALUE)arg);
}
else {
@@ -173,7 +173,7 @@ enum_collect(obj)
VALUE tmp;
tmp = rb_ary_new();
- rb_iterate(rb_each, obj, rb_iterator_p() ? collect_i : enum_all, tmp);
+ rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : enum_all, tmp);
return tmp;
}
@@ -225,7 +225,7 @@ enum_min(obj)
{
NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0);
- rb_iterate(rb_each, obj, rb_iterator_p()?min_ii:min_i, (VALUE)memo);
+ rb_iterate(rb_each, obj, rb_block_given_p()?min_ii:min_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
return memo->u1.value;
}
@@ -270,7 +270,7 @@ enum_max(obj)
{
NODE *memo = rb_node_newnode(NODE_MEMO, Qnil, 0, 0);
- rb_iterate(rb_each, obj, rb_iterator_p()?max_ii:max_i, (VALUE)memo);
+ rb_iterate(rb_each, obj, rb_block_given_p()?max_ii:max_i, (VALUE)memo);
rb_gc_force_recycle((VALUE)memo);
return memo->u1.value;
}
diff --git a/eval.c b/eval.c
index b753509..1027e82 100644
--- a/eval.c
+++ b/eval.c
@@ -74,7 +74,7 @@ static VALUE rb_cBinding;
static VALUE proc_call _((VALUE,VALUE));
static VALUE rb_f_binding _((VALUE));
static void rb_f_END _((void));
-static VALUE rb_f_iterator_p _((void));
+static VALUE rb_f_block_given_p _((void));
static VALUE block_pass _((VALUE,NODE*));
static VALUE rb_cMethod;
static VALUE method_proc _((VALUE));
@@ -126,29 +126,35 @@ safe_setter(val)
}
void
+rb_secure(level)
+ int level;
+{
+ if (level <= ruby_safe_level) {
+ rb_raise(rb_eSecurityError, "Insecure operation `%s' for level %d",
+ rb_id2name(ruby_frame->last_func), ruby_safe_level);
+ }
+}
+
+void
rb_check_safe_str(x)
VALUE x;
{
if (ruby_safe_level > 0 && OBJ_TAINTED(x)){
- rb_raise(rb_eSecurityError, "Insecure operation - %s",
- rb_id2name(ruby_frame->last_func));
+ if (ruby_frame->last_func) {
+ rb_raise(rb_eSecurityError, "Insecure operation - %s",
+ rb_id2name(ruby_frame->last_func));
+ }
+ else {
+ rb_raise(rb_eSecurityError, "Insecure operation: -r");
+ }
}
+ rb_secure(4);
if (TYPE(x)!= T_STRING) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected String)",
rb_class2name(CLASS_OF(x)));
}
}
-void
-rb_secure(level)
- int level;
-{
- if (level <= ruby_safe_level) {
- rb_raise(rb_eSecurityError, "Insecure operation `%s' for level %d",
- rb_id2name(ruby_frame->last_func), ruby_safe_level);
- }
-}
-
static void print_undef _((VALUE, ID)) NORETURN;
static void
print_undef(klass, id)
@@ -1642,7 +1648,7 @@ is_defined(self, node, buf)
return "method";
case NODE_YIELD:
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
return "yield";
}
break;
@@ -2562,7 +2568,7 @@ rb_eval(self, n)
case NODE_BLOCK_ARG:
if (ruby_scope->local_vars == 0)
rb_bug("unexpected block argument");
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
result = rb_f_lambda();
ruby_scope->local_vars[node->nd_cnt] = result;
}
@@ -3291,14 +3297,20 @@ rb_jump_tag(tag)
}
int
-rb_iterator_p()
+rb_block_given_p()
{
if (ruby_frame->iter) return Qtrue;
return Qfalse;
}
+int
+rb_iterator_p()
+{
+ return rb_block_given_p();
+}
+
static VALUE
-rb_f_iterator_p()
+rb_f_block_given_p()
{
if (ruby_frame->prev && ruby_frame->prev->iter) return Qtrue;
return Qfalse;
@@ -4158,7 +4170,7 @@ rb_call0(klass, recv, id, argc, argv, body, nosuper)
rb_raise(rb_eLocalJumpError, "unexpected redo");
break;
case TAG_RETRY:
- if (!rb_iterator_p()) {
+ if (!rb_block_given_p()) {
rb_raise(rb_eLocalJumpError, "retry outside of rescue clause");
}
default:
@@ -4247,7 +4259,7 @@ rb_f_send(argc, argv, recv)
if (argc == 0) rb_raise(rb_eArgError, "no method name given");
vid = *argv++; argc--;
- PUSH_ITER(rb_iterator_p()?ITER_PRE:ITER_NOT);
+ PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
vid = rb_call(CLASS_OF(recv), recv, rb_to_id(vid), argc, argv, 1);
POP_ITER();
@@ -4708,7 +4720,7 @@ specific_eval(argc, argv, klass, self)
{
char *file = "(eval)";
int line = 1;
- int iter = rb_iterator_p();
+ int iter = rb_block_given_p();
if (argc > 0) {
if (ruby_safe_level >= 4) {
@@ -5207,7 +5219,7 @@ rb_obj_call_init(obj, argc, argv)
int argc;
VALUE *argv;
{
- PUSH_ITER(rb_iterator_p()?ITER_PRE:ITER_NOT);
+ PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
rb_funcall2(obj, init, argc, argv);
POP_ITER();
}
@@ -5447,7 +5459,8 @@ Init_eval()
rb_define_hooked_variable("$!", &ruby_errinfo, 0, errinfo_setter);
rb_define_global_function("eval", rb_f_eval, -1);
- rb_define_global_function("iterator?", rb_f_iterator_p, 0);
+ rb_define_global_function("iterator?", rb_f_block_given_p, 0);
+ rb_define_global_function("block_given?", rb_f_block_given_p, 0);
rb_define_global_function("method_missing", rb_f_missing, -1);
rb_define_global_function("loop", rb_f_loop, 0);
@@ -5678,7 +5691,7 @@ rb_f_binding(self)
*data = *ruby_block;
data->orig_thread = rb_thread_current();
- data->iter = rb_f_iterator_p();
+ data->iter = rb_f_block_given_p();
frame_dup(&data->frame);
if (ruby_frame->prev) {
data->frame.last_func = ruby_frame->prev->last_func;
@@ -5754,7 +5767,7 @@ proc_new(klass)
struct BLOCK *data;
struct RVarmap *vars;
- if (!rb_iterator_p() && !rb_f_iterator_p()) {
+ if (!rb_block_given_p() && !rb_f_block_given_p()) {
rb_raise(rb_eArgError, "tried to create Procedure-Object out of iterator");
}
@@ -5856,7 +5869,7 @@ proc_call(proc, args)
}
if (orphan) {/* orphan procedure */
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
ruby_block->frame.iter = ITER_CUR;
}
else {
@@ -6086,7 +6099,7 @@ method_call(argc, argv, method)
volatile int safe = ruby_safe_level;
Data_Get_Struct(method, struct METHOD, data);
- PUSH_ITER(rb_iterator_p()?ITER_PRE:ITER_NOT);
+ PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
PUSH_TAG(PROT_NONE);
if (OBJ_TAINTED(data->recv) || OBJ_TAINTED(method)) {
OBJ_TAINT(method);
@@ -6612,23 +6625,12 @@ rb_thread_fd_close(fd)
static void
rb_thread_deadlock()
{
-#if 1
curr_thread = main_thread;
th_raise_argc = 1;
th_raise_argv[0] = rb_exc_new2(rb_eFatal, "Thread: deadlock");
th_raise_file = ruby_sourcefile;
th_raise_line = ruby_sourceline;
rb_thread_restore_context(main_thread, RESTORE_RAISE);
-#else
- static int invoked = 0;
-
- if (invoked) return;
- invoked = 1;
- rb_prohibit_interrupt = 1;
- ruby_errinfo = rb_exc_new2(rb_eFatal, "Thread: deadlock");
- set_backtrace(ruby_errinfo, make_backtrace());
- rb_abort();
-#endif
}
static void
@@ -6741,7 +6743,7 @@ rb_thread_schedule()
if (!next && (th->status == THREAD_RUNNABLE || th->status == THREAD_TO_KILL)) {
found = 1;
}
- if ((th->wait_for&WAIT_JOIN) && rb_thread_dead(th->join)) {
+ if ((th->wait_for & WAIT_JOIN) && rb_thread_dead(th->join)) {
th->join = 0;
th->wait_for = 0;
th->status = THREAD_RUNNABLE;
@@ -6775,7 +6777,7 @@ rb_thread_schedule()
END_FOREACH_FROM(curr, th);
/* Do the select if needed */
- if (need_select || !found) {
+ if (need_select) {
do {
/* Convert delay to a timeval */
/* If a thread is runnable, just poll */
@@ -6855,6 +6857,7 @@ rb_thread_schedule()
END_FOREACH_FROM(curr, th);
if (!next) {
+ /* raise fatal error to main thread */
curr_thread->file = ruby_sourcefile;
curr_thread->line = ruby_sourceline;
FOREACH_THREAD_FROM(curr, th) {
@@ -6864,7 +6867,6 @@ rb_thread_schedule()
th->file, th->line);
}
END_FOREACH_FROM(curr, th);
- /* raise fatal error to main thread */
rb_thread_deadlock();
next = main_thread;
rb_thread_ready(next);
@@ -7178,7 +7180,7 @@ rb_thread_stop()
{
rb_thread_critical = 0;
if (curr_thread == curr_thread->next) {
- rb_raise(rb_eThreadError, "stopping only thread");
+ rb_raise(rb_eThreadError, "stopping only thread\n\tnote: use sleep to stop forever");
}
curr_thread->status = THREAD_STOPPED;
rb_thread_schedule();
@@ -7523,8 +7525,8 @@ static VALUE
rb_thread_initialize(thread, args)
VALUE thread, args;
{
- if (!rb_iterator_p()) {
- rb_raise(rb_eThreadError, "must be called as iterator");
+ if (!rb_block_given_p()) {
+ rb_raise(rb_eThreadError, "must be called with a block");
}
return rb_thread_start_0(rb_thread_yield, args, rb_thread_check(thread));
}
@@ -7533,8 +7535,8 @@ static VALUE
rb_thread_start(klass, args)
VALUE klass, args;
{
- if (!rb_iterator_p()) {
- rb_raise(rb_eThreadError, "must be called as iterator");
+ if (!rb_block_given_p()) {
+ rb_raise(rb_eThreadError, "must be called with a block");
}
return rb_thread_start_0(rb_thread_yield, args, rb_thread_alloc(klass));
}
diff --git a/ext/dbm/dbm.c b/ext/dbm/dbm.c
index 66b41d0..c956684 100644
--- a/ext/dbm/dbm.c
+++ b/ext/dbm/dbm.c
@@ -162,7 +162,7 @@ fdbm_delete(obj, keystr)
value = dbm_fetch(dbm, key);
if (value.dptr == 0) {
- if (rb_iterator_p()) rb_yield(keystr);
+ if (rb_block_given_p()) rb_yield(keystr);
return Qnil;
}
diff --git a/ext/etc/etc.c b/ext/etc/etc.c
index 049b94e..ee0cd52 100644
--- a/ext/etc/etc.c
+++ b/ext/etc/etc.c
@@ -133,7 +133,7 @@ etc_passwd(obj)
#ifdef HAVE_GETPWENT
struct passwd *pw;
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
setpwent();
while (pw = getpwent()) {
rb_yield(setup_passwd(pw));
@@ -210,7 +210,7 @@ etc_group(obj)
#ifdef HAVE_GETGRENT
struct group *grp;
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
setgrent();
while (grp = getgrent()) {
rb_yield(setup_group(grp));
diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in
index 9715206..0787ae4 100644
--- a/ext/extmk.rb.in
+++ b/ext/extmk.rb.in
@@ -334,11 +334,6 @@ def create_makefile(target)
$DLDFLAGS = $DLDFLAGS + " -L" + $topdir
end
- if RUBY_PLATFORM =~ /beos/ and not $static
- $libs = $libs + " @LIBRUBYARG@"
- $DLDFLAGS = $DLDFLAGS + " -L" + $topdir
- end
-
defflag = ''
if RUBY_PLATFORM =~ /cygwin|mingw/ and not $static
if File.exist? target + ".def"
@@ -477,19 +472,6 @@ $(DLLIB): $(OBJS)
dfile.close
end
mfile.close
-
- if RUBY_PLATFORM =~ /beos/
- if RUBY_PLATFORM =~ /^powerpc/ then
- deffilename = "ruby.exp"
- else
- deffilename = "ruby.def"
- end
- print "creating #{deffilename}\n"
- open(deffilename, "w") do |file|
- file.print("EXPORTS\n") if RUBY_PLATFORM =~ /^i/
- file.print("Init_#{target}\n")
- end
- end
end
def extmake(target)
diff --git a/ext/gdbm/gdbm.c b/ext/gdbm/gdbm.c
index 3c1ef88..044a990 100644
--- a/ext/gdbm/gdbm.c
+++ b/ext/gdbm/gdbm.c
@@ -159,7 +159,7 @@ fgdbm_delete(obj, keystr)
value = gdbm_fetch(dbm, key);
if (value.dptr == 0) {
- if (rb_iterator_p()) rb_yield(keystr);
+ if (rb_block_given_p()) rb_yield(keystr);
return Qnil;
}
diff --git a/ext/md5/MANIFEST b/ext/md5/MANIFEST
index 8057ebb..189a482 100644
--- a/ext/md5/MANIFEST
+++ b/ext/md5/MANIFEST
@@ -1,5 +1,6 @@
MANIFEST
depend
+extconf.rb
md5.txt
md5.txt.jp
md5.h
diff --git a/ext/pty/pty.c b/ext/pty/pty.c
index b8c4e9a..52257b0 100644
--- a/ext/pty/pty.c
+++ b/ext/pty/pty.c
@@ -457,7 +457,7 @@ pty_getpty(self, shell)
rb_ary_store(res,1,(VALUE)wport);
rb_ary_store(res,2,INT2FIX(info.child_pid));
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
rb_yield((VALUE)res);
reset_signal_action();
return Qnil;
diff --git a/ext/sdbm/init.c b/ext/sdbm/init.c
index b28b8e3..1e1d5a5 100644
--- a/ext/sdbm/init.c
+++ b/ext/sdbm/init.c
@@ -156,7 +156,7 @@ fsdbm_delete(obj, keystr)
value = sdbm_fetch(dbm, key);
if (value.dptr == 0) {
- if (rb_iterator_p()) rb_yield(keystr);
+ if (rb_block_given_p()) rb_yield(keystr);
return Qnil;
}
diff --git a/ext/tcltklib/extconf.rb b/ext/tcltklib/extconf.rb
index 70a765a..5f56d42 100644
--- a/ext/tcltklib/extconf.rb
+++ b/ext/tcltklib/extconf.rb
@@ -23,6 +23,7 @@ def find_tcl(tcllib)
find_library(tcllib, func, *paths)
else
find_library("tcl", func, *paths) or
+ find_library("tcl8.3", func, *paths) or
find_library("tcl8.2", func, *paths) or
find_library("tcl8.0", func, *paths) or
find_library("tcl7.6", func, *paths)
@@ -36,6 +37,7 @@ def find_tk(tklib)
find_library(tklib, func, *paths)
else
find_library("tk", func, *paths) or
+ find_library("tk8.3", func, *paths) or
find_library("tk8.2", func, *paths) or
find_library("tk8.0", func, *paths) or
find_library("tk4.2", func, *paths)
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 6dd832b..bb3f7f6 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -470,7 +470,7 @@ module TkCore
end
def rb_appsend(interp, async, *args)
- args = args.filter{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')}
+ args = args.collect!{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')}
args.push(').to_s"')
appsend(interp, async, 'ruby "(', *args)
end
@@ -485,7 +485,7 @@ module TkCore
end
def rb_appsend_displayof(interp, win, async, *args)
- args = args.filter{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')}
+ args = args.collect!{|c| _get_eval_string(c).gsub(/[][$"]/, '\\\\\&')}
args.push(').to_s"')
appsend_displayof(interp, win, async, 'ruby "(', *args)
end
@@ -526,7 +526,7 @@ module TkCore
def tk_call(*args)
print args.join(" "), "\n" if $DEBUG
- args.filter {|x|_get_eval_string(x)}
+ args.collect! {|x|_get_eval_string(x)}
args.compact!
args.flatten!
begin
diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb
index be2e50f..55bfde4 100644
--- a/ext/tk/lib/tkafter.rb
+++ b/ext/tk/lib/tkafter.rb
@@ -26,7 +26,7 @@ class TkAfter
end
def TkAfter.info
- tk_call('after', 'info').split(' ').filter{|id|
+ tk_call('after', 'info').split(' ').collect!{|id|
ret = Tk_CBTBL.find{|key,val| val.after_id == id}
(ret == nil)? id: ret[1]
}
diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb
index 80c36f6..914bfe0 100644
--- a/ext/tk/lib/tkcanvas.rb
+++ b/ext/tk/lib/tkcanvas.rb
@@ -216,7 +216,7 @@ class TkCanvas<TkWindow
end
def find(mode, *args)
- list(tk_send 'find', mode, *args).filter{|id|
+ list(tk_send 'find', mode, *args).collect!{|id|
TkcItem.id2obj(id)
}
end
@@ -368,13 +368,6 @@ class TkCanvas<TkWindow
def itemtype(tag)
TkcItem.type2class(tk_send 'type', tagid(tag))
end
-
- def xview(*index)
- tk_send 'xview', *index
- end
- def yview(*index)
- tk_send 'yview', *index
- end
end
module TkcTagAccess
@@ -725,7 +718,7 @@ class TkImage<TkObject
end
def TkImage.names
- Tk.tk_call('image', 'names').split.filter{|id|
+ Tk.tk_call('image', 'names').split.collect!{|id|
(Tk_IMGTBL[id])? Tk_IMGTBL[id] : id
}
end
diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb
index 2b5fb91..163583f 100644
--- a/ext/tk/lib/tktext.rb
+++ b/ext/tk/lib/tktext.rb
@@ -245,16 +245,10 @@ class TkText<TkTextWin
(inf == "")? [0,0,0,0,0]: inf
end
- def yview(*what)
- tk_send 'yview', *what
- end
def yview_pickplace(*what)
tk_send 'yview', '-pickplace', *what
end
- def xview(*what)
- tk_send 'xview', *what
- end
def xview_pickplace(*what)
tk_send 'xview', '-pickplace', *what
end
diff --git a/ext/tk/lib/tkvirtevent.rb b/ext/tk/lib/tkvirtevent.rb
index 0d100c2..b31b990 100644
--- a/ext/tk/lib/tkvirtevent.rb
+++ b/ext/tk/lib/tkvirtevent.rb
@@ -16,7 +16,7 @@ class TkVirtualEvent<TkObject
end
def TkVirtualEvent.info
- tk_call('event', 'info').split(/\s+/).filter{|seq|
+ tk_call('event', 'info').split(/\s+/).collect!{|seq|
TkVirtualEvent.getobj(seq[1..-2])
}
end
@@ -49,8 +49,8 @@ class TkVirtualEvent<TkObject
end
def info
- tk_call('event', 'info', "<#{@id}>").split(/\s+/).filter{|seq|
- l = seq.scan(/<*[^<>]+>*/).filter{|subseq|
+ tk_call('event', 'info', "<#{@id}>").split(/\s+/).collect!{|seq|
+ l = seq.scan(/<*[^<>]+>*/).collect!{|subseq|
case (subseq)
when /^<<[^<>]+>>$/
TkVirtualEvent.getobj(subseq[1..-2])
diff --git a/ext/tk/tkutil.c b/ext/tk/tkutil.c
index 9d4ca0a..6cfdad9 100644
--- a/ext/tk/tkutil.c
+++ b/ext/tk/tkutil.c
@@ -29,7 +29,7 @@ tk_s_new(argc, argv, klass)
{
VALUE obj = rb_class_new_instance(argc, argv, klass);
- if (rb_iterator_p()) rb_obj_instance_eval(0, 0, obj);
+ if (rb_block_given_p()) rb_obj_instance_eval(0, 0, obj);
return obj;
}
diff --git a/file.c b/file.c
index 90e3e4d..3e0a19d 100644
--- a/file.c
+++ b/file.c
@@ -2033,6 +2033,7 @@ rb_find_file(file)
volatile VALUE vpath;
VALUE fname;
char *path;
+ struct stat st;
#if defined(__MACOS__) || defined(riscos)
if (is_macos_native_path(file)) {
@@ -2091,7 +2092,11 @@ rb_find_file(file)
path = 0;
}
- return dln_find_file(file, path);
+ path = dln_find_file(file, path);
+ if (stat(path, &st) == 0) {
+ return path;
+ }
+ return 0;
}
void
diff --git a/hash.c b/hash.c
index dc8bdf5..e66ab12 100644
--- a/hash.c
+++ b/hash.c
@@ -334,7 +334,7 @@ rb_hash_fetch(argc, argv, hash)
rb_scan_args(argc, argv, "11", &key, &if_none);
if (!st_lookup(RHASH(hash)->tbl, key, &val)) {
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
if (argc > 1) {
rb_raise(rb_eArgError, "wrong # of arguments", argc);
}
@@ -421,7 +421,7 @@ rb_hash_delete(hash, key)
}
else if (st_delete(RHASH(hash)->tbl, &key, &val))
return val;
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
return rb_yield(key);
}
return RHASH(hash)->ifnone;
@@ -894,7 +894,7 @@ env_delete_m(obj, name)
VALUE obj, name;
{
VALUE val = env_delete(obj, name);
- if (rb_iterator_p()) rb_yield(name);
+ if (rb_block_given_p()) rb_yield(name);
return val;
}
@@ -934,7 +934,7 @@ env_fetch(argc, argv)
}
env = getenv(nam);
if (!env) {
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
if (argc > 1) {
rb_raise(rb_eArgError, "wrong # of arguments", argc);
}
diff --git a/instruby.rb b/instruby.rb
index ce13ebf..601debf 100644
--- a/instruby.rb
+++ b/instruby.rb
@@ -36,7 +36,7 @@ for dll in Dir['*.dll']
File.install dll, "#{bindir}/#{dll}", 0755, true
end
File.makedirs libdir, true
-for lib in ["libruby.so.LIB", CONFIG["LIBRUBY_SO"]]
+for lib in [CONFIG["LIBRUBY_SO"]]
if File.exist? lib
File.install lib, libdir, 0555, true
end
@@ -57,10 +57,6 @@ File.makedirs archlibdir, true
File.makedirs sitelibdir, true
File.makedirs sitearchlibdir, true
-if RUBY_PLATFORM =~ /cygwin/ and File.exist? "import.h"
- File.install "import.h", archlibdir, 0644, true
-end
-
if RUBY_PLATFORM =~ /-aix/
File.install "ruby.imp", archlibdir, 0644, true
end
diff --git a/io.c b/io.c
index 405aa7d..4ce2339 100644
--- a/io.c
+++ b/io.c
@@ -105,7 +105,7 @@ static VALUE lineno;
#elif defined(FILE_COUNT)
# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
#elif defined(__BEOS__)
-# define ReadDataPending(fp) (fp->_state._eof == 0)
+# define READ_DATA_PENDING(fp) (fp->_state._eof == 0)
#else
/* requires systems own version of the ReadDataPending() */
extern int ReadDataPending();
@@ -393,6 +393,18 @@ rb_io_fileno(io)
}
static VALUE
+rb_io_pid(io)
+ VALUE io;
+{
+ OpenFile *fptr;
+
+ GetOpenFile(io, fptr);
+ if (!fptr->pid)
+ return Qnil;
+ return INT2FIX(fptr->pid);
+}
+
+static VALUE
rb_io_to_io(io)
VALUE io;
{
@@ -1572,10 +1584,11 @@ pipe_open(pname, mode)
}
static VALUE
-rb_io_s_popen(argc, argv, self)
+rb_io_popen(str, argc, argv, klass)
+ char *str;
int argc;
VALUE *argv;
- VALUE self;
+ VALUE klass;
{
char *mode;
VALUE pname, pmode, port, proc;
@@ -1584,66 +1597,42 @@ rb_io_s_popen(argc, argv, self)
mode = "r";
}
else {
- int len;
-
mode = STR2CSTR(pmode);
- len = strlen(mode);
- if (len == 0 || len > 3)
- rb_raise(rb_eArgError, "illegal access mode");
}
Check_SafeStr(pname);
- port = pipe_open(RSTRING(pname)->ptr, mode);
+ port = pipe_open(str, mode);
if (NIL_P(port)) {
/* child */
if (!NIL_P(proc)) {
rb_eval_cmd(proc, rb_ary_new2(0));
- _exit(0);
}
- else if (rb_iterator_p()) {
+ else if (rb_block_given_p()) {
rb_yield(Qnil);
}
- return Qnil;
+ fflush(stdout);
+ fflush(stderr);
+ _exit(0);
}
- else if (rb_iterator_p()) {
- return rb_ensure(rb_yield, port, rb_io_close, port);
+ RBASIC(port)->klass = klass;
+ if (rb_block_given_p()) {
+ rb_ensure(rb_yield, port, rb_io_close, port);
+ return Qnil;
}
return port;
}
static VALUE
-rb_file_initialize(argc, argv, io)
+rb_io_s_popen(argc, argv, klass)
int argc;
VALUE *argv;
- VALUE io;
+ VALUE klass;
{
- VALUE fname, vmode, file, perm;
- char *path, *mode;
-
- rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
- Check_SafeStr(fname);
- path = RSTRING(fname)->ptr;
+ char *str = 0;
- if (FIXNUM_P(vmode)) {
- int flags = NUM2INT(vmode);
- int fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
-
- file = rb_file_sysopen_internal(io, path, flags, fmode);
- }
- else {
- if (!NIL_P(vmode)) {
- mode = STR2CSTR(vmode);
- }
- else {
- mode = "r";
- }
- file = rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
- }
-
- if (rb_iterator_p()) {
- return rb_ensure(rb_yield, file, rb_io_close, file);
+ if (argc >= 1) {
+ str = STR2CSTR(argv[0]);
}
-
- return file;
+ return rb_io_popen(str, argc, argv, klass);
}
static VALUE
@@ -1668,17 +1657,18 @@ rb_file_s_open(argc, argv, klass)
file = rb_file_sysopen_internal((VALUE)io, path, flags, fmode);
}
else {
- if (!NIL_P(vmode)) {
- mode = STR2CSTR(vmode);
+ if (NIL_P(vmode)) {
+ mode = "r";
}
else {
- mode = "r";
+ mode = STR2CSTR(vmode);
}
file = rb_file_open_internal((VALUE)io, RSTRING(fname)->ptr, mode);
}
- if (rb_iterator_p()) {
- return rb_ensure(rb_yield, file, rb_io_close, file);
+ if (rb_block_given_p()) {
+ rb_ensure(rb_yield, file, rb_io_close, file);
+ return Qnil;
}
return file;
@@ -1689,41 +1679,14 @@ rb_f_open(argc, argv)
int argc;
VALUE *argv;
{
- char *mode;
- VALUE pname, pmode, perm;
- VALUE port;
+ if (argc >= 1) {
+ char *str = STR2CSTR(argv[0]);
- rb_scan_args(argc, argv, "12", &pname, &pmode, &perm);
- Check_SafeStr(pname);
- if (RSTRING(pname)->ptr[0] != '|') /* open file */
- return rb_file_s_open(argc, argv, rb_cFile);
-
- /* open pipe */
- if (NIL_P(pmode)) {
- mode = "r";
- }
- else if (FIXNUM_P(pmode)) {
- mode = rb_io_flags_mode(NUM2INT(pmode));
- }
- else {
- int len;
-
- mode = STR2CSTR(pmode);
- len = strlen(mode);
- if (len == 0 || len > 3)
- rb_raise(rb_eArgError, "illegal access mode %s", mode);
- }
-
- port = pipe_open(RSTRING(pname)->ptr+1, mode);
- if (!rb_iterator_p()) return port;
- if (NIL_P(port)) {
- rb_yield(port);
- }
- else if (rb_iterator_p()) {
- return rb_ensure(rb_yield, port, rb_io_close, port);
+ if (str[0] == '|') {
+ return rb_io_popen(str+1, argc, argv, rb_cIO);
+ }
}
-
- return port;
+ return rb_file_s_open(argc, argv, rb_cFile);
}
static VALUE
@@ -2280,12 +2243,44 @@ rb_io_initialize(argc, argv, io)
fp->f = rb_fdopen(NUM2INT(fnum), m);
fp->mode = rb_io_mode_flags(m);
- if (rb_iterator_p()) {
- return rb_ensure(rb_yield, io, rb_io_close, io);
- }
return io;
}
+static VALUE
+rb_file_initialize(argc, argv, io)
+ int argc;
+ VALUE *argv;
+ VALUE io;
+{
+ VALUE fname, vmode, file, perm;
+ char *path, *mode;
+
+ rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
+ Check_SafeStr(fname);
+ path = RSTRING(fname)->ptr;
+
+ if (FIXNUM_P(vmode)) {
+ int flags = NUM2INT(vmode);
+ int fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
+
+ file = rb_file_sysopen_internal(io, path, flags, fmode);
+ }
+ else {
+ if (NIL_P(vmode)) {
+ mode = "r";
+ }
+ else {
+ mode = STR2CSTR(vmode);
+ }
+ file = rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
+ }
+ if (rb_block_given_p()) {
+ rb_warn("File::new() does not take block; use File::open() instead");
+ }
+
+ return file;
+}
+
static int binmode = 0;
static VALUE
@@ -3339,6 +3334,7 @@ Init_IO()
rb_define_method(rb_cIO, "ioctl", rb_io_ioctl, -1);
rb_define_method(rb_cIO, "fcntl", rb_io_fcntl, -1);
+ rb_define_method(rb_cIO, "pid", rb_io_pid, 0);
rb_stdin = orig_stdin = prep_stdio(stdin, FMODE_READABLE, rb_cIO);
rb_define_hooked_variable("$stdin", &rb_stdin, 0, set_stdin);
diff --git a/lib/date2.rb b/lib/date2.rb
index cc75577..e1badcd 100644
--- a/lib/date2.rb
+++ b/lib/date2.rb
@@ -1,5 +1,5 @@
# date2.rb: Written by Tadayoshi Funaba 1998-2000
-# $Id: date2.rb,v 1.18 2000/03/20 16:23:32 tadf Exp $
+# $Id: date2.rb,v 1.21 2000/05/14 15:47:09 tadf Exp $
class Date
@@ -115,6 +115,8 @@ class Date
def ld_to_jd(ld) ld + 2299160 end
def jd_to_ld(jd) jd - 2299160 end
+ def jd_to_wday(jd) (jd + 1) % 7 end
+
def julian_leap? (y) y % 4 == 0 end
def gregorian_leap? (y) y % 4 == 0 and y % 100 != 0 or y % 400 == 0 end
@@ -127,8 +129,8 @@ class Date
m += 13
end
if d < 0
- ny, nm = Date.clfloor(y * 12 + m, 12)
- nm, = Date.clfloor(m + 1, 1)
+ ny, nm = clfloor(y * 12 + m, 12)
+ nm, = clfloor(m + 1, 1)
la = nil
31.downto 1 do |z|
break if la = exist3?(y, m, z, sg)
@@ -199,10 +201,9 @@ class Date
def once(*ids)
for id in ids
module_eval <<-"end;"
- alias_method :__#{id.to_i}__, #{id.inspect}
+ alias_method :__#{id.to_i}__, :#{id.id2name}
def #{id.id2name}(*args, &block)
- def self.#{id.id2name}(*args, &block); @__#{id.to_i}__ end
- @__#{id.to_i}__ = __#{id.to_i}__(*args, &block)
+ (@__#{id.to_i}__ ||= [__#{id.to_i}__(*args, &block)])[0]
end
end;
end
@@ -215,79 +216,76 @@ class Date
def initialize(rjd=0, sg=ITALY) @rjd, @sg = rjd, sg end
def rjd() @rjd end
- def rmjd() Date.jd_to_mjd(@rjd) end
- def rtjd() Date.jd_to_tjd(@rjd) end
- def rtjd2() Date.jd_to_tjd2(@rjd) end
+ def rmjd() type.jd_to_mjd(@rjd) end
+ def rtjd() type.jd_to_tjd(@rjd) end
+ def rtjd2() type.jd_to_tjd2(@rjd) end
once :rmjd, :rtjd, :rtjd2
- def jd() Date.rjd_to_jd(@rjd)[0] end
- def fr1() Date.rjd_to_jd(@rjd)[1] end
- def mjd() Date.jd_to_mjd(jd) end
- def tjd() Date.jd_to_tjd(jd) end
- def tjd2() Date.jd_to_tjd2(jd) end
- def ld() Date.jd_to_ld(jd) end
+ def jd() type.rjd_to_jd(@rjd)[0] end
+ def fr1() type.rjd_to_jd(@rjd)[1] end
+ def mjd() type.jd_to_mjd(jd) end
+ def tjd() type.jd_to_tjd(jd) end
+ def tjd2() type.jd_to_tjd2(jd) end
+ def ld() type.jd_to_ld(jd) end
once :jd, :fr1, :mjd, :tjd, :tjd2, :ld
- def civil() Date.jd_to_civil(jd, @sg) end
- def ordinal() Date.jd_to_ordinal(jd, @sg) end
- def commercial() Date.jd_to_commercial(jd, @sg) end
+ def civil() type.jd_to_civil(jd, @sg) end
+ def ordinal() type.jd_to_ordinal(jd, @sg) end
+ def commercial() type.jd_to_commercial(jd, @sg) end
once :civil, :ordinal, :commercial
+ private :civil, :ordinal, :commercial
def year() civil[0] end
def yday() ordinal[1] end
def mon() civil[1] end
alias_method :month, :mon
- once :year, :yday, :mon, :month
def mday() civil[2] end
alias_method :day, :mday
- once :mday, :day
def cwyear() commercial[0] end
def cweek() commercial[1] end
def cwday() commercial[2] end
- once :cwyear, :cweek, :cwday
-
- def wday() (jd + 1) % 7 end
+ def wday() type.jd_to_wday(jd) end
once :wday
- def os? () Date.os?(jd, @sg) end
- def ns? () Date.ns?(jd, @sg) end
+ def os? () type.os?(jd, @sg) end
+ def ns? () type.ns?(jd, @sg) end
once :os?, :ns?
def leap?
- Date.jd_to_civil(Date.civil_to_jd(year, 3, 1, ns?) - 1,
+ type.jd_to_civil(type.civil_to_jd(year, 3, 1, ns?) - 1,
ns?)[-1] == 29
end
once :leap?
def sg() @sg end
- def newsg(sg=Date::ITALY) Date.new(@rjd, sg) end
+ def newsg(sg=type::ITALY) type.new(@rjd, sg) end
- def italy() newsg(Date::ITALY) end
- def england() newsg(Date::ENGLAND) end
- def julian() newsg(Date::JULIAN) end
- def gregorian() newsg(Date::GREGORIAN) end
+ def italy() newsg(type::ITALY) end
+ def england() newsg(type::ENGLAND) end
+ def julian() newsg(type::JULIAN) end
+ def gregorian() newsg(type::GREGORIAN) end
def + (n)
case n
- when Numeric; return Date.new(@rjd + n, @sg)
+ when Numeric; return type.new(@rjd + n, @sg)
end
fail TypeError, 'expected numeric'
end
def - (x)
case x
- when Numeric; return Date.new(@rjd - x, @sg)
+ when Numeric; return type.new(@rjd - x, @sg)
when Date; return @rjd - x.rjd
end
fail TypeError, 'expected numeric or date'
@@ -310,27 +308,21 @@ class Date
end
def >> (n)
- y, m = Date.clfloor(year * 12 + (mon - 1) + n, 12)
- m, = Date.clfloor(m + 1, 1)
+ y, m = type.clfloor(year * 12 + (mon - 1) + n, 12)
+ m, = type.clfloor(m + 1, 1)
d = mday
- d -= 1 until jd2 = Date.exist3?(y, m, d, ns?)
+ d -= 1 until jd2 = type.exist3?(y, m, d, ns?)
self + (jd2 - jd)
end
def << (n) self >> -n end
def step(limit, step)
- rjd = @rjd
- if (step > 0)
- while rjd <= limit.rjd
- yield Date.new(rjd, @sg)
- rjd += step
- end
- else
- while rjd >= limit.rjd
- yield Date.new(rjd, @sg)
- rjd += step
- end
+ da = self
+ op = [:-,:<=,:>=][step<=>0]
+ while da.__send__(op, limit)
+ yield da
+ da += step
end
self
end
@@ -343,11 +335,12 @@ class Date
alias_method :next, :succ
def eql? (other) Date === other and self == other end
- def hash() Date.clfloor(@rjd)[0] end
- def inspect() format('#<Date: %s,%s>', @rjd, @sg) end
+ def hash() type.clfloor(@rjd)[0] end
+
+ def inspect() format('#<%s: %s,%s>', type, @rjd, @sg) end
def to_s() format('%.4d-%02d-%02d', year, mon, mday) end
def _dump(limit) Marshal.dump([@rjd, @sg], -1) end
- def Date._load(str) Date.new(*Marshal.load(str)) end
+ def self._load(str) new(*Marshal.load(str)) end
end
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 0cd91f3..3c51480 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -333,11 +333,6 @@ def create_makefile(target)
$DLDFLAGS = $DLDFLAGS + " -L$(topdir)"
end
- if RUBY_PLATFORM =~ /beos/
- $libs = $libs + " " + CONFIG["LIBRUBYARG"]
- $DLDFLAGS = $DLDFLAGS + " -L" + CONFIG["prefix"] + "/lib"
- end
-
defflag = ''
if RUBY_PLATFORM =~ /cygwin|mingw/
if File.exist? target + ".def"
@@ -447,19 +442,6 @@ EOMF
dfile.close
end
mfile.close
-
- if RUBY_PLATFORM =~ /beos/
- if RUBY_PLATFORM =~ /^powerpc/ then
- deffilename = "ruby.exp"
- else
- deffilename = "ruby.def"
- end
- print "creating #{deffilename}\n"
- open(deffilename, "w") do |file|
- file.print("EXPORTS\n") if RUBY_PLATFORM =~ /^i/
- file.print("Init_#{target}\n")
- end
- end
end
$OBJEXT = CONFIG["OBJEXT"]
diff --git a/marshal.c b/marshal.c
index c25e0cb..dd8376a 100644
--- a/marshal.c
+++ b/marshal.c
@@ -148,7 +148,7 @@ w_symbol(id, arg)
struct dump_arg *arg;
{
char *sym = rb_id2name(id);
- int num;
+ long num;
if (st_lookup(arg->symbol, id, &num)) {
w_byte(TYPE_SYMLINK, arg);
@@ -258,7 +258,7 @@ w_object(obj, arg, limit)
return;
}
else {
- int num;
+ long num;
limit--;
c_arg.limit = limit;
@@ -381,7 +381,7 @@ w_object(obj, arg, limit)
w_long(len, arg);
mem = rb_ivar_get(CLASS_OF(obj), rb_intern("__member__"));
if (mem == Qnil) {
- rb_raise(rb_eTypeError, "non-initialized struct");
+ rb_raise(rb_eTypeError, "uninitialized struct");
}
for (i=0; i<len; i++) {
w_symbol(FIX2LONG(RARRAY(mem)->ptr[i]), arg);
@@ -813,7 +813,7 @@ r_object(arg)
klass = rb_path2class(r_unique(arg));
mem = rb_ivar_get(klass, rb_intern("__member__"));
if (mem == Qnil) {
- rb_raise(rb_eTypeError, "non-initialized struct");
+ rb_raise(rb_eTypeError, "uninitialized struct");
}
len = r_long(arg);
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index a882f9f..a0a770b 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -14,7 +14,11 @@
(substring ruby-mode-revision (match-beginning 0) (match-end 0))))
(defconst ruby-block-beg-re
- "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do"
+ "class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin"
+ )
+
+(defconst ruby-non-block-do-re
+ "while\\|until\\|for\\|rescue"
)
(defconst ruby-indent-beg-re
@@ -372,6 +376,39 @@ The variable ruby-indent-level controls the amount of indentation.
(goto-char (match-end 0)))
((looking-at ruby-block-beg-re)
(and
+ (or (not (looking-at "do\\>[^_]"))
+ (save-excursion
+ (back-to-indentation)
+ (not (looking-at ruby-non-block-do-re))))
+ (or (bolp)
+ (progn
+ (forward-char -1)
+ (setq w (char-after (point)))
+ (not (or (eq ?_ w)
+ (eq ?. w)))))
+ (goto-char pnt)
+ (setq w (char-after (point)))
+ (not (eq ?_ w))
+ (not (eq ?! w))
+ (not (eq ?? w))
+ (skip-chars-forward " \t")
+ (if (not (eolp))
+ (progn
+ (goto-char (match-beginning 0))
+ (if (looking-at ruby-modifier-re)
+ (ruby-expr-beg 'modifier)
+ t))
+ t)
+ (goto-char pnt)
+ (setq nest (cons (cons nil pnt) nest))
+ (setq depth (1+ depth)))
+ (goto-char pnt))
+ ((looking-at ruby-block-beg-re)
+ (and
+ (or (not (looking-at "do\\>[^_]"))
+ (save-excursion
+ (back-to-indentation)
+ (not (looking-at ruby-non-block-do-re))))
(or (bolp)
(progn
(forward-char -1)
@@ -462,7 +499,7 @@ The variable ruby-indent-level controls the amount of indentation.
(goto-char (cdr (nth 1 state)))
(forward-word -1) ; skip back a keyword
(cond
- ((looking-at "do") ; iter block is a special case
+ ((looking-at "do\\>[^_]") ; iter block is a special case
(cond
((nth 3 state)
(goto-char (nth 3 state))
diff --git a/node.h b/node.h
index cfa3cfa..ce9659a 100644
--- a/node.h
+++ b/node.h
@@ -135,15 +135,15 @@ typedef struct RNode {
union {
struct RNode *node;
ID id;
- int argc;
+ long argc;
VALUE value;
} u2;
union {
struct RNode *node;
ID id;
- int state;
+ long state;
struct global_entry *entry;
- int cnt;
+ long cnt;
VALUE value;
} u3;
} NODE;
diff --git a/object.c b/object.c
index ce3eb2c..1a8e203 100644
--- a/object.c
+++ b/object.c
@@ -159,9 +159,8 @@ inspect_i(id, value, str)
/* need not to show internal data */
if (CLASS_OF(value) == 0) return ST_CONTINUE;
if (!rb_is_instance_id(id)) return ST_CONTINUE;
- if (RSTRING(str)->ptr[0] == '-') {
+ if (RSTRING(str)->ptr[0] == '-') { /* first element */
RSTRING(str)->ptr[0] = '#';
- rb_str_cat2(str, ": ");
}
else {
rb_str_cat2(str, ", ");
@@ -195,16 +194,17 @@ rb_obj_inspect(obj)
&& ROBJECT(obj)->iv_tbl
&& ROBJECT(obj)->iv_tbl->num_entries > 0) {
VALUE str;
- char *b;
+ char *c, *b;
- b = rb_class2name(CLASS_OF(obj));
+ c = rb_class2name(CLASS_OF(obj));
if (rb_inspecting_p(obj)) {
- char *buf = ALLOCA_N(char, strlen(b)+8);
- sprintf(buf, "#<%s:...>", b);
- return rb_str_new2(buf);
+ b = ALLOCA_N(char, strlen(c)+8+16+1); /* 8:tags 16:addr 1:eos */
+ sprintf(b, "#<%s:0x%lx ...>", c, obj);
+ return rb_str_new2(b);
}
- str = rb_str_new2("-<");
- rb_str_cat2(str, b);
+ b = ALLOCA_N(char, strlen(c)+4+16+1); /* 4:tags 16:addr 1:eos */
+ sprintf(b, "-<%s:0x%lx ", c, obj);
+ str = rb_str_new2(b);
return rb_protect_inspect(inspect_obj, obj, str);
}
return rb_funcall(obj, rb_intern("to_s"), 0, 0);
@@ -630,6 +630,7 @@ rb_module_s_new(klass)
VALUE mod = rb_module_new();
RBASIC(mod)->klass = klass;
+ rb_obj_call_init(klass, 0, 0);
return mod;
}
@@ -651,6 +652,7 @@ rb_class_s_new(argc, argv)
/* make metaclass */
RBASIC(klass)->klass = rb_singleton_class_new(RBASIC(super)->klass);
rb_singleton_class_attached(RBASIC(klass)->klass, klass);
+ rb_obj_call_init(klass, argc, argv);
rb_funcall(super, rb_intern("inherited"), 1, klass);
return klass;
@@ -1086,7 +1088,7 @@ Init_Object()
rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, 0);
rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0);
rb_define_private_method(rb_mKernel, "remove_instance_variable",
- rb_obj_remove_instance_variable, 0);
+ rb_obj_remove_instance_variable, 1);
rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1);
rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1);
diff --git a/pack.c b/pack.c
index 028bedd..2e1d5ec 100644
--- a/pack.c
+++ b/pack.c
@@ -23,9 +23,9 @@
#ifdef NATINT_PACK
# define NATINT_LEN(type,len) (natint?sizeof(type):(len))
-# ifndef WORDS_BIGENDIAN
-# define OFF16(p) ((char*)(p) + (natint?(sizeof(short) - 2):0))
-# define OFF32(p) ((char*)(p) + (natint?(sizeof(long) - 4):0))
+# ifdef WORDS_BIGENDIAN
+# define OFF16(p) ((char*)(p) + (natint?0:(sizeof(short) - 2)))
+# define OFF32(p) ((char*)(p) + (natint?0:(sizeof(long) - 4)))
# endif
#else
# define NATINT_LEN(type,len) sizeof(type)
diff --git a/parse.y b/parse.y
index 8c63488..f292e77 100644
--- a/parse.y
+++ b/parse.y
@@ -2256,7 +2256,7 @@ parse_regx(term, paren)
case 'x':
options |= RE_OPTION_EXTENDED;
break;
- case 'p': /* /p is obsolete, works as /m */
+ case 'p': /* /p is obsolete */
rb_warn("/p option is obsolete; use /m\n\tnote: /m does not change ^, $ behavior");
options |= RE_OPTION_POSIXLINE;
break;
diff --git a/process.c b/process.c
index 3729917..bd078a3 100644
--- a/process.c
+++ b/process.c
@@ -509,7 +509,7 @@ rb_f_fork(obj)
#ifdef linux
after_exec();
#endif
- if (rb_iterator_p()) {
+ if (rb_block_given_p()) {
rb_yield(Qnil);
_exit(0);
}
diff --git a/re.c b/re.c
index 4b14001..9861d52 100644
--- a/re.c
+++ b/re.c
@@ -1060,22 +1060,20 @@ static int
rb_reg_get_kcode(re)
VALUE re;
{
- int kcode = 0;
+ int kcode;
switch (RBASIC(re)->flags & KCODE_MASK) {
case KCODE_NONE:
- kcode |= 16; break;
+ return 16;
case KCODE_EUC:
- kcode |= 32; break;
+ return 32;
case KCODE_SJIS:
- kcode |= 48; break;
+ return 48;
case KCODE_UTF8:
- kcode |= 64; break;
+ return 64;
default:
- break;
+ return 0;
}
-
- return kcode;
}
int
diff --git a/regex.c b/regex.c
index d38f640..156e75b 100644
--- a/regex.c
+++ b/regex.c
@@ -232,27 +232,27 @@ re_set_casetable(table)
#endif
#ifdef isblank
-# define ISBLANK(c) (ISASCII (c) && isblank (c))
+# define ISBLANK(c) (ISASCII(c) && isblank(c))
#else
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
#endif
#ifdef isgraph
-# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
+# define ISGRAPH(c) (ISASCII(c) && isgraph(c))
#else
-# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
+# define ISGRAPH(c) (ISASCII(c) && isprint(c) && !isspace(c))
#endif
#undef ISPRINT
-#define ISPRINT(c) (ISASCII (c) && isprint (c))
-#define ISDIGIT(c) (ISASCII (c) && isdigit (c))
-#define ISALNUM(c) (ISASCII (c) && isalnum (c))
-#define ISALPHA(c) (ISASCII (c) && isalpha (c))
-#define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
-#define ISLOWER(c) (ISASCII (c) && islower (c))
-#define ISPUNCT(c) (ISASCII (c) && ispunct (c))
-#define ISSPACE(c) (ISASCII (c) && isspace (c))
-#define ISUPPER(c) (ISASCII (c) && isupper (c))
-#define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
+#define ISPRINT(c) (ISASCII(c) && isprint(c))
+#define ISDIGIT(c) (ISASCII(c) && isdigit(c))
+#define ISALNUM(c) (ISASCII(c) && isalnum(c))
+#define ISALPHA(c) (ISASCII(c) && isalpha(c))
+#define ISCNTRL(c) (ISASCII(c) && iscntrl(c))
+#define ISLOWER(c) (ISASCII(c) && islower(c))
+#define ISPUNCT(c) (ISASCII(c) && ispunct(c))
+#define ISSPACE(c) (ISASCII(c) && isspace(c))
+#define ISUPPER(c) (ISASCII(c) && isupper(c))
+#define ISXDIGIT(c) (ISASCII(c) && isxdigit(c))
#ifndef NULL
# define NULL (void *)0
@@ -264,10 +264,10 @@ re_set_casetable(table)
(Per Bothner suggested the basic approach.) */
#undef SIGN_EXTEND_CHAR
#if __STDC__
-# define SIGN_EXTEND_CHAR(c) ((signed char) (c))
+# define SIGN_EXTEND_CHAR(c) ((signed char)(c))
#else /* not __STDC__ */
/* As in Harbison and Steele. */
-# define SIGN_EXTEND_CHAR(c) ((((unsigned char) (c)) ^ 128) - 128)
+# define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
#endif
/* These are the command codes that appear in compiled regular
@@ -350,10 +350,7 @@ enum regexpcode
stop_paren, /* Place holder at the end of (?:..). */
casefold_on, /* Turn on casefold flag. */
casefold_off, /* Turn off casefold flag. */
- mline_on, /* Turn on multi line match (match with newlines). */
- mline_off, /* Turn off multi line match. */
- posix_on, /* Turn on POSIXified line match (match with newlines). */
- posix_off, /* Turn off POSIXified line match. */
+ option_set, /* Turn on multi line match (match with newlines). */
start_nowidth, /* Save string point to the stack. */
stop_nowidth, /* Restore string place at the point start_nowidth. */
pop_and_fail, /* Fail after popping nowidth entry from stack. */
@@ -395,7 +392,7 @@ enum regexpcode
at SOURCE. */
#define EXTRACT_NUMBER(destination, source) \
do { (destination) = *(source) & 0377; \
- (destination) += SIGN_EXTEND_CHAR (*(char*)((source) + 1)) << 8; } while (0)
+ (destination) += SIGN_EXTEND_CHAR(*(char*)((source) + 1)) << 8; } while (0)
/* Same as EXTRACT_NUMBER, except increment the pointer for source to
point to second byte of SOURCE. Note that SOURCE has to be a value
@@ -538,7 +535,7 @@ print_mbc(c)
if (bufp->allocated == (1L<<16)) goto too_big; \
bufp->allocated *= 2; \
if (bufp->allocated > (1L<<16)) bufp->allocated = (1L<<16); \
- bufp->buffer = (char*)xrealloc (bufp->buffer, bufp->allocated); \
+ bufp->buffer = (char*)xrealloc(bufp->buffer, bufp->allocated); \
if (bufp->buffer == 0) \
goto memory_exhausted; \
b = (b - old_buffer) + bufp->buffer; \
@@ -572,7 +569,7 @@ print_mbc(c)
} \
} while (0)
-#define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
+#define STREQ(s1, s2) ((strcmp(s1, s2) == 0))
#define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
@@ -766,22 +763,12 @@ print_partial_compiled_pattern(start, end)
printf("/casefold_off");
break;
- case mline_on:
- printf("/mline_on");
+ case option_set:
+ printf("/option_set/%d", *p++);
break;
- case mline_off:
- printf("/mline_off");
- break;
-
- case posix_on:
- printf("/posix_on");
-
- case posix_off:
- printf("/posix_off");
-
case start_nowidth:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/start_nowidth//%d", mcnt);
break;
@@ -851,12 +838,12 @@ print_partial_compiled_pattern(start, end)
break;
case on_failure_jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/on_failure_jump//%d", mcnt);
break;
case dummy_failure_jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/dummy_failure_jump//%d", mcnt);
break;
@@ -865,56 +852,56 @@ print_partial_compiled_pattern(start, end)
break;
case finalize_jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/finalize_jump//%d", mcnt);
break;
case maybe_finalize_jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/maybe_finalize_jump//%d", mcnt);
break;
case jump_past_alt:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/jump_past_alt//%d", mcnt);
break;
case jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/jump//%d", mcnt);
break;
case succeed_n:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
- EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
printf("/succeed_n//%d//%d", mcnt, mcnt2);
break;
case jump_n:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
- EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
printf("/jump_n//%d//%d", mcnt, mcnt2);
break;
case set_number_at:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
- EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
printf("/set_number_at//%d//%d", mcnt, mcnt2);
break;
case try_next:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/try_next//%d", mcnt);
break;
case finalize_push:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
printf("/finalize_push//%d", mcnt);
break;
case finalize_push_n:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
- EXTRACT_NUMBER_AND_INCR (mcnt2, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt2, p);
printf("/finalize_push_n//%d//%d", mcnt, mcnt2);
break;
@@ -971,7 +958,7 @@ print_compiled_pattern(bufp)
{
unsigned char *buffer = (unsigned char*)bufp->buffer;
- print_partial_compiled_pattern (buffer, buffer + bufp->used);
+ print_partial_compiled_pattern(buffer, buffer + bufp->used);
}
static char*
@@ -1033,10 +1020,7 @@ calculate_must_string(start, end)
case push_dummy_failure:
case start_paren:
case stop_paren:
- case mline_on:
- case mline_off:
- case posix_on:
- case posix_off:
+ case option_set:
break;
case charset:
@@ -1050,11 +1034,11 @@ calculate_must_string(start, end)
break;
case on_failure_jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
if (mcnt > 0) p += mcnt;
if ((enum regexpcode)p[-3] == jump) {
p -= 3;
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
if (mcnt > 0) p += mcnt;
}
break;
@@ -1063,7 +1047,7 @@ calculate_must_string(start, end)
case succeed_n:
case try_next:
case jump:
- EXTRACT_NUMBER_AND_INCR (mcnt, p);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p);
if (mcnt > 0) p += mcnt;
break;
@@ -1260,6 +1244,7 @@ re_compile_pattern(pattern, size, bufp)
int had_char_class = 0;
int options = bufp->options;
+ int old_options = 0;
bufp->fastmap_accurate = 0;
bufp->must = 0;
@@ -1273,7 +1258,7 @@ re_compile_pattern(pattern, size, bufp)
bufp->allocated = INIT_BUF_SIZE;
if (bufp->buffer)
/* EXTEND_BUFFER loses when bufp->allocated is 0. */
- bufp->buffer = (char*)xrealloc (bufp->buffer, INIT_BUF_SIZE);
+ bufp->buffer = (char*)xrealloc(bufp->buffer, INIT_BUF_SIZE);
else
/* Caller did not allocate a buffer. Do it for them. */
bufp->buffer = (char*)xmalloc(INIT_BUF_SIZE);
@@ -1286,7 +1271,7 @@ re_compile_pattern(pattern, size, bufp)
switch (c) {
case '$':
- if (bufp->options & RE_OPTION_POSIXLINE) {
+ if (bufp->options & RE_OPTION_SINGLELINE) {
BUFPUSH(endbuf);
}
else {
@@ -1306,7 +1291,7 @@ re_compile_pattern(pattern, size, bufp)
break;
case '^':
- if (bufp->options & RE_OPTION_POSIXLINE)
+ if (bufp->options & RE_OPTION_SINGLELINE)
BUFPUSH(begbuf);
else
BUFPUSH(begline);
@@ -1576,7 +1561,7 @@ re_compile_pattern(pattern, size, bufp)
/* Leave room for the null. */
char str[CHAR_CLASS_MAX_LENGTH + 1];
- PATFETCH_RAW (c);
+ PATFETCH_RAW(c);
c1 = 0;
/* If pattern is `[[:'. */
@@ -1610,11 +1595,11 @@ re_compile_pattern(pattern, size, bufp)
char is_upper = STREQ(str, "upper");
char is_xdigit = STREQ(str, "xdigit");
- if (!IS_CHAR_CLASS (str))
+ if (!IS_CHAR_CLASS(str))
goto invalid_pattern;
/* Throw away the ] at the end of the character class. */
- PATFETCH (c);
+ PATFETCH(c);
if (p == pend)
goto invalid_pattern;
@@ -1632,7 +1617,7 @@ re_compile_pattern(pattern, size, bufp)
|| (is_space && ISSPACE(ch))
|| (is_upper && ISUPPER(ch))
|| (is_xdigit && ISXDIGIT(ch)))
- SET_LIST_BIT (ch);
+ SET_LIST_BIT(ch);
}
had_char_class = 1;
}
@@ -1661,14 +1646,16 @@ re_compile_pattern(pattern, size, bufp)
b[-1]--;
if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH)
memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH],
- 2 + EXTRACT_UNSIGNED (&b[(1 << BYTEWIDTH) / BYTEWIDTH])*8);
- b += b[-1] + 2 + EXTRACT_UNSIGNED (&b[b[-1]])*8;
+ 2 + EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH])*8);
+ b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[b[-1]])*8;
break;
case '(':
+ old_options = options;
PATFETCH(c);
if (c == '?') {
int negative = 0;
+ int push_option = 0;
PATFETCH_RAW(c);
switch (c) {
case 'x': case 'p': case 'm': case 'i': case '-':
@@ -1691,28 +1678,26 @@ re_compile_pattern(pattern, size, bufp)
case 'p':
if (negative) {
- if (options&RE_OPTION_POSIXLINE) {
+ if ((options&RE_OPTION_POSIXLINE) == RE_OPTION_POSIXLINE) {
options &= ~RE_OPTION_POSIXLINE;
- BUFPUSH(posix_off);
}
}
- else if (!(options&RE_OPTION_POSIXLINE)) {
+ else if ((options&RE_OPTION_POSIXLINE) != RE_OPTION_POSIXLINE) {
options |= RE_OPTION_POSIXLINE;
- BUFPUSH(posix_on);
}
+ push_option = 1;
break;
case 'm':
if (negative) {
if (options&RE_OPTION_MULTILINE) {
options &= ~RE_OPTION_MULTILINE;
- BUFPUSH(mline_off);
}
}
else if (!(options&RE_OPTION_MULTILINE)) {
options |= RE_OPTION_MULTILINE;
- BUFPUSH(mline_on);
}
+ push_option = 1;
break;
case 'i':
@@ -1757,6 +1742,10 @@ re_compile_pattern(pattern, size, bufp)
default:
FREE_AND_RETURN(stackb, "undefined (?...) sequence");
}
+ if (push_option) {
+ BUFPUSH(option_set);
+ BUFPUSH(options);
+ }
}
else {
PATUNFETCH;
@@ -1813,7 +1802,7 @@ re_compile_pattern(pattern, size, bufp)
break;
}
*stackp++ = c;
- *stackp++ = options;
+ *stackp++ = old_options;
fixup_alt_jump = 0;
laststart = 0;
begalt = b;
@@ -1822,14 +1811,13 @@ re_compile_pattern(pattern, size, bufp)
case ')':
if (stackp == stackb)
FREE_AND_RETURN(stackb, "unmatched )");
- if ((options ^ stackp[-1]) & RE_OPTION_IGNORECASE) {
- BUFPUSH((options&RE_OPTION_IGNORECASE)?casefold_off:casefold_on);
- }
- if ((options ^ stackp[-1]) & RE_OPTION_POSIXLINE) {
- BUFPUSH((options&RE_OPTION_MULTILINE)?posix_off:posix_on);
- }
- if ((options ^ stackp[-1]) & RE_OPTION_MULTILINE) {
- BUFPUSH((options&RE_OPTION_MULTILINE)?mline_off:mline_on);
+
+ if (options != stackp[-1]) {
+ if ((options ^ stackp[-1]) & RE_OPTION_IGNORECASE) {
+ BUFPUSH((options&RE_OPTION_IGNORECASE)?casefold_off:casefold_on);
+ }
+ BUFPUSH(option_set);
+ BUFPUSH(stackp[-1]);
}
pending_exact = 0;
if (fixup_alt_jump) {
@@ -2111,7 +2099,7 @@ re_compile_pattern(pattern, size, bufp)
beg_interval = 0;
/* normal_char and normal_backslash need `c'. */
- PATFETCH (c);
+ PATFETCH(c);
goto normal_char;
case '\\':
@@ -2195,7 +2183,7 @@ re_compile_pattern(pattern, size, bufp)
break;
case 'Z':
- if ((bufp->options & RE_OPTION_POSIXLINE) == 0) {
+ if ((bufp->options & RE_OPTION_SINGLELINE) == 0) {
BUFPUSH(endbuf2);
break;
}
@@ -2789,14 +2777,8 @@ re_compile_fastmap(bufp)
options ^= RE_OPTION_IGNORECASE;
continue;
- case mline_on:
- case mline_off:
- options ^= RE_OPTION_MULTILINE;
- continue;
-
- case posix_on:
- case posix_off:
- options ^= RE_OPTION_POSIXLINE;
+ case option_set:
+ options = *p++;
continue;
case endline:
@@ -2804,7 +2786,7 @@ re_compile_fastmap(bufp)
fastmap[translate['\n']] = 1;
else
fastmap['\n'] = 1;
- if ((options & RE_OPTION_POSIXLINE) == 0 && bufp->can_be_null == 0)
+ if ((options & RE_OPTION_SINGLELINE) == 0 && bufp->can_be_null == 0)
bufp->can_be_null = 2;
break;
@@ -2889,7 +2871,7 @@ re_compile_fastmap(bufp)
case anychar_repeat:
case anychar:
for (j = 0; j < (1 << BYTEWIDTH); j++) {
- if (j != '\n' || (options & RE_OPTION_POSIXLINE))
+ if (j != '\n' || (options & RE_OPTION_MULTILINE))
fastmap[j] = 1;
}
if (bufp->can_be_null) {
@@ -3167,7 +3149,7 @@ re_search(bufp, string, size, startpos, range, regs)
}
}
if (bufp->options & RE_OPTIMIZE_ANCHOR) {
- if (bufp->options&RE_OPTION_POSIXLINE) {
+ if (bufp->options&RE_OPTION_SINGLELINE) {
goto begbuf_match;
}
anchor = 1;
@@ -3783,9 +3765,8 @@ re_match(bufp, string_arg, size, pos, regs)
d += mbclen(*d);
break;
}
- if (!(options&RE_OPTION_MULTILINE) &&
- !(options&RE_OPTION_POSIXLINE) &&
- (TRANSLATE_P() ? translate[*d] : *d) == '\n')
+ if (!(options&RE_OPTION_MULTILINE)
+ && (TRANSLATE_P() ? translate[*d] : *d) == '\n')
goto fail;
SET_REGS_MATCHED;
d++;
@@ -4132,20 +4113,8 @@ re_match(bufp, string_arg, size, pos, regs)
options &= ~RE_OPTION_IGNORECASE;
continue;
- case mline_on:
- options |= RE_OPTION_MULTILINE;
- continue;
-
- case mline_off:
- options &= ~RE_OPTION_MULTILINE;
- continue;
-
- case posix_on:
- options |= RE_OPTION_POSIXLINE;
- continue;
-
- case posix_off:
- options &= ~RE_OPTION_POSIXLINE;
+ case option_set:
+ options = *p++;
continue;
case wordbound:
@@ -4308,7 +4277,7 @@ re_match(bufp, string_arg, size, pos, regs)
case finalize_push:
case jump:
p1++;
- EXTRACT_NUMBER_AND_INCR (mcnt, p1);
+ EXTRACT_NUMBER_AND_INCR(mcnt, p1);
if (mcnt >= 0) break; /* should be backward jump */
p1 += mcnt;
diff --git a/regex.h b/regex.h
index 80369d4..3c2d1ad 100644
--- a/regex.h
+++ b/regex.h
@@ -69,12 +69,14 @@
#define RE_OPTION_IGNORECASE (1L)
/* perl-style extended pattern available */
#define RE_OPTION_EXTENDED (RE_OPTION_IGNORECASE<<1)
-/* newline will be included for ., ^ and $ ignore newline */
-#define RE_OPTION_POSIXLINE (RE_OPTION_EXTENDED<<1)
/* newline will be included for . */
-#define RE_OPTION_MULTILINE (RE_OPTION_POSIXLINE<<1)
+#define RE_OPTION_MULTILINE (RE_OPTION_EXTENDED<<1)
+/* ^ and $ ignore newline */
+#define RE_OPTION_SINGLELINE (RE_OPTION_MULTILINE<<1)
+/* works line Perl's /s; it's called POSIX for wrong reason */
+#define RE_OPTION_POSIXLINE (RE_OPTION_MULTILINE|RE_OPTION_SINGLELINE)
/* search for longest match, in accord with POSIX regexp */
-#define RE_OPTION_LONGEST (RE_OPTION_MULTILINE<<1)
+#define RE_OPTION_LONGEST (RE_OPTION_POSIXLINE<<1)
#define RE_MAY_IGNORECASE (RE_OPTION_LONGEST<<1)
#define RE_OPTIMIZE_ANCHOR (RE_MAY_IGNORECASE<<1)
diff --git a/ruby.1 b/ruby.1
index 3c71b9c..d81833b 100644
--- a/ruby.1
+++ b/ruby.1
@@ -6,7 +6,7 @@ ruby - Interpreted object-oriented scripting language
.SH SYNOPSIS
.B ruby \c
[ \c
-.BI -version \c
+.BI --version \c
] [ \c
.BI -c \c
] [ \c
@@ -48,7 +48,7 @@ ruby - Interpreted object-oriented scripting language
] [ \c
.BI -x "[directory]"\c
] [ \c
-.BI -X "directory"\c
+.BI -C "directory"\c
]
[ \c
.BI -y \c
diff --git a/ruby.c b/ruby.c
index 326c98d..0f32f6c 100644
--- a/ruby.c
+++ b/ruby.c
@@ -641,7 +641,6 @@ proc_options(argc, argv)
addpath(getenv("RUBYLIB"));
}
-
process_sflag();
xflag = 0;
}
diff --git a/ruby.h b/ruby.h
index 40c88fe..82d1db8 100644
--- a/ruby.h
+++ b/ruby.h
@@ -455,7 +455,7 @@ void rb_warning __((const char*, ...)); /* reports if `-w' specified */
VALUE rb_each _((VALUE));
VALUE rb_yield _((VALUE));
-int rb_iterator_p _((void));
+int rb_block_given_p _((void));
VALUE rb_iterate _((VALUE(*)(),VALUE,VALUE(*)(),VALUE));
VALUE rb_rescue _((VALUE(*)(),VALUE,VALUE(*)(),VALUE));
VALUE rb_ensure _((VALUE(*)(),VALUE,VALUE(*)(),VALUE));
diff --git a/sample/cal.rb b/sample/cal.rb
index 8eea4ab..c15bb29 100644
--- a/sample/cal.rb
+++ b/sample/cal.rb
@@ -1,9 +1,10 @@
#! /usr/local/bin/ruby
-# cal.rb: Written by Tadayoshi Funaba 1998, 1999
-# $Id: cal.rb,v 1.6 1999/09/15 05:35:25 tadf Exp $
+# cal.rb: Written by Tadayoshi Funaba 1998-2000
+# $Id: cal.rb,v 1.10 2000/05/20 02:09:47 tadf Exp $
require 'date2'
+require 'getopts'
$tab =
{
@@ -31,89 +32,81 @@ $tab =
$cc = 'gb'
def usage
- $stderr.puts 'usage: cal [-c iso3166] [-jy] [[month] year]'
+ $stderr.puts 'usage: cal [-c iso3166] [-jmty] [[month] year]'
exit 1
end
-def cal(m, y, sg)
- for d in 1..31
- break if jd = Date.exist?(y, m, d, sg)
- end
- fst = cur = Date.new1(jd, sg)
- ti = Date::MONTHNAMES[m]
- ti << ' ' << y.to_s unless $yr
- mo = ti.center((($w + 1) * 7) - 1) << "\n"
- mo << ['S', 'M', 'Tu', 'W', 'Th', 'F', 'S'].
- collect{|x| x.rjust($w)}.join(' ') << "\n"
- mo << ' ' * (($w + 1) * fst.wday)
- while cur.mon == fst.mon
- mo << (if $jd then cur.yday else cur.mday end).to_s.rjust($w)
- mo << (if (cur += 1).wday != 0 then "\s" else "\n" end)
- end
- mo << "\n" * (6 - ((fst.wday + (cur - fst)) / 7))
- mo
+def pict(y, m, sg)
+ d = (1..31).detect{|d| Date.exist?(y, m, d, sg)}
+ fi = Date.new3(y, m, d, sg)
+ fi -= (fi.jd - $k + 1) % 7
+
+ ve = (fi..fi + 6).collect{|cu|
+ %w(S M Tu W Th F S)[cu.wday]
+ }
+ ve += (fi..fi + 41).collect{|cu|
+ if cu.mon == m then cu.send($da) end.to_s
+ }
+
+ ve = ve.collect{|e| e.rjust($dw)}
+
+ gr = group(ve, 7)
+ gr = trans(gr) if $OPT_t
+ ta = gr.collect{|xs| xs.join(' ')}
+
+ ca = %w(January February March April
+ May June July August
+ September October November December)[m - 1]
+ ca = ca + ' ' + y.to_s if not $OPT_y
+ ca = ca.center($mw)
+
+ ta.unshift(ca)
end
-def zip(xs)
- yr = ''
- until xs.empty?
- ln = (if $jd then l, r, *xs = xs; [l, r]
- else l, c, r, *xs = xs; [l, c, r] end).
- collect{|x| x.split(/\n/no, -1)}
- 8.times do
- yr << ln.collect{|x|
- x.shift.ljust((($w + 1) * 7) - 1)}.join(' ') << "\n"
- end
- end
- yr
+def group(xs, n)
+ (0..xs.size / n - 1).collect{|i| xs[i * n, n]}
end
-while /^-([^-].*)$/no =~ $*[0]
- a = $1
- if /^c(.+)?$/no =~ a
- if $1
- $cc = $1.downcase
- elsif $*.length >= 2
- $cc = $*[1].downcase
- $*.shift
- else
- usage
- end
- else
- a.scan(/./no) do |c|
- case c
- when 'j'; $jd = true
- when 'y'; $yr = true
- else usage
- end
- end
- end
- $*.shift
+def trans(xs)
+ (0..xs[0].size - 1).collect{|i| xs.collect{|x| x[i]}}
end
-$*.shift if /^--/no =~ $*[0]
-usage if (sg = $tab[$cc]).nil?
-case $*.length
-when 0
- td = Date.today
- m = td.mon
- y = td.year
-when 1
- y = $*[0].to_i
- $yr = true
-when 2
- m = $*[0].to_i
- y = $*[1].to_i
-else
- usage
+
+def unite(xs)
+ if xs.empty? then [] else xs[0] + unite(xs[1..-1]) end
end
-usage unless m.nil? or (1..12) === m
-usage unless y >= -4712
-$w = if $jd then 3 else 2 end
-unless $yr
- print cal(m, y, sg)
-else
- print y.to_s.center(((($w + 1) * 7) - 1) *
- (if $jd then 2 else 3 end) +
- (if $jd then 2 else 4 end)), "\n\n",
- zip((1..12).collect{|m| cal(m, y, sg)}), "\n"
+
+def block(xs, n)
+ unite(group(xs, n).collect{|ys| trans(ys).collect{|zs| zs.join(' ')}})
+end
+
+def unlines(xs)
+ xs.collect{|x| x + "\n"}.join
end
+
+usage unless getopts('jmty', "c:#{$cc}")
+
+y, m = ARGV.indexes(1, 0).compact.collect{|x| x.to_i}
+$OPT_y ||= (y and not m)
+
+to = Date.today
+y ||= to.year
+m ||= to.mon
+
+usage unless m >= 1 and m <= 12
+usage unless y >= -4712
+usage unless sg = $tab[$OPT_c]
+
+$dw = if $OPT_j then 3 else 2 end
+$mw = ($dw + 1) * 7 - 1
+$mn = if $OPT_j then 2 else 3 end
+$tw = ($mw + 2) * $mn - 2
+
+$k = if $OPT_m then 1 else 0 end
+$da = if $OPT_j then :yday else :mday end
+
+print (if not $OPT_y
+ unlines(pict(y, m, sg))
+ else
+ y.to_s.center($tw) + "\n\n" +
+ unlines(block((1..12).collect{|m| pict(y, m, sg)}, $mn)) + "\n"
+ end)
diff --git a/sample/test.rb b/sample/test.rb
index 7fe0280..dca87d2 100644
--- a/sample/test.rb
+++ b/sample/test.rb
@@ -971,7 +971,6 @@ File.unlink "script_tmp.bak" or `/bin/rm -f "script_tmp.bak"`
$bad = false
for script in Dir["{lib,sample}/**/*.rb"]
unless `./miniruby -c #{script}`.chomp == "Syntax OK"
- p `./miniruby -c #{script}`.chomp
$bad = true
end
end
diff --git a/string.c b/string.c
index 711f7d8..a7e6082 100644
--- a/string.c
+++ b/string.c
@@ -898,12 +898,13 @@ rb_str_aref_m(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE arg1, arg2;
-
- if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
- return rb_str_substr(str, NUM2INT(arg1), NUM2INT(arg2));
+ if (argc == 2) {
+ return rb_str_substr(str, NUM2INT(argv[0]), NUM2INT(argv[1]));
+ }
+ if (argc != 1) {
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
}
- return rb_str_aref(str, arg1);
+ return rb_str_aref(str, argv[0]);
}
static void
@@ -1029,6 +1030,9 @@ rb_str_aset_m(argc, argv, str)
rb_str_replace(str, beg, len, argv[2]);
return argv[2];
}
+ if (argc != 2) {
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 2)", argc);
+ }
return rb_str_aset(str, argv[0], argv[1]);
}
@@ -1038,43 +1042,20 @@ rb_str_slice_bang(argc, argv, str)
VALUE *argv;
VALUE str;
{
- VALUE arg1, arg2;
- long pos, len;
+ VALUE result;
+ VALUE buf[3];
+ int i;
- rb_str_modify(str);
- if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
- pos = NUM2LONG(arg1);
- len = NUM2LONG(arg2);
- delete_pos_len:
- if (pos < 0) {
- pos = RSTRING(str)->len + pos;
- }
- if (pos < 0 || RSTRING(str)->len <= pos) {
- rb_raise(rb_eIndexError, "index %d out of string", pos);
- }
- arg2 = rb_str_substr(str, pos, len);
- rb_str_replace(str, pos, len, rb_str_new(0,0));
- return arg2;
+ if (argc < 1 || 2 < argc) {
+ rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
}
-
- if (!FIXNUM_P(arg1) && rb_range_beg_len(arg1, &pos, &len, RSTRING(str)->len, 0)) {
- goto delete_pos_len;
+ for (i=0; i<argc; i++) {
+ buf[i] = argv[i];
}
-
- pos = NUM2LONG(arg1);
- len = RSTRING(str)->len;
-
- if (pos >= len) return Qnil;
- if (pos < 0) pos += len;
- if (pos < 0) return Qnil;
-
- arg2 = INT2FIX(RSTRING(str)->ptr[pos] & 0xff);
- memmove(RSTRING(str)->ptr + pos,
- RSTRING(str)->ptr + pos + 1,
- RSTRING(str)->len - (pos + 1));
- RSTRING(str)->len--;
-
- return arg2;
+ buf[i] = rb_str_new(0,0);
+ result = rb_str_aref_m(2, buf, str);
+ rb_str_aset_m(3, buf, str);
+ return result;
}
static VALUE
@@ -1107,7 +1088,7 @@ rb_str_sub_bang(argc, argv, str)
int iter = 0;
long plen;
- if (argc == 1 && rb_iterator_p()) {
+ if (argc == 1 && rb_block_given_p()) {
iter = 1;
}
else if (argc == 2) {
@@ -1177,7 +1158,7 @@ str_gsub(argc, argv, str, bang)
char *buf, *bp, *cp;
int tainted = 0;
- if (argc == 1 && rb_iterator_p()) {
+ if (argc == 1 && rb_block_given_p()) {
iter = 1;
}
else if (argc == 2) {
@@ -2545,7 +2526,7 @@ rb_str_scan(str, pat)
VALUE match = Qnil;
pat = get_pat(pat);
- if (!rb_iterator_p()) {
+ if (!rb_block_given_p()) {
VALUE ary = rb_ary_new();
while (!NIL_P(result = scan_once(str, pat, &start))) {
@@ -2849,7 +2830,6 @@ Init_String()
rb_define_method(rb_cString, "slice", rb_str_aref_m, -1);
rb_define_method(rb_cString, "slice!", rb_str_slice_bang, -1);
- rb_define_method(rb_cString, "delete_at", rb_str_slice_bang, -1);
to_str = rb_intern("to_s");
diff --git a/struct.c b/struct.c
index f066d73..961475d 100644
--- a/struct.c
+++ b/struct.c
@@ -52,7 +52,7 @@ rb_struct_s_members(obj)
member = iv_get(obj, "__member__");
if (NIL_P(member)) {
- rb_bug("non-initialized struct");
+ rb_bug("uninitialized struct");
}
ary = rb_ary_new2(RARRAY(member)->len);
p = RARRAY(member)->ptr; pend = p + RARRAY(member)->len;
@@ -81,9 +81,9 @@ rb_struct_getmember(obj, id)
member = iv_get(class_of(obj), "__member__");
if (NIL_P(member)) {
- rb_bug("non-initialized struct");
+ rb_bug("uninitialized struct");
}
- slot = INT2NUM(id);
+ slot = ID2SYM(id);
for (i=0; i<RARRAY(member)->len; i++) {
if (RARRAY(member)->ptr[i] == slot) {
return RSTRUCT(obj)->ptr[i];
diff --git a/version.h b/version.h
index cdc2425..4fc16ca 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
#define RUBY_VERSION "1.5.4"
-#define RUBY_RELEASE_DATE "2000-05-18"
+#define RUBY_RELEASE_DATE "2000-05-24"
#define RUBY_VERSION_CODE 154
-#define RUBY_RELEASE_CODE 20000518
+#define RUBY_RELEASE_CODE 20000524