diff options
-rw-r--r-- | ChangeLog | 97 | ||||
-rw-r--r-- | MANIFEST | 3 | ||||
-rw-r--r-- | Makefile.in | 24 | ||||
-rw-r--r-- | ToDo | 2 | ||||
-rw-r--r-- | array.c | 18 | ||||
-rw-r--r-- | assoc.c | 2 | ||||
-rw-r--r-- | bignum.c | 6 | ||||
-rw-r--r-- | class.c | 4 | ||||
-rw-r--r-- | compar.c | 2 | ||||
-rwxr-xr-x | config.guess | 497 | ||||
-rwxr-xr-x | config.sub | 833 | ||||
-rw-r--r-- | configure.in | 104 | ||||
-rw-r--r-- | defines.h | 5 | ||||
-rw-r--r-- | dir.c | 37 | ||||
-rw-r--r-- | dln.c | 22 | ||||
-rw-r--r-- | enum.c | 6 | ||||
-rw-r--r-- | env.h | 2 | ||||
-rw-r--r-- | error.c | 2 | ||||
-rw-r--r-- | eval.c | 85 | ||||
-rw-r--r-- | ext/MANIFEST | 7 | ||||
-rw-r--r-- | ext/Makefile.in | 40 | ||||
-rw-r--r-- | ext/dbm.c | 441 | ||||
-rw-r--r-- | ext/dbm.doc | 107 | ||||
-rw-r--r-- | ext/extmk.rb.in | 177 | ||||
-rw-r--r-- | ext/socket.c | 761 | ||||
-rw-r--r-- | ext/socket.doc | 227 | ||||
-rw-r--r-- | file.c | 2 | ||||
-rw-r--r-- | gc.c | 40 | ||||
-rw-r--r-- | glob.c | 11 | ||||
-rw-r--r-- | hash.c | 2 | ||||
-rw-r--r-- | ident.h | 2 | ||||
-rw-r--r-- | inits.c | 3 | ||||
-rw-r--r-- | io.c | 46 | ||||
-rw-r--r-- | io.h | 2 | ||||
-rw-r--r-- | math.c | 13 | ||||
-rw-r--r-- | node.h | 2 | ||||
-rw-r--r-- | numeric.c | 30 | ||||
-rw-r--r-- | object.c | 14 | ||||
-rw-r--r-- | pack.c | 2 | ||||
-rw-r--r-- | parse.y | 37 | ||||
-rw-r--r-- | process.c | 2 | ||||
-rw-r--r-- | random.c | 2 | ||||
-rw-r--r-- | range.c | 2 | ||||
-rw-r--r-- | re.c | 2 | ||||
-rw-r--r-- | re.h | 2 | ||||
-rw-r--r-- | regex.c | 522 | ||||
-rw-r--r-- | ruby.c | 5 | ||||
-rw-r--r-- | ruby.h | 9 | ||||
-rw-r--r-- | sample/blk.rb | 4 | ||||
-rwxr-xr-x | sample/from.rb | 140 | ||||
-rw-r--r-- | sample/list.rb | 4 | ||||
-rw-r--r-- | sample/list2.rb | 2 | ||||
-rw-r--r-- | sample/list3.rb | 2 | ||||
-rw-r--r-- | sample/ruby-mode.el | 134 | ||||
-rw-r--r-- | sample/t2.rb | 2 | ||||
-rw-r--r-- | sample/tt.rb | 2 | ||||
-rw-r--r-- | signal.c | 8 | ||||
-rw-r--r-- | spec | 65 | ||||
-rw-r--r-- | sprintf.c | 2 | ||||
-rw-r--r-- | string.c | 238 | ||||
-rw-r--r-- | time.c | 2 | ||||
-rw-r--r-- | util.c | 2 | ||||
-rw-r--r-- | util.h | 2 | ||||
-rw-r--r-- | variable.c | 80 | ||||
-rw-r--r-- | version.c | 4 | ||||
-rw-r--r-- | version.h | 4 |
66 files changed, 2585 insertions, 2375 deletions
@@ -1,3 +1,100 @@ +Fri May 19 15:33:23 1995 Yukihiro Matsumoto <matz@ix-02> + + * version 0.76 + +Fri May 19 00:48:08 1995 Yukihiro Matsumoto (matz@dyna) + + * string.c (Fstr_each): ���ƥ졼���֥��å����ʸ������ѹ����Ԥ�� + �����ɤ���������å����ݥ����ͤ��Ѥ�äƤ�����㳰��ȯ�����롥 + + * ruby-mode.el: ruby-electric-brace�ο��ߡ� + +Thu May 18 12:27:23 1995 Yukihiro Matsumoto <matz@ix-02> + + * string.c (Fstr_tr): tr���ִ��оݤ�`\0'��ޤ�����������ִ���Ԥ� + �ʤ��Х������ä��������ִ�ʸ�����ASCII��˻��ꤷ�ʤ���ư��� + ������⤢�ä�����̤Ȥ���tr��������Τǡ�copyright������� + ̵���ʤä�(�Ȼפ�)�� + + * gc.c (gc): the_scope��ޡ������Ƥ��ʤ��ä��Τǡ����������ѿ����� + ��äƳ���������礬���ä��� + + * gc.c (mark_locations_array): �㴳�ι�®���� + +Mon May 15 11:43:49 1995 Yukihiro Matsumoto <matz@ix-02> + + * ext/extmk.rb.in: Dynamic Load�⥸�塼��Υ���ѥ����ѥ����å��� + �Ԥ�ruby script��autoconf�˶ᤤ���ФǻȤ��롥�������⥸�塼��� + �������ͤ�ext�β��˥ǥ��쥯�ȥ����������ɤ���ɬ�ܤΥե� + ����ϥե�����̾�ΰ�����Ͽ����`MANIFEST'�Ȥ����ե�����Τߡ�ɬ + �פ˱�����`depend'(�ե�����ΰ�¸�ط��Ҥ���ե����� gcc -MM + �ν���)��`extconf.rb'(����ѥ����Ѥ˥饤�֥��ȴؿ���¸�ߥ����� + ������ե�����)���ѰդǤ��롥 + + * eval.c (rb_call): ruby��åɤΰ��������å�����̤������� + jmp_buf����Ѥ��Ƥ����� + + * parse.y: `or'��`and'��ͥ���̤�Ʊ���ˤ����� + +Wed May 3 18:21:36 1995 Yukihiro Matsumoto (matz@dyna) + + * dln.c: Linux�Ǥ�`__.SYMDEF/'�Ǥ��ä��� + + * dln.c: system call�Υ��顼�����å���˺��Ƥ����� + +Wed Apr 26 09:50:56 1995 Yukihiro Matsumoto (matz@ix-02) + + * parse.y: ���ƥ졼���֥��å����ѿ������`|'�dz��褦�ˤ��������� + �ǥ��ƥ졼���ѿ����ʤ�����������Τ�Τ��ά�Ǥ��롥ʸˡ���ѹ��� + �פ��֤���� + +Tue Apr 25 12:04:17 1995 Yukihiro Matsumoto (matz@ix-02) + + * eval.c(require): load��������ʥߥå������ɤε�ǽ��ܤ��Ƥ����� + ����˳�ĥ�Ҥ��䴰��ǽ���ɲä��ƥ桼����dln/dlopen�κ���ռ����� + ɬ�פΤʤ��褦�ˤ����� + + * string.c(sub,sub): ���ƥ졼���Ȥ��Ƥ�ư���褦�ˡ� + + * object.c: init_object -> initialize. + +Mon Apr 24 14:22:39 1995 Yukihiro Matsumoto (matz@ix-02) + + * NEWS-OS 3.4�б� + + * io.c: Solaris��stdio��ư��㤦�褦����signal��EOF���֤��Ƥ��� + ���ġ�perl�Ǥ�Ʊ�ͤ����꤬���롥 + +Fri Apr 21 20:04:39 1995 Yukihiro Matsumoto (matz@ix-02) + + * version 0.75 + + * signal.c: trap���ʤ��ʤäƤ����������ࡥ + + * configure: Solaris 2.3�б��� + + * io.c: #elif�Τʤ�cpp�⤢�롥 + + * dir.c: autoconf 2.x�ؤ��б����Խ�ʬ + +Thu Apr 20 12:31:24 1995 Yukihiro Matsumoto (matz@ix-02) + + * version 0.74 + + * env.h, gc.c, regex.c: IRIX�ؤΰܿ��б� + + * configure: pic����������option�θ��ФΤ��ᡤ�����ƥॿ���פ������ + ������褦�ˡ� + +Tue Apr 18 19:08:17 1995 Yukihiro Matsumoto (matz@ix-02) + + * gc.c(xrealloc): ptr=nil�λ���malloc()��Ʊ��Ư���� + + * array.c(astore): ���������0���ܤ����Ǥ����������size=0�� + realloc()��Ƥ�Ǥ����� + + * configure, glob.c: Solaris 2.x�ǥ���ѥ���Ǥ���褦�� + Mon Apr 10 18:36:06 1995 Yukihiro Matsumoto (matz@ix-02) * version 0.73 @@ -12,8 +12,9 @@ class.c compar.c configure configure.in +config.guess +config.sub defines.h -dict.c dir.c dln.c dln.h diff --git a/Makefile.in b/Makefile.in index c992baea6d..9f804f1706 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,4 +1,4 @@ -2SHELL = /bin/sh +SHELL = /bin/sh #### Start of system configuration section. #### @@ -11,6 +11,7 @@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ PURIFY= +@SET_MAKE@ CFLAGS = @CFLAGS@ STATIC = @STATIC@ @@ -74,7 +75,13 @@ $(PROGRAM): $(OBJS) @rm -f $(PROGRAM) $(PURIFY) $(CC) $(STATIC) $(LDFLAGS) $(OBJS) $(LIBS) -o $(PROGRAM) -extmake:; cd ext; make +extmake:; @echo "Compiling ext modules"; \ + for extdir in ext/*; do \ + test -d $$extdir || continue; \ + test -f $$extdir/MANIFEST || continue; \ + echo `basename $$extdir`; \ + ( cd $$extdir; ../../ruby ../extmk.rb; );\ + done $(bindir)/$(PROGRAM): $(PROGRAM) $(INSTALL_PROGRAM) $(PROGRAM) $(bindir)/$(PROGRAM) @@ -82,9 +89,18 @@ $(bindir)/$(PROGRAM): $(PROGRAM) install: $(bindir)/$(PROGRAM) clean:; @rm -f $(OBJS) + @for extdir in ext/*; do \ + test -d $$extdir || continue; \ + test -f $$extdir/MANIFEST || continue; \ + if test -f $$extdir/Makefile; then \ + ( cd $$extdir; make clean ); \ + fi; \ + done + +realclean: clean + @rm -f ext/extmk.rb + @rm -f core ruby *~ config.* Makefile -realclean:; @rm -f $(OBJS) - @rm -f core ruby *~ config.status Makefile .c.o: $(CC) $(CFLAGS) $(CPPFLAGS) -c $< @@ -3,9 +3,7 @@ * format��ǽ * here document * perl�Τ褦��setuid check -* tr����BSD�����ɤ������(�ޤ���copyright��Ϥä��ꤵ����) * Ŭ�ڤ�signal handling -* dln��COFF�б�(�ޤ���dlopen�б�) * ruby����������ѿ�hook�μ¸� * write debugger for ruby * re-write regex code for speed @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:18 $ created at: Fri Aug 6 09:46:12 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -26,7 +26,10 @@ ary_new2(len) ary->len = 0; ary->capa = len; - ary->ptr = ALLOC_N(VALUE, len); + if (len == 0) + ary->ptr = Qnil; + else + ary->ptr = ALLOC_N(VALUE, len); return (VALUE)ary; } @@ -102,8 +105,13 @@ Sary_create(argc, argv, class) ary->len = argc; ary->capa = argc; - ary->ptr = ALLOC_N(VALUE, argc); - MEMCPY(ary->ptr, argv, VALUE, argc); + if (argc == 0) { + ary->ptr = Qnil; + } + else { + ary->ptr = ALLOC_N(VALUE, argc); + MEMCPY(ary->ptr, argv, VALUE, argc); + } return (VALUE)ary; } @@ -119,7 +127,7 @@ astore(ary, idx, val) } if (idx >= ary->capa) { - ary->capa = idx + ary->capa/5; + ary->capa = idx + ARY_DEFAULT_SIZE; REALLOC_N(ary->ptr, VALUE, ary->capa); } if (idx > ary->len) { @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:30:37 $ created at: Fri Jan 6 10:10:36 JST 1995 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -13,7 +13,7 @@ #include <math.h> extern VALUE C_Integer; -static VALUE C_Bignum; +VALUE C_Bignum; #define BDIGITS(x) RBIGNUM(x)->digits #define BITSPERDIG (sizeof(USHORT)*CHAR_BIT) @@ -367,7 +367,7 @@ dbl2big(d) double u = (d < 0)?-d:d; while (0 != (long)u) { - u /= BIGRAD; + u /= (double)(BIGRAD); i++; } z = bignew(i, d>=0); @@ -591,7 +591,7 @@ bigdivmod(x, y, div, mod) zds = BDIGITS(z); if (nx==ny) zds[nx+1] = 0; while (!yds[ny-1]) ny--; - if ((dd = BIGRAD/(yds[ny-1]+1)) != 1) { + if ((dd = BIGRAD/(int)(yds[ny-1]+1)) != 1) { y = (struct RBignum*)big_clone(y); tds = BDIGITS(y); j = 0; @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:44 $ created at: Tue Aug 10 15:05:44 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -99,6 +99,7 @@ rb_define_class(name, super) id = rb_intern(name); class = rb_define_class_id(id, super); st_add_direct(rb_class_tbl, id, class); + rb_set_class_path(class, 0, name); return class; } @@ -114,6 +115,7 @@ rb_define_class_under(under, name, super) id = rb_intern(name); class = rb_define_class_id(id, super); rb_const_set(under, id, class); + rb_set_class_path(class, under, name); return class; } @@ -6,7 +6,7 @@ $Date: 1994/10/14 06:19:05 $ created at: Thu Aug 26 14:39:48 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ diff --git a/config.guess b/config.guess new file mode 100755 index 0000000000..a3d6a9f1bf --- /dev/null +++ b/config.guess @@ -0,0 +1,497 @@ +#! /bin/sh +# Attempt to guess a canonical system name. +# Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc. +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Written by Per Bothner <[email protected]>. +# The master version of this file is at the FSF in /home/gd/gnu/lib. +# +# This script attempts to guess a canonical system name similar to +# config.sub. If it succeeds, it prints the system name on stdout, and +# exits with 0. Otherwise, it exits with 1. +# +# The plan is that this can be called by configure scripts if you +# don't specify an explicit system type (host/target name). +# +# Only a few systems have been added to this list; please add others +# (but try to keep the structure clean). +# + +# This is needed to find uname on a Pyramid OSx when run in the BSD universe. +# ([email protected] 8/24/94.) +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then + PATH=$PATH:/.attbin ; export PATH +fi + +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown +UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown + +trap 'rm -f dummy.c dummy.o dummy; exit 1' 1 2 15 + +# Note: order is significant - the case branches are not exclusive. + +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in + alpha:OSF1:V*:*) + # After 1.2, OSF1 uses "V1.3" for uname -r. + echo alpha-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^V//'` + exit 0 ;; + alpha:OSF1:*:*) + # 1.2 uses "1.2" for uname -r. + echo alpha-dec-osf${UNAME_RELEASE} + exit 0 ;; + amiga:NetBSD:*:*) + echo m68k-cbm-netbsd${UNAME_RELEASE} + exit 0 ;; + arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) + echo arm-acorn-riscix${UNAME_RELEASE} + exit 0;; + Pyramid*:OSx*:*:*) + if test "`(/bin/universe) 2>/dev/null`" = att ; then + echo pyramid-pyramid-sysv3 + else + echo pyramid-pyramid-bsd + fi + exit 0 ;; + sun4*:SunOS:5.*:*) + echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:6*:*) + # According to config.sub, this is the proper way to canonicalize + # SunOS6. Hard to guess exactly what SunOS6 will be like, but + # it's likely to be more like Solaris than SunOS4. + echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` + exit 0 ;; + sun4*:SunOS:*:*) + case "`/usr/bin/arch -k`" in + Series*|S4*) + UNAME_RELEASE=`uname -v` + ;; + esac + # Japanese Language versions have a version number like `4.1.3-JL'. + echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` + exit 0 ;; + sun3*:SunOS:*:*) + echo m68k-sun-sunos${UNAME_RELEASE} + exit 0 ;; + RISC*:ULTRIX:*:*) + echo mips-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + VAX*:ULTRIX*:*:*) + echo vax-dec-ultrix${UNAME_RELEASE} + exit 0 ;; + mips:*:5*:RISCos) + echo mips-mips-riscos${UNAME_RELEASE} + exit 0 ;; + m88k:CX/UX:7*:*) + echo m88k-harris-cxux7 + exit 0 ;; + m88k:*:4*:R4*) + echo m88k-motorola-sysv4 + exit 0 ;; + m88k:*:3*:R3*) + echo m88k-motorola-sysv3 + exit 0 ;; + AViiON:dgux:*:*) + if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx \ + -o ${TARGET_BINARY_INTERFACE}x = x ] ; then + echo m88k-dg-dgux${UNAME_RELEASE} + else + echo m88k-dg-dguxbcs${UNAME_RELEASE} + fi + exit 0 ;; + M88*:DolphinOS:*:*) # DolphinOS (SVR3) + echo m88k-dolphin-sysv3 + exit 0 ;; + M88*:*:R3*:*) + # Delta 88k system running SVR3 + echo m88k-motorola-sysv3 + exit 0 ;; + XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) + echo m88k-tektronix-sysv3 + exit 0 ;; + Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) + echo m68k-tektronix-bsd + exit 0 ;; + *:IRIX*:*:*) + echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` + exit 0 ;; + ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. + echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id + exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' + i[34]86:AIX:*:*) + echo i386-ibm-aix + exit 0 ;; + *:AIX:2:3) + if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then + sed 's/^ //' << EOF >dummy.c + #include <sys/systemcfg.h> + + main() + { + if (!__power_pc()) + exit(1); + puts("powerpc-ibm-aix3.2.5"); + exit(0); + } +EOF + ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 + rm -f dummy.c dummy + echo rs6000-ibm-aix3.2.5 + elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then + echo rs6000-ibm-aix3.2.4 + else + echo rs6000-ibm-aix3.2 + fi + exit 0 ;; + *:AIX:*:4) + if /usr/sbin/lsattr -EHl proc0 | grep POWER >/dev/null 2>&1; then + IBM_ARCH=rs6000 + else + IBM_ARCH=powerpc + fi + if grep bos410 /usr/include/stdio.h >/dev/null 2>&1; then + IBM_REV=4.1 + elif grep bos411 /usr/include/stdio.h >/dev/null 2>&1; then + IBM_REV=4.1.1 + else + IBM_REV=4.${UNAME_RELEASE} + fi + echo ${IBM_ARCH}-ibm-aix${IBM_REV} + exit 0 ;; + *:AIX:*:*) + echo rs6000-ibm-aix + exit 0 ;; + ibmrt:4.4BSD:*|romp-ibm:BSD:*) + echo romp-ibm-bsd4.4 + exit 0 ;; + ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC NetBSD and + echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to + exit 0 ;; # report: romp-ibm BSD 4.3 + *:BOSX:*:*) + echo rs6000-bull-bosx + exit 0 ;; + DPX/2?00:B.O.S.:*:*) + echo m68k-bull-sysv3 + exit 0 ;; + 9000/[34]??:4.3bsd:1.*:*) + echo m68k-hp-bsd + exit 0 ;; + hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) + echo m68k-hp-bsd4.4 + exit 0 ;; + 9000/[3478]??:HP-UX:*:*) + case "${UNAME_MACHINE}" in + 9000/31? ) HP_ARCH=m68000 ;; + 9000/[34]?? ) HP_ARCH=m68k ;; + 9000/7?? | 9000/8?7 ) HP_ARCH=hppa1.1 ;; + 9000/8?? ) HP_ARCH=hppa1.0 ;; + esac + HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` + echo ${HP_ARCH}-hp-hpux${HPUX_REV} + exit 0 ;; + 3050*:HI-UX:*:*) + sed 's/^ //' << EOF >dummy.c + #include <unistd.h> + int + main () + { + long cpu = sysconf (_SC_CPU_VERSION); + /* The order matters, because CPU_IS_HP_MC68K erroneously returns + true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct + results, however. */ + if (CPU_IS_PA_RISC (cpu)) + { + switch (cpu) + { + case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; + case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; + case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; + default: puts ("hppa-hitachi-hiuxwe2"); break; + } + } + else if (CPU_IS_HP_MC68K (cpu)) + puts ("m68k-hitachi-hiuxwe2"); + else puts ("unknown-hitachi-hiuxwe2"); + exit (0); + } +EOF + ${CC-cc} dummy.c -o dummy && ./dummy && rm dummy.c dummy && exit 0 + rm -f dummy.c dummy + echo unknown-hitachi-hiuxwe2 + exit 0 ;; + 9000/7??:4.3bsd:*:* | 9000/8?7:4.3bsd:*:* ) + echo hppa1.1-hp-bsd + exit 0 ;; + 9000/8??:4.3bsd:*:*) + echo hppa1.0-hp-bsd + exit 0 ;; + hp7??:OSF1:*:* | hp8?7:OSF1:*:* ) + echo hppa1.1-hp-osf + exit 0 ;; + hp8??:OSF1:*:*) + echo hppa1.0-hp-osf + exit 0 ;; + C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) + echo c1-convex-bsd + exit 0 ;; + C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) + echo c34-convex-bsd + exit 0 ;; + C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) + echo c38-convex-bsd + exit 0 ;; + C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) + echo c4-convex-bsd + exit 0 ;; + CRAY*X-MP:UNICOS:*:*) + echo xmp-cray-unicos + exit 0 ;; + CRAY*Y-MP:UNICOS:*:*) + echo ymp-cray-unicos + exit 0 ;; + CRAY-2:UNICOS:*:*) + echo cray2-cray-unicos + exit 0 ;; + hp3[0-9][05]:NetBSD:*:*) + echo m68k-hp-netbsd${UNAME_RELEASE} + exit 0 ;; + i[34]86:BSD/386:*:* | *:BSD/OS:*:*) + echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} + exit 0 ;; + *:FreeBSD:*:*) + echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` + exit 0 ;; + *:NetBSD:*:*) + echo ${UNAME_MACHINE}-unknown-netbsd`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` + exit 0 ;; + *:GNU:*:*) + echo `echo ${UNAME_MACHINE}|sed -e 's,/.*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` + exit 0 ;; + *:Linux:*:*) + echo ${UNAME_MACHINE}-unknown-linux + exit 0 ;; +# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. earlier versions +# are messed up and put the nodename in both sysname and nodename. + i[34]86:DYNIX/ptx:4*:*) + echo i386-sequent-sysv4 + exit 0 ;; + i[34]86:*:4.*:* | i[34]86:SYSTEM_V:4.*:*) + if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then + echo ${UNAME_MACHINE}-univel-sysv${UNAME_RELEASE} + else + echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE} + fi + exit 0 ;; + i[34]86:*:3.2:*) + if test -f /usr/options/cb.name; then + UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` + echo ${UNAME_MACHINE}-unknown-isc$UNAME_REL + elif /bin/uname -X 2>/dev/null >/dev/null ; then + UNAME_REL=`(/bin/uname -X|egrep Release|sed -e 's/.*= //')` + (/bin/uname -X|egrep i80486 >/dev/null) && UNAME_MACHINE=i486 + echo ${UNAME_MACHINE}-unknown-sco$UNAME_REL + else + echo ${UNAME_MACHINE}-unknown-sysv32 + fi + exit 0 ;; + Intel:Mach:3*:*) + echo i386-unknown-mach3 + exit 0 ;; + paragon:*:*:*) + echo i860-intel-osf1 + exit 0 ;; + i860:*:4.*:*) # i860-SVR4 + if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then + echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 + else # Add other i860-SVR4 vendors below as they are discovered. + echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 + fi + exit 0 ;; + mini*:CTIX:SYS*5:*) + # "miniframe" + echo m68010-convergent-sysv + exit 0 ;; + M680[234]0:*:R3V[567]*:*) + test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; + 3[34]??:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0) + uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4.3 && exit 0 ;; + 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) + uname -p 2>/dev/null | grep 86 >/dev/null \ + && echo i486-ncr-sysv4 && exit 0 ;; + m680[234]0:LynxOS:2.2*:*) + echo m68k-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + mc68030:UNIX_System_V:4.*:*) + echo m68k-atari-sysv4 + exit 0 ;; + i[34]86:LynxOS:2.2*:*) + echo i386-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + TSUNAMI:LynxOS:2.2*:*) + echo sparc-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + rs6000:LynxOS:2.2*:*) + echo rs6000-lynx-lynxos${UNAME_RELEASE} + exit 0 ;; + RM*:SINIX-*:*:*) + echo mips-sni-sysv4 + exit 0 ;; + *:SINIX-*:*:*) + if uname -p 2>/dev/null >/dev/null ; then + UNAME_MACHINE=`(uname -p) 2>/dev/null` + echo ${UNAME_MACHINE}-sni-sysv4 + else + echo ns32k-sni-sysv + fi + exit 0 ;; +esac + +#echo '(No uname command or uname output not recognized.)' 1>&2 +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 + +cat >dummy.c <<EOF +main () +{ +#if defined (sony) +#if defined (MIPSEB) + /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, + I don't know.... */ + printf ("mips-sony-bsd\n"); exit (0); +#else +#include <sys/param.h> + printf ("m68k-sony-newsos%s\n", +#ifdef NEWSOS4 + "4" +#else + "" +#endif + ); exit (0); +#endif +#endif + +#if defined (__arm) && defined (__acorn) && defined (__unix) + printf ("arm-acorn-riscix"); exit (0); +#endif + +#if defined (hp300) && !defined (hpux) + printf ("m68k-hp-bsd\n"); exit (0); +#endif + +#if defined (NeXT) +#if !defined (__ARCHITECTURE__) +#define __ARCHITECTURE__ "m68k" +#endif + int version; + version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; + printf ("%s-next-nextstep%s\n", __ARCHITECTURE__, version==2 ? "2" : "3"); + exit (0); +#endif + +#if defined (MULTIMAX) || defined (n16) +#if defined (UMAXV) + printf ("ns32k-encore-sysv\n"); exit (0); +#else +#if defined (CMU) + printf ("ns32k-encore-mach\n"); exit (0); +#else + printf ("ns32k-encore-bsd\n"); exit (0); +#endif +#endif +#endif + +#if defined (__386BSD__) + printf ("i386-unknown-bsd\n"); exit (0); +#endif + +#if defined (sequent) +#if defined (i386) + printf ("i386-sequent-dynix\n"); exit (0); +#endif +#if defined (ns32000) + printf ("ns32k-sequent-dynix\n"); exit (0); +#endif +#endif + +#if defined (_SEQUENT_) + printf ("i386-sequent-ptx\n"); exit (0); +#endif + +#if defined (vax) +#if !defined (ultrix) + printf ("vax-dec-bsd\n"); exit (0); +#else + printf ("vax-dec-ultrix\n"); exit (0); +#endif +#endif + +#if defined (alliant) && defined (i860) + printf ("i860-alliant-bsd\n"); exit (0); +#endif + + exit (1); +} +EOF + +${CC-cc} dummy.c -o dummy 2>/dev/null && ./dummy && rm dummy.c dummy && exit 0 +rm -f dummy.c dummy + +# Apollos put the system type in the environment. + +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } + +# Convex versions that predate uname can use getsysinfo(1) + +if [ -x /usr/convex/getsysinfo ] +then + case `getsysinfo -f cpu_type` in + c1*) + echo c1-convex-bsd + exit 0 ;; + c2*) + if getsysinfo -f scalar_acc + then echo c32-convex-bsd + else echo c2-convex-bsd + fi + exit 0 ;; + c34*) + echo c34-convex-bsd + exit 0 ;; + c38*) + echo c38-convex-bsd + exit 0 ;; + c4*) + echo c4-convex-bsd + exit 0 ;; + esac +fi + +#echo '(Unable to guess system type)' 1>&2 + +exit 1 diff --git a/config.sub b/config.sub new file mode 100755 index 0000000000..5641cc1ce6 --- /dev/null +++ b/config.sub @@ -0,0 +1,833 @@ +#! /bin/sh +# Configuration validation subroutine script, version 1.1. +# Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. +# This file is (in principle) common to ALL GNU software. +# The presence of a machine in this file suggests that SOME GNU software +# can handle that machine. It does not imply ALL GNU software can. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Configuration subroutine to validate and canonicalize a configuration type. +# Supply the specified configuration type as an argument. +# If it is invalid, we print an error message on stderr and exit with code 1. +# Otherwise, we print the canonical config type on stdout and succeed. + +# This file is supposed to be the same for all GNU packages +# and recognize all the CPU types, system types and aliases +# that are meaningful with *any* GNU software. +# Each package is responsible for reporting which valid configurations +# it does not support. The user should be able to distinguish +# a failure to support a valid configuration from a meaningless +# configuration. + +# The goal of this file is to map all the various variations of a given +# machine specification into a single specification in the form: +# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM +# It is wrong to echo any other type of specification. + +if [ x$1 = x ] +then + echo Configuration name missing. 1>&2 + echo "Usage: $0 CPU-MFR-OPSYS" 1>&2 + echo "or $0 ALIAS" 1>&2 + echo where ALIAS is a recognized configuration type. 1>&2 + exit 1 +fi + +# First pass through any local machine types. +case $1 in + *local*) + echo $1 + exit 0 + ;; + *) + ;; +esac + +# Separate what the user gave into CPU-COMPANY and OS (if any). +basic_machine=`echo $1 | sed 's/-[^-]*$//'` +if [ $basic_machine != $1 ] +then os=`echo $1 | sed 's/.*-/-/'` +else os=; fi + +### Let's recognize common machines as not being operating systems so +### that things like config.sub decstation-3100 work. We also +### recognize some manufacturers as not being operating systems, so we +### can provide default operating systems below. +case $os in + -sun*os*) + # Prevent following clause from handling this invalid input. + ;; + -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ + -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ + -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ + -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ + -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ + -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp ) + os= + basic_machine=$1 + ;; + -hiux*) + os=-hiuxwe2 + ;; + -sco4) + os=-sco3.2v4 + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -sco3.2.[4-9]*) + os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -sco3.2v[4-9]*) + # Don't forget version if it is 3.2v4 or newer. + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -sco*) + os=-sco3.2v2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -isc) + os=-isc2.2 + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -clix*) + basic_machine=clipper-intergraph + ;; + -isc*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-unknown/'` + ;; + -lynx*) + os=-lynxos + ;; + -ptx*) + basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` + ;; + -windowsnt*) + os=`echo $os | sed -e 's/windowsnt/winnt/'` + ;; +esac + +# Decode aliases for certain CPU-COMPANY combinations. +case $basic_machine in + # Recognize the basic CPU types without company name. + # Some are omitted here because they have special meanings below. + tahoe | i[345]86 | i860 | m68k | m68000 | m88k | ns32k | arm | pyramid \ + | tron | a29k | 580 | i960 | h8300 | hppa1.0 | hppa1.1 \ + | alpha | we32k | ns16k | clipper | sparclite | i370 | sh \ + | powerpc | sparc64 | 1750a | dsp16xx | mips64 | mipsel \ + | pdp11 | mips64el | mips64orion | mips64orionel \ + | sparc) + basic_machine=$basic_machine-unknown + ;; + # Object if more than one company name word. + *-*-*) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; + # Recognize the basic CPU types with company name. + vax-* | tahoe-* | i[345]86-* | i860-* | m68k-* | m68000-* | m88k-* \ + | sparc-* | ns32k-* | fx80-* | arm-* | c[123]* \ + | mips-* | pyramid-* | tron-* | a29k-* | romp-* | rs6000-* \ + | none-* | 580-* | cray2-* | h8300-* | i960-* | xmp-* | ymp-* \ + | hppa1.0-* | hppa1.1-* | alpha-* | we32k-* | cydra-* | ns16k-* \ + | pn-* | np1-* | xps100-* | clipper-* | orion-* | sparclite-* \ + | pdp11-* | sh-* | powerpc-* | sparc64-* | mips64-* | mipsel-* \ + | mips64el-* | mips64orion-* | mips64orionel-*) + ;; + # Recognize the various machine names and aliases which stand + # for a CPU type and a company and sometimes even an OS. + 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) + basic_machine=m68000-att + ;; + 3b*) + basic_machine=we32k-att + ;; + alliant | fx80) + basic_machine=fx80-alliant + ;; + altos | altos3068) + basic_machine=m68k-altos + ;; + am29k) + basic_machine=a29k-none + os=-bsd + ;; + amdahl) + basic_machine=580-amdahl + os=-sysv + ;; + amiga | amiga-*) + basic_machine=m68k-cbm + ;; + amigados) + basic_machine=m68k-cbm + os=-amigados + ;; + amigaunix | amix) + basic_machine=m68k-cbm + os=-sysv4 + ;; + apollo68) + basic_machine=m68k-apollo + os=-sysv + ;; + balance) + basic_machine=ns32k-sequent + os=-dynix + ;; + convex-c1) + basic_machine=c1-convex + os=-bsd + ;; + convex-c2) + basic_machine=c2-convex + os=-bsd + ;; + convex-c32) + basic_machine=c32-convex + os=-bsd + ;; + convex-c34) + basic_machine=c34-convex + os=-bsd + ;; + convex-c38) + basic_machine=c38-convex + os=-bsd + ;; + cray | ymp) + basic_machine=ymp-cray + os=-unicos + ;; + cray2) + basic_machine=cray2-cray + os=-unicos + ;; + crds | unos) + basic_machine=m68k-crds + ;; + da30 | da30-*) + basic_machine=m68k-da30 + ;; + decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) + basic_machine=mips-dec + ;; + delta | 3300 | motorola-3300 | motorola-delta \ + | 3300-motorola | delta-motorola) + basic_machine=m68k-motorola + ;; + delta88) + basic_machine=m88k-motorola + os=-sysv3 + ;; + dpx20 | dpx20-*) + basic_machine=rs6000-bull + os=-bosx + ;; + dpx2* | dpx2*-bull) + basic_machine=m68k-bull + os=-sysv3 + ;; + ebmon29k) + basic_machine=a29k-amd + os=-ebmon + ;; + elxsi) + basic_machine=elxsi-elxsi + os=-bsd + ;; + encore | umax | mmax) + basic_machine=ns32k-encore + ;; + fx2800) + basic_machine=i860-alliant + ;; + genix) + basic_machine=ns32k-ns + ;; + gmicro) + basic_machine=tron-gmicro + os=-sysv + ;; + h3050r* | hiux*) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + h8300hms) + basic_machine=h8300-hitachi + os=-hms + ;; + harris) + basic_machine=m88k-harris + os=-sysv3 + ;; + hp300-*) + basic_machine=m68k-hp + ;; + hp300bsd) + basic_machine=m68k-hp + os=-bsd + ;; + hp300hpux) + basic_machine=m68k-hp + os=-hpux + ;; + hp9k2[0-9][0-9] | hp9k31[0-9]) + basic_machine=m68000-hp + ;; + hp9k3[2-9][0-9]) + basic_machine=m68k-hp + ;; + hp9k7[0-9][0-9] | hp7[0-9][0-9] | hp9k8[0-9]7 | hp8[0-9]7) + basic_machine=hppa1.1-hp + ;; + hp9k8[0-9][0-9] | hp8[0-9][0-9]) + basic_machine=hppa1.0-hp + ;; + i370-ibm* | ibm*) + basic_machine=i370-ibm + os=-mvs + ;; +# I'm not sure what "Sysv32" means. Should this be sysv3.2? + i[345]86v32) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-sysv32 + ;; + i[345]86v4*) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-sysv4 + ;; + i[345]86v) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-sysv + ;; + i[345]86sol2) + basic_machine=`echo $1 | sed -e 's/86.*/86-unknown/'` + os=-solaris2 + ;; + iris | iris4d) + basic_machine=mips-sgi + case $os in + -irix*) + ;; + *) + os=-irix4 + ;; + esac + ;; + isi68 | isi) + basic_machine=m68k-isi + os=-sysv + ;; + m88k-omron*) + basic_machine=m88k-omron + ;; + magnum | m3230) + basic_machine=mips-mips + os=-sysv + ;; + merlin) + basic_machine=ns32k-utek + os=-sysv + ;; + miniframe) + basic_machine=m68000-convergent + ;; + mips3*-*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` + ;; + mips3*) + basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown + ;; + ncr3000) + basic_machine=i486-ncr + os=-sysv4 + ;; + news | news700 | news800 | news900) + basic_machine=m68k-sony + os=-newsos + ;; + news1000) + basic_machine=m68030-sony + os=-newsos + ;; + news-3600 | risc-news) + basic_machine=mips-sony + os=-newsos + ;; + next | m*-next ) + basic_machine=m68k-next + case $os in + -nextstep* ) + ;; + -ns2*) + os=-nextstep2 + ;; + *) + os=-nextstep3 + ;; + esac + ;; + nh3000) + basic_machine=m68k-harris + os=-cxux + ;; + nh[45]000) + basic_machine=m88k-harris + os=-cxux + ;; + nindy960) + basic_machine=i960-intel + os=-nindy + ;; + np1) + basic_machine=np1-gould + ;; + pa-hitachi) + basic_machine=hppa1.1-hitachi + os=-hiuxwe2 + ;; + paragon) + basic_machine=i860-intel + os=-osf + ;; + pbd) + basic_machine=sparc-tti + ;; + pbb) + basic_machine=m68k-tti + ;; + pc532 | pc532-*) + basic_machine=ns32k-pc532 + ;; + pentium-*) + # We will change tis to say i586 once there has been + # time for various packages to start to recognize that. + basic_machine=i486-`echo $basic_machine | sed 's/^[^-]*-//'` + ;; + pn) + basic_machine=pn-gould + ;; + ps2) + basic_machine=i386-ibm + ;; + rm[46]00) + basic_machine=mips-siemens + ;; + rtpc | rtpc-*) + basic_machine=romp-ibm + ;; + sequent) + basic_machine=i386-sequent + ;; + sh) + basic_machine=sh-hitachi + os=-hms + ;; + sps7) + basic_machine=m68k-bull + os=-sysv2 + ;; + spur) + basic_machine=spur-unknown + ;; + sun2) + basic_machine=m68000-sun + ;; + sun2os3) + basic_machine=m68000-sun + os=-sunos3 + ;; + sun2os4) + basic_machine=m68000-sun + os=-sunos4 + ;; + sun3os3) + basic_machine=m68k-sun + os=-sunos3 + ;; + sun3os4) + basic_machine=m68k-sun + os=-sunos4 + ;; + sun4os3) + basic_machine=sparc-sun + os=-sunos3 + ;; + sun4os4) + basic_machine=sparc-sun + os=-sunos4 + ;; + sun4sol2) + basic_machine=sparc-sun + os=-solaris2 + ;; + sun3 | sun3-*) + basic_machine=m68k-sun + ;; + sun4) + basic_machine=sparc-sun + ;; + sun386 | sun386i | roadrunner) + basic_machine=i386-sun + ;; + symmetry) + basic_machine=i386-sequent + os=-dynix + ;; + tower | tower-32) + basic_machine=m68k-ncr + ;; + udi29k) + basic_machine=a29k-amd + os=-udi + ;; + ultra3) + basic_machine=a29k-nyu + os=-sym1 + ;; + vaxv) + basic_machine=vax-dec + os=-sysv + ;; + vms) + basic_machine=vax-dec + os=-vms + ;; + vxworks960) + basic_machine=i960-wrs + os=-vxworks + ;; + vxworks68) + basic_machine=m68k-wrs + os=-vxworks + ;; + xmp) + basic_machine=xmp-cray + os=-unicos + ;; + xps | xps100) + basic_machine=xps100-honeywell + ;; + none) + basic_machine=none-none + os=-none + ;; + +# Here we handle the default manufacturer of certain CPU types. It is in +# some cases the only manufacturer, in others, it is the most popular. + mips) + basic_machine=mips-mips + ;; + romp) + basic_machine=romp-ibm + ;; + rs6000) + basic_machine=rs6000-ibm + ;; + vax) + basic_machine=vax-dec + ;; + pdp11) + basic_machine=pdp11-dec + ;; + we32k) + basic_machine=we32k-att + ;; + sparc) + basic_machine=sparc-sun + ;; + cydra) + basic_machine=cydra-cydrome + ;; + orion) + basic_machine=orion-highlevel + ;; + orion105) + basic_machine=clipper-highlevel + ;; + *) + echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 + exit 1 + ;; +esac + +# Here we canonicalize certain aliases for manufacturers. +case $basic_machine in + *-digital*) + basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` + ;; + *-commodore*) + basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` + ;; + *) + ;; +esac + +# Decode manufacturer-specific aliases for certain operating systems. + +if [ x"$os" != x"" ] +then +case $os in + # -solaris* is a basic system type, with this one exception. + -solaris1 | -solaris1.*) + os=`echo $os | sed -e 's|solaris1|sunos4|'` + ;; + -solaris) + os=-solaris2 + ;; + -unixware* | svr4*) + os=-sysv4 + ;; + -gnu/linux*) + os=`echo $os | sed -e 's|gnu/linux|linux|'` + ;; + # First accept the basic system types. + # The portable systems comes first. + # Each alternative must end in a *, to match a version number. + # -sysv* is not here because it comes later, after sysvr4. + -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ + | -vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[345]* \ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigados* | -msdos* | -newsos* | -unicos* | -aos* \ + | -nindy* | -vxworks* | -ebmon* | -hms* | -mvs* | -clix* \ + | -riscos* | -linux* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -netbsd* | -freebsd* | -riscix* \ + | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* \ + | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta | -udi | -eabi) + ;; + -sunos5*) + os=`echo $os | sed -e 's|sunos5|solaris2|'` + ;; + -sunos6*) + os=`echo $os | sed -e 's|sunos6|solaris3|'` + ;; + -osfrose*) + os=-osfrose + ;; + -osf*) + os=-osf + ;; + -utek*) + os=-bsd + ;; + -dynix*) + os=-bsd + ;; + -acis*) + os=-aos + ;; + -ctix* | -uts*) + os=-sysv + ;; + # Preserve the version number of sinix5. + -sinix5.*) + os=`echo $os | sed -e 's|sinix|sysv|'` + ;; + -sinix*) + os=-sysv4 + ;; + -triton*) + os=-sysv3 + ;; + -oss*) + os=-sysv3 + ;; + -svr4) + os=-sysv4 + ;; + -svr3) + os=-sysv3 + ;; + -sysvr4) + os=-sysv4 + ;; + # This must come after -sysvr4. + -sysv*) + ;; + -xenix) + os=-xenix + ;; + -none) + ;; + *) + # Get rid of the `-' at the beginning of $os. + os=`echo $os | sed 's/[^-]*-//'` + echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 + exit 1 + ;; +esac +else + +# Here we handle the default operating systems that come with various machines. +# The value should be what the vendor currently ships out the door with their +# machine or put another way, the most popular os provided with the machine. + +# Note that if you're going to try to match "-MANUFACTURER" here (say, +# "-sun"), then you have to tell the case statement up towards the top +# that MANUFACTURER isn't an operating system. Otherwise, code above +# will signal an error saying that MANUFACTURER isn't an operating +# system, and we'll never get to this point. + +case $basic_machine in + *-acorn) + os=-riscix1.2 + ;; + pdp11-*) + os=-none + ;; + *-dec | vax-*) + os=-ultrix4.2 + ;; + m68*-apollo) + os=-domain + ;; + i386-sun) + os=-sunos4.0.2 + ;; + m68000-sun) + os=-sunos3 + # This also exists in the configure program, but was not the + # default. + # os=-sunos4 + ;; + *-tti) # must be before sparc entry or we get the wrong os. + os=-sysv3 + ;; + sparc-* | *-sun) + os=-sunos4.1.1 + ;; + *-ibm) + os=-aix + ;; + *-hp) + os=-hpux + ;; + *-hitachi) + os=-hiux + ;; + i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) + os=-sysv + ;; + *-cbm) + os=-amigados + ;; + *-dg) + os=-dgux + ;; + *-dolphin) + os=-sysv3 + ;; + m68k-ccur) + os=-rtu + ;; + m88k-omron*) + os=-luna + ;; + *-sequent) + os=-ptx + ;; + *-crds) + os=-unos + ;; + *-ns) + os=-genix + ;; + i370-*) + os=-mvs + ;; + *-next) + os=-nextstep3 + ;; + *-gould) + os=-sysv + ;; + *-highlevel) + os=-bsd + ;; + *-encore) + os=-bsd + ;; + *-sgi) + os=-irix + ;; + *-siemens) + os=-sysv4 + ;; + *-masscomp) + os=-rtu + ;; + *) + os=-none + ;; +esac +fi + +# Here we handle the case where we know the os, and the CPU type, but not the +# manufacturer. We pick the logical manufacturer. +vendor=unknown +case $basic_machine in + *-unknown) + case $os in + -riscix*) + vendor=acorn + ;; + -sunos*) + vendor=sun + ;; + -lynxos*) + vendor=lynx + ;; + -aix*) + vendor=ibm + ;; + -hpux*) + vendor=hp + ;; + -hiux*) + vendor=hitachi + ;; + -unos*) + vendor=crds + ;; + -dgux*) + vendor=dg + ;; + -luna*) + vendor=omron + ;; + -genix*) + vendor=ns + ;; + -mvs*) + vendor=ibm + ;; + -ptx*) + vendor=sequent + ;; + -vxworks*) + vendor=wrs + ;; + esac + basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` + ;; +esac + +echo $basic_machine$os diff --git a/configure.in b/configure.in index 13468317ba..77153b6ed0 100644 --- a/configure.in +++ b/configure.in @@ -1,38 +1,52 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(ruby.h) + PROGS="ruby" AC_SUBST(PROGS)dnl + +dnl Checks for programs. AC_PROG_CC AC_PROG_GCC_TRADITIONAL AC_PROG_YACC AC_PROG_INSTALL -AC_CHECK_HEADERS(unistd.h stdlib.h syscall.h a.out.h dirent.h\ - string.h utime.h) +AC_PROG_MAKE_SET + +dnl Checks for libraries. +AC_CHECK_LIB(m, pow) +AC_CHECK_LIB(crypt, crypt) +AC_CHECK_LIB(dl, dlopen, [:]) + +dnl Checks for header files. AC_HEADER_DIRENT +AC_HEADER_STDC +AC_CHECK_HEADERS(fcntl.h limits.h sys/file.h sys/ioctl.h sys/time.h unistd.h\ + stdlib.h syscall.h a.out.h string.h utime.h) + +dnl Checks for typedefs, structures, and compiler characteristics. +AC_TYPE_UID_T +AC_TYPE_SIZE_T +AC_STRUCT_ST_BLKSIZE +AC_STRUCT_ST_BLOCKS +AC_STRUCT_ST_RDEV + +dnl Checks for library functions. AC_TYPE_GETGROUPS AC_TYPE_SIGNAL -AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"]) -AC_CHECK_LIB(dbm, dbm_open, AC_DEFINE(HAVE_LIBDBM)) -AC_CHECK_LIB(socket, socket, AC_DEFINE(HAVE_LIBSOKCET)) -AC_CHECK_LIB(crypt, crypt, [LIBS="$LIBS -lcrypt"]) +AC_FUNC_ALLOCA AC_FUNC_VFORK AC_REPLACE_FUNCS(memmove mkdir strerror strftime\ strstr strtoul strdup) -AC_CHECK_FUNCS(fmod killpg socket random wait4 waitpid syscall getcwd\ +AC_CHECK_FUNCS(fmod killpg random wait4 waitpid syscall getcwd\ setruid seteuid setreuid setrgid setegid setregid\ getpriority sigprocmask dlopen utimes) AC_CHECK_FUNC(setenv, [], AC_CHECK_FUNCS(putenv)) -if test $ac_cv_func strftime = no; then +if test "$ac_cv_func strftime" = no; then AC_STRUCT_TIMEZONE AC_TRY_LINK([], [extern int daylight; int i = daylight;], AC_DEFINE(HAVE_DAYLIGHT)) fi -AC_FUNC_ALLOCA AC_C_BIGENDIAN -AC_STRUCT_ST_BLKSIZE -AC_STRUCT_ST_BLOCKS -AC_STRUCT_ST_RDEV AC_MSG_CHECKING(std stdio) AC_CACHE_VAL(rb_cv_stdstdio, [AC_TRY_COMPILE([#include <stdio.h>], @@ -40,7 +54,7 @@ AC_CACHE_VAL(rb_cv_stdstdio, rb_cv_stdstdio=yes, rb_cv_stdstdio=no)]) AC_MSG_RESULT($rb_cv_stdstdio) -if test $rb_cv_stdstdio = yes; then +if test "$rb_cv_stdstdio" = yes; then AC_DEFINE(STDSTDIO) fi AC_MSG_CHECKING(struct passwd) @@ -51,9 +65,10 @@ AC_EGREP_HEADER(pw_class, pwd.h, AC_DEFINE(PW_CLASS)) AC_EGREP_HEADER(pw_comment, pwd.h, AC_DEFINE(PW_COMMENT)) AC_EGREP_HEADER(pw_expire, pwd.h, AC_DEFINE(PW_EXPIRE)) AC_MSG_RESULT(done) -AC_MSG_CHECKING(whether matz's dln works) -cp confdefs.h config.h -if test $ac_cv_header_a_out_h = yes; then + +if test "$ac_cv_header_a_out_h" = yes; then + AC_MSG_CHECKING(whether matz's dln works) + cp confdefs.h config.h AC_CACHE_VAL(rb_cv_mydln, [AC_TRY_COMPILE([ #define USE_MY_DLN @@ -63,41 +78,58 @@ if test $ac_cv_header_a_out_h = yes; then rb_cv_mydln=yes, rb_cv_mydln=no)]) AC_MSG_RESULT($rb_cv_mydln) - if test $rb_cv_mydln = yes; then + if test "$rb_cv_mydln" = yes; then AC_DEFINE(USE_MY_DLN) fi fi AC_SUBST(STATIC)dnl AC_SUBST(CCDLFLAGS)dnl -AC_SUBST(EXT)dnl +AC_SUBST(LDDLFLAGS)dnl +AC_SUBST(DLEXT)dnl AC_SUBST(EXTMAKE)dnl EXTMAKE= STATIC= -if test $ac_cv_func_dlopen = yes -o $rb_cv_mydln = yes; then +if test "$rb_cv_mydln" = yes; then EXTMAKE=extmake - if test "$rb_cv_mydln" = yes; then - if test "$HOSTTYPE" = sparc; then - if test $ac_cv_prog_CC = gcc; then - STATIC=-static - else - STATIC=-Bstatic - fi - fi - EXT=o - CCDLFLAGS= - LDCMD= - else - EXT=so - if test $ac_cv_prog_CC = gcc; then - CCDLFLAGS=-fpic + if test "$HOSTTYPE" = sparc; then + if test "$ac_cv_prog_CC" = gcc; then + STATIC=-static else - CCDLFLAGS=-pic + STATIC=-Bstatic fi fi + DLEXT=o + AC_DEFINE(DLEXT, ".o") + CCDLFLAGS= + LDCMD= +elif test "$ac_cv_lib_dl" = yes || test "$ac_cv_func_dlopen" = yes; then + AC_CANONICAL_HOST + echo "please mail this value to matz -- $host_os" + EXTMAKE=extmake + DLEXT=so + AC_DEFINE(DLEXT, ".so") + if test "$ac_cv_prog_CC" = gcc; then + CCDLFLAGS=-fpic + else + case "$host_os" in + hpux*) CCDLFLAGS='+z' ;; + solaris*|irix*) CCDLFLAGS='-K pic' ;; + sunos*) CCDLFLAGS='-pic' ;; + svr4*|esix*) CCDLFLAGS='-Kpic' ;; + *) CCDLFLAGS='' ;; + esac + fi + case "$host_os" in + hpux*) LDDLFLAGS='-b' ;; + solaris*) LDDLFLAGS='-G' ;; + sunos*) LDDLFLAGS='-assert nodefinitions' ;; + svr4*|esix*) LDDLFLAGS="-G $LDFLAGS" ;; + *) LDDLFLAGS="" ;; + esac fi cp confdefs.h config.h -AC_OUTPUT(Makefile ext/Makefile) +AC_OUTPUT(Makefile ext/extmk.rb) @@ -21,7 +21,7 @@ #define USE_DL /* a.out.h or dlopen() needed to load object */ -#if !defined(HAVE_DLOPEN) || !defined(HAVE_A_OUT_H) +#if !defined(HAVE_DLOPEN) && !defined(HAVE_A_OUT_H) # undef USE_DL #endif @@ -30,9 +30,6 @@ # define DLN_DEFAULT_PATH "/lib:/usr/lib:." #endif -/* define USE_DBM to use dbm class. */ -#define USE_DBM - #define SAFE_SIGHANDLE #endif @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:28 $ created at: Wed Jan 5 09:51:01 JST 1994 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -24,23 +24,22 @@ char *getenv(); #endif -/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */ -#if defined(DIRENT) || defined(_POSIX_VERSION) -#include <dirent.h> -#define NLENGTH(dirent) (strlen((dirent)->d_name)) -#else /* not (DIRENT or _POSIX_VERSION) */ -#define dirent direct -#define NLENGTH(dirent) ((dirent)->d_namlen) -#ifdef SYSNDIR -#include <sys/ndir.h> -#endif /* SYSNDIR */ -#ifdef SYSDIR -#include <sys/dir.h> -#endif /* SYSDIR */ -#ifdef NDIR -#include <ndir.h> -#endif /* NDIR */ -#endif /* not (DIRENT or _POSIX_VERSION) */ +#if HAVE_DIRENT_H +# include <dirent.h> +# define NAMLEN(dirent) strlen((dirent)->d_name) +#else +# define dirent direct +# define NAMLEN(dirent) (dirent)->d_namlen +# if HAVE_SYS_NDIR_H +# include <sys/ndir.h> +# endif +# if HAVE_SYS_DIR_H +# include <sys/dir.h> +# endif +# if HAVE_NDIR_H +# include <ndir.h> +# endif +#endif static VALUE C_Dir; static ID id_dir; @@ -97,7 +96,7 @@ Fdir_each(dir) GetDIR(dir, dirp); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { - rb_lastline = str_new(dp->d_name, NLENGTH(dp)); + rb_lastline = str_new(dp->d_name, NAMLEN(dp)); rb_yield(rb_lastline); } return dir; @@ -6,7 +6,7 @@ $Date: 1994/12/09 01:28:23 $ created at: Tue Jan 18 17:05:06 JST 1994 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -101,9 +101,9 @@ dln_load(file) /* Load the file as an object one */ init_funcname(buf, file); - if ((init_fct = dlsym(handle, buf)) == NULL) { + if ((init_fct = (void(*)())dlsym(handle, buf)) == NULL) { buf[0] = 'I'; /* try Init_.. */ - if ((init_fct = dlsym(handle, buf)) == NULL) { + if ((init_fct = (void(*)())dlsym(handle, buf)) == NULL) { return -1; } } @@ -416,12 +416,18 @@ undef_print(key, value) return ST_CONTINUE; } +static void +dln_print_undef() +{ + fprintf(stderr, " Undefined symbols:\n"); + st_foreach(undef_tbl, undef_print, NULL); +} + static dln_undefined() { fprintf(stderr, "dln: Calling undefined function\n"); - fprintf(stderr, " Undefined symbols:\n"); - st_foreach(undef_tbl, undef_print, NULL); + dln_print_undef(); #ifdef RUBY rb_exit(1); #else @@ -794,7 +800,7 @@ dln_load_1(fd, disp, need_init) err_exit: if (syms) free(syms); if (reloc) free(reloc); - if (block) free(block); + if (block) free((char*)block); return -1; } @@ -888,7 +894,7 @@ dln_load_lib(lib) fd = open(file, O_RDONLY); if (fd == -1) goto syserr; size = read(fd, armagic, SARMAG); - if (fd == -1) goto syserr; + if (size == -1) goto syserr; if (size != SARMAG) { dln_errno = DLN_ENOTLIB; @@ -900,7 +906,7 @@ dln_load_lib(lib) goto badlib; } - if (strncmp(ahdr.ar_name, "__.SYMDEF", 9) == 0 && ahdr.ar_name[9] == ' ') { + if (strncmp(ahdr.ar_name, "__.SYMDEF", 9) == 0) { /* make hash table from __.SYMDEF */ lib_tbl = st_init_table(strcmp, st_strhash); @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:29 $ created at: Fri Oct 1 15:15:19 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -34,7 +34,7 @@ enum_grep(i, arg) } static void -enum_grep2(i, pat) +enum_grep_iter(i, pat) VALUE i, pat; { if (!id_match) id_match = rb_intern("=~"); @@ -48,7 +48,7 @@ Fenum_grep(obj, pat) VALUE obj; { if (iterator_p()) { - rb_iterate(rb_each, obj, enum_grep2, pat); + rb_iterate(rb_each, obj, enum_grep_iter, pat); return obj; } else { @@ -19,7 +19,7 @@ extern struct ENVIRON { struct ENVIRON *prev; } *the_env; -struct SCOPE { +extern struct SCOPE { struct RBasic super; ID *local_tbl; VALUE *local_vars; @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:31 $ created at: Mon Aug 9 16:11:34 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:45 $ created at: Thu Jun 10 14:22:17 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -454,7 +454,7 @@ ruby_init(argc, argv, envp) if ((state = EXEC_TAG()) == 0) { rb_call_inits(); the_class = (struct RClass*)C_Object; - ruby_init0(argc, argv, envp); + ruby_options(argc, argv, envp); } POP_ITER(); POP_TAG(); @@ -632,7 +632,7 @@ rb_trap_eval(cmd) } } -#define SETUP_ARGS {\ +#define SETUP_ARGS do {\ NODE *n = node->nd_args;\ if (!n) {\ argc = 0;\ @@ -658,7 +658,7 @@ rb_trap_eval(cmd) argv = ALLOCA_N(VALUE, argc);\ MEMCPY(argv, RARRAY(args)->ptr, VALUE, argc);\ }\ -} +} while (0) static VALUE rb_eval(node) @@ -1289,6 +1289,7 @@ rb_eval(node) if (super == Qnil) super = C_Object; class = rb_define_class_id(node->nd_cname, super); rb_const_set(the_class, node->nd_cname, class); + rb_set_class_path(class,the_class,rb_id2name(node->nd_cname)); } module_setup(class, node->nd_body); @@ -1308,6 +1309,7 @@ rb_eval(node) else { module = rb_define_module_id(node->nd_cname); rb_const_set(the_class, node->nd_cname, module); + rb_set_class_path(module,the_class,rb_id2name(node->nd_cname)); } module_setup(module, node->nd_body); @@ -1992,7 +1994,6 @@ rb_call(class, recv, mid, argc, argv, scope) sourcefile = body->file; PUSH_SCOPE(); - PUSH_TAG(); if (body->nd_cnt > 0) { local_vars = ALLOCA_N(VALUE, body->nd_cnt); @@ -2032,6 +2033,7 @@ rb_call(class, recv, mid, argc, argv, scope) } } } + PUSH_TAG(); state = EXEC_TAG(); if (state == 0) { result = rb_eval(body); @@ -2200,7 +2202,7 @@ find_file(file) { extern VALUE rb_load_path; VALUE sep, vpath; - char *path, *found; + char *path; if (file[0] == '/') return file; @@ -2215,10 +2217,7 @@ find_file(file) path = Qnil; } - found = dln_find_file(file, path); - if (found == Qnil) Fail("No such file to load -- %s", file); - - return found; + return dln_find_file(file, path); } VALUE @@ -2232,28 +2231,8 @@ Fload(obj, fname) Check_Type(fname, T_STRING); file = find_file(fname->ptr); + if (!file) Fail("No such file to load -- %s", file); -#ifdef USE_DL - { - static int rb_dln_init = 0; - extern char *rb_dln_argv0; - int len = strlen(file); - - if (len > 3 - && file[len-1] == 'o' && file[len-2] == '.' - || len > 4 - && file[len-1] == 'o' && file[len-2] == 's' && file[len-3] == '.'){ - if (rb_dln_init == 0 && dln_init(rb_dln_argv0) == -1) { - Fail("%s: %s", rb_dln_argv0, dln_strerror()); - } - - if (dln_load(file) == -1) - Fail(dln_strerror()); - - return TRUE; - } - } -#endif PUSH_SELF(TopSelf); PUSH_TAG(); PUSH_CLASS(); @@ -2291,6 +2270,18 @@ Frequire(obj, fname) Check_Type(fname, T_STRING); file = find_file(fname->ptr); + if (!file) { + char *buf = ALLOCA_N(char, strlen(fname->ptr) + 4); + sprintf(buf, "%s.rb", fname->ptr); + file = find_file(buf); +#ifdef USE_DL + if (!file) { + sprintf(buf, "%s%s", fname->ptr, DLEXT); + file = find_file(buf); + } +#endif + if (!file) Fail("No such file to load -- %s", file); + } p = RARRAY(rb_loadfiles)->ptr; pend = p + RARRAY(rb_loadfiles)->len; @@ -2298,10 +2289,36 @@ Frequire(obj, fname) Check_Type(*p, T_STRING); if (strcmp(RSTRING(*p)->ptr, file) == 0) return FALSE; } - ary_push(rb_loadfiles, str_new2(file)); + fname = (struct RString*)str_new2(file); + ary_push(rb_loadfiles, fname); + file = fname->ptr; - Fload(obj, fname); - return TRUE; +#ifdef USE_DL + { + int len = strlen(file), extsiz = sizeof(DLEXT); + + if (len > extsiz) { + int i; + for (i=1;i<extsiz;i++) { + if (file[len-i] != DLEXT[extsiz-i-1]) break; + } + if (i==extsiz) { + static int rb_dln_init = 0; + extern char *rb_dln_argv0; + + if (rb_dln_init == 0 && dln_init(rb_dln_argv0) == -1) { + Fail("%s: %s", rb_dln_argv0, dln_strerror()); + } + + if (dln_load(file) == -1) + Fail(dln_strerror()); + + return TRUE; + } + } + } +#endif + return Fload(obj, fname); } #ifndef RUBY_LIB diff --git a/ext/MANIFEST b/ext/MANIFEST index 881a97c39e..9580b61544 100644 --- a/ext/MANIFEST +++ b/ext/MANIFEST @@ -1,6 +1,3 @@ MANIFEST -Makefile.in -dbm.c -dbm.doc -socket.c -socket.doc +extmk.rb.in + diff --git a/ext/Makefile.in b/ext/Makefile.in deleted file mode 100644 index 20d8c5c9c4..0000000000 --- a/ext/Makefile.in +++ /dev/null @@ -1,40 +0,0 @@ -2SHELL = /bin/sh - -#### Start of system configuration section. #### - -srcdir = @srcdir@ -VPATH = @srcdir@ - -CC = @CC@ - -CFLAGS = -I.. @CCDLFLAGS@ @CFLAGS@ -LIBS = @LIBS@ -EXT = @EXT@ - -prefix = @prefix@ -binprefix = -exec_prefix = @exec_prefix@ -bindir = $(exec_prefix)/bin - -#### End of system configuration section. #### - -.SUFFIXES: .so $(SUFFIXES) - -OBJS = dbm.$(EXT) \ - socket.$(EXT) - -all: $(OBJS) - -clean:; @rm -f *.o *.so - -realclean:; @rm -f *.o *.so - @rm -f core ruby *~ Makefile - -.o.so: - ld -o $*.so $*.o - -# Prevent GNU make v3 from overflowing arg limit on SysV. -.NOEXPORT: -### -dbm.o: dbm.c ../ruby.h ../config.h ../defines.h -socket.o: socket.c ../ruby.h ../config.h ../defines.h ../io.h diff --git a/ext/dbm.c b/ext/dbm.c deleted file mode 100644 index f3e8295d6a..0000000000 --- a/ext/dbm.c +++ /dev/null @@ -1,441 +0,0 @@ -/************************************************ - - dbm.c - - - $Author: matz $ - $Date: 1995/01/10 10:42:24 $ - created at: Mon Jan 24 15:59:52 JST 1994 - - Copyright (C) 1995 Yukihiro Matsumoto - -************************************************/ - -#include "ruby.h" - -#ifdef USE_DBM - -#include <ndbm.h> -#include <fcntl.h> -#include <errno.h> - -VALUE C_DBM; -static ID id_dbm; - -extern VALUE M_Enumerable; - -static void -closeddbm() -{ - Fail("closed DBM file"); -} - -#define GetDBM(obj, dbmp) {\ - DBM **_dbm;\ - Get_Data_Struct(obj, id_dbm, DBM*, _dbm);\ - dbmp = *_dbm;\ - if (dbmp == Qnil) closeddbm();\ -} - -static void -free_dbm(dbmp) - DBM **dbmp; -{ - if (*dbmp) dbm_close(*dbmp); -} - -#define MakeDBM(obj, dp) {\ - DBM **_dbm;\ - if (!id_dbm) id_dbm = rb_intern("dbm");\ - Make_Data_Struct(obj,id_dbm,DBM*,Qnil,free_dbm,_dbm);\ - *_dbm=dp;\ -} - -static VALUE -Sdbm_open(argc, argv, class) - int argc; - VALUE *argv; - VALUE class; -{ - VALUE file, vmode; - DBM *dbm, **dbm2; - int mode; - VALUE obj; - - if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) { - mode = 0666; /* default value */ - } - else if (NIL_P(vmode)) { - mode = -1; /* return nil if DB not exist */ - } - else { - mode = NUM2INT(vmode); - } - Check_Type(file, T_STRING); - - dbm = Qnil; - if (mode >= 0) - dbm = dbm_open(RSTRING(file)->ptr, O_RDWR|O_CREAT, mode); - if (!dbm) - dbm = dbm_open(RSTRING(file)->ptr, O_RDWR, mode); - if (!dbm) - dbm = dbm_open(RSTRING(file)->ptr, O_RDONLY, mode); - - if (!dbm) { - if (mode == -1) return Qnil; - rb_sys_fail(RSTRING(file)->ptr); - } - - obj = obj_alloc(class); - MakeDBM(obj, dbm); - - return obj; -} - -static VALUE -Fdbm_close(obj) - VALUE obj; -{ - DBM **dbmp; - - Get_Data_Struct(obj, id_dbm, DBM*, dbmp); - if (*dbmp == Qnil) Fail("already closed DBM file"); - dbm_close(*dbmp); - *dbmp = Qnil; - - return Qnil; -} - -static VALUE -Fdbm_fetch(obj, keystr) - VALUE obj, keystr; -{ - datum key, value; - DBM *dbm; - - Check_Type(keystr, T_STRING); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; - - GetDBM(obj, dbm); - value = dbm_fetch(dbm, key); - if (value.dptr == Qnil) { - return Qnil; - } - return str_new(value.dptr, value.dsize); -} - -static VALUE -Fdbm_indexes(obj, args) - VALUE obj; - struct RArray *args; -{ - VALUE *p, *pend; - struct RArray *new; - int i = 0; - - if (!args || args->len == 1 && TYPE(args->ptr) != T_ARRAY) { - args = (struct RArray*)rb_to_a(args->ptr[0]); - } - - new = (struct RArray*)ary_new2(args->len); - - p = args->ptr; pend = p + args->len; - while (p < pend) { - new->ptr[i++] = Fdbm_fetch(obj, *p++); - new->len = i; - } - return (VALUE)new; -} - -static VALUE -Fdbm_delete(obj, keystr) - VALUE obj, keystr; -{ - datum key; - DBM *dbm; - - Check_Type(keystr, T_STRING); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; - - GetDBM(obj, dbm); - if (dbm_delete(dbm, key)) { - Fail("dbm_delete failed"); - } - return obj; -} - -static VALUE -Fdbm_shift(obj) - VALUE obj; -{ - datum key, val; - DBM *dbm; - VALUE keystr, valstr; - - GetDBM(obj, dbm); - - key = dbm_firstkey(dbm); - if (!key.dptr) return Qnil; - val = dbm_fetch(dbm, key); - dbm_delete(dbm, key); - - keystr = str_new(key.dptr, key.dsize); - valstr = str_new(val.dptr, val.dsize); - return assoc_new(keystr, valstr); -} - -static VALUE -Fdbm_delete_if(obj) - VALUE obj; -{ - datum key, val; - DBM *dbm; - VALUE keystr, valstr; - - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - val = dbm_fetch(dbm, key); - keystr = str_new(key.dptr, key.dsize); - valstr = str_new(val.dptr, val.dsize); - if (rb_yield(assoc_new(keystr, valstr)) - && dbm_delete(dbm, key)) { - Fail("dbm_delete failed"); - } - } - return obj; -} - -static VALUE -Fdbm_clear(obj) - VALUE obj; -{ - datum key; - DBM *dbm; - - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - if (dbm_delete(dbm, key)) { - Fail("dbm_delete failed"); - } - } - return obj; -} - -static VALUE -Fdbm_store(obj, keystr, valstr) - VALUE obj, keystr, valstr; -{ - datum key, val; - DBM *dbm; - - if (valstr == Qnil) { - Fdbm_delete(obj, keystr); - return Qnil; - } - - Check_Type(keystr, T_STRING); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; - Check_Type(valstr, T_STRING); - val.dptr = RSTRING(valstr)->ptr; - val.dsize = RSTRING(valstr)->len; - - GetDBM(obj, dbm); - if (dbm_store(dbm, key, val, DBM_REPLACE)) { - dbm_clearerr(dbm); - if (errno == EPERM) rb_sys_fail(Qnil); - Fail("dbm_store failed"); - } - return valstr; -} - -static VALUE -Fdbm_length(obj) - VALUE obj; -{ - datum key; - DBM *dbm; - int i = 0; - - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - i++; - } - return INT2FIX(i); -} - -static VALUE -Fdbm_each_value(obj) - VALUE obj; -{ - datum key, val; - DBM *dbm; - - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - val = dbm_fetch(dbm, key); - rb_yield(str_new(val.dptr, val.dsize)); - } - return obj; -} - -static VALUE -Fdbm_each_key(obj) - VALUE obj; -{ - datum key; - DBM *dbm; - - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - rb_yield(str_new(key.dptr, key.dsize)); - } - return obj; -} - -static VALUE -Fdbm_each_pair(obj) - VALUE obj; -{ - datum key, val; - DBM *dbm; - VALUE keystr, valstr; - - GetDBM(obj, dbm); - - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - val = dbm_fetch(dbm, key); - keystr = str_new(key.dptr, key.dsize); - valstr = str_new(val.dptr, val.dsize); - rb_yield(assoc_new(keystr, valstr)); - } - - return obj; -} - -static VALUE -Fdbm_keys(obj) - VALUE obj; -{ - datum key; - DBM *dbm; - VALUE ary; - - ary = ary_new(); - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - ary_push(ary, str_new(key.dptr, key.dsize)); - } - - return ary; -} - -static VALUE -Fdbm_values(obj) - VALUE obj; -{ - datum key, val; - DBM *dbm; - VALUE ary; - - ary = ary_new(); - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - val = dbm_fetch(dbm, key); - ary_push(ary, str_new(val.dptr, val.dsize)); - } - - return ary; -} - -static VALUE -Fdbm_has_key(obj, keystr) - VALUE obj, keystr; -{ - datum key, val; - DBM *dbm; - - Check_Type(keystr, T_STRING); - key.dptr = RSTRING(keystr)->ptr; - key.dsize = RSTRING(keystr)->len; - - GetDBM(obj, dbm); - val = dbm_fetch(dbm, key); - if (val.dptr) return TRUE; - return FALSE; -} - -static VALUE -Fdbm_has_value(obj, valstr) - VALUE obj, valstr; -{ - datum key, val; - DBM *dbm; - - Check_Type(valstr, T_STRING); - val.dptr = RSTRING(valstr)->ptr; - val.dsize = RSTRING(valstr)->len; - - GetDBM(obj, dbm); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - val = dbm_fetch(dbm, key); - if (val.dsize == RSTRING(valstr)->len && - memcmp(val.dptr, RSTRING(valstr)->ptr, val.dsize) == 0) - return TRUE; - } - return FALSE; -} - -static VALUE -Fdbm_to_a(obj) - VALUE obj; -{ - datum key, val; - DBM *dbm; - VALUE ary; - - GetDBM(obj, dbm); - - ary = ary_new(); - for (key = dbm_firstkey(dbm); key.dptr; key = dbm_nextkey(dbm)) { - val = dbm_fetch(dbm, key); - ary_push(ary, assoc_new(str_new(key.dptr, key.dsize), - str_new(val.dptr, val.dsize))); - } - - return ary; -} - -Init_dbm() -{ -#ifdef HAVE_LIBDBM - dln_load_lib("libdbm.a"); -#endif - C_DBM = rb_define_class("DBM", C_Object); - rb_include_module(C_DBM, M_Enumerable); - - rb_define_single_method(C_DBM, "open", Sdbm_open, -1); - rb_define_method(C_DBM, "close", Fdbm_close, 0); - rb_define_method(C_DBM, "[]", Fdbm_fetch, 1); - rb_define_method(C_DBM, "[]=", Fdbm_store, 2); - rb_define_method(C_DBM, "indexes", Fdbm_indexes, -2); - rb_define_method(C_DBM, "length", Fdbm_length, 0); - rb_define_alias(C_DBM, "size", "length"); - rb_define_method(C_DBM, "each", Fdbm_each_pair, 0); - rb_define_method(C_DBM, "each_value", Fdbm_each_value, 0); - rb_define_method(C_DBM, "each_key", Fdbm_each_key, 0); - rb_define_method(C_DBM, "each_pair", Fdbm_each_pair, 0); - rb_define_method(C_DBM, "keys", Fdbm_keys, 0); - rb_define_method(C_DBM, "values", Fdbm_values, 0); - rb_define_method(C_DBM, "shift", Fdbm_shift, 1); - rb_define_method(C_DBM, "delete", Fdbm_delete, 1); - rb_define_method(C_DBM, "delete_if", Fdbm_delete_if, 0); - rb_define_method(C_DBM, "clear", Fdbm_clear, 0); - rb_define_method(C_DBM, "includes", Fdbm_has_key, 1); - rb_define_method(C_DBM, "has_key", Fdbm_has_key, 1); - rb_define_method(C_DBM, "has_value", Fdbm_has_value, 1); - - rb_define_method(C_DBM, "to_a", Fdbm_to_a, 0); -} -#endif /* USE_DBM */ diff --git a/ext/dbm.doc b/ext/dbm.doc deleted file mode 100644 index 48c91a9157..0000000000 --- a/ext/dbm.doc +++ /dev/null @@ -1,107 +0,0 @@ -.\" dbm.doc - -*- Indented-Text -*- created at: Thu Mar 23 20:28:31 JST 1995 - -** DBM(���饹) - -NDBM�ե�������������륯�饹���������ǡ����Ȥ��ʸ����Ǥʤ���Ф� -��ʤ��Ȥ������¤ȡ��ǡ������ե��������¸�����Ȥ�����������Ƥ� -Dict���饹������Ʊ�ͤ˰������Ȥ��Ǥ��롥NDBM�������Ƥ��ʤ������ƥ�Ǥ� -���Υ��饹���������ʤ��� - -SuperClass: Object - -Included Modules: Enumerable - -Methods: - - self [key] - - key���Ȥ����ͤ��֤��� - - self [key]= value - - key���Ȥ��ơ�value���Ǽ���롥value�Ȥ���nil����ꤹ��ȡ� - key���Ф�����ܤκ���Ȥʤ롥 - - clear - - DBM�ե��������Ȥ���ˤ��롥 - - close - - DBM�ե�������������롥�ʸ�������㳰��ȯ�������롥 - - delete(key) - - key���Ȥ����Ȥ������롥 - - delete_if - - ���Ǥ������륤�ƥ졼����key::value�Ȥ����ڥ���Ϳ���ơ��֥��� - ����ɾ�������ͤ����λ�������������ܤ������롥 - - each - each_pair - - key::value�ʤ�ڥ���Ϳ���륤�ƥ졼���� - - each_key - - ���Ƥ�key���Ф��Ʒ����֤����ƥ졼���� - - each_value - - ���Ƥ�value���Ф��Ʒ����֤����ƥ졼���� - - has_key(key) - includes(key) - - key���ǡ����١������¸�ߤ�����������֤� - - has_value(value) - - value���ͤȤ����Ȥ��ǡ����١������¸�ߤ���������� - �֤� - - indexes(ary) - indexes(key-1, ..., key-n) - - 1���ܤη����Ǥ�ʸ��������������Ȥ��Ƽ����ơ��������Ǥ� - �Ȥ������Ǥ�ޤ�������֤���2���ܤη����Ǥϳư������ͤ��� - �������Ǥ�ޤ�������֤�. - - keys - - �ǡ����١������¸�ߤ��륭�����Ƥ�ޤ�������֤��� - - length - size - - �ǡ����١���������Ǥο����֤���(����:���ߤμ¸��Ǥ����ǿ���� - ���뤿��˥ǡ����١�����������������Τǡ��빽�����Ȥ��⤤���� - ��Ĥ��ƻȤ�����.) - - shift - - �ǡ����١���������Ǥ���ļ��Ф�(�ǡ����١�������������)�� - key::value�Ȥ����ڥ����֤��� - - to_a - - �ǡ����١������key-value�ڥ������ǤȤ���������֤��� - - values - - �ǡ����١������¸�ߤ��������Ƥ�ޤ�������֤��� - -Single Methods: - - open(dbname[, mode]) - - dbname�ǻ��ꤷ���ǡ����١�����⡼�ɤ�mode�����ꤷ�ƥ����ץ� - �롥mode�ξ�ά�ͤ�0666�Ǥ��롥mode�Ȥ���nil����ꤹ��ȥǡ��� - �١���������¸�ߤ��ʤ����ˤϿ����˥����ץ���nil���֤��� - -------------------------------------------------------- -Local variables: -fill-column: 70 -end: diff --git a/ext/extmk.rb.in b/ext/extmk.rb.in new file mode 100644 index 0000000000..25bf6b9027 --- /dev/null +++ b/ext/extmk.rb.in @@ -0,0 +1,177 @@ +#! /usr/local/bin/ruby + +def older(file1, file2) + if !File.exists(file1) then + return TRUE + end + if !File.exists(file2) then + return FALSE + end + if File.mtime(file1) < File.mtime(file2) + return TRUE + end + return FALSE +end + +if !File.exists("./Makefile") || + older("./Makefile", "../extmk.rb") || + older("./Makefile", "./extconf.rb") then + + LINK = "@CC@ -o conftest @CFLAGS@ @LDFLAGS@ conftest.c %s > /dev/null 2>&1" + $defs = [] + + def have_library(func, lib) + cfile = open("conftest.c", "w") + printf cfile, "\ +int main() { return 0; } +int t() { %s(); return 0; } +", func + cfile.close + + begin + if system(format(LINK, "-l" + lib)) != 0 + return FALSE + end + ensure + system "/bin/rm -f conftest*" + end + + if $libs + $libs = $libs + " -l" + lib + else + $libs = "-l" + lib + end + $defs.push(format("-DHAVE_LIB%s", lib.toupper)) + return TRUE + end + + def have_func(func) + + cfile = open("conftest.c", "w") + printf cfile, "\ +char %s(); +int main() { return 0; } +int t() { %s(); return 0; } +", func, func + cfile.close + + libs = $libs + libs = "" if libs == nil + + begin + if system(format(LINK, libs)) != 0 + return FALSE + end + ensure + system "/bin/rm -f conftest*" + end + $defs.push(format("-DHAVE_%s", func.toupper)) + return TRUE + + end + + def create_header() + if $defs.length > 0 + hfile = open("extconf.h", "w") + for line in $defs + line =~ /^-D(.*)/ + printf hfile, "#define %s 1\n", $1 + end + hfile.close + end + end + + def create_makefile(target) + mfile = open("Makefile", "w") + printf mfile, "\ +SHELL = /bin/sh + +#### Start of system configuration section. #### + +srcdir = @srcdir@ +VPATH = @srcdir@ + +CC = @CC@ + +CFLAGS = -I../.. @CCDLFLAGS@ @CFLAGS@ %s +LDDLFLAGS = @LDDLFLAGS@ +", $defs.join(" ") + + printf mfile, "\ + +prefix = @prefix@ +binprefix = +exec_prefix = @exec_prefix@ +bindir = $(exec_prefix)/bin +@SET_MAKE@ + +#### End of system configuration section. #### +" + printf mfile, "OBJS = " + if !$objs then + $objs = Dir["*.c"] + for f in $objs + f.sub(/\.c$/, ".o") + end + end + printf mfile, $objs.join(" ") + printf mfile, "\n" + + printf mfile, "\ +TARGET = %s.@DLEXT@ + +all: $(TARGET) + +clean:; @rm -f *.o *.so + @rm -f Makefile extconf.h conftest.* + @rm -f core ruby *~ + +realclean: clean +", target + + if "@DLEXT@" == "so" + printf mfile, "\ +.SUFFIXES: .so $(SUFFIXES) + +$(TARGET).so: $(OBJS) + ld $(LDDLFLAGS) -o $*.so $(OBJS) +" + elsif !File.exists(target + ".c") + printf mfile, "\ +$(TARGET).o: $(OBJS) + ld $(LDDLFLAGS) -r $*.o $(OBJS) +" + end + + if File.exists("depend") + dfile = open("depend", "r") + printf mfile, "###\n" + while line = dfile.gets() + printf mfile, "%s", line + end + dfile.close + end + mfile.close + end + + if File.exists("configure") && + (!File.exists("config.status") || + File.mtime("config.status") < File.mtime("configure")) then + + system "./configure" + + end + + if File.exists("extconf.rb") + load "extconf.rb" + else + Dir.pwd =~ /[^\/]+$/ + create_makefile($&); + end + +end +system "make all" if File.exists("./Makefile") + +#Local variables: +# mode: ruby +#end: diff --git a/ext/socket.c b/ext/socket.c deleted file mode 100644 index ec992340a4..0000000000 --- a/ext/socket.c +++ /dev/null @@ -1,761 +0,0 @@ -/************************************************ - - socket.c - - - $Author: matz $ - $Date: 1995/01/10 10:42:55 $ - created at: Thu Mar 31 12:21:29 JST 1994 - -************************************************/ - -#include "ruby.h" -#ifdef HAVE_SOCKET -#include "io.h" -#include <stdio.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <errno.h> -#include <sys/un.h> - -extern VALUE C_IO; -VALUE C_BasicSocket; -VALUE C_TCPsocket; -VALUE C_TCPserver; -VALUE C_UNIXsocket; -VALUE C_UNIXserver; -VALUE C_Socket; - -FILE *rb_fdopen(); -char *strdup(); - -static VALUE -sock_new(class, fd) - VALUE class; - int fd; -{ - VALUE sock = obj_alloc(class); - OpenFile *fp; - - MakeOpenFile(sock, fp); - fp->f = rb_fdopen(fd, "r"); - setbuf(fp->f, NULL); - fp->f2 = rb_fdopen(fd, "w"); - fp->mode = FMODE_READWRITE|FMODE_SYNC; - - return sock; -} - -static VALUE -Fbsock_shutdown(argc, argv, sock) - int argc; - VALUE *argv; - VALUE sock; -{ - VALUE howto; - int how; - OpenFile *fptr; - - rb_scan_args(argc, argv, "01", &howto); - if (howto == Qnil) - how = 2; - else { - how = NUM2INT(howto); - if (how < 0 && how > 2) how = 2; - } - GetOpenFile(sock, fptr); - if (shutdown(fileno(fptr->f), how) == -1) - rb_sys_fail(Qnil); - - return INT2FIX(0); -} - -static VALUE -Fbsock_setopt(sock, lev, optname, val) - VALUE sock, lev, optname; - struct RString *val; -{ - int level, option; - OpenFile *fptr; - - level = NUM2INT(lev); - option = NUM2INT(optname); - Check_Type(val, T_STRING); - - GetOpenFile(sock, fptr); - if (setsockopt(fileno(fptr->f), level, option, val->ptr, val->len) < 0) - rb_sys_fail(fptr->path); - - return INT2FIX(0); -} - -static VALUE -Fbsock_getopt(sock, lev, optname) - VALUE sock, lev, optname; -{ - int level, option, len; - struct RString *val; - OpenFile *fptr; - - level = NUM2INT(lev); - option = NUM2INT(optname); - len = 256; - val = (struct RString*)str_new(0, len); - Check_Type(val, T_STRING); - - GetOpenFile(sock, fptr); - if (getsockopt(fileno(fptr->f), level, option, val->ptr, &len) < 0) - rb_sys_fail(fptr->path); - val->len = len; - return (VALUE)val; -} - -static VALUE -Fbsock_getsockname(sock) - VALUE sock; -{ - char buf[1024]; - int len = sizeof buf; - OpenFile *fptr; - - GetOpenFile(sock, fptr); - if (getsockname(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0) - rb_sys_fail("getsockname(2)"); - return str_new(buf, len); -} - -static VALUE -Fbsock_getpeername(sock) - VALUE sock; -{ - char buf[1024]; - int len = sizeof buf; - OpenFile *fptr; - - GetOpenFile(sock, fptr); - if (getpeername(fileno(fptr->f), (struct sockaddr*)buf, &len) < 0) - rb_sys_fail("getpeername(2)"); - return str_new(buf, len); -} - -static VALUE -open_inet(class, h, serv, server) - VALUE class, h, serv; - int server; -{ - char *host; - struct hostent *hostent, _hostent; - struct servent *servent, _servent; - struct protoent *protoent; - struct sockaddr_in sockaddr; - int fd, status; - int hostaddr, hostaddrPtr[2]; - int servport; - char *syscall; - VALUE sock; - - if (h) { - Check_Type(h, T_STRING); - host = RSTRING(h)->ptr; - hostent = gethostbyname(host); - if (hostent == NULL) { - hostaddr = inet_addr(host); - if (hostaddr == -1) { - if (server && !strlen(host)) - hostaddr = INADDR_ANY; - else - rb_sys_fail(host); - } - _hostent.h_addr_list = (char **)hostaddrPtr; - _hostent.h_addr_list[0] = (char *)&hostaddr; - _hostent.h_addr_list[1] = NULL; - _hostent.h_length = sizeof(hostaddr); - _hostent.h_addrtype = AF_INET; - hostent = &_hostent; - } - } - servent = NULL; - if (FIXNUM_P(serv)) { - servport = FIX2UINT(serv); - goto setup_servent; - } - Check_Type(serv, T_STRING); - servent = getservbyname(RSTRING(serv)->ptr, "tcp"); - if (servent == NULL) { - servport = strtoul(RSTRING(serv)->ptr, Qnil, 0); - if (servport == -1) Fail("no such servce %s", RSTRING(serv)->ptr); - setup_servent: - _servent.s_port = servport; - _servent.s_proto = "tcp"; - servent = &_servent; - } - protoent = getprotobyname(servent->s_proto); - if (protoent == NULL) Fail("no such proto %s", servent->s_proto); - - fd = socket(PF_INET, SOCK_STREAM, protoent->p_proto); - - sockaddr.sin_family = AF_INET; - if (h == Qnil) { - sockaddr.sin_addr.s_addr = INADDR_ANY; - } - else { - memcpy((char *)&(sockaddr.sin_addr.s_addr), - (char *) hostent->h_addr_list[0], - (size_t) hostent->h_length); - } - sockaddr.sin_port = servent->s_port; - - if (server) { - status = bind(fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)); - syscall = "bind(2)"; - } - else { - status = connect(fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)); - syscall = "connect(2)"; - } - - if (status < 0) { - close (fd); - rb_sys_fail(syscall); - } - if (server) listen(fd, 5); - - /* create new instance */ - sock = sock_new(class, fd); - - return sock; -} - -static VALUE -Stcp_sock_open(class, host, serv) - VALUE class, host, serv; -{ - Check_Type(host, T_STRING); - return open_inet(class, host, serv, 0); -} - -static VALUE -Stcp_svr_open(argc, argv, class) - int argc; - VALUE *argv; - VALUE class; -{ - VALUE arg1, arg2; - - if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) - return open_inet(class, arg1, arg2, 1); - else - return open_inet(class, Qnil, arg1, 1); -} - -static VALUE -sock_accept(class, fd, sockaddr, len) - VALUE class; - int fd; - struct sockaddr *sockaddr; - int *len; -{ - int fd2; - - retry: - fd2 = accept(fd, sockaddr, len); - if (fd2 < 0) { - if (errno == EINTR) goto retry; - rb_sys_fail(Qnil); - } - return sock_new(class, fd2); -} - -static VALUE -Ftcp_accept(sock) - VALUE sock; -{ - OpenFile *fptr; - struct sockaddr_in from; - int fromlen; - - GetOpenFile(sock, fptr); - fromlen = sizeof(struct sockaddr_in); - return sock_accept(C_TCPsocket, fileno(fptr->f), - (struct sockaddr*)&from, &fromlen); -} - -static VALUE -open_unix(class, path, server) - VALUE class; - struct RString *path; - int server; -{ - struct sockaddr_un sockaddr; - int fd, status; - char *syscall; - VALUE sock; - OpenFile *fptr; - - Check_Type(path, T_STRING); - fd = socket(PF_UNIX, SOCK_STREAM, 0); - if (fd < 0) rb_sys_fail("socket(2)"); - - sockaddr.sun_family = AF_UNIX; - strncpy(sockaddr.sun_path, path->ptr, sizeof(sockaddr.sun_path)-1); - sockaddr.sun_path[sizeof(sockaddr.sun_path)-1] = '\0'; - - if (server) { - status = bind(fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)); - syscall = "bind(2)"; - } - else { - status = connect(fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)); - syscall = "connect(2)"; - } - - if (status < 0) { - close (fd); - rb_sys_fail(syscall); - } - - if (server) listen(fd, 5); - - sock = sock_new(class, fd); - GetOpenFile(sock, fptr); - fptr->path = strdup(path->ptr); - - return sock; -} - -static VALUE -tcp_addr(sockaddr) - struct sockaddr_in *sockaddr; -{ - VALUE family, port, addr; - VALUE ary; - struct hostent *hostent; - - family = str_new2("AF_INET"); - hostent = gethostbyaddr((char*)&sockaddr->sin_addr.s_addr, - sizeof(sockaddr->sin_addr), - AF_INET); - if (hostent) { - addr = str_new2(hostent->h_name); - } - else { - char buf[16]; - char *a = (char*)&sockaddr->sin_addr; - sprintf(buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); - addr = str_new2(buf); - } - port = INT2FIX(sockaddr->sin_port); - ary = ary_new3(3, family, port, addr); - - return ary; -} - -static VALUE -Ftcp_addr(sock) - VALUE sock; -{ - OpenFile *fptr; - struct sockaddr_in addr; - int len = sizeof addr; - - GetOpenFile(sock, fptr); - - if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0) - rb_sys_fail("getsockname(2)"); - return tcp_addr(&addr); -} - -static VALUE -Ftcp_peeraddr(sock) - VALUE sock; -{ - OpenFile *fptr; - struct sockaddr_in addr; - int len = sizeof addr; - - GetOpenFile(sock, fptr); - - if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0) - rb_sys_fail("getsockname(2)"); - return tcp_addr(&addr); -} - -static VALUE -Sunix_sock_open(sock, path) - VALUE sock, path; -{ - return open_unix(sock, path, 0); -} - -static VALUE -Funix_path(sock) - VALUE sock; -{ - OpenFile *fptr; - - GetOpenFile(sock, fptr); - if (fptr->path == Qnil) { - struct sockaddr_un addr; - int len = sizeof(addr); - if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0) - rb_sys_fail(Qnil); - fptr->path = strdup(addr.sun_path); - } - return str_new2(fptr->path); -} - -static VALUE -Sunix_svr_open(class, path) - VALUE class, path; -{ - return open_unix(class, path, 1); -} - -static VALUE -Funix_accept(sock) - VALUE sock; -{ - OpenFile *fptr; - struct sockaddr_un from; - int fromlen; - - GetOpenFile(sock, fptr); - fromlen = sizeof(struct sockaddr_un); - return sock_accept(C_UNIXsocket, fileno(fptr->f), - (struct sockaddr*)&from, &fromlen); -} - -static VALUE -unix_addr(sockaddr) - struct sockaddr_un *sockaddr; -{ - return assoc_new(str_new2("AF_UNIX"),str_new2(sockaddr->sun_path)); -} - -static VALUE -Funix_addr(sock) - VALUE sock; -{ - OpenFile *fptr; - struct sockaddr_un addr; - int len = sizeof addr; - - GetOpenFile(sock, fptr); - - if (getsockname(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0) - rb_sys_fail("getsockname(2)"); - return unix_addr(&addr); -} - -static VALUE -Funix_peeraddr(sock) - VALUE sock; -{ - OpenFile *fptr; - struct sockaddr_un addr; - int len = sizeof addr; - - GetOpenFile(sock, fptr); - - if (getpeername(fileno(fptr->f), (struct sockaddr*)&addr, &len) < 0) - rb_sys_fail("getsockname(2)"); - return unix_addr(&addr); -} - -static void -setup_domain_and_type(domain, dv, type, tv) - VALUE domain, type; - int *dv, *tv; -{ - char *ptr; - - if (TYPE(domain) == T_STRING) { - ptr = RSTRING(domain)->ptr; - if (strcmp(ptr, "PF_UNIX") == 0) - *dv = PF_UNIX; - else if (strcmp(ptr, "PF_INET") == 0) - *dv = PF_INET; -#ifdef PF_IMPLINK - else if (strcmp(ptr, "PF_IMPLINK") == 0) - *dv = PF_IMPLINK; -#endif -#ifdef PF_AX25 - else if (strcmp(ptr, "PF_AX25") == 0) - *dv = PF_AX25; -#endif -#ifdef PF_IPX - else if (strcmp(ptr, "PF_IPX") == 0) - *dv = PF_IPX; -#endif - else - Fail("Unknown socket domain %s", ptr); - } - else { - *dv = NUM2INT(domain); - } - if (TYPE(type) == T_STRING) { - ptr = RSTRING(type)->ptr; - if (strcmp(ptr, "SOCK_STREAM") == 0) - *tv = SOCK_STREAM; - else if (strcmp(ptr, "SOCK_DGRAM") == 0) - *tv = SOCK_DGRAM; -#ifdef SOCK_RAW - else if (strcmp(ptr, "SOCK_RAW") == 0) - *tv = SOCK_RAW; -#endif -#ifdef SOCK_SEQPACKET - else if (strcmp(ptr, "SOCK_SEQPACKET") == 0) - *tv = SOCK_SEQPACKET; -#endif -#ifdef SOCK_RDM - else if (strcmp(ptr, "SOCK_RDM") == 0) - *tv = SOCK_RDM; -#endif -#ifdef SOCK_PACKET - else if (strcmp(ptr, "SOCK_PACKET") == 0) - *tv = SOCK_PACKET; -#endif - else - Fail("Unknown socket type %s", ptr); - } - else { - *tv = NUM2INT(type); - } -} - -static VALUE -Ssock_open(class, domain, type, protocol) - VALUE class, domain, type, protocol; -{ - int fd; - int d, t; - - setup_domain_and_type(domain, &d, type, &t); - fd = socket(d, t, NUM2INT(protocol)); - if (fd < 0) rb_sys_fail("socke(2)"); - return sock_new(class, fd); -} - -static VALUE -Ssock_for_fd(class, fd) - VALUE class, fd; -{ - return sock_new(class, NUM2INT(fd)); -} - -static VALUE -Ssock_socketpair(class, domain, type, protocol) - VALUE class, domain, type, protocol; -{ - int fd; - int d, t, sp[2]; - - setup_domain_and_type(domain, &d, type, &t); - if (socketpair(d, t, NUM2INT(protocol), sp) < 0) - rb_sys_fail("socketpair(2)"); - - return assoc_new(sock_new(class, sp[0]), sock_new(class, sp[1])); -} - -static VALUE -Fsock_connect(sock, addr) - VALUE sock; - struct RString *addr; -{ - OpenFile *fptr; - - Check_Type(addr, T_STRING); - str_modify(addr); - - GetOpenFile(sock, fptr); - if (connect(fileno(fptr->f), (struct sockaddr*)addr->ptr, addr->len) < 0) - rb_sys_fail("connect(2)"); - - return INT2FIX(0); -} - -static VALUE -Fsock_bind(sock, addr) - VALUE sock; - struct RString *addr; -{ - OpenFile *fptr; - - Check_Type(addr, T_STRING); - str_modify(addr); - - GetOpenFile(sock, fptr); - if (bind(fileno(fptr->f), (struct sockaddr*)addr->ptr, addr->len) < 0) - rb_sys_fail("bind(2)"); - - return INT2FIX(0); -} - -static VALUE -Fsock_listen(sock, log) - VALUE sock, log; -{ - OpenFile *fptr; - - GetOpenFile(sock, fptr); - if (listen(fileno(fptr->f), NUM2INT(log)) < 0) - rb_sys_fail("listen(2)"); - - return INT2FIX(0); -} - -static VALUE -Fsock_accept(sock) - VALUE sock; -{ - OpenFile *fptr; - VALUE addr, sock2; - char buf[1024]; - int len = sizeof buf; - - GetOpenFile(sock, fptr); - sock2 = sock_accept(C_Socket,fileno(fptr->f),(struct sockaddr*)buf,&len); - - return assoc_new(sock2, str_new(buf, len)); -} - -static VALUE -Fsock_send(argc, argv, sock) - int argc; - VALUE *argv; - VALUE sock; -{ - struct RString *msg, *to; - VALUE flags; - OpenFile *fptr; - FILE *f; - int fd, n; - - rb_scan_args(argc, argv, "21", &msg, &flags, &to); - - Check_Type(msg, T_STRING); - - GetOpenFile(sock, fptr); - f = fptr->f2?fptr->f2:fptr->f; - fd = fileno(f); - if (to) { - Check_Type(to, T_STRING); - n = sendto(fd, msg->ptr, msg->len, NUM2INT(flags), - (struct sockaddr*)to->ptr, to->len); - } - else { - n = send(fd, msg->ptr, msg->len, NUM2INT(flags)); - } - if (n < 0) { - rb_sys_fail("send(2)"); - } - return INT2FIX(n); -} - -static VALUE -sock_recv(sock, argc, argv, from) - VALUE sock; - int argc; - VALUE *argv; - int from; -{ - OpenFile *fptr; - FILE f; - struct RString *str; - char buf[1024]; - int fd, alen = sizeof buf; - VALUE len, flg; - int flags; - - rb_scan_args(argc, argv, "11", &len, &flg); - - if (flg == Qnil) flags = 0; - else flags = NUM2INT(flg); - - str = (struct RString*)str_new(0, NUM2INT(len)); - - GetOpenFile(sock, fptr); - fd = fileno(fptr->f); - if ((str->len = recvfrom(fd, str->ptr, str->len, flags, - (struct sockaddr*)buf, &alen)) < 0) { - rb_sys_fail("recvfrom(2)"); - } - - if (from) - return assoc_new(str, str_new(buf, alen)); - else - return (VALUE)str; -} - -static VALUE -Fsock_recv(argc, argv, sock) - int argc; - VALUE *argv; - VALUE sock; -{ - return sock_recv(sock, argc, argv, 0); -} - -static VALUE -Fsock_recvfrom(argc, argv, sock) - int argc; - VALUE *argv; - VALUE sock; -{ - return sock_recv(sock, argc, argv, 1); -} - -Init_socket () -{ -#ifdef HAVE_LIBSOCKET - dln_load_lib("libsocket.a"); -#endif - C_BasicSocket = rb_define_class("BasicSocket", C_IO); - rb_undef_method(C_BasicSocket, "new"); - rb_define_method(C_BasicSocket, "shutdown", Fbsock_shutdown, -1); - rb_define_method(C_BasicSocket, "setopt", Fbsock_setopt, 3); - rb_define_method(C_BasicSocket, "getopt", Fbsock_getopt, 2); - rb_define_method(C_BasicSocket, "getsockname", Fbsock_getsockname, 0); - rb_define_method(C_BasicSocket, "getpeername", Fbsock_getpeername, 0); - - C_TCPsocket = rb_define_class("TCPsocket", C_BasicSocket); - rb_define_single_method(C_TCPsocket, "open", Stcp_sock_open, 2); - rb_define_single_method(C_TCPsocket, "new", Stcp_sock_open, 2); - rb_define_method(C_TCPsocket, "addr", Ftcp_addr, 0); - rb_define_method(C_TCPsocket, "peeraddr", Ftcp_peeraddr, 0); - - C_TCPserver = rb_define_class("TCPserver", C_TCPsocket); - rb_define_single_method(C_TCPserver, "open", Stcp_svr_open, -1); - rb_define_single_method(C_TCPserver, "new", Stcp_svr_open, -1); - rb_define_method(C_TCPserver, "accept", Ftcp_accept, 0); - - C_UNIXsocket = rb_define_class("UNIXsocket", C_BasicSocket); - rb_define_single_method(C_UNIXsocket, "open", Sunix_sock_open, 1); - rb_define_single_method(C_UNIXsocket, "new", Sunix_sock_open, 1); - rb_define_method(C_UNIXsocket, "path", Funix_path, 0); - rb_define_method(C_UNIXsocket, "addr", Funix_addr, 0); - rb_define_method(C_UNIXsocket, "peeraddr", Funix_peeraddr, 0); - - C_UNIXserver = rb_define_class("UNIXserver", C_UNIXsocket); - rb_define_single_method(C_UNIXserver, "open", Sunix_svr_open, 1); - rb_define_single_method(C_UNIXserver, "new", Sunix_svr_open, 1); - rb_define_method(C_UNIXserver, "accept", Funix_accept, 0); - - C_Socket = rb_define_class("Socket", C_BasicSocket); - rb_define_single_method(C_Socket, "open", Ssock_open, 3); - rb_define_single_method(C_Socket, "new", Ssock_open, 3); - rb_define_single_method(C_Socket, "for_fd", Ssock_for_fd, 1); - - rb_define_method(C_Socket, "connect", Fsock_connect, 1); - rb_define_method(C_Socket, "bind", Fsock_bind, 1); - rb_define_method(C_Socket, "listen", Fsock_listen, 1); - rb_define_method(C_Socket, "accept", Fsock_accept, 0); - - rb_define_method(C_Socket, "send", Fsock_send, -1); - rb_define_method(C_Socket, "recv", Fsock_recv, -1); - rb_define_method(C_Socket, "recvfrom", Fsock_recv, -1); - - rb_define_single_method(C_Socket, "socketpair", Ssock_socketpair, 3); -} -#endif /* HAVE_SOCKET */ diff --git a/ext/socket.doc b/ext/socket.doc deleted file mode 100644 index aa5bfedbff..0000000000 --- a/ext/socket.doc +++ /dev/null @@ -1,227 +0,0 @@ -.\" socket.doc - -*- Indented-Text -*- created at: Thu Mar 23 20:29:02 JST 1995 - -** Socket(���饹) - -SuperClass: BasicSocket - -�����åȤ��Τ�Τ��Ф��륷���ƥॳ�����٥�Υ������������륯�饹�� -Perl�Υ����åȤ��Ф��륢��������Ʊ��٥�ε�ǽ�����Ƥ��롥���Υ��� -���Ǥϥ����åȥ��ɥ쥹��pack���줿ʸ����ǡ����ꤹ�롥UDP�����åȤϤ� -�Υ��饹��Ȥä����Ѥ��롥 - -Methods: - - accept - - ��������³������դ��ơ���������³���Ф��륽���åȤȥ��ɥ쥹�� - �ڥ����֤���accept(2)�ȡ� - - bind(addr) - - bind(2)��Ʊ��Ư���롥addr��pack���줿�����åȥ��ɥ쥹��¤ - �ΤǤ��롥 - - connect(addr) - - connect(2)��Ʊ��Ư���롥addr��pack���줿�����åȥ��ɥ쥹�� - ¤�ΤǤ��롥 - - listen(backlog) - - listen(2)��Ʊ��Ư���롥 - - recv(len[, flags]) - - �����åȤ���ǡ����������ꡤʸ����Ȥ����֤���len�ϼ������ - �����Ĺ������ꤹ�롥flags�ˤĤ��Ƥ�recv(2)�ȡ�flags�Υ� - �ե�����ͤ�0�Ǥ��롥 - - recvfrom(len[, flags]) - - recv��Ʊ�ͤ˥����åȤ���ǡ����������뤬������ͤ�ʸ������� - ����åȤΥ��ɥ쥹�Υڥ��Ǥ��롥�����ˤĤ��Ƥ�recv��Ʊ�͡� - - send(mesg, flags[, to]) - - �����åȤ�𤷤ƥǡ��������롥flags�˴ؤ��Ƥ�send(2)�Ȥλ��� - connect���Ƥ��ʤ������åȤ��Ф��Ƥ�������Ǥ���to����ꤹ��ɬ - �פ����롥�ºݤ����ä��ǡ�����Ĺ�����֤��� - -Single Methods: - - open(domain, type, protocol) - new(domain, type, protocol) - - �����������åȤ��������롥domain��type��protocol�ϥ��롼�� - �ե�������������Ƥ�������ͤǻ��ꤹ�롥domain��type�˴ؤ��� - �ϡ�ʸ����ǻ���Ǥ��뤬�����٤ƤС����Ƥ����ݾڤϤʤ��� - - socketpair(domain, type, protocol) - - �����åȤΥڥ����֤��������λ���� open��Ʊ���Ǥ��롥 - -** BasicSocket(���饹) - -�����åȤ�ɽ����ݥ��饹������Ū�ʥ����å����ϥ��֥��饹���������롥 -�㤨�Х����ͥåȥɥᥤ��ξ���TCPsocket���Ѥ��롥 - -SuperClass: IO - -Methods: - - getopt(level, optname) - - �����åȤΥ��ץ�����������롥getsockopt(2)�ȤΤ��ȡ��� - ���������ץ��������Ƥ�ޤ�ʸ������֤��� - - getpeername - - ��³�������Υ����åȤξ�������롥�ѥå����줿sockaddr��¤�� - ��٥��˥���פ���ʸ�����֤���롥getpeername(2)�ȤΤ��ȡ� - - getsockname - - �����åȤξ�������롥�ѥå����줿sockaddr��¤�Τ�٥��˥���� - ����ʸ�����֤���롥getsockname(2)�ȤΤ��ȡ� - - setopt(level, optname, optval) - - �����åȤΥ��ץ��������ꤹ�롥setsockopt(2)�ȤΤ��ȡ� - - shutdown(how) - - �����åȤΰʹߤ���³��λ�����롥how��0�Ǥ�������ʹߤμ������� - how��1�Ǥ�����ϡ��ʹߤ����������ݤ���롥how��2�λ��ˤϡ����� - �ʹߤ������������Ȥ�˵��ݤ���롥shutdown(2)�ȡ� - -** TCPserver(���饹) - -TCP/IP���ȥ���³�Υ�����¦�Υ����åȤΥ��饹�����Υ��饹�ˤ�ä� -��ñ�˥����åȤ����Ѥ��������ФΥץ�����ߥ��Ǥ��롥�㤨��echo���� -�Фϰʲ��Τ褦�ˤʤ롥 - - gs = TCPserver.open(4444) - socks = [gs] - - while TRUE - nsock = select(socks); - if nsock == nil; continue end - for s in nsock[0] - if s == gs - socks.push(s.accept) - else - if s.eof - s.close - socks.delete(s) - else - str = s.gets - s.write(str) - end - end - end - end - -SuperClass: TCPsocket - -Methods: - - accept - - ���饤����Ȥ������³�������դ�����³����TCPsocket�Υ��� - �������֤��� - -Single Methods: - - new([host, ]service) - open([host, ]service) - - service��/etc/services(�ޤ���NIS)����Ͽ����Ƥ��륵���ӥ�̾�� - �ݡ����ֹ�ǻ��ꤹ�롥host����ꤷ�����ϻ��ꤷ���ۥ��Ȥ������ - ³����������դ��롥��ά�������ƤΥۥ��Ȥ������³�������� - ���롥 - -** TCPsocket - -�����ͥåȥɥᥤ��Υ��ȥ������åȤΥ��饹���̾��IO���饹�� -���֥��饹��Ʊ�ͤ������Ϥ��Ǥ��롥���Υ��饹�ˤ�äƥ����åȤ��Ѥ����� -�饤����Ȥ��ñ�˵��ҤǤ��롥�桼�������ϤΤޤޥ����Ф�ž������� -�������ϰʲ��Τ褦�ˤʤ롥 - - s = TCPsocket("localhost", 4444) - while gets() - s.write($_) - print(s.read) - end - -SuperClass: BasicSocket - -Methods: - - addr - - �����åȤ���³�����ɽ��������֤�����������γ����Ǥ���1���� - ��ʸ���� "AF_INET"����2���Ǥ�port�ֹ桤��3���Ǥ��ۥ��Ȥ�ɽ��ʸ - ����Ǥ��롥 - - peeraddr - - ��³����襽���åȤξ����ɽ��������֤�����������γ����Ǥ� - addr��åɤ��֤������Ʊ���Ǥ��롥 - -Single Methods: - - open(host, service) - new(host, service) - - host�ǻ��ꤷ���ۥ��Ȥ�service�ǻ��ꤷ���ݡ��Ȥ���³���������� - �Ȥ��֤���host�ϥۥ���̾���ޤ��ϥ����ͥåȥ��ɥ쥹��ʸ - ����service��/etc/services(�ޤ���NIS)����Ͽ����Ƥ��륵���� - ��̾���ݡ����ֹ�Ǥ��롥 - -** UNIXserver - -UNIX���ȥ���³�Υ�����¦�Υ����åȤΥ��饹�� - -SuperClass: UNIXsocket - -Methods: - - accept - - ���饤����Ȥ������³�������դ�����³����UNIXsocket�Υ��� - �������֤��� - -** UNIXsocket - -UNIX�ɥᥤ��Υ��ȥ������åȤΥ��饹���̾��IO���饹�Υ��֥��饹 -��Ʊ�ͤ������Ϥ��Ǥ��롥 - -SuperClass: BasicSocket - -Methods: - - addr - - �����åȤ���³�����ɽ��������֤�����������γ����Ǥ���1���� - ��ʸ���� "AF_UNIX"����2���Ǥ�path�Ǥ��롥 - - path - - UNIX�����åȤΥѥ����֤��� - - peeraddr - - ��³����襽���åȤξ����ɽ��������֤�����������γ����Ǥ� - addr��åɤ��֤������Ʊ���Ǥ��롥 - -Single Methods: - - open(path) - new(path) - - path�ǻ��ꤷ���ѥ�̾���Ѥ�����³���������åȤ��֤��� - -------------------------------------------------------- -Local variables: -fill-column: 70 -end: @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:36 $ created at: Mon Nov 15 12:24:34 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:47 $ created at: Tue Oct 5 09:44:46 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -20,6 +20,9 @@ void *malloc(); void *calloc(); void *realloc(); +#ifdef C_ALLOCA +void *alloca(); +#endif void gc(); void gc_mark(); @@ -61,6 +64,7 @@ xrealloc(ptr, size) { void *mem; + if (ptr == Qnil) return xmalloc(size); mem = realloc(ptr, size); if (mem == Qnil) { gc(); @@ -265,7 +269,7 @@ looks_pointerp(p) register RVALUE *p; { register RVALUE *heap_org; - register long i, j, n; + register long i; /* if p looks as a SCM pointer mark location */ for (i=0; i < heaps_used; i++) { @@ -282,14 +286,11 @@ mark_locations_array(x, n) VALUE *x; long n; { - int j; - VALUE p; - - for(j=0;j<n;++j) { - p = x[j]; - if (looks_pointerp(p)) { - gc_mark(p); + while (n--) { + if (looks_pointerp(*x)) { + gc_mark(*x); } + x++; } } @@ -442,8 +443,15 @@ gc_mark(obj) case T_SCOPE: { struct SCOPE *scope = (struct SCOPE*)obj; - if (scope->local_vars) - mark_locations_array(scope->local_vars, scope->local_tbl[0]); + if (scope->local_vars) { + int n = scope->local_tbl[0]; + VALUE *tbl = scope->local_vars; + + while (n--) { + gc_mark(*tbl); + tbl++; + } + } } break; @@ -571,7 +579,13 @@ void gc_mark_env(env) struct ENVIRON *env; { - mark_locations_array(env->argv, env->argc); + int n = env->argc; + VALUE *tbl = env->argv; + + while (n--) { + gc_mark(*tbl); + tbl++; + } } void @@ -579,7 +593,6 @@ gc() { struct gc_list *list; struct ENVIRON *env; - int i, max; jmp_buf save_regs_gc_mark; VALUE stack_end; @@ -594,6 +607,7 @@ gc() for (env = the_env; env; env = env->prev) { gc_mark_env(env); } + gc_mark(the_scope); FLUSH_REGISTER_WINDOWS; /* This assumes that all registers are saved into the jmp_buf */ @@ -77,16 +77,7 @@ # include <strings.h> #endif /* !HAVE_STRING_H */ -#if defined (USG) -# if !defined (isc386) -# include <memory.h> -# endif /* !isc386 */ -# if defined (RISC6000) -extern void bcopy (); -# else /* !RISC6000 */ -# define bcopy(s, d, n) ((void) memcpy ((d), (s), (n))) -# endif /* !RISC6000 */ -#endif /* USG */ +# define bcopy(s, d, n) (memcpy ((d), (s), (n))) #if defined(HAVE_ALLOCA_H) && !defined(__GNUC__) #include <alloca.h> @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:26 $ created at: Mon Nov 22 18:51:18 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -7,7 +7,7 @@ $Date: 1994/08/12 04:47:29 $ created at: Mon Jan 31 16:23:19 JST 1994 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:38 $ created at: Tue Dec 28 16:01:58 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -35,6 +35,7 @@ rb_call_inits() Init_Dir(); Init_Time(); Init_Random(); + Init_signal(); Init_process(); Init_Etc(); Init_load(); @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:39 $ created at: Fri Oct 15 18:08:59 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -285,14 +285,18 @@ Fio_gets(obj) again: bp = buf; + retry: TRAP_BEG; while ((c = getc(f)) != EOF && (*bp++ = c) != newline && bp < bpe) ; TRAP_END; - if (c == EOF && !append && bp == buf) { - str = Qnil; - goto return_gets; + if (c == EOF) { + if (!feof(f)) goto retry; + if (!append && bp == buf) { + str = Qnil; + goto return_gets; + } } if (append) @@ -941,17 +945,21 @@ rb_xstring(str) struct timeval *time_timeval(); #ifdef _STDIO_USES_IOSTREAM /* GNU libc */ -# ifdef _other_gbase -# define READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr < (fp)->_IO_read_end) -# else -# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr) -# endif -#elif __SLBF -# define READ_DATA_PENDING(fp) (fp->_r > 0) -#elif STDSTDIO -# define READ_DATA_PENDING(fp) (fp->_cnt != 0) +# ifdef _other_gbase +# define READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr < (fp)->_IO_read_end) +# else +# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr) +# endif #else +# if __SLBF +# define READ_DATA_PENDING(fp) (fp->_r > 0) +# else +# if STDSTDIO +# define READ_DATA_PENDING(fp) (fp->_cnt != 0) +# else --------------> You Lose <-------------- +# endif +# endif #endif static VALUE @@ -990,7 +998,7 @@ Fselect(argc, argv, obj) pending++; FD_SET(fileno(fptr->f), &pset); } - if (max < fileno(fptr->f)) max = fileno(fptr->f); + if (max < (int)fileno(fptr->f)) max = fileno(fptr->f); } if (pending) { /* no blocking if there's buffered data */ timerec.tv_sec = timerec.tv_usec = 0; @@ -1007,10 +1015,10 @@ Fselect(argc, argv, obj) for (i=0; i<RARRAY(write)->len; i++) { GetOpenFile(RARRAY(write)->ptr[i], fptr); FD_SET(fileno(fptr->f), wp); - if (max > fileno(fptr->f)) max = fileno(fptr->f); + if (max > (int)fileno(fptr->f)) max = fileno(fptr->f); if (fptr->f2) { FD_SET(fileno(fptr->f2), wp); - if (max < fileno(fptr->f2)) max = fileno(fptr->f2); + if (max < (int)fileno(fptr->f2)) max = fileno(fptr->f2); } } } @@ -1024,10 +1032,10 @@ Fselect(argc, argv, obj) for (i=0; i<RARRAY(except)->len; i++) { GetOpenFile(RARRAY(except)->ptr[i], fptr); FD_SET(fileno(fptr->f), ep); - if (max < fileno(fptr->f)) max = fileno(fptr->f); + if (max < (int)fileno(fptr->f)) max = fileno(fptr->f); if (fptr->f2) { FD_SET(fileno(fptr->f2), ep); - if (max > fileno(fptr->f2)) max = fileno(fptr->f2); + if (max > (int)fileno(fptr->f2)) max = fileno(fptr->f2); } } } @@ -1118,7 +1126,7 @@ io_ctl(obj, req, arg, io_p) #endif #endif #ifdef IOCPARM_LEN - len = IOCPARM_LEN(cmd); /* on BSDish systes we're safe */ + len = IOCPARM_LEN(cmd); /* on BSDish systems we're safe */ #else len = 256; /* otherwise guess at what's safe */ #endif @@ -7,7 +7,7 @@ $Date: 1994/08/12 11:06:42 $ created at: Fri Nov 12 16:47:09 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/11/01 08:28:03 $ created at: Tue Jan 25 14:12:56 JST 1994 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -110,9 +110,18 @@ Init_Math() M_Math = rb_define_module("Math"); rb_extend_object(M_Math, M_Math); +#ifdef M_PI rb_define_const(M_Math, "PI", float_new(M_PI)); +#else + rb_define_const(M_Math, "PI", float_new(atan(1.0)*4.0)); +#endif + +#ifdef M_E rb_define_const(M_Math, "E", float_new(M_E)); - +#else + rb_define_const(M_Math, "E", float_new(exp(1.0))); +#endif + rb_define_method(M_Math, "atan2", Fmath_atan2, 2); rb_define_method(M_Math, "cos", Fmath_cos, 1); rb_define_method(M_Math, "sin", Fmath_sin, 1); @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:41 $ created at: Fri May 28 15:14:02 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:42 $ created at: Fri Aug 13 18:33:09 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -166,6 +166,19 @@ Fnum_is_int(num) } static VALUE +Fnum_chr(num) + VALUE num; +{ + char c; + int i = NUM2INT(num); + + if (i < 0 || 0xff < i) + Fail("%d out of char range", i); + c = i; + return str_new(&c, 1); +} + +static VALUE Fflo_to_s(flt) struct RFloat *flt; { @@ -494,19 +507,6 @@ Fint_is_int(num) } static VALUE -Fint_chr(num) - VALUE num; -{ - char c; - int i = NUM2INT(num); - - if (i < 0 || 0xff < i) - Fail("%d out of char range", i); - c = i; - return str_new(&c, 1); -} - -static VALUE Ffix_uminus(num) VALUE num; { @@ -938,11 +938,11 @@ Init_Numeric() rb_define_method(C_Numeric, "step", Fnum_step, 2); rb_define_method(C_Numeric, "times", Fnum_dotimes, 0); rb_define_method(C_Numeric, "is_integer", Fnum_is_int, 0); + rb_define_method(C_Numeric, "chr", Fnum_chr, 0); rb_define_method(C_Numeric, "_inspect", Fkrn_inspect, 0); C_Integer = rb_define_class("Integer", C_Numeric); rb_define_method(C_Integer, "is_integer", Fint_is_int, 0); - rb_define_method(C_Integer, "chr", Fint_chr, 0); C_Fixnum = rb_define_class("Fixnum", C_Integer); @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:49 $ created at: Thu Jul 15 12:01:24 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -30,8 +30,11 @@ VALUE obj_responds_to(); VALUE obj_alloc(); static ID eq, match; + static ID init_object; +static ID init; + static VALUE P_true(obj) VALUE obj; @@ -201,7 +204,7 @@ Fobj_clone(obj) } static VALUE -Fobj_init_object(obj) +Fobj_initialize(obj) VALUE obj; { return Qnil; @@ -278,7 +281,7 @@ Fcls_new(argc, argv, class) { VALUE obj = obj_alloc(class); - rb_funcall2(obj, init_object, argc, argv); + rb_funcall2(obj, init, argc, argv); return obj; } @@ -368,6 +371,7 @@ VALUE boot_defclass(name, super) rb_name_class(obj, id); st_add_direct(rb_class_tbl, id, obj); + rb_set_class_path(obj, 0, name); return (VALUE)obj; } @@ -434,7 +438,7 @@ Init_Object() rb_define_private_method(C_Kernel, "sprintf", Fsprintf, -1); rb_define_alias(C_Kernel, "format", "sprintf"); - rb_define_private_method(C_Object, "init_object", Fobj_init_object, -1); + rb_define_private_method(C_Object, "initialize", Fobj_initialize, -1); rb_define_private_method(C_Object, "single_method_added", Fobj_s_added, 1); rb_define_method(C_Object, "clone", Fobj_clone, 0); @@ -477,5 +481,5 @@ Init_Object() rb_define_const(C_Kernel, "TRUE", TRUE); rb_define_const(C_Kernel, "FALSE", FALSE); - init_object = rb_intern("init_object"); + init = rb_intern("initialize"); } @@ -6,7 +6,7 @@ $Date: 1994/12/09 09:40:22 $ created at: Thu Feb 10 15:17:05 JST 1994 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:50 $ created at: Fri May 28 18:02:42 JST 1993 - Copyright (C) 1994 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -19,6 +19,11 @@ #include "st.h" #include <stdio.h> +/* hack for bison */ +#ifdef const +# undef const +#endif + #include "ident.h" #define is_id_nonop(id) ((id)>LAST_TOKEN) #define is_local_id(id) (is_id_nonop(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL) @@ -137,7 +142,7 @@ static void top_local_setup(); %type <node> f_arglist f_args array assoc_list assocs assoc %type <node> mlhs mlhs_head mlhs_tail lhs iter_var opt_iter_var %type <id> superclass variable symbol -%type <id> fname op rest_arg +%type <id> cname fname op rest_arg %type <num> f_arg %token UPLUS /* unary+ */ %token UMINUS /* unary- */ @@ -163,8 +168,7 @@ static void top_local_setup(); */ %left IF_MOD WHILE_MOD -%left OR -%left AND +%left OR AND %left YIELD RETURN FAIL %right '=' OP_ASGN %right COLON2 @@ -324,6 +328,12 @@ lhs : variable $$ = attrset($1, $3, Qnil); } +cname : IDENTIFIER + { + Error("class/module name must be CONSTANT"); + } + | CONSTANT + fname : IDENTIFIER | CONSTANT | op @@ -700,14 +710,14 @@ primary : literal { $$ = NEW_YIELD(Qnil); } - | primary '{' opt_iter_var '|' compexpr rbrace + | primary '{' opt_iter_var compexpr rbrace { if (nd_type($1) == NODE_LVAR || nd_type($1) == NODE_LVAR2 || nd_type($1) == NODE_CVAR) { $1 = NEW_FCALL($1->nd_vid, Qnil); } - $$ = NEW_ITER($3, $1, $5); + $$ = NEW_ITER($3, $1, $4); } | IDENTIFIER '(' call_args rparen { @@ -767,7 +777,7 @@ primary : literal { $$ = $2; } - | CLASS CONSTANT superclass + | CLASS cname superclass { if (cur_mid || in_single) Error("class definition in method body"); @@ -784,7 +794,7 @@ primary : literal cref_pop(); class_nest--; } - | MODULE CONSTANT + | MODULE cname { if (cur_mid || in_single) Error("module definition in method body"); @@ -854,11 +864,18 @@ opt_else : /* none */ iter_var : lhs | mlhs -opt_iter_var : /* none */ +opt_iter_var : '|' /* none */ '|' { $$ = Qnil; } - | iter_var + | OROP + { + $$ = Qnil; + } + | '|' iter_var '|' + { + $$ = $2; + } case_body : WHEN args then compexpr @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:47 $ created at: Tue Aug 10 14:30:50 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:48 $ created at: Fri Dec 24 16:39:21 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1994/12/06 09:30:12 $ created at: Thu Aug 19 17:46:47 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:49 $ created at: Mon Aug 9 18:24:49 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -7,7 +7,7 @@ $Date: 1994/08/12 04:47:52 $ created at: Thu Sep 30 14:18:32 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -55,41 +55,41 @@ #endif #endif /* atarist */ #else -#if defined(sparc) && !defined(__GNUC__) +#if defined(HAVE_ALLOCA_H) && !defined(__GNUC__) #include <alloca.h> #else -char *alloca (); +char *alloca(); #endif #endif /* __GNUC__ */ #define RE_ALLOCATE alloca -#define FREE_VARIABLES() alloca (0) +#define FREE_VARIABLES() alloca(0) #define FREE_AND_RETURN_VOID(stackb) return #define FREE_AND_RETURN(stackb,val) return(val) #define DOUBLE_STACK(stackx,stackb,len) \ - (stackx = (unsigned char **) alloca (2 * len \ - * sizeof (unsigned char *)),\ + (stackx = (unsigned char **) alloca(2 * len \ + * sizeof(unsigned char *)),\ /* Only copy what is in use. */ \ - (unsigned char **) memcpy (stackx, stackb, len * sizeof (char *))) + (unsigned char **) memcpy(stackx, stackb, len * sizeof (char *))) #else /* NO_ALLOCA defined */ #define RE_ALLOCATE malloc -#define FREE_VAR(var) if (var) free (var); var = NULL +#define FREE_VAR(var) if (var) free(var); var = NULL #define FREE_VARIABLES() \ do { \ - FREE_VAR (regstart); \ - FREE_VAR (regend); \ - FREE_VAR (best_regstart); \ - FREE_VAR (best_regend); \ - FREE_VAR (reg_info); \ + FREE_VAR(regstart); \ + FREE_VAR(regend); \ + FREE_VAR(best_regstart); \ + FREE_VAR(best_regend); \ + FREE_VAR(reg_info); \ } while (0) #define FREE_AND_RETURN_VOID(stackb) free(stackb);return #define FREE_AND_RETURN(stackb,val) free(stackb);return(val) #define DOUBLE_STACK(stackx,stackb,len) \ - (unsigned char **)xrealloc (stackb, 2 * len * sizeof (unsigned char *)) + (unsigned char **)xrealloc(stackb, 2 * len * sizeof(unsigned char *)) #endif /* NO_ALLOCA */ #define RE_TALLOC(n,t) ((t*)RE_ALLOCATE((n)*sizeof(t))) @@ -125,7 +125,7 @@ static void init_syntax_once P((void)); #include "util.h" static void -init_syntax_once () +init_syntax_once() { register int c; static int done = 0; @@ -133,7 +133,7 @@ init_syntax_once () if (done) return; - memset (re_syntax_table, 0, sizeof re_syntax_table); + memset(re_syntax_table, 0, sizeof re_syntax_table); for (c = 'a'; c <= 'z'; c++) re_syntax_table[c] = Sword; @@ -269,7 +269,7 @@ enum regexpcode point to second byte of SOURCE. Note that SOURCE has to be a value such as p, not, e.g., p + 1. */ #define EXTRACT_NUMBER_AND_INCR(destination, source) \ - { EXTRACT_NUMBER (destination, source); \ + { EXTRACT_NUMBER(destination, source); \ (source) += 2; } @@ -281,7 +281,7 @@ enum regexpcode defined in regex.h. */ long -re_set_syntax (syntax) +re_set_syntax(syntax) long syntax; { long ret; @@ -297,11 +297,10 @@ long re_syntax_options = DEFAULT_MBCTYPE; /* Macros for re_compile_pattern, which is found below these definitions. */ -#define CHAR_CLASS_MAX_LENGTH 6 /* Fetch the next character in the uncompiled pattern. */ #define PATFETCH(c) \ {if (p == pend) goto end_of_pattern; \ - c = * (unsigned char *) p++; } + c = *(unsigned char *) p++; } #define PATUNFETCH p-- @@ -319,8 +318,8 @@ long re_syntax_options = DEFAULT_MBCTYPE; /* Make sure we have one more byte of buffer space and then add CH to it. */ #define BUFPUSH(ch) \ { \ - GET_BUFFER_SPACE (1); \ - *b++ = (char) (ch); \ + GET_BUFFER_SPACE(1); \ + *b++ = (char)(ch); \ } /* Extend the buffer by twice its current size via reallociation and @@ -345,31 +344,32 @@ long re_syntax_options = DEFAULT_MBCTYPE; pending_exact = (pending_exact - old_buffer) + bufp->buffer; \ } + /* Set the bit for character C in a character set list. */ #define SET_LIST_BIT(c) \ - (b[(unsigned char) (c) / BYTEWIDTH] \ - |= 1 << ((unsigned char) (c) % BYTEWIDTH)) + (b[(unsigned char)(c) / BYTEWIDTH] \ + |= 1 << ((unsigned char)(c) % BYTEWIDTH)) /* Get the next unsigned number in the uncompiled pattern. */ #define GET_UNSIGNED_NUMBER(num) \ { if (p != pend) \ { \ - PATFETCH (c); \ - while (isdigit (c)) \ + PATFETCH(c); \ + while (isdigit(c)) \ { \ if (num < 0) \ num = 0; \ num = num * 10 + c - '0'; \ if (p == pend) \ break; \ - PATFETCH (c); \ + PATFETCH(c); \ } \ } \ } /* Subroutines for re_compile_pattern. */ -/* static void store_jump (), insert_jump (), store_jump_n (), - insert_jump_n (), insert_op_2 (); */ +/* static void store_jump(), insert_jump(), store_jump_n(), + insert_jump_n(), insert_op_2(); */ #define STORE_MBC(p, c) \ ((p)[0] = (unsigned char)(c >> 8), (p)[1] = (unsigned char)(c)) @@ -377,9 +377,9 @@ long re_syntax_options = DEFAULT_MBCTYPE; (*(p)++ = (unsigned char)(c >> 8), *(p)++ = (unsigned char)(c)) #define EXTRACT_MBC(p) \ - ((unsigned char)(p)[0] << 8 | (unsigned char)(p)[1]) + ((unsigned short)((unsigned char)(p)[0] << 8 | (unsigned char)(p)[1])) #define EXTRACT_MBC_AND_INCR(p) \ - ((p) += 2, (unsigned char)(p)[-2] << 8 | (unsigned char)(p)[-1]) + ((unsigned short)((p) += 2, (unsigned char)(p)[-2] << 8 | (unsigned char)(p)[-1])) #define EXTRACT_UNSIGNED(p) \ ((unsigned char)(p)[0] | (unsigned char)(p)[1] << 8) @@ -402,79 +402,79 @@ long re_syntax_options = DEFAULT_MBCTYPE; }; */ static void -set_list_bits (c1, c2, b) +set_list_bits(c1, c2, b) unsigned short c1, c2; unsigned char *b; { unsigned char sbc_size = b[-1]; - unsigned short mbc_size = EXTRACT_UNSIGNED (&b[sbc_size]); + unsigned short mbc_size = EXTRACT_UNSIGNED(&b[sbc_size]); unsigned short beg, end, upb; if (c1 > c2) return; - if (c1 < 1 << BYTEWIDTH) { + if ((int)c1 < 1 << BYTEWIDTH) { upb = c2; - if (1 << BYTEWIDTH <= upb) + if (1 << BYTEWIDTH <= (int)upb) upb = (1 << BYTEWIDTH) - 1; /* The last single-byte char */ - if (sbc_size <= upb / BYTEWIDTH) { + if (sbc_size <= (unsigned short)(upb / BYTEWIDTH)) { /* Allocate maximum size so it never happens again. */ /* NOTE: memcpy() would not work here. */ - memmove (&b[(1 << BYTEWIDTH) / BYTEWIDTH], &b[sbc_size], 2 + mbc_size*4); - memset (&b[sbc_size], 0, (1 << BYTEWIDTH) / BYTEWIDTH - sbc_size); + memmove(&b[(1 << BYTEWIDTH) / BYTEWIDTH], &b[sbc_size], 2 + mbc_size*4); + memset(&b[sbc_size], 0, (1 << BYTEWIDTH) / BYTEWIDTH - sbc_size); b[-1] = sbc_size = (1 << BYTEWIDTH) / BYTEWIDTH; } for (; c1 <= upb; c1++) - if (!ismbchar (c1)) - SET_LIST_BIT (c1); - if (c2 < 1 << BYTEWIDTH) + if (!ismbchar(c1)) + SET_LIST_BIT(c1); + if ((int)c2 < 1 << BYTEWIDTH) return; c1 = 0x8000; /* The first wide char */ } b = &b[sbc_size + 2]; for (beg = 0, upb = mbc_size; beg < upb; ) { - unsigned short mid = (beg + upb) >> 1; + unsigned short mid = (unsigned short)(beg + upb) >> 1; - if (c1 - 1 > EXTRACT_MBC (&b[mid*4 + 2])) + if ((int)c1 - 1 > (int)EXTRACT_MBC(&b[mid*4 + 2])) beg = mid + 1; else upb = mid; } for (end = beg, upb = mbc_size; end < upb; ) { - unsigned short mid = (end + upb) >> 1; + unsigned short mid = (unsigned short)(end + upb) >> 1; - if (c2 >= EXTRACT_MBC (&b[mid*4]) - 1) + if ((int)c2 >= (int)EXTRACT_MBC(&b[mid*4]) - 1) end = mid + 1; else upb = mid; } if (beg != end) { - if (c1 > EXTRACT_MBC (&b[beg*4])) - c1 = EXTRACT_MBC (&b[beg*4]); - if (c2 < EXTRACT_MBC (&b[(end - 1)*4])) - c2 = EXTRACT_MBC (&b[(end - 1)*4]); + if (c1 > EXTRACT_MBC(&b[beg*4])) + c1 = EXTRACT_MBC(&b[beg*4]); + if (c2 < EXTRACT_MBC(&b[(end - 1)*4])) + c2 = EXTRACT_MBC(&b[(end - 1)*4]); } if (end < mbc_size && end != beg + 1) /* NOTE: memcpy() would not work here. */ - memmove (&b[(beg + 1)*4], &b[end*4], (mbc_size - end)*4); - STORE_MBC (&b[beg*4 + 0], c1); - STORE_MBC (&b[beg*4 + 2], c2); + memmove(&b[(beg + 1)*4], &b[end*4], (mbc_size - end)*4); + STORE_MBC(&b[beg*4 + 0], c1); + STORE_MBC(&b[beg*4 + 2], c2); mbc_size += beg + 1 - end; - STORE_NUMBER (&b[-2], mbc_size); + STORE_NUMBER(&b[-2], mbc_size); } static int -is_in_list (c, b) +is_in_list(c, b) unsigned short c; const unsigned char *b; { unsigned short size; size = *b++; - if (c < 1 << BYTEWIDTH) { - if (c / BYTEWIDTH < size && b[c / BYTEWIDTH] & 1 << c % BYTEWIDTH) { + if ((int)c < 1 << BYTEWIDTH) { + if ((int)c / BYTEWIDTH < (int)size && b[c / BYTEWIDTH] & 1 << c % BYTEWIDTH) { return 1; } } @@ -482,18 +482,18 @@ is_in_list (c, b) unsigned short i, j; b += size + 2; - size = EXTRACT_UNSIGNED (&b[-2]); + size = EXTRACT_UNSIGNED(&b[-2]); for (i = 0, j = size; i < j; ) { - unsigned short k = (i + j) >> 1; + unsigned short k = (unsigned short)(i + j) >> 1; - if (c > EXTRACT_MBC (&b[k*4 + 2])) + if (c > EXTRACT_MBC(&b[k*4 + 2])) i = k + 1; else j = k; } - if (i < size && EXTRACT_MBC (&b[i*4]) <= c - && ((unsigned char) c != '\n' && (unsigned char) c != '\0')) + if (i < size && EXTRACT_MBC(&b[i*4]) <= c + && ((unsigned char)c != '\n' && (unsigned char)c != '\0')) return 1; } return 0; @@ -515,7 +515,7 @@ is_in_list (c, b) re_compile_pattern returns. */ char * -re_compile_pattern (pattern, size, bufp) +re_compile_pattern(pattern, size, bufp) char *pattern; size_t size; struct re_pattern_buffer *bufp; @@ -599,14 +599,14 @@ re_compile_pattern (pattern, size, bufp) bufp->buffer = (char *) xrealloc (bufp->buffer, INIT_BUF_SIZE); else /* Caller did not allocate a buffer. Do it for them. */ - bufp->buffer = (char *) xmalloc (INIT_BUF_SIZE); + bufp->buffer = (char *) xmalloc(INIT_BUF_SIZE); if (!bufp->buffer) goto memory_exhausted; begalt = b = bufp->buffer; } while (p != pend) { - PATFETCH (c); + PATFETCH(c); switch (c) { @@ -630,9 +630,9 @@ re_compile_pattern (pattern, size, bufp) goto normal_char; /* Make operand of last vbar end before this `$'. */ if (fixup_jump) - store_jump (fixup_jump, jump, b); + store_jump(fixup_jump, jump, b); fixup_jump = 0; - BUFPUSH (endline); + BUFPUSH(endline); break; } /* $ means succeed if at end of line, but only in special contexts. @@ -649,7 +649,7 @@ re_compile_pattern (pattern, size, bufp) ? *p1 == '|' : *p1 == '\\' && p1[1] == '|')) { - BUFPUSH (endline); + BUFPUSH(endline); break; } goto normal_char; @@ -668,11 +668,11 @@ re_compile_pattern (pattern, size, bufp) if (p != pattern + 1 && ! (re_syntax_options & RE_CONTEXT_INDEP_OPS)) goto normal_char; - BUFPUSH (begline); + BUFPUSH(begline); begalt = b; } else - BUFPUSH (begline); + BUFPUSH(begline); break; case '+': @@ -700,7 +700,7 @@ re_compile_pattern (pattern, size, bufp) many_times_ok |= c != '?'; if (p == pend) break; - PATFETCH (c); + PATFETCH(c); if (c == '*') ; else if (!(re_syntax_options & RE_BK_PLUS_QM) @@ -710,7 +710,7 @@ re_compile_pattern (pattern, size, bufp) && c == '\\') { /* int c1; */ - PATFETCH (c1); + PATFETCH(c1); if (!(c1 == '+' || c1 == '?')) { PATUNFETCH; @@ -739,14 +739,14 @@ re_compile_pattern (pattern, size, bufp) end a backward relative jump from b to before the next jump we're going to put in below (which jumps from laststart to after this jump). */ - GET_BUFFER_SPACE (3); - store_jump (b, maybe_finalize_jump, laststart - 3); + GET_BUFFER_SPACE(3); + store_jump(b, maybe_finalize_jump, laststart - 3); b += 3; /* Because store_jump put stuff here. */ } /* On failure, jump from laststart to b + 3, which will be the end of the buffer after this jump is inserted. */ - GET_BUFFER_SPACE (3); - insert_jump (on_failure_jump, laststart, b + 3, b); + GET_BUFFER_SPACE(3); + insert_jump(on_failure_jump, laststart, b + 3, b); pending_exact = 0; b += 3; if (!zero_times_ok) @@ -755,15 +755,15 @@ re_compile_pattern (pattern, size, bufp) dummy-failure before the initial on-failure-jump instruction of the loop. This effects a skip over that instruction the first time we hit that loop. */ - GET_BUFFER_SPACE (6); - insert_jump (dummy_failure_jump, laststart, laststart + 6, b); + GET_BUFFER_SPACE(6); + insert_jump(dummy_failure_jump, laststart, laststart + 6, b); b += 3; } break; case '.': laststart = b; - BUFPUSH (anychar); + BUFPUSH(anychar); break; case '[': @@ -776,19 +776,19 @@ re_compile_pattern (pattern, size, bufp) laststart = b; if (*p == '^') { - BUFPUSH (charset_not); + BUFPUSH(charset_not); p++; } else - BUFPUSH (charset); + BUFPUSH(charset); p0 = p; - BUFPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); + BUFPUSH((1 << BYTEWIDTH) / BYTEWIDTH); /* Clear the whole map */ - memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2); + memset(b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2); if ((re_syntax_options & RE_HAT_NOT_NEWLINE) && b[-2] == charset_not) - SET_LIST_BIT ('\n'); + SET_LIST_BIT('\n'); /* Read in characters and ranges, setting map bits. */ @@ -797,7 +797,7 @@ re_compile_pattern (pattern, size, bufp) int size; unsigned last = -1; - if ((size = EXTRACT_UNSIGNED (&b[(1 << BYTEWIDTH) / BYTEWIDTH]))) { + if ((size = EXTRACT_UNSIGNED(&b[(1 << BYTEWIDTH) / BYTEWIDTH]))) { /* Ensure the space is enough to hold another interval of multi-byte chars in charset(_not)?. */ size = (1 << BYTEWIDTH) / BYTEWIDTH + 2 + size*4 + 4; @@ -805,7 +805,7 @@ re_compile_pattern (pattern, size, bufp) EXTEND_BUFFER; } range_retry: - PATFETCH (c); + PATFETCH(c); if (c == ']') { if (p == p0 + 1) { @@ -820,8 +820,8 @@ re_compile_pattern (pattern, size, bufp) expression. */ break; } - if (ismbchar (c)) { - PATFETCH (c1); + if (ismbchar(c)) { + PATFETCH(c1); c = c << 8 | c1; } @@ -832,7 +832,7 @@ re_compile_pattern (pattern, size, bufp) case 'w': for (c = 0; c < 256; c++) if (isalnum(c)) - SET_LIST_BIT (c); + SET_LIST_BIT(c); last = -1; continue; @@ -841,14 +841,14 @@ re_compile_pattern (pattern, size, bufp) goto invalid_char; for (c = 0; c < 256; c++) if (!isalnum(c)) - SET_LIST_BIT (c); + SET_LIST_BIT(c); last = -1; continue; case 's': for (c = 0; c < 256; c++) if (isspace(c)) - SET_LIST_BIT (c); + SET_LIST_BIT(c); last = -1; continue; @@ -857,13 +857,13 @@ re_compile_pattern (pattern, size, bufp) goto invalid_char; for (c = 0; c < 256; c++) if (!isspace(c)) - SET_LIST_BIT (c); + SET_LIST_BIT(c); last = -1; continue; case 'd': for (c = '0'; c <= '9'; c++) - SET_LIST_BIT (c); + SET_LIST_BIT(c); last = -1; continue; @@ -871,9 +871,9 @@ re_compile_pattern (pattern, size, bufp) if (re_syntax_options & RE_MBCTYPE_MASK) goto invalid_char; for (c = 0; c < '0'; c++) - SET_LIST_BIT (c); + SET_LIST_BIT(c); for (c = '9' + 1; c < 256; c++) - SET_LIST_BIT (c); + SET_LIST_BIT(c); last = -1; continue; @@ -894,7 +894,7 @@ re_compile_pattern (pattern, size, bufp) break; default: - if (ismbchar (c)) { + if (ismbchar(c)) { PATFETCH(c1); c = c << 8 | c1; } @@ -914,10 +914,10 @@ re_compile_pattern (pattern, size, bufp) range = 0; if (last < 1 << BYTEWIDTH && c < 1 << BYTEWIDTH) { for (;last<=c;last++) - SET_LIST_BIT (last); + SET_LIST_BIT(last); } else - set_list_bits (last, c, (unsigned char*)b); + set_list_bits(last, c, (unsigned char*)b); } else if (p[0] == '-' && p[1] != ']') { last = c; @@ -926,9 +926,9 @@ re_compile_pattern (pattern, size, bufp) goto range_retry; } else if (c < 1 << BYTEWIDTH) - SET_LIST_BIT (c); + SET_LIST_BIT(c); else - set_list_bits (c, c, (unsigned char*)b); + set_list_bits(c, c, (unsigned char*)b); } /* Discard any character set/class bitmap bytes that are all @@ -936,8 +936,8 @@ re_compile_pattern (pattern, size, bufp) while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) b[-1]--; if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH) - memmove (&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH], - 2 + EXTRACT_UNSIGNED (&b[(1 << BYTEWIDTH) / BYTEWIDTH])*4); + memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH], + 2 + EXTRACT_UNSIGNED (&b[(1 << BYTEWIDTH) / BYTEWIDTH])*4); b += b[-1] + 2 + EXTRACT_UNSIGNED (&b[b[-1]])*4; break; @@ -989,8 +989,8 @@ re_compile_pattern (pattern, size, bufp) /* Laststart should point to the start_memory that we are about to push (unless the pattern has RE_NREGS or more ('s). */ *stackp++ = b - bufp->buffer; - BUFPUSH (start_memory); - BUFPUSH (regnum); + BUFPUSH(start_memory); + BUFPUSH(regnum); *stackp++ = fixup_jump ? fixup_jump - bufp->buffer + 1 : 0; *stackp++ = regnum++; *stackp++ = begalt - bufp->buffer; @@ -1006,9 +1006,9 @@ re_compile_pattern (pattern, size, bufp) if (stackp == stackb) goto unmatched_close; begalt = *--stackp + bufp->buffer; if (fixup_jump) - store_jump (fixup_jump, jump, b); - BUFPUSH (stop_memory); - BUFPUSH (stackp[-1]); + store_jump(fixup_jump, jump, b); + BUFPUSH(stop_memory); + BUFPUSH(stackp[-1]); stackp -= 2; fixup_jump = *stackp ? *stackp + bufp->buffer - 1 : 0; laststart = *--stackp + bufp->buffer; @@ -1023,8 +1023,8 @@ re_compile_pattern (pattern, size, bufp) goto normal_char; /* Insert before the previous alternative a jump which jumps to this alternative if the former fails. */ - GET_BUFFER_SPACE (6); - insert_jump (on_failure_jump, begalt, b + 6, b); + GET_BUFFER_SPACE(6); + insert_jump(on_failure_jump, begalt, b + 6, b); pending_exact = 0; b += 3; /* The alternative before the previous alternative has a @@ -1035,7 +1035,7 @@ re_compile_pattern (pattern, size, bufp) jump, etc.). The last such jump jumps to the correct final destination. */ if (fixup_jump) - store_jump (fixup_jump, jump, b); + store_jump(fixup_jump, jump, b); /* Leave space for a jump after previous alternative---to be filled in later. */ @@ -1088,10 +1088,10 @@ re_compile_pattern (pattern, size, bufp) } lower_bound = -1; /* So can see if are set. */ upper_bound = -1; - GET_UNSIGNED_NUMBER (lower_bound); + GET_UNSIGNED_NUMBER(lower_bound); if (c == ',') { - GET_UNSIGNED_NUMBER (upper_bound); + GET_UNSIGNED_NUMBER(upper_bound); if (upper_bound < 0) upper_bound = RE_DUP_MAX; } @@ -1101,7 +1101,7 @@ re_compile_pattern (pattern, size, bufp) { if (c != '\\') goto invalid_pattern; - PATFETCH (c); + PATFETCH(c); } if (c != '}' || lower_bound < 0 || upper_bound > RE_DUP_MAX || lower_bound > upper_bound @@ -1120,8 +1120,8 @@ re_compile_pattern (pattern, size, bufp) if (upper_bound == 0) { - GET_BUFFER_SPACE (3); - insert_jump (jump, laststart, b + 3, b); + GET_BUFFER_SPACE(3); + insert_jump(jump, laststart, b + 3, b); b += 3; } @@ -1137,13 +1137,13 @@ re_compile_pattern (pattern, size, bufp) unsigned slots_needed = upper_bound == 1 ? 5 : 10; - GET_BUFFER_SPACE (slots_needed); + GET_BUFFER_SPACE(slots_needed); /* Initialize the succeed_n to n, even though it will be set by its attendant set_number_at, because re_compile_fastmap will need to know it. Jump to what the end of buffer will be after inserting this succeed_n and possibly appending a jump_n. */ - insert_jump_n (succeed_n, laststart, b + slots_needed, + insert_jump_n(succeed_n, laststart, b + slots_needed, b, lower_bound); b += 5; /* Just increment for the succeed_n here. */ @@ -1155,18 +1155,18 @@ re_compile_pattern (pattern, size, bufp) if (upper_bound > 1) { - store_jump_n (b, jump_n, laststart, upper_bound - 1); + store_jump_n(b, jump_n, laststart, upper_bound - 1); b += 5; /* When hit this when matching, reset the preceding jump_n's n to upper_bound - 1. */ - BUFPUSH (set_number_at); - GET_BUFFER_SPACE (2); - STORE_NUMBER_AND_INCR (b, -5); - STORE_NUMBER_AND_INCR (b, upper_bound - 1); + BUFPUSH(set_number_at); + GET_BUFFER_SPACE(2); + STORE_NUMBER_AND_INCR(b, -5); + STORE_NUMBER_AND_INCR(b, upper_bound - 1); } /* When hit this when matching, set the succeed_n's n. */ - GET_BUFFER_SPACE (5); - insert_op_2 (set_number_at, laststart, b, 5, lower_bound); + GET_BUFFER_SPACE(5); + insert_op_2(set_number_at, laststart, b, 5, lower_bound); b += 5; } pending_exact = 0; @@ -1180,13 +1180,13 @@ re_compile_pattern (pattern, size, bufp) p = beg_interval; else { - fprintf (stderr, + fprintf(stderr, "regex: no interval beginning to which to backtrack.\n"); exit (1); } beg_interval = 0; - PATFETCH (c); /* normal_char expects char in `c'. */ + PATFETCH(c); /* normal_char expects char in `c'. */ goto normal_char; break; @@ -1200,53 +1200,53 @@ re_compile_pattern (pattern, size, bufp) laststart = b; if (c == 's' || c == 'd') { - BUFPUSH (charset); + BUFPUSH(charset); } else { - BUFPUSH (charset_not); + BUFPUSH(charset_not); } - BUFPUSH ((1 << BYTEWIDTH) / BYTEWIDTH); - memset (b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2); + BUFPUSH((1 << BYTEWIDTH) / BYTEWIDTH); + memset(b, 0, (1 << BYTEWIDTH) / BYTEWIDTH + 2); if (c == 's' || c == 'S') { - SET_LIST_BIT (' '); - SET_LIST_BIT ('\t'); - SET_LIST_BIT ('\n'); - SET_LIST_BIT ('\r'); - SET_LIST_BIT ('\f'); + SET_LIST_BIT(' '); + SET_LIST_BIT('\t'); + SET_LIST_BIT('\n'); + SET_LIST_BIT('\r'); + SET_LIST_BIT('\f'); } else { char cc; for (cc = '0'; cc <= '9'; cc++) { - SET_LIST_BIT (cc); + SET_LIST_BIT(cc); } } while ((int) b[-1] > 0 && b[b[-1] - 1] == 0) b[-1]--; if (b[-1] != (1 << BYTEWIDTH) / BYTEWIDTH) - memmove (&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH], + memmove(&b[b[-1]], &b[(1 << BYTEWIDTH) / BYTEWIDTH], 2 + EXTRACT_UNSIGNED (&b[(1 << BYTEWIDTH) / BYTEWIDTH])*4); - b += b[-1] + 2 + EXTRACT_UNSIGNED (&b[b[-1]])*4; + b += b[-1] + 2 + EXTRACT_UNSIGNED(&b[b[-1]])*4; break; case 'w': laststart = b; - BUFPUSH (wordchar); + BUFPUSH(wordchar); break; case 'W': laststart = b; - BUFPUSH (notwordchar); + BUFPUSH(notwordchar); break; case 'b': - BUFPUSH (wordbound); + BUFPUSH(wordbound); break; case 'B': - BUFPUSH (notwordbound); + BUFPUSH(notwordbound); break; /* hex */ @@ -1298,8 +1298,8 @@ re_compile_pattern (pattern, size, bufp) if (*stackt == c1) goto normal_char; laststart = b; - BUFPUSH (duplicate); - BUFPUSH (c1); + BUFPUSH(duplicate); + BUFPUSH(c1); break; case '+': @@ -1319,7 +1319,7 @@ re_compile_pattern (pattern, size, bufp) default: normal_char: /* Expects the character in `c'. */ c1 = 0; - if (ismbchar (c)) { + if (ismbchar(c)) { c1 = c; PATFETCH(c); } @@ -1336,21 +1336,21 @@ re_compile_pattern (pattern, size, bufp) : (p[0] == '\\' && p[1] == '{')))) { laststart = b; - BUFPUSH (exactn); + BUFPUSH(exactn); pending_exact = b; - BUFPUSH (0); + BUFPUSH(0); } if (c1) { - BUFPUSH (c1); + BUFPUSH(c1); (*pending_exact)++; } - BUFPUSH (c); + BUFPUSH(c); (*pending_exact)++; } } if (fixup_jump) - store_jump (fixup_jump, jump, b); + store_jump(fixup_jump, jump, b); if (stackp != stackb) goto unmatched_open; @@ -1389,7 +1389,7 @@ re_compile_pattern (pattern, size, bufp) address FROM - TO. OPCODE is the opcode to store. */ static void -store_jump (from, opcode, to) +store_jump(from, opcode, to) char *from, *to; int opcode; { @@ -1405,7 +1405,7 @@ store_jump (from, opcode, to) If you call this function, you must zero out pending_exact. */ static void -insert_jump (op, from, to, current_end) +insert_jump(op, from, to, current_end) int op; char *from, *to, *current_end; { @@ -1414,7 +1414,7 @@ insert_jump (op, from, to, current_end) while (pfrom != from) *--pto = *--pfrom; - store_jump (from, op, to); + store_jump(from, op, to); } @@ -1427,14 +1427,14 @@ insert_jump (op, from, to, current_end) If you call this function, you must zero out pending_exact. */ static void -store_jump_n (from, opcode, to, n) +store_jump_n(from, opcode, to, n) char *from, *to; int opcode; unsigned n; { from[0] = (char)opcode; - STORE_NUMBER (from + 1, to - (from + 3)); - STORE_NUMBER (from + 3, n); + STORE_NUMBER(from + 1, to - (from + 3)); + STORE_NUMBER(from + 3, n); } @@ -1447,7 +1447,7 @@ store_jump_n (from, opcode, to, n) If you call this function, you must zero out pending_exact. */ static void -insert_jump_n (op, from, to, current_end, n) +insert_jump_n(op, from, to, current_end, n) int op; char *from, *to, *current_end; unsigned n; @@ -1457,7 +1457,7 @@ insert_jump_n (op, from, to, current_end, n) while (pfrom != from) *--pto = *--pfrom; - store_jump_n (from, op, to, n); + store_jump_n(from, op, to, n); } @@ -1468,7 +1468,7 @@ insert_jump_n (op, from, to, current_end, n) If you call this function, you must zero out pending_exact. */ static void -insert_op_2 (op, there, current_end, num_1, num_2) +insert_op_2(op, there, current_end, num_1, num_2) int op; char *there, *current_end; int num_1, num_2; @@ -1480,8 +1480,8 @@ insert_op_2 (op, there, current_end, num_1, num_2) *--pto = *--pfrom; there[0] = (char)op; - STORE_NUMBER (there + 1, num_1); - STORE_NUMBER (there + 3, num_2); + STORE_NUMBER(there + 1, num_1); + STORE_NUMBER(there + 3, num_2); } @@ -1496,7 +1496,7 @@ insert_op_2 (op, there, current_end, num_1, num_2) The other components of bufp describe the pattern to be used. */ void -re_compile_fastmap (bufp) +re_compile_fastmap(bufp) struct re_pattern_buffer *bufp; { unsigned char *pattern = (unsigned char *) bufp->buffer; @@ -1513,7 +1513,7 @@ re_compile_fastmap (bufp) stackb = RE_TALLOC(NFAILURES, unsigned char*); stackp = stackb; - memset (fastmap, 0, (1 << BYTEWIDTH)); + memset(fastmap, 0, (1 << BYTEWIDTH)); bufp->fastmap_accurate = 1; bufp->can_be_null = 0; @@ -1526,9 +1526,9 @@ re_compile_fastmap (bufp) break; } #ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) + switch ((int) ((enum regexpcode)*p++)) #else - switch ((enum regexpcode) *p++) + switch ((enum regexpcode)*p++) #endif { case exactn: @@ -1558,7 +1558,7 @@ re_compile_fastmap (bufp) case maybe_finalize_jump: case jump: case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); + EXTRACT_NUMBER_AND_INCR(j, p); p += j; if (j > 0) continue; @@ -1573,7 +1573,7 @@ re_compile_fastmap (bufp) && (enum regexpcode) *p != succeed_n) continue; p++; - EXTRACT_NUMBER_AND_INCR (j, p); + EXTRACT_NUMBER_AND_INCR(j, p); p += j; if (stackp != stackb && *stackp == p) stackp--; @@ -1581,10 +1581,10 @@ re_compile_fastmap (bufp) case on_failure_jump: handle_on_failure_jump: - EXTRACT_NUMBER_AND_INCR (j, p); + EXTRACT_NUMBER_AND_INCR(j, p); *++stackp = p + j; if (is_a_succeed_n) - EXTRACT_NUMBER_AND_INCR (k, p); /* Skip the n. */ + EXTRACT_NUMBER_AND_INCR(k, p); /* Skip the n. */ continue; case succeed_n: @@ -1592,7 +1592,7 @@ re_compile_fastmap (bufp) /* Get to the number of times to succeed. */ p += 2; /* Increment p past the n for when k != 0. */ - EXTRACT_NUMBER_AND_INCR (k, p); + EXTRACT_NUMBER_AND_INCR(k, p); if (k == 0) { p -= 4; @@ -1626,13 +1626,13 @@ re_compile_fastmap (bufp) case wordchar: for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) == Sword) + if (SYNTAX(j) == Sword) fastmap[j] = 1; break; case notwordchar: for (j = 0; j < (1 << BYTEWIDTH); j++) - if (SYNTAX (j) != Sword) + if (SYNTAX(j) != Sword) fastmap[j] = 1; break; @@ -1652,15 +1652,15 @@ re_compile_fastmap (bufp) unsigned char c, end; p += p[-1] + 2; - size = EXTRACT_UNSIGNED (&p[-2]); - for (j = 0; j < size; j++) + size = EXTRACT_UNSIGNED(&p[-2]); + for (j = 0; j < (int)size; j++) /* set bits for 1st bytes of multi-byte chars. */ - for (c = (unsigned char) p[j*4], - end = (unsigned char) p[j*4 + 2]; + for (c = (unsigned char)p[j*4], + end = (unsigned char)p[j*4 + 2]; c <= end; c++) /* NOTE: Charset for multi-byte chars might contain single-byte chars. We must reject them. */ - if (ismbchar (c)) + if (ismbchar(c)) fastmap[c] = 1; } break; @@ -1678,13 +1678,13 @@ re_compile_fastmap (bufp) /* NOTE: Charset_not for single-byte chars might contain multi-byte chars. See set_list_bits(). */ for (j = *p * BYTEWIDTH; j < (1 << BYTEWIDTH); j++) - if (!ismbchar (j)) + if (!ismbchar(j)) fastmap[j] = 1; for (j = *p++ * BYTEWIDTH - 1; j >= 0; j--) if (!(p[j / BYTEWIDTH] & (1 << (j % BYTEWIDTH)))) { - if (!ismbchar (j)) + if (!ismbchar(j)) fastmap[j] = 1; } { @@ -1692,13 +1692,13 @@ re_compile_fastmap (bufp) unsigned char c, beg; p += p[-1] + 2; - size = EXTRACT_UNSIGNED (&p[-2]); + size = EXTRACT_UNSIGNED(&p[-2]); c = 0x80; - for (j = 0; j < size; j++) { - for (beg = (unsigned char) p[j*4 + 0]; c < beg; c++) - if (ismbchar (c)) + for (j = 0; j < (int)size; j++) { + for (beg = (unsigned char)p[j*4 + 0]; c < beg; c++) + if (ismbchar(c)) fastmap[c] = 1; - c = (unsigned char) p[j*4 + 2] + 1; + c = (unsigned char)p[j*4 + 2] + 1; } } break; @@ -1735,7 +1735,7 @@ re_compile_fastmap (bufp) failure stack overflow). */ int -re_search (pbufp, string, size, startpos, range, regs) +re_search(pbufp, string, size, startpos, range, regs) struct re_pattern_buffer *pbufp; char *string; int size, startpos, range; @@ -1776,7 +1776,7 @@ re_search (pbufp, string, size, startpos, range, regs) while (range > lim) { c = *p++; - if (ismbchar (c)) { + if (ismbchar(c)) { if (fastmap[c]) break; p++; @@ -1804,7 +1804,7 @@ re_search (pbufp, string, size, startpos, range, regs) && fastmap && pbufp->can_be_null == 0) return -1; - val = re_match (pbufp, string, size, startpos, regs); + val = re_match(pbufp, string, size, startpos, regs); if (val >= 0) return startpos; if (val == -2) @@ -1812,7 +1812,7 @@ re_search (pbufp, string, size, startpos, range, regs) #ifndef NO_ALLOCA #ifdef C_ALLOCA - alloca (0); + alloca(0); #endif /* C_ALLOCA */ #endif /* NO_ALLOCA */ @@ -1822,7 +1822,7 @@ re_search (pbufp, string, size, startpos, range, regs) else if (range > 0) { const char *d = string + startpos; - if (ismbchar (*d)) { + if (ismbchar(*d)) { range--, startpos++; if (!range) break; @@ -1861,7 +1861,7 @@ re_search (pbufp, string, size, startpos, range, regs) int re_max_failures = 2000; /* Routine used by re_match. */ -/* static int memcmp_translate (); *//* already declared */ +/* static int memcmp_translate(); *//* already declared */ /* Structure and accessing macros used in re_match: */ @@ -1930,11 +1930,11 @@ struct register_info { \ *stackp++ = regstart[this_reg]; \ *stackp++ = regend[this_reg]; \ - *stackp++ = (unsigned char *) ®_info[this_reg]; \ + *stackp++ = (unsigned char *)®_info[this_reg]; \ } \ \ /* Push how many registers we saved. */ \ - *stackp++ = (unsigned char *) last_used_reg; \ + *stackp++ = (unsigned char *)last_used_reg; \ \ *stackp++ = pattern_place; \ *stackp++ = string_place; \ @@ -1984,7 +1984,7 @@ struct register_info 2) if we're before the beginning of string2, we have to look at the last character in string1; we assume there is a string1, so use this in conjunction with AT_STRINGS_BEG. */ -#define IS_A_LETTER(d) (SYNTAX (*(d)) == Sword) +#define IS_A_LETTER(d) (SYNTAX(*(d)) == Sword) static void init_regs(regs, num_regs) @@ -2027,7 +2027,7 @@ init_regs(regs, num_regs) length of the substring which was matched. */ int -re_match (pbufp, string_arg, size, pos, regs) +re_match(pbufp, string_arg, size, pos, regs) struct re_pattern_buffer *pbufp; char *string_arg; int size, pos; @@ -2111,8 +2111,8 @@ re_match (pbufp, string_arg, size, pos, regs) failed. */ for (mcnt = 0; mcnt < num_regs; mcnt++) { regstart[mcnt] = regend[mcnt] = (unsigned char *) (-1L); - IS_ACTIVE (reg_info[mcnt]) = 0; - MATCHED_SOMETHING (reg_info[mcnt]) = 0; + IS_ACTIVE(reg_info[mcnt]) = 0; + MATCHED_SOMETHING(reg_info[mcnt]) = 0; } /* Set up pointers to ends of strings. @@ -2136,10 +2136,10 @@ re_match (pbufp, string_arg, size, pos, regs) while (1) { #ifdef DEBUG_REGEX - fprintf (stderr, - "regex loop(%d): matching 0x%02d\n", - p - (unsigned char *) pbufp->buffer, - *p); + fprintf(stderr, + "regex loop(%d): matching 0x%02d\n", + p - (unsigned char *) pbufp->buffer, + *p); #endif is_a_jump_n = 0; /* End of pattern means we might have succeeded. */ @@ -2205,9 +2205,9 @@ re_match (pbufp, string_arg, size, pos, regs) /* Otherwise match next pattern command. */ #ifdef SWITCH_ENUM_BUG - switch ((int) ((enum regexpcode) *p++)) + switch ((int)((enum regexpcode)*p++)) #else - switch ((enum regexpcode) *p++) + switch ((enum regexpcode)*p++) #endif { @@ -2217,18 +2217,18 @@ re_match (pbufp, string_arg, size, pos, regs) within the \( and \) is recorded under that number. */ case start_memory: regstart[*p] = d; - IS_ACTIVE (reg_info[*p]) = 1; - MATCHED_SOMETHING (reg_info[*p]) = 0; + IS_ACTIVE(reg_info[*p]) = 1; + MATCHED_SOMETHING(reg_info[*p]) = 0; p++; break; case stop_memory: regend[*p] = d; - IS_ACTIVE (reg_info[*p]) = 0; + IS_ACTIVE(reg_info[*p]) = 0; /* If just failed to match something this time around with a sub- expression that's in a loop, try to force exit from the loop. */ - if ((! MATCHED_SOMETHING (reg_info[*p]) + if ((! MATCHED_SOMETHING(reg_info[*p]) || (enum regexpcode) p[-3] == start_memory) && (p + 1) != pend) { @@ -2242,7 +2242,7 @@ re_match (pbufp, string_arg, size, pos, regs) case maybe_finalize_jump: case jump: case dummy_failure_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p2); + EXTRACT_NUMBER_AND_INCR(mcnt, p2); if (is_a_jump_n) p2 += 2; break; @@ -2255,8 +2255,8 @@ re_match (pbufp, string_arg, size, pos, regs) jump in the pattern, and d. */ if (mcnt < 0 && (enum regexpcode) *p2++ == on_failure_jump) { - EXTRACT_NUMBER_AND_INCR (mcnt, p2); - PUSH_FAILURE_POINT (p2 + mcnt, d); + EXTRACT_NUMBER_AND_INCR(mcnt, p2); + PUSH_FAILURE_POINT(p2 + mcnt, d); goto fail; } } @@ -2298,8 +2298,8 @@ re_match (pbufp, string_arg, size, pos, regs) /* Compare that many; failure if mismatch, else move past them. */ if (translate - ? memcmp_translate (d, d2, mcnt, translate) - : memcmp ((char *)d, (char *)d2, mcnt)) + ? memcmp_translate(d, d2, mcnt, translate) + : memcmp((char *)d, (char *)d2, mcnt)) goto fail; d += mcnt, d2 += mcnt; } @@ -2309,7 +2309,7 @@ re_match (pbufp, string_arg, size, pos, regs) case anychar: PREFETCH; /* Match anything but a newline, maybe even a null. */ - if (ismbchar (*d)) { + if (ismbchar(*d)) { if (d + 1 == dend || d[1] == '\n' || d[1] == '\0') goto fail; SET_REGS_MATCHED; @@ -2331,20 +2331,20 @@ re_match (pbufp, string_arg, size, pos, regs) int c; PREFETCH; - c = (unsigned char) *d; - if (ismbchar (c)) { + c = (unsigned char)*d; + if (ismbchar(c)) { c <<= 8; if (d + 1 != dend) - c |= (unsigned char) d[1]; + c |= (unsigned char)d[1]; } else if (translate) - c = (unsigned char) translate[c]; + c = (unsigned char)translate[c]; - not = is_in_list (c, p); - if (*(p - 1) == (unsigned char) charset_not) + not = is_in_list(c, p); + if (*(p - 1) == (unsigned char)charset_not) not = !not; - p += 1 + *p + 2 + EXTRACT_UNSIGNED (&p[1 + *p])*4; + p += 1 + *p + 2 + EXTRACT_UNSIGNED(&p[1 + *p])*4; if (!not) goto fail; SET_REGS_MATCHED; @@ -2386,53 +2386,53 @@ re_match (pbufp, string_arg, size, pos, regs) case on_failure_jump: on_failure: - EXTRACT_NUMBER_AND_INCR (mcnt, p); - PUSH_FAILURE_POINT (p + mcnt, d); + EXTRACT_NUMBER_AND_INCR(mcnt, p); + PUSH_FAILURE_POINT(p + mcnt, d); break; /* The end of a smart repeat has a maybe_finalize_jump back. Change it either to a finalize_jump or an ordinary jump. */ case maybe_finalize_jump: - EXTRACT_NUMBER_AND_INCR (mcnt, p); + EXTRACT_NUMBER_AND_INCR(mcnt, p); { register unsigned char *p2 = p; /* Compare what follows with the beginning of the repeat. If we can establish that there is nothing that they would both match, we can change to finalize_jump. */ while (p2 + 1 != pend - && (*p2 == (unsigned char) stop_memory - || *p2 == (unsigned char) start_memory)) + && (*p2 == (unsigned char)stop_memory + || *p2 == (unsigned char)start_memory)) p2 += 2; /* Skip over reg number. */ if (p2 == pend) - p[-3] = (unsigned char) finalize_jump; - else if (*p2 == (unsigned char) exactn - || *p2 == (unsigned char) endline) + p[-3] = (unsigned char)finalize_jump; + else if (*p2 == (unsigned char)exactn + || *p2 == (unsigned char)endline) { - register int c = *p2 == (unsigned char) endline ? '\n' : p2[2]; + register int c = *p2 == (unsigned char)endline ? '\n' : p2[2]; register unsigned char *p1 = p + mcnt; /* p1[0] ... p1[2] are an on_failure_jump. Examine what follows that. */ - if (p1[3] == (unsigned char) exactn && p1[5] != c) - p[-3] = (unsigned char) finalize_jump; - else if (p1[3] == (unsigned char) charset - || p1[3] == (unsigned char) charset_not) { + if (p1[3] == (unsigned char)exactn && p1[5] != c) + p[-3] = (unsigned char)finalize_jump; + else if (p1[3] == (unsigned char)charset + || p1[3] == (unsigned char)charset_not) { int not; - if (ismbchar (c)) + if (ismbchar(c)) c = c << 8 | p2[3]; /* `is_in_list()' is TRUE if c would match */ /* That means it is not safe to finalize. */ - not = is_in_list (c, p1 + 4); - if (p1[3] == (unsigned char) charset_not) + not = is_in_list(c, p1 + 4); + if (p1[3] == (unsigned char)charset_not) not = !not; if (!not) - p[-3] = (unsigned char) finalize_jump; + p[-3] = (unsigned char)finalize_jump; } } } p -= 2; /* Point at relative address again. */ - if (p[-1] != (unsigned char) finalize_jump) + if (p[-1] != (unsigned char)finalize_jump) { - p[-1] = (unsigned char) jump; + p[-1] = (unsigned char)jump; goto nofinalize; } /* Note fall through. */ @@ -2445,13 +2445,13 @@ re_match (pbufp, string_arg, size, pos, regs) because didn't fail. Also remove the register information put on by the on_failure_jump. */ case finalize_jump: - POP_FAILURE_POINT (); + POP_FAILURE_POINT(); /* Note fall through. */ /* Jump without taking off any failure points. */ case jump: nofinalize: - EXTRACT_NUMBER_AND_INCR (mcnt, p); + EXTRACT_NUMBER_AND_INCR(mcnt, p); p += mcnt; break; @@ -2461,20 +2461,20 @@ re_match (pbufp, string_arg, size, pos, regs) finalize_jump, also, and with a pattern of, say, `a+', we are skipping over the on_failure_jump, so we have to push something meaningless for finalize_jump to pop. */ - PUSH_FAILURE_POINT (0, 0); + PUSH_FAILURE_POINT(0, 0); goto nofinalize; /* Have to succeed matching what follows at least n times. Then just handle like an on_failure_jump. */ case succeed_n: - EXTRACT_NUMBER (mcnt, p + 2); + EXTRACT_NUMBER(mcnt, p + 2); /* Originally, this is how many times we HAVE to succeed. */ if (mcnt) { mcnt--; p += 2; - STORE_NUMBER_AND_INCR (p, mcnt); + STORE_NUMBER_AND_INCR(p, mcnt); } else if (mcnt == 0) { @@ -2484,13 +2484,13 @@ re_match (pbufp, string_arg, size, pos, regs) } else { - fprintf (stderr, "regex: the succeed_n's n is not set.\n"); - exit (1); + fprintf(stderr, "regex: the succeed_n's n is not set.\n"); + exit(1); } break; case jump_n: - EXTRACT_NUMBER (mcnt, p + 2); + EXTRACT_NUMBER(mcnt, p + 2); /* Originally, this is how many times we CAN jump. */ if (mcnt) { @@ -2508,10 +2508,10 @@ re_match (pbufp, string_arg, size, pos, regs) { register unsigned char *p1; - EXTRACT_NUMBER_AND_INCR (mcnt, p); + EXTRACT_NUMBER_AND_INCR(mcnt, p); p1 = p + mcnt; - EXTRACT_NUMBER_AND_INCR (mcnt, p); - STORE_NUMBER (p1, mcnt); + EXTRACT_NUMBER_AND_INCR(mcnt, p); + STORE_NUMBER(p1, mcnt); break; } @@ -2532,7 +2532,7 @@ re_match (pbufp, string_arg, size, pos, regs) case wordchar: PREFETCH; - if (!IS_A_LETTER (d)) + if (!IS_A_LETTER(d)) goto fail; d++; SET_REGS_MATCHED; @@ -2540,7 +2540,7 @@ re_match (pbufp, string_arg, size, pos, regs) case notwordchar: PREFETCH; - if (IS_A_LETTER (d)) + if (IS_A_LETTER(d)) goto fail; d++; SET_REGS_MATCHED; @@ -2560,19 +2560,19 @@ re_match (pbufp, string_arg, size, pos, regs) PREFETCH; c = *d++; - if (ismbchar (c)) { - if (c != (unsigned char) *p++ + if (ismbchar(c)) { + if (c != (unsigned char)*p++ || !--mcnt /* �ѥ���������������ѥ��뤵 ��Ƥ���¤�, ���Υ����å��� ��Ĺ����ǰ�Τ���. */ || d == dend - || (unsigned char) *d++ != (unsigned char) *p++) + || (unsigned char)*d++ != (unsigned char)*p++) goto fail; continue; } /* compiled code translation needed for ruby */ - if ((unsigned char) translate[c] - != (unsigned char) translate[*p++]) + if ((unsigned char)translate[c] + != (unsigned char)translate[*p++]) goto fail; } while (--mcnt); @@ -2602,7 +2602,7 @@ re_match (pbufp, string_arg, size, pos, regs) skip it. */ if (!stackp[-2]) { - POP_FAILURE_POINT (); + POP_FAILURE_POINT(); goto fail; } @@ -2614,10 +2614,10 @@ re_match (pbufp, string_arg, size, pos, regs) /* Make the ones that weren't saved -1 or 0 again. */ for (this_reg = num_regs - 1; this_reg > last_used_reg; this_reg--) { - regend[this_reg] = (unsigned char *) (-1L); - regstart[this_reg] = (unsigned char *) (-1L); - IS_ACTIVE (reg_info[this_reg]) = 0; - MATCHED_SOMETHING (reg_info[this_reg]) = 0; + regend[this_reg] = (unsigned char *)(-1L); + regstart[this_reg] = (unsigned char *)(-1L); + IS_ACTIVE(reg_info[this_reg]) = 0; + MATCHED_SOMETHING(reg_info[this_reg]) = 0; } /* And restore the rest from the stack. */ @@ -2640,7 +2640,7 @@ re_match (pbufp, string_arg, size, pos, regs) static int -memcmp_translate (s1, s2, len, translate) +memcmp_translate(s1, s2, len, translate) unsigned char *s1, *s2; register int len; unsigned char *translate; @@ -2649,7 +2649,7 @@ memcmp_translate (s1, s2, len, translate) while (len) { c = *p1++; - if (ismbchar (c)) { + if (ismbchar(c)) { if (c != *p2++ || !--len || *p1++ != *p2++) return 1; } @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:51 $ created at: Tue Aug 10 12:47:31 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -16,7 +16,6 @@ #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> -#include <signal.h> #include "dln.h" #ifdef HAVE_STRING_H @@ -446,7 +445,7 @@ ruby_script(name) } void -ruby_init0(argc, argv, envp) +ruby_options(argc, argv, envp) int argc; char **argv, **envp; { @@ -6,7 +6,7 @@ $Date: 1995/01/12 08:54:52 $ created at: Thu Jun 10 14:26:32 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto *************************************************/ @@ -16,11 +16,14 @@ #include "config.h" #include "defines.h" -#ifdef __STDC__ -#else +#ifndef __STDC__ #define volatile +#ifdef __GNUC__ +#define const __const__ +#else #define const #endif +#endif #if defined(HAVE_ALLOCA_H) && !defined(__GNUC__) #include <alloca.h> diff --git a/sample/blk.rb b/sample/blk.rb index 12d1038fd0..e11cc026ea 100644 --- a/sample/blk.rb +++ b/sample/blk.rb @@ -2,8 +2,8 @@ def foo() $block = Block.new end -foo(){i| print "i = ", i, "\n"} +foo(){|i| print "i = ", i, "\n"} $block.call(2) -foo(){i| print "i*2 = ", i*2, "\n"} +foo(){|i| print "i*2 = ", i*2, "\n"} $block.call(2) diff --git a/sample/from.rb b/sample/from.rb index df82d5a745..f21b1d10f5 100755 --- a/sample/from.rb +++ b/sample/from.rb @@ -1,7 +1,5 @@ #! /usr/local/bin/ruby -$= = TRUE - module ParseDate MONTHS = { 'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, @@ -10,7 +8,7 @@ module ParseDate MONTHPAT = MONTHS.keys.join('|') DAYPAT = 'mon|tue|wed|thu|fri|sat|sun' - def ParseDate.parsedate(date) + def parsedate(date) if date.sub(/(#{DAYPAT})/i, ' ') dayofweek = $1 end @@ -20,13 +18,13 @@ module ParseDate if date =~ /19(\d\d)/ year = $1 end - if date.sub(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/, ' ') + if date.sub(/\s*(\d+)\s+(#{MONTHPAT})\S*\s+/i, ' ') dayofmonth = $1 monthname = $2 - elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/, ' ') + elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\s+/i, ' ') monthname = $1 dayofmonth = $2 - elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/, ' ') + elsif date.sub(/\s*(#{MONTHPAT})\S*\s+(\d+)\D+/i, ' ') monthname = $1 dayofmonth = $2 elsif date.sub(/\s*(\d\d?)\/(\d\d?)/, ' ') @@ -44,52 +42,130 @@ module ParseDate end - def parsedate(date) - ParseDate.parsedate(date) +include ParseDate + +def decode64(str) + e = -1; + c = "," + for line in str.split("\n") + line.tr 'A-Za-z0-9+/', "\000-\377" + line.each_byte { |ch| + e+=1 + if e==0 + c = ch << 2 + elsif e==1 + c |= ch >>4 + string += [c].pack('c') + c = ch << 4 + elsif e == 2 + c |= ch >> 2 + string += [c].pack('c'); + c = ch << 6 + elsif e==3 + c |= ch + string += [c].pack('c') + e = -1; + end + } + end + return string; +end + +def j2e(str) + while str =~ /\033\$B([^\033]*)\033\(B/ + s = $1 + pre, post = $`, $' + s.gsub(/./) { |ch| + (ch[0]|0x80).chr + } + str = pre + s + post end + str +end -# include ParseDate +def decode_b(str) + while str =~ /=\?ISO-2022-JP\?B\?(.*)=\?=/ + pre, post = $`, $' + s = decode64($1) + str = pre + s + post + end + j2e(str) +end if $ARGV[0] == '-w' wait = TRUE $ARGV.shift end +class Mail + + def Mail.new(f) + if !f.is_kind_of(IO) + f = open(f, "r") + me = super + f.close + else + me = super + end + return me + end + + def initialize(f) + @header = {} + @body = [] + while f.gets() + $_.chop + continue if /^From / # skip From-line + break if /^[ \t]*$/ # end of header + if /^(\S+):\s*(.*)/ + @header[attr = $1.capitalize] = $2 + elsif attr + sub(/^\s*/, '') + @header[attr] += "\n" + $_ + end + end + + return if ! $_ + + while f.gets() + break if /^From / + @body.push($_) + end + end + + def header + return @header + end + + def body + return @body + end + +end + $ARGV[0] = '/usr/spool/mail/' + ENV['USER'] if $ARGV.length == 0 $outcount = 0; def fromout(date, from, subj) + return if !date y = m = d = 0 y, m, d = parsedate(date) if date from = "sombody@somewhere" if ! from subj = "(nil)" if ! subj - printf "%-2d/%02d/%02d [%-28.28s] %-40.40s\n", y, m, d, from, subj + from = decode_b(from) + subj = decode_b(subj) + printf "%-02d/%02d/%02d [%-28.28s] %-40.40s\n", y, m, d, from, subj $outcount += 1 end - -while TRUE - fields = {} - while gets() - $_.chop - continue if /^From / # skip From-line - break if /^[ \t]*$/ # end of header - if /^(\S+):\s*(.*)/ - fields[attr = $1] = $2 - elsif attr - sub(/^\s*/, '') - fields[attr] += "\n" + $_ - end - end - break if ! $_ - - fromout fields['Date'], fields['From'], fields['Subject'] - - while gets() - break if /^From / +for file in $ARGV + continue if !File.exists(file) + f = open(file, "r") + while !f.eof + mail = Mail.new(f) + fromout mail.header['Date'], mail.header['From'], mail.header['Subject'] end - - break if ! $_ + f.close end if $outcount == 0 diff --git a/sample/list.rb b/sample/list.rb index fa145f4627..93e3182f84 100644 --- a/sample/list.rb +++ b/sample/list.rb @@ -1,7 +1,7 @@ # Linked list example class MyElem # ���֥��������������˼�ưŪ�˸ƤФ���å� - def init_object(item) + def initialize(item) # @�ѿ��ϥ������ѿ�(������פ�ʤ�) @data = item @next = nil @@ -54,7 +54,7 @@ class MyList end class Point - def init_object(x, y) + def initialize(x, y) @x = x; @y = y self end diff --git a/sample/list2.rb b/sample/list2.rb index 1c2ca08150..914cb8996e 100644 --- a/sample/list2.rb +++ b/sample/list2.rb @@ -1,6 +1,6 @@ # Linked list example -- short version class Point - def init_object(x, y) + def initialize(x, y) @x = x; @y = y self end diff --git a/sample/list3.rb b/sample/list3.rb index 6bedc6ced9..2c1beb6fa2 100644 --- a/sample/list3.rb +++ b/sample/list3.rb @@ -2,7 +2,7 @@ # using _inspect class Point - def init_object(x, y) + def initialize(x, y) @x = x; @y = y self end diff --git a/sample/ruby-mode.el b/sample/ruby-mode.el index fd44dc661b..bcbbdc35f3 100644 --- a/sample/ruby-mode.el +++ b/sample/ruby-mode.el @@ -18,7 +18,7 @@ (defconst ruby-block-end-re "end") (defconst ruby-delimiter - (concat "[$/(){}#\"'`]\\|\\[\\|\\]\\|\\b\\(" + (concat "[$/<(){}#\"'`]\\|\\[\\|\\]\\|\\b\\(" ruby-block-beg-re "\\|" ruby-block-end-re "\\)\\b") ) @@ -37,10 +37,11 @@ (if ruby-mode-map nil (setq ruby-mode-map (make-sparse-keymap)) + (define-key ruby-mode-map "{" 'ruby-electric-brace) + (define-key ruby-mode-map "}" 'ruby-electric-brace) (define-key ruby-mode-map "\e\C-a" 'ruby-beginning-of-defun) (define-key ruby-mode-map "\e\C-e" 'ruby-end-of-defun) (define-key ruby-mode-map "\t" 'ruby-indent-command) - (define-key ruby-mode-map "\t" 'ruby-indent-command) (define-key ruby-mode-map "\C-m" 'ruby-reindent-then-newline-and-indent) (define-key ruby-mode-map "\C-j" 'newline)) @@ -178,7 +179,9 @@ The variable ruby-indent-level controls the amount of indentation. (t (goto-char indent-point) (setq in-string t)))) - ((string= "/" w) + ((or (string= "/" w) + (string= "<" w)) + (if (string= "<" w) (setq w ">")) (let (c) (save-excursion (goto-char pnt) @@ -261,120 +264,6 @@ The variable ruby-indent-level controls the amount of indentation. (error (format "bad string %s" w))))))) (list in-string in-paren (car nest) depth))) -(defun ruby-parse-region (start end) - (let ((indent-point end) - (indent 0) - (in-string nil) - (in-paren nil) - (depth 0) - (nest nil)) - (save-excursion - (if start - (goto-char start) - (ruby-beginning-of-defun)) - (while (and (> indent-point (point)) - (re-search-forward ruby-delimiter indent-point t)) - (let ((w (buffer-substring (match-beginning 0) (match-end 0))) - (pnt (match-beginning 0))) - (cond - ((or (string= "\"" w) ;skip string - (string= "'" w) - (string= "`" w)) - (cond - ((string= w (char-to-string (char-after (point)))) - (forward-char 1)) - ((re-search-forward (format "[^\\]%s" w) indent-point t) - nil) - (t - (goto-char indent-point) - (setq in-string t)))) - ((or (string= "/" w) - (string= "<" w)) - (if (string= "<" w) (setq w ">")) - (let (c) - (save-excursion - (goto-char pnt) - (skip-chars-backward " \t") - (setq c (char-after (1- (point)))) - (if c (setq c (char-syntax c)))) - (if (or (eq c ?.) - (and (eq c ?w) - (save-excursion - (forward-word -1) - (or - (looking-at ruby-block-beg-re) - (looking-at ruby-block-mid-re))))) - (cond - ((string= w (char-to-string (char-after (point)))) - (forward-char 1)) - ((re-search-forward (format "[^\\]%s" w) indent-point t) - nil) - (t - (goto-char indent-point) - (setq in-string t)))))) - ((string= "$" w) ;skip $char - (forward-char 1)) - ((string= "#" w) ;skip comment - (forward-line 1)) - ((string= "(" w) ;skip to matching paren - (let ((orig depth)) - (setq nest (cons (point) nest)) - (setq depth (1+ depth)) - (while (and (/= depth orig) - (re-search-forward "[()]" indent-point t)) - (cond - ((= (char-after (match-beginning 0)) ?\( ) - (setq nest (cons (point) nest)) - (setq depth (1+ depth))) - (t - (setq nest (cdr nest)) - (setq depth (1- depth))))) - (if (> depth orig) (setq in-paren ?\()))) - ((string= "[" w) ;skip to matching paren - (let ((orig depth)) - (setq nest (cons (point) nest)) - (setq depth (1+ depth)) - (while (and (/= depth orig) - (re-search-forward "\\[\\|\\]" indent-point t)) - (cond - ((= (char-after (match-beginning 0)) ?\[ ) - (setq nest (cons (point) nest)) - (setq depth (1+ depth))) - (t - (setq nest (cdr nest)) - (setq depth (1- depth))))) - (if (> depth orig) (setq in-paren ?\[)))) - ((string= "{" w) ;skip to matching paren - (let ((orig depth)) - (setq nest (cons (point) nest)) - (setq depth (1+ depth)) - (while (and (/= depth orig) - (re-search-forward "[{}]" indent-point t)) - (cond - ((= (char-after (match-beginning 0)) ?{ ) - (setq nest (cons (point) nest)) - (setq depth (1+ depth))) - (t - (setq nest (cdr nest)) - (setq depth (1- depth))))) - (if (> depth orig) (setq in-paren ?{)))) - ((string-match ruby-block-end-re w) - (setq nest (cdr nest)) - (setq depth (1- depth))) - ((string-match ruby-block-beg-re w) - (let (c) - (save-excursion - (goto-char pnt) - (skip-chars-backward " \t") - (setq c (char-after (1- (point))))) - (if (or (null c) (= c ?\n) (= c ?\;)) - (progn - (setq nest (cons (point) nest)) - (setq depth (1+ depth)))))) - (t - (error (format "bad string %s" w))))))) - (list in-string in-paren (car nest) depth))) - (defun ruby-calculate-indent (&optional parse-start) (save-excursion (beginning-of-line) @@ -413,6 +302,11 @@ The variable ruby-indent-level controls the amount of indentation. (setq indent (- indent ruby-indent-level))) indent))) +(defun ruby-electric-brace (arg) + (interactive "P") + (self-insert-command (prefix-numeric-value arg)) + (ruby-indent-line t)) + (defun ruby-beginning-of-defun (&optional arg) "Move backward to next beginning-of-defun. With argument, do this that many times. @@ -433,12 +327,12 @@ An end of a defun is found by moving forward from the beginning of one." (defun ruby-reindent-then-newline-and-indent () (interactive "*") + (save-excursion + (delete-region (point) (progn (skip-chars-backward " \t") (point)))) (insert ?\n) (save-excursion (forward-line -1) - (indent-according-to-mode) - (end-of-line) - (delete-region (point) (progn (skip-chars-backward " \t") (point)))) + (indent-according-to-mode)) (indent-according-to-mode)) (defun ruby-encomment-region (beg end) diff --git a/sample/t2.rb b/sample/t2.rb index a34c171837..2e3741e8f1 100644 --- a/sample/t2.rb +++ b/sample/t2.rb @@ -16,7 +16,7 @@ def tt end end -test = tt{i| +test = tt{|i| if i == 3; break end println("ttt: ", i); } diff --git a/sample/tt.rb b/sample/tt.rb index 4afa2022e6..f4960feaea 100644 --- a/sample/tt.rb +++ b/sample/tt.rb @@ -96,5 +96,5 @@ def tt end end -test = tt() {i|break if i == 2} +test = tt() {|i|break if i == 2} println([1,2,3,4].join(":")) @@ -383,3 +383,11 @@ Ftrap(argc, argv) #endif return Qnil; } + +Init_signal() +{ + extern VALUE C_Kernel; + + rb_define_method(C_Kernel, "kill", Fkill, -1); + rb_define_method(C_Kernel, "trap", Ftrap, -1); +} @@ -865,13 +865,6 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� ���ޥ�ɥ饤������Ϥ�EOF����ã���Ƥ����硤�����֤��� - esub(pattern) - - �����ƥ��ѿ�`$_'�λؤ�ʸ������Ф����ִ���Ԥʤ����ƥ졼����ʸ - ������� pattern�˥ޥå�������ʬʸ���������˥֥��å���ɾ������ - ���η�̤��֤������롥String���饹��esub��åɤβ���Ȥ� - ���ȡ�esub��åɤ�`$_'���ͤ����롥 - eval(expr) expr�Ȥ���Ϳ����줿ʸ�����ruby�ץ������Ȥ��Ʋ�ᡤ�¹Ԥ��롥 @@ -914,11 +907,12 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� ��ã�������ˤ�nil���֤����Ԥζ��ڤ�ϥ����ƥ��ѿ�`$/'�ˤ�ä� �ѹ��Ǥ��롥�ɤ߹����ʸ����ϥ����ƥ��ѿ�`$_'�ˤ⥻�åȤ���롥 - gsub(pattern, replace) + gsub(pattern[, replace]) - �����ƥ��ѿ�`$_'�λؤ�ʸ������Ф����ִ���Ԥʤ���ʸ������� - pattern�˥ޥå�������ʬ������replace���֤������롥String���饹 - ��gsub��åɤβ���ȤΤ��ȡ�gsub��åɤ�`$_'���ͤ� + �����ƥ��ѿ�`$_'�λؤ�ʸ������� pattern�˥ޥå�������ʬ������ + replace���֤������롥String���饹��gsub��åɤβ���Ȥ� + ���ȡ�����replace����ά���줿���ˤϥ��ƥ졼���Ȥ���ư����� + ���å���ɾ��������̤��ִ����롥 gsub��åɤ�`$_'���ͤ� ���롥 iterator_p() @@ -995,10 +989,11 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� require(file) - file������ɤ��롥load�Ȥ�ư��ΰ㤤��require�ϥ����ɤ����ե� - ����Υե�ѥ����ѿ�`$"'�˳Ф��Ƥ��ơ����˥����ɤ����ե������ - �ƥ����ɤ��ʤ����Ǥ��롥�ºݤ˥����ɤ������ˤ�TRUE�����˥����� - ����Ƥ�����ˤ�FALSE���֤��� + file������ɤ��롥load�Ȥ�ư��ΰ㤤�ϳ�ĥ�Ҥ���äƤ�������� + �����ɤ����ե�����Υե�ѥ����ѿ�`$"'�˳Ф��Ƥ��ƴ��˥����ɤ� + ���ե�����Ϻƥ����ɤ��ʤ����ȥ����ʥߥå������ǥ����б��� + �Ƥ�����(OS �ˤ��)�Ǥ��롥�ºݤ˥����ɤ������ˤ� TRUE�����˥��� + �ɤ���Ƥ�����ˤ�FALSE���֤��� select(reads[, writes[, execpts[, timeout]]]) @@ -1031,12 +1026,13 @@ Ruby�ˤϸ�̩�ʰ�̣�Ǥϴؿ��Ϥʤ���Kernel���饹�δؿ���åɤ�(���Ƥ� ����ν���ͤ����ꤷ���Ť�����ͤ��֤�������ͤ���ά���줿���� ��time(3)���֤��ͤ�ǥե���ȤȤ��롥 - sub(pattern, replace) + sub(pattern[, replace]) - �����ƥ��ѿ�`$_'�λؤ�ʸ������Ф����ִ���Ԥʤ���ʸ������Ǻ� - ���pattern�˥ޥå�������ʬ��replace���֤������롥sub��å� - ��`$_'���ͤ����롥����¾�ξܺ٤˴ؤ��Ƥ�String���饹��sub - ��åɤβ���ȤΤ��ȡ� + �����ƥ��ѿ�`$_'�λؤ�ʸ����Ǻǽ��pattern�˥ޥå�������ʬ�� + replace���֤������롥����replace ����ά���줿���ˤϥ��ƥ졼�� + �Ȥ���ư����֥��å���ɾ��������̤��ִ����롥sub��åɤ� + `$_'���ͤ����롥����¾�ξܺ٤˴ؤ��Ƥ�String���饹��sub�� + ���åɤβ���ȤΤ��ȡ� syscall(num, arg..) @@ -1615,7 +1611,7 @@ Methods: find - ���Ǥ��Ф��ƥ֥��å���ɾ�������ͤ����ˤʤä��ǽ�����Ǥ��֤��� + ���Ǥ��Ф��ƥ֥��å���ɾ�������ͤ����ˤʤä��ǽ�����Ǥ��֤��� find_all @@ -2632,7 +2628,7 @@ Methods: �����ǻ��ꤷ���⥸�塼���self�˥��롼�ɤ��롥�⥸�塼��� �������Ƥ����åɤ��ðۥ�åɤȤ����ɲä���롥 - init_object + initialize ���֥������Ȥ��������˸ƤӽФ���롥�ǥե���Ȥ�����ϲ��⤷�� �������֥��饹��ɬ�פ˱����ƺ��������뤳�Ȥ����Ԥ���Ƥ��롥 @@ -2923,17 +2919,12 @@ Methods: ʸ����Τ��줾��ΥХ��ȤˤĤ��Ʒ����֤����ƥ졼���� - esub(pattern) - - ʸ�������pattern�˥ޥå�������ʬ���ִ����륤�ƥ졼�����ޥå� - ������ʬʸ���������Ȥ��ƥ֥��å���ɾ��������̤�ʸ������֤� - �����롥sub/gsub�Τ褦��`&', `\1..\9'���ִ��ϹԤʤ��ʤ��� - - gsub(pattern, replace) + gsub(pattern[, replace]) - ʸ�������pattern�˥ޥå�������ʬ������replace���֤������롥 - �ִ�ʸ����replace���&��\0�ϥޥå�����ʸ����ˡ�\1..\9��n���� - �γ�̤����Ƥ��֤��������롥 + ʸ�������pattern�˥ޥå�������ʬ������replace���֤������롥�� + ��ʸ����replace���&��\0�ϥޥå�����ʸ����ˡ�\1..\9��n���ܤ� + ��̤����Ƥ��֤��������롥����replace����ά���줿���ˤϥ��� + �졼���Ȥ���ư����֥��å���ɾ��������̤��ִ����롥 hex @@ -3019,12 +3010,12 @@ Methods: ʸ���������ζ����������� - sub(pattern, replace) + sub(pattern[, replace]) - ʸ�������pattern�˥ޥå�������ʬ��replace���֤������롥�ִ�ʸ - ����replace���&��\0�ϥޥå�����ʸ����ˡ�\1..\9�� n���ܤγ�� - �����Ƥ��֤��������롥sub()��gsub()�Ȱۤʤꡤ�ǽ�Υޥå��� - �����ִ����롥 + ʸ�����pattern�˥ޥå�����ǽ����ʬ��replace���֤������롥�� + ��ʸ����replace���&��\0�ϥޥå�����ʸ����ˡ�\1..\9�� n���ܤ� + ��̤����Ƥ��֤��������롥����replace����ά���줿���ˤϥ��� + �졼���Ȥ���ư����֥��å���ɾ��������̤��ִ����롥 sum([bits]) @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:42:59 $ created at: Fri Oct 15 10:39:26 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date: 1995/01/10 10:43:01 $ created at: Mon Aug 9 17:12:58 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -561,7 +561,7 @@ Fstr_upto(beg, end) } static VALUE -Fstr_aref_internal(str, indx) +str_aref(str, indx) struct RString *str; VALUE indx; { @@ -619,7 +619,7 @@ Fstr_aref(argc, argv, str) if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) { return str_substr(str, NUM2INT(arg1), NUM2INT(arg2)); } - return Fstr_aref_internal(str, arg1); + return str_aref(str, arg1); } static void @@ -676,6 +676,21 @@ str_sub(str, pat, val, once) { int beg, end, offset, n; + Check_Type(val, T_STRING); + str_modify(str); + + switch (TYPE(pat)) { + case T_REGEXP: + break; + + case T_STRING: + return str_sub(str, re_regcomp(pat), val, once); + + default: + /* type failed */ + Check_Type(pat, T_REGEXP); + } + for (offset=0, n=0; (beg=research(pat, str, offset)) >= 0; offset=BEG(0)+STRLEN(val)) { @@ -690,7 +705,7 @@ str_sub(str, pat, val, once) } static VALUE -Fstr_aset_internal(str, indx, val) +str_aset(str, indx, val) struct RString *str; VALUE indx, val; { @@ -771,52 +786,20 @@ Fstr_aset(argc, argv, str) str_replace(str, beg, len, arg3); return arg3; } - return Fstr_aset_internal(str, arg1, arg2); -} - -static VALUE -Fstr_sub_internal(str, pat, val, once) - VALUE str, pat, val; - int once; -{ - Check_Type(val, T_STRING); - str_modify(str); - - switch (TYPE(pat)) { - case T_REGEXP: - return str_sub(str, pat, val, once); - - case T_STRING: - return str_sub(str, re_regcomp(pat), val, once); - - default: - /* type failed */ - Check_Type(pat, T_REGEXP); - } - return Qnil; /* not reached */ -} - -static VALUE -Fstr_sub(str, pat, val) - VALUE str, pat, val; -{ - return Fstr_sub_internal(str, pat, val, 1); + return str_aset(str, arg1, arg2); } static VALUE -Fstr_gsub(str, pat, val) - VALUE str, pat, val; -{ - return Fstr_sub_internal(str, pat, val, 0); -} - -static VALUE -Fstr_esub(str, pat) +str_sub_iter(str, pat, once) VALUE str, pat; { VALUE val; int beg, end, offset, n; + if (!iterator_p()) { + Fail("Wrong # of arguments(1 for 2)"); + } + str_modify(str); switch (TYPE(pat)) { case T_REGEXP: @@ -837,34 +820,67 @@ Fstr_esub(str, pat) val = obj_as_string(val); str_replace2(str, beg, END(0)-1, val); offset=BEG(0)+STRLEN(val); + if (once) break; } return (VALUE)str; } -extern VALUE rb_lastline; +static VALUE +Fstr_sub(argc, argv, str) + int argc; + VALUE *argv; + VALUE str; +{ + VALUE pat, val; + + if (rb_scan_args(argc, argv, "11", &pat, &val) == 1) { + return str_sub_iter(str, pat, 1); + } + return str_sub(str, pat, val, 1); +} static VALUE -Fsub(obj, pat, val) - VALUE obj, pat, val; +Fstr_gsub(argc, argv, str) + int argc; + VALUE *argv; + VALUE str; { - Check_Type(rb_lastline, T_STRING); - return Fstr_sub_internal(rb_lastline, pat, val, 1); + VALUE pat, val; + + if (rb_scan_args(argc, argv, "11", &pat, &val) == 1) { + return str_sub_iter(str, pat, 0); + } + return str_sub(str, pat, val, 0); } +extern VALUE rb_lastline; + static VALUE -Fgsub(obj, pat, val) - VALUE obj, pat, val; +Fsub(argc, argv) + int argc; + VALUE *argv; { + VALUE pat, val; + Check_Type(rb_lastline, T_STRING); - return Fstr_sub_internal(rb_lastline, pat, val, 0); + if (rb_scan_args(argc, argv, "11", &pat, &val) == 1) { + return str_sub_iter(rb_lastline, pat, 1); + } + return str_sub(rb_lastline, pat, val, 1); } static VALUE -Fesub(obj, pat) - VALUE obj, pat; +Fgsub(argc, argv) + int argc; + VALUE *argv; { + VALUE pat, val; + Check_Type(rb_lastline, T_STRING); - return Fstr_esub(rb_lastline, pat); + if (rb_scan_args(argc, argv, "11", &pat, &val) == 1) { + return str_sub_iter(rb_lastline, pat, 0); + } + return str_sub(rb_lastline, pat, val, 0); } static VALUE @@ -1077,36 +1093,39 @@ Fstr_tolower(str) } struct tr { - int last, max; + unsigned char gen, now, max; char *p, *pend; } trsrc, trrepl; -static +static char trnext(t) struct tr *t; { - while (t->p < t->pend) { - if (t->max) { - if (++t->last < t->max) - return t->last; - t->last = t->max = 0; - } - else if (t->last && *t->p == '-') { - t->p++; - t->max = *t->p; - if (t->p == t->pend) { - t->p--; - return '-'; - } - else if (t->max < t->last) { - t->last = t->max - 1; - return '-'; + for (;;) { + if (!t->gen) { + if (t->p == t->pend) return -1; + t->now = *t->p++; + if (t->p < t->pend && *t->p == '-') { + t->p++; + if (t->p < t->pend) { + if (t->now > *t->p) { + t->p++; + continue; + } + t->gen = 1; + t->max = *t->p++; + } } - continue; + return t->now; + } + else if (++t->now < t->max) { + return t->now; + } + else { + t->gen = 0; + return t->max; } - return t->last = *t->p++; } - return -1; } static VALUE @@ -1114,8 +1133,8 @@ Fstr_tr(str, src, repl) struct RString *str, *src, *repl; { struct tr trsrc, trrepl; - char trans[256]; int cflag = 0; + char trans[256]; int i, c, save; char *s, *send, *t; @@ -1127,34 +1146,46 @@ Fstr_tr(str, src, repl) } Check_Type(repl, T_STRING); trrepl.p = repl->ptr; trrepl.pend = trrepl.p + repl->len; - trsrc.last = trrepl.last = trsrc.max = trrepl.max = 0; + trsrc.gen = trrepl.gen = 0; + trsrc.now = trrepl.now = 0; + trsrc.max = trrepl.max = 0; - for (i=0; i<256; i++) { - trans[i] = cflag ? 1 : 0; - } - - while ((c = trnext(&trsrc)) >= 0) { - trans[c & 0xff] = cflag ? 0 : 1; - } - - c = 0; - for (i=0; i<256; i++) { - if (trans[i] == 0) { - trans[i] = i; + if (cflag) { + for (i=0; i<256; i++) { + trans[i] = 1; } - else { - c = trnext(&trrepl); - if (c == -1) { - trans[i] = trrepl.last; + while ((c = trnext(&trsrc)) >= 0) { + trans[c & 0xff] = 0; + } + for (i=0; i<256; i++) { + if (trans[i] == 0) { + trans[i] = i; } else { - trans[i] = c; + c = trnext(&trrepl); + if (c == -1) { + trans[i] = trrepl.now; + } + else { + trans[i] = c; + } } } } + else { + char r; + + for (i=0; i<256; i++) { + trans[i] = 0; + } + while ((c = trnext(&trsrc)) >= 0) { + r = trnext(&trrepl); + if (r == -1) r = trrepl.now; + trans[c & 0xff] = r; + } + } str_modify(str); - t = s = str->ptr; send = s + str->len; while (s < send) { c = *s++ & 0xff; @@ -1162,7 +1193,6 @@ Fstr_tr(str, src, repl) *t++ = c; } *t = '\0'; - str->len = t - str->ptr; return (VALUE)str; } @@ -1177,7 +1207,7 @@ tr_setup_table(str, table) char c; tr.p = str->ptr; tr.pend = tr.p + str->len; - tr.last = tr.max = 0; + tr.gen = tr.now = tr.max = 0; if (str->len > 2 && str->ptr[0] == '^') { cflag++; tr.p++; @@ -1422,6 +1452,7 @@ Fstr_each(str) int newline; int rslen; char *p = str->ptr, *pend = p + str->len, *s; + char *ptr = p; if (RS == Qnil) { rb_yield(str); @@ -1447,6 +1478,7 @@ Fstr_each(str) memcmp(RSTRING(RS)->ptr, p-rslen+1, rslen) == 0)) { rb_lastline = str_new(s, p - s + 1); rb_yield(rb_lastline); + if (str->ptr != ptr) Fail("string modified"); s = p + 1; } } @@ -1465,8 +1497,8 @@ Fstr_each_byte(str) { int i; - for (i=0; str->len; i++) { - rb_yield(str->ptr[i] & 0xff); + for (i=0; i<str->len; i++) { + rb_yield(INT2FIX(str->ptr[i] & 0xff)); } return (VALUE)str; } @@ -1705,9 +1737,8 @@ Init_String() rb_define_method(C_String, "rjust", Fstr_rjust, 1); rb_define_method(C_String, "center", Fstr_center, 1); - rb_define_method(C_String, "sub", Fstr_sub, 2); - rb_define_method(C_String, "gsub", Fstr_gsub, 2); - rb_define_method(C_String, "esub", Fstr_esub, 1); + rb_define_method(C_String, "sub", Fstr_sub, -1); + rb_define_method(C_String, "gsub", Fstr_gsub, -1); rb_define_method(C_String, "chop", Fstr_chop, 0); rb_define_method(C_String, "strip", Fstr_strip, 0); @@ -1721,9 +1752,8 @@ Init_String() rb_define_method(C_String, "sum", Fstr_sum, -1); - rb_define_private_method(C_Kernel, "sub", Fsub, 2); - rb_define_private_method(C_Kernel, "gsub", Fgsub, 2); - rb_define_private_method(C_Kernel, "esub", Fesub, 1); + rb_define_private_method(C_Kernel, "sub", Fsub, -1); + rb_define_private_method(C_Kernel, "gsub", Fgsub, -1); pr_str = rb_intern("to_s"); } @@ -6,7 +6,7 @@ $Date: 1994/12/06 09:30:28 $ created at: Tue Dec 28 14:31:59 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -7,7 +7,7 @@ $Date$ created at: Fri Mar 10 17:22:34 JST 1995 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -6,7 +6,7 @@ $Date$ created at: Thu Mar 9 11:55:53 JST 1995 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ #ifndef UTIL_H diff --git a/variable.c b/variable.c index 34bd8f4de5..c6b180736d 100644 --- a/variable.c +++ b/variable.c @@ -19,7 +19,11 @@ st_table *rb_class_tbl; #define class_tbl rb_class_tbl #define instance_tbl (RBASIC(Qself)->iv_tbl) -st_table *new_idhash() +VALUE rb_const_bound(); +VALUE rb_const_get(); + +st_table * +new_idhash() { return st_init_table(ST_NUMCMP, ST_NUMHASH); } @@ -31,13 +35,77 @@ Init_var_tables() class_tbl = new_idhash(); } +char * +rb_class2path(class) + VALUE class; +{ + VALUE path = rb_ivar_get_1(class, rb_intern("__classpath__")); + if (TYPE(path) != T_STRING) Bug("class path does not set properly"); + return RSTRING(path)->ptr; +} + +void +rb_set_class_path(class, under, name) + VALUE class, under; + char *name; +{ + VALUE str; + char *s; + + str = str_new2(name); + if (under) { + str_cat(str, ":", 1); + s = rb_class2path(under); + str_cat(str, s, strlen(s)); + } + rb_ivar_set_1(class, rb_intern("__classpath__"), str); +} + +VALUE +rb_path2class(path) + char *path; +{ + char *p, *name, *s; + ID id; + VALUE class; + + p = path; + while (*p) { + if (*p == ':') break; + *p++; + } + if (*p == '\0') { /* pre-defined class */ + if (!st_lookup(class_tbl, rb_intern(path), &class)) { + Fail("Undefined class -- %s", path); + } + return class; + } + class = rb_path2class(p+1); + name = ALLOCA_N(char, p-path+1); + s = name; + while (path<p) { + *s++ = *path++; + } + *s = '\0'; + id = rb_intern(name); + if (!rb_const_bound(class, id)) + Fail("%s not defined", name); + class = rb_const_get(class, id); + switch (TYPE(class)) { + case T_CLASS: + case T_MODULE: + break; + default: + Fail("%s not a module/class"); + } + return class; +} + void rb_name_class(class, id) VALUE class; ID id; { - VALUE body; - rb_ivar_set_1(class, rb_intern("__classname__"), INT2FIX(id)); } @@ -58,14 +126,10 @@ rb_class2name(class) Fail("0x%x is not a class/module", class); } - while (FL_TEST(class, FL_SINGLE)) { + while (FL_TEST(class, FL_SINGLE) || TYPE(class) == T_ICLASS) { class = (struct RClass*)class->super; } - while (TYPE(class) == T_ICLASS) { - class = (struct RClass*)class->super; - } - name = rb_ivar_get_1(class, rb_intern("__classname__")); if (name) { name = FIX2INT(name); @@ -7,7 +7,7 @@ $Date: 1995/01/12 08:54:54 $ created at: Thu Sep 30 20:08:01 JST 1993 - Copyright (C) 1995 Yukihiro Matsumoto + Copyright (C) 1993-1995 Yukihiro Matsumoto ************************************************/ @@ -29,6 +29,6 @@ show_version() show_copyright() { - fprintf(stderr, "ruby - Copyright (C) 1995 Yukihiro Matsumoto\n"); + fprintf(stderr, "ruby - Copyright (C) 1993-1995 Yukihiro Matsumoto\n"); exit(0); } @@ -1,2 +1,2 @@ -#define RUBY_VERSION "0.73" -#define VERSION_DATE "95/04/13" +#define RUBY_VERSION "0.76" +#define VERSION_DATE "95/05/19" |