Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial revision

git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@2 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
commit 99d0354e89aefdb6373dbeb22506216b8790a0bd 1 parent 502e754
matz authored
Showing with 60,385 additions and 0 deletions.
  1. +4,305 −0 ChangeLog
  2. +186 −0 MANIFEST
  3. +219 −0 Makefile.in
  4. +108 −0 README
  5. +1,064 −0 README.EXT
  6. +150 −0 README.jp
  7. +4 −0 ToDo
  8. +1,242 −0 array.c
  9. +1,249 −0 bignum.c
  10. +427 −0 class.c
  11. +100 −0 compar.c
  12. +36 −0 config.dj
  13. +613 −0 config.guess
  14. +931 −0 config.sub
  15. +4,038 −0 configure
  16. +5 −0 configure.bat
  17. +474 −0 configure.in
  18. +50 −0 defines.h
  19. +427 −0 dir.c
  20. +1,445 −0 dln.c
  21. +22 −0 dln.h
  22. +4 −0 dmyext.c
  23. +369 −0 enum.c
  24. +49 −0 env.h
  25. +832 −0 error.c
  26. +5,402 −0 eval.c
  27. +12 −0 ext/Setup
  28. +12 −0 ext/Setup.dj
  29. +12 −0 ext/Setup.nt
  30. +12 −0 ext/Setup.x68
  31. +73 −0 ext/aix_ld.rb
  32. +6 −0 ext/curses/MANIFEST
  33. +798 −0 ext/curses/curses.c
  34. +21 −0 ext/curses/extconf.rb
  35. +28 −0 ext/curses/hello.rb
  36. +76 −0 ext/curses/rain.rb
  37. +90 −0 ext/curses/view.rb
  38. +4 −0 ext/dbm/MANIFEST
  39. +515 −0 ext/dbm/dbm.c
  40. +1 −0  ext/dbm/depend
  41. +5 −0 ext/dbm/extconf.rb
  42. +5 −0 ext/etc/MANIFEST
  43. +1 −0  ext/etc/depend
  44. +266 −0 ext/etc/etc.c
  45. +73 −0 ext/etc/etc.doc
  46. +7 −0 ext/etc/extconf.rb
  47. +468 −0 ext/extmk.rb.in
  48. +480 −0 ext/extmk.rb.nt
  49. +3 −0  ext/fcntl/MANIFEST
  50. +1 −0  ext/fcntl/depend
  51. +106 −0 ext/fcntl/fcntl.c
  52. +3 −0  ext/kconv/MANIFEST
  53. +1 −0  ext/kconv/depend
  54. +1,881 −0 ext/kconv/kconv.c
  55. +5 −0 ext/marshal/MANIFEST
  56. +2 −0  ext/marshal/depend
  57. +1 −0  ext/marshal/extconf.rb
  58. +850 −0 ext/marshal/marshal.c
  59. +48 −0 ext/marshal/marshal.doc
  60. +6 −0 ext/md5/MANIFEST
  61. +2 −0  ext/md5/depend
  62. +36 −0 ext/md5/md5.doc
  63. +86 −0 ext/md5/md5.h
  64. +337 −0 ext/md5/md5c.c
  65. +90 −0 ext/md5/md5init.c
  66. +4 −0 ext/socket/MANIFEST
  67. +1 −0  ext/socket/depend
  68. +17 −0 ext/socket/extconf.rb
  69. +1,407 −0 ext/socket/socket.c
  70. +3 −0  ext/tkutil/MANIFEST
  71. +1 −0  ext/tkutil/depend
  72. +46 −0 ext/tkutil/tkutil.c
  73. +1,756 −0 file.c
  74. +190 −0 fnmatch.c
  75. +36 −0 fnmatch.h
  76. +989 −0 gc.c
  77. +574 −0 glob.c
  78. +1,005 −0 hash.c
  79. +48 −0 inits.c
  80. +238 −0 install-sh
  81. +2,306 −0 io.c
  82. +53 −0 io.h
  83. +28 −0 lib/English.rb
  84. +54 −0 lib/base64.rb
  85. +56 −0 lib/cgi-lib.rb
  86. +490 −0 lib/complex.rb
  87. +227 −0 lib/date.rb
  88. +262 −0 lib/debug.rb
  89. +94 −0 lib/e2mmap.rb
  90. +71 −0 lib/e2mmap1_0.rb
  91. +205 −0 lib/finalize.rb
  92. +39 −0 lib/find.rb
  93. +617 −0 lib/ftplib.rb
  94. +142 −0 lib/getopts.rb
  95. +207 −0 lib/jcode.rb
  96. +48 −0 lib/mailread.rb
  97. +308 −0 lib/mathn.rb
  98. +777 −0 lib/matrix.rb
  99. +183 −0 lib/mutex_m.rb
  100. +40 −0 lib/observer.rb
  101. +84 −0 lib/parsearg.rb
  102. +42 −0 lib/parsedate.rb
  103. +55 −0 lib/ping.rb
  104. +361 −0 lib/rational.rb
  105. +376 −0 lib/sync.rb
  106. +110 −0 lib/thread.rb
  107. +128 −0 lib/thwait.rb
  108. +829 −0 lib/tk.rb
  109. +326 −0 lib/tkcanvas.rb
  110. +38 −0 lib/tkclass.rb
  111. +528 −0 lib/tkcore.rb
  112. +67 −0 lib/tkentry.rb
  113. +27 −0 lib/tkscrollbox.rb
  114. +164 −0 lib/tktext.rb
  115. +550 −0 lib/tkthcore.rb
  116. +75 −0 lib/tracer.rb
  117. +33 −0 main.c
  118. +135 −0 math.c
  119. +189 −0 missing/alloca.c
  120. +276 −0 missing/crypt.c
  121. +248 −0 missing/dir.h
  122. +36 −0 missing/dup2.c
  123. +32 −0 missing/file.h
  124. +90 −0 missing/flock.c
  125. +24 −0 missing/memmove.c
  126. +104 −0 missing/mkdir.c
  127. +2,191 −0 missing/nt.c
  128. +225 −0 missing/nt.h
  129. +77 −0 missing/setenv.c
  130. +13 −0 missing/strcasecmp.c
  131. +25 −0 missing/strdup.c
  132. +19 −0 missing/strerror.c
  133. +889 −0 missing/strftime.c
  134. +73 −0 missing/strstr.c
  135. +84 −0 missing/strtol.c
  136. +184 −0 missing/strtoul.c
  137. +12 −0 missing/x68.c
  138. +290 −0 node.h
  139. +1,154 −0 numeric.c
  140. +697 −0 object.c
  141. +883 −0 pack.c
  142. +3,717 −0 parse.y
  143. +998 −0 process.c
  144. +100 −0 random.c
  145. +211 −0 range.c
  146. +886 −0 re.c
  147. +34 −0 re.h
