summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-12-07 16:47:21 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-12-07 16:47:21 +0000
commitb514a325b560d0f36451050e15dd7ff985171d7b (patch)
tree381b72778e5ed473e47665757e47f66ef7191ce5
parentbe1fea072cd0d22788ef8a931c0c6b64a2503b5d (diff)
This commit was manufactured by cvs2svn to create tag 'v1_4_3'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_4_3@582 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog196
-rw-r--r--MANIFEST2
-rw-r--r--Makefile.in2
-rw-r--r--array.c25
-rw-r--r--bignum.c17
-rw-r--r--configure180
-rw-r--r--configure.in28
-rw-r--r--dir.c167
-rw-r--r--dln.c2
-rw-r--r--enum.c29
-rw-r--r--error.c23
-rw-r--r--eval.c103
-rw-r--r--ext/Win32API/Win32API.c16
-rw-r--r--ext/Win32API/depend1
-rw-r--r--ext/curses/MANIFEST1
-rw-r--r--ext/curses/depend1
-rw-r--r--ext/kconv/kconv.c2017
-rw-r--r--ext/nkf/depend2
-rw-r--r--ext/nkf/nkf.c26
-rw-r--r--ext/pty/MANIFEST1
-rw-r--r--ext/pty/depend1
-rw-r--r--ext/readline/MANIFEST1
-rw-r--r--ext/readline/depend1
-rw-r--r--ext/sdbm/MANIFEST1
-rw-r--r--ext/sdbm/depend2
-rw-r--r--ext/socket/extconf.rb6
-rw-r--r--ext/tcltklib/extconf.rb2
-rw-r--r--ext/tk/lib/tk.rb2
-rw-r--r--ext/tk/lib/tkcanvas.rb1
-rw-r--r--ext/tk/lib/tkentry.rb6
-rw-r--r--ext/tk/lib/tkfont.rb15
-rw-r--r--file.c19
-rw-r--r--gc.c21
-rw-r--r--hash.c10
-rw-r--r--intern.h11
-rw-r--r--io.c40
-rw-r--r--lib/debug.rb14
-rw-r--r--lib/net/pop.rb207
-rw-r--r--lib/net/session.rb267
-rw-r--r--lib/net/smtp.rb103
-rw-r--r--lib/pstore.rb34
-rw-r--r--lib/singleton.rb1
-rw-r--r--marshal.c22
-rw-r--r--misc/inf-ruby.el7
-rw-r--r--misc/ruby-mode.el12
-rw-r--r--missing/fnmatch.c199
-rw-r--r--missing/fnmatch.h57
-rw-r--r--node.h8
-rw-r--r--numeric.c10
-rw-r--r--process.c18
-rw-r--r--random.c23
-rw-r--r--re.c27
-rw-r--r--re.h3
-rw-r--r--regex.c10
-rw-r--r--ruby.c11
-rw-r--r--rubytest.rb2
-rw-r--r--sample/io.rb44
-rw-r--r--signal.c2
-rw-r--r--sprintf.c6
-rw-r--r--string.c21
-rw-r--r--variable.c12
-rw-r--r--version.h8
-rw-r--r--win32/config.status2
-rw-r--r--win32/ruby.def1
-rw-r--r--win32/win32.c27
65 files changed, 3418 insertions, 718 deletions
diff --git a/ChangeLog b/ChangeLog
index 900a94ea97..d97debfe18 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,195 @@
+Mon Dec 6 15:55:30 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * numeric.c (fix_rshift): Fix -1 >> 32 returned 0. (-1 is true)
+
+ * numeric.c (fix_rshift): Fix 1 >> -1 returned 0. (2 is true)
+
+Mon Dec 6 11:47:23 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * sprintf.c (rb_f_sprintf): formatted string must be tainted if
+ any of parameters is tainted.
+
+ * file.c (rb_file_s_expand_path): expanded file path need not to
+ be tainted always.
+
+Sat Dec 4 01:40:22 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * bignum.c (rb_big_rand): should not use rand/random where drand48
+ may be available. RANDOM_NUMBER should be provided from outside.
+
+Fri Dec 3 09:54:59 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (rb_f_require): should check require 'feature.o' too.
+
+Thu Dec 2 11:58:15 1999 Koji Arai <JCA02266@nifty.ne.jp>
+
+ * eval.c (rb_thread_loading): should maintain loading_tbl.
+
+Thu Dec 2 10:21:43 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (rb_thread_loading_done): wrong parameter to st_delete().
+
+Wed Dec 1 09:47:33 1999 Kazunori NISHI <kazunori@swlab.csce.kyushu-u.ac.jp>
+
+ * string.c (rb_str_split_method): should increment end too.
+
+Tue Nov 30 01:46:18 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * re.c (rb_reg_source): generated source string must be tainted if
+ regex is tainted.
+
+ * file.c (rb_file_s_basename): basename should not be tainted
+ unless the original path is tainted.
+
+ * file.c (rb_file_s_dirname): ditto.
+
+Mon Nov 29 15:28:52 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * variable.c (rb_path2class): evaluated value from path should be
+ module or class.
+
+Fri Nov 26 18:12:49 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (rb_exec_end_proc): should remove only end_procs defined
+ within load wrapper.
+
+ * eval.c (rb_load): save and restore ruby_wrapper around loading.
+
+ * eval.c (rb_mark_end_proc): mark end procs registered by END{} or
+ at_exit{}.
+
+ * eval.c (rb_set_end_proc): should not call rb_global_variable()
+ on heap address; it crashed mod_ruby.
+
+Fri Nov 26 18:12:49 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * enum.c (enum_grep): does not return nil.
+
+ * eval.c (rb_mark_end_proc): mark end procs registered by END{} or
+ at_exit{}.
+
+ * eval.c (rb_set_end_proc): should not call rb_global_variable()
+ on heap address; it crashed mod_ruby.
+
+Thu Nov 18 16:18:27 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * lib/pstore.rb: mutual lock by flock(2).
+
+Thu Nov 18 11:44:13 1999 Masahiro Tomita <tommy@tmtm.org>
+
+ * io.c (read_all): should check bytes too.
+
+Mon Nov 15 16:50:34 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * enum.c (enum_grep): grep with block returns collection of
+ evaluated values of block over matched elements.
+
+Mon Nov 15 04:50:33 1999 Koji Arai <JCA02266@nifty.ne.jp>
+
+ * re.c (rb_reg_source): should not call rb_reg_expr_str()
+ everytime.
+
+Fri Nov 12 23:52:19 1999 Katsuyuki Komatsu <komatsu@sarion.co.jp>
+
+ * process.c (rb_f_system): argument check for NT, __EMX__, DJGPP.
+
+Wed Nov 10 21:54:11 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * hash.c (rb_any_cmp): Fixed return without value.
+
+Tue Nov 9 13:21:04 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * configure.in: AC_MINIX move to before AC_EXEEXT and AC_OBJEXT.
+
+Mon Nov 8 19:52:29 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * configure.in: Renamed AC_CHAR_UNSIGNED to AC_C_CHAR_UNSIGNED.
+
+ * configure.in: Added default to AC_CHECK_SIZEOF().
+
+Mon Nov 8 14:28:18 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (rb_f_eval): fake outer scope when eval() called without
+ bindings.
+
+ * eval.c (rb_f_binding): should copy last_class in the outer frame too.
+
+Sun Nov 7 18:31:04 1999 Yasuhiro Fukuma <yasuf@big.or.jp>
+
+ * eval.c (is_defined): last_class may be 0.
+
+Sat Nov 6 19:26:55 1999 EGUCHI Osamu <eguchi@shizuokanet.ne.jp>
+
+ * Makefile.in: Added depend entry make parse.@OBJEXT@ from parse.c
+ for UCB make
+
+Wed Nov 3 08:52:57 1999 Masaki Fukushima <fukusima@goto.info.waseda.ac.jp>
+
+ * io.c (Init_IO): forgot to use INT2FIX() around SEEK_SET, etc.
+
+Wed Nov 3 00:25:20 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * string.c (rb_str_split_method): use mbclen2() to handle kcode
+ option of regexp objects.
+
+Sun Oct 31 13:12:42 1999 WATANABE Hirofumi <eban@os.rim.or.jp>
+
+ * regex.c (re_compile_pattern): wrong [\W] match.
+
+Thu Oct 28 13:35:40 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * string.c (rb_str_split_method): should be mbchar aware with
+ single char separators.
+
+Wed Oct 27 12:57:21 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * random.c (rb_f_srand): random seed should be unsigned.
+
+Tue Oct 26 19:20:54 1999 Koji Arai <JCA02266@nifty.ne.jp>
+
+ * marshal.c (r_object): should register class/module objects.
+
+Sat Oct 23 15:59:39 1999 Takaaki Tateishi <ttate@jaist.ac.jp>
+
+ * process.c (rb_f_system): should require at least one argument.
+
+Thu Oct 21 16:14:19 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * dir.c (fnmatch): use eban's fnmatch; do not depend on systems's
+ fnmatch (which may have portability problem) anymore.
+
+Wed Oct 20 15:14:24 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * marshal.c (marshal_load): should protect the generated object
+ table (arg->data) from GC.
+
+Mon Oct 18 16:15:52 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * ext/nkf/nkf.c (rb_nkf_kconv): output should be NUL terminated.
+
+Fri Oct 15 22:50:41 1999 WATANABE Hirofumi <eban@os.rim.or.jp>
+
+ * error.c (sys_nerr): on CYGWIN, it is _sys_nerr.
+
+Fri Oct 15 01:32:31 1999 WATANABE Hirofumi <eban@os.rim.or.jp>
+
+ * ext/Win32API/Win32API.c (Win32API_Call): need to use NUM2ULONG,
+ not NUM2INT.
+
+Tue Oct 12 22:29:04 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
+
+ * eval.c (block_pass): should copy block to prevent modifications.
+ tag in the structure should be updated from latest prot_tag.
+
+ * eval.c (proc_s_new): tag in struct BLOCK should not point into
+ unused stack.
+
+ * io.c (io_read): length may be 0 or negative.
+
+Tue Oct 12 13:26:27 1999 Jun-ichiro itojun Hagino <itojun@itojun.org>
+
+ * signal.c (posix_signal): RETSIGTYPE may be void.
+
Mon Oct 11 17:42:25 1999 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* parse.y (rb_intern): should generate distinct ID_ATTRSET symbols
@@ -16,6 +208,10 @@ Mon Oct 4 12:42:32 1999 Kazuhiko Izawa <izawa@erec.che.tohoku.ac.jp>
* pack.c (pack_unpack): % in printf format should be %%.
+Wed Oct 6 17:13:19 1999 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
+
+ * ruby.c (addpath): rubylib_mangled_path() modified.
+
Mon Oct 4 10:01:40 1999 Yukihiro Matsumoto <matz@netlab.co.jp>
* variable.c (rb_obj_instance_variables): should always return
diff --git a/MANIFEST b/MANIFEST
index 335b570bed..67ccf3f46a 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -75,7 +75,6 @@ util.c
variable.c
version.c
version.h
-beos/ruby.def.in
cygwin/GNUmakefile.in
ext/Setup
ext/Setup.dj
@@ -89,6 +88,7 @@ lib/Env.rb
lib/README
lib/base64.rb
lib/cgi.rb
+lib/cgi/session.rb
lib/cgi-lib.rb
lib/complex.rb
lib/date.rb
diff --git a/Makefile.in b/Makefile.in
index e846d8d72f..5b66caa96b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -141,6 +141,8 @@ parse.c: parse.y
$(YACC) $<
mv -f y.tab.c parse.c
+parse.@OBJEXT@: parse.c
+
alloca.@OBJEXT@: @srcdir@/missing/alloca.c
$(CC) -I. $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/alloca.c
diff --git a/array.c b/array.c
index 9cc0ac1815..f3bd553872 100644
--- a/array.c
+++ b/array.c
@@ -280,6 +280,7 @@ VALUE
rb_ary_pop(ary)
VALUE ary;
{
+ rb_ary_modify(ary);
if (RARRAY(ary)->len == 0) return Qnil;
if (RARRAY(ary)->len * 10 < RARRAY(ary)->capa && RARRAY(ary)->capa > ARY_DEFAULT_SIZE) {
RARRAY(ary)->capa = RARRAY(ary)->len * 2;
@@ -294,6 +295,7 @@ rb_ary_shift(ary)
{
VALUE top;
+ rb_ary_modify(ary);
if (RARRAY(ary)->len == 0) return Qnil;
top = RARRAY(ary)->ptr[0];
@@ -821,6 +823,7 @@ rb_ary_reverse(ary)
VALUE *p1, *p2;
VALUE tmp;
+ rb_ary_modify(ary);
if (RARRAY(ary)->len == 0) return ary;
p1 = RARRAY(ary)->ptr;
@@ -940,22 +943,19 @@ rb_ary_delete_at(ary, at)
VALUE ary;
VALUE at;
{
- long i1, i2, pos;
+ long i, pos = NUM2LONG(at), len = RARRAY(ary)->len;
VALUE del = Qnil;
rb_ary_modify(ary);
- pos = NUM2LONG(at);
- for (i1 = i2 = 0; i1 < RARRAY(ary)->len; i1++) {
- if (i1 == pos) {
- del = RARRAY(ary)->ptr[i1];
- continue;
- }
- if (i1 != i2) {
- RARRAY(ary)->ptr[i2] = RARRAY(ary)->ptr[i1];
- }
- i2++;
+ if (pos >= len) return Qnil;
+ if (pos < 0) pos += len;
+ if (pos < 0) return Qnil;
+
+ del = RARRAY(ary)->ptr[pos];
+ for (i = pos + 1; i < len; i++, pos++) {
+ RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
}
- RARRAY(ary)->len = i2;
+ RARRAY(ary)->len = pos;
return del;
}
@@ -1005,6 +1005,7 @@ static VALUE
rb_ary_clear(ary)
VALUE ary;
{
+ rb_ary_modify(ary);
RARRAY(ary)->len = 0;
if (ARY_DEFAULT_SIZE*3 < RARRAY(ary)->capa) {
RARRAY(ary)->capa = ARY_DEFAULT_SIZE * 2;
diff --git a/bignum.c b/bignum.c
index 36a46af3fd..870e4129c5 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 long)(x) << BITSPERDIG)
-#define BIGDN(x) (((x)<0) ? ~((~(x))>>BITSPERDIG) : (x)>>BITSPERDIG)
+#define BIGDN(x) RSHIFT(x,BITSPERDIG)
#define BIGLO(x) ((USHORT)((x) & (BIGRAD-1)))
static VALUE
@@ -1255,20 +1255,17 @@ rb_big_abs(x)
*/
VALUE
-rb_big_rand(max)
+rb_big_rand(max, rand)
VALUE max;
+ double rand;
{
- struct RBignum *v;
+ VALUE v;
long len;
- len = RBIGNUM(max)->len;
- v = RBIGNUM(bignew(len,1));
+ len = RBIGNUM(v)->len;
+ v = bignew(len,1);
while (len--) {
-#ifdef HAVE_RANDOM
- BDIGITS(v)[len] = random();
-#else
- BDIGITS(v)[len] = rand();
-#endif
+ BDIGITS(v)[len] = ((USHORT)~0) * rand;
}
return rb_big_mod((VALUE)v, max);
diff --git a/configure b/configure
index 462280501c..8a964db77c 100644
--- a/configure
+++ b/configure
@@ -1175,13 +1175,64 @@ else
fi
+# checks for UNIX variants that set C preprocessor variables
+ac_safe=`echo "minix/config.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for minix/config.h""... $ac_c" 1>&6
+echo "configure:1182: checking for minix/config.h" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 1187 "configure"
+#include "confdefs.h"
+#include <minix/config.h>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1192: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=yes"
+else
+ echo "$ac_err" >&5
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ echo "$ac_t""yes" 1>&6
+ MINIX=yes
+else
+ echo "$ac_t""no" 1>&6
+MINIX=
+fi
+
+if test "$MINIX" = yes; then
+ cat >> confdefs.h <<\EOF
+#define _POSIX_SOURCE 1
+EOF
+
+ cat >> confdefs.h <<\EOF
+#define _POSIX_1_SOURCE 2
+EOF
+
+ cat >> confdefs.h <<\EOF
+#define _MINIX 1
+EOF
+
+fi
+
+
echo $ac_n "checking for Cygwin environment""... $ac_c" 1>&6
-echo "configure:1180: checking for Cygwin environment" >&5
+echo "configure:1231: checking for Cygwin environment" >&5
if eval "test \"`echo '$''{'ac_cv_cygwin'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1185 "configure"
+#line 1236 "configure"
#include "confdefs.h"
int main() {
@@ -1192,7 +1243,7 @@ int main() {
return __CYGWIN__;
; return 0; }
EOF
-if { (eval echo configure:1196: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1247: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_cygwin=yes
else
@@ -1209,19 +1260,19 @@ echo "$ac_t""$ac_cv_cygwin" 1>&6
CYGWIN=
test "$ac_cv_cygwin" = yes && CYGWIN=yes
echo $ac_n "checking for mingw32 environment""... $ac_c" 1>&6
-echo "configure:1213: checking for mingw32 environment" >&5
+echo "configure:1264: checking for mingw32 environment" >&5
if eval "test \"`echo '$''{'ac_cv_mingw32'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 1218 "configure"
+#line 1269 "configure"
#include "confdefs.h"
int main() {
return __MINGW32__;
; return 0; }
EOF
-if { (eval echo configure:1225: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1276: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
ac_cv_mingw32=yes
else
@@ -1240,7 +1291,7 @@ test "$ac_cv_mingw32" = yes && MINGW32=yes
echo $ac_n "checking for executable suffix""... $ac_c" 1>&6
-echo "configure:1244: checking for executable suffix" >&5
+echo "configure:1295: checking for executable suffix" >&5
if eval "test \"`echo '$''{'ac_cv_exeext'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -1250,7 +1301,7 @@ else
rm -f conftest*
echo 'int main () { return 0; }' > conftest.$ac_ext
ac_cv_exeext=
- if { (eval echo configure:1254: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
+ if { (eval echo configure:1305: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; }; then
for file in conftest.*; do
case $file in
*.c | *.o | *.obj) ;;
@@ -1271,13 +1322,13 @@ echo "$ac_t""${ac_cv_exeext}" 1>&6
ac_exeext=$EXEEXT
echo $ac_n "checking for object suffix""... $ac_c" 1>&6
-echo "configure:1275: checking for object suffix" >&5
+echo "configure:1326: checking for object suffix" >&5
if eval "test \"`echo '$''{'ac_cv_objext'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
rm -f conftest*
echo 'int i = 1;' > conftest.$ac_ext
-if { (eval echo configure:1281: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1332: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
for ac_file in conftest.*; do
case $ac_file in
*.c) ;;
@@ -1295,64 +1346,13 @@ OBJEXT=$ac_cv_objext
ac_objext=$ac_cv_objext
-# checks for UNIX variants that set C preprocessor variables
-ac_safe=`echo "minix/config.h" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for minix/config.h""... $ac_c" 1>&6
-echo "configure:1302: checking for minix/config.h" >&5
-if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
- echo $ac_n "(cached) $ac_c" 1>&6
-else
- cat > conftest.$ac_ext <<EOF
-#line 1307 "configure"
-#include "confdefs.h"
-#include <minix/config.h>
-EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1312: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
-if test -z "$ac_err"; then
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=yes"
-else
- echo "$ac_err" >&5
- echo "configure: failed program was:" >&5
- cat conftest.$ac_ext >&5
- rm -rf conftest*
- eval "ac_cv_header_$ac_safe=no"
-fi
-rm -f conftest*
-fi
-if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
- echo "$ac_t""yes" 1>&6
- MINIX=yes
-else
- echo "$ac_t""no" 1>&6
-MINIX=
-fi
-
-if test "$MINIX" = yes; then
- cat >> confdefs.h <<\EOF
-#define _POSIX_SOURCE 1
-EOF
-
- cat >> confdefs.h <<\EOF
-#define _POSIX_1_SOURCE 2
-EOF
-
- cat >> confdefs.h <<\EOF
-#define _MINIX 1
-EOF
-
-fi
-
-
echo $ac_n "checking size of int""... $ac_c" 1>&6
echo "configure:1351: checking size of int" >&5
if eval "test \"`echo '$''{'ac_cv_sizeof_int'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
- { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+ ac_cv_sizeof_int=4
else
cat > conftest.$ac_ext <<EOF
#line 1359 "configure"
@@ -1391,7 +1391,7 @@ if eval "test \"`echo '$''{'ac_cv_sizeof_short'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
- { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+ ac_cv_sizeof_short=2
else
cat > conftest.$ac_ext <<EOF
#line 1398 "configure"
@@ -1430,7 +1430,7 @@ if eval "test \"`echo '$''{'ac_cv_sizeof_long'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
- { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+ ac_cv_sizeof_long=4
else
cat > conftest.$ac_ext <<EOF
#line 1437 "configure"
@@ -1469,7 +1469,7 @@ if eval "test \"`echo '$''{'ac_cv_sizeof_voidp'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
- { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+ ac_cv_sizeof_voidp=4
else
cat > conftest.$ac_ext <<EOF
#line 1476 "configure"
@@ -1508,7 +1508,7 @@ if eval "test \"`echo '$''{'ac_cv_sizeof_float'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
- { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+ ac_cv_sizeof_float=4
else
cat > conftest.$ac_ext <<EOF
#line 1515 "configure"
@@ -1547,7 +1547,7 @@ if eval "test \"`echo '$''{'ac_cv_sizeof_double'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
if test "$cross_compiling" = yes; then
- { echo "configure: error: can not run test program while cross compiling" 1>&2; exit 1; }
+ ac_cv_sizeof_double=8
else
cat > conftest.$ac_ext <<EOF
#line 1554 "configure"
@@ -3641,7 +3641,7 @@ else
int main() {
/* Ultrix mips cc rejects this. */
-typedef int charset[2]; const charset x;
+typedef int charset[2]; const charset x = {0,0};
/* SunOS 4.1.1 cc rejects this. */
char const *const *ccp;
char **p;
@@ -3783,7 +3783,7 @@ else
int
main()
{
- if (-1==(-1>>1))
+ if (-1==(-1>>(unsigned)1))
return 0;
return 1;
}
@@ -4085,6 +4085,10 @@ echo "configure:4028: checking whether OS depend dynamic link works" >&5
fi
rb_cv_dlopen=yes ;;
netbsd*) LDSHARED="ld -shared"
+ case "$host_cpu" in
+ alpha)
+ LDFLAGS="-export-dynamic" ;;
+ esac
rb_cv_dlopen=yes ;;
openbsd*) LDSHARED="ld -Bforcearchive -Bshareable"
rb_cv_dlopen=yes ;;
@@ -4093,7 +4097,7 @@ echo "configure:4028: checking whether OS depend dynamic link works" >&5
rb_cv_dlopen=yes ;;
esac ;;
bsdi*) LDSHARED="ld -shared"
- LDFLAGS="-rdynamic -Wl,-rpath,/usr/local/lib/ruby/1.4/i386-bsdi4.0"
+ LDFLAGS='-rdynamic -Wl,-rpath,$(prefix)/lib/ruby/$(MAJOR).$(MINOR)/i386-bsdi4.0'
rb_cv_dlopen=yes ;;
nextstep*) LDSHARED='cc -r -nostdlib'
LDFLAGS="-u libsys_s"
@@ -4141,12 +4145,12 @@ if test "$ac_cv_header_a_out_h" = yes; then
if test "$with_dln_a_out" = yes || test "$rb_cv_dlopen" = unknown; then
cat confdefs.h > config.h
echo $ac_n "checking whether matz's dln works""... $ac_c" 1>&6
-echo "configure:4145: checking whether matz's dln works" >&5
+echo "configure:4149: checking whether matz's dln works" >&5
if eval "test \"`echo '$''{'rb_cv_dln_a_out'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4150 "configure"
+#line 4154 "configure"
#include "confdefs.h"
#define USE_DLN_A_OUT
@@ -4156,7 +4160,7 @@ int main() {
; return 0; }
EOF
-if { (eval echo configure:4160: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:4164: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest*
rb_cv_dln_a_out=yes
else
@@ -4263,7 +4267,7 @@ fi
case "$host_os" in
human*)
echo $ac_n "checking for _harderr in -lsignal""... $ac_c" 1>&6
-echo "configure:4267: checking for _harderr in -lsignal" >&5
+echo "configure:4271: checking for _harderr in -lsignal" >&5
ac_lib_var=`echo signal'_'_harderr | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@@ -4271,7 +4275,7 @@ else
ac_save_LIBS="$LIBS"
LIBS="-lsignal $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 4275 "configure"
+#line 4279 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
@@ -4282,7 +4286,7 @@ int main() {
_harderr()
; return 0; }
EOF
-if { (eval echo configure:4286: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4290: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
@@ -4310,7 +4314,7 @@ else
fi
echo $ac_n "checking for hmemset in -lhmem""... $ac_c" 1>&6
-echo "configure:4314: checking for hmemset in -lhmem" >&5
+echo "configure:4318: checking for hmemset in -lhmem" >&5
ac_lib_var=`echo hmem'_'hmemset | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
@@ -4318,7 +4322,7 @@ else
ac_save_LIBS="$LIBS"
LIBS="-lhmem $LIBS"
cat > conftest.$ac_ext <<EOF
-#line 4322 "configure"
+#line 4326 "configure"
#include "confdefs.h"
/* Override any gcc2 internal prototype to avoid an error. */
/* We use char because int might match the return type of a gcc2
@@ -4329,7 +4333,7 @@ int main() {
hmemset()
; return 0; }
EOF
-if { (eval echo configure:4333: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4337: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_lib_$ac_lib_var=yes"
else
@@ -4359,12 +4363,12 @@ fi
for ac_func in select
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:4363: checking for $ac_func" >&5
+echo "configure:4367: checking for $ac_func" >&5
if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
cat > conftest.$ac_ext <<EOF
-#line 4368 "configure"
+#line 4372 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */
@@ -4387,7 +4391,7 @@ $ac_func();
; return 0; }
EOF
-if { (eval echo configure:4391: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:4395: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest*
eval "ac_cv_func_$ac_func=yes"
else
@@ -4412,7 +4416,7 @@ fi
done
echo $ac_n "checking whether PD libc _dtos18 fail to convert big number""... $ac_c" 1>&6
-echo "configure:4416: checking whether PD libc _dtos18 fail to convert big number" >&5
+echo "configure:4420: checking whether PD libc _dtos18 fail to convert big number" >&5
if eval "test \"`echo '$''{'rb_cv_missing__dtos18'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -4420,7 +4424,7 @@ else
rb_cv_missing__dtos18=no
else
cat > conftest.$ac_ext <<EOF
-#line 4424 "configure"
+#line 4428 "configure"
#include "confdefs.h"
#include <stdio.h>
@@ -4432,7 +4436,7 @@ main ()
}
EOF
-if { (eval echo configure:4436: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4440: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
rb_cv_missing__dtos18=yes
else
@@ -4454,7 +4458,7 @@ EOF
fi
echo $ac_n "checking whether PD libc fconvert fail to round""... $ac_c" 1>&6
-echo "configure:4458: checking whether PD libc fconvert fail to round" >&5
+echo "configure:4462: checking whether PD libc fconvert fail to round" >&5
if eval "test \"`echo '$''{'rb_cv_missing_fconvert'+set}'`\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6
else
@@ -4462,7 +4466,7 @@ else
rb_cv_missing_fconvert=no
else
cat > conftest.$ac_ext <<EOF
-#line 4466 "configure"
+#line 4470 "configure"
#include "confdefs.h"
#include <stdio.h>
@@ -4475,7 +4479,7 @@ main ()
}
EOF
-if { (eval echo configure:4479: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:4483: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
then
rb_cv_missing_fconvert=yes
else
diff --git a/configure.in b/configure.in
index 00b6ff12ce..a595f6eec1 100644
--- a/configure.in
+++ b/configure.in
@@ -77,18 +77,18 @@ AC_CHECK_PROGS(AR, ar aal, ar)
AC_PROG_LN_S
AC_PROG_MAKE_SET
-AC_EXEEXT
-AC_OBJEXT
-
# checks for UNIX variants that set C preprocessor variables
AC_MINIX
-AC_CHECK_SIZEOF(int)
-AC_CHECK_SIZEOF(short)
-AC_CHECK_SIZEOF(long)
-AC_CHECK_SIZEOF(void*)
-AC_CHECK_SIZEOF(float)
-AC_CHECK_SIZEOF(double)
+AC_EXEEXT
+AC_OBJEXT
+
+AC_CHECK_SIZEOF(int, 4)
+AC_CHECK_SIZEOF(short, 2)
+AC_CHECK_SIZEOF(long, 4)
+AC_CHECK_SIZEOF(void*, 4)
+AC_CHECK_SIZEOF(float, 4)
+AC_CHECK_SIZEOF(double, 8)
AC_CACHE_CHECK(for prototypes, rb_cv_have_prototypes,
[AC_TRY_COMPILE([int foo(int x) { return 0; }], [return foo(10);],
@@ -253,14 +253,14 @@ test $rb_cv_func_strtod = no && LIBOBJS="$LIBOBJS strtod.o"
AC_C_BIGENDIAN
AC_C_CONST
-AC_CHAR_UNSIGNED
+AC_C_CHAR_UNSIGNED
AC_CACHE_CHECK(whether right shift preserve sign bit, rb_cv_rshift_sign,
[AC_TRY_RUN([
int
main()
{
- if (-1==(-1>>1))
+ if (-1==(-1>>(unsigned)1))
return 0;
return 1;
}
@@ -429,6 +429,10 @@ if test "$with_dln_a_out" != yes; then
fi
rb_cv_dlopen=yes ;;
netbsd*) LDSHARED="ld -shared"
+ case "$host_cpu" in
+ alpha)
+ LDFLAGS="-export-dynamic" ;;
+ esac
rb_cv_dlopen=yes ;;
openbsd*) LDSHARED="ld -Bforcearchive -Bshareable"
rb_cv_dlopen=yes ;;
@@ -437,7 +441,7 @@ if test "$with_dln_a_out" != yes; then
rb_cv_dlopen=yes ;;
esac ;;
bsdi*) LDSHARED="ld -shared"
- LDFLAGS="-rdynamic -Wl,-rpath,/usr/local/lib/ruby/1.4/i386-bsdi4.0"
+ LDFLAGS='-rdynamic -Wl,-rpath,$(prefix)/lib/ruby/$(MAJOR).$(MINOR)/i386-bsdi4.0'
rb_cv_dlopen=yes ;;
nextstep*) LDSHARED='cc -r -nostdlib'
LDFLAGS="-u libsys_s"
diff --git a/dir.c b/dir.c
index 31116a9fff..a771534155 100644
--- a/dir.c
+++ b/dir.c
@@ -47,12 +47,6 @@
# endif
#endif
-#ifdef HAVE_FNMATCH_H
-#include <fnmatch.h>
-#else
-#include "missing/fnmatch.h"
-#endif
-
#include <errno.h>
#ifdef USE_CWGUSI
# include <sys/errno.h>
@@ -66,6 +60,167 @@ char *getenv();
char *strchr _((char*,char));
#endif
+#include <ctype.h>
+
+#define FNM_NOESCAPE 0x01
+#define FNM_PATHNAME 0x02
+#define FNM_PERIOD 0x04
+#define FNM_NOCASE 0x08
+
+#define FNM_NOMATCH 1
+#define FNM_ERROR 2
+
+#define downcase(c) (nocase && isupper(c) ? tolower(c) : (c))
+
+#if defined DOSISH
+#define isdirsep(c) ((c) == '/' || (c) == '\\')
+static char *
+find_dirsep(s)
+ char *s;
+{
+ while (*s) {
+ if (isdirsep(*s))
+ return s;
+ s++;
+ }
+ return 0;
+}
+#else
+#define isdirsep(c) ((c) == '/')
+#define find_dirsep(s) strchr(s, '/')
+#endif
+
+static char *
+range(pat, test, flags)
+ char *pat;
+ char test;
+ int flags;
+{
+ int not, ok = 0;
+ int nocase = flags & FNM_NOCASE;
+ int escape = !(flags & FNM_NOESCAPE);
+
+ not = *pat == '!' || *pat == '^';
+ if (not)
+ pat++;
+
+ test = downcase(test);
+
+ while (*pat) {
+ int cstart, cend;
+ cstart = cend = *pat++;
+ if (cstart == ']')
+ return ok == not ? 0 : pat;
+ else if (escape && cstart == '\\')
+ cstart = cend = *pat++;
+ if (*pat == '-' && pat[1] != ']') {
+ if (escape && pat[1] == '\\')
+ pat++;
+ cend = pat[1];
+ if (!cend)
+ return 0;
+ pat += 2;
+ }
+ if (downcase(cstart) <= test && test <= downcase(cend))
+ ok = 1;
+ }
+ return 0;
+}
+
+#define PERIOD(s) (period && *(s) == '.' && \
+ ((s) == string || pathname && isdirsep(*(s))))
+static int
+fnmatch(pat, string, flags)
+ char *pat;
+ char *string;
+ int flags;
+{
+ int c;
+ int test;
+ char *s = string;
+ int escape = !(flags & FNM_NOESCAPE);
+ int pathname = flags & FNM_PATHNAME;
+ int period = flags & FNM_PERIOD;
+ int nocase = flags & FNM_NOCASE;
+
+ while (c = *pat++) {
+ switch (c) {
+ case '?':
+ if (!*s || pathname && isdirsep(*s) || PERIOD(s))
+ return FNM_NOMATCH;
+ s++;
+ break;
+ case '*':
+ while ((c = *pat++) == '*')
+ ;
+
+ if (PERIOD(s))
+ return FNM_NOMATCH;
+
+ if (!c) {
+ if (pathname && find_dirsep(s))
+ return FNM_NOMATCH;
+ else
+ return 0;
+ }
+ else if (pathname && isdirsep(c)) {
+ s = find_dirsep(s);
+ if (s)
+ break;
+ return FNM_NOMATCH;
+ }
+
+ test = escape && c == '\\' ? *pat : c;
+ test = downcase(test);
+ pat--;
+ while (*s) {
+ if ((c == '[' || downcase(*s) == test) &&
+ !fnmatch(pat, s, flags & ~FNM_PERIOD))
+ return 0;
+ else if (pathname && isdirsep(*s))
+ break;
+ s++;
+ }
+ return FNM_NOMATCH;
+
+ case '[':
+ if (!*s || pathname && isdirsep(*s) || PERIOD(s))
+ return FNM_NOMATCH;
+ pat = range(pat, *s, flags);
+ if (!pat)
+ return FNM_NOMATCH;
+ s++;
+ break;
+
+ case '\\':
+ if (escape
+#if defined DOSISH
+ && *pat && strchr("*?[\\", *pat)
+#endif
+ ) {
+ c = *pat;
+ if (!c)
+ c = '\\';
+ else
+ pat++;
+ }
+ /* FALLTHROUGH */
+
+ default:
+#if defined DOSISH
+ if (pathname && isdirsep(c) && isdirsep(*s))
+ ;
+ else
+#endif
+ if(downcase(c) != downcase(*s))
+ return FNM_NOMATCH;
+ s++;
+ break;
+ }
+ }
+ return !*s ? 0 : FNM_NOMATCH;
+}
+
VALUE rb_cDir;
static void
diff --git a/dln.c b/dln.c
index e6c7adde70..02ef484b36 100644
--- a/dln.c
+++ b/dln.c
@@ -80,7 +80,7 @@ int eaccess();
#endif
#ifndef FUNCNAME_PATTERN
-# if defined(__hp9000s300) || (defined(__NetBSD__) && (!defined(__alpha__) && !defined(__mips__))) || defined(__BORLANDC__) || (defined(__FreeBSD__) && __FreeBSD__ < 3) || defined(NeXT) || defined(__WATCOMC__) || defined(__APPLE__)
+# if defined(__hp9000s300) || (defined(__NetBSD__) && (!defined(__alpha__) && !defined(__mips__))) || defined(__BORLANDC__) || (defined(__FreeBSD__) && __FreeBSD__ < 3) || defined(__OpenBSD__) || defined(NeXT) || defined(__WATCOMC__) || defined(__APPLE__)
# define FUNCNAME_PATTERN "_Init_%.200s"
# else
# define FUNCNAME_PATTERN "Init_%.200s"
diff --git a/enum.c b/enum.c
index dc7e2112a4..2825855d53 100644
--- a/enum.c
+++ b/enum.c
@@ -33,11 +33,11 @@ grep_i(i, arg)
}
static VALUE
-grep_iter_i(i, pat)
- VALUE i, pat;
+grep_iter_i(i, arg)
+ VALUE i, *arg;
{
- if (RTEST(rb_funcall(pat, id_eqq, 1, i))) {
- rb_yield(i);
+ if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
+ rb_ary_push(arg[1], rb_yield(i));
}
return Qnil;
}
@@ -46,19 +46,16 @@ static VALUE
enum_grep(obj, pat)
VALUE obj, pat;
{
+ VALUE tmp, arg[2];
+
+ arg[0] = pat; arg[1] = tmp = rb_ary_new();
if (rb_iterator_p()) {
- rb_iterate(rb_each, obj, grep_iter_i, pat);
- return obj;
+ rb_iterate(rb_each, obj, grep_iter_i, (VALUE)arg);
}
else {
- VALUE tmp, arg[2];
-
- arg[0] = pat; arg[1] = tmp = rb_ary_new();
rb_iterate(rb_each, obj, grep_i, (VALUE)arg);
-
- if (RARRAY(tmp)->len == 0) return Qnil;
- return tmp;
}
+ return tmp;
}
struct find_arg {
@@ -201,7 +198,7 @@ min_i(i, min)
*min = i;
else {
cmp = rb_funcall(i, id_cmp, 1, *min);
- if (FIX2LONG(cmp) < 0)
+ if (NUM2LONG(cmp) < 0)
*min = i;
}
return Qnil;
@@ -217,7 +214,7 @@ min_ii(i, min)
*min = i;
else {
cmp = rb_yield(rb_assoc_new(i, *min));
- if (FIX2LONG(cmp) < 0)
+ if (NUM2LONG(cmp) < 0)
*min = i;
}
return Qnil;
@@ -243,7 +240,7 @@ max_i(i, max)
*max = i;
else {
cmp = rb_funcall(i, id_cmp, 1, *max);
- if (FIX2LONG(cmp) > 0)
+ if (NUM2LONG(cmp) > 0)
*max = i;
}
return Qnil;
@@ -259,7 +256,7 @@ max_ii(i, max)
*max = i;
else {
cmp = rb_yield(rb_assoc_new(i, *max));
- if (FIX2LONG(cmp) > 0)
+ if (NUM2LONG(cmp) > 0)
*max = i;
}
return Qnil;
diff --git a/error.c b/error.c
index 6a48210b4e..feb3778d54 100644
--- a/error.c
+++ b/error.c
@@ -26,6 +26,13 @@
int sys_nerr = 256;
#endif
+#if defined __CYGWIN__
+# include <cygwin/version.h>
+# if (CYGWIN_VERSION_API_MAJOR > 0) || (CYGWIN_VERSION_API_MINOR >= 8)
+# define sys_nerr _sys_nerr
+# endif
+#endif
+
int ruby_nerrs;
static void
@@ -34,14 +41,20 @@ err_snprintf(buf, len, fmt, args)
int len;
va_list args;
{
+ int n;
+
if (!ruby_sourcefile) {
vsnprintf(buf, len, fmt, args);
+ return;
+ }
+ else if (ruby_sourceline == 0) {
+ n = snprintf(buf, len, "%s: ", ruby_sourcefile);
}
else {
- int n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
- if (len > n) {
- vsnprintf((char*)buf+n, len-n, fmt, args);
- }
+ n = snprintf(buf, len, "%s:%d: ", ruby_sourcefile, ruby_sourceline);
+ }
+ if (len > n) {
+ vsnprintf((char*)buf+n, len-n, fmt, args);
}
}
@@ -432,7 +445,7 @@ static const syserr_index_entry syserr_index[]= {
static VALUE *syserr_list;
#endif
-#ifndef NT
+#if !defined NT && !defined sys_nerr
extern int sys_nerr;
#endif
diff --git a/eval.c b/eval.c
index f225bf47bd..1f00dff714 100644
--- a/eval.c
+++ b/eval.c
@@ -292,10 +292,15 @@ rb_enable_super(klass, name)
ID mid = rb_intern(name);
body = search_method(klass, mid, &origin);
- if (!body || !body->nd_body || origin != klass) {
+ if (!body) {
print_undef(klass, mid);
}
- body->nd_noex &= ~NOEX_UNDEF;
+ if (!body->nd_body) {
+ remove_method(klass, mid);
+ }
+ else {
+ body->nd_noex &= ~NOEX_UNDEF;
+ }
}
static void
@@ -1511,6 +1516,7 @@ is_defined(self, node, buf)
case NODE_SUPER:
case NODE_ZSUPER:
if (ruby_frame->last_func == 0) return 0;
+ else if (ruby_frame->last_class == 0) return 0;
else if (rb_method_boundp(RCLASS(ruby_frame->last_class)->super,
ruby_frame->last_func, 0)) {
if (nd_type(node) == NODE_SUPER) {
@@ -1707,7 +1713,7 @@ call_trace_func(event, file, line, self, id, klass)
prev = ruby_frame;
PUSH_FRAME();
- *ruby_frame = *_frame.prev;
+ *ruby_frame = *prev;
ruby_frame->prev = prev;
if (file) {
@@ -4369,7 +4375,7 @@ rb_f_eval(argc, argv, self)
VALUE *argv;
VALUE self;
{
- VALUE src, scope, vfile, vline;
+ VALUE src, scope, vfile, vline, val;
char *file = "(eval)";
int line = 1;
@@ -4383,6 +4389,19 @@ rb_f_eval(argc, argv, self)
}
Check_SafeStr(src);
+ if (NIL_P(scope) && ruby_frame->prev) {
+ struct FRAME *prev;
+ VALUE val;
+
+ prev = ruby_frame;
+ PUSH_FRAME();
+ *ruby_frame = *prev->prev;
+ ruby_frame->prev = prev;
+ val = eval(self, src, scope, file, line);
+ POP_FRAME();
+
+ return val;
+ }
return eval(self, src, scope, file, line);
}
@@ -4636,6 +4655,7 @@ rb_load(fname, wrap)
int state;
char *file;
volatile ID last_func;
+ volatile VALUE wrapper = 0;
VALUE self = ruby_top_self;
TMP_PROTECT;
@@ -4652,9 +4672,11 @@ rb_load(fname, wrap)
PUSH_VARS();
PUSH_CLASS();
+ wrapper = ruby_wrapper;
if (!wrap) {
rb_secure(4); /* should alter global state */
ruby_class = rb_cObject;
+ ruby_wrapper = 0;
}
else {
/* load in anonymous module as toplevel */
@@ -4701,7 +4723,7 @@ rb_load(fname, wrap)
POP_FRAME();
POP_CLASS();
POP_VARS();
- ruby_wrapper = 0;
+ ruby_wrapper = wrapper;
if (ruby_nerrs > 0) {
ruby_nerrs = 0;
rb_exc_raise(ruby_errinfo);
@@ -4812,6 +4834,7 @@ rb_f_require(obj, fname)
ext = strrchr(buf, '.');
strcpy(ext, DLEXT);
file = feature = buf;
+ if (rb_provided(feature)) return Qfalse;
}
file = find_file(file);
if (file) goto load_dyna;
@@ -5174,7 +5197,8 @@ struct end_proc_data {
VALUE data;
struct end_proc_data *next;
};
-static struct end_proc_data *end_proc_data;
+
+static struct end_proc_data *end_procs, *ephemeral_end_procs;
void
rb_set_end_proc(func, data)
@@ -5182,12 +5206,31 @@ rb_set_end_proc(func, data)
VALUE data;
{
struct end_proc_data *link = ALLOC(struct end_proc_data);
+ struct end_proc_data **list;
- link->next = end_proc_data;
+ if (ruby_wrapper) list = &ephemeral_end_procs;
+ else list = &end_procs;
+ link->next = *list;
link->func = func;
link->data = data;
- rb_global_variable(&link->data);
- end_proc_data = link;
+ *list = link;
+}
+
+void
+rb_mark_end_proc()
+{
+ struct end_proc_data *link;
+
+ link = end_procs;
+ while (link) {
+ rb_gc_mark(link->data);
+ link = link->next;
+ }
+ link = ephemeral_end_procs;
+ while (link) {
+ rb_gc_mark(link->data);
+ link = link->next;
+ }
}
static void
@@ -5220,17 +5263,20 @@ rb_f_at_exit()
void
rb_exec_end_proc()
{
- struct end_proc_data *link = end_proc_data;
- struct end_proc_data *tmp;
+ struct end_proc_data *link;
int status;
+ link = end_procs;
while (link) {
rb_protect((VALUE(*)())link->func, link->data, &status);
- tmp = link->next;
+ link = link->next;
+ }
+ while (ephemeral_end_procs) {
+ link = ephemeral_end_procs;
+ ephemeral_end_procs = link->next;
+ rb_protect((VALUE(*)())link->func, link->data, &status);
free(link);
- link = tmp;
}
- end_proc_data = 0;
}
void
@@ -5310,6 +5356,7 @@ Init_eval()
rb_define_global_function("untrace_var", rb_f_untrace_var, -1);
rb_define_global_function("set_trace_func", set_trace_func, 1);
+ rb_global_variable(&trace_func);
rb_define_virtual_variable("$SAFE", safe_getter, safe_setter);
}
@@ -5475,6 +5522,7 @@ rb_f_binding(self)
frame_dup(&data->frame);
if (ruby_frame->prev) {
data->frame.last_func = ruby_frame->prev->last_func;
+ data->frame.last_class = ruby_frame->prev->last_class;
}
if (data->iter) {
@@ -5549,6 +5597,7 @@ proc_s_new(klass)
data->orig_thread = rb_thread_current();
data->iter = data->prev?Qtrue:Qfalse;
+ data->tag = 0; /* should not point into stack */
frame_dup(&data->frame);
if (data->iter) {
blk_copy_prev(data);
@@ -5589,6 +5638,7 @@ proc_call(proc, args)
VALUE proc, args; /* OK */
{
struct BLOCK * volatile old_block;
+ struct BLOCK _block;
struct BLOCK *data;
volatile VALUE result = Qnil;
int state;
@@ -5600,7 +5650,8 @@ proc_call(proc, args)
/* PUSH BLOCK from data */
old_block = ruby_block;
- ruby_block = data;
+ _block = *data;
+ ruby_block = &_block;
PUSH_ITER(ITER_CUR);
ruby_frame->iter = ITER_CUR;
@@ -5625,6 +5676,7 @@ proc_call(proc, args)
}
PUSH_TAG(PROT_NONE);
+ _block.tag = prot_tag;
state = EXEC_TAG();
if (state == 0) {
proc_set_safe_level(proc);
@@ -5690,6 +5742,7 @@ block_pass(self, node)
{
VALUE block = rb_eval(self, node->nd_body);
struct BLOCK * volatile old_block;
+ struct BLOCK _block;
struct BLOCK *data;
volatile VALUE result = Qnil;
int state;
@@ -5712,11 +5765,13 @@ block_pass(self, node)
/* PUSH BLOCK from data */
old_block = ruby_block;
- ruby_block = data;
+ _block = *data;
+ ruby_block = &_block;
PUSH_ITER(ITER_PRE);
ruby_frame->iter = ITER_PRE;
PUSH_TAG(PROT_NONE);
+ _block.tag = prot_tag;
state = EXEC_TAG();
if (state == 0) {
proc_set_safe_level(block);
@@ -5724,7 +5779,7 @@ block_pass(self, node)
}
POP_TAG();
POP_ITER();
- if (ruby_block->tag->dst == state) {
+ if (_block.tag->dst == state) {
state &= TAG_MASK;
orphan = 2;
}
@@ -5937,7 +5992,7 @@ Init_Proc()
rb_define_global_function("lambda", rb_f_lambda, 0);
rb_define_global_function("binding", rb_f_binding, 0);
rb_cBinding = rb_define_class("Binding", rb_cObject);
- rb_undef_method(CLASS_OF(rb_cMethod), "new");
+ rb_undef_method(CLASS_OF(rb_cBinding), "new");
rb_define_method(rb_cBinding, "clone", bind_clone, 0);
rb_cMethod = rb_define_class("Method", rb_cObject);
@@ -6085,6 +6140,7 @@ thread_mark(th)
rb_gc_mark(th->errinfo);
rb_gc_mark(th->last_line);
rb_gc_mark(th->last_match);
+ rb_gc_mark(th->trace);
rb_mark_tbl(th->locals);
/* mark data in copied stack */
@@ -7277,9 +7333,12 @@ static int
rb_thread_loading(feature)
const char *feature;
{
- if (!rb_provided(feature)) return Qfalse; /* need to load */
- if (!loading_tbl) {
- loading_tbl = st_init_strtable();
+ if (!rb_provided(feature)) {
+ if (!loading_tbl) {
+ loading_tbl = st_init_strtable();
+ }
+ st_insert(loading_tbl, feature, 0);
+ return Qfalse; /* need to load */
}
while (st_lookup(loading_tbl, feature, 0)) {
CHECK_INTS;
@@ -7293,7 +7352,7 @@ rb_thread_loading_done(feature)
const char *feature;
{
if (loading_tbl) {
- st_delete(loading_tbl, feature, 0);
+ st_delete(loading_tbl, &feature, 0);
}
}
diff --git a/ext/Win32API/Win32API.c b/ext/Win32API/Win32API.c
index 9f75653132..8efb3ddad6 100644
--- a/ext/Win32API/Win32API.c
+++ b/ext/Win32API/Win32API.c
@@ -140,7 +140,7 @@ Win32API_Call(argc, argv, obj)
obj_proc = rb_iv_get(obj, "__proc__");
- ApiFunction = (FARPROC)NUM2INT(obj_proc);
+ ApiFunction = (FARPROC)NUM2ULONG(obj_proc);
obj_import = rb_iv_get(obj, "__import__");
obj_export = rb_iv_get(obj, "__export__");
@@ -159,7 +159,7 @@ Win32API_Call(argc, argv, obj)
switch (timport) {
case _T_NUMBER:
case _T_INTEGER:
- lParam = NUM2INT(rb_ary_entry(args, i));
+ lParam = NUM2ULONG(rb_ary_entry(args, i));
#if defined(_MSC_VER) || defined(__LCC__)
_asm {
mov eax, lParam
@@ -173,9 +173,15 @@ Win32API_Call(argc, argv, obj)
break;
case _T_POINTER:
str = rb_ary_entry(args, i);
- Check_Type(str, T_STRING);
- rb_str_modify(str);
- pParam = RSTRING(str)->ptr;
+ if (NIL_P(str)) {
+ pParam = 0;
+ } else if (FIXNUM_P(str)){
+ pParam = (char *)NUM2ULONG(str);
+ } else {
+ Check_Type(str, T_STRING);
+ rb_str_modify(str);
+ pParam = RSTRING(str)->ptr;
+ }
#if defined(_MSC_VER) || defined(__LCC__)
_asm {
mov eax, dword ptr pParam
diff --git a/ext/Win32API/depend b/ext/Win32API/depend
deleted file mode 100644
index b224bb66c9..0000000000
--- a/ext/Win32API/depend
+++ /dev/null
@@ -1 +0,0 @@
-Win32API.o : Win32API.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/curses/MANIFEST b/ext/curses/MANIFEST
index db5e54ffe8..e1a25d962d 100644
--- a/ext/curses/MANIFEST
+++ b/ext/curses/MANIFEST
@@ -1,5 +1,6 @@
MANIFEST
curses.c
+depend
extconf.rb
hello.rb
rain.rb
diff --git a/ext/curses/depend b/ext/curses/depend
new file mode 100644
index 0000000000..ecb79e512d
--- /dev/null
+++ b/ext/curses/depend
@@ -0,0 +1 @@
+curses.o: curses.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/kconv/kconv.c b/ext/kconv/kconv.c
new file mode 100644
index 0000000000..969c2cb504
--- /dev/null
+++ b/ext/kconv/kconv.c
@@ -0,0 +1,2017 @@
+/** Network Kanji Filter. (PDS Version)
+************************************************************************
+** Copyright (C) 1987, Fujitsu LTD. (Itaru ICHIKAWA)
+** Ï¢ÍíÀ衧 ¡Ê³ô¡ËÉÙ»ÎÄ̸¦µæ½ê¡¡¥½¥Õ¥È£³¸¦¡¡»ÔÀî¡¡»ê
+** ¡ÊE-Mail Address: ichikawa@flab.fujitsu.co.jp¡Ë
+** Copyright (C) 1996
+** Ï¢ÍíÀ衧 ΰµåÂç³Ø¾ðÊó¹©³Ø²Ê ²ÏÌî ¿¿¼£ mine/X0208 support
+** ¡ÊE-Mail Address: kono@ie.u-ryukyu.ac.jp¡Ë
+** Ï¢ÍíÀ衧 COW for DOS & Win16 & Win32 & OS/2
+** ¡ÊE-Mail Address: GHG00637@niftyserve.or.jp¡Ë
+** ±ÄÍø¤òÌÜŪ¤È¤·¤Ê¤¤¸Â¤ê¡¢¤³¤Î¥½¡¼¥¹¤Î¤¤¤«¤Ê¤ë
+** Ê£¼Ì¡¤²þÊÑ¡¤½¤Àµ¤âµöÂú¤·¤Þ¤¹¡£¤½¤ÎºÝ¤Ë¤Ï¡¢¤³¤ÎÉôʬ¤ò»Ä¤¹¤³¤È¡£
+** ¤³¤Î¥×¥í¥°¥é¥à¤Ë¤Ä¤¤¤Æ¤ÏÆä˲¿¤ÎÊݾڤ⤷¤Ê¤¤¡¢°­¤·¤«¤é¤º¡£
+** Everyone is permitted to do anything on this program
+** including copying, modifying, improving
+** as long as you don't try to make money off it,
+** or pretend that you wrote it.
+** i.e., the above copyright notice has to appear in all copies.
+** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
+***********************************************************************/
+
+/***********************************************************************
+** 1996/03/10 modified for Kconv - by Ikuo Nakagawa
+***********************************************************************/
+/***********************************************************************
+** 1996/12/18 modified for kconv(ruby) - by matz@ruby.club.or.jp
+***********************************************************************/
+
+static char *CopyRight =
+ "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),1996 S. Kono, COW";
+static char *Version =
+ "1.62";
+static char *Patchlevel =
+ "5/9612/Shinji Kono, COW matz";
+
+#include "ruby.h"
+
+/*
+**
+**
+**
+** USAGE: nkf [flags] [file]
+**
+** Flags:
+** b Output is bufferred (DEFAULT)
+** u Output is unbufferred
+**
+** t no operation
+**
+** j Outout code is JIS 7 bit (DEFAULT SELECT)
+** s Output code is MS Kanji (DEFAULT SELECT)
+** e Output code is AT&T JIS (DEFAULT SELECT)
+** l Output code is JIS 7bit and ISO8859-1 Latin-1
+**
+** m MIME conversion for ISO-2022-JP
+** i_ Output sequence to designate JIS-kanji (DEFAULT_J)
+** o_ Output sequence to designate single-byte roman characters (DEFAULT_R)
+**
+** r {de/en}crypt ROT13/47
+**
+** v display Version
+**
+** T Text mode output (for MS-DOS)
+**
+** x Do not convert X0201 kana into X0208
+** Z Convert X0208 alphabet to ASCII
+**
+** f60 fold option
+**
+** m MIME decode
+** B try to fix broken JIS, missing Escape
+** B[1-9] broken level
+**
+** O Output to 'nkf.out' file
+** d Delete \r in line feed
+** c Add \r in line feed
+**/
+/******************************/
+/* ¥Ç¥Õ¥©¥ë¥È¤Î½ÐÎÏ¥³¡¼¥ÉÁªÂò */
+/* Select DEFAULT_CODE */
+#define DEFAULT_CODE_JIS
+/* #define DEFAULT_CODE_SJIS */
+/* #define DEFAULT_CODE_EUC */
+/******************************/
+
+/* for Kconv: _AUTO, _EUC, _SJIS, _JIS */
+#define _AUTO 0
+#define _JIS 1
+#define _EUC 2
+#define _SJIS 3
+#define _BINARY 4
+#define _NOCONV 4
+#define _UNKNOWN _AUTO
+
+#if (defined(__TURBOC__) || defined(LSI_C)) && !defined(MSDOS)
+#define MSDOS
+#endif
+
+#include <stdio.h>
+
+#if defined(MSDOS) || defined(__OS2__)
+#include <stdlib.h>
+#include <fcntl.h>
+#include <io.h>
+#endif
+
+#ifdef MSDOS
+#ifdef LSI_C
+#define setbinmode(fp) fsetbin(fp)
+#else /* Microsoft C, Turbo C */
+#define setbinmode(fp) setmode(fileno(fp), O_BINARY)
+#endif
+#else /* UNIX,OS/2 */
+#define setbinmode(fp)
+#endif
+
+#ifdef _IOFBF /* SysV and MSDOS */
+#define setvbuffer(fp, buf, size) setvbuf(fp, buf, _IOFBF, size)
+#else /* BSD */
+#define setvbuffer(fp, buf, size) setbuffer(fp, buf, size)
+#endif
+
+/*Borland C++ 4.5 EasyWin*/
+#if defined(__TURBOC__) && defined(_Windows) && !defined(__WIN32__) /*Easy Win */
+#define EASYWIN
+#include <windows.h>
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#define TRUE 1
+#endif
+
+/* state of output_mode and input_mode */
+
+#define ASCII 0
+#define X0208 1
+#define X0201 2
+#define NO_X0201 3
+#define JIS_INPUT 4
+#define SJIS_INPUT 5
+#define LATIN1_INPUT 6
+#define FIXED_MIME 7
+#define DOUBLE_SPACE -2
+
+#define NL 0x0a
+#define ESC 0x1b
+#define SP 0x20
+#define AT 0x40
+#define SSP 0xa0
+#define DEL 0x7f
+#define SI 0x0f
+#define SO 0x0e
+#define SSO 0x8e
+
+#define HOLD_SIZE 32
+#define IOBUF_SIZE 16384
+
+#define DEFAULT_J 'B'
+#define DEFAULT_R 'B'
+
+#define SJ0162 0x00e1 /* 01 - 62 ku offset */
+#define SJ6394 0x0161 /* 63 - 94 ku offset */
+
+
+/* MIME preprocessor */
+
+#define _GETC() (inlen-- ? (int)(*inptr++) : EOF)
+#define _UNGETC(c) (inlen++, *--inptr = (c))
+#define PUTCHAR(c) (outlen + 1 < outsiz ? \
+ ((outptr[outlen++] = (c)), (outptr[outlen] = '\0')) : EOF)
+#define GETC() ((!mime_mode)?_GETC():mime_getc())
+#define UNGETC(c) ((!mime_mode)?_UNGETC(c):mime_ungetc(c))
+
+#ifdef EASYWIN /*Easy Win */
+extern POINT _BufferSize;
+#endif
+
+/* buffers */
+
+static unsigned char hold_buf[HOLD_SIZE*2];
+static int hold_count;
+static unsigned char *inptr;
+static int inlen;
+static char *outptr;
+static int outsiz;
+static int outlen;
+
+/* MIME preprocessor fifo */
+
+#define MIME_BUF_SIZE (1024) /* 2^n ring buffer */
+#define MIME_BUF_MASK (MIME_BUF_SIZE-1)
+#define Fifo(n) mime_buf[(n)&MIME_BUF_MASK]
+static unsigned char mime_buf[MIME_BUF_SIZE];
+static unsigned int mime_top = 0;
+static unsigned int mime_last = 0; /* decoded */
+static unsigned int mime_input = 0; /* undecoded */
+
+/* flags */
+static int unbuf_f = FALSE;
+static int estab_f = FALSE;
+static int rot_f = FALSE; /* rot14/43 mode */
+static int input_f = FALSE; /* non fixed input code */
+static int alpha_f = FALSE; /* convert JIx0208 alphbet to ASCII */
+static int mime_f = FALSE; /* convert MIME B base64 or Q */
+static int mimebuf_f = FALSE; /* MIME buffered input */
+static int broken_f = FALSE; /* convert ESC-less broken JIS */
+static int iso8859_f = FALSE; /* ISO8859 through */
+#if defined(MSDOS) || defined(__OS2__)
+static int x0201_f = TRUE; /* Assume JISX0201 kana */
+#else
+static int x0201_f = NO_X0201; /* Assume NO JISX0201 */
+#endif
+
+/* X0208 -> ASCII converter */
+
+static int c1_return;
+
+/* fold parameter */
+static int line = 0; /* chars in line */
+static int prev = 0;
+static int fold_f = FALSE;
+static int fold_len = 0;
+
+/* options */
+static char kanji_intro = DEFAULT_J,
+ ascii_intro = DEFAULT_R;
+
+/* Folding */
+
+#define FOLD_MARGIN 10
+#define DEFAULT_FOLD 60
+
+/* Global states */
+static int output_mode = ASCII, /* output kanji mode */
+ input_mode = ASCII, /* input kanji mode */
+ shift_mode = FALSE; /* TRUE shift out, or X0201 */
+static int mime_mode = FALSE; /* MIME mode B base64, Q hex */
+
+/* X0208 -> ASCII translation table */
+/* X0201 / X0208 conversion tables */
+
+/* X0201 kana conversion table */
+/* 90-9F A0-DF */
+static unsigned char cv[]= {
+0x21,0x21,0x21,0x23,0x21,0x56,0x21,0x57,
+0x21,0x22,0x21,0x26,0x25,0x72,0x25,0x21,
+0x25,0x23,0x25,0x25,0x25,0x27,0x25,0x29,
+0x25,0x63,0x25,0x65,0x25,0x67,0x25,0x43,
+0x21,0x3c,0x25,0x22,0x25,0x24,0x25,0x26,
+0x25,0x28,0x25,0x2a,0x25,0x2b,0x25,0x2d,
+0x25,0x2f,0x25,0x31,0x25,0x33,0x25,0x35,
+0x25,0x37,0x25,0x39,0x25,0x3b,0x25,0x3d,
+0x25,0x3f,0x25,0x41,0x25,0x44,0x25,0x46,
+0x25,0x48,0x25,0x4a,0x25,0x4b,0x25,0x4c,
+0x25,0x4d,0x25,0x4e,0x25,0x4f,0x25,0x52,
+0x25,0x55,0x25,0x58,0x25,0x5b,0x25,0x5e,
+0x25,0x5f,0x25,0x60,0x25,0x61,0x25,0x62,
+0x25,0x64,0x25,0x66,0x25,0x68,0x25,0x69,
+0x25,0x6a,0x25,0x6b,0x25,0x6c,0x25,0x6d,
+0x25,0x6f,0x25,0x73,0x21,0x2b,0x21,0x2c,
+0x00,0x00};
+
+
+/* X0201 kana conversion table for daguten */
+/* 90-9F A0-DF */
+static unsigned char dv[]= {
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x25,0x2c,0x25,0x2e,
+0x25,0x30,0x25,0x32,0x25,0x34,0x25,0x36,
+0x25,0x38,0x25,0x3a,0x25,0x3c,0x25,0x3e,
+0x25,0x40,0x25,0x42,0x25,0x45,0x25,0x47,
+0x25,0x49,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x25,0x50,0x25,0x53,
+0x25,0x56,0x25,0x59,0x25,0x5c,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00};
+
+/* X0201 kana conversion table for han-daguten */
+/* 90-9F A0-DF */
+static unsigned char ev[]= {
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x25,0x51,0x25,0x54,
+0x25,0x57,0x25,0x5a,0x25,0x5d,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00};
+
+
+/* X0208 kigou conversion table */
+/* 0x8140 - 0x819e */
+static unsigned char fv[] = {
+0x00,0x00,0x00,0x00,0x2c,0x2e,0x00,0x3a,
+0x3b,0x3f,0x21,0x00,0x00,0x27,0x60,0x00,
+0x5e,0x00,0x5f,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x2d,0x00,0x2f,
+0x5c,0x00,0x00,0x7c,0x00,0x00,0x60,0x27,
+0x22,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,
+0x7b,0x7d,0x3c,0x3e,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,
+0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+} ;
+
+
+/* This converts =?ISO-2022-JP?B?HOGE HOGE?= */
+
+static unsigned char *mime_pattern[] = {
+ (unsigned char *)"\075?ISO-8859-1?Q?",
+ (unsigned char *)"\075?ISO-2022-JP?B?",
+ (unsigned char *)"\075?ISO-2022-JP?Q?",
+ NULL
+};
+
+static int mime_encode[] = {
+ 'Q', 'B', 'Q',
+ 0
+};
+
+static int add_cr = FALSE;
+static int del_cr = FALSE;
+
+static void (*iconv) _((register int c2,register int c1)); /* s_iconv or oconv */
+static void (*oconv) _((register int c2,register int c1)); /* [ejs]_oconv */
+static int do_kconv _((VALUE, VALUE, int out_code, int in_code));
+static void h_conv _((register int c2,register int c1));
+static int push_hold_buf _((int c2,int c1));
+static void s_iconv _((register int c2,register int c1));
+static void e_oconv _((register int c2,register int c1));
+static void s_oconv _((register int c2,register int c1));
+static void j_oconv _((register int c2,register int c1));
+static int fold _((register int c2,register int c1));
+static int pre_convert _((register int c1,register int c2));
+static int mime_begin _((void));
+static int mime_getc _((void));
+static int mime_ungetc _((unsigned int c));
+static int mime_integrity _((unsigned char *p));
+static int base64decode _((int c));
+
+#ifdef notdef
+main (argc, argv)
+ int argc;
+ char **argv;
+{
+ register FILE *fin;
+ register char *cp;
+
+#ifdef EASYWIN /*Easy Win */
+ _BufferSize.y = 400;/*Set Scroll Buffer Size*/
+#endif
+#ifdef DEFAULT_CODE_JIS
+ oconv = j_oconv; /* DEFAULT Code is JIS */
+#endif
+#ifdef DEFAULT_CODE_SJIS
+ oconv = s_oconv; /* DEFAULT Code is S-JIS */
+#endif
+#ifdef DEFAULT_CODE_EUC
+ oconv = e_oconv; /* DEFAULT Code is EUC */
+#endif
+
+ for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
+ cp = *argv;
+ while (*cp) {
+ switch (*cp++) {
+ case 'b': /* buffered mode */
+ unbuf_f = FALSE;
+ continue;
+ case 'u': /* non bufferd mode */
+ unbuf_f = TRUE;
+ continue;
+ case 'j': /* JIS output */
+ case 'n':
+ oconv = j_oconv;
+ continue;
+ case 'e': /* AT&T EUC output */
+ oconv = e_oconv;
+ continue;
+ case 's': /* SJIS output */
+ oconv = s_oconv;
+ continue;
+ case 'l': /* ISO8859 Latin-1 support, no conversion */
+ iso8859_f = TRUE; /* Only compatible with ISO-2022-JP */
+ input_f = LATIN1_INPUT;
+ continue;
+ case 'i': /* Kanji IN ESC-$-@/B */
+ if(*cp=='@'||*cp=='B')
+ kanji_intro = *cp++;
+ continue;
+ case 'o': /* ASCII IN ESC-(-J/B */
+ if(*cp=='J'||*cp=='B'||*cp=='H')
+ ascii_intro = *cp++;
+ continue;
+ case 'r':
+ rot_f = TRUE;
+ continue;
+#if defined(MSDOS) || defined(__OS2__)
+ case 'T':
+ binmode_f = FALSE;
+ continue;
+#endif
+ case 'v':
+ usage();
+ exit(1);
+ break;
+ /* Input code assumption */
+ case 'J': /* JIS input */
+ case 'E': /* AT&T EUC input */
+ input_f = JIS_INPUT;
+ continue;
+ case 'S': /* MS Kanji input */
+ input_f = SJIS_INPUT;
+ if(x0201_f==NO_X0201) x0201_f=TRUE;
+ continue;
+ case 'Z': /* Convert X0208 alphabet to asii */
+ /* bit:0 Convert X0208
+ bit:1 Convert Kankaku to one space
+ bit:2 Convert Kankaku to two spaces
+ */
+ if('9'>= *cp && *cp>='0')
+ alpha_f |= 1<<(*cp++ -'0');
+ else
+ alpha_f |= TRUE;
+ continue;
+ case 'x': /* Convert X0201 kana to X0208 or X0201 Conversion */
+ x0201_f = FALSE; /* No X0201->X0208 conversion */
+ /* accept X0201
+ ESC-(-I in JIS, EUC, MS Kanji
+ SI/SO in JIS, EUC, MS Kanji
+ SSO in EUC, JIS, not in MS Kanji
+ MS Kanji (0xa0-0xdf)
+ output X0201
+ ESC-(-I in JIS (0x20-0x5f)
+ SSO in EUC (0xa0-0xdf)
+ 0xa0-0xd in MS Kanji (0xa0-0xdf)
+ */
+ continue;
+ case 'X': /* Assume X0201 kana */
+ /* Default value is NO_X0201 for EUC/MS-Kanji mix */
+ x0201_f = TRUE;
+ continue;
+ case 'f': /* folding -f60 or -f */
+ fold_f = TRUE;
+ fold_len = atoi(cp);
+ if(!(0<fold_len && fold_len<BUFSIZ))
+ fold_len = DEFAULT_FOLD;
+ while('0'<= *cp && *cp <='9') cp++;
+ continue;
+ case 'm': /* MIME support */
+ mime_f = TRUE;
+ if(*cp=='B'||*cp=='Q') {
+ mime_mode = *cp++;
+ mimebuf_f = FIXED_MIME;
+ }
+ continue;
+ case 'B': /* Broken JIS support */
+ /* bit:0 no ESC JIS
+ bit:1 allow any x on ESC-(-x or ESC-$-x
+ bit:2 reset to ascii on NL
+ */
+ if('9'>= *cp && *cp>='0')
+ broken_f |= 1<<(*cp++ -'0');
+ else
+ broken_f |= TRUE;
+ continue;
+ case 'O':/* for Output file */
+ file_out = TRUE;
+ continue;
+ case 'c':/* add cr code */
+ add_cr = TRUE;
+ continue;
+ case 'd':/* delete cr code */
+ del_cr = TRUE;
+ continue;
+ default:
+ /* bogus option but ignored */
+ continue;
+ }
+ }
+ }
+
+ if(iso8859_f && (oconv != j_oconv || !x0201_f )) {
+ fprintf(stderr,"Mixed ISO8859/JISX0201/SJIS/EUC output is not allowed.\n");
+ exit(1);
+ }
+
+ if(binmode_f == TRUE)
+#ifdef __OS2__
+ if(freopen("","wb",stdout) == NULL)
+ return (-1);
+#else
+ setbinmode(stdout);
+#endif
+
+ if(unbuf_f)
+ setbuf (stdout, (char *) NULL);
+ else
+ setvbuffer (stdout, stdobuf, IOBUF_SIZE);
+
+ if(argc == 0) {
+ if(binmode_f == TRUE)
+#ifdef __OS2__
+ if(freopen("","rb",stdin) == NULL) return (-1);
+#else
+ setbinmode(stdin);
+#endif
+ setvbuffer (stdin, stdibuf, IOBUF_SIZE);
+ convert (stdin);
+ } else {
+ while (argc--) {
+ if((fin = fopen (*argv++, "r")) == NULL) {
+ perror (*--argv);
+ return (-1);
+ } else {
+/* reopen file for stdout */
+ if(file_out == TRUE){
+ if(argc == 1 ) {
+ if(freopen(*argv++, "w", stdout) == NULL) {
+ perror (*--argv);
+ return (-1);
+ }
+ argc--;
+ } else {
+ if(freopen("nkf.out", "w", stdout) == NULL) {
+ perror (*--argv);
+ return (-1);
+ }
+ }
+ if(binmode_f == TRUE) {
+#ifdef __OS2__
+ if(freopen("","wb",stdout) == NULL)
+ return (-1);
+#else
+ setbinmode(stdout);
+#endif
+ }
+ }
+ if(binmode_f == TRUE)
+#ifdef __OS2__
+ if(freopen("","rb",fin) == NULL)
+ return (-1);
+#else
+ setbinmode(fin);
+#endif
+ setvbuffer (fin, stdibuf, IOBUF_SIZE);
+ convert (fin);
+ fclose (fin);
+ }
+ }
+ }
+#ifdef EASYWIN /*Easy Win */
+ if(file_out == FALSE)
+ scanf("%d",&end_check);
+ else
+ fclose(stdout);
+#else /* for Other OS */
+ if(file_out == TRUE)
+ fclose(stdout);
+#endif
+ return (0);
+}
+#endif /* notdef */
+
+static int
+do_kconv(in, out, out_code, in_code)
+ VALUE in, out;
+ int out_code, in_code;
+{
+ register int c1, c2;
+
+ c2 = 0;
+
+ inptr = (unsigned char *)RSTRING(in)->ptr; /* input buffer */
+ inlen = RSTRING(in)->len; /* input buffer size*/
+ outptr = RSTRING(out)->ptr; /* output buffer */
+ outsiz = RSTRING(out)->len; /* output buffer size */
+ outlen = 0; /* current length of output string */
+
+ if (inlen <= 0) {
+ return 0;
+ }
+ *outptr = '\0';
+
+ x0201_f = TRUE; /* don't assume JISX0201 kana */
+ rot_f = FALSE; /* rot14/43 mode */
+ input_f = FALSE; /* non fixed input code */
+ alpha_f = FALSE; /* convert JISX0208 alphbet to ASCII */
+ mime_f = TRUE; /* convert MIME base64 */
+ broken_f = FALSE; /* convert ESC-less broken JIS */
+
+ switch (out_code) {
+ case _SJIS:
+ oconv = s_oconv;
+ break;
+ case _EUC:
+ oconv = e_oconv;
+ break;
+ default:
+ oconv = j_oconv;
+ break;
+ }
+
+ switch (in_code) {
+ case _SJIS:
+ input_f = SJIS_INPUT;
+ x0201_f = TRUE;
+ break;
+ case _EUC:
+ case _JIS:
+ input_f = JIS_INPUT;
+ break;
+ default:
+ input_f = FALSE;
+ break;
+ }
+
+ if(input_f == JIS_INPUT || input_f == LATIN1_INPUT) {
+ estab_f = TRUE; iconv = oconv;
+ } else if(input_f == SJIS_INPUT) {
+ estab_f = TRUE; iconv = s_iconv;
+ } else {
+ estab_f = FALSE; iconv = oconv;
+ }
+ input_mode = ASCII;
+ output_mode = ASCII;
+ shift_mode = FALSE;
+ mime_mode = FALSE;
+
+#define NEXT continue /* no output, get next */
+#define SEND ; /* output c1 and c2, get next */
+#define LAST break /* end of loop, go closing */
+
+ while ((c1 = GETC()) != EOF) {
+ if(!c2 && !input_mode && c1<DEL && !mime_mode && !output_mode
+ && !shift_mode && !fold_f && !rot_f) {
+ /* plain ASCII tight loop, no conversion and no fold */
+ while(c1!='=' && c1!=SO && c1!=EOF &&
+ c1!=ESC && c1!='$' && c1<DEL && c1!='\r' && c1!='\n') {
+ PUTCHAR(c1);
+ c1 = _GETC();
+ }
+ if(c1==EOF) LAST;
+ }
+ if(c2) {
+ /* second byte */
+ if(c2 > DEL) {
+ /* in case of 8th bit is on */
+ if(!estab_f) {
+ /* in case of not established yet */
+ if(c1 > SSP) {
+ /* It is still ambiguious */
+ h_conv (c2, c1);
+ c2 = 0;
+ NEXT;
+ } else if(c1 < AT) {
+ /* ignore bogus code */
+ c2 = 0;
+ NEXT;
+ } else {
+ /* established */
+ /* it seems to be MS Kanji */
+ estab_f = TRUE;
+ iconv = s_iconv;
+ SEND;
+ }
+ } else
+ /* in case of already established */
+ if(c1 < AT) {
+ /* ignore bogus code */
+ c2 = 0;
+ NEXT;
+ } else
+ SEND;
+ } else
+ /* 7 bit code */
+ /* it might be kanji shitfted */
+ if((c1 == DEL) || (c1 <= SP)) {
+ /* ignore bogus first code */
+ c2 = 0;
+ NEXT;
+ } else
+ SEND;
+ } else {
+ /* first byte */
+ if(c1 > DEL) {
+ /* 8 bit code */
+ if(!estab_f && !iso8859_f) {
+ /* not established yet */
+ if(c1 < SSP) {
+ /* it seems to be MS Kanji */
+ estab_f = TRUE;
+ iconv = s_iconv;
+ } else if(c1 < 0xe0) {
+ /* it seems to be EUC */
+ estab_f = TRUE;
+ iconv = oconv;
+ } else {
+ /* still ambiguious */
+ }
+ c2 = c1;
+ NEXT;
+ } else { /* estab_f==TRUE */
+ if(iso8859_f) {
+ SEND;
+ } else if(SSP<=c1 && c1<0xe0 && iconv == s_iconv) {
+ /* SJIS X0201 Case... */
+ /* This is too arrogant, but ... */
+ if(x0201_f==NO_X0201) {
+ iconv = oconv;
+ c2 = c1;
+ NEXT;
+ } else
+ if(x0201_f) {
+ if(dv[(c1-SSP)*2]||ev[(c1-SSP)*2]) {
+ /* look ahead for X0201/X0208conversion */
+ if((c2 = GETC()) == EOF) {
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ LAST;
+ } else if(c2==(0xde)) { /* ÂùÅÀ */
+ (*oconv)(dv[(c1-SSP)*2],dv[(c1-SSP)*2+1]);
+ c2=0;
+ NEXT;
+ } else if(c2==(0xdf)&&ev[(c1-SSP)*2]) {
+ /* ȾÂùÅÀ */
+ (*oconv)(ev[(c1-SSP)*2],ev[(c1-SSP)*2+1]);
+ c2=0;
+ NEXT;
+ }
+ UNGETC(c2); c2 = 0;
+ }
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ NEXT;
+ } else
+ SEND;
+ } else if(c1==SSO && iconv != s_iconv) {
+ /* EUC X0201 Case */
+ /* This is too arrogant
+ if(x0201_f == NO_X0201) {
+ estab_f = FALSE;
+ c2 = 0;
+ NEXT;
+ } */
+ c1 = GETC(); /* skip SSO */
+ euc_1byte_check:
+ if(x0201_f && SSP<=c1 && c1<0xe0) {
+ if(dv[(c1-SSP)*2]||ev[(c1-SSP)*2]) {
+ if((c2 = GETC()) == EOF) {
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ LAST;
+ }
+ /* forward lookup ÂùÅÀ/ȾÂùÅÀ */
+ if(c2 != SSO) {
+ UNGETC(c2); c2 = 0;
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ NEXT;
+ } else if((c2 = GETC()) == EOF) {
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ (*oconv)(0,SSO);
+ LAST;
+ } else if(c2==(0xde)) { /* ÂùÅÀ */
+ (*oconv)(dv[(c1-SSP)*2],dv[(c1-SSP)*2+1]);
+ c2=0;
+ NEXT;
+ } else if(c2==(0xdf)&&ev[(c1-SSP)*2]) {
+ /* ȾÂùÅÀ */
+ (*oconv)(ev[(c1-SSP)*2],ev[(c1-SSP)*2+1]);
+ c2=0;
+ NEXT;
+ } else {
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ /* we have to check this c2 */
+ /* and no way to push back SSO */
+ c1 = c2; c2 = 0;
+ goto euc_1byte_check;
+ }
+ }
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ NEXT;
+ } else
+ SEND;
+ } else if(c1 < SSP && iconv != s_iconv) {
+ /* strange code in EUC */
+ iconv = s_iconv; /* try SJIS */
+ c2 = c1;
+ NEXT;
+ } else {
+ /* already established */
+ c2 = c1;
+ NEXT;
+ }
+ }
+ } else if((c1 > SP) && (c1 != DEL)) {
+ /* in case of Roman characters */
+ if(shift_mode) {
+ c1 |= 0x80;
+ /* output 1 shifted byte */
+ if(x0201_f && (!iso8859_f||input_mode==X0201) &&
+ SSP<=c1 && c1<0xe0 ) {
+ if(dv[(c1-SSP)*2]||ev[(c1-SSP)*2]) {
+ if((c2 = GETC()) == EOF) {
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ LAST;
+ } else if(c2==(0xde&0x7f)) { /* ÂùÅÀ */
+ (*oconv)(dv[(c1-SSP)*2],dv[(c1-SSP)*2+1]);
+ c2=0;
+ NEXT;
+ } else if(c2==(0xdf&0x7f)&&ev[(c1-SSP)*2]) {
+ /* ȾÂùÅÀ */
+ (*oconv)(ev[(c1-SSP)*2],ev[(c1-SSP)*2+1]);
+ c2=0;
+ NEXT;
+ }
+ UNGETC(c2); c2 = 0;
+ }
+ (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);
+ NEXT;
+ } else
+ SEND;
+ } else if(c1 == '(' && broken_f && input_mode == X0208
+ && !mime_mode ) {
+ /* Try to recover missing escape */
+ if((c1 = GETC()) == EOF) {
+ (*oconv) (0, '(');
+ LAST;
+ } else {
+ if(c1 == 'B' || c1 == 'J' || c1 == 'H') {
+ input_mode = ASCII; shift_mode = FALSE;
+ NEXT;
+ } else {
+ (*oconv) (0, '(');
+ /* do not modify various input_mode */
+ /* It can be vt100 sequence */
+ SEND;
+ }
+ }
+ } else if(input_mode == X0208) {
+ /* in case of Kanji shifted */
+ c2 = c1;
+ NEXT;
+ /* goto next_byte */
+ } else if(c1 == '=' && mime_f && !mime_mode ) {
+ if((c1 = _GETC()) == EOF) {
+ (*oconv) (0, '=');
+ LAST;
+ } else if(c1 == '?') {
+ /* =? is mime conversion start sequence */
+ if(mime_begin() == EOF) /* check in detail */
+ LAST;
+ else
+ NEXT;
+ } else {
+ (*oconv) (0, '=');
+ _UNGETC(c1);
+ NEXT;
+ }
+ } else if(c1 == '$' && broken_f && !mime_mode) {
+ /* try to recover missing escape */
+ if((c1 = GETC()) == EOF) {
+ (*oconv) (0, '$');
+ LAST;
+ } else if(c1 == '@'|| c1 == 'B') {
+ /* in case of Kanji in ESC sequence */
+ input_mode = X0208;
+ shift_mode = FALSE;
+ NEXT;
+ } else {
+ /* sorry */
+ (*oconv) (0, '$');
+ (*oconv) (0, c1);
+ NEXT;
+ }
+ } else
+ SEND;
+ } else if(c1 == SI) {
+ shift_mode = FALSE;
+ NEXT;
+ } else if(c1 == SO) {
+ shift_mode = TRUE;
+ NEXT;
+ } else if(c1 == ESC ) {
+ if((c1 = GETC()) == EOF) {
+ (*oconv) (0, ESC);
+ LAST;
+ } else if(c1 == '$') {
+ if((c1 = GETC()) == EOF) {
+ (*oconv) (0, ESC);
+ (*oconv) (0, '$');
+ LAST;
+ } else if(c1 == '@'|| c1 == 'B') {
+ /* This is kanji introduction */
+ input_mode = X0208;
+ shift_mode = FALSE;
+ NEXT;
+ } else if(broken_f&0x2) {
+ input_mode = X0208;
+ shift_mode = FALSE;
+ NEXT;
+ } else {
+ (*oconv) (0, ESC);
+ (*oconv) (0, '$');
+ (*oconv) (0, c1);
+ NEXT;
+ }
+ } else if(c1 == '(') {
+ if((c1 = GETC()) == EOF) {
+ (*oconv) (0, ESC);
+ (*oconv) (0, '(');
+ LAST;
+ } else {
+ if(c1 == 'I') {
+ /* This is X0201 kana introduction */
+ input_mode = X0201; shift_mode = X0201;
+ NEXT;
+ } else if(c1 == 'B' || c1 == 'J' || c1 == 'H') {
+ /* This is X0208 kanji introduction */
+ input_mode = ASCII; shift_mode = FALSE;
+ NEXT;
+ } else if(broken_f&0x2) {
+ input_mode = ASCII; shift_mode = FALSE;
+ NEXT;
+ } else {
+ (*oconv) (0, ESC);
+ (*oconv) (0, '(');
+ /* maintain various input_mode here */
+ SEND;
+ }
+ }
+ } else {
+ /* lonely ESC */
+ (*oconv) (0, ESC);
+ SEND;
+ }
+ } else if(c1 == NL && broken_f&4) {
+ input_mode = ASCII;
+ SEND;
+ } else
+ SEND;
+ }
+ /* send: */
+ if(input_mode == X0208)
+ (*oconv) (c2, c1); /* this is JIS, not SJIS/EUC case */
+ else
+ (*iconv) (c2, c1); /* can be EUC/SJIS */
+ c2 = 0;
+ continue;
+ /* goto next_word */
+ }
+
+ /* epilogue */
+ (*iconv) (EOF, 0);
+ return outlen;
+}
+
+
+static void
+h_conv (c2, c1)
+ register int c1,
+ c2;
+{
+ register int wc;
+
+
+ /** it must NOT be in the kanji shifte sequence */
+ /** it must NOT be written in JIS7 */
+ /** and it must be after 2 byte 8bit code */
+
+ hold_count = 0;
+ push_hold_buf (c2, c1);
+ c2 = 0;
+
+ while ((c1 = GETC()) != EOF) {
+ if(c2) {
+ /* second byte */
+ if(!estab_f) {
+ /* not established */
+ if(c1 > SSP) {
+ /* it is still ambiguious yet */
+ SEND;
+ } else if(c1 < AT) {
+ /* ignore bogus first byte */
+ c2 = 0;
+ SEND;
+ } else {
+ /* now established */
+ /* it seems to be MS Kanji */
+ estab_f = TRUE;
+ iconv = s_iconv;
+ SEND;
+ }
+ } else
+ SEND;
+ } else {
+ /* First byte */
+ if(c1 > DEL) {
+ /* 8th bit is on */
+ if(c1 < SSP) {
+ /* it seems to be MS Kanji */
+ estab_f = TRUE;
+ iconv = s_iconv;
+ } else if(c1 < 0xe0) {
+ /* it seems to be EUC */
+ estab_f = TRUE;
+ iconv = oconv;
+ } else {
+ /* still ambiguious */
+ }
+ c2 = c1;
+ NEXT;
+ } else
+ /* 7 bit code , then send without any process */
+ SEND;
+ }
+ /* send: */
+ if((push_hold_buf (c2, c1) == EOF) || estab_f)
+ break;
+ c2 = 0;
+ continue;
+ }
+
+ /** now,
+ ** 1) EOF is detected, or
+ ** 2) Code is established, or
+ ** 3) Buffer is FULL (but last word is pushed)
+ **
+ ** in 1) and 3) cases, we continue to use
+ ** Kanji codes by oconv and leave estab_f unchanged.
+ **/
+
+ for (wc = 0; wc < hold_count; wc += 2) {
+ c2 = hold_buf[wc];
+ c1 = hold_buf[wc+1];
+ (*iconv) (c2, c1);
+ }
+ return;
+}
+
+
+
+static int
+push_hold_buf (c2, c1)
+ int c2,
+ c1;
+{
+ if(hold_count >= HOLD_SIZE*2)
+ return (EOF);
+ hold_buf[hold_count++] = c2;
+ hold_buf[hold_count++] = c1;
+ return ((hold_count >= HOLD_SIZE*2) ? EOF : hold_count);
+}
+
+
+static void
+s_iconv (c2, c1)
+ register int c2,
+ c1;
+{
+ if((c2 == EOF) || (c2 == 0)) {
+ /* NOP */
+ } else {
+ c2 = c2 + c2 - ((c2 <= 0x9f) ? SJ0162 : SJ6394);
+ if(c1 < 0x9f)
+ c1 = c1 - ((c1 > DEL) ? SP : 0x1f);
+ else {
+ c1 = c1 - 0x7e;
+ c2++;
+ }
+ }
+ (*oconv) (c2, c1);
+}
+
+
+static void
+e_oconv (c2, c1)
+ register int c2,
+ c1;
+{
+ c2 = pre_convert(c1,c2); c1 = c1_return;
+ if(fold_f) {
+ switch(fold(c2,c1)) {
+ case '\n':
+ if(add_cr == TRUE) {
+ PUTCHAR('\r');
+ c1 = '\n';
+ }
+ PUTCHAR('\n');
+ break;
+ case 0: return;
+ case '\r':
+ c1 = '\n'; c2 = 0;
+ break;
+ case '\t':
+ case ' ':
+ c1 = ' '; c2 = 0;
+ break;
+ }
+ }
+ if(c2==DOUBLE_SPACE) {
+ PUTCHAR(' '); PUTCHAR(' ');
+ return;
+ }
+ if(c2 == EOF)
+ return;
+ else if(c2 == 0 && (c1&0x80)) {
+ PUTCHAR(SSO); PUTCHAR(c1);
+ } else if(c2 == 0) {
+ if(c1 == '\n' && add_cr == TRUE)
+ PUTCHAR('\r');
+ if(c1 != '\r')
+ PUTCHAR(c1);
+ else if(del_cr == FALSE)
+ PUTCHAR(c1);
+ } else {
+ if((c1<0x20 || 0x7e<c1) ||
+ (c2<0x20 || 0x7e<c2)) {
+ estab_f = FALSE;
+ return; /* too late to rescue this char */
+ }
+ PUTCHAR(c2 | 0x080);
+ PUTCHAR(c1 | 0x080);
+ }
+}
+
+
+static void
+s_oconv (c2, c1)
+ register int c2,
+ c1;
+{
+ c2 = pre_convert(c1,c2); c1 = c1_return;
+ if(fold_f) {
+ switch(fold(c2,c1)) {
+ case '\n':
+ if(add_cr == TRUE) {
+ PUTCHAR('\r');
+ c1 = '\n';
+ }
+ PUTCHAR('\n');
+ break;
+ case '\r':
+ c1 = '\n'; c2 = 0;
+ break;
+ case 0: return;
+ case '\t':
+ case ' ':
+ c1 = ' '; c2 = 0;
+ break;
+ }
+ }
+ if(c2==DOUBLE_SPACE) {
+ PUTCHAR(' '); PUTCHAR(' ');
+ return;
+ }
+ if(c2 == EOF)
+ return;
+ else if(c2 == 0) {
+ if(c1 == '\n' && add_cr == TRUE)
+ PUTCHAR('\r');
+ if(c1 != '\r')
+ PUTCHAR(c1);
+ else if(del_cr == FALSE)
+ PUTCHAR(c1);
+ } else {
+ if((c1<0x20 || 0x7e<c1) ||
+ (c2<0x20 || 0x7e<c2)) {
+ estab_f = FALSE;
+ return; /* too late to rescue this char */
+ }
+ PUTCHAR((((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1)));
+ PUTCHAR((c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
+ }
+}
+
+static void
+j_oconv (c2, c1)
+ register int c2,
+ c1;
+{
+ c2 = pre_convert(c1,c2); c1 = c1_return;
+ if(fold_f) {
+ switch(fold(c2,c1)) {
+ case '\n':
+ if(output_mode) {
+ PUTCHAR(ESC);
+ PUTCHAR('(');
+ PUTCHAR(ascii_intro);
+ }
+ if(add_cr == TRUE) {
+ PUTCHAR('\r');
+ c1 = '\n';
+ }
+ PUTCHAR('\n');
+ output_mode = ASCII;
+ break;
+ case '\r':
+ c1 = '\n'; c2 = 0;
+ break;
+ case '\t':
+ case ' ':
+ c1 = ' '; c2 = 0;
+ break;
+ case 0: return;
+ }
+ }
+ if(c2 == EOF) {
+ if(output_mode) {
+ PUTCHAR(ESC);
+ PUTCHAR('(');
+ PUTCHAR(ascii_intro);
+ }
+ } else if(c2 == 0 && (c1 & 0x80)) {
+ if(input_mode==X0201 || !iso8859_f) {
+ if(output_mode!=X0201) {
+ PUTCHAR(ESC);
+ PUTCHAR('(');
+ PUTCHAR('I');
+ output_mode = X0201;
+ }
+ c1 &= 0x7f;
+ } else {
+ /* iso8859 introduction, or 8th bit on */
+ /* Can we convert in 7bit form using ESC-'-'-A ?
+ Is this popular? */
+ }
+ PUTCHAR(c1);
+ } else if(c2 == 0) {
+ if(output_mode) {
+ PUTCHAR(ESC);
+ PUTCHAR('(');
+ PUTCHAR(ascii_intro);
+ output_mode = ASCII;
+ }
+ if(c1 == '\n' && add_cr == TRUE)
+ PUTCHAR('\r');
+ if(c1 != '\r')
+ PUTCHAR(c1);
+ else if(del_cr == FALSE)
+ PUTCHAR(c1);
+ } else if(c2 == DOUBLE_SPACE) {
+ if(output_mode) {
+ PUTCHAR(ESC);
+ PUTCHAR('(');
+ PUTCHAR(ascii_intro);
+ output_mode = ASCII;
+ }
+ PUTCHAR(' ');
+ if(c1 == '\n' && add_cr == TRUE)
+ PUTCHAR('\r');
+ if(c1 != '\r')
+ PUTCHAR(c1);
+ else if(del_cr == FALSE)
+ PUTCHAR(c1);
+ } else {
+ if(output_mode != X0208) {
+ PUTCHAR(ESC);
+ PUTCHAR('$');
+ PUTCHAR(kanji_intro);
+ output_mode = X0208;
+ }
+ if(c1<0x20 || 0x7e<c1)
+ return;
+ if(c2<0x20 || 0x7e<c2)
+ return;
+ PUTCHAR(c2);
+ if(c1 == '\n' && add_cr == TRUE)
+ PUTCHAR('\r');
+ if(c1 != '\r')
+ PUTCHAR(c1);
+ else if(del_cr == FALSE)
+ PUTCHAR(c1);
+ }
+}
+
+
+#define rot13(c) ( \
+ ( c < 'A' ) ? c: \
+ (c <= 'M') ? (c + 13): \
+ (c <= 'Z') ? (c - 13): \
+ (c < 'a') ? (c): \
+ (c <= 'm') ? (c + 13): \
+ (c <= 'z') ? (c - 13): \
+ (c) \
+)
+
+#define rot47(c) ( \
+ ( c < '!' ) ? c: \
+ ( c <= 'O' ) ? (c + 47) : \
+ ( c <= '~' ) ? (c - 47) : \
+ c \
+)
+
+/*
+ Return value of fold()
+
+ \n add newline and output char
+ \r add newline and output nothing
+ ' ' space
+ 0 skip
+ 1 (or else) normal output
+
+ fold state in prev (previous character)
+
+ >0x80 Japanese (X0208/X0201)
+ <0x80 ASCII
+ \n new line
+ ' ' space
+
+ This fold algorthm does not preserve heading space in a line.
+ This is the main difference from fmt.
+*/
+
+static int
+fold(c2,c1)
+register int c2,c1;
+{
+ int prev0;
+ if(c1=='\r')
+ return 0; /* ignore cr */
+ if(c1== 8) {
+ if(line>0) line--;
+ return 1;
+ }
+ if(c2==EOF && line != 0) /* close open last line */
+ return '\n';
+ /* new line */
+ if(c1=='\n') {
+ if(prev == c1) { /* duplicate newline */
+ if(line) {
+ line = 0;
+ return '\n'; /* output two newline */
+ } else {
+ line = 0;
+ return 1;
+ }
+ } else {
+ if(prev&0x80) { /* Japanese? */
+ prev = c1;
+ return 0; /* ignore given single newline */
+ } else if(prev==' ') {
+ return 0;
+ } else {
+ prev = c1;
+ if(++line<=fold_len)
+ return ' ';
+ else {
+ line = 0;
+ return '\r'; /* fold and output nothing */
+ }
+ }
+ }
+ }
+ if(c1=='\f') {
+ prev = '\n';
+ if(line==0)
+ return 1;
+ line = 0;
+ return '\n'; /* output newline and clear */
+ }
+ /* X0208 kankaku or ascii space */
+ if( (c2==0&&c1==' ')||
+ (c2==0&&c1=='\t')||
+ (c2==DOUBLE_SPACE)||
+ (c2=='!'&& c1=='!')) {
+ if(prev == ' ') {
+ return 0; /* remove duplicate spaces */
+ }
+ prev = ' ';
+ if(++line<=fold_len)
+ return ' '; /* output ASCII space only */
+ else {
+ prev = ' '; line = 0;
+ return '\r'; /* fold and output nothing */
+ }
+ }
+ prev0 = prev; /* we still need this one... , but almost done */
+ prev = c1;
+ if(c2 || (SSP<=c1 && c1<=0xdf))
+ prev |= 0x80; /* this is Japanese */
+ line += (c2==0)?1:2;
+ if(line<=fold_len) { /* normal case */
+ return 1;
+ }
+ if(line>=fold_len+FOLD_MARGIN) { /* too many kinsou suspension */
+ line = (c2==0)?1:2;
+ return '\n'; /* We can't wait, do fold now */
+ }
+ /* simple kinsoku rules return 1 means no folding */
+ if(c2==0) {
+ if(c1==0xde) return 1; /* ¡«*/
+ if(c1==0xdf) return 1; /* ¡¬*/
+ if(c1==0xa4) return 1; /* ¡£*/
+ if(c1==0xa3) return 1; /* ¡¤*/
+ if(c1==0xa1) return 1; /* ¡×*/
+ if(c1==0xb0) return 1; /* - */
+ if(SSP<=c1 && c1<=0xdf) { /* X0201 */
+ line = 1;
+ return '\n';/* add one new line before this character */
+ }
+ /* fold point in ASCII { [ ( */
+ if(( c1!=')'&&
+ c1!=']'&&
+ c1!='}'&&
+ c1!='.'&&
+ c1!=','&&
+ c1!='!'&&
+ c1!='?'&&
+ c1!='/'&&
+ c1!=':'&&
+ c1!=';')&&
+ ((prev0=='\n')|| (prev0==' ')|| /* ignored new line */
+ (prev0&0x80)) /* X0208 - ASCII */
+ ) {
+ line = 1;
+ return '\n';/* add one new line before this character */
+ }
+ return 1; /* default no fold in ASCII */
+ } else {
+ if(c2=='!') {
+ if(c1=='"') return 1; /* ¡¢ */
+ if(c1=='#') return 1; /* ¡£ */
+ if(c1=='$') return 1; /* ¡¤ */
+ if(c1=='%') return 1; /* ¡¥ */
+ if(c1=='\'') return 1; /* ¡Ü */
+ if(c1=='(') return 1; /* ¡¨ */
+ if(c1==')') return 1; /* ¡© */
+ if(c1=='*') return 1; /* ¡ª */
+ if(c1=='+') return 1; /* ¡« */
+ if(c1==',') return 1; /* ¡¬ */
+ }
+ line = 2;
+ return '\n'; /* add one new line before this character */
+ }
+}
+
+static int
+pre_convert(c1,c2)
+register int c1,c2;
+{
+ if(c2) c1 &= 0x7f;
+ c1_return = c1;
+ if(c2==EOF) return c2;
+ c2 &= 0x7f;
+ if(rot_f) {
+ if(c2) {
+ c1 = rot47(c1);
+ c2 = rot47(c2);
+ } else {
+ if(!(c1 & 0x80))
+ c1 = rot13(c1);
+ }
+ c1_return = c1;
+ }
+ /* JISX0208 Alphabet */
+ if(alpha_f && c2 == 0x23 ) return 0;
+ /* JISX0208 Kigou */
+ if(alpha_f && c2 == 0x21 ) {
+ if(0x21==c1) {
+ if(alpha_f&0x2) {
+ c1_return = ' ';
+ return 0;
+ } else if(alpha_f&0x4) {
+ c1_return = ' ';
+ return DOUBLE_SPACE;
+ } else {
+ return c2;
+ }
+ } else if(0x20<c1 && c1<0x7f && fv[c1-0x20]) {
+ c1_return = fv[c1-0x20];
+ return 0;
+ }
+ }
+ return c2;
+}
+
+
+static int iso8859_f_save;
+
+#define nkf_toupper(c) (('a'<=c && c<='z')?(c-('a'-'A')):c)
+/* I don't trust portablity of toupper */
+
+static int
+mime_begin()
+{
+ int c1;
+ int i,j,k;
+ unsigned char *p,*q;
+ int r[20]; /* recovery buffer, max mime pattern lenght */
+
+ mime_mode = FALSE;
+ /* =? has been checked */
+ j = 0;
+ p = mime_pattern[j];
+ r[0]='='; r[1]='?';
+
+ for(i=2;p[i]>' ';i++) { /* start at =? */
+ if( ((r[i] = c1 = _GETC())==EOF) || nkf_toupper(c1) != p[i] ) {
+ /* pattern fails, try next one */
+ q = p;
+ while (p = mime_pattern[++j]) {
+ for(k=2;k<i;k++) /* assume length(p) > i */
+ if(p[k]!=q[k]) break;
+ if(k==i && nkf_toupper(c1)==p[k]) break;
+ }
+ if(p) continue; /* found next one, continue */
+ /* all fails, output from recovery buffer */
+ _UNGETC(c1);
+ for(j=0;j<i;j++) {
+ (*oconv)(0,r[j]);
+ }
+ return c1;
+ }
+ }
+ iso8859_f_save = iso8859_f;
+ if(j==0) {
+ iso8859_f = TRUE;
+ }
+ mime_mode = mime_encode[j];
+ if(mime_mode=='B') {
+ mimebuf_f = unbuf_f;
+ if(!unbuf_f) {
+ /* do MIME integrity check */
+ return mime_integrity(mime_pattern[j]);
+ }
+ }
+ mimebuf_f = TRUE;
+ return c1;
+}
+
+#define mime_getc0() (mimebuf_f?_GETC():Fifo(mime_input++))
+#define mime_ungetc0(c) (mimebuf_f?_UNGETC(c):mime_input--)
+
+static int
+mime_getc()
+{
+ int c1, c2, c3, c4, cc;
+ int t1, t2, t3, t4, mode, exit_mode;
+
+ if(mime_top != mime_last) { /* Something is in FIFO */
+ return Fifo(mime_top++);
+ }
+
+ if(mimebuf_f == FIXED_MIME)
+ exit_mode = mime_mode;
+ else
+ exit_mode = FALSE;
+ if(mime_mode == 'Q') {
+ if((c1 = mime_getc0()) == EOF) return (EOF);
+ if(c1=='_') return ' ';
+ if(c1!='=' && c1!='?')
+ return c1;
+ mime_mode = exit_mode; /* prepare for quit */
+ if(c1<=' ') return c1;
+ if((c2 = mime_getc0()) == EOF) return (EOF);
+ if(c2<=' ') return c2;
+ if(c1=='?'&&c2=='=') {
+ /* end Q encoding */
+ input_mode = exit_mode;
+ iso8859_f = iso8859_f_save;
+ return _GETC();
+ }
+ if(c1=='?') {
+ mime_mode = 'Q'; /* still in MIME */
+ mime_ungetc0(c2);
+ return c1;
+ }
+ if((c3 = mime_getc0()) == EOF) return (EOF);
+ if(c2<=' ') return c2;
+ mime_mode = 'Q'; /* still in MIME */
+#define hex(c) (('0'<=c&&c<='9')?(c-'0'):\
+ ('A'<=c&&c<='F')?(c-'A'+10):('a'<=c&&c<='f')?(c-'a'+10):0)
+ return ((hex(c2)<<4) + hex(c3));
+ }
+
+ if(mime_mode != 'B') {
+ mime_mode = FALSE;
+ return _GETC();
+ }
+
+
+ /* Base64 encoding */
+ /*
+ MIME allows line break in the middle of
+ Base64, but we are very pessimistic in decoding
+ in unbuf mode because MIME encoded code may broken by
+ less or editor's control sequence (such as ESC-[-K in unbuffered
+ mode. ignore incomplete MIME.
+ */
+ mode = mime_mode;
+ mime_mode = exit_mode; /* prepare for quit */
+
+ while ((c1 = mime_getc0())<=' ') {
+ if(c1==EOF)
+ return (EOF);
+ }
+ if((c2 = mime_getc0())<=' ') {
+ if(c2==EOF)
+ return (EOF);
+ if(mimebuf_f!=FIXED_MIME) input_mode = ASCII;
+ return c2;
+ }
+ if((c1 == '?') && (c2 == '=')) {
+ input_mode = ASCII;
+ while((c1 = _GETC())==' ' /* || c1=='\n' || c1=='\r' */);
+ return c1;
+ }
+ if((c3 = mime_getc0())<=' ') {
+ if(c3==EOF)
+ return (EOF);
+ if(mimebuf_f!=FIXED_MIME) input_mode = ASCII;
+ return c3;
+ }
+ if((c4 = mime_getc0())<=' ') {
+ if(c4==EOF)
+ return (EOF);
+ if(mimebuf_f!=FIXED_MIME) input_mode = ASCII;
+ return c4;
+ }
+
+ mime_mode = mode; /* still in MIME sigh... */
+
+ /* BASE 64 decoding */
+
+ t1 = 0x3f & base64decode(c1);
+ t2 = 0x3f & base64decode(c2);
+ t3 = 0x3f & base64decode(c3);
+ t4 = 0x3f & base64decode(c4);
+ cc = ((t1 << 2) & 0x0fc) | ((t2 >> 4) & 0x03);
+ if(c2 != '=') {
+ Fifo(mime_last++) = cc;
+ cc = ((t2 << 4) & 0x0f0) | ((t3 >> 2) & 0x0f);
+ if(c3 != '=') {
+ Fifo(mime_last++) = cc;
+ cc = ((t3 << 6) & 0x0c0) | (t4 & 0x3f);
+ if(c4 != '=')
+ Fifo(mime_last++) = cc;
+ }
+ } else {
+ return c1;
+ }
+ return Fifo(mime_top++);
+}
+
+static int
+mime_ungetc(c)
+unsigned int c;
+{
+ Fifo(mime_last++) = c;
+ return c;
+}
+
+
+static int
+mime_integrity(p)
+unsigned char *p;
+{
+ int c,d;
+ unsigned int q;
+ /* In buffered mode, read until =? or NL or buffer full
+ */
+ mime_input = mime_top;
+ mime_last = mime_top;
+ while(*p) Fifo(mime_input++) = *p++;
+ d = 0;
+ q = mime_input;
+ while((c=_GETC())!=EOF) {
+ if(((mime_input-mime_top)&MIME_BUF_MASK)==0) break;
+ if(c=='=' && d=='?') {
+ /* checked. skip header, start decode */
+ Fifo(mime_input++) = c;
+ mime_input = q;
+ return 1;
+ }
+ if(!( (c=='+'||c=='/'|| c=='=' || c=='?' ||
+ ('a'<=c && c<='z')||('A'<= c && c<='Z')||('0'<=c && c<='9'))))
+ break;
+ /* Should we check length mod 4? */
+ Fifo(mime_input++) = c;
+ d=c;
+ }
+ /* In case of Incomplete MIME, no MIME decode */
+ Fifo(mime_input++) = c;
+ mime_last = mime_input; /* point undecoded buffer */
+ mime_mode = 1; /* no decode on Fifo last in mime_getc */
+ return 1;
+}
+
+static int
+base64decode(c)
+ int c;
+{
+ int i;
+ if(c > '@')
+ if(c < '[')
+ i = c - 'A'; /* A..Z 0-25 */
+ else
+ i = c - 'G' /* - 'a' + 26 */ ; /* a..z 26-51 */
+ else if(c > '/')
+ i = c - '0' + '4' /* - '0' + 52 */ ; /* 0..9 52-61 */
+ else if(c == '+')
+ i = '>' /* 62 */ ; /* + 62 */
+ else
+ i = '?' /* 63 */ ; /* / 63 */
+ return (i);
+}
+
+#ifdef notdef
+int
+usage()
+{
+ fprintf(stderr,"USAGE: nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");
+ fprintf(stderr,"Flags:\n");
+ fprintf(stderr,"b,u Output is bufferred (DEFAULT),Output is unbufferred\n");
+#ifdef DEFAULT_CODE_SJIS
+ fprintf(stderr,"j,s,e Outout code is JIS 7 bit, Shift JIS (DEFAULT), AT&T JIS (EUC)\n");
+#endif
+#ifdef DEFAULT_CODE_JIS
+ fprintf(stderr,"j,s,e Outout code is JIS 7 bit (DEFAULT), Shift JIS, AT&T JIS (EUC)\n");
+#endif
+#ifdef DEFAULT_CODE_EUC
+ fprintf(stderr,"j,s,e Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC) (DEFAULT)\n");
+#endif
+ fprintf(stderr,"J,S,E Input assumption is JIS 7 bit , Shift JIS, AT&T JIS (EUC)\n");
+ fprintf(stderr,"t no conversion\n");
+ fprintf(stderr,"i_ Output sequence to designate JIS-kanji (DEFAULT B)\n");
+ fprintf(stderr,"o_ Output sequence to designate ASCII (DEFAULT B)\n");
+ fprintf(stderr,"r {de/en}crypt ROT13/47\n");
+ fprintf(stderr,"v Show this usage\n");
+ fprintf(stderr,"m[BQ] MIME decode [B:base64 stream,Q:quoted stream]\n");
+ fprintf(stderr,"l ISO8859-1 (Latin-1) support\n");
+ fprintf(stderr,"f Folding: -f60 or -f\n");
+ fprintf(stderr,"Z[0-2] Convert X0208 alphabet to ASCII 1: Kankaku to space,2: 2 spaces\n");
+ fprintf(stderr,"X,x Assume X0201 kana in MS-Kanji, -x preserves X0201\n");
+ fprintf(stderr,"B[0-2] Broken input 0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");
+#ifdef MSDOS
+ fprintf(stderr,"T Text mode output\n");
+#endif
+ fprintf(stderr,"O Output to File (DEFAULT 'nkf.out')\n");
+ fprintf(stderr,"d,c Delete \\r in line feed, Add \\r in line feed\n");
+ fprintf(stderr,"Network Kanji Filter Version %s (%s) "
+#if defined(MSDOS) && !defined(_Windows)
+ "for DOS"
+#endif
+#if !defined(__WIN32__) && defined(_Windows)
+ "for Win16"
+#endif
+#if defined(__WIN32__) && defined(_Windows)
+ "for Win32"
+#endif
+#ifdef __OS2__
+ "for OS/2"
+#endif
+ ,Version,Patchlevel);
+ fprintf(stderr,"\n%s\n",CopyRight);
+ return 0;
+}
+#endif /* notdef */
+
+static VALUE
+kconv_kconv(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ VALUE src, dst;
+ VALUE in, out;
+ int in_code, out_code;
+ char *codename = 0;
+
+ rb_scan_args(argc, argv, "12", &src, &out, &in);
+ Check_Type(src, T_STRING);
+
+ if (NIL_P(out)) {
+ codename = rb_get_kcode();
+ goto codeselect;
+ }
+ else if (TYPE(out) == T_STRING) {
+ codename = RSTRING(out)->ptr;
+ codeselect:
+ switch (codename[0]) {
+ case 'E': case 'e':
+ out_code = _EUC;
+ break;
+ case 'S': case 's':
+ out_code = _SJIS;
+ break;
+ case 'J': case 'j':
+ default:
+ out_code = _JIS;
+ break;
+ }
+ }
+ else {
+ out_code = NUM2INT(out);
+ if (out_code == _NOCONV) return (VALUE)src;
+ }
+ if (NIL_P(in)) {
+ in_code = _AUTO;
+ }
+ else if (TYPE(in) == T_STRING) {
+ switch (RSTRING(in)->ptr[0]) {
+ case 'E': case 'e':
+ in_code = _EUC;
+ break;
+ case 'S': case 's':
+ in_code = _SJIS;
+ break;
+ case 'J': case 'j':
+ in_code = _JIS;
+ break;
+ default:
+ in_code = _AUTO;
+ break;
+ }
+ }
+ else {
+ in_code = NUM2INT(in);
+ if (in_code == _NOCONV) return (VALUE)src;
+ }
+
+ dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ RSTRING(dst)->len = do_kconv(src, dst, out_code, in_code);
+
+ return dst;
+}
+
+static VALUE
+kconv_tojis(obj, src)
+ VALUE obj, src;
+{
+ VALUE dst;
+
+ Check_Type(src, T_STRING);
+
+ dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ RSTRING(dst)->len = do_kconv(src, dst, _JIS, _AUTO);
+
+ return dst;
+}
+
+static VALUE
+kconv_toeuc(obj, src)
+ VALUE obj, src;
+{
+ VALUE dst;
+
+ Check_Type(src, T_STRING);
+
+ dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ RSTRING(dst)->len = do_kconv(src, dst, _EUC, _AUTO);
+
+ return (VALUE)dst;
+}
+
+static VALUE
+kconv_tosjis(obj, src)
+ VALUE obj, src;
+{
+ VALUE dst;
+
+ Check_Type(src, T_STRING);
+
+ dst = str_new(0, RSTRING(src)->len*3+10); /* large enough? */
+ RSTRING(dst)->len = do_kconv(src, dst, _SJIS, _AUTO);
+
+ return dst;
+}
+
+/*
+ * Character code detection - Algorithm described in:
+ * Ken Lunde. `Understanding Japanese Information Processing'
+ * O'Reilly & Associates, Sebastopol, CA.
+ */
+
+static VALUE
+kconv_guess(obj, src)
+ VALUE obj, src;
+{
+ unsigned char *p;
+ unsigned char *pend;
+ int sequence_counter = 0;
+
+ Check_Type(src, T_STRING);
+
+ p = RSTRING(src)->ptr;
+ pend = p + RSTRING(src)->len;
+
+#define INCR do {\
+ p++;\
+ if (p==pend) return INT2FIX(_UNKNOWN);\
+ sequence_counter++;\
+ if (sequence_counter % 2 == 1 && *p != 0xa4)\
+ sequence_counter = 0;\
+ if (6 <= sequence_counter) {\
+ sequence_counter = 0;\
+ return INT2FIX(_EUC);\
+ }\
+} while (0)
+
+ if (*p == 0xa4)
+ sequence_counter = 1;
+
+ while (p<pend) {
+ if (*p == '\033') {
+ return INT2FIX(_JIS);
+ }
+ if ('\000' < *p && *p < '\006'
+ || *p == 0x7f
+ || *p == 0xdf) {
+ return INT2FIX(_BINARY);
+ }
+ if (0x81 <= *p && *p <= 0x8d) {
+ return INT2FIX(_SJIS);
+ }
+ if (0x8f <= *p && *p <= 0x9f) {
+ return INT2FIX(_SJIS);
+ }
+ if (*p == 0x8e) { /* SS2 */
+ INCR;
+ if ((0x40 <= *p && *p <= 0x7e) ||
+ (0x80 <= *p && *p <= 0xa0) ||
+ (0xe0 <= *p && *p <= 0xfc))
+ return INT2FIX(_SJIS);
+ }
+ else if (0xa1 <= *p && *p <= 0xdf) {
+ INCR;
+ if (0xf0 <= *p && *p <= 0xfe)
+ return INT2FIX(_EUC);
+ if (0xe0 <= *p && *p <= 0xef) {
+ while (p < pend && *p >= 0x40) {
+ if (*p >= 0x81) {
+ if (*p <= 0x8d || (0x8f <= *p && *p <= 0x9f)) {
+ return INT2FIX(_SJIS);
+ }
+ else if (0xfd <= *p && *p <= 0xfe) {
+ return INT2FIX(_EUC);
+ }
+ }
+ INCR;
+ }
+ }
+ else if (*p <= 0x9f) {
+ return INT2FIX(_SJIS);
+ }
+ }
+ else if (0xf0 <= *p && *p <= 0xfe) {
+ return INT2FIX(_EUC);
+ }
+ else if (0xe0 <= *p && *p <= 0xef) {
+ INCR;
+ if ((0x40 <= *p && *p <= 0x7e) ||
+ (0x80 <= *p && *p <= 0xa0)) {
+ return INT2FIX(_SJIS);
+ }
+ if (0xfd <= *p && *p <= 0xfe) {
+ return INT2FIX(_EUC);
+ }
+ }
+ INCR;
+ }
+ return INT2FIX(_UNKNOWN);
+}
+
+void
+Init_kconv()
+{
+ VALUE mKconv = rb_define_module("Kconv");
+
+ rb_define_module_function(mKconv, "kconv", kconv_kconv, -1);
+ rb_define_module_function(mKconv, "tojis", kconv_tojis, 1);
+ rb_define_module_function(mKconv, "toeuc", kconv_toeuc, 1);
+ rb_define_module_function(mKconv, "tosjis", kconv_tosjis, 1);
+ rb_define_module_function(mKconv, "guess", kconv_guess, 1);
+
+ rb_define_const(mKconv, "AUTO", INT2FIX(_AUTO));
+ rb_define_const(mKconv, "JIS", INT2FIX(_JIS));
+ rb_define_const(mKconv, "EUC", INT2FIX(_EUC));
+ rb_define_const(mKconv, "SJIS", INT2FIX(_SJIS));
+ rb_define_const(mKconv, "BINARY", INT2FIX(_BINARY));
+ rb_define_const(mKconv, "NOCONV", INT2FIX(_NOCONV));
+ rb_define_const(mKconv, "UNKNOWN", INT2FIX(_UNKNOWN));
+}
+
+/**
+ ** ¥Ñ¥Ã¥ÁÀ©ºî¼Ô
+ ** void@merope.pleiades.or.jp (Kusakabe Youichi)
+ ** NIDE Naoyuki <nide@ics.nara-wu.ac.jp>
+ ** ohta@src.ricoh.co.jp (Junn Ohta)
+ ** inouet@strl.nhk.or.jp (Tomoyuki Inoue)
+ ** kiri@pulser.win.or.jp (Tetsuaki Kiriyama)
+ ** Kimihiko Sato <sato@sail.t.u-tokyo.ac.jp>
+ ** a_kuroe@kuroe.aoba.yokohama.jp (Akihiko Kuroe)
+ ** kono@ie.u-ryukyu.ac.jp (Shinji Kono)
+ ** GHG00637@nifty-serve.or.jp (COW)
+ ** j_kuro@pluto.ai.kyutech.ac.jp (Jun Kuroda)
+ **
+ ** ºÇ½ª¹¹¿·Æü
+ ** 1996.12.18
+ **/
+
+/* end */
diff --git a/ext/nkf/depend b/ext/nkf/depend
index 645bc869c8..13e32e6074 100644
--- a/ext/nkf/depend
+++ b/ext/nkf/depend
@@ -1 +1 @@
-nkf.o : nkf.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h nkf1.7/nkf.c
+nkf.o : nkf.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h $(srcdir)/nkf1.7/nkf.c
diff --git a/ext/nkf/nkf.c b/ext/nkf/nkf.c
index 80d0d2e4be..b59688cb03 100644
--- a/ext/nkf/nkf.c
+++ b/ext/nkf/nkf.c
@@ -31,14 +31,12 @@ rb_nkf_putchar(c)
{
if (output_ctr >= o_len) {
o_len += incsize;
- rb_str_cat(dst, "", incsize);
+ rb_str_cat(dst, 0, incsize);
+ output = RSTRING(dst)->ptr;
incsize *= 2;
}
-
output[output_ctr++] = c;
-/*
-printf("[[%c][%c][%d]]\n", c, output[output_ctr - 1], output_ctr);
-*/
+
return c;
}
@@ -51,6 +49,7 @@ rb_nkf_kconv(obj, opt, src)
{
int i;
char *opt_ptr, *opt_end;
+ volatile VALUE v;
reinit();
opt_ptr = str2cstr(opt, &i);
@@ -66,7 +65,8 @@ rb_nkf_kconv(obj, opt, src)
input_ctr = 0;
input = str2cstr(src, &i_len);
- dst = rb_str_new(0, i_len*3 + 10); /* large enough? */
+ dst = rb_str_new(0, i_len*3 + 10);
+ v = dst;
output_ctr = 0;
output = RSTRING(dst)->ptr;
@@ -78,18 +78,8 @@ rb_nkf_kconv(obj, opt, src)
}
kanji_convert(NULL);
- if (output_ctr > 0) output_ctr--;
- if (output[output_ctr] == '\0') {
-/*
-printf("([%c][%d])\n", output[output_ctr], output_ctr);
-*/
- RSTRING(dst)->len = output_ctr;
- } else {
-/*
-printf("<[%c][%d]>\n", output[output_ctr], output_ctr);
-*/
- RSTRING(dst)->len = output_ctr + 1;
- }
+ RSTRING(dst)->ptr[output_ctr] = '\0';
+ RSTRING(dst)->len = output_ctr;
return dst;
}
diff --git a/ext/pty/MANIFEST b/ext/pty/MANIFEST
index 5e5af7dd6b..f46d611e5b 100644
--- a/ext/pty/MANIFEST
+++ b/ext/pty/MANIFEST
@@ -3,6 +3,7 @@ README
README.expect
README.expect.jp
README.jp
+depend
expect_sample.rb
extconf.rb
lib/expect.rb
diff --git a/ext/pty/depend b/ext/pty/depend
new file mode 100644
index 0000000000..888be6c301
--- /dev/null
+++ b/ext/pty/depend
@@ -0,0 +1 @@
+pty.o: pty.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/readline/MANIFEST b/ext/readline/MANIFEST
index f73a899abb..f8bfd1ea2c 100644
--- a/ext/readline/MANIFEST
+++ b/ext/readline/MANIFEST
@@ -1,4 +1,5 @@
MANIFEST
README
+depend
extconf.rb
readline.c
diff --git a/ext/readline/depend b/ext/readline/depend
new file mode 100644
index 0000000000..6570c5a036
--- /dev/null
+++ b/ext/readline/depend
@@ -0,0 +1 @@
+readline.o: readline.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/sdbm/MANIFEST b/ext/sdbm/MANIFEST
index d0ed99ba77..8888e69ad4 100644
--- a/ext/sdbm/MANIFEST
+++ b/ext/sdbm/MANIFEST
@@ -1,5 +1,6 @@
MANIFEST
_sdbm.c
+depend
extconf.rb
init.c
sdbm.h
diff --git a/ext/sdbm/depend b/ext/sdbm/depend
new file mode 100644
index 0000000000..1d8b13d13f
--- /dev/null
+++ b/ext/sdbm/depend
@@ -0,0 +1,2 @@
+_sdbm.o: _sdbm.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
+init.o: init.c $(hdrdir)/ruby.h $(topdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 47addfeff8..6975994ef8 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -148,7 +148,6 @@ EOF
$CFLAGS="-DHAVE_SA_LEN "+$CFLAGS
end
-have_header("sys/sysctl.h")
have_header("netinet/tcp.h")
have_header("netinet/udp.h")
@@ -160,6 +159,10 @@ if try_run(<<EOF)
#include <sys/socket.h>
#include <netinet/in.h>
+#ifndef AF_LOCAL
+#define AF_LOCAL AF_UNIX
+#endif
+
main()
{
int passive, gaierr, inet4 = 0, inet6 = 0;
@@ -176,6 +179,7 @@ main()
goto bad;
}
for (ai = aitop; ai; ai = ai->ai_next) {
+ if (ai->ai_family == AF_LOCAL) continue;
if (ai->ai_addr == NULL ||
ai->ai_addrlen == 0 ||
getnameinfo(ai->ai_addr, ai->ai_addrlen,
diff --git a/ext/tcltklib/extconf.rb b/ext/tcltklib/extconf.rb
index e1086855ba..713cc811e5 100644
--- a/ext/tcltklib/extconf.rb
+++ b/ext/tcltklib/extconf.rb
@@ -21,6 +21,7 @@ def find_tcl(tcllib)
find_library(tcllib, func, *paths)
else
find_library("tcl", func, *paths) or
+ find_library("tcl8.2", func, *paths) or
find_library("tcl8.0", func, *paths) or
find_library("tcl7.6", func, *paths)
end
@@ -33,6 +34,7 @@ def find_tk(tklib)
find_library(tklib, func, *paths)
else
find_library("tk", func, *paths) or
+ find_library("tk8.2", func, *paths) or
find_library("tk8.0", func, *paths) or
find_library("tk4.2", func, *paths)
end
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index f831dbc78a..c933f9db8b 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -2131,6 +2131,8 @@ class TkTextWin<TkWindow
end
class TkListbox<TkTextWin
+ include Scrollable
+
WidgetClassNames['Listbox'] = self
def TkListbox.to_eval
'Listbox'
diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb
index 40bfa54846..c67bc456ed 100644
--- a/ext/tk/lib/tkcanvas.rb
+++ b/ext/tk/lib/tkcanvas.rb
@@ -129,6 +129,7 @@ end
class TkCanvas<TkWindow
include TkTreatCItemFont
+ include Scrollable
WidgetClassName = 'Canvas'.freeze
WidgetClassNames[WidgetClassName] = self
diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb
index 5822c00e53..90d5fe3b43 100644
--- a/ext/tk/lib/tkentry.rb
+++ b/ext/tk/lib/tkentry.rb
@@ -15,8 +15,8 @@ class TkEntry<TkLabel
def create_self
tk_call 'entry', @path
end
- def scrollcommand(cmd)
- configure 'scrollcommand', cmd
+ def xscrollcommand(cmd=Proc.new)
+ configure_cmd 'xscrollcommand', cmd
end
def delete(s, e=None)
@@ -45,7 +45,7 @@ class TkEntry<TkLabel
tk_send 'selection', 'adjust', index
end
def selection_clear
- tk_send 'selection', 'clear', 'end'
+ tk_send 'selection', 'clear'
end
def selection_from(index)
tk_send 'selection', 'from', index
diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb
index c680d166e7..2683260d69 100644
--- a/ext/tk/lib/tkfont.rb
+++ b/ext/tk/lib/tkfont.rb
@@ -667,7 +667,20 @@ class TkFont
alias measure_core measure_core_tk8x
alias metrics_core metrics_core_tk8x
- when /^8\.1/
+ when /^8\.[12]/
+ alias create_latinfont create_latinfont_tk8x
+ alias create_kanjifont create_kanjifont_tk81
+ alias create_compoundfont create_compoundfont_tk81
+ alias actual_core actual_core_tk8x
+ alias configure_core configure_core_tk8x
+ alias configinfo_core configinfo_core_tk8x
+ alias delete_core delete_core_tk8x
+ alias latin_replace_core latin_replace_core_tk8x
+ alias kanji_replace_core kanji_replace_core_tk81
+ alias measure_core measure_core_tk8x
+ alias metrics_core metrics_core_tk8x
+
+ when /^8\.*/
alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk81
alias create_compoundfont create_compoundfont_tk81
diff --git a/file.c b/file.c
index b53c814211..ec0b24e464 100644
--- a/file.c
+++ b/file.c
@@ -1062,12 +1062,14 @@ rb_file_s_expand_path(argc, argv)
VALUE fname, dname;
char *s, *p;
char buf[MAXPATHLEN+2];
+ int tainted = 0;
rb_scan_args(argc, argv, "11", &fname, &dname);
s = STR2CSTR(fname);
p = buf;
if (s[0] == '~') {
+ tainted = 1;
if (isdirsep(s[1]) || s[1] == '\0') {
char *dir = getenv("HOME");
@@ -1110,9 +1112,11 @@ rb_file_s_expand_path(argc, argv)
else if (!isdirsep(*s)) {
if (argc == 2) {
dname = rb_file_s_expand_path(1, &dname);
+ if (OBJ_TAINTED(dname)) tainted = 1;
strcpy(buf, RSTRING(dname)->ptr);
}
else {
+ tainted = 1;
#ifdef HAVE_GETCWD
getcwd(buf, MAXPATHLEN);
#else
@@ -1172,7 +1176,9 @@ rb_file_s_expand_path(argc, argv)
if (p == buf || !isdirsep(*p)) p++;
*p = '\0';
- return rb_tainted_str_new2(buf);
+ fname = rb_str_new2(buf);
+ if (tainted) OBJ_TAINT(fname);
+ return fname;
}
static int
@@ -1203,7 +1209,7 @@ rb_file_s_basename(argc, argv)
int argc;
VALUE *argv;
{
- VALUE fname, fext;
+ VALUE fname, fext, basename;
char *name, *p, *ext;
int f;
@@ -1224,7 +1230,9 @@ rb_file_s_basename(argc, argv)
f = rmext(p, ext);
if (f) return rb_str_new(p, f);
}
- return rb_tainted_str_new2(p);
+ basename = rb_str_new2(p);
+ if (OBJ_TAINTED(fname)) OBJ_TAINT(basename);
+ return basename;
}
static VALUE
@@ -1232,6 +1240,7 @@ rb_file_s_dirname(obj, fname)
VALUE obj, fname;
{
char *name, *p;
+ VALUE dirname;
name = STR2CSTR(fname);
p = strrchr(name, '/');
@@ -1240,7 +1249,9 @@ rb_file_s_dirname(obj, fname)
}
if (p == name)
p++;
- return rb_tainted_str_new(name, p - name);
+ dirname = rb_str_new(name, p - name);
+ if (OBJ_TAINTED(fname)) OBJ_TAINT(dirname);
+ return dirname;
}
static VALUE
diff --git a/gc.c b/gc.c
index ed159a7ffd..c477d45456 100644
--- a/gc.c
+++ b/gc.c
@@ -242,8 +242,8 @@ add_heap()
/* Realloc heaps */
heaps_length += HEAPS_INCREMENT;
heaps = (heaps_used>0)?
- (RVALUE**)realloc(heaps, heaps_length*sizeof(RVALUE)):
- (RVALUE**)malloc(heaps_length*sizeof(RVALUE));
+ (RVALUE**)realloc(heaps, heaps_length*sizeof(RVALUE*)):
+ (RVALUE**)malloc(heaps_length*sizeof(RVALUE*));
if (heaps == 0) rb_fatal("can't alloc memory");
}
@@ -893,6 +893,10 @@ rb_gc()
jmp_buf save_regs_gc_mark;
#ifdef C_ALLOCA
VALUE stack_end;
+ alloca(0);
+# define STACK_END (&stack_end)
+#else
+# define STACK_END alloca(1)
#endif
alloc_objects = 0;
@@ -901,10 +905,6 @@ rb_gc()
if (during_gc) return;
during_gc++;
-#ifdef C_ALLOCA
- alloca(0);
-#endif
-
/* mark frame stack */
for (frame = ruby_frame; frame; frame = frame->prev) {
rb_gc_mark_frame(frame);
@@ -924,18 +924,14 @@ rb_gc()
/* This assumes that all registers are saved into the jmp_buf */
setjmp(save_regs_gc_mark);
mark_locations_array((VALUE*)save_regs_gc_mark, sizeof(save_regs_gc_mark) / sizeof(VALUE *));
-#ifdef C_ALLOCA
- rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)&stack_end);
-#else
- rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)alloca(1));
-#endif
+ rb_gc_mark_locations(rb_gc_stack_start, (VALUE*)STACK_END);
#if defined(THINK_C) || defined(__human68k__)
#ifndef __human68k__
mark_locations_array((VALUE*)((char*)save_regs_gc_mark+2),
sizeof(save_regs_gc_mark) / sizeof(VALUE *));
#endif
rb_gc_mark_locations((VALUE*)((char*)rb_gc_stack_start + 2),
- (VALUE*)((char*)&stack_end + 2));
+ (VALUE*)((char*)STACK_END + 2));
#endif
rb_gc_mark_threads();
@@ -943,6 +939,7 @@ rb_gc()
for (list = Global_List; list; list = list->next) {
rb_gc_mark(*list->varptr);
}
+ rb_mark_end_proc();
rb_gc_mark_global_tbl();
rb_mark_tbl(rb_class_tbl);
diff --git a/hash.c b/hash.c
index a0d11c06dd..b06b3535ea 100644
--- a/hash.c
+++ b/hash.c
@@ -79,19 +79,17 @@ static int
rb_any_cmp(a, b)
VALUE a, b;
{
+ VALUE args[2];
if (FIXNUM_P(a)) {
if (FIXNUM_P(b)) return a != b;
}
else if (TYPE(a) == T_STRING) {
if (TYPE(b) == T_STRING) return rb_str_cmp(a, b);
}
- else {
- VALUE args[2];
- args[0] = a;
- args[1] = b;
- return !rb_with_disable_interrupt(eql, (VALUE)args);
- }
+ args[0] = a;
+ args[1] = b;
+ return !rb_with_disable_interrupt(eql, (VALUE)args);
}
static int
diff --git a/intern.h b/intern.h
index 4bfefa2fd1..c916f11b46 100644
--- a/intern.h
+++ b/intern.h
@@ -57,7 +57,7 @@ VALUE rb_big_and _((VALUE, VALUE));
VALUE rb_big_or _((VALUE, VALUE));
VALUE rb_big_xor _((VALUE, VALUE));
VALUE rb_big_lshift _((VALUE, VALUE));
-VALUE rb_big_rand _((VALUE));
+VALUE rb_big_rand _((VALUE, double));
/* class.c */
VALUE rb_class_new _((VALUE));
VALUE rb_singleton_class_new _((VALUE));
@@ -82,7 +82,7 @@ VALUE rb_singleton_class _((VALUE));
/* enum.c */
VALUE rb_enum_length _((VALUE));
/* error.c */
-extern int ruby_nerrs;
+EXTERN int ruby_nerrs;
VALUE rb_exc_new _((VALUE, const char*, long));
VALUE rb_exc_new2 _((VALUE, const char*));
VALUE rb_exc_new3 _((VALUE, VALUE));
@@ -121,6 +121,7 @@ VALUE rb_f_lambda _((void));
VALUE rb_protect _((VALUE (*)(), VALUE, int*));
void rb_set_end_proc _((void (*)(), VALUE));
void rb_exec_end_proc _((void));
+void rb_mark_end_proc _((void));
void rb_gc_mark_threads _((void));
void rb_thread_start_timer _((void));
void rb_thread_stop_timer _((void));
@@ -210,6 +211,12 @@ VALUE rb_Array _((VALUE));
/* parse.y */
extern int ruby_sourceline;
extern char *ruby_sourcefile;
+#define yyparse rb_yyparse
+#define yylex rb_yylex
+#define yyerror rb_yyerror
+#define yylval rb_yylval
+#define yychar rb_yychar
+#define yydebug rb_yydebug
int yyparse _((void));
ID rb_id_attrset _((ID));
void rb_parser_append_print _((void));
diff --git a/io.c b/io.c
index c1c7d511db..9d098b331a 100644
--- a/io.c
+++ b/io.c
@@ -426,7 +426,7 @@ read_all(port)
TRAP_BEG;
n = fread(RSTRING(str)->ptr+bytes, 1, siz-bytes, fptr->f);
TRAP_END;
- if (n == 0) {
+ if (n == 0 && bytes == 0) {
if (feof(fptr->f)) return Qnil;
rb_sys_fail(fptr->path);
}
@@ -452,15 +452,15 @@ io_fread(ptr, len, f)
int c;
while (n--) {
+ if (!READ_DATA_PENDING(f)) {
+ rb_thread_wait_fd(fileno(f));
+ }
c = getc(f);
if (c == EOF) {
*ptr = '\0';
break;
}
*ptr++ = c;
- if (!READ_DATA_PENDING(f)) {
- rb_thread_wait_fd(fileno(f));
- }
}
return len - n - 1;
@@ -482,11 +482,15 @@ io_read(argc, argv, io)
}
len = NUM2INT(length);
+ if (len < 0) {
+ rb_raise(rb_eArgError, "negative length %d given", len);
+ }
GetOpenFile(io, fptr);
rb_io_check_readable(fptr);
if (feof(fptr->f)) return Qnil;
str = rb_str_new(0, len);
+ if (len == 0) return str;
READ_CHECK(fptr->f);
n = io_fread(RSTRING(str)->ptr, len, fptr->f);
@@ -1088,7 +1092,7 @@ VALUE
rb_io_binmode(io)
VALUE io;
{
-#if defined(NT) || defined(DJGPP) || defined(__CYGWIN32__)\
+#if defined(NT) || defined(DJGPP) || defined(__CYGWIN__)\
|| defined(__human68k__) || defined(USE_CWGUSI) || defined(__EMX__)
OpenFile *fptr;
@@ -1334,7 +1338,7 @@ rb_file_sysopen(fname, flags, mode)
return rb_file_sysopen_internal(rb_cFile, fname, flags, mode);
}
-#if defined (NT) || defined(DJGPP) || defined(__CYGWIN32__) || defined(__human68k__)
+#if defined (NT) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__)
static struct pipe_list {
OpenFile *fptr;
struct pipe_list *next;
@@ -1393,7 +1397,7 @@ static void
pipe_finalize(fptr)
OpenFile *fptr;
{
-#if !defined (__CYGWIN32__)
+#if !defined (__CYGWIN__)
if (fptr->f != NULL) {
pclose(fptr->f);
}
@@ -1524,7 +1528,7 @@ pipe_open(pname, mode)
if (fptr->f) fptr->f2 = f;
else fptr->f = f;
}
-#if defined (__CYGWIN32__)
+#if defined (__CYGWIN__)
fptr->finalize = pipe_finalize;
pipe_add_fptr(fptr);
#endif
@@ -2283,13 +2287,13 @@ next_argv()
fstat(fileno(fr), &st);
if (*ruby_inplace_mode) {
str = rb_str_new2(fn);
-#if defined(MSDOS) || defined(__CYGWIN32__) || defined(NT)
+#if defined(MSDOS) || defined(__CYGWIN__) || defined(NT)
ruby_add_suffix(str, ruby_inplace_mode);
#else
rb_str_cat(str, ruby_inplace_mode,
strlen(ruby_inplace_mode));
#endif
-#if defined(MSDOS) || defined(__BOW__) || defined(__CYGWIN32__) || defined(NT) || defined(__human68k__) || defined(__EMX__)
+#if defined(MSDOS) || defined(__BOW__) || defined(__CYGWIN__) || defined(NT) || defined(__human68k__) || defined(__EMX__)
(void)fclose(fr);
(void)unlink(RSTRING(str)->ptr);
(void)rename(fn, RSTRING(str)->ptr);
@@ -2304,7 +2308,7 @@ next_argv()
#endif
}
else {
-#if !defined(MSDOS) && !defined(__BOW__) && !defined(__CYGWIN32__) && !defined(NT) && !defined(__human68k__)
+#if !defined(MSDOS) && !defined(__BOW__) && !defined(__CYGWIN__) && !defined(NT) && !defined(__human68k__)
if (unlink(fn) < 0) {
rb_warn("Can't remove %s: %s, skipping file",
fn, strerror(errno));
@@ -2316,7 +2320,7 @@ next_argv()
#endif
}
fw = rb_fopen(fn, "w");
-#if !defined(MSDOS) && !defined(__CYGWIN32__) && !(NT) && !defined(__human68k__) && !defined(USE_CWGUSI) && !defined(__BEOS__) && !defined(__EMX__)
+#if !defined(MSDOS) && !defined(__CYGWIN__) && !(NT) && !defined(__human68k__) && !defined(USE_CWGUSI) && !defined(__BEOS__) && !defined(__EMX__)
fstat(fileno(fw), &st2);
fchmod(fileno(fw), st.st_mode);
if (st.st_uid!=st2.st_uid || st.st_gid!=st2.st_gid) {
@@ -2623,7 +2627,7 @@ rb_io_ctl(io, req, arg, io_p)
int io_p;
{
#if !defined(MSDOS) && !defined(__human68k__)
- int cmd = NUM2INT(req);
+ int cmd = NUM2ULONG(req);
OpenFile *fptr;
int len = 0;
int fd;
@@ -2669,7 +2673,7 @@ rb_io_ctl(io, req, arg, io_p)
fd = fileno(fptr->f);
#ifdef HAVE_FCNTL
TRAP_BEG;
-# ifdef USE_CWGUSI
+# if defined(USE_CWGUSI) || defined(__CYGWIN__)
retval = io_p?ioctl(fd, cmd, (void*) narg):fcntl(fd, cmd, narg);
# else
retval = io_p?ioctl(fd, cmd, narg):fcntl(fd, cmd, narg);
@@ -3250,9 +3254,9 @@ Init_IO()
rb_define_method(rb_cIO, "flush", rb_io_flush, 0);
rb_define_method(rb_cIO, "tell", rb_io_tell, 0);
rb_define_method(rb_cIO, "seek", rb_io_seek, 2);
- rb_define_const(rb_cIO, "SEEK_SET", SEEK_SET);
- rb_define_const(rb_cIO, "SEEK_CUR", SEEK_CUR);
- rb_define_const(rb_cIO, "SEEK_END", SEEK_END);
+ rb_define_const(rb_cIO, "SEEK_SET", INT2FIX(SEEK_SET));
+ rb_define_const(rb_cIO, "SEEK_CUR", INT2FIX(SEEK_CUR));
+ rb_define_const(rb_cIO, "SEEK_END", INT2FIX(SEEK_END));
rb_define_method(rb_cIO, "rewind", rb_io_rewind, 0);
rb_define_method(rb_cIO, "pos", rb_io_tell, 0);
rb_define_method(rb_cIO, "pos=", rb_io_set_pos, 1);
@@ -3330,7 +3334,7 @@ Init_IO()
rb_define_virtual_variable("$-i", opt_i_get, opt_i_set);
-#if defined (NT) || defined(DJGPP) || defined(__CYGWIN32__) || defined(__human68k__)
+#if defined (NT) || defined(DJGPP) || defined(__CYGWIN__) || defined(__human68k__)
atexit(pipe_atexit);
#endif
diff --git a/lib/debug.rb b/lib/debug.rb
index d2f1da83ff..f257e0c777 100644
--- a/lib/debug.rb
+++ b/lib/debug.rb
@@ -25,6 +25,8 @@ class DEBUGGER__
@last_file = nil
@last = [nil, nil]
@scripts = {}
+ @no_step = nil
+ @finish_pos = 0
end
DEBUG_LAST_CMD = []
@@ -254,9 +256,13 @@ class DEBUGGER__
STDOUT.printf "#%d %s\n", frame_pos, info
when /^fi(?:nish)?$/
- @finish_pos = @frames.size - frame_pos
- frame_pos = 0
- return
+ if frame_pos == 0
+ STDOUT.print "\"finish\" not meaningful in the outermost frame.\n"
+ else
+ @finish_pos = @frames.size - frame_pos
+ frame_pos = 0
+ return
+ end
when /^q(?:uit)?$/
input = readline("really quit? (y/n) ", false)
@@ -383,10 +389,10 @@ class DEBUGGER__
@frames.unshift binding
when 'return', 'end'
+ @frames.shift
if @frames.size == @finish_pos
@stop_next = 1
end
- @frames.shift
when 'raise'
excn_handle(file, line, id, binding)
diff --git a/lib/net/pop.rb b/lib/net/pop.rb
index bd4551571d..c492a4cd20 100644
--- a/lib/net/pop.rb
+++ b/lib/net/pop.rb
@@ -1,8 +1,14 @@
-#
-# pop.rb version 1.0.1
-#
-# author: Minero Aoki <aamine@dp.u-netsurf.ne.jp>
-#
+=begin
+
+= Net module version 1.0.2 reference manual
+
+pop.rb written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
+
+This library is distributed under the terms of Ruby style license.
+You can freely distribute/modify/copy this file.
+
+=end
+
require 'net/session'
require 'md5'
@@ -10,8 +16,44 @@ require 'md5'
module Net
+=begin
+
+== Net::POP3Session
+
+=== Super Class
+
+Net::Session
+
+=== Class Methods
+
+: new( address = 'localhost', port = 110 )
+
+ This method create a new POP3Session object but this will not open connection.
+
+=end
+
class POP3Session < Session
+
+=begin
+
+=== Methods
+
+: start( account, password )
+
+ This method start POP session.
+
+: each{|popmail| ...}
+
+ This method is equals to "POP3Session.mails.each"
+
+: mails
+
+ This method returns an array of <a href="#popi">POP3Session::POPMail</a>.
+ This array is renewed when login.
+
+=end
+
attr :mails
def each() @mails.each{|m| yield m} end
@@ -44,6 +86,17 @@ module Net
end
+=begin
+
+== Net::POP3Session::POPMail
+
+A class of mail which exists on POP server.
+
+=== Super Class
+
+Object
+
+=end
class POPMail
@@ -55,6 +108,39 @@ module Net
@deleted = false
end
+=begin
+
+=== Method
+
+: all
+: pop
+: mail
+
+ This method fetches a mail and return it.
+
+: header
+
+ This method fetches only mail header.
+
+: top( lines )
+
+ This method fetches mail header and 'lines' lines body.
+
+: delete
+: delete!
+
+ This method deletes mail.
+
+: size
+
+ size of mail(bytes)
+
+: deleted?
+
+ true if mail was deleted
+
+=end
+
attr :size
def all( dest = '' )
@@ -83,8 +169,23 @@ module Net
end
- end
+ end # POP3Session
+
+ POPSession = POP3Session
+ POP3 = POP3Session
+
+=begin
+
+== Net::APOP3Session
+
+This class has no new methods. Only way of authetication is changed.
+
+=== Super Class
+
+Net::POP3Session
+
+=end
class APOPSession < POP3Session
@@ -95,14 +196,85 @@ module Net
end
+ APOP = APOPSession
- POPSession = POP3Session
- POP3 = POP3Session
+=begin
+
+== Net::POP3Command
+
+POP3 protocol class.
+
+=== Super Class
+
+Net::Command
+
+=== Class Methods
+: new( socket )
+
+ This method creates new POP3Command object. 'socket' must be ProtocolSocket.
+
+=end
class POP3Command < Command
+
+=begin
+
+=== Methods
+
+: auth( account, password )
+
+ This method do POP authorization (no RPOP)
+ In case of failed authorization, raises Protocol::ProtocolError exception.
+
+: list
+
+ a list of mails which existing on server.
+ The list is an array like "array[ number ] = size".
+
+ ex:
+
+ The list from server is
+
+ 1 2452
+ 2 3355
+ 4 9842
+ :
+
+ then, an array is
+
+ [ nil, 2452, 3355, nil, 9842, ... ]
+
+: quit
+
+ This method finishes POP3 session.
+
+: rset
+
+ This method reset all changes done in current session,
+ by sending 'RSET' command.
+
+: top( num, lines = 0 )
+
+ This method gets all mail header and 'lines' lines body
+ by sending 'TOP' command. 'num' is mail number.
+
+ WARNING: the TOP command is 'Optional' in RFC1939 (POP3)
+
+
+: retr( num : Integer )
+
+ This method gets a mail by 'RETR' command. 'num' is mail number.
+
+
+: dele( num : Integer )
+
+ This method deletes a mail on server by 'DELE'.
+
+=end
+
def auth( acnt, pass )
@socket.writeline( 'USER ' + acnt )
check_reply_auth
@@ -190,6 +362,23 @@ module Net
end
+=begin
+
+== APOPCommand
+
+=== Super Class
+
+POP3
+
+=== Methods
+
+: auth( account, password )
+
+ This method do authorization by sending 'APOP' command.
+ If server is not APOP server, this raises Net::ProtoAuthError exception.
+ On other errors, raises Net::ProtocolError.
+
+=end
class APOPCommand < POP3Command
@@ -223,7 +412,7 @@ module Net
end
- unless Session::Version == '1.0.1' then
+ unless Session::Version == '1.0.2' then
$stderr.puts "WARNING: wrong version of session.rb & pop.rb"
end
diff --git a/lib/net/session.rb b/lib/net/session.rb
index b0977e7e14..3f7ef7f51f 100644
--- a/lib/net/session.rb
+++ b/lib/net/session.rb
@@ -1,8 +1,14 @@
-#
-# session.rb version 1.0.1
-#
-# author: Minero Aoki <aamine@dp.u-netsurf.ne.jp>
-#
+=begin
+
+= Net module version 1.0.2 reference manual
+
+session.rb written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
+
+This library is distributed under the terms of Ruby style license.
+You can freely distribute/modify/copy this file.
+
+=end
+
require 'socket'
@@ -19,16 +25,47 @@ class String
end
+=begin
-module Net
+== Net::Session
+
+the abstruct class for Internet session
+
+=== Super Class
+
+Object
+
+=== Constants
+
+: Version
+
+ The version of Session class. It is a string like "1.0.2".
+
+=end
- DEBUG = $DEBUG
- # DEBUG = false
+module Net
class Session
- Version = '1.0.1'
+ Version = '1.0.2'
+
+=begin
+
+=== Class Methods
+
+: new( address = 'localhost', port = nil )
+
+ This method Create a new Session object.
+
+: start( address = 'localhost', port = nil, *args )
+: start( address = 'localhost', port = nil, *args ){|session| .... }
+
+ This method create a new Session object and start session.
+ If you call this method with block, Session object give itself
+ to block and finish session when block returns.
+
+=end
def initialize( addr = 'localhost', port = nil )
proto_initialize
@@ -50,6 +87,19 @@ module Net
end
end
+=begin
+
+=== Methods
+
+: address
+
+ the address of connecting server (FQDN).
+
+: port
+
+ connecting port number
+
+=end
attr :address
attr :port
@@ -59,21 +109,45 @@ module Net
attr :proto_type
attr :proto, true
+=begin
+
+: start( *args )
+
+ This method start session. If you call this method when the session
+ is already started, this only returns false without doing anything.
+
+ '*args' are specified in subclasses.
+
+: finish
+
+ This method finish session. If you call this method before session starts,
+ it only return false without doing anything.
+
+: active?
+
+ true if session have been started
+
+=end
+
def start( *args )
return false if active?
+ @active = true
if ProtocolSocket === args[0] then
@socket = args.shift
+ @socket.pipe = @pipe
else
- @socket = ProtocolSocket.open( @address, @port )
+ @socket = ProtocolSocket.open( @address, @port, @pipe )
end
+ @pipe = nil
+
@proto = @proto_type.new( @socket )
do_start( *args )
-
- @active = true
end
def finish
+ @active = false
+
if @proto then
do_finish
@proto = nil
@@ -86,9 +160,36 @@ module Net
def active?() @active end
+ def set_pipe( arg )
+ @pipe = arg
+ end
+
end
+=begin
+
+== Net::Command
+
+=== Super Class
+
+Object
+
+=== Class Methods
+
+: new( socket )
+
+ This method create new Command object. 'socket' must be ProtocolSocket.
+ This method is abstract class.
+
+
+=== Methods
+
+: quit
+
+ This method finishes protocol.
+
+=end
class Command
@@ -181,12 +282,28 @@ MES
end
+=begin
+
+== Net::ProtocolSocket
+
+=== Super Class
+
+Object
+
+=== Class Methods
+
+: new( address = 'localhost', port = nil )
+
+ This create new ProtocolSocket object, and connect to server.
+
+=end
class ProtocolSocket
- def initialize( addr, port )
+ def initialize( addr, port, pipe = nil )
@address = addr
@port = port
+ @pipe = pipe
@ipaddr = ''
@closed = false
@@ -195,14 +312,39 @@ MES
@socket = TCPsocket.new( addr, port )
@ipaddr = @socket.addr[3]
-
- @dout = Net::DEBUG
end
+ attr :pipe, true
+
class << self
alias open new
end
+=begin
+
+=== Methods
+
+: close
+
+ This method closes socket.
+
+: addr
+
+ a FQDN address of server
+
+: ipaddr
+
+ an IP address of server
+
+: port
+
+ connecting port number.
+
+: closed?
+
+ true if ProtocolSokcet have been closed already
+
+=end
attr :socket, true
@@ -225,6 +367,36 @@ MES
TERMEXP = /\n|\r\n|\r/o
+=begin
+
+: read( length )
+
+ This method read 'length' bytes and return the string.
+
+: readuntil( target )
+
+ This method read until find 'target'. Returns read string.
+
+: readline
+
+ read until "\r\n" and returns it without "\r\n".
+
+: read_pendstr
+
+ This method read until "\r\n.\r\n".
+ At the same time, delete period at line head and final line ("\r\n.\r\n").
+
+: read_pendlist
+: read_pendlist{|line| .... }
+
+ This method read until "\r\n.\r\n". This method resembles to 'read_pendstr',
+ but 'read_pendlist' don't check period at line head, and returns array which
+ each element is one line.
+
+ When this method was called with block, evaluate it for each reading a line.
+
+=end
+
def read( len, ret = '' )
rsize = 0
@@ -256,7 +428,7 @@ MES
def read_pendstr( dest = '' )
- $stderr.puts "reading pendstr" if pre = @dout ; @dout = false
+ @pipe << "reading text...\n" if pre = @pipe ; @pipe = nil
rsize = 0
@@ -266,12 +438,14 @@ MES
dest << str
end
- $stderr.puts "read pendstr #{rsize} bytes" if @dout = pre
+ @pipe << "read #{rsize} bytes\n" if @pipe = pre
return dest
end
def read_pendlist
+ @pipe << "reading list...\n" if pre = @pipe ; @pipe = nil
+
arr = []
str = nil
call = iterator?
@@ -282,6 +456,7 @@ MES
yield str if iterator?
end
+ @pipe << "read #{arr.size} lines\n" if @pipe = pre
return arr
end
@@ -300,16 +475,34 @@ MES
ret = @buffer[ 0, len ]
@buffer = @buffer[ len, bsi - len ]
- if @dout then
- $stderr.print 'read "'
- debugout ret
- $stderr.print "\"\n"
- end
+ @pipe << %{read "#{debugstr ret}"\n} if @pipe
return ret
end
- ### write
+=begin
+
+: write( src )
+
+ This method send 'src'. ProtocolSocket read strings from 'src' by 'each'
+ iterator. This method returns written bytes.
+
+: writebin( src )
+
+ This method send 'src'. ProtocolSokcet read string from 'src' by 'each'
+ iterator. This method returns written bytes.
+
+: writeline( str )
+
+ This method writes 'str'. There has not to be bare "\r" or "\n" in 'str'.
+
+: write_pendstr( src )
+
+ This method writes 'src' as a mail.
+ ProtocolSocket reads strings from 'src' by 'each' iterator.
+ This returns written bytes.
+
+=end
public
@@ -341,8 +534,7 @@ MES
def write_pendstr( src )
- $stderr.puts "writing pendstr from #{src.type}" if pre = @dout
- @dout = false
+ @pipe << "writing text from #{src.type}" if pre = @pipe ; @pipe = nil
do_write_beg
each_crlf_line( src ) do |line|
@@ -352,7 +544,7 @@ MES
do_write_do D_CRLF
wsize = do_write_fin
- $stderr.puts "wrote pendstr #{wsize} bytes" if @dout = pre
+ @pipe << "wrote #{wsize} bytes text" if @pipe = pre
return wsize
end
@@ -382,7 +574,7 @@ MES
buf << "\n" unless /\n|\r/o === buf[-1,1]
beg = 0
- while pos = buf.index(TERMEXP, beg) do
+ while pos = buf.index( TERMEXP, beg ) do
pos += $&.size
tmp = buf[ beg, pos - beg ]
tmp.chop!
@@ -393,39 +585,46 @@ MES
def do_write_beg
- $stderr.print 'write "' if @dout
+ @wtmp = 'write "' if @pipe
@writtensize = 0
@sending = ''
end
def do_write_do( arg )
- debugout arg if @dout
+ @wtmp << debugstr( arg ) if @pipe
if @sending.size < 128 then
@sending << arg
else
@sending << '...' unless @sending[-1] == ?.
end
+
s = @socket.write( arg )
@writtensize += s
return s
end
def do_write_fin
- $stderr.puts if @dout
+ if @pipe then
+ @wtmp << "\n"
+ @pipe << @wtmp
+ @wtmp = nil
+ end
@socket.flush
return @writtensize
end
- def debugout( ret )
- while ret and tmp = ret[ 0, 50 ] do
- ret = ret[ 50, ret.size - 50 ]
+ def debugstr( str )
+ ret = ''
+ while str and tmp = str[ 0, 50 ] do
+ str = str[ 50, str.size - 50 ]
tmp = tmp.inspect
- $stderr.print tmp[ 1, tmp.size - 2 ]
+ ret << tmp[ 1, tmp.size - 2 ]
end
+ ret
end
end
diff --git a/lib/net/smtp.rb b/lib/net/smtp.rb
index 9f534c20c0..de97feaa23 100644
--- a/lib/net/smtp.rb
+++ b/lib/net/smtp.rb
@@ -1,12 +1,34 @@
-#
-# smtp.rb version 1.0.1
-#
-# author Minero Aoki <aamine@dp.u-netsurf.ne.jp>
-#
+=begin
+
+= Net module version 1.0.2 reference manual
+
+smtp.rb written by Minero Aoki <aamine@dp.u-netsurf.ne.jp>
+
+This library is distributed under the terms of Ruby style license.
+You can freely redistribute/modify/copy this file.
+
+=end
+
require 'net/session'
+=begin
+
+== Net::SMTPSession
+
+=== Super Class
+
+Net::Session
+
+=== Class Methods
+
+: new( address = 'localhost', port = 25 )
+
+ This method create new SMTPSession object.
+
+=end
+
module Net
class SMTPSession < Session
@@ -16,6 +38,33 @@ module Net
@port = 25
end
+=begin
+
+=== Methods
+
+: start( helo_domain = ENV['HOSTNAME'] )
+
+ This method opens TCP connection and start SMTP session.
+ If session had been started, do nothing and return false.
+
+: sendmail( mailsrc, from_domain, to_addrs )
+
+ This method sends 'mailsrc' as mail. SMTPSession read strings from 'mailsrc'
+ by calling 'each' iterator, and convert them into "\r\n" terminated string when write.
+
+ SMTPSession's Exceptions are:
+ * Protocol::ProtoSyntaxError: syntax error (errno.500)
+ * Protocol::ProtoFatalError: fatal error (errno.550)
+ * Protocol::ProtoUnknownError: unknown error
+ * Protocol::ProtoServerBusy: temporary error (errno.420/450)
+
+: finish
+
+ This method closes SMTP session.
+ If session had not started, do nothind and return false.
+
+=end
+
def sendmail( mailsrc, fromaddr, toaddrs )
@proto.mailfrom( fromaddr )
@proto.rcpt( toaddrs )
@@ -43,6 +92,48 @@ module Net
SMTP = SMTPSession
+=begin
+
+== Net::SMTPCommand
+
+=== Super Class
+
+Net::Command
+
+=== Class Methods
+
+: new( socket )
+
+ This method creates new SMTPCommand object, and open SMTP session.
+
+
+=== Methods
+
+: helo( helo_domain )
+
+ This method send "HELO" command and start SMTP session.<br>
+ helo_domain is localhost's FQDN.
+
+: mailfrom( from_addr )
+
+ This method sends "MAIL FROM" command.<br>
+ from_addr is your mail address(????@????).
+
+: rcpt( to_addrs )
+
+ This method sends "RCPT TO" command.<br>
+ to_addrs is array of mail address(???@???) of destination.
+
+: data( mailsrc )
+
+ This method send 'mailsrc' as mail. SMTP reads strings from 'mailsrc'
+ by calling 'each' iterator.
+
+: quit
+
+ This method sends "QUIT" command and ends SMTP session.
+
+=end
class SMTPCommand < Command
@@ -121,7 +212,7 @@ module Net
end
- unless Session::Version == '1.0.1' then
+ unless Session::Version == '1.0.2' then
$stderr.puts "WARNING: wrong version of session.rb & smtp.rb"
end
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 2aa9864b58..0f37491baf 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -13,6 +13,7 @@
# end
require "marshal"
+require "ftools"
class PStore
class Error < StandardError
@@ -77,12 +78,19 @@ class PStore
raise PStore::Error, "nested transaction" if @transaction
begin
@transaction = true
- value = file = nil
- begin
- File::open(@filename, "r") do |file|
- @table = Marshal.load(file)
- end
- rescue Errno::ENOENT
+ value = nil
+ backup = @filename+"~"
+ if File::exist?(@filename)
+ file = File::open(@filename, "r+")
+ orig = true
+ else
+ file = File::open(@filename, "w+")
+ end
+ file.flock(File::LOCK_EX)
+ if orig
+ File::copy @filename, backup
+ @table = Marshal::load(file)
+ else
@table = {}
end
begin
@@ -95,16 +103,11 @@ class PStore
ensure
unless @abort
begin
- File::rename @filename, @filename+"~"
- rescue Errno::ENOENT
- no_orig = true
- end
- begin
- File::open(@filename, "w") do |file|
- Marshal::dump(@table, file)
- end
+ file.rewind
+ Marshal::dump(@table, file)
rescue
- File::rename @filename+"~", @filename unless no_orig
+ File::rename backup, @filename if File::exist?(backup)
+ raise
end
end
@abort = false
@@ -112,6 +115,7 @@ class PStore
ensure
@table = nil
@transaction = false
+ file.close if file
end
value
end
diff --git a/lib/singleton.rb b/lib/singleton.rb
index 8167a01aa8..4aea574e7a 100644
--- a/lib/singleton.rb
+++ b/lib/singleton.rb
@@ -14,6 +14,7 @@ module Singleton
def Singleton.append_features(klass)
klass.private_class_method(:new)
klass.instance_eval %{
+ @__instance__ = nil
def instance
unless @__instance__
@__instance__ = new
diff --git a/marshal.c b/marshal.c
index 82d6907276..4f13724a27 100644
--- a/marshal.c
+++ b/marshal.c
@@ -449,7 +449,7 @@ struct load_arg {
FILE *fp;
char *ptr, *end;
st_table *symbol;
- st_table *data;
+ VALUE data;
VALUE proc;
};
@@ -602,7 +602,7 @@ r_regist(v, arg)
if (arg->proc) {
rb_funcall(arg->proc, rb_intern("call"), 1, v);
}
- st_insert(arg->data, arg->data->num_entries, v);
+ rb_hash_aset(arg->data, INT2FIX(RHASH(arg->data)->tbl->num_entries), v);
return v;
}
@@ -612,14 +612,17 @@ r_object(arg)
{
VALUE v;
int type = r_byte(arg);
+ long id;
switch (type) {
case TYPE_LINK:
- if (st_lookup(arg->data, r_long(arg), &v)) {
- return v;
+ id = r_long(arg);
+ v = rb_hash_aref(arg->data, INT2FIX(id));
+ if (NIL_P(v)) {
+ rb_raise(rb_eArgError, "dump format error (unlinked)");
}
- rb_raise(rb_eArgError, "dump format error (unlinked)");
- break;
+ return v;
+ break;
case TYPE_UCLASS:
{
@@ -789,7 +792,7 @@ r_object(arg)
{
char *buf;
r_bytes(buf, arg);
- return rb_path2class(buf);
+ return r_regist(rb_path2class(buf), arg);
}
default:
@@ -811,7 +814,6 @@ load_ensure(arg)
struct load_arg *arg;
{
st_free_table(arg->symbol);
- st_free_table(arg->data);
return 0;
}
@@ -846,11 +848,13 @@ marshal_load(argc, argv)
major = r_byte(&arg);
if (major == MARSHAL_MAJOR) {
+ volatile VALUE hash; /* protect from GC */
+
if (r_byte(&arg) != MARSHAL_MINOR) {
rb_warn("Old marshal file format (can be read)");
}
arg.symbol = st_init_numtable();
- arg.data = st_init_numtable();
+ arg.data = hash = rb_hash_new();
if (NIL_P(proc)) arg.proc = 0;
else arg.proc = proc;
v = rb_ensure(load, (VALUE)&arg, load_ensure, (VALUE)&arg);
diff --git a/misc/inf-ruby.el b/misc/inf-ruby.el
index eaa904951c..f192147a37 100644
--- a/misc/inf-ruby.el
+++ b/misc/inf-ruby.el
@@ -18,7 +18,7 @@
;;; "Mode for editing ruby source files")
;;; (setq auto-mode-alist
;;; (append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
-;;; (setq interpreter-mode-alist (append '(("^#!.*ruby" . ruby-mode))
+;;; (setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
;;; interpreter-mode-alist))
;;;
;;; (2) set to road inf-ruby and set inf-ruby key definition in ruby-mode.
@@ -35,9 +35,12 @@
;;; HISTORY
;;; senda - 8 Apr 1998: Created.
;;; $Log$
+;;; Revision 1.2.2.1 1999/12/01 09:24:48 matz
+;;; 19991201
+;;;
;;; Revision 1.2 1999/08/13 05:45:18 matz
;;; 1.4.0
-;;;
+;;;
;;; Revision 1.1.1.1.2.1 1999/07/15 07:59:59 matz
;;; 990715
;;;
diff --git a/misc/ruby-mode.el b/misc/ruby-mode.el
index 50e4f50e87..5ebf4f875e 100644
--- a/misc/ruby-mode.el
+++ b/misc/ruby-mode.el
@@ -180,12 +180,7 @@ The variable ruby-indent-level controls the amount of indentation.
(back-to-indentation)
(setq top (current-column))
(skip-chars-backward " \t")
- (cond
- ((>= x shift)
- (setq shift 0))
- ((>= shift top)
- (setq shift (- shift top)))
- (t (setq shift 0)))
+ (if (>= shift top) (setq shift (- shift top)))
(if (and (bolp)
(= x top))
(move-to-column (+ x shift))
@@ -669,7 +664,6 @@ An end of a defun is found by moving forward from the beginning of one."
"return"
"then"
"throw"
- "self"
"super"
"unless"
"undef"
@@ -681,8 +675,8 @@ An end of a defun is found by moving forward from the beginning of one."
"\\)\\>[^_]")
2)
;; variables
- '("\\b\\(nil\\|self\\|true\\|false\\)\\b"
- 1 font-lock-variable-name-face)
+ '("\\(^\\|[^_:.@$]\\|\\.\\.\\)\\b\\(nil\\|self\\|true\\|false\\)\\b[^_]"
+ 2 font-lock-variable-name-face)
;; variables
'("[$@].\\(\\w\\|_\\)*"
0 font-lock-variable-name-face)
diff --git a/missing/fnmatch.c b/missing/fnmatch.c
deleted file mode 100644
index 4cf746118a..0000000000
--- a/missing/fnmatch.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Copyright (c) 1989, 1993, 1994
- * The Regents of the University of California. All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * Guido van Rossum.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
-#endif /* LIBC_SCCS and not lint */
-
-/*
- * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
- * Compares a filename or pathname to a pattern.
- */
-
-#include "missing/fnmatch.h"
-#include <string.h>
-
-#define EOS '\0'
-
-static char *rangematch();
-
-int
-fnmatch(pattern, string, flags)
- char *pattern;
- char *string;
- int flags;
-{
- char *stringstart;
- char c, test;
-
- for (stringstart = string;;) {
- switch (c = *pattern++) {
- case EOS:
- return (*string == EOS ? 0 : FNM_NOMATCH);
- case '?':
- if (*string == EOS) {
- return (FNM_NOMATCH);
- }
- if (*string == '/' && (flags & FNM_PATHNAME)) {
- return (FNM_NOMATCH);
- }
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
- return (FNM_NOMATCH);
- }
- ++string;
- break;
- case '*':
- c = *pattern;
- /* Collapse multiple stars. */
- while (c == '*') {
- c = *++pattern;
- }
-
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
- return (FNM_NOMATCH);
- }
-
- /* Optimize for pattern with * at end or before /. */
- if (c == EOS) {
- if (flags & FNM_PATHNAME) {
- return (strchr(string, '/') == NULL ? 0 : FNM_NOMATCH);
- }
- else {
- return (0);
- }
- }
- else if (c == '/' && flags & FNM_PATHNAME) {
- if ((string = strchr(string, '/')) == NULL) {
- return (FNM_NOMATCH);
- }
- break;
- }
-
- /* General case, use recursion. */
- while ((test = *string) != EOS) {
- if (!fnmatch(pattern, string, flags & ~FNM_PERIOD)) {
- return (0);
- }
- if (test == '/' && flags & FNM_PATHNAME) {
- break;
- }
- ++string;
- }
- return (FNM_NOMATCH);
- case '[':
- if (*string == EOS) {
- return (FNM_NOMATCH);
- }
- if (*string == '/' && flags & FNM_PATHNAME) {
- return (FNM_NOMATCH);
- }
- if (*string == '.' && (flags & FNM_PERIOD) &&
- (string == stringstart ||
- ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) {
- return (FNM_NOMATCH);
- }
- if ((pattern = rangematch(pattern, *string, flags)) == NULL) {
- return (FNM_NOMATCH);
- }
- ++string;
- break;
- case '\\':
- if (!(flags & FNM_NOESCAPE)) {
- if ((c = *pattern++) == EOS) {
- c = '\\';
- --pattern;
- }
- }
- /* FALLTHROUGH */
- default:
- if (c != *string) {
- return (FNM_NOMATCH);
- }
- string++;
- break;
- }
- /* NOTREACHED */
- }
-}
-
-static char*
-rangematch(pattern, test, flags)
- char *pattern;
- int test, flags;
-{
- int negate, ok;
- char c, c2;
-
- /*
- * A bracket expression starting with an unquoted circumflex
- * character produces unspecified results (IEEE 1003.2-1992,
- * 3.13.2). This implementation treats it like '!', for
- * consistency with the regular expression syntax.
- * J.T. Conklin (conklin@ngai.kaleida.com)
- */
- if ((negate = (*pattern == '!' || *pattern == '^'))) {
- ++pattern;
- }
-
- for (ok = 0; (c = *pattern++) != ']';) {
- if (c == '\\' && !(flags & FNM_NOESCAPE)) {
- c = *pattern++;
- }
- if (c == EOS) {
- return (NULL);
- }
- if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') {
- pattern += 2;
- if (c2 == '\\' && !(flags & FNM_NOESCAPE)) {
- c2 = *pattern++;
- }
- if (c2 == EOS) {
- return (NULL);
- }
- if (c <= test && test <= c2) {
- ok = 1;
- }
- }
- else if (c == test) {
- ok = 1;
- }
- }
- return (ok == negate ? NULL : pattern);
-}
diff --git a/missing/fnmatch.h b/missing/fnmatch.h
deleted file mode 100644
index 773851625a..0000000000
--- a/missing/fnmatch.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*-
- * Copyright (c) 1992, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93
- */
-
-/* This file has been modified by matz@netlab.co.jp */
-
-#ifndef _FNMATCH_H_
-#define _FNMATCH_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define FNM_NOMATCH 1 /* Match failed. */
-
-#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
-#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
-#define FNM_PERIOD 0x04 /* Period must be matched by period. */
-
-int fnmatch();
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !_FNMATCH_H_ */
diff --git a/node.h b/node.h
index 4add37b47c..ea44a454d5 100644
--- a/node.h
+++ b/node.h
@@ -13,6 +13,10 @@
#ifndef NODE_H
#define NODE_H
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
enum node_type {
NODE_METHOD,
NODE_FBODY,
@@ -331,4 +335,8 @@ VALUE rb_gvar_get _((struct global_entry *));
VALUE rb_gvar_set _((struct global_entry *, VALUE));
VALUE rb_gvar_defined _((struct global_entry *));
+#if defined(__cplusplus)
+} /* extern "C" { */
+#endif
+
#endif
diff --git a/numeric.c b/numeric.c
index d1c016e708..f3e5d55379 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1169,12 +1169,10 @@ fix_rshift(x, y)
long i, val;
i = NUM2LONG(y);
- if (i < sizeof(long) * 8) {
- val = RSHIFT(FIX2LONG(x), i);
- return INT2FIX(val);
- }
-
- return INT2FIX(0);
+ if (i < 0)
+ return fix_lshift(x, INT2FIX(-i));
+ val = RSHIFT(FIX2LONG(x), i);
+ return INT2FIX(val);
}
static VALUE
diff --git a/process.c b/process.c
index d5c2d5eb8a..211445b88d 100644
--- a/process.c
+++ b/process.c
@@ -600,6 +600,13 @@ rb_f_system(argc, argv)
VALUE cmd;
int state;
+ fflush(stdout);
+ fflush(stderr);
+ if (argc == 0) {
+ rb_last_status = INT2FIX(0);
+ rb_raise(rb_eArgError, "wrong # of arguments");
+ }
+
if (TYPE(argv[0]) == T_ARRAY) {
if (RARRAY(argv[0])->len != 2) {
rb_raise(rb_eArgError, "wrong first argument");
@@ -619,6 +626,11 @@ rb_f_system(argc, argv)
VALUE cmd;
int state;
+ if (argc == 0) {
+ rb_last_status = INT2FIX(0);
+ rb_raise(rb_eArgError, "wrong # of arguments");
+ }
+
if (TYPE(argv[0]) == T_ARRAY) {
if (RARRAY(argv[0])->len != 2) {
rb_raise(rb_eArgError, "wrong first argument");
@@ -644,7 +656,7 @@ rb_f_system(argc, argv)
fflush(stderr);
if (argc == 0) {
rb_last_status = INT2FIX(0);
- return INT2FIX(0);
+ rb_raise(rb_eArgError, "wrong # of arguments");
}
if (TYPE(argv[0]) == T_ARRAY) {
@@ -667,7 +679,7 @@ rb_f_system(argc, argv)
#if defined(USE_CWGUSI)
rb_notimplement();
#else
- volatile VALUE prog = 0;
+ volatile VALUE prog = 0;
int pid;
int i;
@@ -675,7 +687,7 @@ rb_f_system(argc, argv)
fflush(stderr);
if (argc == 0) {
rb_last_status = INT2FIX(0);
- return INT2FIX(0);
+ rb_raise(rb_eArgError, "wrong # of arguments");
}
if (TYPE(argv[0]) == T_ARRAY) {
diff --git a/random.c b/random.c
index e977094eaa..67c752d0f7 100644
--- a/random.c
+++ b/random.c
@@ -87,11 +87,11 @@ rb_f_srand(argc, argv, obj)
VALUE *argv;
VALUE obj;
{
- VALUE seed;
- int old;
- static int saved_seed;
+ VALUE a;
+ unsigned int seed, old;
+ static unsigned int saved_seed;
- if (rb_scan_args(argc, argv, "01", &seed) == 0) {
+ if (rb_scan_args(argc, argv, "01", &a) == 0) {
static int n = 0;
struct timeval tv;
@@ -99,7 +99,7 @@ rb_f_srand(argc, argv, obj)
seed = tv.tv_sec ^ tv.tv_usec ^ getpid() ^ n++;
}
else {
- seed = NUM2UINT(seed);
+ seed = NUM2UINT(a);
}
#ifdef HAVE_RANDOM
@@ -116,7 +116,7 @@ rb_f_srand(argc, argv, obj)
old = saved_seed;
saved_seed = seed;
- return rb_int2inum(old);
+ return rb_uint2inum(old);
}
static VALUE
@@ -126,13 +126,12 @@ rb_f_rand(obj, vmax)
long val, max;
switch (TYPE(vmax)) {
- case T_BIGNUM:
- return rb_big_rand(vmax);
-
case T_FLOAT:
- if (RFLOAT(vmax)->value > LONG_MAX || RFLOAT(vmax)->value < LONG_MIN)
- return rb_big_rand(rb_dbl2big(RFLOAT(vmax)->value));
- break;
+ if (RFLOAT(vmax)->value <= LONG_MAX && RFLOAT(vmax)->value >= LONG_MIN)
+ break;
+ /* fall through */
+ case T_BIGNUM:
+ return rb_big_rand(vmax, RANDOM_NUMBER);
}
max = NUM2LONG(vmax);
diff --git a/re.c b/re.c
index ac73732d39..c038f2c1c6 100644
--- a/re.c
+++ b/re.c
@@ -182,6 +182,21 @@ kcode_reset_option()
}
}
+int
+rb_mbclen2(c, re)
+ unsigned char c;
+ VALUE re;
+{
+ int len;
+
+ if (!FL_TEST(re, KCODE_FIXED))
+ return mbclen(c);
+ kcode_set_option(re);
+ len = mbclen(c);
+ kcode_reset_option();
+ return len;
+}
+
extern int ruby_in_compile;
static void
@@ -260,9 +275,8 @@ static VALUE
rb_reg_source(re)
VALUE re;
{
- VALUE str = rb_str_new(0,0);
- rb_reg_expr_str(str, RREGEXP(re)->str,RREGEXP(re)->len);
-
+ VALUE str = rb_str_new(RREGEXP(re)->str,RREGEXP(re)->len);
+ if (OBJ_TAINTED(re)) OBJ_TAINT(str);
return str;
}
@@ -538,6 +552,7 @@ rb_reg_search(reg, str, pos, reverse)
}
result = re_search(RREGEXP(reg)->ptr,RSTRING(str)->ptr,RSTRING(str)->len,
pos, range, regs);
+
if (FL_TEST(reg, KCODE_FIXED))
kcode_reset_option();
@@ -710,7 +725,7 @@ static VALUE
match_string(match)
VALUE match;
{
- return rb_str_dup(RMATCH(match)->str);
+ return RMATCH(match)->str; /* str is frozen */
}
VALUE rb_cRegexp;
@@ -1263,7 +1278,9 @@ Init_Regexp()
rb_global_variable(&reg_cache);
rb_global_variable(&matchcache);
- rb_cMatch = rb_define_class("MatchingData", rb_cData);
+ rb_cMatch = rb_define_class("MatchingData", rb_cObject);
+ rb_undef_method(CLASS_OF(rb_cMatch), "new");
+
rb_define_method(rb_cMatch, "clone", match_clone, 0);
rb_define_method(rb_cMatch, "size", match_size, 0);
rb_define_method(rb_cMatch, "length", match_size, 0);
diff --git a/re.h b/re.h
index dc4cd17354..9d3b77f519 100644
--- a/re.h
+++ b/re.h
@@ -36,4 +36,7 @@ VALUE rb_reg_regsub _((VALUE, VALUE, struct re_registers *));
int rb_kcode _((void));
extern int ruby_ignorecase;
+
+int rb_mbclen2 _((unsigned char, VALUE));
+#define mbclen2(c,re) rb_mbclen2((c),(re))
#endif
diff --git a/regex.c b/regex.c
index fd8a447b05..9988be2d2a 100644
--- a/regex.c
+++ b/regex.c
@@ -48,13 +48,6 @@
# include <sys/types.h>
#endif
-#if defined(STDC_HEADERS)
-# include <stddef.h>
-#else
-/* We need this for `regex.h', and perhaps for the Emacs include files. */
-# include <sys/types.h>
-#endif
-
#ifndef __STDC__
# define volatile
#endif
@@ -1406,7 +1399,8 @@ re_compile_pattern(pattern, size, bufp)
case 'W':
for (c = 0; c < (1 << BYTEWIDTH); c++) {
if (SYNTAX(c) != Sword &&
- (current_mbctype || SYNTAX(c) != Sword2))
+ (current_mbctype && !re_mbctab[c] ||
+ !current_mbctype && SYNTAX(c) != Sword2))
SET_LIST_BIT(c);
}
last = -1;
diff --git a/ruby.c b/ruby.c
index 0b4d486ec8..752b2b18fc 100644
--- a/ruby.c
+++ b/ruby.c
@@ -176,8 +176,11 @@ rubylib_mangle(s, l)
strcpy(ret + newl, s + oldl);
return ret;
}
+#define rubylib_mangled_path(s, l) rb_str_new2(rubylib_mangle((s), (l)))
+#define rubylib_mangled_path2(s) rb_str_new2(rubylib_mangle((s), 0))
#else
-#define rubylib_mangle(s, l) (s)
+#define rubylib_mangled_path(s, l) rb_str_new((s), (l))
+#define rubylib_mangled_path2(s) rb_str_new2(s)
#endif
static void
@@ -202,18 +205,18 @@ addpath(path)
while (*p) {
while (*p == sep) p++;
if (s = strchr(p, sep)) {
- rb_ary_push(ary, rb_str_new(rubylib_mangle(p, (int)(s-p)), (int)(s-p)));
+ rb_ary_push(ary, rubylib_mangled_path(p, (int)(s-p)));
p = s + 1;
}
else {
- rb_ary_push(ary, rb_str_new2(rubylib_mangle(p, 0)));
+ rb_ary_push(ary, rubylib_mangled_path2(p));
break;
}
}
rb_load_path = rb_ary_plus(ary, rb_load_path);
}
else {
- rb_ary_unshift(rb_load_path, rb_str_new2(rubylib_mangle(path, 0)));
+ rb_ary_unshift(rb_load_path, rubylib_mangled_path2(path));
}
}
diff --git a/rubytest.rb b/rubytest.rb
index 7b886fd3f4..20032e303e 100644
--- a/rubytest.rb
+++ b/rubytest.rb
@@ -9,6 +9,8 @@ if File.exist? CONFIG['LIBRUBY_SO']
dldpath = "SHLIB_PATH"
when /-aix/
dldpath = "LIBPATH"
+ when /-beos/
+ dldpath = "LIBRARY_PATH"
else
dldpath = "LD_LIBRARY_PATH"
end
diff --git a/sample/io.rb b/sample/io.rb
deleted file mode 100644
index 0b38d2112d..0000000000
--- a/sample/io.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-# IO test
-# usage: ruby io.rb file..
-
-home = ENV["HOME"]
-home.sub("m", "&&")
-print(home, "\n")
-print(home.reverse, "\n")
-
-if File.s("io.rb")
- print(File.s("io.rb"), ": io.rb\n")
-end
-
-$/="f\n"
-for i in "abc\n\ndef\nghi\n"
- print("tt: ", i)
-end
-
-printf("%s:(%d)%s\n", $0, ARGV.length, ARGV[0])
-passwd = open(ARGV[0], "r")
-#printf("%s", passwd.find{i|i =~ /\*/})
-
-n = 1
-for i in passwd #.grep(/^\*/)
- printf("%6d: %s", n, i)
- n = n + 1;
-end
-
-fp = open("|-", "r")
-
-if fp == nil
- for i in 1..5
- print(i, "\n")
- end
-else
- for line in fp
- print(line)
- end
-end
-
-def printUsage()
- if $USAGE
- apply($USAGE);
- end
-end
diff --git a/signal.c b/signal.c
index 6489760bc6..fe1107d46d 100644
--- a/signal.c
+++ b/signal.c
@@ -298,7 +298,7 @@ posix_signal(signum, handler)
sigact.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */
#endif
#ifdef SA_NOCLDWAIT
- if (signum == SIGCHLD && handler == (RETSIGTYPE)SIG_IGN)
+ if (signum == SIGCHLD && handler == SIG_IGN)
sigact.sa_flags |= SA_NOCLDWAIT;
#endif
sigaction(signum, &sigact, 0);
diff --git a/sprintf.c b/sprintf.c
index 3c71e9771f..346cf2b643 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -147,12 +147,13 @@ rb_f_sprintf(argc, argv)
char *buf, *p, *end;
int blen, bsiz;
VALUE result;
-
int width, prec, flags = FNONE;
+ int tainted = 0;
VALUE tmp;
VALUE str;
fmt = GETARG();
+ if (OBJ_TAINTED(fmt)) tainted = 1;
p = str2cstr(fmt, &blen);
end = p + blen;
blen = 0;
@@ -172,6 +173,7 @@ rb_f_sprintf(argc, argv)
p = t + 1; /* skip `%' */
width = prec = -1;
+
retry:
switch (*p) {
default:
@@ -290,6 +292,7 @@ rb_f_sprintf(argc, argv)
int len;
str = rb_obj_as_string(arg);
+ if (OBJ_TAINTED(str)) tainted = 1;
len = RSTRING(str)->len;
if (flags&FPREC) {
if (prec < len) {
@@ -618,6 +621,7 @@ rb_f_sprintf(argc, argv)
result = rb_str_new(buf, blen);
free(buf);
+ if (tainted) OBJ_TAINT(result);
return result;
}
diff --git a/string.c b/string.c
index f7366cf99a..1f357efdd5 100644
--- a/string.c
+++ b/string.c
@@ -112,9 +112,10 @@ rb_str_new4(orig)
str->ptr = RSTRING(orig)->ptr;
RSTRING(orig)->orig = (VALUE)str;
str->orig = 0;
- if (FL_TEST(str, FL_TAINT)) {
+ if (FL_TEST(orig, FL_TAINT)) {
FL_SET(str, FL_TAINT);
}
+ FL_SET(str, STR_FREEZE);
return (VALUE)str;
}
}
@@ -756,6 +757,7 @@ rb_str_upto(beg, end, excl)
int excl;
{
VALUE current;
+ ID succ = rb_intern("succ");
if (TYPE(end) != T_STRING) end = rb_str_to_str(end);
@@ -763,7 +765,7 @@ rb_str_upto(beg, end, excl)
while (rb_str_cmp(current, end) <= 0) {
rb_yield(current);
if (!excl && rb_str_equal(current, end)) break;
- current = rb_str_succ(current);
+ current = rb_funcall(current, succ, 0, 0);
if (excl && rb_str_equal(current, end)) break;
if (RSTRING(current)->len > RSTRING(end)->len)
break;
@@ -1110,7 +1112,7 @@ rb_str_gsub_bang(argc, argv, str)
* Always consume at least one character of the input string
* in order to prevent infinite loops.
*/
- len = mbclen(RSTRING(str)->ptr[END(0)]);
+ len = mbclen2(RSTRING(str)->ptr[END(0)], pat);
if (RSTRING(str)->len > END(0)) {
memcpy(bp, RSTRING(str)->ptr+END(0), len);
bp += len;
@@ -1343,12 +1345,6 @@ rb_str_inspect(str)
*b++ = *p++;
}
}
-#if 0
- else if ((c & 0x80) && rb_kcode() != MBCTYPE_EUC) {
- CHECK(1);
- *b++ = c;
- }
-#endif
else if (c == '"'|| c == '\\') {
CHECK(2);
*b++ = '\\';
@@ -2069,6 +2065,7 @@ rb_str_split_method(argc, argv, str)
if (!NIL_P(limit) && lim <= ++i) break;
}
end++;
+ if (ismbchar(*ptr)) {ptr++; end++;}
}
}
}
@@ -2082,11 +2079,11 @@ rb_str_split_method(argc, argv, str)
regs = RMATCH(rb_backref_get())->regs;
if (start == end && BEG(0) == END(0)) {
if (last_null == 1) {
- rb_ary_push(result, rb_str_substr(str, beg, mbclen(RSTRING(str)->ptr[beg])));
+ rb_ary_push(result, rb_str_substr(str, beg, mbclen2(RSTRING(str)->ptr[beg],spat)));
beg = start;
}
else {
- start += mbclen(RSTRING(str)->ptr[start]);
+ start += mbclen2(RSTRING(str)->ptr[start],spat);
last_null = 1;
continue;
}
@@ -2396,7 +2393,7 @@ scan_once(str, pat, start)
/*
* Always consume at least one character of the input string
*/
- *start = END(0)+mbclen(RSTRING(str)->ptr[END(0)]);
+ *start = END(0)+mbclen2(RSTRING(str)->ptr[END(0)],pat);
}
else {
*start = END(0);
diff --git a/variable.c b/variable.c
index 7b273933ac..28fc2b78ba 100644
--- a/variable.c
+++ b/variable.c
@@ -195,10 +195,20 @@ VALUE
rb_path2class(path)
const char *path;
{
+ VALUE c;
+
if (path[0] == '#') {
rb_raise(rb_eArgError, "can't retrieve anonymous class %s", path);
}
- return rb_eval_string(path);
+ c = rb_eval_string(path);
+ switch (TYPE(c)) {
+ case T_MODULE:
+ case T_CLASS:
+ break;
+ default:
+ rb_raise(rb_eTypeError, "class path %s does not point class", path);
+ }
+ return c;
}
void
diff --git a/version.h b/version.h
index 0d5ed1f1eb..f5950c05af 100644
--- a/version.h
+++ b/version.h
@@ -1,4 +1,4 @@
-#define RUBY_VERSION "1.4.2"
-#define RUBY_RELEASE_DATE "1999-09-18"
-#define RUBY_VERSION_CODE 142
-#define RUBY_RELEASE_CODE 19990918
+#define RUBY_VERSION "1.4.3"
+#define RUBY_RELEASE_DATE "1999-12-07"
+#define RUBY_VERSION_CODE 143
+#define RUBY_RELEASE_CODE 19991207
diff --git a/win32/config.status b/win32/config.status
index 9b959ff4bb..ff19d709a6 100644
--- a/win32/config.status
+++ b/win32/config.status
@@ -35,7 +35,7 @@ s%@RANLIB@%rem%g
s%@AR@%lib -nologo%g
s%@LN_S@%%g
s%@SET_MAKE@%%g
-s%@LIBOBJS@% crypt.obj alloca.obj win32.obj fnmatch.obj isinf.obj isnan.obj%g
+s%@LIBOBJS@% crypt.obj alloca.obj win32.obj isinf.obj isnan.obj%g
s%@ALLOCA@%%g
s%@DEFAULT_KCODE@%%g
s%@EXEEXT@%.exe%g
diff --git a/win32/ruby.def b/win32/ruby.def
index 1c79697fd7..008452fa8d 100644
--- a/win32/ruby.def
+++ b/win32/ruby.def
@@ -31,6 +31,7 @@ EXPORTS
rb_eSystemCallError
rb_eZeroDivError
rb_mErrno
+ ruby_nerrs
;eval.c
rb_cProc
ruby_frame
diff --git a/win32/win32.c b/win32/win32.c
index a28006ce86..864fbfb5df 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -1218,12 +1218,6 @@ NtMakeCmdVector (char *cmdline, char ***vec, int InputCmd)
// UNIX compatible directory access functions for NT
//
-//
-// File names are converted to lowercase if the
-// CONVERT_TO_LOWER_CASE variable is defined.
-//
-
-#define CONVERT_TO_LOWER_CASE
#define PATHLEN 1024
//
@@ -1246,8 +1240,6 @@ opendir(char *filename)
char root[PATHLEN];
char volname[PATHLEN];
DWORD serial, maxname, flags;
- BOOL downcase;
- char *dummy;
//
// check to see if we\'ve got a directory
@@ -1259,21 +1251,6 @@ opendir(char *filename)
}
//
- // check out the file system characteristics
- //
- if (GetFullPathName(filename, PATHLEN, root, &dummy)) {
- if (dummy = strchr(root, '\\'))
- *++dummy = '\0';
- if (GetVolumeInformation(root, volname, PATHLEN,
- &serial, &maxname, &flags, 0, 0)) {
- downcase = !(flags & FS_CASE_SENSITIVE);
- }
- }
- else {
- downcase = TRUE;
- }
-
- //
// Get us a DIR structure
//
@@ -1309,8 +1286,6 @@ opendir(char *filename)
idx = strlen(FindData.cFileName)+1;
p->start = ALLOC_N(char, idx);
strcpy (p->start, FindData.cFileName);
- if (downcase)
- strlwr(p->start);
p->nfiles++;
//
@@ -1334,8 +1309,6 @@ opendir(char *filename)
rb_fatal ("opendir: malloc failed!\n");
}
strcpy(&p->start[idx], FindData.cFileName);
- if (downcase)
- strlwr(&p->start[idx]);
p->nfiles++;
idx += len+1;
}