Sorry, we could not display the entire diff because it was too big.
View
4,305 ChangeLog
4,305 additions, 0 deletions not shown
View
186 MANIFEST
@@ -0,0 +1,186 @@
+ChangeLog
+MANIFEST
+Makefile.in
+README
+README.jp
+README.EXT
+ToDo
+array.c
+bignum.c
+class.c
+compar.c
+configure
+configure.bat
+configure.in
+config.dj
+config.guess
+config.sub
+defines.h
+dir.c
+dln.c
+dln.h
+dmyext.c
+enum.c
+env.h
+error.c
+eval.c
+file.c
+fnmatch.c
+fnmatch.h
+gc.c
+glob.c
+hash.c
+inits.c
+install-sh
+io.c
+io.h
+main.c
+math.c
+node.h
+numeric.c
+object.c
+pack.c
+parse.y
+process.c
+random.c
+range.c
+re.c
+re.h
+regex.c
+regex.h
+ruby.1
+ruby.c
+ruby.h
+sig.h
+signal.c
+sprintf.c
+st.c
+st.h
+string.c
+struct.c
+time.c
+top.sed
+util.h
+util.c
+variable.c
+version.c
+version.h
+ext/Setup
+ext/Setup.dj
+ext/Setup.nt
+ext/Setup.x68
+ext/extmk.rb.in
+ext/extmk.rb.nt
+ext/aix_ld.rb
+lib/English.rb
+lib/base64.rb
+lib/cgi-lib.rb
+lib/complex.rb
+lib/date.rb
+lib/debug.rb
+lib/e2mmap.rb
+lib/e2mmap1_0.rb
+lib/find.rb
+lib/finalize.rb
+lib/ftplib.rb
+lib/getopts.rb
+lib/jcode.rb
+lib/mailread.rb
+lib/mathn.rb
+lib/matrix.rb
+lib/mutex_m.rb
+lib/observer.rb
+lib/parsearg.rb
+lib/parsedate.rb
+lib/ping.rb
+lib/rational.rb
+lib/sync.rb
+lib/thread.rb
+lib/thwait.rb
+lib/tk.rb
+lib/tkcore.rb
+lib/tkcanvas.rb
+lib/tkclass.rb
+lib/tkentry.rb
+lib/tkscrollbox.rb
+lib/tktext.rb
+lib/tkthcore.rb
+lib/tracer.rb
+missing/alloca.c
+missing/crypt.c
+missing/dir.h
+missing/dup2.c
+missing/file.h
+missing/flock.c
+missing/memmove.c
+missing/mkdir.c
+missing/nt.c
+missing/nt.h
+missing/setenv.c
+missing/strcasecmp.c
+missing/strdup.c
+missing/strerror.c
+missing/strftime.c
+missing/strstr.c
+missing/strtol.c
+missing/strtoul.c
+missing/x68.c
+sample/biorhythm.rb
+sample/clnt.rb
+sample/dbmtest.rb
+sample/dir.rb
+sample/eval.rb
+sample/export.rb
+sample/exyacc.rb
+sample/fact.rb
+sample/fib.awk
+sample/fib.pl
+sample/fib.rb
+sample/fib.scm
+sample/freq.rb
+sample/from.rb
+sample/fullpath.rb
+sample/getopts.test
+sample/io.rb
+sample/less.rb
+sample/list.rb
+sample/list2.rb
+sample/list3.rb
+sample/mrshtest.rb
+sample/mkproto.rb
+sample/mpart.rb
+sample/observ.rb
+sample/occur.pl
+sample/occur.rb
+sample/occur2.rb
+sample/philos.rb
+sample/pi.rb
+sample/rcs.awk
+sample/rcs.dat
+sample/rcs.rb
+sample/regx.rb
+sample/ruby-mode.el
+sample/rubydb2x.el
+sample/rubydb3x.el
+sample/sieve.rb
+sample/svr.rb
+sample/test.rb
+sample/time.rb
+sample/tkbiff.rb
+sample/tkbrowse.rb
+sample/tkdialog.rb
+sample/tkfrom.rb
+sample/tkhello.rb
+sample/tkline.rb
+sample/tktimer.rb
+sample/trojan.rb
+sample/tsvr.rb
+sample/uumerge.rb
+win32/Makefile
+win32/config.h
+win32/ntsetup.bat
+win32/ruby.def
+x68/fconvert.c
+x68/select.c
+x68/_dtos18.c
+x68/_round.c
View
219 Makefile.in
@@ -0,0 +1,219 @@
+SHELL = /bin/sh
+
+#### Start of system configuration section. ####
+
+srcdir = @srcdir@
+VPATH = @srcdir@:@srcdir@/missing
+
+CC = @CC@
+YACC = @YACC@
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_DATA = @INSTALL_DATA@
+PURIFY =
+@SET_MAKE@
+
+CFLAGS = @CFLAGS@ -I@srcdir@
+LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
+LIBS = @LIBS@ $(EXTLIBS)
+MISSING = @LIBOBJS@ @ALLOCA@
+
+program_transform_name = -e @program_transform_name@
+RUBY_INSTALL_NAME = `t='$(program_transform_name)'; echo ruby | sed $$t`
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+libdir = @libdir@/$(RUBY_INSTALL_NAME)
+
+binsuffix = @binsuffix@
+
+#### End of system configuration section. ####
+
+
+LIBRUBY = libruby.a
+
+EXTOBJS = dmyext.o
+
+MAINOBJ = main.o
+
+OBJS = array.o \
+ bignum.o \
+ class.o \
+ compar.o \
+ dir.o \
+ dln.o \
+ enum.o \
+ error.o \
+ eval.o \
+ file.o \
+ fnmatch.o \
+ gc.o \
+ glob.o \
+ hash.o \
+ inits.o \
+ io.o \
+ math.o \
+ numeric.o \
+ object.o \
+ pack.o \
+ parse.o \
+ process.o \
+ random.o \
+ range.o \
+ re.o \
+ regex.o \
+ ruby.o \
+ signal.o \
+ sprintf.o \
+ st.o \
+ string.o \
+ struct.o \
+ time.o \
+ util.o \
+ variable.o \
+ version.o \
+ $(MISSING)
+
+all: miniruby$(binsuffix) @srcdir@/ext/Setup
+ @if test -z "$$UNDER_EXTMAKE_RB"; \
+ then echo "Compiling ext modules"; \
+ UNDER_EXTMAKE_RB=yes; export UNDER_EXTMAKE_RB; \
+ cd ext; ../miniruby ./extmk.rb @EXTSTATIC@; fi
+
+miniruby$(binsuffix): $(OBJS) $(MAINOBJ) $(EXTOBJS)
+ @rm -f $@
+ $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(OBJS) $(EXTOBJS) $(LIBS) -o miniruby
+
+ruby$(binsuffix): $(LIBRUBY) $(MAINOBJ) $(EXTOBJS)
+ @rm -f $@
+ $(PURIFY) $(CC) $(LDFLAGS) $(MAINOBJ) $(EXTOBJS) $(LIBRUBY) $(LIBS) -o ruby
+
+$(LIBRUBY): $(OBJS) dmyext.o
+ @AR@ rcu $(LIBRUBY) $(OBJS) dmyext.o
+ @-@RANLIB@ $(LIBRUBY) 2> /dev/null || true
+
+install:; $(INSTALL_PROGRAM) ruby$(binsuffix) $(bindir)/$(RUBY_INSTALL_NAME)$(binsuffix)
+ @-@STRIP@ $(bindir)/$(RUBY_INSTALL_NAME)$(binsuffix)
+ @test -d $(libdir) || mkdir $(libdir)
+ cd ext; ../miniruby ./extmk.rb install
+ @for rb in `grep '^lib/' @srcdir@/MANIFEST`; do \
+ $(INSTALL_DATA) @srcdir@/$$rb $(libdir); \
+ done
+
+clean:; @rm -f $(OBJS) $(LIBRUBY) $(MAINOBJ)
+ @rm -f ext/extinit.c ext/extinit.o dmyext.o
+ cd ext; ../miniruby ./extmk.rb clean
+
+realclean: clean
+ @rm -f Makefile ext/extmk.rb ext/config.cache parse.c
+ @rm -f config.cache config.h config.log config.status
+ @rm -f core ruby$(binsuffix) miniruby$(binsuffix) parse.c *~ *.core gmon.out
+
+test:; @-./ruby @srcdir@/sample/test.rb > ./ruby_test 2>&1; \
+ if grep '^end of test' ./ruby_test > /dev/null; then \
+ echo "test succeeded"; \
+ else \
+ grep '^sample/test.rb' ./ruby_test; \
+ grep '^not' ./ruby_test; \
+ echo "test failed";\
+ fi;\
+ rm -f ./ruby_test
+
+.c.o:
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
+
+parse.c: parse.y
+ $(YACC) $<
+ mv -f y.tab.c parse.c
+
+alloca.o: @srcdir@/missing/alloca.c
+ $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/alloca.c
+
+crypt.o: @srcdir@/missing/crypt.c
+ $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/crypt.c
+
+dup2.o: @srcdir@/missing/dup2.c
+ $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/dup2.c
+
+flock.o: @srcdir@/missing/flock.c
+ $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/flock.c
+
+memmove.o: @srcdir@/missing/memmove.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/memmove.c
+
+mkdir.o: @srcdir@/missing/mkdir.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/mkdir.c
+
+setenv.o: @srcdir@/missing/setenv.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/setenv.c
+
+strcasecmp.o: @srcdir@/missing/strcasecmp.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strcasecmp.c
+
+strerror.o: @srcdir@/missing/strerror.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strerror.c
+
+strdup.o: @srcdir@/missing/strdup.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strdup.c
+
+strftime.o: @srcdir@/missing/strftime.c
+ $(CC) -I. $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strftime.c
+
+strstr.o: @srcdir@/missing/strstr.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strstr.c
+
+strtol.o: @srcdir@/missing/strtol.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strtol.c
+
+strtoul.o: @srcdir@/missing/strtoul.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/strtoul.c
+
+nt.o: @srcdir@/missing/nt.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/nt.c
+
+x68.o: @srcdir@/missing/x68.c
+ $(CC) $(CFLAGS) $(CPPFLAGS) -c @srcdir@/missing/x68.c
+
+# Prevent GNU make v3 from overflowing arg limit on SysV.
+.NOEXPORT:
+###
+parse.o : parse.y ruby.h defines.h config.h env.h node.h st.h regex.h
+###
+array.o: array.c ruby.h config.h defines.h
+bignum.o: bignum.c ruby.h config.h defines.h
+class.o: class.c ruby.h config.h defines.h node.h st.h
+compar.o: compar.c ruby.h config.h defines.h
+dir.o: dir.c ruby.h config.h defines.h
+dln.o: dln.c config.h defines.h dln.h st.h
+dmyext.o: dmyext.c
+enum.o: enum.c ruby.h config.h defines.h
+error.o: error.c ruby.h config.h defines.h env.h
+eval.o: eval.c ruby.h config.h defines.h env.h node.h sig.h st.h dln.h
+file.o: file.c ruby.h config.h defines.h io.h sig.h
+fnmatch.o: fnmatch.c config.h fnmatch.h
+gc.o: gc.c ruby.h config.h defines.h env.h sig.h st.h node.h re.h regex.h
+glob.o: glob.c config.h fnmatch.h
+hash.o: hash.c ruby.h config.h defines.h st.h
+inits.o: inits.c ruby.h config.h defines.h
+io.o: io.c ruby.h config.h defines.h io.h sig.h
+main.o: main.c
+math.o: math.c ruby.h config.h defines.h
+numeric.o: numeric.c ruby.h config.h defines.h
+object.o: object.c ruby.h config.h defines.h st.h
+pack.o: pack.c ruby.h config.h defines.h
+process.o: process.c ruby.h config.h defines.h sig.h st.h
+random.o: random.c ruby.h config.h defines.h
+range.o: range.c ruby.h config.h defines.h
+re.o: re.c ruby.h config.h defines.h re.h regex.h
+regex.o: regex.c config.h defines.h regex.h util.h
+ruby.o: ruby.c ruby.h config.h defines.h re.h regex.h dln.h
+signal.o: signal.c ruby.h config.h defines.h sig.h
+sprintf.o: sprintf.c ruby.h config.h defines.h
+st.o: st.c config.h st.h
+string.o: string.c ruby.h config.h defines.h re.h regex.h
+struct.o: struct.c ruby.h config.h defines.h
+time.o: time.c ruby.h config.h defines.h
+util.o: util.c defines.h config.h util.h
+variable.o: variable.c ruby.h config.h defines.h env.h st.h
+version.o: version.c ruby.h config.h defines.h version.h
View
108 README
@@ -0,0 +1,108 @@
+* What's Ruby
+
+Ruby is the interpreted scripting language for quick and
+easy object-oriented programming. It has many features to
+process text files and to do system management tasks (as in
+perl). It is simple, straight-forward, and extensible.
+
+* Features of ruby
+
+ + Simple Syntax
+ + *Normal* Object-Oriented features(ex. class, method calls)
+ + *Advanced* Object-Oriented features(ex. Mix-in, Singleton-method)
+ + Operator Overloading
+ + Exception Handling
+ + Iterators and Closures
+ + Garbage Collection
+ + Dynamic Loading of Object files(on some architecture)
+ + Highly Portable(works on many UNIX machines)
+
+* How to get ruby
+
+** by ftp
+
+The ruby distribution can be found on
+
+ ftp://ftp.netlab.co.jp/pub/lang/ruby/
+
+* How to compile and install
+
+This is what you need to do to compile and install ruby:
+
+ 1. Run ./configure, which will generate config.h and Makefile.
+
+ 2. Edit defines.h if you need. Probably this step will not need.
+
+ 3. Remove comment mark(#) before the module names from ext/Setup, if
+ you want to link modules statically.
+
+ If you want to link all the extension modules, remove comment
+ mark from the line "#option nodynamic".
+
+ 4. Run make.
+
+ 5. Optionally, run 'make test' to check that the compiled ruby
+ interpreter works well. If you see the message "test succeeded",
+ your ruby works as it should.
+
+ 6. Run 'make install'
+
+If you fail to compile ruby, please send the detailed error report with
+the error log and machine/OS type, to help others.
+
+* Copying
+
+Ruby is copyrighted by Yukihiro Matsumoto <matz@ruby.club.co.jp>.
+
+This source is distributed under the conditions blow:
+
+ 1. You may make and give away verbatim copies of the source form of
+ the software without restriction, provided that you do not modify
+ the original distribution files.
+
+ If you want to distribute the modified version in any way, contact
+ the author.
+
+ 2. You may distribute the software in object code or executable
+ form, provided that you distribute it with instructions on where
+ to get the software.
+
+ 3. You may modify the software in any way, provided that you do not
+ distribute the modified version.
+
+ 4. You may modify and include the part of the software into any other
+ software (possibly commercial). But some files in the distribution
+ are not written by the author, so that they are not under this terms.
+ They are gc.c(partly)��utils.c(partly), regex.[ch]��fnmatch.[ch]��
+ glob.c, st.[ch] and somme files under the ./missing directory. See
+ each files for the copying condition.
+
+ 5. The scripts and library files supplied as input to or produced as
+ output from the software do not automatically fall under the
+ copyright of the software, but belong to whomever generated them,
+ and may be sold commercially, and may be aggregated with this
+ software.
+
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ PURPOSE.
+
+* ruby home-page
+
+ The URL of the ruby home-page is:
+
+ http://www.netlab.co.jp/ruby/
+
+* The Author
+
+Feel free to send comments and bug reports to the author. Here is the
+author's latest mail address:
+
+ matz@netlab.co.jp
+
+-------------------------------------------------------
+created at: Thu Aug 3 11:57:36 JST 1995
+Local variables:
+mode: indented-text
+end:
View
1,064 README.EXT
@@ -0,0 +1,1064 @@
+.\" README.EXT - -*- Text -*- created at: Mon Aug 7 16:45:54 JST 1995
+
+This document explains how to make extention modules for ruby.
+
+1��Basic knowledge
+
+In C, variables have types and data do not have types. In contrast,
+ruby variables do not have static type and data themselves have
+types. So, data need to be converted across the languages.
+
+Data in ruby represented C type `VALUE'. Each VALUE data have its
+data-type.
+
+ruby�Υǡ�����VALUE�Ȥ���C�η���ɽ������ޤ���VALUE���Υǡ�
+���Ϥ��Υǡ��������פ�ʬ���ΤäƤ��ޤ������Υǡ��������פ�
+�����Τϥǡ���(���֥�������)�μºݤι�¤���̣���Ƥ��ơ�ruby
+�Υ��饹�ȤϤޤ���ä���ΤǤ���
+
+To retrieve an C data from the VALUE, you need to:
+
+ (1) Identify VALUE's data type
+ (2) Convert VALUE into C data
+
+Converting to wrong data type may cause serious promblems.
+
+
+1.1 Data-types
+
+Ruby interpreter has data-types as below:
+
+ T_NIL nil
+ T_OBJECT ordinaly object
+ T_CLASS class
+ T_MODULE module
+ T_FLOAT floating point number
+ T_STRING string
+ T_REGEXP regular expression
+ T_ARRAY array
+ T_FIXNUM Fixnum(31bit integer)
+ T_HASH assosiative array
+ T_STRUCT (ruby) structure
+ T_BIGNUM multi precision integer
+ T_TRUE true
+ T_FALSE false
+ T_DATA data
+
+Otherwise, there are several other types used internally:
+
+ T_ICLASS
+ T_MATCH
+ T_VARMAP
+ T_SCOPE
+ T_NODE
+
+Most of the types are represented by C structures.
+
+1.2 Check Data Type of the VALUE
+
+The macro TYPE() defined in ruby.h shows data-type of the VALUE.
+TYPE() returns the constant number T_XXXX described above. To handle
+data-types, the code will be like:
+
+ switch (TYPE(obj)) {
+ case T_FIXNUM:
+ /* process Fixnum */
+ break;
+ case T_STRING:
+ /* process String */
+ break;
+ case T_ARRAY:
+ /* process Array */
+ break;
+ default:
+ /* raise exception */
+ Fail("not valid value");
+ break;
+ }
+
+There is the data-type check function.
+
+ void Check_Type(VALUE value, int type)
+
+It raises an exception, if the VALUE does not have the type specified.
+
+There are faster check-macros for fixnums and nil.
+
+ FIXNUM_P(obj)
+ NIL_P(obj)
+
+1.3 Convert VALUE into C data
+
+�ǡ��������פ�T_NIL, T_FALSE, T_TRUE�Ǥ�������ǡ����Ϥ��줾
+��nil, FALSE, TRUE�Ǥ������Υǡ��������פΥ��֥������ȤϤҤ�
+�Ĥ��Ĥ���¸�ߤ��ޤ���
+
+�ǡ��������פ�T_FIXNUM�λ��������31bit�Υ�������������
+����FIXNUM��C�������Ѵ����뤿��ˤϥޥ����FIX2INT()�פ��
+���ޤ������줫�顤FIXNUM�˸¤餺ruby�Υǡ����������Ѵ�����
+��NUM2INT()�פȤ����ޥ�������ޤ������Υޥ���ϥǡ�������
+�פΥ���å�̵���ǻȤ��ޤ�(�����Ѵ��Ǥ��ʤ����ˤ��㳰��
+ȯ�����)��
+
+����ʳ��Υǡ��������פ��б�����C�ι�¤�Τ�����ޤ����б���
+�빽¤�ΤΤ���VALUE�Ϥ��Τޤޥ��㥹��(���Ѵ�)����й�¤�Τ�
+�ݥ��󥿤��Ѵ��Ǥ��ޤ���
+
+��¤�Τϡ�struct RXxxxx�פȤ���̾���ruby.h��������Ƥ���
+�����㤨��ʸ����ϡ�struct RString�פǤ����ºݤ˻Ȥ���ǽ���
+����Τ�ʸ��������󤯤餤��Ȼפ��ޤ���
+
+ruby.h�ǤϹ�¤�Τإ��㥹�Ȥ���ޥ�����RXXXXX()��(�����ʸ
+��ˤ������)�Ȥ���̾����󶡤���Ƥ��ޤ�(��: RSTRING())��
+
+�㤨�С�ʸ����str��Ĺ������뤿��ˤϡ�RSTRING(str)->len�פ�
+����ʸ����str��char*�Ȥ�����뤿��ˤϡ�RSTRING(str)->ptr��
+�Ȥ��ޤ�������ξ��ˤϡ����줾���RARRAT(str)->len�ס�
+��RARRAT(str)->ptr�פȤʤ�ޤ���
+
+ruby�ι�¤�Τ�ľ�ܥ�������������˵���Ĥ��ʤ���Фʤ�ʤ���
+�Ȥϡ������ʸ����ι�¤�Τ���Ȥϻ��Ȥ������ǡ�ľ���ѹ���
+�ʤ����ȤǤ���ľ���ѹ�������硤���֥������Ȥ����Ƥ�������
+�Ȥ�ʤ��ʤäơ��פ�̥Х��θ���ˤʤ�ޤ���
+
+1.4 Convert C data into VALUE
+
+VALUE�μºݤι�¤��
+
+ * FIXNUM��
+
+ 1bit�����եȤ��ơ�LSB��Ω�Ƥ롥
+
+ * ����¾�Υݥ��󥿤ξ��
+
+ ���Τޤ�VALUE�˥��㥹�Ȥ��롥
+
+�ȤʤäƤ��ޤ�����äơ�LSB�����å������VALUE��FIXNUM����
+�����狼��櫓�Ǥ�(�ݥ��󥿤�LSB��Ω�äƤ��ʤ����Ȥ��ꤷ��
+����)��
+
+�Ǥ����顤FIXNUM�ʳ���ruby�Υ��֥������Ȥι�¤�Τ�ñ��VALUE
+�˥��㥹�Ȥ�������VALUE���Ѵ�����ޤ����������Ǥ�դι�¤
+�Τ�VALUE�˥��㥹�Ƚ����櫓�ǤϤ���ޤ��󡥥��㥹�Ȥ����
+��ruby���ΤäƤ��빽¤��(ruby.h��������Ƥ���struct RXxxx
+�Τ��)����ˤ��Ƥ����Ƥ��������
+
+FIXNUM�˴ؤ��Ƥ��Ѵ��ޥ�����ͳ����ɬ�פ�����ޤ���C�����
+����VALUE���Ѵ�����ޥ���ϰʲ��Τ�Τ�����ޤ���ɬ�פ˱���
+�ƻȤ�ʬ���Ƥ��������
+
+ INT2FIX() ��Ȥ����31bit����˼�ޤ��
+ INT2NUM() Ǥ�դ�����VALUE��
+
+INT2NUM()�����FIXNUM���ϰϤ˼�ޤ�ʤ���硤Bignum���Ѵ�
+���Ƥ���ޤ�(���������٤�)��
+
+1.5 Manipulate ruby data
+
+�����Ҥ٤��̤ꡤruby�ι�¤�Τ򥢥���������������Ƥι�����
+�Ԥ����Ȥϴ�����ޤ��󡥤ǡ�ruby�Υǡ�����������ˤ�
+ruby���Ѱդ��Ƥ���ؿ���Ѥ��Ƥ��������
+
+�����ǤϤ�äȤ�Ȥ���Ǥ���ʸ������������/�����
+���ؿ�򤢤��ޤ�(���ǤϤʤ��Ǥ�)��
+
+ String funtions
+
+ str_new(char *ptr, int len)
+
+ Creates a new ruby string.
+
+ str_new2(char *ptr)
+
+ Creates a new ruby string from C string. This is equivalent to
+ str_new(ptr, strlen(ptr)).
+
+ str_cat(VALUE str, char *ptr, int len)
+
+ Appends len bytes data from ptr to the ruby string.
+
+ Array functions
+
+ ary_new()
+
+ Creates an array with no element.
+
+ ary_new2(int len)
+
+ Creates an array with no element, with allocating internal buffer
+ for len elements.
+
+ ary_new3(int n, ...)
+
+ Creates an n-elements array from arguments.
+
+ ary_new4(int n, VALUE *elts)
+
+ Creates an n-elements array from C array.
+
+ ary_push(VALUE ary)
+ ary_pop(VALUE ary, VALUE val)
+ ary_shift(VALUE ary)
+ ary_unshift(VALUE ary, VALUE val)
+ ary_entry(VALUE ary, int idx)
+
+ Array operations. The first argument to each functions must be an
+ array. They may dump core if other types given.
+
+2. Extend ruby with C
+
+����Ū��ruby�ǽ񤱤뤳�Ȥ�C�Ǥ�񤱤ޤ���ruby���Τ�Τ�C�ǵ�
+�Ҥ���Ƥ����Ǥ����顤����Ȥ���������ʤ�Ǥ����ɡ�������
+��ruby�γ�ĥ�˻Ȥ����Ȥ�¿�������ͽ¬����뵡ǽ���濴�˾�
+�𤷤ޤ���
+
+2.1 Add new features to ruby
+
+ruby���󶡤���Ƥ���ؿ��Ȥ���ruby���󥿥ץ꥿�˿�������ǽ
+���ɲä��뤳�Ȥ��Ǥ��ޤ���ruby�Ǥϰʲ��ε�ǽ���ɲä���ؿ�
+�󶡤���Ƥ��ޤ���
+
+ * ���饹���⥸�塼��
+ * �᥽�åɡ��ðۥ᥽�åɤʤ�
+ * ���
+
+�ǤϽ�˾Ҳ𤷤ޤ���
+
+2.1.1 Class/module definition
+
+���饹��⥸�塼��������뤿��ˤϡ��ʲ��δؿ��Ȥ��ޤ���
+
+ VALUE rb_define_class(char *name, VALUE super)
+ VALUE rb_define_module(char *name)
+
+�����δؿ�Ͽ����������줿���饹��⥸�塼����֤��ޤ���
+�᥽�åɤ��������ˤ������ͤ�ɬ�פʤΤǡ��ۤȤ�ɤξ��
+������ͤ��ѿ�˳�Ǽ���Ƥ���ɬ�פ�����Ǥ��礦��
+
+2.1.2 Method/singleton method definition
+
+�᥽�åɤ��ðۥ᥽�åɤ�������ˤϰʲ��δؿ��Ȥ��ޤ���
+
+ void rb_define_method(VALUE class, char *name,
+ VALUE (*func)(), int argc)
+
+ void rb_define_singleton_method(VALUE object, char *name,
+ VALUE (*func)(), int argc)
+
+
+ǰ�Τ����������ȡ��ðۥ᥽�åɡפȤϡ���������Υ��֥�����
+�Ȥ��Ф��Ƥ��ͭ��ʥ᥽�åɤǤ���ruby�ǤϤ褯Smalltalk�ˤ�
+���륯�饹�᥽�åɤȤ��ơ����饹���Ф����ðۥ᥽�åɤ��Ȥ��
+�ޤ���
+
+�����δؿ�� argc�Ȥ�������C�δؿ���Ϥ������ο�(��
+���)����ޤ���argc����λ��ϴؿ�˰��Ϥ����ο���̣
+���ޤ���16�İʾ�ΰ��ϻȤ��ޤ���(�����פ�ޤ����͡�����
+�ʤ�)��
+
+argc����λ��ϰ��ο�ǤϤʤ����������ꤷ�����Ȥˤʤ�ޤ���
+argc��-1�λ��ϰ��������������Ϥ���ޤ���argc��-2�λ��ϰ�
+���ruby������Ȥ����Ϥ���ޤ���
+
+�᥽�åɤ�������ؿ�Ϥ⤦��Ĥ���ޤ����ҤȤĤ�private��
+���åɤ�������ؿ�ǡ�����rb_define_method()��Ʊ���Ǥ���
+
+ void rb_define_private_method(VALUE class, char *name,
+ VALUE (*func)(), int argc)
+
+private�᥽�åɤȤϴؿ����Ǥ����ƤӽФ����Ȥν���ʤ��᥽��
+�ɤǤ���
+
+�⤦�ҤȤĤϥ⥸�塼��ؿ���������ΤǤ����⥸�塼��ؿ�
+�Ȥϥ⥸�塼����ðۥ᥽�åɤǤ��ꡤƱ����private�᥽�åɤ�
+�⤢���ΤǤ�����򤢤����Math�⥸�塼���sqrt()�ʤɤ�����
+���ޤ������Υ᥽�åɤ�
+
+ Math.sqrt(4)
+
+�Ȥ�������Ǥ�
+
+ include Math
+ sqrt(4)
+
+�Ȥ�������Ǥ�Ȥ��ޤ����⥸�塼��ؿ��������ؿ�ϰʲ���
+�̤�Ǥ���
+
+ void rb_define_module_function(VALUE module, char *name,
+ VALUE (*func)(), int argc)
+
+�ؿ�Ū�᥽�å�(Kernel�⥸�塼���privaet method)�������뤿
+��δؿ�ϰʲ����̤�Ǥ���
+
+ void rb_define_global_function(char *name, VALUE (*func)(), int argc)
+
+
+2.1.3 Constant definition
+
+��ĥ�⥸�塼�뤬ɬ�פ����Ϥ��餫���������Ƥ��������ɤ�
+�Ǥ��礦������������ؿ����Ĥ���ޤ���
+
+ void rb_define_const(VALUE class, char *name, VALUE val)
+ void rb_define_global_const(char *name, VALUE val)
+
+��Ԥ�����Υ��饹/�⥸�塼���°���������������Ρ���
+�Ԥϥ����Х�������������ΤǤ���
+
+2.2 Use ruby features from C
+
+��ˡ�1.5 ruby�Υǡ���������٤ǰ���Ҳ𤷤��褦�ʴؿ��
+�Ȥ��С�ruby�ε�ǽ��¸����Ƥ���ؿ��ľ�ܸƤӽФ����Ȥ�����
+�ޤ���
+
+# ���Τ褦�ʴؿ�ΰ���ɽ�Ϥ��ޤΤȤ�����ޤ��󡥥�������
+# �뤷���ʤ��Ǥ��͡�
+
+����ʳ��ˤ�ruby�ε�ǽ��ƤӽФ���ˡ�Ϥ����Ĥ�����ޤ���
+
+2.2.1 ruby�Υץ�����eval����
+
+C����ruby�ε�ǽ��ƤӽФ���äȤ��ñ����ˡ�Ȥ��ơ�ʸ�����
+Ϳ����줿ruby�Υץ�����ɾ�����ؿ����ޤ���
+
+ VALUE rb_eval_string(char *str)
+
+����ɾ��ϸ��ߤδĶ��ǹԤ��ޤ����Ĥޤꡤ���ߤΥ������ѿ�
+�ʤɤ��Ѥ��ޤ���
+
+2.2.2 ID or Symbol
+
+C����ʸ������ͳ������ruby�Υ᥽�åɤ�ƤӽФ����Ȥ�Ǥ���
+����������ˡ�ruby���󥿥ץ꥿��ǥ᥽�åɤ��ѿ�̾����ꤹ��
+���˻Ȥ��Ƥ���ID�ˤĤ���������Ƥ����ޤ��礦��
+
+ID�Ȥ��ѿ�̾���᥽�å�̾��ɽ�����Ǥ���ruby����Ǥ�
+
+ :���̻�
+
+�ǥ��������Ǥ��ޤ���C���餳��������뤿��ˤϴؿ�
+
+ rb_intern(char *name)
+
+��Ȥ��ޤ����ޤ���ʸ��α黻�ҤϤ���ʸ���ɤ����Τޤޥ���
+�ܥ�ˤʤäƤ��ޤ���
+
+2.2.3 Invoke ruby method from C
+
+C����ʸ������ͳ������ruby�Υ᥽�åɤ�ƤӽФ�����ˤϰʲ�
+�δؿ��Ȥ��ޤ���
+
+ VALUE rb_funcall(VALUE recv, ID mid, int argc, ...)
+
+���δؿ�ϥ��֥�������recv��mid�ǻ��ꤵ���᥽�åɤ�Ƥӽ�
+���ޤ���
+
+2.2.4 �ѿ�/���򻲾�/��������
+
+C����ؿ��Ȥäƻ��ȡ������Ǥ���Τϡ����饹�����󥹥�
+���ѿ�Ǥ�������ѿ�ϰ���Τ�Τ�C������ѿ�Ȥ��ƥ�����
+���Ǥ��ޤ����������ѿ�򻲾Ȥ�����ˡ�ϸ��Ƥ��ޤ���
+
+���֥������ȤΥ��󥹥����ѿ�򻲾ȡ���������ؿ�ϰʲ�����
+��Ǥ���
+
+ VALUE rb_ivar_get(VALUE obj, ID id)
+ VALUE rb_ivar_set(VALUE obj, ID id, VALUE val)
+
+id��rb_intern()��������Τ�ȤäƤ��������
+
+���饹���򻲾Ȥ���ˤϰʲ��δؿ��ȤäƤ��������
+
+ VALUE rb_const_get(VALUE obj, ID id)
+
+���饹���򿷤��������뤿��ˤϡ�2.1.3 ������٤ǾҲ�
+��Ƥ���ؿ��ȤäƤ��������
+
+3. Informatin sharing between ruby and C
+
+C����ruby�δ֤Ǿ����ͭ������ˡ�ˤĤ��Ʋ��⤷�ޤ���
+
+3.1 Ruby constant that C���黲�ȤǤ���ruby�����
+
+Following ruby constants can be referred from C.
+
+ TRUE
+ FALSE
+
+Boolean values. FALSE is false in the C also (i.e. 0).
+
+ Qnil
+
+Ruby nil in C scope.
+
+3.2 Global variables shared between C and ruby
+
+C��ruby������ѿ��Ȥäƾ����ͭ�Ǥ��ޤ�����ͭ�Ǥ������
+�ѿ�ˤϤ����Ĥ��μ��ब����ޤ������Τʤ��Ǥ�äȤ��ɤ��Ȥ�
+���Ȼפ���Τ�rb_define_variable()�Ǥ���
+
+ void rb_define_variable(char *name, VALUE *var)
+
+���δؿ��ruby��C�ȤǶ�ͭ��������ѿ�������ޤ����ѿ�̾��
+`$'�ǻϤޤ�ʤ����ˤϼ�ưŪ���ɲä���ޤ��������ѿ���ͤ���
+������ȼ�ưŪ��ruby���б������ѿ���ͤ��Ѥ��ޤ���
+
+�ޤ�ruby¦����Ϲ����Ǥ��ʤ��ѿ�⤢��ޤ�������read only��
+�ѿ�ϰʲ��δؿ�������ޤ���
+
+ void rb_define_readonly_variable(char *name, VALUE *var)
+
+������ѿ��¾��hook��Ĥ�������ѿ�����Ǥ��ޤ���hook�դ�
+������ѿ�ϰʲ��δؿ���Ѥ��������ޤ���hook�դ�����ѿ��
+�ͤλ��Ȥ������hook�ǹԤ�ɬ�פ�����ޤ���
+
+ void rb_define_hooked_variable(char *name, VALUE *var,
+ VALUE (*getter)(), VALUE (*setter)())
+
+���δؿ��C�δؿ�ˤ�ä�hook�ΤĤ���줿����ѿ��������
+�����ѿ���Ȥ��줿���ˤϴؿ�getter�����ѿ���ͤ����åȤ���
+�����ˤϴؿ�setter���ƤФ�롥hook����ꤷ�ʤ�����getter��
+setter��0����ꤷ�ޤ���
+
+# getter��setter��0�ʤ��rb_define_variable()��Ʊ���ˤʤ롥
+
+���줫�顤C�δؿ�ˤ�äƼ¸������ruby������ѿ��������
+�ؿ����ޤ���
+
+ void rb_define_virtual_variable(char *name,
+ VALUE (*getter)(), VALUE (*setter)())
+
+���δؿ�ˤ�ä������줿ruby������ѿ���Ȥ��줿���ˤ�
+getter�����ѿ���ͤ����åȤ��줿���ˤ�setter���ƤФ�ޤ���
+
+The prototypes of the getter and setter functions are as following:
+
+ (*getter)(ID id, void *data, struct global_entry* entry);
+ (*setter)(VALUE val, ID id, void *data, struct global_entry* entry);
+
+3.3 Encapsulate C data into ruby object
+
+C������������줿�ǡ���(��¤��)��ruby�Υ��֥������ȤȤ���
+��갷��������礬���ꤨ�ޤ������Τ褦�ʾ��ˤϡ�Data�Ȥ���
+ruby���֥������Ȥ�C�ι�¤��(�ؤΥݥ���)�򤯤�ळ�Ȥ�ruby
+���֥������ȤȤ��Ƽ�갷����褦�ˤʤ�ޤ���
+
+Data���֥������Ȥ������ƹ�¤�Τ�ruby���֥������Ȥ˥��ץ���
+�����뤿��ˤϡ��ʲ��Υޥ����Ȥ��ޤ���
+
+ Data_Wrap_Struct(class,mark,free,ptr)
+
+���Υޥ��������ͤ������줿Data���֥������ȤǤ���
+
+class�Ϥ���Data���֥������ȤΥ��饹�Ǥ���ptr�ϥ��ץ��벽����
+C�ι�¤�ΤؤΥݥ��󥿤Ǥ���mark�Ϥ��ι�¤�Τ�ruby�Υ��֥���
+���Ȥؤλ��Ȥ�������˻Ȥ��ؿ�Ǥ������Τ褦�ʻ��Ȥ�ޤޤʤ�
+���ˤ�0����ꤷ�ޤ���
+
+# ���Τ褦�ʻ��Ȥϴ�����ޤ���
+
+free�Ϥ��ι�¤�Τ��⤦���פˤʤä����˸ƤФ��ؿ�Ǥ�������
+�ؿ�����١������쥯������ƤФ�ޤ���
+
+C�ι�¤�Τγ����Data���֥������Ȥ�����Ʊ���˹Ԥ��ޥ����
+���ưʲ��Τ�Τ��󶡤���Ƥ��ޤ���
+
+ Data_Make_Struct(class, type, mark, free, sval)
+
+���Υޥ��������ͤ������줿Data���֥������ȤǤ���
+
+class, mark, free��Data_Wrap_Struct��Ʊ��Ư���򤷤ޤ���type
+�ϳ����Ƥ�C��¤�Τη��Ǥ��������Ƥ�줿��¤�Τ��ѿ�sval
+����������ޤ��������ѿ�η��� (type*) �Ǥ���ɬ�פ�����ޤ���
+
+Data���֥������Ȥ���ݥ��󥿤���Ф��Τϰʲ��Υޥ�����Ѥ�
+�ޤ���
+
+ Data_Get_Struct(obj, type, sval)
+
+C�ι�¤�ΤؤΥݥ��󥿤��ѿ�sval����������ޤ���
+
+������Data�λȤ���Ϥ��ä�ʬ����ˤ����Τǡ�����������
+����򻲾Ȥ��Ƥ��������
+
+4��Example - Create dbm module
+
+�����ޤǤ�����ǤȤꤢ������ĥ�⥸�塼��Ϻ���Ϥ��Ǥ���
+ruby��ext�ǥ��쥯�ȥ�ˤ��Ǥ˴ޤޤ�Ƥ���dbm�⥸�塼������
+�����ʳ�Ū��������ޤ���
+
+(1) make the directory
+
+ % mkdir ext/dbm
+
+ruby��Ÿ�������ǥ��쥯�ȥ�β���ext�ǥ��쥯�ȥ����˳�ĥ��
+���塼���ѤΥǥ��쥯�ȥ����ޤ���̾���Ŭ������ǹ�����
+����
+
+(2) create MANIFEST file
+
+ % cd ext/dbm
+ % touch MANIFEST
+
+��ĥ�⥸�塼��Υǥ��쥯�ȥ�β��ˤ�MANIFEST�Ȥ����ե����뤬
+ɬ�פʤΤǡ��Ȥꤢ������Υե�������äƤ����ޤ�����Ǥ���
+�ե�����ˤ�ɬ�פʥե�����������뤳�Ȥˤʤ�ޤ���
+
+MANIFEST�Ȥ����ե�����ϡ�make�λ��˥ǥ��쥯�ȥ꤬��ĥ�⥸�塼
+���ޤ�Ǥ��뤫�ɤ���Ƚ�ꤹ�뤿��˻Ȥ���Ƥ��ޤ���
+
+(3) design the library
+
+�ޤ�������ʤ�Ǥ����ɡ��ɤ�������ǽ��¸����뤫�ɤ����ޤ���
+�פ���ɬ�פ�����ޤ����ɤ�ʥ��饹��Ĥ��뤫�����Υ��饹�ˤ�
+�ɤ�ʥ᥽�åɤ����뤫�����饹���󶡤������ʤɤˤĤ����߷�
+���ޤ���dbm���饹�ˤĤ��Ƥ�ext/dbm.doc�򻲾Ȥ��Ƥ��������
+
+(4) write C code.
+
+��ĥ�⥸�塼�����ΤȤʤ�C���Υ�������񤭤ޤ���C���Υ���
+�����ҤȤĤλ��ˤϡ֥⥸�塼��̾.c�פ���֤��ɤ��Ǥ��礦��C
+���Υ�������ʣ��ξ��ˤϵդˡ֥⥸�塼��̾.c�פȤ����ե�
+����̾���򤱤�ɬ�פ�����ޤ������֥������ȥե�����ȥ⥸�塼
+�����������Ū���������֥⥸�塼��̾.o�פȤ����ե�����
+�Ȥ����ͤ��뤫��Ǥ���
+
+ruby�ϳ�ĥ�⥸�塼�����ɤ�����ˡ�Init_�⥸�塼��̾�פ�
+�����ؿ��ưŪ�˼¹Ԥ��ޤ���dbm�⥸�塼��ξ���Init_dbm��
+�Ǥ������δؿ����ǥ��饹���⥸�塼�롤�᥽�åɡ����ʤɤ�
+����Ԥ��ޤ���dbm.c���������Ѥ��ޤ���
+
+--
+Init_dbm()
+{
+ /* DBM���饹�������� */
+ cDBM = rb_define_class("DBM", cObject);
+ /* DBM��Enumerate�⥸�塼��򥤥󥯥롼�ɤ��� */
+ rb_include_module(cDBM, mEnumerable);
+
+ /* DBM���饹�Υ��饹�᥽�å�open(): ����C������Ǽ�� */
+ rb_define_singleton_method(cDBM, "open", fdbm_s_open, -1);
+
+ /* DBM���饹�Υ᥽�å�close(): ���Ϥʤ� */
+ rb_define_method(cDBM, "close", fdbm_close, 0);
+ /* DBM���饹�Υ᥽�å�[]: ����1�� */
+ rb_define_method(cDBM, "[]", fdbm_fetch, 1);
+ :
+
+ /* DBM�ǡ������Ǽ���륤�󥹥����ѿ�̾�Τ����ID */
+ id_dbm = rb_intern("dbm");
+}
+--
+
+DBM�⥸�塼���dbm�Υǡ������б����륪�֥������Ȥˤʤ�Ϥ���
+�����顤C�������dbm��ruby������˼�����ɬ�פ�����ޤ���
+
+
+dbm.c�Ǥ�Data_Make_Struct��ʲ��Τ褦�˻ȤäƤ��ޤ���
+
+--
+struct dbmdata {
+ int di_size;
+ DBM *di_dbm;
+};
+
+
+obj = Data_Make_Struct(class,struct dbmdata,0,free_dbm,dbmp);
+--
+
+�����Ǥ�dbmstruct��¤�ΤؤΥݥ��󥿤�Data�˥��ץ��벽���Ƥ�
+�ޤ���DBM*��ľ�ܥ��ץ��벽���ʤ��Τ�close()�������ν�����
+���ƤΤ��ȤǤ���
+
+Data���֥������Ȥ���dbmstruct��¤�ΤΥݥ��󥿤���Ф�����
+�˰ʲ��Υޥ����ȤäƤ��ޤ���
+
+--
+#define GetDBM(obj, dbmp) {\
+ Data_Get_Struct(obj, struct dbmdata, dbmp);\
+ if (dbmp->di_dbm == 0) closed_dbm();\
+}
+--
+
+���ä�ʣ���ʥޥ���Ǥ������פ����dbmdata��¤�ΤΥݥ���
+�μ��Ф��ȡ�close����Ƥ��뤫�ɤ����Υ���å���ޤȤ�Ƥ�
+�����Ǥ���
+
+DBM���饹�ˤϤ�������᥽�åɤ�����ޤ�����ʬ�ह���3�����
+���μ����ޤ����ҤȤĤϰ��ο����Τ�Τǡ����
+���Ƥ�delete�᥽�åɤ�����ޤ���delete�᥽�åɤ����Ƥ���
+fdbm_delete()�Ϥ��Τ褦�ˤʤäƤ��ޤ���
+
+--
+static VALUE
+fdbm_delete(obj, keystr)
+ VALUE obj, keystr;
+{
+ :
+}
+--
+
+���ο����Υ����פ���1���self����2���ʹߤ��᥽�å�
+�ΰ��Ȥʤ�ޤ���
+
+���ο�����Τ�Τ�C������Ǽ���Τ�ruby������Ǽ�
+���ΤȤ�����ޤ���dbm�⥸�塼�����ǡ�C������Ǽ����
+��DBM�Υ��饹�᥽�åɤǤ���open()�Ǥ�����������Ƥ����
+��fdbm_s_open()�Ϥ����ʤäƤ��ޤ���
+
+--
+static VALUE
+fdbm_s_open(argc, argv, class)
+ int argc;
+ VALUE *argv;
+ VALUE class;
+{
+ :
+ if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
+ mode = 0666; /* default value */
+ }
+ :
+}
+--
+
+���Υ����פδؿ����1���Ϳ����줿���ο���2���Ϳ��
+��줿�������äƤ�������ˤʤ�ޤ���self����3���Ȥ���Ϳ
+�����ޤ���
+
+���������Ϳ����줿������Ϥ��뤿��δؿ�open()�Ǥ�Ȥ�
+��Ƥ���rb_scan_args()�Ǥ�����3���˻��ꤷ���ե����ޥåȤ�
+��������4�ѿ�ʹߤ˻��ꤷ���ѿ���ͤ��������Ƥ���ޤ�������
+�ե����ޥåȤϡ���1ʸ���ܤ���ά�Ǥ��ʤ����ο���2ʸ���ܤ�
+��ά�Ǥ�����ο���3ʸ���ܤ��б�������̵꤬�����ޤ�ΰ�
+����뤫�ɤ����򼨤�"*"�Ǥ���2ʸ���ܤ�3ʸ���ܤϾ�ά�Ǥ���
+����dbm.c����Ǥϡ��ե����ޥåȤ�"11"�Ǥ����顤���Ϻ���1��
+�ǡ�2�Ĥޤǵ���Ȥ�����̣�ˤʤ�ޤ�����ά����Ƥ������
+�ѿ���ͤ�nil(C���Υ�٥�Ǥ�Qnil)�ˤʤ�ޤ���
+
+ruby������ǰ�������Τ�indexes������ޤ�������Ϥ�
+���Ǥ���
+
+--
+static VALUE
+fdbm_indexes(obj, args)
+ VALUE obj;
+ struct RArray *args;
+{
+ :
+}
+--
+
+��1����self����2����ruby������Ǥ��������Ǥϥ��㥹�Ȥ�
+�餹���� struct RArray* �Ǽ�Ƥ��ޤ�����VALUE�Ǥ�Ʊ������
+�Ǥ���
+
+** ��ջ��
+
+ruby�ȶ�ͭ�Ϥ��ʤ���ruby�Υ��֥������Ȥ��Ǽ�����ǽ��Τ���
+C������ѿ�ϰʲ��δؿ��Ȥä�ruby���󥿥ץ꥿���ѿ��¸��
+�򶵤��Ƥ����Ƥ���������Ǥʤ���GC�ǥȥ�֥�򵯤����ޤ���
+
+ void rb_global_variable(VALUE *var)
+
+(5) prepare extconf.rb
+
+�⤷�ǥ��쥯�ȥ�ˡ�extconf.rb�פȤ����ե����뤬¸�ߤ���С�
+make���˼¹Ԥ���ޤ����ʤ����Ŭ���Makefile��������ޤ���
+
+extconf.rb�ϥ⥸�塼��Υ���ѥ����ɬ�פʾ��Υ���å��ʤ�
+��Ԥ����Ȥ���Ū�Ǥ���extconf.rb����Ǥϰʲ���ruby�ؿ��Ȥ�
+���Ȥ�����ޤ���
+
+ have_library(lib, func): �饤�֥���¸�ߥ���å�
+ have_func(func): �ؿ��¸�ߥ���å�
+ have_header(header): �إå�ե������¸�ߥ���å�
+ create_makefile(target): Makefile����
+
+�ʲ����ѿ��Ȥ����Ȥ��Ǥ��ޤ���
+
+ $CFLAGS: ����ѥ�������ɲ�Ū�˻��ꤹ��ե饰(-I�ʤ�)
+ $LDFLAGS: ��󥯻����ɲ�Ū�˻��ꤹ��ե饰(-L�ʤ�)
+
+�⥸�塼��򥳥�ѥ��뤹���郎·��ʤ������Υ⥸�塼��ϥ�
+��ѥ��뤷�ʤ����ˤ�create_makefile��ƤФʤ����Makefile��
+�����줺������ѥ����Ԥ��ޤ���
+
+(6) prepare depend (optional)
+
+�⤷���ǥ��쥯�ȥ��depend�Ȥ����ե����뤬¸�ߤ���С�
+Makefile����¸�ط������å����Ƥ���ޤ���
+
+ % gcc -MM *.c > depend
+
+�ʤɤǺ�뤳�Ȥ�����ޤ������ä�»��̵���Ǥ��礦��
+
+(7) MANIFEST�ե�����˥ե�����̾�������
+
+ % ls > MANIFEST
+ % vi MANIFEST
+
+*.o, *~�ʤ���ɬ�פʥե�����ʳ���MANIFEST���ɲä��Ƥ����ޤ���
+make���ˤ�MANIFEST�����Ƥϻ��Ȥ��ޤ���Τǡ���ΤޤޤǤ�����
+�ϵ����ޤ��󤬡��ѥå������󥰤λ��˻��Ȥ��뤳�Ȥ�����Τȡ�
+ɬ�פʥե��������̤Ǥ���Τǡ��Ѱդ��Ƥ��������ɤ��Ǥ���
+����
+
+(8) make
+
+ruby�Υǥ��쥯�ȥ��make��¹Ԥ����Makefile��������make��
+ɬ�פˤ�äƤϤ��Υ⥸�塼���ruby�ؤΥ�󥯤ޤǼ�ưŪ�˼¹�
+���Ƥ���ޤ���extconf.rb��񤭴�����ʤɤ���Makefile�κ���
+��ɬ�פʻ��Ϥޤ�ruby�ǥ��쥯�ȥ��make���Ƥ��������
+
+(9) debug
+
+�ޤ����ǥХå����ʤ���ư���ʤ��Ǥ��礦�͡�ext/Setup�˥ǥ���
+���ȥ�̾��񤯤���Ū�˥�󥯤���ΤǥǥХå����Ȥ���褦�ˤ�
+��ޤ�������ʬ����ѥ��뤬�٤��ʤ�ޤ����ɡ�
+
+(10) done, now you have the extension module
+
+��Ϥ��ä���Ȥ��ʤꡤ��������ʤꡤ���ʤꡤ����ͳ�ˤ�
+�Ȥ����������ruby�κ�Ԥϳ�ĥ�⥸�塼��˴ؤ��ư��ڤθ����
+��ĥ���ޤ���
+
+Appendix A. ruby�Υ����������ɤ�ʬ��
+
+ruby�Υ������Ϥ����Ĥ���ʬ�ह�뤳�Ȥ�����ޤ������Τ������
+���饤�֥�����ʬ�ϴ���Ū�˳�ĥ�⥸�塼���Ʊ�������ˤʤ�
+�Ƥ��ޤ��������Υ������Ϻ��ޤǤ�����ǤۤȤ�����Ǥ����
+�פ��ޤ���
+
+coore ruby language
+
+ class.c
+ error.c
+ eval.c
+ gc.c
+ object.c
+ parse.y
+ variable.c
+
+utility functions
+
+ dln.c
+ fnmatch.c
+ glob.c
+ regex.c
+ st.c
+ util.c
+
+ruby interpreter implementation
+
+ dmyext.c
+ inits.c
+ main.c
+ ruby.c
+ version.c
+
+class library
+
+ array.c
+ bignum.c
+ compar.c
+ dir.c
+ enum.c
+ file.c
+ hash.c
+ io.c
+ math.c
+ numeric.c
+ pack.c
+ process.c
+ random.c
+ range.c
+ re.c
+ signal.c
+ sprintf.c
+ string.c
+ struct.c
+ time.c
+
+Appendix B. ��ĥ�Ѵؿ��ե����
+
+C��줫��ruby�ε�ǽ�����Ѥ���API�ϰʲ����̤�Ǥ��롥
+
+** ��
+
+ VALUE
+
+ruby���֥������Ȥ�ɽ�����뷿��ɬ�פ˱����ƥ��㥹�Ȥ����Ѥ��롥
+�Ȥ߹��߷���ɽ������C�η���ruby.h�˵��Ҥ��Ƥ���R�ǻϤޤ빽¤
+�ΤǤ��롥VALUE���򤳤��˥��㥹�Ȥ��뤿���R�ǻϤޤ빽¤��
+̾�������ʸ��ˤ���̾��Υޥ����Ѱդ���Ƥ��롥
+
+** Variables and constants
+
+ Qnil
+
+const: nil object
+
+ TRUE
+
+const: TRUE object(default true value)
+
+ FALSE
+
+const: FALSE object
+
+** C�ǡ����Υ��ץ��벽
+
+ Data_Wrap_Struct(VALUE class, void (*mark)(), void (*free)(), void *sval)
+
+C��Ǥ�դΥݥ��󥿤򥫥ץ��벽����ruby���֥������Ȥ��֤�����
+�Υݥ��󥿤�ruby���饢����������ʤ��ʤä�����free�ǻ��ꤷ��
+�ؿ�ƤФ�롥�ޤ������Υݥ��󥿤λؤ��ǡ�����¾��ruby����
+�������Ȥ�ؤ��Ƥ����硤mark�˻��ꤹ��ؿ�ǥޡ�������ɬ��
+�����롥
+
+ Data_Make_Struct(class, type, mark, free, sval)
+
+type���Υ����malloc�����ѿ�sval�����������塤����򥫥ץ�
+�벽�����ǡ������֤��ޥ���
+
+ Data_Get_Struct(data, type, sval)
+
+data����type���Υݥ��󥿤���Ф��ѿ�sval����������ޥ���
+
+** ���饹/�⥸�塼�����
+
+ VALUE rb_define_class(char *name, VALUE super)
+
+super�Υ��֥��饹�Ȥ��ƿ�����ruby���饹�������롥
+
+ VALUE rb_define_class_under(VALUE module, char *name, VALUE super)
+
+super�Υ��֥��饹�Ȥ��ƿ�����ruby���饹��������module����
+��Ȥ��������롥
+
+ VALUE rb_define_module(char *name)
+
+������ruby�⥸�塼��������롥
+
+ VALUE rb_define_module_under(VALUE module, char *name, VALUE super)
+
+������ruby�⥸�塼���������module�����Ȥ��������롥
+
+ void rb_include_module(VALUE class, VALUE module)
+
+�⥸�塼��򥤥󥯥롼�ɤ��롥class�����Ǥ�module�򥤥󥯥롼
+�ɤ��Ƥ�����ˤϲ��⤷�ʤ�(¿�ť��󥯥롼�ɤζػ�)��
+
+ void rb_extend_object(VALUE object, VALUE module)
+
+���֥������Ȥ�⥸�塼��(��������Ƥ���᥽�å�)�dz�ĥ���롥
+
+** ����ѿ����
+
+ void rb_define_variable(char *name, VALUE *var)
+
+ruby��C�ȤǶ�ͭ���륰���Х��ѿ�������롥�ѿ�̾��`$'�ǻ�
+�ޤ�ʤ����ˤϼ�ưŪ���ɲä���롥name�Ȥ���ruby�μ��̻ҤȤ�
+�Ƶ��ʤ�ʸ��(�㤨��` ')��ޤ���ˤ�ruby�ץ���फ��
+�ϸ����ʤ��ʤ롥
+
+ void rb_define_readonly_variable(char *name, VALUE *var)
+
+ruby��C�ȤǶ�ͭ����read only�Υ����Х��ѿ�������롥read
+only�Ǥ��뤳�Ȱʳ���rb_define_variable()��Ʊ����
+
+ void rb_define_virtual_variable(char *name,
+ VALUE (*getter)(), VALUE (*setter)())
+
+�ؿ�ˤ�äƼ¸������ruby�ѿ�������롥�ѿ���Ȥ��줿��
+�ˤ�getter�����ѿ���ͤ����åȤ��줿���ˤ�setter���ƤФ�롥
+
+ void rb_define_hooked_variable(char *name, VALUE *var,
+ VALUE (*getter)(), VALUE (*setter)())
+
+�ؿ�ˤ�ä�hook�ΤĤ���줿�����Х��ѿ�������롥�ѿ�
+���Ȥ��줿���ˤ�getter�����ؿ���ͤ����åȤ��줿���ˤ�setter
+���ƤФ�롥getter��setter��0����ꤷ�����ˤ�hook����ꤷ��
+���Τ�Ʊ����ˤʤ롥
+
+ void rb_global_variable(VALUE *var)
+
+GC�Τ��ᡤruby�ץ���फ��ϥ�����������ʤ���, ruby���֥���
+���Ȥ�ޤ�����ѿ��ޡ������롥
+
+** ���饹���
+
+ void rb_define_const(VALUE class, char *name, VALUE val)
+
+���饹���������롥
+
+ void rb_define_global_const(char *name, VALUE val)
+
+������������롥
+
+ rb_define_const(cKernal, name, val)
+
+��Ʊ����̣��
+
+** �᥽�å����
+
+ rb_define_method(VALUE class, char *name, VALUE (*func)(), int argc)
+
+�᥽�åɤ������롥argc��self�����ο�argc��-1�λ�,
+�ؿ�ˤϰ��ο�(self��ޤޤʤ�)����1���, �����������2��
+��Ȥ�������Ϳ������(��3����self)��argc��-2�λ�, ��1��
+��self, ��2���args(args�ϰ���ޤ�ruby������)�Ȥ�����
+����Ϳ�����롥
+
+ rb_define_private_method(VALUE class, char *name, VALUE (*func)(), int argc)
+
+private�᥽�åɤ������롥����rb_define_method()��Ʊ����
+
+ rb_define_singleton_method(VALUE class, char *name, VALUE (*func)(), int argc)
+
+�ðۥ᥽�åɤ������롥����rb_define_method()��Ʊ����
+
+ rb_scan_args(int atgc, VALUE *argv, char *fmt, ...)
+
+argc,argv�����Ϳ����줿����ʬ�򤹤롥fmt��ɬ�ܰ��ο�,
+�ղð��ο�, �Ĥ�ΰ����뤫����ꤹ��ʸ�����, "����
+��*"�Ȥ�������Ǥ��롥 2 ���ܤο���"*"�Ϥ��줾���ά��ǽ��
+���롥ɬ�ܰ���Ĥ�ʤ�����0����ꤹ�롥��3���ʹߤ���
+��ؤΥݥ��󥿤�, ��������Ǥ������ѿ�˳�Ǽ����롥�ղð�
+����б�������Ϳ�����Ƥ��ʤ������ѿ��Qnil����������
+�롥
+
+** ruby�᥽�åɸƤӽФ�
+
+ VALUE rb_funcall(VALUE recv, ID mid, int narg, ...)
+
+�᥽�åɸƤӽФ���ʸ���󤫤�mid����뤿��ˤ�rb_intern()��Ȥ���
+
+ VALUE rb_funcall2(VALUE recv, ID mid, int argc, VALUE *argv)
+
+�᥽�åɸƤӽФ�������argc,argv������Ϥ���
+
+ VALUE rb_eval_string(char *str)
+
+ʸ�����ruby�ȥ�����ץȤ��ƥ���ѥ��롦�¹Ԥ��롥
+
+ ID rb_intern(char *name)
+
+ʸ������б�����ID���֤���
+
+ char *rb_id2name(ID id)
+
+ID���б�����ʸ������֤�(�ǥХå���)��
+
+ char *rb_class2name(VALUE class)
+
+class��̾����֤�(�ǥХå���)��class��̾����ʤ����ˤ�,
+������̤ä�̾����ĥ��饹��̾����֤���
+
+** ���󥹥����ѿ�
+
+ VALUE rb_iv_get(VALUE obj, char *name)
+
+obj�Υ��󥹥����ѿ���ͤ���롥`@'�ǻϤޤ�ʤ����󥹥���
+�ѿ�� ruby�ץ���फ�饢�������Ǥ��ʤ��ֱ��줿�ץ��󥹥�
+���ѿ�ˤʤ롥
+
+ VALUE rb_iv_set(VALUE obj, char *name, VALUE val)
+
+obj�Υ��󥹥����ѿ��val�˥��åȤ��롥
+
+** ��湽¤
+
+ VALUE rb_iterate(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)
+
+func2��֥�å��Ȥ������ꤷ, func1�򥤥ƥ졼���Ȥ��ƸƤ֡�
+func1�ˤ� arg1�����Ȥ����Ϥ���, func2�ˤ���1���˥��ƥ졼
+������Ϳ����줿��, ��2����arg2���Ϥ���롥
+
+ VALUE rb_yield(VALUE val)
+
+val���ͤȤ��ƥ��ƥ졼���֥�å���ƤӽФ���
+
+ VALUE rb_rescue(VALUE (*func1)(), void *arg1, VALUE (*func2)(), void *arg2)
+
+�ؿ�func1��arg1����˸ƤӽФ���func1�μ¹�����㳰��ȯ���
+�����ˤ� func2��arg2����Ȥ��ƸƤ֡�����ͤ��㳰��ȯ�����
+���ä�����func1�������, �㳰��ȯ��������ˤ�func2������ͤ�
+���롥
+
+ VALUE rb_ensure(VALUE (*func1)(), void *arg1, void (*func2)(), void *arg2)
+
+�ؿ�func1��arg1����Ȥ��Ƽ¹Ԥ�, �¹Խ�λ��(���Ȥ��㳰��ȯ
+����Ƥ�) func2��arg2����Ȥ��Ƽ¹Ԥ��롥����ͤ�func1����
+���ͤǤ���(�㳰��ȯ������������ʤ�)��
+
+** �㳰�����顼
+
+ void Warning(char *fmt, ...)
+
+verbose����ɸ�२�顼���Ϥ˷ٹ�����ɽ�����롥����printf()��Ʊ����
+
+ void Fail(char *fmt, ...)
+
+�㳰��ȯ������롥����printf()��Ʊ����
+
+ void Fatal(char *fmt, ...)
+
+��̿Ū�㳰��ȯ������롥�̾���㳰����ϹԤʤ�줺, ���󥿡�
+�ץ꥿����λ����(�����ensure�ǻ��ꤵ�줿�����ɤϽ�λ��˼�
+�Ԥ����)��
+
+ void Bug(char *fmt, ...)
+
+���󥿡��ץ꥿�ʤɥץ����ΥХ��Ǥ���ȯ�����Ϥ��Τʤ���
+���λ��Ƥ֡����󥿡��ץ꥿�ϥ������פ�ľ��˽�λ���롥�㳰
+����ϰ��ڹԤʤ��ʤ���
+
+** ruby�ν��¹�
+
+ruby�򥢥ץꥱ����������������ˤϰʲ��Υ��󥿥ե�����
+��Ȥ����̾�γ�ĥ�⥸�塼��ˤ�ɬ�פʤ���
+
+ void ruby_init(int argc, char **argv, char **envp)
+
+ruby���󥿥ץ꥿�ν���Ԥʤ���
+
+ void ruby_run()
+
+ruby���󥿥ץ꥿��¹Ԥ��롥
+
+ void ruby_script(char *name)
+
+ruby�Υ�����ץ�̾($0)�����ꤹ�롥
+
+Appendix B. extconf.rb�ǻȤ���ؿ��
+
+extconf.rb����Ǥ����Ѳ�ǽ�ʥ���ѥ��������å��δؿ�ϰ�
+�����̤�Ǥ��롥
+
+ have_library(lib, func)
+
+�ؿ�func�������Ƥ���饤�֥��lib��¸�ߤ����å����롥��
+���֥�꤬¸�ߤ������TRUE���֤���
+
+ have_func(func)
+
+�ؿ�func��¸�ߤ����å����롥func��ɸ��Ǥϥ�󥯤���ʤ���
+���֥����Τ�ΤǤ�����ˤ����have_library�Ǥ��Υ饤�֥��
+�����å����Ƥ�����ؿ�¸�ߤ����TRUE���֤���
+
+ have_header(header)
+
+�إå�ե������¸�ߤ����å����롥�إå�ե����뤬¸�ߤ���
+��TRUE���֤���
+
+ create_makefile(target)
+
+��ĥ�⥸�塼���Ѥ�Makefile�������롥���δؿ��ƤФʤ����
+���Υ⥸�塼��ϥ���ѥ��뤵��ʤ���target�ϥ⥸�塼��̾��ɽ
+����
+
+/*
+ * Local variables:
+ * fill-column: 60
+ * end:
+ */
View
150 README.jp
@@ -0,0 +1,150 @@
+* Ruby�Ȥ�
+
+Ruby�ϥ���ץ뤫�Ķ��Ϥʥ��֥������Ȼظ�������ץȸ��Ǥ���
+Ruby�Ϻǽ餫����ʥ��֥������Ȼظ����Ȥ����߷פ���Ƥ���
+�����顤���֥������Ȼظ��ץ���ߥ󥰤��ڤ˹Ԥ�������
+����������̾�μ�³�����Υץ���ߥ󥰤��ǽ�Ǥ���
+
+Ruby�ϥƥ����Ƚ���ط���ǽ�Ϥʤɤ�ͥ�졤perl��Ʊ�����餤����
+�Ǥ�������˥���ץ��ʸˡ�ȡ��㳰����䥤�ƥ졼���ʤɤε���
+�ˤ�äơ����ʬ����䤹���ץ���ߥ󥰤�����ޤ���
+
+* Ruby������
+
+ + ����ץ��ʸˡ
+ + ���̤Υ��֥������Ȼظ���ǽ(���饹���᥽�åɥ�����ʤ�)
+ + �ü�ʥ��֥������Ȼظ���ǽ(Mixin, �ðۥ᥽�åɤʤ�)
+ + �黻�ҥ����С�����
+ + �㳰����ǽ
+ + ���ƥ졼���ȥ�������
+ + �����١������쥯��
+ + ����ʥߥå����ǥ��� (�������ƥ����ˤ��)
+ + �ܿ�����⤤��¿����UNIX���ư��
+
+* ����ˡ
+
+** ftp��
+
+�ʲ��ξ��ˤ����Ƥ���ޤ���
+
+ ftp://ftp.netlab.co.jp/pub/lang/ruby/
+
+* �ۡ���ڡ���
+
+ Ruby�Υۡ���ڡ�����URL��
+
+ http://www.netlab.co.jp/ruby/jp/
+
+ �Ǥ���
+
+* �ᥤ��󥰥ꥹ��
+
+ Ruby�˴ؤ������Τ���Υᥤ��󥰥ꥹ�Ȥ��ߤ��ޤ�������
+ �ɥ쥹��
+
+ ruby-list@netlab.co.jp
+
+ �Ǥ������Υ��ɥ쥹�˥ᥤ������С���ưŪ����Ͽ����ޤ���
+
+* ����ѥ��롦���󥹥ȡ���
+
+�ʲ��μ��ǹԤäƤ��������
+
+ 1. configure��¹Ԥ���Makefile�ʤɤ�������
+
+ 2. (ɬ�פʤ��)defines.h���Խ�����
+
+ ¿ʬ��ɬ��̵���Ȼפ��ޤ���
+
+ 3. (ɬ�פʤ��)ext/Setup����Ū�˥�󥯤����ĥ�⥸�塼���
+ ���ꤹ��
+
+ ext/Setup�˵��Ҥ����⥸�塼�����Ū�˥�󥯤���ޤ���
+
+ ����ʥߥå����ǥ��󥰤򥵥ݡ��Ȥ��Ƥ��ʤ��������ƥ�
+ ���Ǥ�Setup��1���ܤΡ�option nodynamic�פȤ����ԤΥ�
+ ���Ȥ򳰤�ɬ�פ�����ޤ����ޤ������Υ������ƥ�����
+ ��ĥ�⥸�塼������Ѥ��뤿��ˤϡ����餫������Ū�˥��
+ �����Ƥ���ɬ�פ�����ޤ���
+
+ 4. make��¹Ԥ��ƥ���ѥ��뤹��
+
+ 5. make test�ǥƥ��Ȥ�Ԥ���
+
+ ��test succeeded�פ�ɽ�����������Ǥ���������ƥ���
+ �����Ƥⴰ�����ݾڤ���Ƥ�����ǤϤ���ޤ���
+
+ 6. make install
+
+�⤷������ѥ�����˥��顼��ȯ��������ˤϥ��顼�Υ��ȥ�
+����OS�μ����ޤ�Ǥ������ܤ�����ݡ��Ȥ��Ԥ���äƤ�
+������¾����Τ���ˤ�ʤ�ޤ���
+
+* �ܿ�
+
+UNIX�Ǥ����configure���ۤȤ�ɤκ��ۤ�ۼ�Ƥ����Ϥ���
+�������פ�̸���Ȥ������ä����(����˰㤤�ʤ�)����Ԥˤ���
+���Ȥ��ݡ��Ȥ���С����Ǥ��뤫���Τ�ޤ���
+
+�������ƥ����ˤ�äȤ��¸����Τ�GC��Ǥ���ruby��GC���о�
+�Υ������ƥ���㤬setjmp()�ˤ�ä���ƤΥ쥸������ jmp_buf��
+��Ǽ���뤳�Ȥȡ�jmp_buf�ȥ����å���32bit���饤����Ȥ����
+���뤳�Ȥ��ꤷ�Ƥ��ޤ����ä���Ԥ��Ω���ʤ������б�����
+��˺���Ǥ��礦����Ԥβ������Ū��ñ�ǡ�gc.c�ǥ����å���
+�ޡ������Ƥ�����ʬ�˥��饤����ȤΥХ��ȿ������餷�ƥޡ�
+�����륳���ɤ��ɲä������ǺѤߤޤ�����defined(THINK_C)�פ�
+����Ƥ�����ʬ�򻲹ͤˤ��Ƥ������
+
+# �ºݤˤ�ruby��Think C�Ǥϥ���ѥ���Ǥ��ޤ���
+
+�쥸����������ɥ�����CPU�Ǥϡ��쥸����������ɥ��򥹥���
+���˥ե�å��夹�륢����֥饳���ɤ��ɲä���ɬ�פ����뤫����
+��ޤ���
+
+* ���۾��
+
+��Ԥϰʲ��ξ��Τ�Ȥ�ruby�����ۤ��ޤ���
+
+ + ������
+
+ ���ۤ������֤�ݻ��¤꼫ͳ�Ǥ����ѹ���Ԥä���Τ��
+ ���ۤ��뤳�Ȥ��˾������ˤϺ�Ԥ�Ϣ���Ƥ��������
+
+ �ѹ���Ԥʤ�ʤ�ruby�򥳥�ѥ��뤷���Х��ʥ�����ۤ϶ػ�
+ ���ޤ��󤬡��Х��ʥ����ä��ͤ�������������Ǥ����
+ ���ˡ�������������ˡ��������Ƥ��������
+
+ + �ѹ�
+
+ �����ۤ�Ԥ�ʤ��¤ꡤ�����ʤ���Ū�Ǥ��켫ͳ�Ǥ����������
+ ��ǽ��ĥ��Х�����Ϻ�ԤؤΥե����ɥХå�����Ԥ��ޤ�
+ (�������ǤϤ���ޤ���)��
+
+ + ¾�Υץ����ؤΰ���
+
+ �����ʤ���Ū�Ǥ��켫ͳ�Ǥ����������ruby�˴ޤޤ��¾�κ�
+ �Ԥˤ�륳���ɤϡ����줾��κ�Ԥΰո��ˤ����¤��ä���
+ ��ޤ�������Ū�ˤ�gc.c(����)��util.c(����)��regex.[ch]��
+ fnmatch.[ch]��glob.c��st.[ch]��./missing�ǥ��쥯�ȥ겼��
+ �ե����뷲������ޤ���
+
+ + Ruby������ץȤθ���
+
+ ��Ƥ�ruby������ץȤθ���Ϥ��줾������Ԥ�°���ޤ���
+ ��ԤϤ����˴ؤ��ư��ڤθ�����ĥ���ޤ��󡥤ޤ�ruby��
+ �Ȥ߹��ि��γ�ĥ�⥸�塼��˴ؤ��Ƥ�Ʊ�ͤǤ���
+
+ + ̵�ݾ�
+
+ Ruby��̵�ݾڤǤ�����Ԥ�ruby�򥵥ݡ��Ȥ���ջ֤Ϥ���ޤ�
+ ����ruby���ȤΥХ����뤤��ruby������ץȤΥХ��ʤɤ���ȯ
+ ����뤤���ʤ�»�����Ф��Ƥ���Ǥ����ޤ���
+
+* ���
+
+�����ȡ��Х���ݡ��Ȥ���¾�� matz@netlab.co.jp �ޤǡ�
+-------------------------------------------------------
+created at: Thu Aug 3 11:57:36 JST 1995
+Local variables:
+mode: indented-text
+end:
View
4 ToDo
@@ -0,0 +1,4 @@
+* non-blocking open/write for thread
+* �ѥå������ޤ�������ѿ�Υ����������
+* format��ǽ
+* re-write regex code for speed and copyright
View
1,242 array.c
@@ -0,0 +1,1242 @@
+/************************************************
+
+ array.c -
+
+ $Author$
+ $Date$
+ created at: Fri Aug 6 09:46:12 JST 1993
+
+ Copyright (C) 1993-1996 Yukihiro Matsumoto
+
+************************************************/
+
+#include "ruby.h"
+
+VALUE cArray;
+
+VALUE rb_to_a();
+
+#define ARY_DEFAULT_SIZE 16
+
+void
+memclear(mem, size)
+ register VALUE *mem;
+ register int size;
+{
+ while (size--) {
+ *mem++ = Qnil;
+ }
+}
+
+#define ARY_FREEZE FL_USER1
+
+static void
+ary_modify(ary)
+ VALUE ary;
+{
+ rb_secure(5);
+ if (FL_TEST(ary, ARY_FREEZE)) {
+ TypeError("can't modify frozen array");
+ }
+}
+
+VALUE
+ary_freeze(ary)
+ VALUE ary;
+{
+ FL_SET(ary, ARY_FREEZE);
+ return ary;
+}
+
+static VALUE
+ary_frozen_p(ary)
+ VALUE ary;
+{
+ if (FL_TEST(ary, ARY_FREEZE))
+ return TRUE;
+ return FALSE;
+}
+
+VALUE
+ary_new2(len)
+ int len;
+{
+ NEWOBJ(ary, struct RArray);
+ OBJSETUP(ary, cArray, T_ARRAY);
+
+ ary->len = 0;
+ ary->capa = len;
+ if (len == 0)
+ ary->ptr = 0;
+ else {
+ ary->ptr = ALLOC_N(VALUE, len);
+ memclear(ary->ptr, len);
+ }
+
+ return (VALUE)ary;
+}
+
+VALUE
+ary_new()
+{
+ return ary_new2(ARY_DEFAULT_SIZE);
+}
+
+#include <varargs.h>
+
+VALUE
+ary_new3(n, va_alist)
+ int n;
+ va_dcl
+{
+ va_list ar;
+ struct RArray* ary;
+ int i;
+
+ if (n < 0) {
+ IndexError("Negative number of items(%d)", n);
+ }
+ ary = (struct RArray*)ary_new2(n<ARY_DEFAULT_SIZE?ARY_DEFAULT_SIZE:n);
+
+ va_start(ar);
+ for (i=0; i<n; i++) {
+ ary->ptr[i] = va_arg(ar, VALUE);
+ }
+ va_end(ar);
+
+ ary->len = n;
+ return (VALUE)ary;
+}
+
+VALUE
+ary_new4(n, elts)
+ int n;
+ VALUE *elts;
+{
+ struct RArray* ary;
+
+ ary = (struct RArray*)ary_new2(n);
+ MEMCPY(ary->ptr, elts, VALUE, n);
+ ary->len = n;
+
+ return (VALUE)ary;
+}
+
+VALUE
+assoc_new(car, cdr)
+ VALUE car, cdr;
+{
+ struct RArray* ary;
+
+ ary = (struct RArray*)ary_new2(2);
+ ary->ptr[0] = car;
+ ary->ptr[1] = cdr;
+ ary->len = 2;
+
+ return (VALUE)ary;
+}
+
+static VALUE
+ary_s_new(argc, argv, class)
+ int argc;
+ VALUE *argv;
+ VALUE class;
+{
+ VALUE size;
+ NEWOBJ(ary, struct RArray);
+ OBJSETUP(ary, class, T_ARRAY);
+
+ rb_scan_args(argc, argv, "01", &size);
+ ary->len = 0;
+ ary->capa = NIL_P(size)?ARY_DEFAULT_SIZE:NUM2INT(size);
+ ary->ptr = ALLOC_N(VALUE, ary->capa);
+ memclear(ary->ptr, ary->capa);
+
+ return (VALUE)ary;
+}
+
+static VALUE
+ary_s_create(argc, argv, class)
+ int argc;
+ VALUE *argv;
+ VALUE class;
+{
+ NEWOBJ(ary, struct RArray);
+ OBJSETUP(ary, class, T_ARRAY);
+
+ ary->len = argc;
+ ary->capa = argc;
+ if (argc == 0) {
+ ary->ptr = 0;
+ }
+ else {
+ ary->ptr = ALLOC_N(VALUE, argc);
+ MEMCPY(ary->ptr, argv, VALUE, argc);
+ }
+
+ return (VALUE)ary;
+}
+
+void
+ary_store(ary, idx, val)
+ struct RArray *ary;
+ int idx;
+ VALUE val;
+{
+ ary_modify(ary);
+ if (idx < 0) {
+ IndexError("negative index for array");
+ }
+
+ if (idx >= ary->capa) {
+ ary->capa = idx + ARY_DEFAULT_SIZE;
+ REALLOC_N(ary->ptr, VALUE, ary->capa);
+ }
+ if (idx > ary->len) {
+ memclear(ary->ptr+ary->len, idx-ary->len+1);
+ }
+
+ if (idx >= ary->len) {
+ ary->len = idx + 1;
+ }
+ ary->ptr[idx] = val;
+}
+
+VALUE
+ary_push(ary, item)
+ struct RArray *ary;
+ VALUE item;
+{
+ ary_store(ary, ary->len, item);
+ return (VALUE)ary;
+}
+
+static VALUE
+ary_push_method(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ struct RArray *ary;
+{
+ while (argc--) {
+ ary_store(ary, ary->len, *argv++);
+ }
+ return (VALUE)ary;
+}
+
+VALUE
+ary_pop(ary)
+ struct RArray *ary;
+{
+ if (ary->len == 0) return Qnil;
+ if (ary->len * 10 < ary->capa && ary->capa > ARY_DEFAULT_SIZE) {
+ ary->capa = ary->len * 2;
+ REALLOC_N(ary->ptr, VALUE, ary->capa);
+ }
+ return ary->ptr[--ary->len];
+}
+
+VALUE
+ary_shift(ary)
+ struct RArray *ary;
+{
+ VALUE top;
+
+ if (ary->len == 0) return Qnil;
+
+ top = ary->ptr[0];
+ ary->len--;
+
+ /* sliding items */
+ MEMMOVE(ary->ptr, ary->ptr+1, VALUE, ary->len);
+ if (ary->len * 10 < ary->capa && ary->capa > ARY_DEFAULT_SIZE) {
+ ary->capa = ary->len * 2;
+ REALLOC_N(ary->ptr, VALUE, ary->capa);
+ }
+
+ return top;
+}
+
+VALUE
+ary_unshift(ary, item)
+ struct RArray *ary;
+ int item;
+{
+ ary_modify(ary);
+ if (ary->len >= ary->capa) {
+ ary->capa+=ARY_DEFAULT_SIZE;
+ REALLOC_N(ary->ptr, VALUE, ary->capa);
+ }
+
+ /* sliding items */
+ MEMMOVE(ary->ptr+1, ary->ptr, VALUE, ary->len);
+
+ ary->len++;
+ return ary->ptr[0] = item;
+}
+
+VALUE
+ary_entry(ary, offset)
+ struct RArray *ary;
+ int offset;
+{
+ if (ary->len == 0) return Qnil;
+
+ if (offset < 0) {
+ offset = ary->len + offset;
+ }
+ if (offset < 0 || ary->len <= offset) {
+ return Qnil;
+ }
+
+ return ary->ptr[offset];
+}
+
+static VALUE
+ary_subseq(ary, beg, len)
+ struct RArray *ary;
+ int beg, len;
+{
+ struct RArray *ary2;
+
+ if (beg < 0) {
+ beg = ary->len + beg;
+ if (beg < 0) beg = 0;
+ }
+ if (len < 0) {
+ IndexError("negative length %d", ary->len);
+ }
+ if (len == 0) {
+ return ary_new2(0);
+ }
+ if (beg + len > ary->len) {
+ len = ary->len - beg;
+ }
+
+ ary2 = (struct RArray*)ary_new2(len);
+ MEMCPY(ary2->ptr, ary->ptr+beg, VALUE, len);
+ ary2->len = len;
+
+ return (VALUE)ary2;
+}
+
+static VALUE
+beg_len(range, begp, lenp, len)
+ VALUE range;
+ int *begp, *lenp;
+ int len;
+{
+ int beg, end;
+
+ if (!range_beg_end(range, &beg, &end)) return FALSE;
+
+ if ((beg > 0 && end > 0 || beg < 0 && end < 0) && beg > end) {
+ IndexError("end smaller than beg [%d..%d]", beg, end);
+ }
+
+ if (beg < 0) {
+ beg = len + beg;
+ if (beg < 0) beg = 0;
+ }
+ *begp = beg;
+ if (beg > len) {
+ *lenp = 0;
+ }
+ else {
+ if (end < 0) {
+ end = len + end;
+ if (end < 0) end = -1;
+ }
+ if (end > len) end = len;
+ if (beg > end) {
+ *lenp = 0;
+ }
+ else {
+ *lenp = end - beg +1;
+ }
+ }
+ return TRUE;
+}
+
+static VALUE
+ary_aref(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ struct RArray *ary;
+{
+ VALUE arg1, arg2;
+ int beg, len;
+
+ if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
+ beg = NUM2INT(arg1);
+ len = NUM2INT(arg2);
+ if (len <= 0) {
+ return ary_new();
+ }
+ return ary_subseq(ary, beg, len);
+ }
+
+ /* special case - speeding up */
+ if (FIXNUM_P(arg1)) {
+ return ary_entry(ary, FIX2INT(arg1));
+ }
+ else {
+ /* check if idx is Range */
+ if (beg_len(arg1, &beg, &len, ary->len)) {
+ return ary_subseq(ary, beg, len);
+ }
+ }
+ if (TYPE(arg1) == T_BIGNUM) {
+ IndexError("index too big");
+ }
+ return ary_entry(ary, NUM2INT(arg1));
+}
+
+static VALUE
+ary_index(ary, val)
+ struct RArray *ary;
+ VALUE val;
+{
+ int i;
+
+ for (i=0; i<ary->len; i++) {
+ if (rb_equal(ary->ptr[i], val))
+ return INT2FIX(i);
+ }
+ return Qnil;
+}
+
+static VALUE
+ary_indexes(ary, args)
+ struct RArray *ary, *args;
+{
+ VALUE *p, *pend;
+ VALUE new_ary;
+ int i = 0;
+
+ if (!args || NIL_P(args)) {
+ return ary_new2(0);
+ }
+
+ new_ary = ary_new2(args->len);
+
+ p = args->ptr; pend = p + args->len;
+ while (p < pend) {
+ ary_store(new_ary, i++, ary_entry(ary, NUM2INT(*p)));
+ p++;
+ }
+ return new_ary;
+}
+
+static void
+ary_replace(ary, beg, len, rpl)
+ struct RArray *ary, *rpl;
+ int beg, len;
+{
+ ary_modify(ary);
+ if (TYPE(rpl) != T_ARRAY) {
+ rpl = (struct RArray*)rb_to_a(rpl);
+ }
+ if (beg < 0) {
+ beg = ary->len + beg;
+ if (beg < 0) beg = 0;
+ }
+ if (beg >= ary->len) {
+ len = beg + rpl->len;
+ if (len >= ary->capa) {
+ ary->capa=len;
+ REALLOC_N(ary->ptr, VALUE, ary->capa);
+ }
+ memclear(ary->ptr+ary->len, beg-ary->len);
+ MEMCPY(ary->ptr+beg, rpl->ptr, VALUE, rpl->len);
+ ary->len = len;
+ }
+ else {
+ int alen;
+
+ if (beg + len > ary->len) {
+ len = ary->len - beg;
+ }
+ if (len < 0) {
+ IndexError("negative length %d", ary->len);
+ }
+
+ alen = ary->len + rpl->len - len;
+ if (alen >= ary->capa) {
+ ary->capa=alen;
+ REALLOC_N(ary->ptr, VALUE, ary->capa);
+ }
+
+ if (len != RARRAY(rpl)->len) {
+ MEMMOVE(ary->ptr+beg+rpl->len, ary->ptr+beg+len,
+ VALUE, ary->len-(beg+len));
+ ary->len = alen;
+ }
+ MEMCPY(ary->ptr+beg, rpl->ptr, VALUE, rpl->len);
+ }
+}
+
+static VALUE
+ary_aset(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ struct RArray *ary;
+{
+ VALUE arg1, arg2;
+ struct RArray *arg3;
+ int offset;
+ int beg, len;
+
+ if (rb_scan_args(argc, argv, "21", &arg1, &arg2, &arg3) == 3) {
+ beg = NUM2INT(arg1);
+ len = NUM2INT(arg2);
+ ary_replace(ary, beg, len, arg3);
+ return (VALUE)arg3;
+ }
+ else if (FIXNUM_P(arg1)) {
+ offset = FIX2INT(arg1);
+ goto fixnum;
+ }
+ else if (beg_len(arg1, &beg, &len, ary->len)) {
+ /* check if idx is Range */
+ ary_replace(ary, beg, len, arg2);
+ return arg2;
+ }
+ if (TYPE(arg1) == T_BIGNUM) {
+ IndexError("index too big");
+ }
+
+ offset = NUM2INT(arg1);
+ fixnum:
+ if (offset < 0) {
+ offset = ary->len + offset;
+ }
+ ary_store(ary, offset, arg2);
+ return arg2;
+}
+
+VALUE
+ary_each(ary)
+ struct RArray *ary;
+{
+ int i;
+
+ for (i=0; i<ary->len; i++) {
+ rb_yield(ary->ptr[i]);
+ }
+ return Qnil;
+}
+
+static VALUE
+ary_each_index(ary)
+ struct RArray *ary;
+{
+ int i;
+
+ for (i=0; i<ary->len; i++) {
+ rb_yield(INT2FIX(i));
+ }
+ return Qnil;
+}
+
+static VALUE
+ary_reverse_each(ary)
+ struct RArray *ary;
+{
+ int len = ary->len;
+
+ while (len--) {
+ rb_yield(ary->ptr[len]);
+ }
+ return Qnil;
+}
+
+static VALUE
+ary_length(ary)
+ struct RArray *ary;
+{
+ return INT2FIX(ary->len);
+}
+
+static VALUE
+ary_empty_p(ary)
+ struct RArray *ary;
+{
+ if (ary->len == 0)
+ return TRUE;
+ return FALSE;
+}
+
+static VALUE
+ary_clone(ary)
+ struct RArray *ary;
+{
+ VALUE ary2 = ary_new2(ary->len);
+
+ CLONESETUP(ary2, ary);
+ MEMCPY(RARRAY(ary2)->ptr, ary->ptr, VALUE, ary->len);
+ RARRAY(ary2)->len = ary->len;
+ return ary2;
+}
+
+extern VALUE OFS;
+
+VALUE
+ary_join(ary, sep)
+ struct RArray *ary;
+ struct RString *sep;
+{
+ int i;
+ VALUE result, tmp;
+ if (ary->len == 0) return str_new(0, 0);
+
+ switch (TYPE(ary->ptr[0])) {
+ case T_STRING:
+ result = str_dup(ary->ptr[0]);
+ break;
+ case T_ARRAY:
+ result = ary_join(ary->ptr[0], sep);
+ break;
+ default:
+ result = obj_as_string(ary->ptr[0]);
+ break;
+ }
+
+ for (i=1; i<ary->len; i++) {
+ tmp = ary->ptr[i];
+ switch (TYPE(tmp)) {
+ case T_STRING:
+ break;
+ case T_ARRAY:
+ tmp = ary_join(tmp, sep);
+ break;
+ default:
+ tmp = obj_as_string(tmp);
+ }
+ if (!NIL_P(sep)) str_cat(result, sep->ptr, sep->len);
+ str_cat(result, RSTRING(tmp)->ptr, RSTRING(tmp)->len);
+ if (str_tainted(tmp)) str_taint(result);
+ }
+
+ return result;
+}
+
+static VALUE
+ary_join_method(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ struct RArray *ary;
+{
+ VALUE sep;
+
+ rb_scan_args(argc, argv, "01", &sep);
+ if (NIL_P(sep)) sep = OFS;
+ if (!NIL_P(sep)) Check_Type(sep, T_STRING);
+
+ return ary_join(ary, sep);
+}
+
+VALUE
+ary_to_s(ary)
+ VALUE ary;
+{
+ VALUE str = ary_join(ary, OFS);
+ if (NIL_P(str)) return str_new(0, 0);
+ return str;
+}
+
+VALUE
+ary_print_on(ary, port)
+ struct RArray *ary;
+ VALUE port;
+{
+ int i;
+
+ for (i=0; i<ary->len; i++) {
+ if (!NIL_P(OFS) && i>0) {
+ io_write(port, OFS);
+ }
+ io_write(port, ary->ptr[i]);
+ }
+ return port;
+}
+
+static VALUE
+ary_inspect(ary)
+ struct RArray *ary;
+{
+ int i, len;
+ VALUE s, str;
+
+ if (ary->len == 0) return str_new2("[]");
+ str = str_new2("[");
+ len = 1;
+
+ for (i=0; i<ary->len; i++) {
+ s = rb_inspect(ary->ptr[i]);
+ if (i > 0) str_cat(str, ", ", 2);
+ str_cat(str, RSTRING(s)->ptr, RSTRING(s)->len);
+ len += RSTRING(s)->len + 2;
+ }
+ str_cat(str, "]", 1);
+
+ return str;
+}
+
+static VALUE
+ary_to_a(ary)
+ VALUE ary;
+{
+ return ary;
+}
+
+VALUE
+rb_to_a(obj)
+ VALUE obj;
+{
+ if (TYPE(obj) == T_ARRAY) return obj;
+ obj = rb_funcall(obj, rb_intern("to_a"), 0);
+ if (TYPE(obj) != T_ARRAY) {
+ Bug("`to_a' did not return Array");
+ }
+ return obj;
+}
+
+VALUE
+ary_reverse(ary)
+ struct RArray *ary;
+{
+ VALUE *p1, *p2;
+ VALUE tmp;
+
+ p1 = ary->ptr;
+ p2 = p1 + ary->len - 1; /* points last item */
+
+ while (p1 < p2) {
+ tmp = *p1;
+ *p1 = *p2;
+ *p2 = tmp;
+ p1++; p2--;
+ }
+
+ return (VALUE)ary;
+}