Initial commit
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
# cryptowallFileFinder
|
||||
This ruby program finds all files infected with cryptowall and puts them in a txt file for you.
|
||||
|
||||
Download the whole repository with the ruby source code. Clicking start.bat will scan all local drives and place a txt in this directory.
|
||||
|
||||
89
find_cryptowall_infected_files.rb
Normal file
89
find_cryptowall_infected_files.rb
Normal file
@@ -0,0 +1,89 @@
|
||||
require 'win32ole'
|
||||
require 'FileUtils'
|
||||
|
||||
|
||||
def infectedFiles(decryptFile)
|
||||
infectedPath = File.dirname("#{decryptFile}")
|
||||
infectedFiles = Dir["#{infectedPath}/*.*"]
|
||||
return infectedFiles
|
||||
end
|
||||
|
||||
def infectedFileExpandedPath(file)
|
||||
infectedFileExpandedPath = File.expand_path(file.to_s)
|
||||
return infectedFileExpandedPath
|
||||
end
|
||||
|
||||
def decryptFiles(path)
|
||||
decryptFiles = Dir["#{path}/**/DECRYPT_INSTRUCTION.TXT"]
|
||||
return decryptFiles
|
||||
end
|
||||
|
||||
|
||||
def myFile
|
||||
myFile = File.new("files.txt","a")
|
||||
return myFile
|
||||
end
|
||||
|
||||
def openFile
|
||||
openFile = File.open("files.txt","a")
|
||||
return openFile
|
||||
end
|
||||
|
||||
def writeMyFile(whatToWrite)
|
||||
if !isDecryptInstructions(whatToWrite) && !isTorInstructions(whatToWrite)
|
||||
whatToWrite = infectedFileExpandedPath(whatToWrite)
|
||||
whatToWrite = whatToWrite.gsub("/","\\")
|
||||
openFile.puts(whatToWrite)
|
||||
openFile.close
|
||||
end
|
||||
end
|
||||
|
||||
def deleteInstructions(file)
|
||||
if isTorInstructions(file) or isDecryptInstructions(file)
|
||||
FileUtils.rm(File.expand_path(file.to_s))
|
||||
end
|
||||
end
|
||||
|
||||
def isTorInstructions(file)
|
||||
if file.include? "TOR"
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def isDecryptInstructions(file)
|
||||
if file.include? "DECRYPT"
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def findInfectedFiles(path)
|
||||
decryptFiles(path).each do |f|
|
||||
infectedFiles(f).each do |returnedFiles|
|
||||
writeMyFile(returnedFiles)
|
||||
deleteInstructions(returnedFiles)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
file_system = WIN32OLE.new("Scripting.FileSystemObject")
|
||||
drives = file_system.Drives
|
||||
drives.each do |drive|
|
||||
if drive.DriveType == 2
|
||||
findInfectedFiles(drive.Path)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
155
ruby/bin/erb
Normal file
155
ruby/bin/erb
Normal file
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env ruby
|
||||
# Tiny eRuby --- ERB2
|
||||
# Copyright (c) 1999-2000,2002 Masatoshi SEKI
|
||||
# You can redistribute it and/or modify it under the same terms as Ruby.
|
||||
|
||||
require 'erb'
|
||||
|
||||
class ERB
|
||||
module Main
|
||||
def ARGV.switch
|
||||
return nil if self.empty?
|
||||
arg = self.shift
|
||||
return nil if arg == '--'
|
||||
if arg =~ /^-(.)(.*)/
|
||||
if $1 == '-'
|
||||
arg, @maybe_arg = arg.split(/=/, 2)
|
||||
return arg
|
||||
end
|
||||
raise 'unknown switch "-"' if $2[0] == ?- and $1 != 'T'
|
||||
if $2.size > 0
|
||||
self.unshift "-#{$2}"
|
||||
@maybe_arg = $2
|
||||
else
|
||||
@maybe_arg = nil
|
||||
end
|
||||
"-#{$1}"
|
||||
else
|
||||
self.unshift arg
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def ARGV.req_arg
|
||||
(@maybe_arg || self.shift || raise('missing argument')).tap {
|
||||
@maybe_arg = nil
|
||||
}
|
||||
end
|
||||
|
||||
def trim_mode_opt(trim_mode, disable_percent)
|
||||
return trim_mode if disable_percent
|
||||
case trim_mode
|
||||
when 0
|
||||
return '%'
|
||||
when 1
|
||||
return '%>'
|
||||
when 2
|
||||
return '%<>'
|
||||
when '-'
|
||||
return '%-'
|
||||
end
|
||||
end
|
||||
module_function :trim_mode_opt
|
||||
|
||||
def run(factory=ERB)
|
||||
trim_mode = 0
|
||||
disable_percent = false
|
||||
begin
|
||||
while switch = ARGV.switch
|
||||
case switch
|
||||
when '-x' # ruby source
|
||||
output = true
|
||||
when '-n' # line number
|
||||
number = true
|
||||
when '-v' # verbose
|
||||
$VERBOSE = true
|
||||
when '--version' # version
|
||||
STDERR.puts factory.version
|
||||
exit
|
||||
when '-d', '--debug' # debug
|
||||
$DEBUG = true
|
||||
when '-r' # require
|
||||
require ARGV.req_arg
|
||||
when '-S' # security level
|
||||
arg = ARGV.req_arg
|
||||
raise "invalid safe_level #{arg.dump}" unless arg =~ /^[0-3]$/
|
||||
safe_level = arg.to_i
|
||||
when '-T' # trim mode
|
||||
arg = ARGV.req_arg
|
||||
if arg == '-'
|
||||
trim_mode = arg
|
||||
next
|
||||
end
|
||||
raise "invalid trim mode #{arg.dump}" unless arg =~ /^[0-2]$/
|
||||
trim_mode = arg.to_i
|
||||
when '-E', '--encoding'
|
||||
arg = ARGV.req_arg
|
||||
set_encoding(*arg.split(/:/, 2))
|
||||
when '-U'
|
||||
set_encoding(Encoding::UTF_8, Encoding::UTF_8)
|
||||
when '-P'
|
||||
disable_percent = true
|
||||
when '--help'
|
||||
raise "print this help"
|
||||
else
|
||||
raise "unknown switch #{switch.dump}"
|
||||
end
|
||||
end
|
||||
rescue # usage
|
||||
STDERR.puts $!.to_s
|
||||
STDERR.puts File.basename($0) +
|
||||
" [switches] [inputfile]"
|
||||
STDERR.puts <<EOU
|
||||
-x print ruby script
|
||||
-n print ruby script with line number
|
||||
-v enable verbose mode
|
||||
-d set $DEBUG to true
|
||||
-r library load a library
|
||||
-S safe_level set $SAFE (0..3)
|
||||
-E ex[:in] set default external/internal encodings
|
||||
-U set default encoding to UTF-8.
|
||||
-T trim_mode specify trim_mode (0..2, -)
|
||||
-P ignore lines which start with "%"
|
||||
EOU
|
||||
exit 1
|
||||
end
|
||||
|
||||
$<.set_encoding(Encoding::ASCII_8BIT, nil)
|
||||
src = $<.read
|
||||
filename = $FILENAME
|
||||
exit 2 unless src
|
||||
trim = trim_mode_opt(trim_mode, disable_percent)
|
||||
erb = factory.new(src.untaint, safe_level, trim)
|
||||
erb.filename = filename
|
||||
if output
|
||||
if number
|
||||
erb.src.each_line.with_index do |line, l|
|
||||
puts "%3d %s"%[l+1, line]
|
||||
end
|
||||
else
|
||||
puts erb.src
|
||||
end
|
||||
else
|
||||
erb.run(TOPLEVEL_BINDING.taint)
|
||||
end
|
||||
end
|
||||
module_function :run
|
||||
|
||||
def set_encoding(extern, intern = nil)
|
||||
verbose, $VERBOSE = $VERBOSE, nil
|
||||
Encoding.default_external = extern unless extern.nil? || extern.empty?
|
||||
Encoding.default_internal = intern unless intern.nil? || intern.empty?
|
||||
[$stdin, $stdout, $stderr].each do |io|
|
||||
io.set_encoding(extern, intern)
|
||||
end
|
||||
ensure
|
||||
$VERBOSE = verbose
|
||||
end
|
||||
module_function :set_encoding
|
||||
class << self; private :set_encoding; end
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
ERB::Main.run
|
||||
end
|
||||
6
ruby/bin/erb.bat
Normal file
6
ruby/bin/erb.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
25
ruby/bin/gem
Normal file
25
ruby/bin/gem
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env ruby
|
||||
#--
|
||||
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
||||
# All rights reserved.
|
||||
# See LICENSE.txt for permissions.
|
||||
#++
|
||||
|
||||
require 'rubygems'
|
||||
require 'rubygems/gem_runner'
|
||||
require 'rubygems/exceptions'
|
||||
|
||||
required_version = Gem::Requirement.new ">= 1.8.7"
|
||||
|
||||
unless required_version.satisfied_by? Gem.ruby_version then
|
||||
abort "Expected Ruby Version #{required_version}, is #{Gem.ruby_version}"
|
||||
end
|
||||
|
||||
args = ARGV.clone
|
||||
|
||||
begin
|
||||
Gem::GemRunner.new.run args
|
||||
rescue Gem::SystemExitException => e
|
||||
exit e.exit_code
|
||||
end
|
||||
|
||||
6
ruby/bin/gem.bat
Normal file
6
ruby/bin/gem.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
11
ruby/bin/irb
Normal file
11
ruby/bin/irb
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# irb.rb - interactive ruby
|
||||
# $Release Version: 0.9.6 $
|
||||
# $Revision: 40560 $
|
||||
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
||||
#
|
||||
|
||||
require "irb"
|
||||
|
||||
IRB.start(__FILE__)
|
||||
6
ruby/bin/irb.bat
Normal file
6
ruby/bin/irb.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
BIN
ruby/bin/libeay32.dll
Normal file
BIN
ruby/bin/libeay32.dll
Normal file
Binary file not shown.
BIN
ruby/bin/libffi-6.dll
Normal file
BIN
ruby/bin/libffi-6.dll
Normal file
Binary file not shown.
BIN
ruby/bin/libgdbm-3.dll
Normal file
BIN
ruby/bin/libgdbm-3.dll
Normal file
Binary file not shown.
BIN
ruby/bin/libgdbm_compat-3.dll
Normal file
BIN
ruby/bin/libgdbm_compat-3.dll
Normal file
Binary file not shown.
BIN
ruby/bin/libiconv-2.dll
Normal file
BIN
ruby/bin/libiconv-2.dll
Normal file
Binary file not shown.
BIN
ruby/bin/libyaml-0-2.dll
Normal file
BIN
ruby/bin/libyaml-0-2.dll
Normal file
Binary file not shown.
BIN
ruby/bin/msvcrt-ruby210.dll
Normal file
BIN
ruby/bin/msvcrt-ruby210.dll
Normal file
Binary file not shown.
33
ruby/bin/rake
Normal file
33
ruby/bin/rake
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
#--
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007 Jim Weirich
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
# IN THE SOFTWARE.
|
||||
#++
|
||||
|
||||
begin
|
||||
require 'rubygems'
|
||||
gem 'rake'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
require 'rake'
|
||||
|
||||
Rake.application.run
|
||||
6
ruby/bin/rake.bat
Normal file
6
ruby/bin/rake.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
44
ruby/bin/rdoc
Normal file
44
ruby/bin/rdoc
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# RDoc: Documentation tool for source code
|
||||
# (see lib/rdoc/rdoc.rb for more information)
|
||||
#
|
||||
# Copyright (c) 2003 Dave Thomas
|
||||
# Released under the same terms as Ruby
|
||||
|
||||
begin
|
||||
gem 'rdoc'
|
||||
rescue NameError => e # --disable-gems
|
||||
raise unless e.name == :gem
|
||||
rescue Gem::LoadError
|
||||
end
|
||||
|
||||
require 'rdoc/rdoc'
|
||||
|
||||
begin
|
||||
r = RDoc::RDoc.new
|
||||
r.document ARGV
|
||||
rescue Errno::ENOSPC
|
||||
$stderr.puts 'Ran out of space creating documentation'
|
||||
$stderr.puts
|
||||
$stderr.puts 'Please free up some space and try again'
|
||||
rescue SystemExit
|
||||
raise
|
||||
rescue Exception => e
|
||||
if $DEBUG_RDOC then
|
||||
$stderr.puts e.message
|
||||
$stderr.puts "#{e.backtrace.join "\n\t"}"
|
||||
$stderr.puts
|
||||
elsif Interrupt === e then
|
||||
$stderr.puts
|
||||
$stderr.puts 'Interrupted'
|
||||
else
|
||||
$stderr.puts "uh-oh! RDoc had a problem:"
|
||||
$stderr.puts e.message
|
||||
$stderr.puts
|
||||
$stderr.puts "run with --debug for full backtrace"
|
||||
end
|
||||
|
||||
exit 1
|
||||
end
|
||||
|
||||
6
ruby/bin/rdoc.bat
Normal file
6
ruby/bin/rdoc.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
12
ruby/bin/ri
Normal file
12
ruby/bin/ri
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
begin
|
||||
gem 'rdoc'
|
||||
rescue NameError => e # --disable-gems
|
||||
raise unless e.name == :gem
|
||||
rescue Gem::LoadError
|
||||
end
|
||||
|
||||
require 'rdoc/ri/driver'
|
||||
|
||||
RDoc::RI::Driver.run ARGV
|
||||
6
ruby/bin/ri.bat
Normal file
6
ruby/bin/ri.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
BIN
ruby/bin/ruby.exe
Normal file
BIN
ruby/bin/ruby.exe
Normal file
Binary file not shown.
BIN
ruby/bin/rubyw.exe
Normal file
BIN
ruby/bin/rubyw.exe
Normal file
Binary file not shown.
BIN
ruby/bin/ssleay32.dll
Normal file
BIN
ruby/bin/ssleay32.dll
Normal file
Binary file not shown.
BIN
ruby/bin/tcl85.dll
Normal file
BIN
ruby/bin/tcl85.dll
Normal file
Binary file not shown.
BIN
ruby/bin/tclpip85.dll
Normal file
BIN
ruby/bin/tclpip85.dll
Normal file
Binary file not shown.
3
ruby/bin/testrb
Normal file
3
ruby/bin/testrb
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'test/unit'
|
||||
exit Test::Unit::AutoRunner.run(true)
|
||||
6
ruby/bin/testrb.bat
Normal file
6
ruby/bin/testrb.bat
Normal file
@@ -0,0 +1,6 @@
|
||||
@ECHO OFF
|
||||
IF NOT "%~f0" == "~f0" GOTO :WinNT
|
||||
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
|
||||
GOTO :EOF
|
||||
:WinNT
|
||||
@"%~dp0ruby.exe" "%~dpn0" %*
|
||||
BIN
ruby/bin/tk85.dll
Normal file
BIN
ruby/bin/tk85.dll
Normal file
Binary file not shown.
BIN
ruby/bin/zlib1.dll
Normal file
BIN
ruby/bin/zlib1.dll
Normal file
Binary file not shown.
232
ruby/include/ruby-2.1.0/i386-mingw32/ruby/config.h
Normal file
232
ruby/include/ruby-2.1.0/i386-mingw32/ruby/config.h
Normal file
@@ -0,0 +1,232 @@
|
||||
#ifndef INCLUDE_RUBY_CONFIG_H
|
||||
#define INCLUDE_RUBY_CONFIG_H 1
|
||||
/* confdefs.h */
|
||||
#define CANONICALIZATION_FOR_MATHN 1
|
||||
#define RUBY_MSVCRT_VERSION 60
|
||||
#define STDC_HEADERS 1
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
#define HAVE_STDLIB_H 1
|
||||
#define HAVE_STRING_H 1
|
||||
#define HAVE_MEMORY_H 1
|
||||
#define HAVE_STRINGS_H 1
|
||||
#define HAVE_INTTYPES_H 1
|
||||
#define HAVE_STDINT_H 1
|
||||
#define HAVE_UNISTD_H 1
|
||||
#define __EXTENSIONS__ 1
|
||||
#define _ALL_SOURCE 1
|
||||
#define _GNU_SOURCE 1
|
||||
#define _POSIX_PTHREAD_SEMANTICS 1
|
||||
#define _TANDEM_SOURCE 1
|
||||
#define RUBY_SYMBOL_EXPORT_BEGIN _Pragma("GCC visibility push(default)")
|
||||
#define RUBY_SYMBOL_EXPORT_END _Pragma("GCC visibility pop")
|
||||
#define HAVE_TYPE_NET_LUID 1
|
||||
#define HAVE__GMTIME64_S 1
|
||||
#define HAVE_DIRENT_H 1
|
||||
#define HAVE__BOOL 1
|
||||
#define HAVE_STDBOOL_H 1
|
||||
#define HAVE_LIMITS_H 1
|
||||
#define HAVE_SYS_FILE_H 1
|
||||
#define HAVE_FCNTL_H 1
|
||||
#define HAVE_SYS_FCNTL_H 1
|
||||
#define HAVE_DIRECT_H 1
|
||||
#define HAVE_SYS_UTIME_H 1
|
||||
#define HAVE_FLOAT_H 1
|
||||
#define HAVE_LOCALE_H 1
|
||||
#define HAVE_TIME_H 1
|
||||
#define HAVE_PROCESS_H 1
|
||||
#define HAVE_MALLOC_H 1
|
||||
#define HAVE_SETJMPEX_H 1
|
||||
#define _FILE_OFFSET_BITS 64
|
||||
#define HAVE_LONG_LONG 1
|
||||
#define HAVE_OFF_T 1
|
||||
#define SIZEOF_INT 4
|
||||
#define SIZEOF_SHORT 2
|
||||
#define SIZEOF_LONG 4
|
||||
#define SIZEOF_LONG_LONG 8
|
||||
#define SIZEOF___INT64 8
|
||||
#define SIZEOF___INT128 0
|
||||
#define SIZEOF_OFF_T 8
|
||||
#define SIZEOF_VOIDP 4
|
||||
#define SIZEOF_FLOAT 4
|
||||
#define SIZEOF_DOUBLE 8
|
||||
#define SIZEOF_TIME_T 8
|
||||
#define SIZEOF_CLOCK_T 4
|
||||
#define PRI_LL_PREFIX "I64"
|
||||
#define rb_pid_t pid_t
|
||||
#define SIGNEDNESS_OF_PID_T -1
|
||||
#define PIDT2NUM(v) INT2NUM(v)
|
||||
#define NUM2PIDT(v) NUM2INT(v)
|
||||
#define PRI_PIDT_PREFIX PRI_INT_PREFIX
|
||||
#define rb_uid_t int
|
||||
#define SIGNEDNESS_OF_UID_T -1
|
||||
#define UIDT2NUM(v) INT2NUM(v)
|
||||
#define NUM2UIDT(v) NUM2INT(v)
|
||||
#define PRI_UIDT_PREFIX PRI_INT_PREFIX
|
||||
#define rb_gid_t int
|
||||
#define SIGNEDNESS_OF_GID_T -1
|
||||
#define GIDT2NUM(v) INT2NUM(v)
|
||||
#define NUM2GIDT(v) NUM2INT(v)
|
||||
#define PRI_GIDT_PREFIX PRI_INT_PREFIX
|
||||
#define rb_time_t time_t
|
||||
#define SIGNEDNESS_OF_TIME_T -1
|
||||
#define TIMET2NUM(v) LL2NUM(v)
|
||||
#define NUM2TIMET(v) NUM2LL(v)
|
||||
#define PRI_TIMET_PREFIX PRI_LL_PREFIX
|
||||
#define rb_dev_t dev_t
|
||||
#define SIGNEDNESS_OF_DEV_T +1
|
||||
#define DEVT2NUM(v) UINT2NUM(v)
|
||||
#define NUM2DEVT(v) NUM2UINT(v)
|
||||
#define PRI_DEVT_PREFIX PRI_INT_PREFIX
|
||||
#define rb_mode_t mode_t
|
||||
#define SIGNEDNESS_OF_MODE_T +1
|
||||
#define MODET2NUM(v) UINT2NUM(v)
|
||||
#define NUM2MODET(v) NUM2UINT(v)
|
||||
#define PRI_MODET_PREFIX PRI_INT_PREFIX
|
||||
#define rb_rlim_t int long "long long"
|
||||
#define SIGNEDNESS_OF_RLIM_T -1
|
||||
#define RLIM2NUM(v) LONG2NUM(v)
|
||||
#define NUM2RLIM(v) NUM2LONG(v)
|
||||
#define PRI_RLIM_PREFIX PRI_LONG_PREFIX
|
||||
#define rb_off_t off_t
|
||||
#define SIGNEDNESS_OF_OFF_T -1
|
||||
#define OFFT2NUM(v) LL2NUM(v)
|
||||
#define NUM2OFFT(v) NUM2LL(v)
|
||||
#define PRI_OFFT_PREFIX PRI_LL_PREFIX
|
||||
#define rb_clockid_t int
|
||||
#define SIGNEDNESS_OF_CLOCKID_T -1
|
||||
#define CLOCKID2NUM(v) INT2NUM(v)
|
||||
#define NUM2CLOCKID(v) NUM2INT(v)
|
||||
#define PRI_CLOCKID_PREFIX PRI_INT_PREFIX
|
||||
#define HAVE_PROTOTYPES 1
|
||||
#define TOKEN_PASTE(x,y) x##y
|
||||
#define STRINGIZE(expr) STRINGIZE0(expr)
|
||||
#define HAVE_STDARG_PROTOTYPES 1
|
||||
#define HAVE_VA_ARGS_MACRO 1
|
||||
#define NORETURN(x) __attribute__ ((noreturn)) x
|
||||
#define DEPRECATED(x) __attribute__ ((deprecated)) x
|
||||
#define NOINLINE(x) __attribute__ ((noinline)) x
|
||||
#define FUNC_STDCALL(x) __attribute__ ((stdcall)) x
|
||||
#define FUNC_CDECL(x) __attribute__ ((cdecl)) x
|
||||
#define FUNC_FASTCALL(x) __attribute__ ((fastcall)) x
|
||||
#define HAVE_ATTRIBUTE_FUNCTION_ALIAS 1
|
||||
#define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) type prot __attribute__((alias(#name)));
|
||||
#define RUBY_ALIAS_FUNCTION_VOID(prot, name, args) RUBY_ALIAS_FUNCTION_TYPE(void, prot, name, args)
|
||||
#define HAVE_GCC_ATOMIC_BUILTINS 1
|
||||
#define HAVE_GCC_SYNC_BUILTINS 1
|
||||
#define UNREACHABLE __builtin_unreachable()
|
||||
#define RUBY_FUNC_EXPORTED __attribute__ ((visibility("default"))) extern
|
||||
#define RUBY_FUNCTION_NAME_STRING __func__
|
||||
#define HAVE_DECL_SYS_NERR 1
|
||||
#define HAVE_DECL_GETENV 1
|
||||
#define SIZEOF_SIZE_T 4
|
||||
#define SIZEOF_PTRDIFF_T 4
|
||||
#define HAVE_STRUCT_STAT_ST_RDEV 1
|
||||
#define HAVE_ST_RDEV 1
|
||||
#define SIZEOF_STRUCT_STAT_ST_SIZE SIZEOF_LONG_LONG
|
||||
#define HAVE_STRUCT_TIMEVAL 1
|
||||
#define SIZEOF_STRUCT_TIMEVAL_TV_SEC SIZEOF_LONG
|
||||
#define TYPEOF_TIMEVAL_TV_SEC long
|
||||
#define HAVE_STRUCT_TIMESPEC 1
|
||||
#define HAVE_STRUCT_TIMEZONE 1
|
||||
#define HAVE_RB_FD_INIT 1
|
||||
#define HAVE_INT8_T 1
|
||||
#define SIZEOF_INT8_T 1
|
||||
#define HAVE_UINT8_T 1
|
||||
#define SIZEOF_UINT8_T 1
|
||||
#define HAVE_INT16_T 1
|
||||
#define SIZEOF_INT16_T 2
|
||||
#define HAVE_UINT16_T 1
|
||||
#define SIZEOF_UINT16_T 2
|
||||
#define HAVE_INT32_T 1
|
||||
#define SIZEOF_INT32_T 4
|
||||
#define HAVE_UINT32_T 1
|
||||
#define SIZEOF_UINT32_T 4
|
||||
#define HAVE_INT64_T 1
|
||||
#define SIZEOF_INT64_T 8
|
||||
#define HAVE_UINT64_T 1
|
||||
#define SIZEOF_UINT64_T 8
|
||||
#define HAVE_INTPTR_T 1
|
||||
#define SIZEOF_INTPTR_T 4
|
||||
#define HAVE_UINTPTR_T 1
|
||||
#define SIZEOF_UINTPTR_T 4
|
||||
#define HAVE_SSIZE_T 1
|
||||
#define SIZEOF_SSIZE_T 4
|
||||
#define uid_t int
|
||||
#define gid_t int
|
||||
#define GETGROUPS_T int
|
||||
#define RETSIGTYPE void
|
||||
#define HAVE_ALLOCA 1
|
||||
#define HAVE_DUP2 1
|
||||
#define HAVE_MEMMOVE 1
|
||||
#define HAVE_STRERROR 1
|
||||
#define HAVE_STRCHR 1
|
||||
#define HAVE_STRSTR 1
|
||||
#define HAVE_FLOCK 1
|
||||
#define HAVE_ISNAN 1
|
||||
#define HAVE_FINITE 1
|
||||
#define HAVE_ISINF 1
|
||||
#define HAVE_HYPOT 1
|
||||
#define HAVE_ACOSH 1
|
||||
#define HAVE_ERF 1
|
||||
#define HAVE_TGAMMA 1
|
||||
#define HAVE_CBRT 1
|
||||
#define HAVE_SIGNBIT 1
|
||||
#define HAVE__SETJMP 1
|
||||
#define HAVE_CHSIZE 1
|
||||
#define HAVE_CLOCK_GETTIME 1
|
||||
#define HAVE_COSH 1
|
||||
#define HAVE_DUP 1
|
||||
#define HAVE_FCNTL 1
|
||||
#define HAVE_FMOD 1
|
||||
#define HAVE_FSYNC 1
|
||||
#define HAVE_FTRUNCATE 1
|
||||
#define HAVE_FTRUNCATE64 1
|
||||
#define HAVE_GETCWD 1
|
||||
#define HAVE_GETTIMEOFDAY 1
|
||||
#define HAVE_GMTIME_R 1
|
||||
#define HAVE_LINK 1
|
||||
#define HAVE_LLABS 1
|
||||
#define HAVE_LOG2 1
|
||||
#define HAVE_MBLEN 1
|
||||
#define HAVE_MKTIME 1
|
||||
#define HAVE_ROUND 1
|
||||
#define HAVE_SEEKDIR 1
|
||||
#define HAVE_SINH 1
|
||||
#define HAVE_SPAWNV 1
|
||||
#define HAVE_TANH 1
|
||||
#define HAVE_TELLDIR 1
|
||||
#define HAVE_TIMES 1
|
||||
#define HAVE_TRUNCATE 1
|
||||
#define HAVE_TRUNCATE64 1
|
||||
#define HAVE_WAITPID 1
|
||||
#define HAVE_BUILTIN___BUILTIN_BSWAP32 1
|
||||
#define HAVE_BUILTIN___BUILTIN_BSWAP64 1
|
||||
#define HAVE_BUILTIN___BUILTIN_CLZ 1
|
||||
#define HAVE_BUILTIN___BUILTIN_CLZL 1
|
||||
#define HAVE_BUILTIN___BUILTIN_CLZLL 1
|
||||
#define HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR 1
|
||||
#define HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P 1
|
||||
#define HAVE_CLOCK_GETRES 1
|
||||
#define HAVE_DECL_TZNAME 1
|
||||
#define HAVE_TZNAME 1
|
||||
#define HAVE_DAYLIGHT 1
|
||||
#define HAVE_VAR_TIMEZONE 1
|
||||
#define TYPEOF_VAR_TIMEZONE long
|
||||
#define HAVE_TIMEZONE 1
|
||||
#define TIMEZONE_VOID 1
|
||||
#define RSHIFT(x,y) ((x)>>(int)(y))
|
||||
#define FILE_COUNT _cnt
|
||||
#define FILE_READPTR _ptr
|
||||
#define SIZEOF_STRUCT_STAT_ST_INO 2
|
||||
#define STACK_GROW_DIRECTION -1
|
||||
#define DLEXT_MAXLEN 3
|
||||
#define DLEXT ".so"
|
||||
#define LIBDIR_BASENAME "lib"
|
||||
#define EXECUTABLE_EXTS ".exe",".com",".cmd",".bat"
|
||||
#define RUBY_SETJMP(env) __builtin_setjmp((env))
|
||||
#define RUBY_LONGJMP(env,val) __builtin_longjmp((env),val)
|
||||
#define RUBY_JMP_BUF jmp_buf
|
||||
#define LOAD_RELATIVE 1
|
||||
#define RUBY_PLATFORM "i386-mingw32"
|
||||
#endif /* INCLUDE_RUBY_CONFIG_H */
|
||||
35
ruby/include/ruby-2.1.0/ruby.h
Normal file
35
ruby/include/ruby-2.1.0/ruby.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/**********************************************************************
|
||||
|
||||
ruby.h -
|
||||
|
||||
$Author$
|
||||
created at: Sun 10 12:06:15 Jun JST 2007
|
||||
|
||||
Copyright (C) 2007-2008 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_H
|
||||
#define RUBY_H 1
|
||||
|
||||
#define HAVE_RUBY_DEFINES_H 1
|
||||
#define HAVE_RUBY_ENCODING_H 1
|
||||
#define HAVE_RUBY_INTERN_H 1
|
||||
#define HAVE_RUBY_IO_H 1
|
||||
#define HAVE_RUBY_MISSING_H 1
|
||||
#define HAVE_RUBY_ONIGURUMA_H 1
|
||||
#define HAVE_RUBY_RE_H 1
|
||||
#define HAVE_RUBY_REGEX_H 1
|
||||
#define HAVE_RUBY_RUBY_H 1
|
||||
#define HAVE_RUBY_ST_H 1
|
||||
#define HAVE_RUBY_THREAD_H 1
|
||||
#define HAVE_RUBY_UTIL_H 1
|
||||
#define HAVE_RUBY_VERSION_H 1
|
||||
#define HAVE_RUBY_VM_H 1
|
||||
#ifdef _WIN32
|
||||
#define HAVE_RUBY_WIN32_H 1
|
||||
#endif
|
||||
|
||||
#include "ruby/ruby.h"
|
||||
|
||||
#endif /* RUBY_H */
|
||||
18
ruby/include/ruby-2.1.0/ruby/backward/classext.h
Normal file
18
ruby/include/ruby-2.1.0/ruby/backward/classext.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#if defined __GNUC__
|
||||
#warning use of RClass internals is deprecated
|
||||
#elif defined _MSC_VER || defined __BORLANDC__
|
||||
#pragma message("warning: use of RClass internals is deprecated")
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_BACKWARD_CLASSEXT_H
|
||||
#define RUBY_BACKWARD_CLASSEXT_H 1
|
||||
|
||||
typedef struct rb_deprecated_classext_struct {
|
||||
VALUE super;
|
||||
} rb_deprecated_classext_t;
|
||||
|
||||
#undef RCLASS_SUPER(c)
|
||||
#define RCLASS_EXT(c) ((rb_deprecated_classext_t *)RCLASS(c)->ptr)
|
||||
#define RCLASS_SUPER(c) (RCLASS(c)->super)
|
||||
|
||||
#endif /* RUBY_BACKWARD_CLASSEXT_H */
|
||||
6
ruby/include/ruby-2.1.0/ruby/backward/rubyio.h
Normal file
6
ruby/include/ruby-2.1.0/ruby/backward/rubyio.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#if defined __GNUC__
|
||||
#warning use "ruby/io.h" instead of "rubyio.h"
|
||||
#elif defined _MSC_VER || defined __BORLANDC__
|
||||
#pragma message("warning: use \"ruby/io.h\" instead of \"rubyio.h\"")
|
||||
#endif
|
||||
#include "ruby/io.h"
|
||||
52
ruby/include/ruby-2.1.0/ruby/backward/rubysig.h
Normal file
52
ruby/include/ruby-2.1.0/ruby/backward/rubysig.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/**********************************************************************
|
||||
|
||||
rubysig.h -
|
||||
|
||||
$Author: nobu $
|
||||
$Date: 2013-04-05 19:29:38 +0900 (Fri, 05 Apr 2013) $
|
||||
created at: Wed Aug 16 01:15:38 JST 1995
|
||||
|
||||
Copyright (C) 1993-2008 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#if defined __GNUC__
|
||||
#warning rubysig.h is obsolete
|
||||
#elif defined _MSC_VER || defined __BORLANDC__
|
||||
#pragma message("warning: rubysig.h is obsolete")
|
||||
#endif
|
||||
|
||||
#ifndef RUBYSIG_H
|
||||
#define RUBYSIG_H
|
||||
#include "ruby/ruby.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
struct rb_blocking_region_buffer;
|
||||
DEPRECATED(RUBY_EXTERN struct rb_blocking_region_buffer *rb_thread_blocking_region_begin(void));
|
||||
DEPRECATED(RUBY_EXTERN void rb_thread_blocking_region_end(struct rb_blocking_region_buffer *));
|
||||
#define TRAP_BEG do {struct rb_blocking_region_buffer *__region = rb_thread_blocking_region_begin();
|
||||
#define TRAP_END rb_thread_blocking_region_end(__region);} while (0)
|
||||
#define RUBY_CRITICAL(statements) do {statements;} while (0)
|
||||
#define DEFER_INTS (0)
|
||||
#define ENABLE_INTS (1)
|
||||
#define ALLOW_INTS do {CHECK_INTS;} while (0)
|
||||
#define CHECK_INTS rb_thread_check_ints()
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
6
ruby/include/ruby-2.1.0/ruby/backward/st.h
Normal file
6
ruby/include/ruby-2.1.0/ruby/backward/st.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#if defined __GNUC__
|
||||
#warning use "ruby/st.h" instead of bare "st.h"
|
||||
#elif defined _MSC_VER || defined __BORLANDC__
|
||||
#pragma message("warning: use \"ruby/st.h\" instead of bare \"st.h\"")
|
||||
#endif
|
||||
#include "ruby/st.h"
|
||||
6
ruby/include/ruby-2.1.0/ruby/backward/util.h
Normal file
6
ruby/include/ruby-2.1.0/ruby/backward/util.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#if defined __GNUC__
|
||||
#warning use "ruby/util.h" instead of bare "util.h"
|
||||
#elif defined _MSC_VER || defined __BORLANDC__
|
||||
#pragma message("warning: use \"ruby/util.h\" instead of bare \"util.h\"")
|
||||
#endif
|
||||
#include "ruby/util.h"
|
||||
110
ruby/include/ruby-2.1.0/ruby/debug.h
Normal file
110
ruby/include/ruby-2.1.0/ruby/debug.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/**********************************************************************
|
||||
|
||||
ruby/debug.h -
|
||||
|
||||
$Author: ko1 $
|
||||
created at: Tue Nov 20 20:35:08 2012
|
||||
|
||||
Copyright (C) 2012 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RB_DEBUG_H
|
||||
#define RB_DEBUG_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
/* Note: This file contains experimental APIs. */
|
||||
/* APIs can be replaced at Ruby 2.0.1 or later */
|
||||
|
||||
|
||||
/* profile frames APIs */
|
||||
int rb_profile_frames(int start, int limit, VALUE *buff, int *lines);
|
||||
VALUE rb_profile_frame_path(VALUE frame);
|
||||
VALUE rb_profile_frame_absolute_path(VALUE frame);
|
||||
VALUE rb_profile_frame_label(VALUE frame);
|
||||
VALUE rb_profile_frame_base_label(VALUE frame);
|
||||
VALUE rb_profile_frame_full_label(VALUE frame);
|
||||
VALUE rb_profile_frame_first_lineno(VALUE frame);
|
||||
VALUE rb_profile_frame_classpath(VALUE frame);
|
||||
VALUE rb_profile_frame_singleton_method_p(VALUE frame);
|
||||
VALUE rb_profile_frame_method_name(VALUE frame);
|
||||
VALUE rb_profile_frame_qualified_method_name(VALUE frame);
|
||||
|
||||
/* debug inspector APIs */
|
||||
typedef struct rb_debug_inspector_struct rb_debug_inspector_t;
|
||||
typedef VALUE (*rb_debug_inspector_func_t)(const rb_debug_inspector_t *, void *);
|
||||
|
||||
VALUE rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data);
|
||||
VALUE rb_debug_inspector_frame_self_get(const rb_debug_inspector_t *dc, long index);
|
||||
VALUE rb_debug_inspector_frame_class_get(const rb_debug_inspector_t *dc, long index);
|
||||
VALUE rb_debug_inspector_frame_binding_get(const rb_debug_inspector_t *dc, long index);
|
||||
VALUE rb_debug_inspector_frame_iseq_get(const rb_debug_inspector_t *dc, long index);
|
||||
VALUE rb_debug_inspector_backtrace_locations(const rb_debug_inspector_t *dc);
|
||||
|
||||
/* Old style set_trace_func APIs */
|
||||
|
||||
/* duplicated def of include/ruby/ruby.h */
|
||||
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data);
|
||||
int rb_remove_event_hook(rb_event_hook_func_t func);
|
||||
|
||||
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data);
|
||||
void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data);
|
||||
int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func);
|
||||
int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data);
|
||||
|
||||
/* TracePoint APIs */
|
||||
|
||||
VALUE rb_tracepoint_new(VALUE target_thread_not_supported_yet, rb_event_flag_t events, void (*func)(VALUE, void *), void *data);
|
||||
VALUE rb_tracepoint_enable(VALUE tpval);
|
||||
VALUE rb_tracepoint_disable(VALUE tpval);
|
||||
VALUE rb_tracepoint_enabled_p(VALUE tpval);
|
||||
|
||||
typedef struct rb_trace_arg_struct rb_trace_arg_t;
|
||||
rb_trace_arg_t *rb_tracearg_from_tracepoint(VALUE tpval);
|
||||
|
||||
rb_event_flag_t rb_tracearg_event_flag(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_event(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_lineno(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_path(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_method_id(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_binding(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_self(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg);
|
||||
VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg);
|
||||
|
||||
/* Postponed Job API */
|
||||
typedef void (*rb_postponed_job_func_t)(void *arg);
|
||||
int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data);
|
||||
int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data);
|
||||
|
||||
/* undocumented advanced tracing APIs */
|
||||
|
||||
typedef enum {
|
||||
RUBY_EVENT_HOOK_FLAG_SAFE = 0x01,
|
||||
RUBY_EVENT_HOOK_FLAG_DELETED = 0x02,
|
||||
RUBY_EVENT_HOOK_FLAG_RAW_ARG = 0x04
|
||||
} rb_event_hook_flag_t;
|
||||
|
||||
void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag);
|
||||
void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flag);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_DEBUG_H */
|
||||
324
ruby/include/ruby-2.1.0/ruby/defines.h
Normal file
324
ruby/include/ruby-2.1.0/ruby/defines.h
Normal file
@@ -0,0 +1,324 @@
|
||||
/************************************************
|
||||
|
||||
defines.h -
|
||||
|
||||
$Author: akr $
|
||||
created at: Wed May 18 00:21:44 JST 1994
|
||||
|
||||
************************************************/
|
||||
|
||||
#ifndef RUBY_DEFINES_H
|
||||
#define RUBY_DEFINES_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ruby/config.h"
|
||||
#ifdef RUBY_EXTCONF_H
|
||||
#include RUBY_EXTCONF_H
|
||||
#endif
|
||||
|
||||
/* AC_INCLUDES_DEFAULT */
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
#endif
|
||||
#ifdef STDC_HEADERS
|
||||
# include <stdlib.h>
|
||||
# include <stddef.h>
|
||||
#else
|
||||
# ifdef HAVE_STDLIB_H
|
||||
# include <stdlib.h>
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAVE_STRING_H
|
||||
# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# include <string.h>
|
||||
#endif
|
||||
#ifdef HAVE_STRINGS_H
|
||||
# include <strings.h>
|
||||
#endif
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_SELECT_H
|
||||
# include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#if defined HAVE_SETJMPEX_H && defined HAVE__SETJMPEX
|
||||
#include <setjmpex.h>
|
||||
#endif
|
||||
|
||||
#include "ruby/missing.h"
|
||||
|
||||
#define RUBY
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifndef HAVE_PROTOTYPES
|
||||
# define HAVE_PROTOTYPES 1
|
||||
# endif
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#undef _
|
||||
#ifdef HAVE_PROTOTYPES
|
||||
# define _(args) args
|
||||
#else
|
||||
# define _(args) ()
|
||||
#endif
|
||||
|
||||
#undef __
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# define __(args) args
|
||||
#else
|
||||
# define __(args) ()
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define ANYARGS ...
|
||||
#else
|
||||
#define ANYARGS
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_SYMBOL_EXPORT_BEGIN
|
||||
# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
|
||||
# define RUBY_SYMBOL_EXPORT_END /* end */
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#define xmalloc ruby_xmalloc
|
||||
#define xmalloc2 ruby_xmalloc2
|
||||
#define xcalloc ruby_xcalloc
|
||||
#define xrealloc ruby_xrealloc
|
||||
#define xrealloc2 ruby_xrealloc2
|
||||
#define xfree ruby_xfree
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
|
||||
# define RUBY_ATTR_ALLOC_SIZE(params) __attribute__ ((__alloc_size__ params))
|
||||
#else
|
||||
# define RUBY_ATTR_ALLOC_SIZE(params)
|
||||
#endif
|
||||
|
||||
void *xmalloc(size_t) RUBY_ATTR_ALLOC_SIZE((1));
|
||||
void *xmalloc2(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
|
||||
void *xcalloc(size_t,size_t) RUBY_ATTR_ALLOC_SIZE((1,2));
|
||||
void *xrealloc(void*,size_t) RUBY_ATTR_ALLOC_SIZE((2));
|
||||
void *xrealloc2(void*,size_t,size_t) RUBY_ATTR_ALLOC_SIZE((2,3));
|
||||
void xfree(void*);
|
||||
|
||||
#define STRINGIZE(expr) STRINGIZE0(expr)
|
||||
#ifndef STRINGIZE0
|
||||
#define STRINGIZE0(expr) #expr
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LONG_LONG
|
||||
# define HAVE_TRUE_LONG_LONG 1
|
||||
#endif
|
||||
|
||||
#if SIZEOF_LONG_LONG > 0
|
||||
# define LONG_LONG long long
|
||||
#elif SIZEOF___INT64 > 0
|
||||
# define HAVE_LONG_LONG 1
|
||||
# define LONG_LONG __int64
|
||||
# undef SIZEOF_LONG_LONG
|
||||
# define SIZEOF_LONG_LONG SIZEOF___INT64
|
||||
#endif
|
||||
|
||||
#ifndef BDIGIT
|
||||
# if SIZEOF_INT*2 <= SIZEOF_LONG_LONG
|
||||
# define BDIGIT unsigned int
|
||||
# define SIZEOF_BDIGITS SIZEOF_INT
|
||||
# define BDIGIT_DBL unsigned LONG_LONG
|
||||
# define BDIGIT_DBL_SIGNED LONG_LONG
|
||||
# define PRI_BDIGIT_PREFIX ""
|
||||
# define PRI_BDIGIT_DBL_PREFIX PRI_LL_PREFIX
|
||||
# elif SIZEOF_INT*2 <= SIZEOF_LONG
|
||||
# define BDIGIT unsigned int
|
||||
# define SIZEOF_BDIGITS SIZEOF_INT
|
||||
# define BDIGIT_DBL unsigned long
|
||||
# define BDIGIT_DBL_SIGNED long
|
||||
# define PRI_BDIGIT_PREFIX ""
|
||||
# define PRI_BDIGIT_DBL_PREFIX "l"
|
||||
# elif SIZEOF_SHORT*2 <= SIZEOF_LONG
|
||||
# define BDIGIT unsigned short
|
||||
# define SIZEOF_BDIGITS SIZEOF_SHORT
|
||||
# define BDIGIT_DBL unsigned long
|
||||
# define BDIGIT_DBL_SIGNED long
|
||||
# define PRI_BDIGIT_PREFIX "h"
|
||||
# define PRI_BDIGIT_DBL_PREFIX "l"
|
||||
# else
|
||||
# define BDIGIT unsigned short
|
||||
# define SIZEOF_BDIGITS (SIZEOF_LONG/2)
|
||||
# define SIZEOF_ACTUAL_BDIGIT SIZEOF_LONG
|
||||
# define BDIGIT_DBL unsigned long
|
||||
# define BDIGIT_DBL_SIGNED long
|
||||
# define PRI_BDIGIT_PREFIX "h"
|
||||
# define PRI_BDIGIT_DBL_PREFIX "l"
|
||||
# endif
|
||||
#endif
|
||||
#ifndef SIZEOF_ACTUAL_BDIGIT
|
||||
# define SIZEOF_ACTUAL_BDIGIT SIZEOF_BDIGITS
|
||||
#endif
|
||||
|
||||
#ifdef PRI_BDIGIT_PREFIX
|
||||
# define PRIdBDIGIT PRI_BDIGIT_PREFIX"d"
|
||||
# define PRIiBDIGIT PRI_BDIGIT_PREFIX"i"
|
||||
# define PRIoBDIGIT PRI_BDIGIT_PREFIX"o"
|
||||
# define PRIuBDIGIT PRI_BDIGIT_PREFIX"u"
|
||||
# define PRIxBDIGIT PRI_BDIGIT_PREFIX"x"
|
||||
# define PRIXBDIGIT PRI_BDIGIT_PREFIX"X"
|
||||
#endif
|
||||
|
||||
#ifdef PRI_BDIGIT_DBL_PREFIX
|
||||
# define PRIdBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"d"
|
||||
# define PRIiBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"i"
|
||||
# define PRIoBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"o"
|
||||
# define PRIuBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"u"
|
||||
# define PRIxBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"x"
|
||||
# define PRIXBDIGIT_DBL PRI_BDIGIT_DBL_PREFIX"X"
|
||||
#endif
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
#undef _WIN32
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__EMX__)
|
||||
#define DOSISH 1
|
||||
# define DOSISH_DRIVE_LETTER
|
||||
#endif
|
||||
|
||||
#ifdef AC_APPLE_UNIVERSAL_BUILD
|
||||
#undef WORDS_BIGENDIAN
|
||||
#ifdef __BIG_ENDIAN__
|
||||
#define WORDS_BIGENDIAN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "ruby/win32.h"
|
||||
#endif
|
||||
|
||||
#if defined(__BEOS__) && !defined(__HAIKU__) && !defined(BONE)
|
||||
#include <net/socket.h> /* intern.h needs fd_set definition */
|
||||
#endif
|
||||
|
||||
#ifdef __SYMBIAN32__
|
||||
# define FALSE 0
|
||||
# define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifdef RUBY_EXPORT
|
||||
#undef RUBY_EXTERN
|
||||
|
||||
#ifndef FALSE
|
||||
# define FALSE 0
|
||||
#elif FALSE
|
||||
# error FALSE must be false
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
#elif !TRUE
|
||||
# error TRUE must be true
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_FUNC_EXPORTED
|
||||
#define RUBY_FUNC_EXPORTED
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_EXTERN
|
||||
#define RUBY_EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifndef EXTERN
|
||||
#define EXTERN RUBY_EXTERN /* deprecated */
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_MBCHAR_MAXSIZE
|
||||
#define RUBY_MBCHAR_MAXSIZE INT_MAX
|
||||
/* MB_CUR_MAX will not work well in C locale */
|
||||
#endif
|
||||
|
||||
#if defined(__sparc)
|
||||
void rb_sparc_flush_register_windows(void);
|
||||
# define FLUSH_REGISTER_WINDOWS rb_sparc_flush_register_windows()
|
||||
#elif defined(__ia64)
|
||||
void *rb_ia64_bsp(void);
|
||||
void rb_ia64_flushrs(void);
|
||||
# define FLUSH_REGISTER_WINDOWS rb_ia64_flushrs()
|
||||
#else
|
||||
# define FLUSH_REGISTER_WINDOWS ((void)0)
|
||||
#endif
|
||||
|
||||
#if defined(DOSISH)
|
||||
#define PATH_SEP ";"
|
||||
#else
|
||||
#define PATH_SEP ":"
|
||||
#endif
|
||||
#define PATH_SEP_CHAR PATH_SEP[0]
|
||||
|
||||
#define PATH_ENV "PATH"
|
||||
|
||||
#if defined(DOSISH) && !defined(__EMX__)
|
||||
#define ENV_IGNORECASE
|
||||
#endif
|
||||
|
||||
#ifndef CASEFOLD_FILESYSTEM
|
||||
# if defined DOSISH
|
||||
# define CASEFOLD_FILESYSTEM 1
|
||||
# else
|
||||
# define CASEFOLD_FILESYSTEM 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef DLEXT_MAXLEN
|
||||
#define DLEXT_MAXLEN 4
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_PLATFORM
|
||||
#define RUBY_PLATFORM "unknown-unknown"
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_ALIAS_FUNCTION_TYPE
|
||||
#define RUBY_ALIAS_FUNCTION_TYPE(type, prot, name, args) \
|
||||
type prot {return name args;}
|
||||
#endif
|
||||
#ifndef RUBY_ALIAS_FUNCTION_VOID
|
||||
#define RUBY_ALIAS_FUNCTION_VOID(prot, name, args) \
|
||||
void prot {name args;}
|
||||
#endif
|
||||
#ifndef RUBY_ALIAS_FUNCTION
|
||||
#define RUBY_ALIAS_FUNCTION(prot, name, args) \
|
||||
RUBY_ALIAS_FUNCTION_TYPE(VALUE, prot, name, args)
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_DEFINES_H */
|
||||
32
ruby/include/ruby-2.1.0/ruby/digest.h
Normal file
32
ruby/include/ruby-2.1.0/ruby/digest.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/************************************************
|
||||
|
||||
digest.h - header file for ruby digest modules
|
||||
|
||||
$Author: akr $
|
||||
created at: Fri May 25 08:54:56 JST 2001
|
||||
|
||||
|
||||
Copyright (C) 2001-2006 Akinori MUSHA
|
||||
|
||||
$RoughId: digest.h,v 1.3 2001/07/13 15:38:27 knu Exp $
|
||||
$Id: digest.h 25189 2009-10-02 12:04:37Z akr $
|
||||
|
||||
************************************************/
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
#define RUBY_DIGEST_API_VERSION 2
|
||||
|
||||
typedef void (*rb_digest_hash_init_func_t)(void *);
|
||||
typedef void (*rb_digest_hash_update_func_t)(void *, unsigned char *, size_t);
|
||||
typedef void (*rb_digest_hash_finish_func_t)(void *, unsigned char *);
|
||||
|
||||
typedef struct {
|
||||
int api_version;
|
||||
size_t digest_len;
|
||||
size_t block_len;
|
||||
size_t ctx_size;
|
||||
rb_digest_hash_init_func_t init_func;
|
||||
rb_digest_hash_update_func_t update_func;
|
||||
rb_digest_hash_finish_func_t finish_func;
|
||||
} rb_digest_metadata_t;
|
||||
217
ruby/include/ruby-2.1.0/ruby/dl.h
Normal file
217
ruby/include/ruby-2.1.0/ruby/dl.h
Normal file
@@ -0,0 +1,217 @@
|
||||
#ifndef RUBY_DL_H
|
||||
#define RUBY_DL_H
|
||||
|
||||
#include <ruby.h>
|
||||
|
||||
#if !defined(FUNC_CDECL)
|
||||
# define FUNC_CDECL(x) x
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_DLFCN_H)
|
||||
# include <dlfcn.h>
|
||||
# /* some stranger systems may not define all of these */
|
||||
#ifndef RTLD_LAZY
|
||||
#define RTLD_LAZY 0
|
||||
#endif
|
||||
#ifndef RTLD_GLOBAL
|
||||
#define RTLD_GLOBAL 0
|
||||
#endif
|
||||
#ifndef RTLD_NOW
|
||||
#define RTLD_NOW 0
|
||||
#endif
|
||||
#else
|
||||
# if defined(_WIN32)
|
||||
# include <windows.h>
|
||||
# define dlopen(name,flag) ((void)(flag),(void*)LoadLibrary(name))
|
||||
# define dlerror() strerror(rb_w32_map_errno(GetLastError()))
|
||||
# define dlsym(handle,name) ((void*)GetProcAddress((handle),(name)))
|
||||
# define RTLD_LAZY -1
|
||||
# define RTLD_NOW -1
|
||||
# define RTLD_GLOBAL -1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define MAX_CALLBACK 5
|
||||
#define DLSTACK_TYPE SIGNED_VALUE
|
||||
#define DLSTACK_SIZE (20)
|
||||
#define DLSTACK_PROTO \
|
||||
DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,\
|
||||
DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,\
|
||||
DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,\
|
||||
DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE,DLSTACK_TYPE
|
||||
#define DLSTACK_ARGS(stack) \
|
||||
(stack)[0],(stack)[1],(stack)[2],(stack)[3],(stack)[4],\
|
||||
(stack)[5],(stack)[6],(stack)[7],(stack)[8],(stack)[9],\
|
||||
(stack)[10],(stack)[11],(stack)[12],(stack)[13],(stack)[14],\
|
||||
(stack)[15],(stack)[16],(stack)[17],(stack)[18],(stack)[19]
|
||||
|
||||
#define DLSTACK_PROTO0_ void
|
||||
#define DLSTACK_PROTO1_ DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO2_ DLSTACK_PROTO1_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO3_ DLSTACK_PROTO2_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO4_ DLSTACK_PROTO3_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO4_ DLSTACK_PROTO3_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO5_ DLSTACK_PROTO4_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO6_ DLSTACK_PROTO5_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO7_ DLSTACK_PROTO6_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO8_ DLSTACK_PROTO7_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO9_ DLSTACK_PROTO8_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO10_ DLSTACK_PROTO9_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO11_ DLSTACK_PROTO10_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO12_ DLSTACK_PROTO11_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO13_ DLSTACK_PROTO12_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO14_ DLSTACK_PROTO13_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO14_ DLSTACK_PROTO13_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO15_ DLSTACK_PROTO14_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO16_ DLSTACK_PROTO15_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO17_ DLSTACK_PROTO16_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO18_ DLSTACK_PROTO17_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO19_ DLSTACK_PROTO18_, DLSTACK_TYPE
|
||||
#define DLSTACK_PROTO20_ DLSTACK_PROTO19_, DLSTACK_TYPE
|
||||
|
||||
/*
|
||||
* Add ",..." as the last argument.
|
||||
* This is required for variable argument functions such
|
||||
* as fprintf() on x86_64-linux.
|
||||
*
|
||||
* http://refspecs.linuxfoundation.org/elf/x86_64-abi-0.95.pdf
|
||||
* page 19:
|
||||
*
|
||||
* For calls that may call functions that use varargs or stdargs
|
||||
* (prototype-less calls or calls to functions containing ellipsis
|
||||
* (...) in the declaration) %al is used as hidden argument to
|
||||
* specify the number of SSE registers used.
|
||||
*/
|
||||
#define DLSTACK_PROTO0 void
|
||||
#define DLSTACK_PROTO1 DLSTACK_PROTO1_, ...
|
||||
#define DLSTACK_PROTO2 DLSTACK_PROTO2_, ...
|
||||
#define DLSTACK_PROTO3 DLSTACK_PROTO3_, ...
|
||||
#define DLSTACK_PROTO4 DLSTACK_PROTO4_, ...
|
||||
#define DLSTACK_PROTO4 DLSTACK_PROTO4_, ...
|
||||
#define DLSTACK_PROTO5 DLSTACK_PROTO5_, ...
|
||||
#define DLSTACK_PROTO6 DLSTACK_PROTO6_, ...
|
||||
#define DLSTACK_PROTO7 DLSTACK_PROTO7_, ...
|
||||
#define DLSTACK_PROTO8 DLSTACK_PROTO8_, ...
|
||||
#define DLSTACK_PROTO9 DLSTACK_PROTO9_, ...
|
||||
#define DLSTACK_PROTO10 DLSTACK_PROTO10_, ...
|
||||
#define DLSTACK_PROTO11 DLSTACK_PROTO11_, ...
|
||||
#define DLSTACK_PROTO12 DLSTACK_PROTO12_, ...
|
||||
#define DLSTACK_PROTO13 DLSTACK_PROTO13_, ...
|
||||
#define DLSTACK_PROTO14 DLSTACK_PROTO14_, ...
|
||||
#define DLSTACK_PROTO14 DLSTACK_PROTO14_, ...
|
||||
#define DLSTACK_PROTO15 DLSTACK_PROTO15_, ...
|
||||
#define DLSTACK_PROTO16 DLSTACK_PROTO16_, ...
|
||||
#define DLSTACK_PROTO17 DLSTACK_PROTO17_, ...
|
||||
#define DLSTACK_PROTO18 DLSTACK_PROTO18_, ...
|
||||
#define DLSTACK_PROTO19 DLSTACK_PROTO19_, ...
|
||||
#define DLSTACK_PROTO20 DLSTACK_PROTO20_, ...
|
||||
|
||||
#define DLSTACK_ARGS0(stack)
|
||||
#define DLSTACK_ARGS1(stack) (stack)[0]
|
||||
#define DLSTACK_ARGS2(stack) DLSTACK_ARGS1(stack), (stack)[1]
|
||||
#define DLSTACK_ARGS3(stack) DLSTACK_ARGS2(stack), (stack)[2]
|
||||
#define DLSTACK_ARGS4(stack) DLSTACK_ARGS3(stack), (stack)[3]
|
||||
#define DLSTACK_ARGS5(stack) DLSTACK_ARGS4(stack), (stack)[4]
|
||||
#define DLSTACK_ARGS6(stack) DLSTACK_ARGS5(stack), (stack)[5]
|
||||
#define DLSTACK_ARGS7(stack) DLSTACK_ARGS6(stack), (stack)[6]
|
||||
#define DLSTACK_ARGS8(stack) DLSTACK_ARGS7(stack), (stack)[7]
|
||||
#define DLSTACK_ARGS9(stack) DLSTACK_ARGS8(stack), (stack)[8]
|
||||
#define DLSTACK_ARGS10(stack) DLSTACK_ARGS9(stack), (stack)[9]
|
||||
#define DLSTACK_ARGS11(stack) DLSTACK_ARGS10(stack), (stack)[10]
|
||||
#define DLSTACK_ARGS12(stack) DLSTACK_ARGS11(stack), (stack)[11]
|
||||
#define DLSTACK_ARGS13(stack) DLSTACK_ARGS12(stack), (stack)[12]
|
||||
#define DLSTACK_ARGS14(stack) DLSTACK_ARGS13(stack), (stack)[13]
|
||||
#define DLSTACK_ARGS15(stack) DLSTACK_ARGS14(stack), (stack)[14]
|
||||
#define DLSTACK_ARGS16(stack) DLSTACK_ARGS15(stack), (stack)[15]
|
||||
#define DLSTACK_ARGS17(stack) DLSTACK_ARGS16(stack), (stack)[16]
|
||||
#define DLSTACK_ARGS18(stack) DLSTACK_ARGS17(stack), (stack)[17]
|
||||
#define DLSTACK_ARGS19(stack) DLSTACK_ARGS18(stack), (stack)[18]
|
||||
#define DLSTACK_ARGS20(stack) DLSTACK_ARGS19(stack), (stack)[19]
|
||||
|
||||
extern VALUE rb_mDL;
|
||||
extern VALUE rb_cDLHandle;
|
||||
extern VALUE rb_cDLSymbol;
|
||||
extern VALUE rb_eDLError;
|
||||
extern VALUE rb_eDLTypeError;
|
||||
|
||||
#define ALIGN_OF(type) offsetof(struct {char align_c; type align_x;}, align_x)
|
||||
|
||||
#define ALIGN_VOIDP ALIGN_OF(void*)
|
||||
#define ALIGN_SHORT ALIGN_OF(short)
|
||||
#define ALIGN_CHAR ALIGN_OF(char)
|
||||
#define ALIGN_INT ALIGN_OF(int)
|
||||
#define ALIGN_LONG ALIGN_OF(long)
|
||||
#if HAVE_LONG_LONG
|
||||
#define ALIGN_LONG_LONG ALIGN_OF(LONG_LONG)
|
||||
#endif
|
||||
#define ALIGN_FLOAT ALIGN_OF(float)
|
||||
#define ALIGN_DOUBLE ALIGN_OF(double)
|
||||
|
||||
#define DLALIGN(ptr,offset,align) \
|
||||
((offset) += ((align) - ((uintptr_t)((char *)(ptr) + (offset))) % (align)) % (align))
|
||||
|
||||
|
||||
#define DLTYPE_VOID 0
|
||||
#define DLTYPE_VOIDP 1
|
||||
#define DLTYPE_CHAR 2
|
||||
#define DLTYPE_SHORT 3
|
||||
#define DLTYPE_INT 4
|
||||
#define DLTYPE_LONG 5
|
||||
#if HAVE_LONG_LONG
|
||||
#define DLTYPE_LONG_LONG 6
|
||||
#endif
|
||||
#define DLTYPE_FLOAT 7
|
||||
#define DLTYPE_DOUBLE 8
|
||||
#define MAX_DLTYPE 9
|
||||
|
||||
#if SIZEOF_VOIDP == SIZEOF_LONG
|
||||
# define PTR2NUM(x) (ULONG2NUM((unsigned long)(x)))
|
||||
# define NUM2PTR(x) ((void*)(NUM2ULONG(x)))
|
||||
#else
|
||||
/* # error --->> Ruby/DL2 requires sizeof(void*) == sizeof(long) to be compiled. <<--- */
|
||||
# define PTR2NUM(x) (ULL2NUM((unsigned long long)(x)))
|
||||
# define NUM2PTR(x) ((void*)(NUM2ULL(x)))
|
||||
#endif
|
||||
|
||||
#define BOOL2INT(x) (((x) == Qtrue)?1:0)
|
||||
#define INT2BOOL(x) ((x)?Qtrue:Qfalse)
|
||||
|
||||
typedef void (*freefunc_t)(void*);
|
||||
|
||||
struct dl_handle {
|
||||
void *ptr;
|
||||
int open;
|
||||
int enable_close;
|
||||
};
|
||||
|
||||
|
||||
struct cfunc_data {
|
||||
void *ptr;
|
||||
char *name;
|
||||
int type;
|
||||
ID calltype;
|
||||
VALUE wrap;
|
||||
};
|
||||
extern ID rbdl_id_cdecl;
|
||||
extern ID rbdl_id_stdcall;
|
||||
#define CFUNC_CDECL (rbdl_id_cdecl)
|
||||
#define CFUNC_STDCALL (rbdl_id_stdcall)
|
||||
|
||||
struct ptr_data {
|
||||
void *ptr;
|
||||
long size;
|
||||
freefunc_t free;
|
||||
VALUE wrap[2];
|
||||
};
|
||||
|
||||
#define RDL_HANDLE(obj) ((struct dl_handle *)(DATA_PTR(obj)))
|
||||
#define RCFUNC_DATA(obj) ((struct cfunc_data *)(DATA_PTR(obj)))
|
||||
#define RPTR_DATA(obj) ((struct ptr_data *)(DATA_PTR(obj)))
|
||||
|
||||
VALUE rb_dlcfunc_new(void (*func)(), int dltype, const char * name, ID calltype);
|
||||
int rb_dlcfunc_kind_p(VALUE func);
|
||||
VALUE rb_dlptr_new(void *ptr, long size, freefunc_t func);
|
||||
VALUE rb_dlptr_new2(VALUE klass, void *ptr, long size, freefunc_t func);
|
||||
VALUE rb_dlptr_malloc(long size, freefunc_t func);
|
||||
|
||||
#endif
|
||||
363
ruby/include/ruby-2.1.0/ruby/encoding.h
Normal file
363
ruby/include/ruby-2.1.0/ruby/encoding.h
Normal file
@@ -0,0 +1,363 @@
|
||||
/**********************************************************************
|
||||
|
||||
encoding.h -
|
||||
|
||||
$Author: matz $
|
||||
created at: Thu May 24 11:49:41 JST 2007
|
||||
|
||||
Copyright (C) 2007 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_ENCODING_H
|
||||
#define RUBY_ENCODING_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "ruby/oniguruma.h"
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#define ENCODING_INLINE_MAX 127
|
||||
#define ENCODING_SHIFT (FL_USHIFT+10)
|
||||
#define ENCODING_MASK (((VALUE)ENCODING_INLINE_MAX)<<ENCODING_SHIFT) /* FL_USER10|FL_USER11|FL_USER12|FL_USER13|FL_USER14|FL_USER15|FL_USER16 */
|
||||
|
||||
#define ENCODING_SET_INLINED(obj,i) do {\
|
||||
RBASIC(obj)->flags &= ~ENCODING_MASK;\
|
||||
RBASIC(obj)->flags |= (VALUE)(i) << ENCODING_SHIFT;\
|
||||
} while (0)
|
||||
#define ENCODING_SET(obj,i) rb_enc_set_index((obj), (i))
|
||||
|
||||
#define ENCODING_GET_INLINED(obj) (int)((RBASIC(obj)->flags & ENCODING_MASK)>>ENCODING_SHIFT)
|
||||
#define ENCODING_GET(obj) \
|
||||
(ENCODING_GET_INLINED(obj) != ENCODING_INLINE_MAX ? \
|
||||
ENCODING_GET_INLINED(obj) : \
|
||||
rb_enc_get_index(obj))
|
||||
|
||||
#define ENCODING_IS_ASCII8BIT(obj) (ENCODING_GET_INLINED(obj) == 0)
|
||||
|
||||
#define ENCODING_MAXNAMELEN 42
|
||||
|
||||
#define ENC_CODERANGE_MASK ((int)(FL_USER8|FL_USER9))
|
||||
#define ENC_CODERANGE_UNKNOWN 0
|
||||
#define ENC_CODERANGE_7BIT ((int)FL_USER8)
|
||||
#define ENC_CODERANGE_VALID ((int)FL_USER9)
|
||||
#define ENC_CODERANGE_BROKEN ((int)(FL_USER8|FL_USER9))
|
||||
#define ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & ENC_CODERANGE_MASK)
|
||||
#define ENC_CODERANGE_ASCIIONLY(obj) (ENC_CODERANGE(obj) == ENC_CODERANGE_7BIT)
|
||||
#define ENC_CODERANGE_SET(obj,cr) (RBASIC(obj)->flags = \
|
||||
(RBASIC(obj)->flags & ~ENC_CODERANGE_MASK) | (cr))
|
||||
#define ENC_CODERANGE_CLEAR(obj) ENC_CODERANGE_SET((obj),0)
|
||||
|
||||
/* assumed ASCII compatibility */
|
||||
#define ENC_CODERANGE_AND(a, b) \
|
||||
((a) == ENC_CODERANGE_7BIT ? (b) : \
|
||||
(a) == ENC_CODERANGE_VALID ? ((b) == ENC_CODERANGE_7BIT ? ENC_CODERANGE_VALID : (b)) : \
|
||||
ENC_CODERANGE_UNKNOWN)
|
||||
|
||||
#define ENCODING_CODERANGE_SET(obj, encindex, cr) \
|
||||
do { \
|
||||
VALUE rb_encoding_coderange_obj = (obj); \
|
||||
ENCODING_SET(rb_encoding_coderange_obj, (encindex)); \
|
||||
ENC_CODERANGE_SET(rb_encoding_coderange_obj, (cr)); \
|
||||
} while (0)
|
||||
|
||||
typedef OnigEncodingType rb_encoding;
|
||||
|
||||
int rb_char_to_option_kcode(int c, int *option, int *kcode);
|
||||
|
||||
int rb_enc_replicate(const char *, rb_encoding *);
|
||||
int rb_define_dummy_encoding(const char *);
|
||||
#define rb_enc_to_index(enc) ((enc) ? ENC_TO_ENCINDEX(enc) : 0)
|
||||
int rb_enc_get_index(VALUE obj);
|
||||
void rb_enc_set_index(VALUE obj, int encindex);
|
||||
int rb_enc_find_index(const char *name);
|
||||
int rb_to_encoding_index(VALUE);
|
||||
rb_encoding* rb_to_encoding(VALUE);
|
||||
rb_encoding* rb_find_encoding(VALUE);
|
||||
rb_encoding* rb_enc_get(VALUE);
|
||||
rb_encoding* rb_enc_compatible(VALUE,VALUE);
|
||||
rb_encoding* rb_enc_check(VALUE,VALUE);
|
||||
VALUE rb_enc_associate_index(VALUE, int);
|
||||
VALUE rb_enc_associate(VALUE, rb_encoding*);
|
||||
void rb_enc_copy(VALUE dst, VALUE src);
|
||||
|
||||
VALUE rb_enc_str_new(const char*, long, rb_encoding*);
|
||||
VALUE rb_enc_str_new_cstr(const char*, rb_encoding*);
|
||||
VALUE rb_enc_reg_new(const char*, long, rb_encoding*, int);
|
||||
PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3);
|
||||
VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list);
|
||||
long rb_enc_strlen(const char*, const char*, rb_encoding*);
|
||||
char* rb_enc_nth(const char*, const char*, long, rb_encoding*);
|
||||
VALUE rb_obj_encoding(VALUE);
|
||||
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc);
|
||||
VALUE rb_enc_uint_chr(unsigned int code, rb_encoding *enc);
|
||||
|
||||
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *);
|
||||
VALUE rb_str_export_to_enc(VALUE, rb_encoding *);
|
||||
VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to);
|
||||
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts);
|
||||
|
||||
#if defined(__GNUC__) && !defined(__PCC__)
|
||||
#define rb_enc_str_new_cstr(str, enc) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_enc_str_new((str), (long)strlen(str), (enc)) : \
|
||||
rb_enc_str_new_cstr((str), (enc)); \
|
||||
})
|
||||
#endif
|
||||
|
||||
PRINTF_ARGS(NORETURN(void rb_enc_raise(rb_encoding *, VALUE, const char*, ...)), 3, 4);
|
||||
|
||||
/* index -> rb_encoding */
|
||||
rb_encoding* rb_enc_from_index(int idx);
|
||||
|
||||
/* name -> rb_encoding */
|
||||
rb_encoding * rb_enc_find(const char *name);
|
||||
|
||||
/* rb_encoding * -> name */
|
||||
#define rb_enc_name(enc) (enc)->name
|
||||
|
||||
/* rb_encoding * -> minlen/maxlen */
|
||||
#define rb_enc_mbminlen(enc) (enc)->min_enc_len
|
||||
#define rb_enc_mbmaxlen(enc) (enc)->max_enc_len
|
||||
|
||||
/* -> mbclen (no error notification: 0 < ret <= e-p, no exception) */
|
||||
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc);
|
||||
|
||||
/* -> mbclen (only for valid encoding) */
|
||||
int rb_enc_fast_mbclen(const char *p, const char *e, rb_encoding *enc);
|
||||
|
||||
/* -> chlen, invalid or needmore */
|
||||
int rb_enc_precise_mbclen(const char *p, const char *e, rb_encoding *enc);
|
||||
#define MBCLEN_CHARFOUND_P(ret) ONIGENC_MBCLEN_CHARFOUND_P(ret)
|
||||
#define MBCLEN_CHARFOUND_LEN(ret) ONIGENC_MBCLEN_CHARFOUND_LEN(ret)
|
||||
#define MBCLEN_INVALID_P(ret) ONIGENC_MBCLEN_INVALID_P(ret)
|
||||
#define MBCLEN_NEEDMORE_P(ret) ONIGENC_MBCLEN_NEEDMORE_P(ret)
|
||||
#define MBCLEN_NEEDMORE_LEN(ret) ONIGENC_MBCLEN_NEEDMORE_LEN(ret)
|
||||
|
||||
/* -> 0x00..0x7f, -1 */
|
||||
int rb_enc_ascget(const char *p, const char *e, int *len, rb_encoding *enc);
|
||||
|
||||
|
||||
/* -> code (and len) or raise exception */
|
||||
unsigned int rb_enc_codepoint_len(const char *p, const char *e, int *len, rb_encoding *enc);
|
||||
|
||||
/* prototype for obsolete function */
|
||||
unsigned int rb_enc_codepoint(const char *p, const char *e, rb_encoding *enc);
|
||||
/* overriding macro */
|
||||
#define rb_enc_codepoint(p,e,enc) rb_enc_codepoint_len((p),(e),0,(enc))
|
||||
#define rb_enc_mbc_to_codepoint(p, e, enc) ONIGENC_MBC_TO_CODE((enc),(UChar*)(p),(UChar*)(e))
|
||||
|
||||
/* -> codelen>0 or raise exception */
|
||||
int rb_enc_codelen(int code, rb_encoding *enc);
|
||||
/* -> 0 for invalid codepoint */
|
||||
int rb_enc_code_to_mbclen(int code, rb_encoding *enc);
|
||||
#define rb_enc_code_to_mbclen(c, enc) ONIGENC_CODE_TO_MBCLEN((enc), (c));
|
||||
|
||||
/* code,ptr,encoding -> write buf */
|
||||
#define rb_enc_mbcput(c,buf,enc) ONIGENC_CODE_TO_MBC((enc),(c),(UChar*)(buf))
|
||||
|
||||
/* start, ptr, end, encoding -> prev_char */
|
||||
#define rb_enc_prev_char(s,p,e,enc) ((char *)onigenc_get_prev_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
|
||||
/* start, ptr, end, encoding -> next_char */
|
||||
#define rb_enc_left_char_head(s,p,e,enc) ((char *)onigenc_get_left_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
|
||||
#define rb_enc_right_char_head(s,p,e,enc) ((char *)onigenc_get_right_adjust_char_head((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e)))
|
||||
#define rb_enc_step_back(s,p,e,n,enc) ((char *)onigenc_step_back((enc),(UChar*)(s),(UChar*)(p),(UChar*)(e),(int)(n)))
|
||||
|
||||
/* ptr, ptr, encoding -> newline_or_not */
|
||||
#define rb_enc_is_newline(p,end,enc) ONIGENC_IS_MBC_NEWLINE((enc),(UChar*)(p),(UChar*)(end))
|
||||
|
||||
#define rb_enc_isctype(c,t,enc) ONIGENC_IS_CODE_CTYPE((enc),(c),(t))
|
||||
#define rb_enc_isascii(c,enc) ONIGENC_IS_CODE_ASCII(c)
|
||||
#define rb_enc_isalpha(c,enc) ONIGENC_IS_CODE_ALPHA((enc),(c))
|
||||
#define rb_enc_islower(c,enc) ONIGENC_IS_CODE_LOWER((enc),(c))
|
||||
#define rb_enc_isupper(c,enc) ONIGENC_IS_CODE_UPPER((enc),(c))
|
||||
#define rb_enc_ispunct(c,enc) ONIGENC_IS_CODE_PUNCT((enc),(c))
|
||||
#define rb_enc_isalnum(c,enc) ONIGENC_IS_CODE_ALNUM((enc),(c))
|
||||
#define rb_enc_isprint(c,enc) ONIGENC_IS_CODE_PRINT((enc),(c))
|
||||
#define rb_enc_isspace(c,enc) ONIGENC_IS_CODE_SPACE((enc),(c))
|
||||
#define rb_enc_isdigit(c,enc) ONIGENC_IS_CODE_DIGIT((enc),(c))
|
||||
|
||||
#define rb_enc_asciicompat(enc) (rb_enc_mbminlen(enc)==1 && !rb_enc_dummy_p(enc))
|
||||
|
||||
int rb_enc_casefold(char *to, const char *p, const char *e, rb_encoding *enc);
|
||||
int rb_enc_toupper(int c, rb_encoding *enc);
|
||||
int rb_enc_tolower(int c, rb_encoding *enc);
|
||||
ID rb_intern3(const char*, long, rb_encoding*);
|
||||
ID rb_interned_id_p(const char *, long, rb_encoding *);
|
||||
int rb_enc_symname_p(const char*, rb_encoding*);
|
||||
int rb_enc_symname2_p(const char*, long, rb_encoding*);
|
||||
int rb_enc_str_coderange(VALUE);
|
||||
long rb_str_coderange_scan_restartable(const char*, const char*, rb_encoding*, int*);
|
||||
int rb_enc_str_asciionly_p(VALUE);
|
||||
#define rb_enc_str_asciicompat_p(str) rb_enc_asciicompat(rb_enc_get(str))
|
||||
VALUE rb_enc_from_encoding(rb_encoding *enc);
|
||||
int rb_enc_unicode_p(rb_encoding *enc);
|
||||
rb_encoding *rb_ascii8bit_encoding(void);
|
||||
rb_encoding *rb_utf8_encoding(void);
|
||||
rb_encoding *rb_usascii_encoding(void);
|
||||
rb_encoding *rb_locale_encoding(void);
|
||||
rb_encoding *rb_filesystem_encoding(void);
|
||||
rb_encoding *rb_default_external_encoding(void);
|
||||
rb_encoding *rb_default_internal_encoding(void);
|
||||
#ifndef rb_ascii8bit_encindex
|
||||
int rb_ascii8bit_encindex(void);
|
||||
#endif
|
||||
#ifndef rb_utf8_encindex
|
||||
int rb_utf8_encindex(void);
|
||||
#endif
|
||||
#ifndef rb_usascii_encindex
|
||||
int rb_usascii_encindex(void);
|
||||
#endif
|
||||
int rb_locale_encindex(void);
|
||||
int rb_filesystem_encindex(void);
|
||||
VALUE rb_enc_default_external(void);
|
||||
VALUE rb_enc_default_internal(void);
|
||||
void rb_enc_set_default_external(VALUE encoding);
|
||||
void rb_enc_set_default_internal(VALUE encoding);
|
||||
VALUE rb_locale_charmap(VALUE klass);
|
||||
long rb_memsearch(const void*,long,const void*,long,rb_encoding*);
|
||||
char *rb_enc_path_next(const char *,const char *,rb_encoding*);
|
||||
char *rb_enc_path_skip_prefix(const char *,const char *,rb_encoding*);
|
||||
char *rb_enc_path_last_separator(const char *,const char *,rb_encoding*);
|
||||
char *rb_enc_path_end(const char *,const char *,rb_encoding*);
|
||||
const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc);
|
||||
const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc);
|
||||
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc);
|
||||
|
||||
RUBY_EXTERN VALUE rb_cEncoding;
|
||||
#define ENC_DUMMY_FLAG (1<<24)
|
||||
#define ENC_INDEX_MASK (~(~0U<<24))
|
||||
|
||||
#define ENC_TO_ENCINDEX(enc) (int)((enc)->ruby_encoding_index & ENC_INDEX_MASK)
|
||||
|
||||
#define ENC_DUMMY_P(enc) ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG)
|
||||
#define ENC_SET_DUMMY(enc) ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG)
|
||||
|
||||
static inline int
|
||||
rb_enc_dummy_p(rb_encoding *enc)
|
||||
{
|
||||
return ENC_DUMMY_P(enc) != 0;
|
||||
}
|
||||
|
||||
/* econv stuff */
|
||||
|
||||
typedef enum {
|
||||
econv_invalid_byte_sequence,
|
||||
econv_undefined_conversion,
|
||||
econv_destination_buffer_full,
|
||||
econv_source_buffer_empty,
|
||||
econv_finished,
|
||||
econv_after_output,
|
||||
econv_incomplete_input
|
||||
} rb_econv_result_t;
|
||||
|
||||
typedef struct rb_econv_t rb_econv_t;
|
||||
|
||||
VALUE rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts);
|
||||
int rb_econv_has_convpath_p(const char* from_encoding, const char* to_encoding);
|
||||
|
||||
int rb_econv_prepare_options(VALUE opthash, VALUE *ecopts, int ecflags);
|
||||
int rb_econv_prepare_opts(VALUE opthash, VALUE *ecopts);
|
||||
|
||||
rb_econv_t *rb_econv_open(const char *source_encoding, const char *destination_encoding, int ecflags);
|
||||
rb_econv_t *rb_econv_open_opts(const char *source_encoding, const char *destination_encoding, int ecflags, VALUE ecopts);
|
||||
|
||||
rb_econv_result_t rb_econv_convert(rb_econv_t *ec,
|
||||
const unsigned char **source_buffer_ptr, const unsigned char *source_buffer_end,
|
||||
unsigned char **destination_buffer_ptr, unsigned char *destination_buffer_end,
|
||||
int flags);
|
||||
void rb_econv_close(rb_econv_t *ec);
|
||||
|
||||
/* result: 0:success -1:failure */
|
||||
int rb_econv_set_replacement(rb_econv_t *ec, const unsigned char *str, size_t len, const char *encname);
|
||||
|
||||
/* result: 0:success -1:failure */
|
||||
int rb_econv_decorate_at_first(rb_econv_t *ec, const char *decorator_name);
|
||||
int rb_econv_decorate_at_last(rb_econv_t *ec, const char *decorator_name);
|
||||
|
||||
VALUE rb_econv_open_exc(const char *senc, const char *denc, int ecflags);
|
||||
|
||||
/* result: 0:success -1:failure */
|
||||
int rb_econv_insert_output(rb_econv_t *ec,
|
||||
const unsigned char *str, size_t len, const char *str_encoding);
|
||||
|
||||
/* encoding that rb_econv_insert_output doesn't need conversion */
|
||||
const char *rb_econv_encoding_to_insert_output(rb_econv_t *ec);
|
||||
|
||||
/* raise an error if the last rb_econv_convert is error */
|
||||
void rb_econv_check_error(rb_econv_t *ec);
|
||||
|
||||
/* returns an exception object or nil */
|
||||
VALUE rb_econv_make_exception(rb_econv_t *ec);
|
||||
|
||||
int rb_econv_putbackable(rb_econv_t *ec);
|
||||
void rb_econv_putback(rb_econv_t *ec, unsigned char *p, int n);
|
||||
|
||||
/* returns the corresponding ASCII compatible encoding for encname,
|
||||
* or NULL if encname is not ASCII incompatible encoding. */
|
||||
const char *rb_econv_asciicompat_encoding(const char *encname);
|
||||
|
||||
VALUE rb_econv_str_convert(rb_econv_t *ec, VALUE src, int flags);
|
||||
VALUE rb_econv_substr_convert(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, int flags);
|
||||
VALUE rb_econv_str_append(rb_econv_t *ec, VALUE src, VALUE dst, int flags);
|
||||
VALUE rb_econv_substr_append(rb_econv_t *ec, VALUE src, long byteoff, long bytesize, VALUE dst, int flags);
|
||||
VALUE rb_econv_append(rb_econv_t *ec, const char *bytesrc, long bytesize, VALUE dst, int flags);
|
||||
|
||||
void rb_econv_binmode(rb_econv_t *ec);
|
||||
|
||||
/* flags for rb_econv_open */
|
||||
|
||||
#define ECONV_ERROR_HANDLER_MASK 0x000000ff
|
||||
|
||||
#define ECONV_INVALID_MASK 0x0000000f
|
||||
#define ECONV_INVALID_REPLACE 0x00000002
|
||||
|
||||
#define ECONV_UNDEF_MASK 0x000000f0
|
||||
#define ECONV_UNDEF_REPLACE 0x00000020
|
||||
#define ECONV_UNDEF_HEX_CHARREF 0x00000030
|
||||
|
||||
#define ECONV_DECORATOR_MASK 0x0000ff00
|
||||
#define ECONV_NEWLINE_DECORATOR_MASK 0x00003f00
|
||||
#define ECONV_NEWLINE_DECORATOR_READ_MASK 0x00000f00
|
||||
#define ECONV_NEWLINE_DECORATOR_WRITE_MASK 0x00003000
|
||||
|
||||
#define ECONV_UNIVERSAL_NEWLINE_DECORATOR 0x00000100
|
||||
#define ECONV_CRLF_NEWLINE_DECORATOR 0x00001000
|
||||
#define ECONV_CR_NEWLINE_DECORATOR 0x00002000
|
||||
#define ECONV_XML_TEXT_DECORATOR 0x00004000
|
||||
#define ECONV_XML_ATTR_CONTENT_DECORATOR 0x00008000
|
||||
|
||||
#define ECONV_STATEFUL_DECORATOR_MASK 0x00f00000
|
||||
#define ECONV_XML_ATTR_QUOTE_DECORATOR 0x00100000
|
||||
|
||||
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
|
||||
#define ECONV_DEFAULT_NEWLINE_DECORATOR ECONV_CRLF_NEWLINE_DECORATOR
|
||||
#else
|
||||
#define ECONV_DEFAULT_NEWLINE_DECORATOR 0
|
||||
#endif
|
||||
|
||||
/* end of flags for rb_econv_open */
|
||||
|
||||
/* flags for rb_econv_convert */
|
||||
#define ECONV_PARTIAL_INPUT 0x00010000
|
||||
#define ECONV_AFTER_OUTPUT 0x00020000
|
||||
/* end of flags for rb_econv_convert */
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_ENCODING_H */
|
||||
959
ruby/include/ruby-2.1.0/ruby/intern.h
Normal file
959
ruby/include/ruby-2.1.0/ruby/intern.h
Normal file
@@ -0,0 +1,959 @@
|
||||
/**********************************************************************
|
||||
|
||||
intern.h -
|
||||
|
||||
$Author: nagachika $
|
||||
created at: Thu Jun 10 14:22:17 JST 1993
|
||||
|
||||
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
||||
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_INTERN_H
|
||||
#define RUBY_INTERN_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ruby/defines.h"
|
||||
#ifdef RUBY_EXTCONF_H
|
||||
#include RUBY_EXTCONF_H
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# include <stdarg.h>
|
||||
#else
|
||||
# include <varargs.h>
|
||||
#endif
|
||||
|
||||
#include "ruby/st.h"
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
/*
|
||||
* Functions and variables that are used by more than one source file of
|
||||
* the kernel.
|
||||
*/
|
||||
|
||||
#define UNLIMITED_ARGUMENTS (-1)
|
||||
|
||||
/* array.c */
|
||||
void rb_mem_clear(register VALUE*, register long);
|
||||
VALUE rb_assoc_new(VALUE, VALUE);
|
||||
VALUE rb_check_array_type(VALUE);
|
||||
VALUE rb_ary_new(void);
|
||||
VALUE rb_ary_new_capa(long capa);
|
||||
VALUE rb_ary_new_from_args(long n, ...);
|
||||
VALUE rb_ary_new_from_values(long n, const VALUE *elts);
|
||||
VALUE rb_ary_tmp_new(long);
|
||||
void rb_ary_free(VALUE);
|
||||
void rb_ary_modify(VALUE);
|
||||
VALUE rb_ary_freeze(VALUE);
|
||||
VALUE rb_ary_shared_with_p(VALUE, VALUE);
|
||||
VALUE rb_ary_aref(int, VALUE*, VALUE);
|
||||
VALUE rb_ary_subseq(VALUE, long, long);
|
||||
void rb_ary_store(VALUE, long, VALUE);
|
||||
VALUE rb_ary_dup(VALUE);
|
||||
VALUE rb_ary_resurrect(VALUE ary);
|
||||
VALUE rb_ary_to_ary(VALUE);
|
||||
VALUE rb_ary_to_s(VALUE);
|
||||
VALUE rb_ary_cat(VALUE, const VALUE *, long);
|
||||
VALUE rb_ary_push(VALUE, VALUE);
|
||||
VALUE rb_ary_pop(VALUE);
|
||||
VALUE rb_ary_shift(VALUE);
|
||||
VALUE rb_ary_unshift(VALUE, VALUE);
|
||||
VALUE rb_ary_entry(VALUE, long);
|
||||
VALUE rb_ary_each(VALUE);
|
||||
VALUE rb_ary_join(VALUE, VALUE);
|
||||
VALUE rb_ary_reverse(VALUE);
|
||||
VALUE rb_ary_rotate(VALUE, long);
|
||||
VALUE rb_ary_sort(VALUE);
|
||||
VALUE rb_ary_sort_bang(VALUE);
|
||||
VALUE rb_ary_delete(VALUE, VALUE);
|
||||
VALUE rb_ary_delete_at(VALUE, long);
|
||||
VALUE rb_ary_clear(VALUE);
|
||||
VALUE rb_ary_plus(VALUE, VALUE);
|
||||
VALUE rb_ary_concat(VALUE, VALUE);
|
||||
VALUE rb_ary_assoc(VALUE, VALUE);
|
||||
VALUE rb_ary_rassoc(VALUE, VALUE);
|
||||
VALUE rb_ary_includes(VALUE, VALUE);
|
||||
VALUE rb_ary_cmp(VALUE, VALUE);
|
||||
VALUE rb_ary_replace(VALUE copy, VALUE orig);
|
||||
VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long));
|
||||
VALUE rb_ary_resize(VALUE ary, long len);
|
||||
#define rb_ary_new2 rb_ary_new_capa
|
||||
#define rb_ary_new3 rb_ary_new_from_args
|
||||
#define rb_ary_new4 rb_ary_new_from_values
|
||||
/* bignum.c */
|
||||
VALUE rb_big_new(long, int);
|
||||
int rb_bigzero_p(VALUE x);
|
||||
VALUE rb_big_clone(VALUE);
|
||||
void rb_big_2comp(VALUE);
|
||||
VALUE rb_big_norm(VALUE);
|
||||
void rb_big_resize(VALUE big, long len);
|
||||
VALUE rb_cstr_to_inum(const char*, int, int);
|
||||
VALUE rb_str_to_inum(VALUE, int, int);
|
||||
VALUE rb_cstr2inum(const char*, int);
|
||||
VALUE rb_str2inum(VALUE, int);
|
||||
VALUE rb_big2str(VALUE, int);
|
||||
DEPRECATED(VALUE rb_big2str0(VALUE, int, int));
|
||||
SIGNED_VALUE rb_big2long(VALUE);
|
||||
#define rb_big2int(x) rb_big2long(x)
|
||||
VALUE rb_big2ulong(VALUE);
|
||||
#define rb_big2uint(x) rb_big2ulong(x)
|
||||
DEPRECATED(VALUE rb_big2ulong_pack(VALUE x));
|
||||
#if HAVE_LONG_LONG
|
||||
LONG_LONG rb_big2ll(VALUE);
|
||||
unsigned LONG_LONG rb_big2ull(VALUE);
|
||||
#endif /* HAVE_LONG_LONG */
|
||||
DEPRECATED(void rb_quad_pack(char*,VALUE));
|
||||
DEPRECATED(VALUE rb_quad_unpack(const char*,int));
|
||||
void rb_big_pack(VALUE val, unsigned long *buf, long num_longs);
|
||||
VALUE rb_big_unpack(unsigned long *buf, long num_longs);
|
||||
int rb_uv_to_utf8(char[6],unsigned long);
|
||||
VALUE rb_dbl2big(double);
|
||||
double rb_big2dbl(VALUE);
|
||||
VALUE rb_big_cmp(VALUE, VALUE);
|
||||
VALUE rb_big_eq(VALUE, VALUE);
|
||||
VALUE rb_big_eql(VALUE, VALUE);
|
||||
VALUE rb_big_plus(VALUE, VALUE);
|
||||
VALUE rb_big_minus(VALUE, VALUE);
|
||||
VALUE rb_big_mul(VALUE, VALUE);
|
||||
VALUE rb_big_div(VALUE, VALUE);
|
||||
VALUE rb_big_idiv(VALUE, VALUE);
|
||||
VALUE rb_big_modulo(VALUE, VALUE);
|
||||
VALUE rb_big_divmod(VALUE, VALUE);
|
||||
VALUE rb_big_pow(VALUE, VALUE);
|
||||
VALUE rb_big_and(VALUE, VALUE);
|
||||
VALUE rb_big_or(VALUE, VALUE);
|
||||
VALUE rb_big_xor(VALUE, VALUE);
|
||||
VALUE rb_big_lshift(VALUE, VALUE);
|
||||
VALUE rb_big_rshift(VALUE, VALUE);
|
||||
|
||||
/* For rb_integer_pack and rb_integer_unpack: */
|
||||
/* "MS" in MSWORD and MSBYTE means "most significant" */
|
||||
/* "LS" in LSWORD and LSBYTE means "least significant" */
|
||||
#define INTEGER_PACK_MSWORD_FIRST 0x01
|
||||
#define INTEGER_PACK_LSWORD_FIRST 0x02
|
||||
#define INTEGER_PACK_MSBYTE_FIRST 0x10
|
||||
#define INTEGER_PACK_LSBYTE_FIRST 0x20
|
||||
#define INTEGER_PACK_NATIVE_BYTE_ORDER 0x40
|
||||
#define INTEGER_PACK_2COMP 0x80
|
||||
#define INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION 0x400
|
||||
/* For rb_integer_unpack: */
|
||||
#define INTEGER_PACK_FORCE_BIGNUM 0x100
|
||||
#define INTEGER_PACK_NEGATIVE 0x200
|
||||
/* Combinations: */
|
||||
#define INTEGER_PACK_LITTLE_ENDIAN \
|
||||
(INTEGER_PACK_LSWORD_FIRST | \
|
||||
INTEGER_PACK_LSBYTE_FIRST)
|
||||
#define INTEGER_PACK_BIG_ENDIAN \
|
||||
(INTEGER_PACK_MSWORD_FIRST | \
|
||||
INTEGER_PACK_MSBYTE_FIRST)
|
||||
int rb_integer_pack(VALUE val, void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
|
||||
VALUE rb_integer_unpack(const void *words, size_t numwords, size_t wordsize, size_t nails, int flags);
|
||||
size_t rb_absint_size(VALUE val, int *nlz_bits_ret);
|
||||
size_t rb_absint_numwords(VALUE val, size_t word_numbits, size_t *nlz_bits_ret);
|
||||
int rb_absint_singlebit_p(VALUE val);
|
||||
|
||||
/* rational.c */
|
||||
VALUE rb_rational_raw(VALUE, VALUE);
|
||||
#define rb_rational_raw1(x) rb_rational_raw((x), INT2FIX(1))
|
||||
#define rb_rational_raw2(x,y) rb_rational_raw((x), (y))
|
||||
VALUE rb_rational_new(VALUE, VALUE);
|
||||
#define rb_rational_new1(x) rb_rational_new((x), INT2FIX(1))
|
||||
#define rb_rational_new2(x,y) rb_rational_new((x), (y))
|
||||
VALUE rb_Rational(VALUE, VALUE);
|
||||
#define rb_Rational1(x) rb_Rational((x), INT2FIX(1))
|
||||
#define rb_Rational2(x,y) rb_Rational((x), (y))
|
||||
VALUE rb_flt_rationalize_with_prec(VALUE, VALUE);
|
||||
VALUE rb_flt_rationalize(VALUE);
|
||||
/* complex.c */
|
||||
VALUE rb_complex_raw(VALUE, VALUE);
|
||||
#define rb_complex_raw1(x) rb_complex_raw((x), INT2FIX(0))
|
||||
#define rb_complex_raw2(x,y) rb_complex_raw((x), (y))
|
||||
VALUE rb_complex_new(VALUE, VALUE);
|
||||
#define rb_complex_new1(x) rb_complex_new((x), INT2FIX(0))
|
||||
#define rb_complex_new2(x,y) rb_complex_new((x), (y))
|
||||
VALUE rb_complex_polar(VALUE, VALUE);
|
||||
VALUE rb_Complex(VALUE, VALUE);
|
||||
#define rb_Complex1(x) rb_Complex((x), INT2FIX(0))
|
||||
#define rb_Complex2(x,y) rb_Complex((x), (y))
|
||||
/* class.c */
|
||||
VALUE rb_class_boot(VALUE);
|
||||
VALUE rb_class_new(VALUE);
|
||||
VALUE rb_mod_init_copy(VALUE, VALUE);
|
||||
VALUE rb_singleton_class_clone(VALUE);
|
||||
void rb_singleton_class_attached(VALUE,VALUE);
|
||||
VALUE rb_make_metaclass(VALUE, VALUE);
|
||||
void rb_check_inheritable(VALUE);
|
||||
VALUE rb_class_inherited(VALUE, VALUE);
|
||||
VALUE rb_define_class_id(ID, VALUE);
|
||||
VALUE rb_define_class_id_under(VALUE, ID, VALUE);
|
||||
VALUE rb_module_new(void);
|
||||
VALUE rb_define_module_id(ID);
|
||||
VALUE rb_define_module_id_under(VALUE, ID);
|
||||
VALUE rb_include_class_new(VALUE, VALUE);
|
||||
VALUE rb_mod_included_modules(VALUE);
|
||||
VALUE rb_mod_include_p(VALUE, VALUE);
|
||||
VALUE rb_mod_ancestors(VALUE);
|
||||
VALUE rb_class_instance_methods(int, VALUE*, VALUE);
|
||||
VALUE rb_class_public_instance_methods(int, VALUE*, VALUE);
|
||||
VALUE rb_class_protected_instance_methods(int, VALUE*, VALUE);
|
||||
VALUE rb_class_private_instance_methods(int, VALUE*, VALUE);
|
||||
VALUE rb_obj_singleton_methods(int, VALUE*, VALUE);
|
||||
void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int);
|
||||
void rb_frozen_class_p(VALUE);
|
||||
void rb_undef(VALUE, ID);
|
||||
void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
|
||||
void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int);
|
||||
void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int);
|
||||
VALUE rb_singleton_class(VALUE);
|
||||
/* compar.c */
|
||||
int rb_cmpint(VALUE, VALUE, VALUE);
|
||||
NORETURN(void rb_cmperr(VALUE, VALUE));
|
||||
/* cont.c */
|
||||
VALUE rb_fiber_new(VALUE (*)(ANYARGS), VALUE);
|
||||
VALUE rb_fiber_resume(VALUE fib, int argc, VALUE *args);
|
||||
VALUE rb_fiber_yield(int argc, VALUE *args);
|
||||
VALUE rb_fiber_current(void);
|
||||
VALUE rb_fiber_alive_p(VALUE);
|
||||
/* enum.c */
|
||||
VALUE rb_enum_values_pack(int, const VALUE*);
|
||||
/* enumerator.c */
|
||||
VALUE rb_enumeratorize(VALUE, VALUE, int, VALUE *);
|
||||
typedef VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE);
|
||||
VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, VALUE *, rb_enumerator_size_func *);
|
||||
#ifndef RUBY_EXPORT
|
||||
#define rb_enumeratorize_with_size(obj, id, argc, argv, size_fn) \
|
||||
rb_enumeratorize_with_size(obj, id, argc, argv, (rb_enumerator_size_func *)(size_fn))
|
||||
#endif
|
||||
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \
|
||||
if (!rb_block_given_p()) \
|
||||
return rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()),\
|
||||
(argc), (argv), (size_fn)); \
|
||||
} while (0)
|
||||
#define RETURN_ENUMERATOR(obj, argc, argv) RETURN_SIZED_ENUMERATOR(obj, argc, argv, 0)
|
||||
/* error.c */
|
||||
VALUE rb_exc_new(VALUE, const char*, long);
|
||||
VALUE rb_exc_new_cstr(VALUE, const char*);
|
||||
VALUE rb_exc_new_str(VALUE, VALUE);
|
||||
#define rb_exc_new2 rb_exc_new_cstr
|
||||
#define rb_exc_new3 rb_exc_new_str
|
||||
PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2);
|
||||
PRINTF_ARGS(NORETURN(void rb_loaderror_with_path(VALUE path, const char*, ...)), 2, 3);
|
||||
PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3);
|
||||
PRINTF_ARGS(NORETURN(void rb_name_error_str(VALUE, const char*, ...)), 2, 3);
|
||||
NORETURN(void rb_invalid_str(const char*, const char*));
|
||||
PRINTF_ARGS(void rb_compile_error(const char*, int, const char*, ...), 3, 4);
|
||||
PRINTF_ARGS(void rb_compile_error_with_enc(const char*, int, void *, const char*, ...), 4, 5);
|
||||
PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2);
|
||||
NORETURN(void rb_error_frozen(const char*));
|
||||
void rb_error_untrusted(VALUE);
|
||||
void rb_check_frozen(VALUE);
|
||||
void rb_check_trusted(VALUE);
|
||||
#define rb_check_frozen_internal(obj) do { \
|
||||
VALUE frozen_obj = (obj); \
|
||||
if (OBJ_FROZEN(frozen_obj)) { \
|
||||
rb_error_frozen(rb_obj_classname(frozen_obj)); \
|
||||
} \
|
||||
} while (0)
|
||||
#define rb_check_trusted_internal(obj) ((void) 0)
|
||||
#ifdef __GNUC__
|
||||
#define rb_check_frozen(obj) __extension__({rb_check_frozen_internal(obj);})
|
||||
#define rb_check_trusted(obj) __extension__({rb_check_trusted_internal(obj);})
|
||||
#else
|
||||
static inline void
|
||||
rb_check_frozen_inline(VALUE obj)
|
||||
{
|
||||
rb_check_frozen_internal(obj);
|
||||
}
|
||||
#define rb_check_frozen(obj) rb_check_frozen_inline(obj)
|
||||
static inline void
|
||||
rb_check_trusted_inline(VALUE obj)
|
||||
{
|
||||
rb_check_trusted_internal(obj);
|
||||
}
|
||||
#define rb_check_trusted(obj) rb_check_trusted_inline(obj)
|
||||
#endif
|
||||
void rb_check_copyable(VALUE obj, VALUE orig);
|
||||
|
||||
#define OBJ_INIT_COPY(obj, orig) \
|
||||
((obj) != (orig) && (rb_obj_init_copy((obj), (orig)), 1))
|
||||
|
||||
/* eval.c */
|
||||
int rb_sourceline(void);
|
||||
const char *rb_sourcefile(void);
|
||||
VALUE rb_check_funcall(VALUE, ID, int, const VALUE*);
|
||||
|
||||
NORETURN(void rb_error_arity(int, int, int));
|
||||
#define rb_check_arity rb_check_arity /* for ifdef */
|
||||
static inline void
|
||||
rb_check_arity(int argc, int min, int max)
|
||||
{
|
||||
if ((argc < min) || (max != UNLIMITED_ARGUMENTS && argc > max))
|
||||
rb_error_arity(argc, min, max);
|
||||
}
|
||||
|
||||
#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT)
|
||||
typedef struct {
|
||||
int maxfd;
|
||||
fd_set *fdset;
|
||||
} rb_fdset_t;
|
||||
|
||||
void rb_fd_init(rb_fdset_t *);
|
||||
void rb_fd_term(rb_fdset_t *);
|
||||
void rb_fd_zero(rb_fdset_t *);
|
||||
void rb_fd_set(int, rb_fdset_t *);
|
||||
void rb_fd_clr(int, rb_fdset_t *);
|
||||
int rb_fd_isset(int, const rb_fdset_t *);
|
||||
void rb_fd_copy(rb_fdset_t *, const fd_set *, int);
|
||||
void rb_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src);
|
||||
int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
|
||||
|
||||
#define rb_fd_ptr(f) ((f)->fdset)
|
||||
#define rb_fd_max(f) ((f)->maxfd)
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
typedef struct {
|
||||
int capa;
|
||||
fd_set *fdset;
|
||||
} rb_fdset_t;
|
||||
|
||||
void rb_fd_init(rb_fdset_t *);
|
||||
void rb_fd_term(rb_fdset_t *);
|
||||
#define rb_fd_zero(f) ((f)->fdset->fd_count = 0)
|
||||
void rb_fd_set(int, rb_fdset_t *);
|
||||
#define rb_fd_clr(n, f) rb_w32_fdclr((n), (f)->fdset)
|
||||
#define rb_fd_isset(n, f) rb_w32_fdisset((n), (f)->fdset)
|
||||
#define rb_fd_copy(d, s, n) rb_w32_fd_copy((d), (s), (n))
|
||||
void rb_w32_fd_copy(rb_fdset_t *, const fd_set *, int);
|
||||
#define rb_fd_dup(d, s) rb_w32_fd_dup((d), (s))
|
||||
void rb_w32_fd_dup(rb_fdset_t *dst, const rb_fdset_t *src);
|
||||
#define rb_fd_select(n, rfds, wfds, efds, timeout) rb_w32_select((n), (rfds) ? ((rb_fdset_t*)(rfds))->fdset : NULL, (wfds) ? ((rb_fdset_t*)(wfds))->fdset : NULL, (efds) ? ((rb_fdset_t*)(efds))->fdset: NULL, (timeout))
|
||||
#define rb_fd_resize(n, f) ((void)(f))
|
||||
|
||||
#define rb_fd_ptr(f) ((f)->fdset)
|
||||
#define rb_fd_max(f) ((f)->fdset->fd_count)
|
||||
|
||||
#else
|
||||
|
||||
typedef fd_set rb_fdset_t;
|
||||
#define rb_fd_zero(f) FD_ZERO(f)
|
||||
#define rb_fd_set(n, f) FD_SET((n), (f))
|
||||
#define rb_fd_clr(n, f) FD_CLR((n), (f))
|
||||
#define rb_fd_isset(n, f) FD_ISSET((n), (f))
|
||||
#define rb_fd_copy(d, s, n) (*(d) = *(s))
|
||||
#define rb_fd_dup(d, s) (*(d) = *(s))
|
||||
#define rb_fd_resize(n, f) ((void)(f))
|
||||
#define rb_fd_ptr(f) (f)
|
||||
#define rb_fd_init(f) FD_ZERO(f)
|
||||
#define rb_fd_init_copy(d, s) (*(d) = *(s))
|
||||
#define rb_fd_term(f) ((void)(f))
|
||||
#define rb_fd_max(f) FD_SETSIZE
|
||||
#define rb_fd_select(n, rfds, wfds, efds, timeout) select((n), (rfds), (wfds), (efds), (timeout))
|
||||
|
||||
#endif
|
||||
|
||||
NORETURN(void rb_exc_raise(VALUE));
|
||||
NORETURN(void rb_exc_fatal(VALUE));
|
||||
VALUE rb_f_exit(int,VALUE*);
|
||||
VALUE rb_f_abort(int,VALUE*);
|
||||
void rb_remove_method(VALUE, const char*);
|
||||
void rb_remove_method_id(VALUE, ID);
|
||||
#define rb_disable_super(klass, name) ((void)0)
|
||||
#define rb_enable_super(klass, name) ((void)0)
|
||||
#define HAVE_RB_DEFINE_ALLOC_FUNC 1
|
||||
typedef VALUE (*rb_alloc_func_t)(VALUE);
|
||||
void rb_define_alloc_func(VALUE, rb_alloc_func_t);
|
||||
void rb_undef_alloc_func(VALUE);
|
||||
rb_alloc_func_t rb_get_alloc_func(VALUE);
|
||||
void rb_clear_cache(void);
|
||||
void rb_clear_constant_cache(void);
|
||||
void rb_clear_method_cache_by_class(VALUE);
|
||||
void rb_alias(VALUE, ID, ID);
|
||||
void rb_attr(VALUE,ID,int,int,int);
|
||||
int rb_method_boundp(VALUE, ID, int);
|
||||
int rb_method_basic_definition_p(VALUE, ID);
|
||||
VALUE rb_eval_cmd(VALUE, VALUE, int);
|
||||
int rb_obj_respond_to(VALUE, ID, int);
|
||||
int rb_respond_to(VALUE, ID);
|
||||
VALUE rb_f_notimplement(int argc, VALUE *argv, VALUE obj);
|
||||
void rb_interrupt(void);
|
||||
VALUE rb_apply(VALUE, ID, VALUE);
|
||||
void rb_backtrace(void);
|
||||
ID rb_frame_this_func(void);
|
||||
VALUE rb_obj_instance_eval(int, VALUE*, VALUE);
|
||||
VALUE rb_obj_instance_exec(int, VALUE*, VALUE);
|
||||
VALUE rb_mod_module_eval(int, VALUE*, VALUE);
|
||||
VALUE rb_mod_module_exec(int, VALUE*, VALUE);
|
||||
void rb_load(VALUE, int);
|
||||
void rb_load_protect(VALUE, int, int*);
|
||||
NORETURN(void rb_jump_tag(int));
|
||||
int rb_provided(const char*);
|
||||
int rb_feature_provided(const char *, const char **);
|
||||
void rb_provide(const char*);
|
||||
VALUE rb_f_require(VALUE, VALUE);
|
||||
VALUE rb_require_safe(VALUE, int);
|
||||
void rb_obj_call_init(VALUE, int, VALUE*);
|
||||
VALUE rb_class_new_instance(int, VALUE*, VALUE);
|
||||
VALUE rb_block_proc(void);
|
||||
VALUE rb_block_lambda(void);
|
||||
VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE);
|
||||
VALUE rb_obj_is_proc(VALUE);
|
||||
VALUE rb_proc_call(VALUE, VALUE);
|
||||
VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE);
|
||||
int rb_proc_arity(VALUE);
|
||||
VALUE rb_proc_lambda_p(VALUE);
|
||||
VALUE rb_binding_new(void);
|
||||
VALUE rb_obj_method(VALUE, VALUE);
|
||||
VALUE rb_obj_is_method(VALUE);
|
||||
VALUE rb_method_call(int, VALUE*, VALUE);
|
||||
VALUE rb_method_call_with_block(int, VALUE *, VALUE, VALUE);
|
||||
int rb_mod_method_arity(VALUE, ID);
|
||||
int rb_obj_method_arity(VALUE, ID);
|
||||
VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*);
|
||||
void rb_set_end_proc(void (*)(VALUE), VALUE);
|
||||
void rb_exec_end_proc(void);
|
||||
void rb_thread_schedule(void);
|
||||
void rb_thread_wait_fd(int);
|
||||
int rb_thread_fd_writable(int);
|
||||
void rb_thread_fd_close(int);
|
||||
int rb_thread_alone(void);
|
||||
DEPRECATED(void rb_thread_polling(void));
|
||||
void rb_thread_sleep(int);
|
||||
void rb_thread_sleep_forever(void);
|
||||
void rb_thread_sleep_deadly(void);
|
||||
VALUE rb_thread_stop(void);
|
||||
VALUE rb_thread_wakeup(VALUE);
|
||||
VALUE rb_thread_wakeup_alive(VALUE);
|
||||
VALUE rb_thread_run(VALUE);
|
||||
VALUE rb_thread_kill(VALUE);
|
||||
VALUE rb_thread_create(VALUE (*)(ANYARGS), void*);
|
||||
DEPRECATED(int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *));
|
||||
int rb_thread_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *);
|
||||
void rb_thread_wait_for(struct timeval);
|
||||
VALUE rb_thread_current(void);
|
||||
VALUE rb_thread_main(void);
|
||||
VALUE rb_thread_local_aref(VALUE, ID);
|
||||
VALUE rb_thread_local_aset(VALUE, ID, VALUE);
|
||||
void rb_thread_atfork(void);
|
||||
void rb_thread_atfork_before_exec(void);
|
||||
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE);
|
||||
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE);
|
||||
VALUE rb_exec_recursive_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE);
|
||||
VALUE rb_exec_recursive_paired_outer(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE,VALUE);
|
||||
/* dir.c */
|
||||
VALUE rb_dir_getwd(void);
|
||||
/* file.c */
|
||||
VALUE rb_file_s_expand_path(int, VALUE *);
|
||||
VALUE rb_file_expand_path(VALUE, VALUE);
|
||||
VALUE rb_file_s_absolute_path(int, VALUE *);
|
||||
VALUE rb_file_absolute_path(VALUE, VALUE);
|
||||
VALUE rb_file_dirname(VALUE fname);
|
||||
int rb_find_file_ext_safe(VALUE*, const char* const*, int);
|
||||
VALUE rb_find_file_safe(VALUE, int);
|
||||
int rb_find_file_ext(VALUE*, const char* const*);
|
||||
VALUE rb_find_file(VALUE);
|
||||
VALUE rb_file_directory_p(VALUE,VALUE);
|
||||
VALUE rb_str_encode_ospath(VALUE);
|
||||
int rb_is_absolute_path(const char *);
|
||||
/* gc.c */
|
||||
NORETURN(void rb_memerror(void));
|
||||
int rb_during_gc(void);
|
||||
void rb_gc_mark_locations(VALUE*, VALUE*);
|
||||
void rb_mark_tbl(struct st_table*);
|
||||
void rb_mark_set(struct st_table*);
|
||||
void rb_mark_hash(struct st_table*);
|
||||
void rb_gc_mark_maybe(VALUE);
|
||||
void rb_gc_mark(VALUE);
|
||||
void rb_gc_force_recycle(VALUE);
|
||||
void rb_gc(void);
|
||||
void rb_gc_copy_finalizer(VALUE,VALUE);
|
||||
void rb_gc_finalize_deferred(void);
|
||||
void rb_gc_call_finalizer_at_exit(void);
|
||||
VALUE rb_gc_enable(void);
|
||||
VALUE rb_gc_disable(void);
|
||||
VALUE rb_gc_start(void);
|
||||
DEPRECATED(void rb_gc_set_params(void));
|
||||
VALUE rb_define_finalizer(VALUE, VALUE);
|
||||
VALUE rb_undefine_finalizer(VALUE);
|
||||
size_t rb_gc_count(void);
|
||||
size_t rb_gc_stat(VALUE);
|
||||
VALUE rb_gc_latest_gc_info(VALUE);
|
||||
/* hash.c */
|
||||
void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t);
|
||||
VALUE rb_check_hash_type(VALUE);
|
||||
void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE);
|
||||
VALUE rb_hash(VALUE);
|
||||
VALUE rb_hash_new(void);
|
||||
VALUE rb_hash_dup(VALUE);
|
||||
VALUE rb_hash_freeze(VALUE);
|
||||
VALUE rb_hash_aref(VALUE, VALUE);
|
||||
VALUE rb_hash_lookup(VALUE, VALUE);
|
||||
VALUE rb_hash_lookup2(VALUE, VALUE, VALUE);
|
||||
VALUE rb_hash_fetch(VALUE, VALUE);
|
||||
VALUE rb_hash_aset(VALUE, VALUE, VALUE);
|
||||
VALUE rb_hash_clear(VALUE);
|
||||
VALUE rb_hash_delete_if(VALUE);
|
||||
VALUE rb_hash_delete(VALUE,VALUE);
|
||||
VALUE rb_hash_set_ifnone(VALUE hash, VALUE ifnone);
|
||||
typedef VALUE rb_hash_update_func(VALUE newkey, VALUE oldkey, VALUE value);
|
||||
VALUE rb_hash_update_by(VALUE hash1, VALUE hash2, rb_hash_update_func *func);
|
||||
struct st_table *rb_hash_tbl(VALUE);
|
||||
int rb_path_check(const char*);
|
||||
int rb_env_path_tainted(void);
|
||||
VALUE rb_env_clear(void);
|
||||
/* io.c */
|
||||
#define rb_defout rb_stdout
|
||||
RUBY_EXTERN VALUE rb_fs;
|
||||
RUBY_EXTERN VALUE rb_output_fs;
|
||||
RUBY_EXTERN VALUE rb_rs;
|
||||
RUBY_EXTERN VALUE rb_default_rs;
|
||||
RUBY_EXTERN VALUE rb_output_rs;
|
||||
VALUE rb_io_write(VALUE, VALUE);
|
||||
VALUE rb_io_gets(VALUE);
|
||||
VALUE rb_io_getbyte(VALUE);
|
||||
VALUE rb_io_ungetc(VALUE, VALUE);
|
||||
VALUE rb_io_ungetbyte(VALUE, VALUE);
|
||||
VALUE rb_io_close(VALUE);
|
||||
VALUE rb_io_flush(VALUE);
|
||||
VALUE rb_io_eof(VALUE);
|
||||
VALUE rb_io_binmode(VALUE);
|
||||
VALUE rb_io_ascii8bit_binmode(VALUE);
|
||||
VALUE rb_io_addstr(VALUE, VALUE);
|
||||
VALUE rb_io_printf(int, VALUE*, VALUE);
|
||||
VALUE rb_io_print(int, VALUE*, VALUE);
|
||||
VALUE rb_io_puts(int, VALUE*, VALUE);
|
||||
VALUE rb_io_fdopen(int, int, const char*);
|
||||
VALUE rb_io_get_io(VALUE);
|
||||
VALUE rb_file_open(const char*, const char*);
|
||||
VALUE rb_file_open_str(VALUE, const char*);
|
||||
VALUE rb_gets(void);
|
||||
void rb_write_error(const char*);
|
||||
void rb_write_error2(const char*, long);
|
||||
void rb_close_before_exec(int lowfd, int maxhint, VALUE noclose_fds);
|
||||
int rb_pipe(int *pipes);
|
||||
int rb_reserved_fd_p(int fd);
|
||||
int rb_cloexec_open(const char *pathname, int flags, mode_t mode);
|
||||
int rb_cloexec_dup(int oldfd);
|
||||
int rb_cloexec_dup2(int oldfd, int newfd);
|
||||
int rb_cloexec_pipe(int fildes[2]);
|
||||
int rb_cloexec_fcntl_dupfd(int fd, int minfd);
|
||||
#define RB_RESERVED_FD_P(fd) rb_reserved_fd_p(fd)
|
||||
void rb_update_max_fd(int fd);
|
||||
void rb_fd_fix_cloexec(int fd);
|
||||
/* marshal.c */
|
||||
VALUE rb_marshal_dump(VALUE, VALUE);
|
||||
VALUE rb_marshal_load(VALUE);
|
||||
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE (*dumper)(VALUE), VALUE (*loader)(VALUE, VALUE));
|
||||
/* numeric.c */
|
||||
NORETURN(void rb_num_zerodiv(void));
|
||||
#define RB_NUM_COERCE_FUNCS_NEED_OPID 1
|
||||
VALUE rb_num_coerce_bin(VALUE, VALUE, ID);
|
||||
VALUE rb_num_coerce_cmp(VALUE, VALUE, ID);
|
||||
VALUE rb_num_coerce_relop(VALUE, VALUE, ID);
|
||||
VALUE rb_num_coerce_bit(VALUE, VALUE, ID);
|
||||
VALUE rb_num2fix(VALUE);
|
||||
VALUE rb_fix2str(VALUE, int);
|
||||
VALUE rb_dbl_cmp(double, double);
|
||||
/* object.c */
|
||||
int rb_eql(VALUE, VALUE);
|
||||
VALUE rb_any_to_s(VALUE);
|
||||
VALUE rb_inspect(VALUE);
|
||||
VALUE rb_obj_is_instance_of(VALUE, VALUE);
|
||||
VALUE rb_obj_is_kind_of(VALUE, VALUE);
|
||||
VALUE rb_obj_alloc(VALUE);
|
||||
VALUE rb_obj_clone(VALUE);
|
||||
VALUE rb_obj_dup(VALUE);
|
||||
VALUE rb_obj_init_copy(VALUE,VALUE);
|
||||
VALUE rb_obj_taint(VALUE);
|
||||
VALUE rb_obj_tainted(VALUE);
|
||||
VALUE rb_obj_untaint(VALUE);
|
||||
VALUE rb_obj_untrust(VALUE);
|
||||
VALUE rb_obj_untrusted(VALUE);
|
||||
VALUE rb_obj_trust(VALUE);
|
||||
VALUE rb_obj_freeze(VALUE);
|
||||
VALUE rb_obj_frozen_p(VALUE);
|
||||
VALUE rb_obj_id(VALUE);
|
||||
VALUE rb_obj_class(VALUE);
|
||||
VALUE rb_class_real(VALUE);
|
||||
VALUE rb_class_inherited_p(VALUE, VALUE);
|
||||
VALUE rb_class_superclass(VALUE);
|
||||
VALUE rb_class_get_superclass(VALUE);
|
||||
VALUE rb_convert_type(VALUE,int,const char*,const char*);
|
||||
VALUE rb_check_convert_type(VALUE,int,const char*,const char*);
|
||||
VALUE rb_check_to_integer(VALUE, const char *);
|
||||
VALUE rb_check_to_float(VALUE);
|
||||
VALUE rb_to_int(VALUE);
|
||||
VALUE rb_check_to_int(VALUE);
|
||||
VALUE rb_Integer(VALUE);
|
||||
VALUE rb_to_float(VALUE);
|
||||
VALUE rb_Float(VALUE);
|
||||
VALUE rb_String(VALUE);
|
||||
VALUE rb_Array(VALUE);
|
||||
VALUE rb_Hash(VALUE);
|
||||
double rb_cstr_to_dbl(const char*, int);
|
||||
double rb_str_to_dbl(VALUE, int);
|
||||
/* parse.y */
|
||||
RUBY_EXTERN int ruby_sourceline;
|
||||
RUBY_EXTERN char *ruby_sourcefile;
|
||||
ID rb_id_attrset(ID);
|
||||
int rb_is_const_id(ID);
|
||||
int rb_is_global_id(ID);
|
||||
int rb_is_instance_id(ID);
|
||||
int rb_is_attrset_id(ID);
|
||||
int rb_is_class_id(ID);
|
||||
int rb_is_local_id(ID);
|
||||
int rb_is_junk_id(ID);
|
||||
int rb_symname_p(const char*);
|
||||
int rb_sym_interned_p(VALUE);
|
||||
VALUE rb_backref_get(void);
|
||||
void rb_backref_set(VALUE);
|
||||
VALUE rb_lastline_get(void);
|
||||
void rb_lastline_set(VALUE);
|
||||
VALUE rb_sym_all_symbols(void);
|
||||
/* process.c */
|
||||
void rb_last_status_set(int status, rb_pid_t pid);
|
||||
VALUE rb_last_status_get(void);
|
||||
struct rb_exec_arg {
|
||||
VALUE execarg_obj;
|
||||
};
|
||||
DEPRECATED(int rb_proc_exec_n(int, VALUE*, const char*));
|
||||
int rb_proc_exec(const char*);
|
||||
DEPRECATED(VALUE rb_exec_arg_init(int argc, VALUE *argv, int accept_shell, struct rb_exec_arg *e));
|
||||
DEPRECATED(int rb_exec_arg_addopt(struct rb_exec_arg *e, VALUE key, VALUE val));
|
||||
DEPRECATED(void rb_exec_arg_fixup(struct rb_exec_arg *e));
|
||||
DEPRECATED(int rb_run_exec_options(const struct rb_exec_arg *e, struct rb_exec_arg *s));
|
||||
DEPRECATED(int rb_run_exec_options_err(const struct rb_exec_arg *e, struct rb_exec_arg *s, char*, size_t));
|
||||
DEPRECATED(int rb_exec(const struct rb_exec_arg*));
|
||||
DEPRECATED(int rb_exec_err(const struct rb_exec_arg*, char*, size_t));
|
||||
DEPRECATED(rb_pid_t rb_fork(int*, int (*)(void*), void*, VALUE));
|
||||
DEPRECATED(rb_pid_t rb_fork_err(int*, int (*)(void*, char*, size_t), void*, VALUE, char*, size_t));
|
||||
VALUE rb_f_exec(int,VALUE*);
|
||||
rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags);
|
||||
void rb_syswait(rb_pid_t pid);
|
||||
rb_pid_t rb_spawn(int, VALUE*);
|
||||
rb_pid_t rb_spawn_err(int, VALUE*, char*, size_t);
|
||||
VALUE rb_proc_times(VALUE);
|
||||
VALUE rb_detach_process(rb_pid_t pid);
|
||||
/* range.c */
|
||||
VALUE rb_range_new(VALUE, VALUE, int);
|
||||
VALUE rb_range_beg_len(VALUE, long*, long*, long, int);
|
||||
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp);
|
||||
/* random.c */
|
||||
unsigned int rb_genrand_int32(void);
|
||||
double rb_genrand_real(void);
|
||||
void rb_reset_random_seed(void);
|
||||
VALUE rb_random_bytes(VALUE rnd, long n);
|
||||
VALUE rb_random_int(VALUE rnd, VALUE max);
|
||||
unsigned int rb_random_int32(VALUE rnd);
|
||||
double rb_random_real(VALUE rnd);
|
||||
unsigned long rb_random_ulong_limited(VALUE rnd, unsigned long limit);
|
||||
unsigned long rb_genrand_ulong_limited(unsigned long i);
|
||||
/* re.c */
|
||||
#define rb_memcmp memcmp
|
||||
int rb_memcicmp(const void*,const void*,long);
|
||||
void rb_match_busy(VALUE);
|
||||
VALUE rb_reg_nth_defined(int, VALUE);
|
||||
VALUE rb_reg_nth_match(int, VALUE);
|
||||
int rb_reg_backref_number(VALUE match, VALUE backref);
|
||||
VALUE rb_reg_last_match(VALUE);
|
||||
VALUE rb_reg_match_pre(VALUE);
|
||||
VALUE rb_reg_match_post(VALUE);
|
||||
VALUE rb_reg_match_last(VALUE);
|
||||
#define HAVE_RB_REG_NEW_STR 1
|
||||
VALUE rb_reg_new_str(VALUE, int);
|
||||
VALUE rb_reg_new(const char *, long, int);
|
||||
VALUE rb_reg_alloc(void);
|
||||
VALUE rb_reg_init_str(VALUE re, VALUE s, int options);
|
||||
VALUE rb_reg_match(VALUE, VALUE);
|
||||
VALUE rb_reg_match2(VALUE);
|
||||
int rb_reg_options(VALUE);
|
||||
/* ruby.c */
|
||||
#define rb_argv rb_get_argv()
|
||||
RUBY_EXTERN VALUE rb_argv0;
|
||||
VALUE rb_get_argv(void);
|
||||
void *rb_load_file(const char*);
|
||||
void *rb_load_file_str(VALUE);
|
||||
/* signal.c */
|
||||
VALUE rb_f_kill(int, VALUE*);
|
||||
#ifdef POSIX_SIGNAL
|
||||
#define posix_signal ruby_posix_signal
|
||||
RETSIGTYPE (*posix_signal(int, RETSIGTYPE (*)(int)))(int);
|
||||
#endif
|
||||
void rb_trap_exit(void);
|
||||
void rb_trap_exec(void);
|
||||
const char *ruby_signal_name(int);
|
||||
void ruby_default_signal(int);
|
||||
/* sprintf.c */
|
||||
VALUE rb_f_sprintf(int, const VALUE*);
|
||||
PRINTF_ARGS(VALUE rb_sprintf(const char*, ...), 1, 2);
|
||||
VALUE rb_vsprintf(const char*, va_list);
|
||||
PRINTF_ARGS(VALUE rb_str_catf(VALUE, const char*, ...), 2, 3);
|
||||
VALUE rb_str_vcatf(VALUE, const char*, va_list);
|
||||
VALUE rb_str_format(int, const VALUE *, VALUE);
|
||||
/* string.c */
|
||||
VALUE rb_str_new(const char*, long);
|
||||
VALUE rb_str_new_cstr(const char*);
|
||||
VALUE rb_str_new_shared(VALUE);
|
||||
VALUE rb_str_new_frozen(VALUE);
|
||||
VALUE rb_str_new_with_class(VALUE, const char*, long);
|
||||
VALUE rb_tainted_str_new_cstr(const char*);
|
||||
VALUE rb_tainted_str_new(const char*, long);
|
||||
VALUE rb_external_str_new(const char*, long);
|
||||
VALUE rb_external_str_new_cstr(const char*);
|
||||
VALUE rb_locale_str_new(const char*, long);
|
||||
VALUE rb_locale_str_new_cstr(const char*);
|
||||
VALUE rb_filesystem_str_new(const char*, long);
|
||||
VALUE rb_filesystem_str_new_cstr(const char*);
|
||||
VALUE rb_str_buf_new(long);
|
||||
VALUE rb_str_buf_new_cstr(const char*);
|
||||
VALUE rb_str_buf_new2(const char*);
|
||||
VALUE rb_str_tmp_new(long);
|
||||
VALUE rb_usascii_str_new(const char*, long);
|
||||
VALUE rb_usascii_str_new_cstr(const char*);
|
||||
void rb_str_free(VALUE);
|
||||
void rb_str_shared_replace(VALUE, VALUE);
|
||||
VALUE rb_str_buf_append(VALUE, VALUE);
|
||||
VALUE rb_str_buf_cat(VALUE, const char*, long);
|
||||
VALUE rb_str_buf_cat2(VALUE, const char*);
|
||||
VALUE rb_str_buf_cat_ascii(VALUE, const char*);
|
||||
VALUE rb_obj_as_string(VALUE);
|
||||
VALUE rb_check_string_type(VALUE);
|
||||
void rb_must_asciicompat(VALUE);
|
||||
VALUE rb_str_dup(VALUE);
|
||||
VALUE rb_str_resurrect(VALUE str);
|
||||
VALUE rb_str_locktmp(VALUE);
|
||||
VALUE rb_str_unlocktmp(VALUE);
|
||||
VALUE rb_str_dup_frozen(VALUE);
|
||||
#define rb_str_dup_frozen rb_str_new_frozen
|
||||
VALUE rb_str_plus(VALUE, VALUE);
|
||||
VALUE rb_str_times(VALUE, VALUE);
|
||||
long rb_str_sublen(VALUE, long);
|
||||
VALUE rb_str_substr(VALUE, long, long);
|
||||
VALUE rb_str_subseq(VALUE, long, long);
|
||||
char *rb_str_subpos(VALUE, long, long*);
|
||||
void rb_str_modify(VALUE);
|
||||
void rb_str_modify_expand(VALUE, long);
|
||||
VALUE rb_str_freeze(VALUE);
|
||||
void rb_str_set_len(VALUE, long);
|
||||
VALUE rb_str_resize(VALUE, long);
|
||||
VALUE rb_str_cat(VALUE, const char*, long);
|
||||
VALUE rb_str_cat2(VALUE, const char*);
|
||||
VALUE rb_str_append(VALUE, VALUE);
|
||||
VALUE rb_str_concat(VALUE, VALUE);
|
||||
st_index_t rb_memhash(const void *ptr, long len);
|
||||
st_index_t rb_hash_start(st_index_t);
|
||||
st_index_t rb_hash_uint32(st_index_t, uint32_t);
|
||||
st_index_t rb_hash_uint(st_index_t, st_index_t);
|
||||
st_index_t rb_hash_end(st_index_t);
|
||||
#define rb_hash_uint32(h, i) st_hash_uint32((h), (i))
|
||||
#define rb_hash_uint(h, i) st_hash_uint((h), (i))
|
||||
#define rb_hash_end(h) st_hash_end(h)
|
||||
st_index_t rb_str_hash(VALUE);
|
||||
int rb_str_hash_cmp(VALUE,VALUE);
|
||||
int rb_str_comparable(VALUE, VALUE);
|
||||
int rb_str_cmp(VALUE, VALUE);
|
||||
VALUE rb_str_equal(VALUE str1, VALUE str2);
|
||||
VALUE rb_str_drop_bytes(VALUE, long);
|
||||
void rb_str_update(VALUE, long, long, VALUE);
|
||||
VALUE rb_str_replace(VALUE, VALUE);
|
||||
VALUE rb_str_inspect(VALUE);
|
||||
VALUE rb_str_dump(VALUE);
|
||||
VALUE rb_str_split(VALUE, const char*);
|
||||
void rb_str_associate(VALUE, VALUE);
|
||||
VALUE rb_str_associated(VALUE);
|
||||
void rb_str_setter(VALUE, ID, VALUE*);
|
||||
VALUE rb_str_intern(VALUE);
|
||||
VALUE rb_sym_to_s(VALUE);
|
||||
long rb_str_strlen(VALUE);
|
||||
VALUE rb_str_length(VALUE);
|
||||
long rb_str_offset(VALUE, long);
|
||||
size_t rb_str_capacity(VALUE);
|
||||
VALUE rb_str_ellipsize(VALUE, long);
|
||||
VALUE rb_str_scrub(VALUE, VALUE);
|
||||
#if defined(__GNUC__) && !defined(__PCC__)
|
||||
#define rb_str_new_cstr(str) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_str_new((str), (long)strlen(str)) : \
|
||||
rb_str_new_cstr(str); \
|
||||
})
|
||||
#define rb_tainted_str_new_cstr(str) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_tainted_str_new((str), (long)strlen(str)) : \
|
||||
rb_tainted_str_new_cstr(str); \
|
||||
})
|
||||
#define rb_usascii_str_new_cstr(str) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_usascii_str_new((str), (long)strlen(str)) : \
|
||||
rb_usascii_str_new_cstr(str); \
|
||||
})
|
||||
#define rb_external_str_new_cstr(str) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_external_str_new((str), (long)strlen(str)) : \
|
||||
rb_external_str_new_cstr(str); \
|
||||
})
|
||||
#define rb_locale_str_new_cstr(str) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_locale_str_new((str), (long)strlen(str)) : \
|
||||
rb_locale_str_new_cstr(str); \
|
||||
})
|
||||
#define rb_str_buf_new_cstr(str) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(str)) ? \
|
||||
rb_str_buf_cat(rb_str_buf_new((long)strlen(str)), \
|
||||
(str), (long)strlen(str)) : \
|
||||
rb_str_buf_new_cstr(str); \
|
||||
})
|
||||
#define rb_str_buf_cat2(str, ptr) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(ptr)) ? \
|
||||
rb_str_buf_cat((str), (ptr), (long)strlen(ptr)) : \
|
||||
rb_str_buf_cat2((str), (ptr)); \
|
||||
})
|
||||
#define rb_str_cat2(str, ptr) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(ptr)) ? \
|
||||
rb_str_cat((str), (ptr), (long)strlen(ptr)) : \
|
||||
rb_str_cat2((str), (ptr)); \
|
||||
})
|
||||
#define rb_exc_new_cstr(klass, ptr) __extension__ ( \
|
||||
{ \
|
||||
(__builtin_constant_p(ptr)) ? \
|
||||
rb_exc_new((klass), (ptr), (long)strlen(ptr)) : \
|
||||
rb_exc_new_cstr((klass), (ptr)); \
|
||||
})
|
||||
#endif
|
||||
#define rb_str_new2 rb_str_new_cstr
|
||||
#define rb_str_new3 rb_str_new_shared
|
||||
#define rb_str_new4 rb_str_new_frozen
|
||||
#define rb_str_new5 rb_str_new_with_class
|
||||
#define rb_tainted_str_new2 rb_tainted_str_new_cstr
|
||||
#define rb_str_buf_new2 rb_str_buf_new_cstr
|
||||
#define rb_usascii_str_new2 rb_usascii_str_new_cstr
|
||||
/* struct.c */
|
||||
VALUE rb_struct_new(VALUE, ...);
|
||||
VALUE rb_struct_define(const char*, ...);
|
||||
VALUE rb_struct_define_under(VALUE, const char*, ...);
|
||||
VALUE rb_struct_alloc(VALUE, VALUE);
|
||||
VALUE rb_struct_initialize(VALUE, VALUE);
|
||||
VALUE rb_struct_aref(VALUE, VALUE);
|
||||
VALUE rb_struct_aset(VALUE, VALUE, VALUE);
|
||||
VALUE rb_struct_getmember(VALUE, ID);
|
||||
DEPRECATED(VALUE rb_struct_iv_get(VALUE, const char*));
|
||||
VALUE rb_struct_s_members(VALUE);
|
||||
VALUE rb_struct_members(VALUE);
|
||||
VALUE rb_struct_alloc_noinit(VALUE);
|
||||
VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...);
|
||||
VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, ...);
|
||||
|
||||
/* thread.c */
|
||||
typedef void rb_unblock_function_t(void *);
|
||||
typedef VALUE rb_blocking_function_t(void *);
|
||||
void rb_thread_check_ints(void);
|
||||
int rb_thread_interrupted(VALUE thval);
|
||||
|
||||
/* Use rb_thread_call_without_gvl family instead. */
|
||||
DEPRECATED(VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data1,
|
||||
rb_unblock_function_t *ubf, void *data2));
|
||||
#define RUBY_UBF_IO ((rb_unblock_function_t *)-1)
|
||||
#define RUBY_UBF_PROCESS ((rb_unblock_function_t *)-1)
|
||||
VALUE rb_mutex_new(void);
|
||||
VALUE rb_mutex_locked_p(VALUE mutex);
|
||||
VALUE rb_mutex_trylock(VALUE mutex);
|
||||
VALUE rb_mutex_lock(VALUE mutex);
|
||||
VALUE rb_mutex_unlock(VALUE mutex);
|
||||
VALUE rb_mutex_sleep(VALUE self, VALUE timeout);
|
||||
VALUE rb_mutex_synchronize(VALUE mutex, VALUE (*func)(VALUE arg), VALUE arg);
|
||||
/* time.c */
|
||||
VALUE rb_time_new(time_t, long);
|
||||
VALUE rb_time_nano_new(time_t, long);
|
||||
VALUE rb_time_num_new(VALUE, VALUE);
|
||||
struct timeval rb_time_interval(VALUE num);
|
||||
struct timeval rb_time_timeval(VALUE time);
|
||||
struct timespec rb_time_timespec(VALUE time);
|
||||
/* variable.c */
|
||||
VALUE rb_mod_name(VALUE);
|
||||
VALUE rb_class_path(VALUE);
|
||||
VALUE rb_class_path_cached(VALUE);
|
||||
void rb_set_class_path(VALUE, VALUE, const char*);
|
||||
void rb_set_class_path_string(VALUE, VALUE, VALUE);
|
||||
VALUE rb_path_to_class(VALUE);
|
||||
VALUE rb_path2class(const char*);
|
||||
void rb_name_class(VALUE, ID);
|
||||
VALUE rb_class_name(VALUE);
|
||||
void rb_autoload(VALUE, ID, const char*);
|
||||
VALUE rb_autoload_load(VALUE, ID);
|
||||
VALUE rb_autoload_p(VALUE, ID);
|
||||
VALUE rb_f_trace_var(int, VALUE*);
|
||||
VALUE rb_f_untrace_var(int, VALUE*);
|
||||
VALUE rb_f_global_variables(void);
|
||||
void rb_alias_variable(ID, ID);
|
||||
struct st_table* rb_generic_ivar_table(VALUE);
|
||||
void rb_copy_generic_ivar(VALUE,VALUE);
|
||||
void rb_free_generic_ivar(VALUE);
|
||||
VALUE rb_ivar_get(VALUE, ID);
|
||||
VALUE rb_ivar_set(VALUE, ID, VALUE);
|
||||
VALUE rb_ivar_defined(VALUE, ID);
|
||||
void rb_ivar_foreach(VALUE, int (*)(ANYARGS), st_data_t);
|
||||
st_index_t rb_ivar_count(VALUE);
|
||||
VALUE rb_attr_get(VALUE, ID);
|
||||
VALUE rb_obj_instance_variables(VALUE);
|
||||
VALUE rb_obj_remove_instance_variable(VALUE, VALUE);
|
||||
void *rb_mod_const_at(VALUE, void*);
|
||||
void *rb_mod_const_of(VALUE, void*);
|
||||
VALUE rb_const_list(void*);
|
||||
VALUE rb_mod_constants(int, VALUE *, VALUE);
|
||||
VALUE rb_mod_remove_const(VALUE, VALUE);
|
||||
int rb_const_defined(VALUE, ID);
|
||||
int rb_const_defined_at(VALUE, ID);
|
||||
int rb_const_defined_from(VALUE, ID);
|
||||
VALUE rb_const_get(VALUE, ID);
|
||||
VALUE rb_const_get_at(VALUE, ID);
|
||||
VALUE rb_const_get_from(VALUE, ID);
|
||||
void rb_const_set(VALUE, ID, VALUE);
|
||||
VALUE rb_const_remove(VALUE, ID);
|
||||
VALUE rb_mod_const_missing(VALUE,VALUE);
|
||||
VALUE rb_cvar_defined(VALUE, ID);
|
||||
void rb_cvar_set(VALUE, ID, VALUE);
|
||||
VALUE rb_cvar_get(VALUE, ID);
|
||||
void rb_cv_set(VALUE, const char*, VALUE);
|
||||
VALUE rb_cv_get(VALUE, const char*);
|
||||
void rb_define_class_variable(VALUE, const char*, VALUE);
|
||||
VALUE rb_mod_class_variables(int, VALUE*, VALUE);
|
||||
VALUE rb_mod_remove_cvar(VALUE, VALUE);
|
||||
|
||||
ID rb_frame_callee(void);
|
||||
VALUE rb_str_succ(VALUE);
|
||||
VALUE rb_time_succ(VALUE);
|
||||
int rb_frame_method_id_and_class(ID *idp, VALUE *klassp);
|
||||
VALUE rb_make_backtrace(void);
|
||||
VALUE rb_make_exception(int, VALUE*);
|
||||
|
||||
/* deprecated */
|
||||
DEPRECATED(void rb_frame_pop(void));
|
||||
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_INTERN_H */
|
||||
214
ruby/include/ruby-2.1.0/ruby/io.h
Normal file
214
ruby/include/ruby-2.1.0/ruby/io.h
Normal file
@@ -0,0 +1,214 @@
|
||||
/**********************************************************************
|
||||
|
||||
rubyio.h -
|
||||
|
||||
$Author: nobu $
|
||||
created at: Fri Nov 12 16:47:09 JST 1993
|
||||
|
||||
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_IO_H
|
||||
#define RUBY_IO_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include "ruby/encoding.h"
|
||||
|
||||
#if defined(HAVE_STDIO_EXT_H)
|
||||
#include <stdio_ext.h>
|
||||
#endif
|
||||
|
||||
#include "ruby/config.h"
|
||||
#if defined(HAVE_POLL)
|
||||
# ifdef _AIX
|
||||
# define reqevents events
|
||||
# define rtnevents revents
|
||||
# endif
|
||||
# include <poll.h>
|
||||
# ifdef _AIX
|
||||
# undef reqevents
|
||||
# undef rtnevents
|
||||
# undef events
|
||||
# undef revents
|
||||
# endif
|
||||
# define RB_WAITFD_IN POLLIN
|
||||
# define RB_WAITFD_PRI POLLPRI
|
||||
# define RB_WAITFD_OUT POLLOUT
|
||||
#else
|
||||
# define RB_WAITFD_IN 0x001
|
||||
# define RB_WAITFD_PRI 0x002
|
||||
# define RB_WAITFD_OUT 0x004
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
typedef struct {
|
||||
char *ptr; /* off + len <= capa */
|
||||
int off;
|
||||
int len;
|
||||
int capa;
|
||||
} rb_io_buffer_t;
|
||||
|
||||
typedef struct rb_io_t {
|
||||
int fd; /* file descriptor */
|
||||
FILE *stdio_file; /* stdio ptr for read/write if available */
|
||||
int mode; /* mode flags: FMODE_XXXs */
|
||||
rb_pid_t pid; /* child's pid (for pipes) */
|
||||
int lineno; /* number of lines read */
|
||||
VALUE pathv; /* pathname for file */
|
||||
void (*finalize)(struct rb_io_t*,int); /* finalize proc */
|
||||
|
||||
rb_io_buffer_t wbuf, rbuf;
|
||||
|
||||
VALUE tied_io_for_writing;
|
||||
|
||||
/*
|
||||
* enc enc2 read action write action
|
||||
* NULL NULL force_encoding(default_external) write the byte sequence of str
|
||||
* e1 NULL force_encoding(e1) convert str.encoding to e1
|
||||
* e1 e2 convert from e2 to e1 convert str.encoding to e2
|
||||
*/
|
||||
struct rb_io_enc_t {
|
||||
rb_encoding *enc;
|
||||
rb_encoding *enc2;
|
||||
int ecflags;
|
||||
VALUE ecopts;
|
||||
} encs;
|
||||
|
||||
rb_econv_t *readconv;
|
||||
rb_io_buffer_t cbuf;
|
||||
|
||||
rb_econv_t *writeconv;
|
||||
VALUE writeconv_asciicompat;
|
||||
int writeconv_pre_ecflags;
|
||||
VALUE writeconv_pre_ecopts;
|
||||
int writeconv_initialized;
|
||||
|
||||
VALUE write_lock;
|
||||
} rb_io_t;
|
||||
|
||||
#define HAVE_RB_IO_T 1
|
||||
|
||||
#define FMODE_READABLE 0x00000001
|
||||
#define FMODE_WRITABLE 0x00000002
|
||||
#define FMODE_READWRITE (FMODE_READABLE|FMODE_WRITABLE)
|
||||
#define FMODE_BINMODE 0x00000004
|
||||
#define FMODE_SYNC 0x00000008
|
||||
#define FMODE_TTY 0x00000010
|
||||
#define FMODE_DUPLEX 0x00000020
|
||||
#define FMODE_APPEND 0x00000040
|
||||
#define FMODE_CREATE 0x00000080
|
||||
/* #define FMODE_NOREVLOOKUP 0x00000100 */
|
||||
#define FMODE_WSPLIT 0x00000200
|
||||
#define FMODE_WSPLIT_INITIALIZED 0x00000400
|
||||
#define FMODE_TRUNC 0x00000800
|
||||
#define FMODE_TEXTMODE 0x00001000
|
||||
/* #define FMODE_PREP 0x00010000 */
|
||||
#define FMODE_SETENC_BY_BOM 0x00100000
|
||||
|
||||
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
|
||||
|
||||
#define RB_IO_BUFFER_INIT(buf) do {\
|
||||
(buf).ptr = NULL;\
|
||||
(buf).off = 0;\
|
||||
(buf).len = 0;\
|
||||
(buf).capa = 0;\
|
||||
} while (0)
|
||||
|
||||
#define MakeOpenFile(obj, fp) do {\
|
||||
if (RFILE(obj)->fptr) {\
|
||||
rb_io_close(obj);\
|
||||
rb_io_fptr_finalize(RFILE(obj)->fptr);\
|
||||
RFILE(obj)->fptr = 0;\
|
||||
}\
|
||||
(fp) = 0;\
|
||||
RB_IO_FPTR_NEW(fp);\
|
||||
RFILE(obj)->fptr = (fp);\
|
||||
} while (0)
|
||||
|
||||
#define RB_IO_FPTR_NEW(fp) do {\
|
||||
(fp) = ALLOC(rb_io_t);\
|
||||
(fp)->fd = -1;\
|
||||
(fp)->stdio_file = NULL;\
|
||||
(fp)->mode = 0;\
|
||||
(fp)->pid = 0;\
|
||||
(fp)->lineno = 0;\
|
||||
(fp)->pathv = Qnil;\
|
||||
(fp)->finalize = 0;\
|
||||
RB_IO_BUFFER_INIT((fp)->wbuf);\
|
||||
RB_IO_BUFFER_INIT((fp)->rbuf);\
|
||||
RB_IO_BUFFER_INIT((fp)->cbuf);\
|
||||
(fp)->readconv = NULL;\
|
||||
(fp)->writeconv = NULL;\
|
||||
(fp)->writeconv_asciicompat = Qnil;\
|
||||
(fp)->writeconv_pre_ecflags = 0;\
|
||||
(fp)->writeconv_pre_ecopts = Qnil;\
|
||||
(fp)->writeconv_initialized = 0;\
|
||||
(fp)->tied_io_for_writing = 0;\
|
||||
(fp)->encs.enc = NULL;\
|
||||
(fp)->encs.enc2 = NULL;\
|
||||
(fp)->encs.ecflags = 0;\
|
||||
(fp)->encs.ecopts = Qnil;\
|
||||
(fp)->write_lock = 0;\
|
||||
} while (0)
|
||||
|
||||
FILE *rb_io_stdio_file(rb_io_t *fptr);
|
||||
|
||||
FILE *rb_fdopen(int, const char*);
|
||||
int rb_io_modestr_fmode(const char *modestr);
|
||||
int rb_io_modestr_oflags(const char *modestr);
|
||||
int rb_io_oflags_fmode(int oflags);
|
||||
void rb_io_check_writable(rb_io_t*);
|
||||
void rb_io_check_readable(rb_io_t*);
|
||||
void rb_io_check_char_readable(rb_io_t *fptr);
|
||||
void rb_io_check_byte_readable(rb_io_t *fptr);
|
||||
int rb_io_fptr_finalize(rb_io_t*);
|
||||
void rb_io_synchronized(rb_io_t*);
|
||||
void rb_io_check_initialized(rb_io_t*);
|
||||
void rb_io_check_closed(rb_io_t*);
|
||||
VALUE rb_io_get_io(VALUE io);
|
||||
VALUE rb_io_check_io(VALUE io);
|
||||
VALUE rb_io_get_write_io(VALUE io);
|
||||
VALUE rb_io_set_write_io(VALUE io, VALUE w);
|
||||
int rb_io_wait_readable(int);
|
||||
int rb_io_wait_writable(int);
|
||||
int rb_wait_for_single_fd(int fd, int events, struct timeval *tv);
|
||||
void rb_io_set_nonblock(rb_io_t *fptr);
|
||||
int rb_io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p, int *fmode_p);
|
||||
ssize_t rb_io_bufwrite(VALUE io, const void *buf, size_t size);
|
||||
|
||||
/* compatibility for ruby 1.8 and older */
|
||||
#define rb_io_mode_flags(modestr) rb_io_modestr_fmode(modestr)
|
||||
#define rb_io_modenum_flags(oflags) rb_io_oflags_fmode(oflags)
|
||||
|
||||
VALUE rb_io_taint_check(VALUE);
|
||||
NORETURN(void rb_eof_error(void));
|
||||
|
||||
void rb_io_read_check(rb_io_t*);
|
||||
int rb_io_read_pending(rb_io_t*);
|
||||
DEPRECATED(void rb_read_check(FILE*));
|
||||
|
||||
struct stat;
|
||||
VALUE rb_stat_new(const struct stat *);
|
||||
|
||||
/* gc.c */
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_IO_H */
|
||||
244
ruby/include/ruby-2.1.0/ruby/missing.h
Normal file
244
ruby/include/ruby-2.1.0/ruby/missing.h
Normal file
@@ -0,0 +1,244 @@
|
||||
/************************************************
|
||||
|
||||
missing.h - prototype for *.c in ./missing, and
|
||||
for missing timeval struct
|
||||
|
||||
$Author: nobu $
|
||||
created at: Sat May 11 23:46:03 JST 2002
|
||||
|
||||
************************************************/
|
||||
|
||||
#ifndef RUBY_MISSING_H
|
||||
#define RUBY_MISSING_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ruby/config.h"
|
||||
#include <stddef.h>
|
||||
#include <math.h> /* for INFINITY and NAN */
|
||||
#ifdef RUBY_EXTCONF_H
|
||||
#include RUBY_EXTCONF_H
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMEVAL) || !defined(HAVE_STRUCT_TIMESPEC)
|
||||
#if defined(HAVE_TIME_H)
|
||||
# include <time.h>
|
||||
#endif
|
||||
#if defined(HAVE_SYS_TIME_H)
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef RUBY_SYMBOL_EXPORT_BEGIN
|
||||
# define RUBY_SYMBOL_EXPORT_BEGIN /* begin */
|
||||
# define RUBY_SYMBOL_EXPORT_END /* end */
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMEVAL)
|
||||
struct timeval {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_usec; /* microseconds */
|
||||
};
|
||||
#endif /* HAVE_STRUCT_TIMEVAL */
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMESPEC)
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* nanoseconds */
|
||||
};
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_STRUCT_TIMEZONE)
|
||||
struct timezone {
|
||||
int tz_minuteswest;
|
||||
int tz_dsttime;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef RUBY_EXPORT
|
||||
#undef RUBY_EXTERN
|
||||
#endif
|
||||
#ifndef RUBY_EXTERN
|
||||
#define RUBY_EXTERN extern
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#ifndef HAVE_ACOSH
|
||||
RUBY_EXTERN double acosh(double);
|
||||
RUBY_EXTERN double asinh(double);
|
||||
RUBY_EXTERN double atanh(double);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CRYPT
|
||||
RUBY_EXTERN char *crypt(const char *, const char *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DUP2
|
||||
RUBY_EXTERN int dup2(int, int);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_EACCESS
|
||||
RUBY_EXTERN int eaccess(const char*, int);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ROUND
|
||||
RUBY_EXTERN double round(double); /* numeric.c */
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FINITE
|
||||
RUBY_EXTERN int finite(double);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FLOCK
|
||||
RUBY_EXTERN int flock(int, int);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_FREXP
|
||||
RUBY_EXTERN double frexp(double, int *);
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef HAVE_HYPOT
|
||||
RUBY_EXTERN double hypot(double, double);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_ERF
|
||||
RUBY_EXTERN double erf(double);
|
||||
RUBY_EXTERN double erfc(double);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_TGAMMA
|
||||
RUBY_EXTERN double tgamma(double);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_LGAMMA_R
|
||||
RUBY_EXTERN double lgamma_r(double, int *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CBRT
|
||||
RUBY_EXTERN double cbrt(double);
|
||||
#endif
|
||||
|
||||
#if !defined(INFINITY) || !defined(NAN)
|
||||
union bytesequence4_or_float {
|
||||
unsigned char bytesequence[4];
|
||||
float float_value;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef INFINITY
|
||||
# define HAVE_INFINITY
|
||||
#else
|
||||
/** @internal */
|
||||
RUBY_EXTERN const union bytesequence4_or_float rb_infinity;
|
||||
# define INFINITY (rb_infinity.float_value)
|
||||
#endif
|
||||
|
||||
#ifdef NAN
|
||||
# define HAVE_NAN
|
||||
#else
|
||||
/** @internal */
|
||||
RUBY_EXTERN const union bytesequence4_or_float rb_nan;
|
||||
# define NAN (rb_nan.float_value)
|
||||
#endif
|
||||
|
||||
#ifndef isinf
|
||||
# ifndef HAVE_ISINF
|
||||
# if defined(HAVE_FINITE) && defined(HAVE_ISNAN)
|
||||
# ifdef HAVE_IEEEFP_H
|
||||
# include <ieeefp.h>
|
||||
# endif
|
||||
# define isinf(x) (!finite(x) && !isnan(x))
|
||||
# else
|
||||
RUBY_EXTERN int isinf(double);
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef isnan
|
||||
# ifndef HAVE_ISNAN
|
||||
RUBY_EXTERN int isnan(double);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_MEMCMP
|
||||
RUBY_EXTERN int memcmp(const void *, const void *, size_t);
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef HAVE_MEMMOVE
|
||||
RUBY_EXTERN void *memmove(void *, const void *, size_t);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_MODF
|
||||
RUBY_EXTERN double modf(double, double *);
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef HAVE_STRCHR
|
||||
RUBY_EXTERN char *strchr(const char *, int);
|
||||
RUBY_EXTERN char *strrchr(const char *, int);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
RUBY_EXTERN char *strerror(int);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRSTR
|
||||
RUBY_EXTERN char *strstr(const char *, const char *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_STRTOL
|
||||
RUBY_EXTERN long strtol(const char *, char **, int);
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifndef HAVE_STRLCPY
|
||||
RUBY_EXTERN size_t strlcpy(char *, const char*, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
RUBY_EXTERN size_t strlcat(char *, const char*, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SIGNBIT
|
||||
RUBY_EXTERN int signbit(double x);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FFS
|
||||
RUBY_EXTERN int ffs(int);
|
||||
#endif
|
||||
|
||||
#ifdef BROKEN_CLOSE
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
RUBY_EXTERN int ruby_getpeername(int, struct sockaddr *, socklen_t *);
|
||||
RUBY_EXTERN int ruby_getsockname(int, struct sockaddr *, socklen_t *);
|
||||
RUBY_EXTERN int ruby_shutdown(int, int);
|
||||
RUBY_EXTERN int ruby_close(int);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETPROCTITLE
|
||||
RUBY_EXTERN void setproctitle(const char *fmt, ...);
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_MISSING_H */
|
||||
837
ruby/include/ruby-2.1.0/ruby/oniguruma.h
Normal file
837
ruby/include/ruby-2.1.0/ruby/oniguruma.h
Normal file
@@ -0,0 +1,837 @@
|
||||
#ifndef ONIGURUMA_H
|
||||
#define ONIGURUMA_H
|
||||
/**********************************************************************
|
||||
oniguruma.h - Onigmo (Oniguruma-mod) (regular expression library)
|
||||
**********************************************************************/
|
||||
/*-
|
||||
* Copyright (c) 2002-2009 K.Kosako <sndgk393 AT ybb DOT ne DOT jp>
|
||||
* Copyright (c) 2011-2013 K.Takata <kentkt AT csc DOT jp>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define ONIGURUMA
|
||||
#define ONIGURUMA_VERSION_MAJOR 5
|
||||
#define ONIGURUMA_VERSION_MINOR 13
|
||||
#define ONIGURUMA_VERSION_TEENY 5
|
||||
|
||||
#ifdef __cplusplus
|
||||
# ifndef HAVE_PROTOTYPES
|
||||
# define HAVE_PROTOTYPES 1
|
||||
# endif
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */
|
||||
#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDARG_H
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef P_
|
||||
#if defined(__STDC__) || defined(_WIN32)
|
||||
# define P_(args) args
|
||||
#else
|
||||
# define P_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PV_
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# define PV_(args) args
|
||||
#else
|
||||
# define PV_(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#ifdef RUBY_EXTERN
|
||||
#define ONIG_EXTERN RUBY_EXTERN
|
||||
#else
|
||||
#if defined(_WIN32) && !defined(__GNUC__)
|
||||
#if defined(EXPORT) || defined(RUBY_EXPORT)
|
||||
#define ONIG_EXTERN extern __declspec(dllexport)
|
||||
#else
|
||||
#define ONIG_EXTERN extern __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef ONIG_EXTERN
|
||||
#define ONIG_EXTERN extern
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
/* PART: character encoding */
|
||||
|
||||
#ifndef ONIG_ESCAPE_UCHAR_COLLISION
|
||||
#define UChar OnigUChar
|
||||
#endif
|
||||
|
||||
typedef unsigned char OnigUChar;
|
||||
typedef unsigned int OnigCodePoint;
|
||||
typedef unsigned int OnigCtype;
|
||||
typedef size_t OnigDistance;
|
||||
typedef ptrdiff_t OnigPosition;
|
||||
|
||||
#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0)
|
||||
|
||||
typedef unsigned int OnigCaseFoldType; /* case fold flag */
|
||||
|
||||
ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag;
|
||||
|
||||
/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */
|
||||
/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */
|
||||
#define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20)
|
||||
#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30)
|
||||
|
||||
#define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR
|
||||
#define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag
|
||||
|
||||
|
||||
#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13
|
||||
/* 13 => Unicode:0x1ffc */
|
||||
|
||||
/* code range */
|
||||
#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0])
|
||||
#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1]
|
||||
#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2]
|
||||
|
||||
typedef struct {
|
||||
int byte_len; /* argument(original) character(s) byte length */
|
||||
int code_len; /* number of code */
|
||||
OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN];
|
||||
} OnigCaseFoldCodeItem;
|
||||
|
||||
typedef struct {
|
||||
OnigCodePoint esc;
|
||||
OnigCodePoint anychar;
|
||||
OnigCodePoint anytime;
|
||||
OnigCodePoint zero_or_one_time;
|
||||
OnigCodePoint one_or_more_time;
|
||||
OnigCodePoint anychar_anytime;
|
||||
} OnigMetaCharTableType;
|
||||
|
||||
typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg);
|
||||
|
||||
typedef struct OnigEncodingTypeST {
|
||||
int (*precise_mbc_enc_len)(const OnigUChar* p,const OnigUChar* e, struct OnigEncodingTypeST* enc);
|
||||
const char* name;
|
||||
int max_enc_len;
|
||||
int min_enc_len;
|
||||
int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc);
|
||||
OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc);
|
||||
int (*code_to_mbclen)(OnigCodePoint code, struct OnigEncodingTypeST* enc);
|
||||
int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf, struct OnigEncodingTypeST* enc);
|
||||
int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to, struct OnigEncodingTypeST* enc);
|
||||
int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg, struct OnigEncodingTypeST* enc);
|
||||
int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[], struct OnigEncodingTypeST* enc);
|
||||
int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end);
|
||||
int (*is_code_ctype)(OnigCodePoint code, OnigCtype ctype, struct OnigEncodingTypeST* enc);
|
||||
int (*get_ctype_code_range)(OnigCtype ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[], struct OnigEncodingTypeST* enc);
|
||||
OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc);
|
||||
int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc);
|
||||
int ruby_encoding_index;
|
||||
unsigned int flags;
|
||||
} OnigEncodingType;
|
||||
|
||||
typedef OnigEncodingType* OnigEncoding;
|
||||
|
||||
ONIG_EXTERN OnigEncodingType OnigEncodingASCII;
|
||||
|
||||
#define ONIG_ENCODING_ASCII (&OnigEncodingASCII)
|
||||
|
||||
#define ONIG_ENCODING_UNDEF ((OnigEncoding )0)
|
||||
|
||||
|
||||
/* work size */
|
||||
#define ONIGENC_CODE_TO_MBC_MAXLEN 7
|
||||
#define ONIGENC_MBC_CASE_FOLD_MAXLEN 18
|
||||
/* 18: 6(max-byte) * 3(case-fold chars) */
|
||||
|
||||
/* character types */
|
||||
#define ONIGENC_CTYPE_NEWLINE 0
|
||||
#define ONIGENC_CTYPE_ALPHA 1
|
||||
#define ONIGENC_CTYPE_BLANK 2
|
||||
#define ONIGENC_CTYPE_CNTRL 3
|
||||
#define ONIGENC_CTYPE_DIGIT 4
|
||||
#define ONIGENC_CTYPE_GRAPH 5
|
||||
#define ONIGENC_CTYPE_LOWER 6
|
||||
#define ONIGENC_CTYPE_PRINT 7
|
||||
#define ONIGENC_CTYPE_PUNCT 8
|
||||
#define ONIGENC_CTYPE_SPACE 9
|
||||
#define ONIGENC_CTYPE_UPPER 10
|
||||
#define ONIGENC_CTYPE_XDIGIT 11
|
||||
#define ONIGENC_CTYPE_WORD 12
|
||||
#define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */
|
||||
#define ONIGENC_CTYPE_ASCII 14
|
||||
#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII
|
||||
|
||||
/* flags */
|
||||
#define ONIGENC_FLAG_NONE 0U
|
||||
#define ONIGENC_FLAG_UNICODE 1U
|
||||
|
||||
#define onig_enc_len(enc,p,e) ONIGENC_MBC_ENC_LEN(enc, p, e)
|
||||
|
||||
#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF)
|
||||
#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1)
|
||||
#define ONIGENC_IS_MBC_HEAD(enc,p,e) (ONIGENC_MBC_ENC_LEN(enc,p,e) != 1)
|
||||
#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128)
|
||||
#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128)
|
||||
#define ONIGENC_IS_MBC_WORD(enc,s,end) \
|
||||
ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end))
|
||||
#define ONIGENC_IS_MBC_ASCII_WORD(enc,s,end) \
|
||||
onigenc_ascii_is_code_ctype( \
|
||||
ONIGENC_MBC_TO_CODE(enc,s,end),ONIGENC_CTYPE_WORD,enc)
|
||||
#define ONIGENC_IS_UNICODE(enc) ((enc)->flags & ONIGENC_FLAG_UNICODE)
|
||||
|
||||
|
||||
#define ONIGENC_NAME(enc) ((enc)->name)
|
||||
|
||||
#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \
|
||||
(enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf,enc)
|
||||
#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \
|
||||
(enc)->is_allowed_reverse_match(s,end,enc)
|
||||
#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s,end) \
|
||||
(enc)->left_adjust_char_head(start, s, end, enc)
|
||||
#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \
|
||||
(enc)->apply_all_case_fold(case_fold_flag,f,arg,enc)
|
||||
#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \
|
||||
(enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs,enc)
|
||||
#define ONIGENC_STEP_BACK(enc,start,s,end,n) \
|
||||
onigenc_step_back((enc),(start),(s),(end),(n))
|
||||
|
||||
#define ONIGENC_CONSTRUCT_MBCLEN_CHARFOUND(n) (n)
|
||||
#define ONIGENC_MBCLEN_CHARFOUND_P(r) (0 < (r))
|
||||
#define ONIGENC_MBCLEN_CHARFOUND_LEN(r) (r)
|
||||
|
||||
#define ONIGENC_CONSTRUCT_MBCLEN_INVALID() (-1)
|
||||
#define ONIGENC_MBCLEN_INVALID_P(r) ((r) == -1)
|
||||
|
||||
#define ONIGENC_CONSTRUCT_MBCLEN_NEEDMORE(n) (-1-(n))
|
||||
#define ONIGENC_MBCLEN_NEEDMORE_P(r) ((r) < -1)
|
||||
#define ONIGENC_MBCLEN_NEEDMORE_LEN(r) (-1-(r))
|
||||
|
||||
#define ONIGENC_PRECISE_MBC_ENC_LEN(enc,p,e) (enc)->precise_mbc_enc_len(p,e,enc)
|
||||
|
||||
ONIG_EXTERN
|
||||
int onigenc_mbclen_approximate P_((const OnigUChar* p,const OnigUChar* e, struct OnigEncodingTypeST* enc));
|
||||
|
||||
#define ONIGENC_MBC_ENC_LEN(enc,p,e) onigenc_mbclen_approximate(p,e,enc)
|
||||
#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len)
|
||||
#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc)
|
||||
#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len)
|
||||
#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end),enc)
|
||||
#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end),enc)
|
||||
#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code,enc)
|
||||
#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf,enc)
|
||||
#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \
|
||||
(enc)->property_name_to_ctype(enc,p,end)
|
||||
|
||||
#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype,enc)
|
||||
|
||||
#define ONIGENC_IS_CODE_NEWLINE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE)
|
||||
#define ONIGENC_IS_CODE_GRAPH(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH)
|
||||
#define ONIGENC_IS_CODE_PRINT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT)
|
||||
#define ONIGENC_IS_CODE_ALNUM(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM)
|
||||
#define ONIGENC_IS_CODE_ALPHA(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA)
|
||||
#define ONIGENC_IS_CODE_LOWER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER)
|
||||
#define ONIGENC_IS_CODE_UPPER(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER)
|
||||
#define ONIGENC_IS_CODE_CNTRL(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL)
|
||||
#define ONIGENC_IS_CODE_PUNCT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT)
|
||||
#define ONIGENC_IS_CODE_SPACE(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE)
|
||||
#define ONIGENC_IS_CODE_BLANK(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK)
|
||||
#define ONIGENC_IS_CODE_DIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT)
|
||||
#define ONIGENC_IS_CODE_XDIGIT(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT)
|
||||
#define ONIGENC_IS_CODE_WORD(enc,code) \
|
||||
ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD)
|
||||
|
||||
#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \
|
||||
(enc)->get_ctype_code_range(ctype,sbout,ranges,enc)
|
||||
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end, int n));
|
||||
|
||||
|
||||
/* encoding API */
|
||||
ONIG_EXTERN
|
||||
int onigenc_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onigenc_set_default_encoding P_((OnigEncoding enc));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onigenc_get_default_encoding P_((void));
|
||||
ONIG_EXTERN
|
||||
void onigenc_set_default_caseconv_table P_((const OnigUChar* table));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end, const OnigUChar** prev));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end));
|
||||
ONIG_EXTERN
|
||||
int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
ONIG_EXTERN
|
||||
int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p));
|
||||
|
||||
|
||||
|
||||
/* PART: regular expression */
|
||||
|
||||
/* config parameters */
|
||||
#define ONIG_NREGION 10
|
||||
#define ONIG_MAX_BACKREF_NUM 1000
|
||||
#define ONIG_MAX_CAPTURE_GROUP_NUM 32767
|
||||
#define ONIG_MAX_REPEAT_NUM 100000
|
||||
#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000
|
||||
/* constants */
|
||||
#define ONIG_MAX_ERROR_MESSAGE_LEN 90
|
||||
|
||||
typedef unsigned int OnigOptionType;
|
||||
|
||||
#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE
|
||||
|
||||
/* options */
|
||||
#define ONIG_OPTION_NONE 0U
|
||||
#define ONIG_OPTION_IGNORECASE 1U
|
||||
#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1)
|
||||
#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1)
|
||||
#define ONIG_OPTION_DOTALL ONIG_OPTION_MULTILINE
|
||||
#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1)
|
||||
#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1)
|
||||
#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1)
|
||||
#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1)
|
||||
#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1)
|
||||
/* options (search time) */
|
||||
#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1)
|
||||
#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1)
|
||||
#define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1)
|
||||
/* options (ctype range) */
|
||||
#define ONIG_OPTION_ASCII_RANGE (ONIG_OPTION_POSIX_REGION << 1)
|
||||
#define ONIG_OPTION_POSIX_BRACKET_ALL_RANGE (ONIG_OPTION_ASCII_RANGE << 1)
|
||||
#define ONIG_OPTION_WORD_BOUND_ALL_RANGE (ONIG_OPTION_POSIX_BRACKET_ALL_RANGE << 1)
|
||||
/* options (newline) */
|
||||
#define ONIG_OPTION_NEWLINE_CRLF (ONIG_OPTION_WORD_BOUND_ALL_RANGE << 1)
|
||||
#define ONIG_OPTION_MAXBIT ONIG_OPTION_NEWLINE_CRLF /* limit */
|
||||
|
||||
#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt))
|
||||
#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt))
|
||||
#define ONIG_IS_OPTION_ON(options,option) ((options) & (option))
|
||||
|
||||
/* syntax */
|
||||
typedef struct {
|
||||
unsigned int op;
|
||||
unsigned int op2;
|
||||
unsigned int behavior;
|
||||
OnigOptionType options; /* default option */
|
||||
OnigMetaCharTableType meta_char_table;
|
||||
} OnigSyntaxType;
|
||||
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxASIS;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxPosixBasic;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxPosixExtended;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxEmacs;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxGrep;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxGnuRegex;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxJava;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl58;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl58_NG;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxPerl;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxRuby;
|
||||
ONIG_EXTERN const OnigSyntaxType OnigSyntaxPython;
|
||||
|
||||
/* predefined syntaxes (see regsyntax.c) */
|
||||
#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS)
|
||||
#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic)
|
||||
#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended)
|
||||
#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs)
|
||||
#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep)
|
||||
#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex)
|
||||
#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava)
|
||||
#define ONIG_SYNTAX_PERL58 (&OnigSyntaxPerl58)
|
||||
#define ONIG_SYNTAX_PERL58_NG (&OnigSyntaxPerl58_NG)
|
||||
#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl)
|
||||
#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby)
|
||||
#define ONIG_SYNTAX_PYTHON (&OnigSyntaxPython)
|
||||
|
||||
/* default syntax */
|
||||
ONIG_EXTERN const OnigSyntaxType* OnigDefaultSyntax;
|
||||
#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax
|
||||
|
||||
/* syntax (operators) */
|
||||
#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0)
|
||||
#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */
|
||||
#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */
|
||||
#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3)
|
||||
#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */
|
||||
#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5)
|
||||
#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */
|
||||
#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7)
|
||||
#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */
|
||||
#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */
|
||||
#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */
|
||||
#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */
|
||||
#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */
|
||||
#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */
|
||||
#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */
|
||||
#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */
|
||||
#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */
|
||||
#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */
|
||||
#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */
|
||||
#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */
|
||||
#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */
|
||||
#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */
|
||||
#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */
|
||||
#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */
|
||||
#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */
|
||||
#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */
|
||||
#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */
|
||||
#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */
|
||||
#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */
|
||||
#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */
|
||||
#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */
|
||||
#define ONIG_SYN_OP_ESC_O_BRACE_OCTAL (1U<<31) /* \o{OOO} */ /* NOTIMPL */
|
||||
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */
|
||||
#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */
|
||||
#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsxadlu), (?-imsx), (?^imsxalu) */
|
||||
#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imxadu), (?-imx) */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */
|
||||
#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */
|
||||
#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */
|
||||
#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?<name>...) */
|
||||
#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k<name> */
|
||||
#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g<name>, \g<n> */
|
||||
#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@<x>..) */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */
|
||||
#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */
|
||||
#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */
|
||||
#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */
|
||||
#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */
|
||||
/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */
|
||||
#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */
|
||||
#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_R_LINEBREAK (1U<<21) /* \R as (?>\x0D\x0A|[\x0A-\x0D\x{85}\x{2028}\x{2029}]) */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_X_EXTENDED_GRAPHEME_CLUSTER (1U<<22) /* \X as (?>\P{M}\p{M}*) */
|
||||
#define ONIG_SYN_OP2_ESC_V_VERTICAL_WHITESPACE (1U<<23) /* \v, \V -- Perl */ /* NOTIMPL */
|
||||
#define ONIG_SYN_OP2_ESC_H_HORIZONTAL_WHITESPACE (1U<<24) /* \h, \H -- Perl */ /* NOTIMPL */
|
||||
#define ONIG_SYN_OP2_ESC_CAPITAL_K_KEEP (1U<<25) /* \K */
|
||||
#define ONIG_SYN_OP2_ESC_G_BRACE_BACKREF (1U<<26) /* \g{name}, \g{n} */
|
||||
#define ONIG_SYN_OP2_QMARK_SUBEXP_CALL (1U<<27) /* (?&name), (?n), (?R), (?0) */
|
||||
#define ONIG_SYN_OP2_QMARK_VBAR_BRANCH_RESET (1U<<28) /* (?|...) */ /* NOTIMPL */
|
||||
#define ONIG_SYN_OP2_QMARK_LPAREN_CONDITION (1U<<29) /* (?(cond)yes...|no...) */
|
||||
#define ONIG_SYN_OP2_QMARK_CAPITAL_P_NAMED_GROUP (1U<<30) /* (?P<name>...), (?P=name), (?P>name) -- Python/PCRE */
|
||||
#define ONIG_SYN_OP2_OPTION_JAVA (1U<<31) /* (?idmsux), (?-idmsux) */ /* NOTIMPL */
|
||||
|
||||
/* syntax (behavior) */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */
|
||||
#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */
|
||||
#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */
|
||||
#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */
|
||||
#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */
|
||||
#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */
|
||||
#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/
|
||||
#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */
|
||||
#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */
|
||||
#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?<x>)(?<x>) */
|
||||
#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */
|
||||
#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME_CALL (1U<<10) /* (?<x>)(?<x>)(?&x) */
|
||||
|
||||
/* syntax (behavior) in char class [...] */
|
||||
#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */
|
||||
#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */
|
||||
#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22)
|
||||
#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */
|
||||
/* syntax (behavior) warning */
|
||||
#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */
|
||||
#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */
|
||||
#define ONIG_SYN_WARN_CC_DUP (1U<<26) /* [aa] */
|
||||
|
||||
/* meta character specifiers (onig_set_meta_char()) */
|
||||
#define ONIG_META_CHAR_ESCAPE 0
|
||||
#define ONIG_META_CHAR_ANYCHAR 1
|
||||
#define ONIG_META_CHAR_ANYTIME 2
|
||||
#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3
|
||||
#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4
|
||||
#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5
|
||||
|
||||
#define ONIG_INEFFECTIVE_META_CHAR 0
|
||||
|
||||
/* error codes */
|
||||
#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000)
|
||||
/* normal return */
|
||||
#define ONIG_NORMAL 0
|
||||
#define ONIG_MISMATCH -1
|
||||
#define ONIG_NO_SUPPORT_CONFIG -2
|
||||
|
||||
/* internal error */
|
||||
#define ONIGERR_MEMORY -5
|
||||
#define ONIGERR_TYPE_BUG -6
|
||||
#define ONIGERR_PARSER_BUG -11
|
||||
#define ONIGERR_STACK_BUG -12
|
||||
#define ONIGERR_UNDEFINED_BYTECODE -13
|
||||
#define ONIGERR_UNEXPECTED_BYTECODE -14
|
||||
#define ONIGERR_MATCH_STACK_LIMIT_OVER -15
|
||||
#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SET -21
|
||||
#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22
|
||||
/* general error */
|
||||
#define ONIGERR_INVALID_ARGUMENT -30
|
||||
/* syntax error */
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100
|
||||
#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101
|
||||
#define ONIGERR_EMPTY_CHAR_CLASS -102
|
||||
#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103
|
||||
#define ONIGERR_END_PATTERN_AT_ESCAPE -104
|
||||
#define ONIGERR_END_PATTERN_AT_META -105
|
||||
#define ONIGERR_END_PATTERN_AT_CONTROL -106
|
||||
#define ONIGERR_META_CODE_SYNTAX -108
|
||||
#define ONIGERR_CONTROL_CODE_SYNTAX -109
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110
|
||||
#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111
|
||||
#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113
|
||||
#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114
|
||||
#define ONIGERR_NESTED_REPEAT_OPERATOR -115
|
||||
#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116
|
||||
#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117
|
||||
#define ONIGERR_END_PATTERN_IN_GROUP -118
|
||||
#define ONIGERR_UNDEFINED_GROUP_OPTION -119
|
||||
#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121
|
||||
#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122
|
||||
#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123
|
||||
#define ONIGERR_INVALID_CONDITION_PATTERN -124
|
||||
/* values error (syntax error) */
|
||||
#define ONIGERR_TOO_BIG_NUMBER -200
|
||||
#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201
|
||||
#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202
|
||||
#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203
|
||||
#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204
|
||||
#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205
|
||||
#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206
|
||||
#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207
|
||||
#define ONIGERR_INVALID_BACKREF -208
|
||||
#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209
|
||||
#define ONIGERR_TOO_SHORT_DIGITS -210
|
||||
#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212
|
||||
#define ONIGERR_EMPTY_GROUP_NAME -214
|
||||
#define ONIGERR_INVALID_GROUP_NAME -215
|
||||
#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216
|
||||
#define ONIGERR_UNDEFINED_NAME_REFERENCE -217
|
||||
#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218
|
||||
#define ONIGERR_MULTIPLEX_DEFINED_NAME -219
|
||||
#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220
|
||||
#define ONIGERR_NEVER_ENDING_RECURSION -221
|
||||
#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222
|
||||
#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223
|
||||
#define ONIGERR_TOO_MANY_CAPTURE_GROUPS -224
|
||||
#define ONIGERR_INVALID_CODE_POINT_VALUE -400
|
||||
#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400
|
||||
#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401
|
||||
#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402
|
||||
#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403
|
||||
|
||||
/* errors related to thread */
|
||||
#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001
|
||||
|
||||
|
||||
/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */
|
||||
#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31
|
||||
#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \
|
||||
((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i])
|
||||
|
||||
typedef struct OnigCaptureTreeNodeStruct {
|
||||
int group; /* group number */
|
||||
OnigPosition beg;
|
||||
OnigPosition end;
|
||||
int allocated;
|
||||
int num_childs;
|
||||
struct OnigCaptureTreeNodeStruct** childs;
|
||||
} OnigCaptureTreeNode;
|
||||
|
||||
/* match result region type */
|
||||
struct re_registers {
|
||||
int allocated;
|
||||
int num_regs;
|
||||
OnigPosition* beg;
|
||||
OnigPosition* end;
|
||||
/* extended */
|
||||
OnigCaptureTreeNode* history_root; /* capture history tree root */
|
||||
};
|
||||
|
||||
/* capture tree traverse */
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2
|
||||
#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \
|
||||
( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST )
|
||||
|
||||
|
||||
#define ONIG_REGION_NOTPOS -1
|
||||
|
||||
typedef struct re_registers OnigRegion;
|
||||
|
||||
typedef struct {
|
||||
OnigEncoding enc;
|
||||
OnigUChar* par;
|
||||
OnigUChar* par_end;
|
||||
} OnigErrorInfo;
|
||||
|
||||
typedef struct {
|
||||
int lower;
|
||||
int upper;
|
||||
} OnigRepeatRange;
|
||||
|
||||
typedef void (*OnigWarnFunc) P_((const char* s));
|
||||
extern void onig_null_warn P_((const char* s));
|
||||
#define ONIG_NULL_WARN onig_null_warn
|
||||
|
||||
#define ONIG_CHAR_TABLE_SIZE 256
|
||||
|
||||
/* regex_t state */
|
||||
#define ONIG_STATE_NORMAL 0
|
||||
#define ONIG_STATE_SEARCHING 1
|
||||
#define ONIG_STATE_COMPILING -1
|
||||
#define ONIG_STATE_MODIFY -2
|
||||
|
||||
#define ONIG_STATE(reg) \
|
||||
((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state)
|
||||
|
||||
typedef struct re_pattern_buffer {
|
||||
/* common members of BBuf(bytes-buffer) */
|
||||
unsigned char* p; /* compiled pattern */
|
||||
unsigned int used; /* used space for p */
|
||||
unsigned int alloc; /* allocated space for p */
|
||||
|
||||
int state; /* normal, searching, compiling */
|
||||
int num_mem; /* used memory(...) num counted from 1 */
|
||||
int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */
|
||||
int num_null_check; /* OP_NULL_CHECK_START/END id counter */
|
||||
int num_comb_exp_check; /* combination explosion check */
|
||||
int num_call; /* number of subexp call */
|
||||
unsigned int capture_history; /* (?@...) flag (1-31) */
|
||||
unsigned int bt_mem_start; /* need backtrack flag */
|
||||
unsigned int bt_mem_end; /* need backtrack flag */
|
||||
int stack_pop_level;
|
||||
int repeat_range_alloc;
|
||||
OnigRepeatRange* repeat_range;
|
||||
|
||||
OnigEncoding enc;
|
||||
OnigOptionType options;
|
||||
const OnigSyntaxType* syntax;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
void* name_table;
|
||||
|
||||
/* optimization info (string search, char-map and anchors) */
|
||||
int optimize; /* optimize flag */
|
||||
int threshold_len; /* search str-length for apply optimize */
|
||||
int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */
|
||||
OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */
|
||||
OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */
|
||||
int sub_anchor; /* start-anchor for exact or map */
|
||||
unsigned char *exact;
|
||||
unsigned char *exact_end;
|
||||
unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */
|
||||
int *int_map; /* BM skip for exact_len > 255 */
|
||||
int *int_map_backward; /* BM skip for backward search */
|
||||
OnigDistance dmin; /* min-distance of exact or map */
|
||||
OnigDistance dmax; /* max-distance of exact or map */
|
||||
|
||||
/* regex_t link chain */
|
||||
struct re_pattern_buffer* chain; /* escape compile-conflict */
|
||||
} OnigRegexType;
|
||||
|
||||
typedef OnigRegexType* OnigRegex;
|
||||
|
||||
#ifndef ONIG_ESCAPE_REGEX_T_COLLISION
|
||||
typedef OnigRegexType regex_t;
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct {
|
||||
int num_of_elements;
|
||||
OnigEncoding pattern_enc;
|
||||
OnigEncoding target_enc;
|
||||
OnigSyntaxType* syntax;
|
||||
OnigOptionType option;
|
||||
OnigCaseFoldType case_fold_flag;
|
||||
} OnigCompileInfo;
|
||||
|
||||
/* Oniguruma Native API */
|
||||
ONIG_EXTERN
|
||||
int onig_init P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_error_code_to_str PV_((OnigUChar* s, OnigPosition err_code, ...));
|
||||
ONIG_EXTERN
|
||||
void onig_set_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
void onig_set_verb_warn_func P_((OnigWarnFunc f));
|
||||
ONIG_EXTERN
|
||||
int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, const OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_reg_init P_((OnigRegex reg, OnigOptionType option, OnigCaseFoldType case_fold_flag, OnigEncoding enc, const OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
int onig_new_without_alloc P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
void onig_free P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
void onig_free_body P_((OnigRegex));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo));
|
||||
ONIG_EXTERN
|
||||
OnigPosition onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
OnigPosition onig_search_gpos P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* global_pos, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
OnigPosition onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option));
|
||||
ONIG_EXTERN
|
||||
OnigRegion* onig_region_new P_((void));
|
||||
ONIG_EXTERN
|
||||
void onig_region_init P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
void onig_region_free P_((OnigRegion* region, int free_self));
|
||||
ONIG_EXTERN
|
||||
void onig_region_copy P_((OnigRegion* to, OnigRegion* from));
|
||||
ONIG_EXTERN
|
||||
void onig_region_clear P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_region_resize P_((OnigRegion* region, int n));
|
||||
ONIG_EXTERN
|
||||
int onig_region_set P_((OnigRegion* region, int at, int beg, int end));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums));
|
||||
ONIG_EXTERN
|
||||
int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region));
|
||||
ONIG_EXTERN
|
||||
int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_names P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_captures P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_number_of_capture_histories P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region));
|
||||
ONIG_EXTERN
|
||||
int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,OnigPosition,OnigPosition,int,int,void*), void* arg));
|
||||
ONIG_EXTERN
|
||||
int onig_noname_group_capture_is_active P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigEncoding onig_get_encoding P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_options P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
const OnigSyntaxType* onig_get_syntax P_((OnigRegex reg));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_syntax P_((const OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_syntax P_((OnigSyntaxType* to, const OnigSyntaxType* from));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior));
|
||||
ONIG_EXTERN
|
||||
void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options));
|
||||
ONIG_EXTERN
|
||||
int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code));
|
||||
ONIG_EXTERN
|
||||
void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from));
|
||||
ONIG_EXTERN
|
||||
OnigCaseFoldType onig_get_default_case_fold_flag P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag));
|
||||
ONIG_EXTERN
|
||||
unsigned int onig_get_match_stack_limit_size P_((void));
|
||||
ONIG_EXTERN
|
||||
int onig_set_match_stack_limit_size P_((unsigned int size));
|
||||
ONIG_EXTERN
|
||||
int onig_end P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_version P_((void));
|
||||
ONIG_EXTERN
|
||||
const char* onig_copyright P_((void));
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ONIGURUMA_H */
|
||||
71
ruby/include/ruby-2.1.0/ruby/re.h
Normal file
71
ruby/include/ruby-2.1.0/ruby/re.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/**********************************************************************
|
||||
|
||||
re.h -
|
||||
|
||||
$Author: nobu $
|
||||
created at: Thu Sep 30 14:18:32 JST 1993
|
||||
|
||||
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_RE_H
|
||||
#define RUBY_RE_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ruby/regex.h"
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
typedef struct re_pattern_buffer Regexp;
|
||||
|
||||
struct rmatch_offset {
|
||||
long beg;
|
||||
long end;
|
||||
};
|
||||
|
||||
struct rmatch {
|
||||
struct re_registers regs;
|
||||
|
||||
int char_offset_updated;
|
||||
int char_offset_num_allocated;
|
||||
struct rmatch_offset *char_offset;
|
||||
};
|
||||
|
||||
struct RMatch {
|
||||
struct RBasic basic;
|
||||
VALUE str;
|
||||
struct rmatch *rmatch;
|
||||
VALUE regexp; /* RRegexp */
|
||||
};
|
||||
|
||||
#define RMATCH(obj) (R_CAST(RMatch)(obj))
|
||||
#define RMATCH_REGS(obj) (&(R_CAST(RMatch)(obj))->rmatch->regs)
|
||||
|
||||
VALUE rb_reg_regcomp(VALUE);
|
||||
long rb_reg_search(VALUE, VALUE, long, int);
|
||||
VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE);
|
||||
long rb_reg_adjust_startpos(VALUE, VALUE, long, int);
|
||||
void rb_match_busy(VALUE);
|
||||
VALUE rb_reg_quote(VALUE);
|
||||
regex_t *rb_reg_prepare_re(VALUE re, VALUE str);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_RE_H */
|
||||
46
ruby/include/ruby-2.1.0/ruby/regex.h
Normal file
46
ruby/include/ruby-2.1.0/ruby/regex.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/**********************************************************************
|
||||
|
||||
regex.h -
|
||||
|
||||
$Author: nobu $
|
||||
|
||||
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef ONIGURUMA_REGEX_H
|
||||
#define ONIGURUMA_REGEX_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef RUBY
|
||||
#include "ruby/oniguruma.h"
|
||||
#else
|
||||
#include "oniguruma.h"
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#ifndef ONIG_RUBY_M17N
|
||||
|
||||
ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding;
|
||||
|
||||
#define mbclen(p,e,enc) rb_enc_mbclen((p),(e),(enc))
|
||||
|
||||
#endif /* ifndef ONIG_RUBY_M17N */
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* ONIGURUMA_REGEX_H */
|
||||
1872
ruby/include/ruby-2.1.0/ruby/ruby.h
Normal file
1872
ruby/include/ruby-2.1.0/ruby/ruby.h
Normal file
File diff suppressed because it is too large
Load Diff
154
ruby/include/ruby-2.1.0/ruby/st.h
Normal file
154
ruby/include/ruby-2.1.0/ruby/st.h
Normal file
@@ -0,0 +1,154 @@
|
||||
/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */
|
||||
|
||||
/* @(#) st.h 5.1 89/12/14 */
|
||||
|
||||
#ifndef RUBY_ST_H
|
||||
#define RUBY_ST_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ruby/defines.h"
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#if SIZEOF_LONG == SIZEOF_VOIDP
|
||||
typedef unsigned long st_data_t;
|
||||
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
|
||||
typedef unsigned LONG_LONG st_data_t;
|
||||
#else
|
||||
# error ---->> st.c requires sizeof(void*) == sizeof(long) or sizeof(LONG_LONG) to be compiled. <<----
|
||||
#endif
|
||||
#define ST_DATA_T_DEFINED
|
||||
|
||||
#ifndef CHAR_BIT
|
||||
# ifdef HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
# else
|
||||
# define CHAR_BIT 8
|
||||
# endif
|
||||
#endif
|
||||
#ifndef _
|
||||
# define _(args) args
|
||||
#endif
|
||||
#ifndef ANYARGS
|
||||
# ifdef __cplusplus
|
||||
# define ANYARGS ...
|
||||
# else
|
||||
# define ANYARGS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef struct st_table st_table;
|
||||
|
||||
typedef st_data_t st_index_t;
|
||||
typedef int st_compare_func(st_data_t, st_data_t);
|
||||
typedef st_index_t st_hash_func(st_data_t);
|
||||
|
||||
typedef char st_check_for_sizeof_st_index_t[SIZEOF_VOIDP == (int)sizeof(st_index_t) ? 1 : -1];
|
||||
#define SIZEOF_ST_INDEX_T SIZEOF_VOIDP
|
||||
|
||||
struct st_hash_type {
|
||||
int (*compare)(ANYARGS /*st_data_t, st_data_t*/); /* st_compare_func* */
|
||||
st_index_t (*hash)(ANYARGS /*st_data_t*/); /* st_hash_func* */
|
||||
};
|
||||
|
||||
#define ST_INDEX_BITS (sizeof(st_index_t) * CHAR_BIT)
|
||||
|
||||
#if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR) && defined(HAVE_BUILTIN___BUILTIN_TYPES_COMPATIBLE_P)
|
||||
# define ST_DATA_COMPATIBLE_P(type) \
|
||||
__builtin_choose_expr(__builtin_types_compatible_p(type, st_data_t), 1, 0)
|
||||
#else
|
||||
# define ST_DATA_COMPATIBLE_P(type) 0
|
||||
#endif
|
||||
|
||||
struct st_table {
|
||||
const struct st_hash_type *type;
|
||||
st_index_t num_bins;
|
||||
unsigned int entries_packed : 1;
|
||||
#ifdef __GNUC__
|
||||
/*
|
||||
* C spec says,
|
||||
* A bit-field shall have a type that is a qualified or unqualified
|
||||
* version of _Bool, signed int, unsigned int, or some other
|
||||
* implementation-defined type. It is implementation-defined whether
|
||||
* atomic types are permitted.
|
||||
* In short, long and long long bit-field are implementation-defined
|
||||
* feature. Therefore we want to supress a warning explicitly.
|
||||
*/
|
||||
__extension__
|
||||
#endif
|
||||
st_index_t num_entries : ST_INDEX_BITS - 1;
|
||||
union {
|
||||
struct {
|
||||
struct st_table_entry **bins;
|
||||
struct st_table_entry *head, *tail;
|
||||
} big;
|
||||
struct {
|
||||
struct st_packed_entry *entries;
|
||||
st_index_t real_entries;
|
||||
} packed;
|
||||
} as;
|
||||
};
|
||||
|
||||
#define st_is_member(table,key) st_lookup((table),(key),(st_data_t *)0)
|
||||
|
||||
enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK};
|
||||
|
||||
st_table *st_init_table(const struct st_hash_type *);
|
||||
st_table *st_init_table_with_size(const struct st_hash_type *, st_index_t);
|
||||
st_table *st_init_numtable(void);
|
||||
st_table *st_init_numtable_with_size(st_index_t);
|
||||
st_table *st_init_strtable(void);
|
||||
st_table *st_init_strtable_with_size(st_index_t);
|
||||
st_table *st_init_strcasetable(void);
|
||||
st_table *st_init_strcasetable_with_size(st_index_t);
|
||||
int st_delete(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
|
||||
int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t);
|
||||
int st_shift(st_table *, st_data_t *, st_data_t *); /* returns 0:notfound 1:deleted */
|
||||
int st_insert(st_table *, st_data_t, st_data_t);
|
||||
int st_insert2(st_table *, st_data_t, st_data_t, st_data_t (*)(st_data_t));
|
||||
int st_lookup(st_table *, st_data_t, st_data_t *);
|
||||
int st_get_key(st_table *, st_data_t, st_data_t *);
|
||||
typedef int st_update_callback_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing);
|
||||
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg);
|
||||
int st_foreach(st_table *, int (*)(ANYARGS), st_data_t);
|
||||
int st_foreach_check(st_table *, int (*)(ANYARGS), st_data_t, st_data_t);
|
||||
int st_reverse_foreach(st_table *, int (*)(ANYARGS), st_data_t);
|
||||
st_index_t st_keys(st_table *table, st_data_t *keys, st_index_t size);
|
||||
st_index_t st_keys_check(st_table *table, st_data_t *keys, st_index_t size, st_data_t never);
|
||||
st_index_t st_values(st_table *table, st_data_t *values, st_index_t size);
|
||||
st_index_t st_values_check(st_table *table, st_data_t *values, st_index_t size, st_data_t never);
|
||||
void st_add_direct(st_table *, st_data_t, st_data_t);
|
||||
void st_free_table(st_table *);
|
||||
void st_cleanup_safe(st_table *, st_data_t);
|
||||
void st_clear(st_table *);
|
||||
st_table *st_copy(st_table *);
|
||||
int st_numcmp(st_data_t, st_data_t);
|
||||
st_index_t st_numhash(st_data_t);
|
||||
int st_locale_insensitive_strcasecmp(const char *s1, const char *s2);
|
||||
int st_locale_insensitive_strncasecmp(const char *s1, const char *s2, size_t n);
|
||||
#define st_strcasecmp st_locale_insensitive_strcasecmp
|
||||
#define st_strncasecmp st_locale_insensitive_strncasecmp
|
||||
size_t st_memsize(const st_table *);
|
||||
st_index_t st_hash(const void *ptr, size_t len, st_index_t h);
|
||||
st_index_t st_hash_uint32(st_index_t h, uint32_t i);
|
||||
st_index_t st_hash_uint(st_index_t h, st_index_t i);
|
||||
st_index_t st_hash_end(st_index_t h);
|
||||
st_index_t st_hash_start(st_index_t h);
|
||||
#define st_hash_start(h) ((st_index_t)(h))
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_ST_H */
|
||||
19
ruby/include/ruby-2.1.0/ruby/subst.h
Normal file
19
ruby/include/ruby-2.1.0/ruby/subst.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef RUBY_SUBST_H
|
||||
#define RUBY_SUBST_H 1
|
||||
|
||||
#undef snprintf
|
||||
#undef vsnprintf
|
||||
#define snprintf ruby_snprintf
|
||||
#define vsnprintf ruby_vsnprintf
|
||||
|
||||
#ifdef BROKEN_CLOSE
|
||||
#undef getpeername
|
||||
#define getpeername ruby_getpeername
|
||||
#undef getsockname
|
||||
#define getsockname ruby_getsockname
|
||||
#undef shutdown
|
||||
#define shutdown ruby_shutdown
|
||||
#undef close
|
||||
#define close ruby_close
|
||||
#endif
|
||||
#endif
|
||||
45
ruby/include/ruby-2.1.0/ruby/thread.h
Normal file
45
ruby/include/ruby-2.1.0/ruby/thread.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/**********************************************************************
|
||||
|
||||
thread.h -
|
||||
|
||||
$Author: matz $
|
||||
created at: Tue Jul 10 17:35:43 JST 2012
|
||||
|
||||
Copyright (C) 2007 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_THREAD_H
|
||||
#define RUBY_THREAD_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ruby/intern.h"
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
|
||||
|
||||
void *rb_thread_call_without_gvl(void *(*func)(void *), void *data1,
|
||||
rb_unblock_function_t *ubf, void *data2);
|
||||
void *rb_thread_call_without_gvl2(void *(*func)(void *), void *data1,
|
||||
rb_unblock_function_t *ubf, void *data2);
|
||||
|
||||
#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_AFTER 0x01
|
||||
#define RUBY_CALL_WO_GVL_FLAG_SKIP_CHECK_INTS_
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_THREAD_H */
|
||||
95
ruby/include/ruby-2.1.0/ruby/util.h
Normal file
95
ruby/include/ruby-2.1.0/ruby/util.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/**********************************************************************
|
||||
|
||||
util.h -
|
||||
|
||||
$Author: nobu $
|
||||
created at: Thu Mar 9 11:55:53 JST 1995
|
||||
|
||||
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_UTIL_H
|
||||
#define RUBY_UTIL_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "ruby/defines.h"
|
||||
#ifdef RUBY_EXTCONF_H
|
||||
#include RUBY_EXTCONF_H
|
||||
#endif
|
||||
|
||||
#ifndef _
|
||||
#ifdef __cplusplus
|
||||
# ifndef HAVE_PROTOTYPES
|
||||
# define HAVE_PROTOTYPES 1
|
||||
# endif
|
||||
# ifndef HAVE_STDARG_PROTOTYPES
|
||||
# define HAVE_STDARG_PROTOTYPES 1
|
||||
# endif
|
||||
#endif
|
||||
#ifdef HAVE_PROTOTYPES
|
||||
# define _(args) args
|
||||
#else
|
||||
# define _(args) ()
|
||||
#endif
|
||||
#ifdef HAVE_STDARG_PROTOTYPES
|
||||
# define __(args) args
|
||||
#else
|
||||
# define __(args) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
#define scan_oct(s,l,e) ((int)ruby_scan_oct((s),(l),(e)))
|
||||
unsigned long ruby_scan_oct(const char *, size_t, size_t *);
|
||||
#define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e)))
|
||||
unsigned long ruby_scan_hex(const char *, size_t, size_t *);
|
||||
|
||||
void ruby_qsort(void *, const size_t, const size_t,
|
||||
int (*)(const void *, const void *, void *), void *);
|
||||
|
||||
void ruby_setenv(const char *, const char *);
|
||||
void ruby_unsetenv(const char *);
|
||||
#undef setenv
|
||||
#undef unsetenv
|
||||
#define setenv(name,val) ruby_setenv((name),(val))
|
||||
#define unsetenv(name,val) ruby_unsetenv(name)
|
||||
|
||||
char *ruby_strdup(const char *);
|
||||
#undef strdup
|
||||
#define strdup(s) ruby_strdup(s)
|
||||
|
||||
char *ruby_getcwd(void);
|
||||
#define my_getcwd() ruby_getcwd()
|
||||
|
||||
double ruby_strtod(const char *, char **);
|
||||
#undef strtod
|
||||
#define strtod(s,e) ruby_strtod((s),(e))
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1300
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4723)
|
||||
#endif
|
||||
#if defined _MSC_VER && _MSC_VER >= 1300
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
void ruby_each_words(const char *, void (*)(const char*, int, void*), void *);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_UTIL_H */
|
||||
74
ruby/include/ruby-2.1.0/ruby/version.h
Normal file
74
ruby/include/ruby-2.1.0/ruby/version.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/**********************************************************************
|
||||
|
||||
ruby/version.h -
|
||||
|
||||
$Author: nobu $
|
||||
created at: Wed May 13 12:56:56 JST 2009
|
||||
|
||||
Copyright (C) 1993-2009 Yukihiro Matsumoto
|
||||
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
/*
|
||||
* This file contains only
|
||||
* - never-changable informations, and
|
||||
* - interfaces accessible from extension libraries.
|
||||
*
|
||||
* Never try to check RUBY_VERSION_CODE etc in extension libraries,
|
||||
* check the features with mkmf.rb instead.
|
||||
*/
|
||||
|
||||
#ifndef RUBY_VERSION_H
|
||||
#define RUBY_VERSION_H 1
|
||||
|
||||
/* The origin. */
|
||||
#define RUBY_AUTHOR "Yukihiro Matsumoto"
|
||||
#define RUBY_BIRTH_YEAR 1993
|
||||
#define RUBY_BIRTH_MONTH 2
|
||||
#define RUBY_BIRTH_DAY 24
|
||||
|
||||
/* API version */
|
||||
#define RUBY_API_VERSION_MAJOR 2
|
||||
#define RUBY_API_VERSION_MINOR 1
|
||||
#define RUBY_API_VERSION_TEENY 0
|
||||
#define RUBY_API_VERSION_CODE (RUBY_API_VERSION_MAJOR*10000+RUBY_API_VERSION_MINOR*100+RUBY_API_VERSION_TEENY)
|
||||
|
||||
#ifdef RUBY_EXTERN
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
/*
|
||||
* Interfaces from extension libraries.
|
||||
*
|
||||
* Before using these infos, think thrice whether they are really
|
||||
* necessary or not, and if the answer was yes, think twice a week
|
||||
* later again.
|
||||
*/
|
||||
RUBY_EXTERN const int ruby_api_version[3];
|
||||
RUBY_EXTERN const char ruby_version[];
|
||||
RUBY_EXTERN const char ruby_release_date[];
|
||||
RUBY_EXTERN const char ruby_platform[];
|
||||
RUBY_EXTERN const int ruby_patchlevel;
|
||||
RUBY_EXTERN const char ruby_description[];
|
||||
RUBY_EXTERN const char ruby_copyright[];
|
||||
RUBY_EXTERN const char ruby_engine[];
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
64
ruby/include/ruby-2.1.0/ruby/vm.h
Normal file
64
ruby/include/ruby-2.1.0/ruby/vm.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/**********************************************************************
|
||||
|
||||
ruby/vm.h -
|
||||
|
||||
$Author: nobu $
|
||||
created at: Sat May 31 15:17:36 2008
|
||||
|
||||
Copyright (C) 2008 Yukihiro Matsumoto
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef RUBY_VM_H
|
||||
#define RUBY_VM_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
/* Place holder.
|
||||
*
|
||||
* We will prepare VM creation/control APIs on 1.9.2 or later.
|
||||
* If you have an interest about it, please see mvm branch.
|
||||
* http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/mvm/
|
||||
*/
|
||||
|
||||
/* VM type declaration */
|
||||
typedef struct rb_vm_struct ruby_vm_t;
|
||||
|
||||
/* core API */
|
||||
int ruby_vm_destruct(ruby_vm_t *vm);
|
||||
|
||||
/**
|
||||
* ruby_vm_at_exit registers a function _func_ to be invoked when a VM
|
||||
* passed away. Functions registered this way runs in reverse order
|
||||
* of registration, just like END {} block does. The difference is
|
||||
* its timing to be triggered. ruby_vm_at_exit functions runs when a
|
||||
* VM _passed_ _away_, while END {} blocks runs just _before_ a VM
|
||||
* _is_ _passing_ _away_.
|
||||
*
|
||||
* You cannot register a function to another VM than where you are in.
|
||||
* So where to register is intuitive, omitted. OTOH the argument
|
||||
* _func_ cannot know which VM it is in because at the time of
|
||||
* invocation, the VM has already died and there is no execution
|
||||
* context. The VM itself is passed as the first argument to it.
|
||||
*
|
||||
* @param[in] func the function to register.
|
||||
*/
|
||||
void ruby_vm_at_exit(void(*func)(ruby_vm_t *));
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_VM_H */
|
||||
837
ruby/include/ruby-2.1.0/ruby/win32.h
Normal file
837
ruby/include/ruby-2.1.0/ruby/win32.h
Normal file
@@ -0,0 +1,837 @@
|
||||
#ifndef RUBY_WIN32_H
|
||||
#define RUBY_WIN32_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#if 0
|
||||
} /* satisfy cc-mode */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, Intergraph Corporation
|
||||
*
|
||||
* You may distribute under the terms of either the GNU General Public
|
||||
* License or the Artistic License, as specified in the perl README file.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Definitions for NT port of Perl
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Ok now we can include the normal include files.
|
||||
*/
|
||||
|
||||
/* #include <stdarg.h> conflict with varargs.h? */
|
||||
#if !defined(WSAAPI)
|
||||
#if defined(__cplusplus) && defined(_MSC_VER)
|
||||
extern "C++" { /* template without extern "C++" */
|
||||
#endif
|
||||
#if !defined(_WIN64) && !defined(WIN32)
|
||||
#define WIN32
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1400
|
||||
#include <iphlpapi.h>
|
||||
#endif
|
||||
#if defined(__cplusplus) && defined(_MSC_VER)
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* We're not using Microsoft's "extensions" to C for
|
||||
* Structured Exception Handling (SEH) so we can nuke these
|
||||
*/
|
||||
#undef try
|
||||
#undef except
|
||||
#undef finally
|
||||
#undef leave
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <direct.h>
|
||||
#include <process.h>
|
||||
#include <time.h>
|
||||
#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
|
||||
extern "C++" { /* template without extern "C++" */
|
||||
#endif
|
||||
#include <math.h>
|
||||
#if defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER == 1200
|
||||
}
|
||||
#endif
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_SYS_UTIME_H
|
||||
# include <sys/utime.h>
|
||||
#else
|
||||
# include <utime.h>
|
||||
#endif
|
||||
#include <io.h>
|
||||
#include <malloc.h>
|
||||
#if defined __MINGW32__ || __BORLANDC__ >= 0x0580
|
||||
# include <stdint.h>
|
||||
#else
|
||||
# if !defined(_INTPTR_T_DEFINED)
|
||||
# ifdef _WIN64
|
||||
typedef __int64 intptr_t;
|
||||
# else
|
||||
typedef int intptr_t;
|
||||
# endif
|
||||
# define _INTPTR_T_DEFINED
|
||||
# endif
|
||||
# if !defined(INTPTR_MAX)
|
||||
# ifdef _WIN64
|
||||
# define INTPTR_MAX 9223372036854775807I64
|
||||
# else
|
||||
# define INTPTR_MAX 2147483647
|
||||
# endif
|
||||
# define INTPTR_MIN (-INTPTR_MAX-1)
|
||||
# endif
|
||||
# if !defined(_UINTPTR_T_DEFINED)
|
||||
# ifdef _WIN64
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
# else
|
||||
typedef unsigned int uintptr_t;
|
||||
# endif
|
||||
# define _UINTPTR_T_DEFINED
|
||||
# endif
|
||||
# if !defined(UINTPTR_MAX)
|
||||
# ifdef _WIN64
|
||||
# define UINTPTR_MAX 18446744073709551615UI64
|
||||
# else
|
||||
# define UINTPTR_MAX 4294967295U
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
#ifndef __MINGW32__
|
||||
# define mode_t int
|
||||
#endif
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#define rb_w32_iswinnt() TRUE
|
||||
#define rb_w32_iswin95() FALSE
|
||||
|
||||
#define WNOHANG -1
|
||||
|
||||
typedef int clockid_t;
|
||||
#define CLOCK_REALTIME 0
|
||||
#define CLOCK_MONOTONIC 1
|
||||
|
||||
#undef getc
|
||||
#undef putc
|
||||
#undef fgetc
|
||||
#undef fputc
|
||||
#undef getchar
|
||||
#undef putchar
|
||||
#undef fgetchar
|
||||
#undef fputchar
|
||||
#undef utime
|
||||
#undef lseek
|
||||
#undef stat
|
||||
#undef fstat
|
||||
#define getc(_stream) rb_w32_getc(_stream)
|
||||
#define getchar() rb_w32_getc(stdin)
|
||||
#define putc(_c, _stream) rb_w32_putc(_c, _stream)
|
||||
#define putchar(_c) rb_w32_putc(_c, stdout)
|
||||
#ifdef RUBY_EXPORT
|
||||
#define fgetc(_stream) getc(_stream)
|
||||
#define fputc(_c, _stream) putc(_c, _stream)
|
||||
#define fgetchar() getchar()
|
||||
#define fputchar(_c) putchar(_c)
|
||||
#define utime(_p, _t) rb_w32_utime(_p, _t)
|
||||
#define lseek(_f, _o, _w) _lseeki64(_f, _o, _w)
|
||||
|
||||
#define pipe(p) rb_w32_pipe(p)
|
||||
#define open rb_w32_open
|
||||
#define close(h) rb_w32_close(h)
|
||||
#define fclose(f) rb_w32_fclose(f)
|
||||
#define read(f, b, s) rb_w32_read(f, b, s)
|
||||
#define write(f, b, s) rb_w32_write(f, b, s)
|
||||
#define getpid() rb_w32_getpid()
|
||||
#define getppid() rb_w32_getppid()
|
||||
#define sleep(x) rb_w32_Sleep((x)*1000)
|
||||
#define Sleep(msec) (void)rb_w32_Sleep(msec)
|
||||
#define fstati64(fd,st) rb_w32_fstati64(fd,st)
|
||||
#ifdef __BORLANDC__
|
||||
#define creat(p, m) _creat(p, m)
|
||||
#define eof() _eof()
|
||||
#define filelength(h) _filelength(h)
|
||||
#define mktemp(t) _mktemp(t)
|
||||
#define tell(h) _tell(h)
|
||||
#define _open _sopen
|
||||
#define sopen _sopen
|
||||
#undef fopen
|
||||
#define fopen(p, m) rb_w32_fopen(p, m)
|
||||
#undef fdopen
|
||||
#define fdopen(h, m) rb_w32_fdopen(h, m)
|
||||
#undef fsopen
|
||||
#define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh)
|
||||
#endif /* __BORLANDC__ */
|
||||
|
||||
#undef execv
|
||||
#define execv(path,argv) rb_w32_aspawn(P_OVERLAY,path,argv)
|
||||
#if !defined(__BORLANDC__)
|
||||
#undef isatty
|
||||
#define isatty(h) rb_w32_isatty(h)
|
||||
#endif /* __BORLANDC__ */
|
||||
|
||||
#undef mkdir
|
||||
#define mkdir(p, m) rb_w32_mkdir(p, m)
|
||||
#undef rmdir
|
||||
#define rmdir(p) rb_w32_rmdir(p)
|
||||
#undef unlink
|
||||
#define unlink(p) rb_w32_unlink(p)
|
||||
#endif /* RUBY_EXPORT */
|
||||
|
||||
#if SIZEOF_OFF_T == 8
|
||||
#define off_t __int64
|
||||
#define stat stati64
|
||||
#define fstat(fd,st) fstati64(fd,st)
|
||||
#if defined(__BORLANDC__)
|
||||
#define stati64(path, st) rb_w32_stati64(path, st)
|
||||
#elif !defined(_MSC_VER) || RT_VER < 80
|
||||
#define stati64 _stati64
|
||||
#ifndef _stati64
|
||||
#define _stati64(path, st) rb_w32_stati64(path, st)
|
||||
#endif
|
||||
#else
|
||||
#define stati64 _stat64
|
||||
#define _stat64(path, st) rb_w32_stati64(path, st)
|
||||
#endif
|
||||
#else
|
||||
#define stat(path,st) rb_w32_stat(path,st)
|
||||
#define fstat(fd,st) rb_w32_fstat(fd,st)
|
||||
extern int rb_w32_stat(const char *, struct stat *);
|
||||
extern int rb_w32_fstat(int, struct stat *);
|
||||
#endif
|
||||
#define access(path,mode) rb_w32_access(path,mode)
|
||||
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#define fsync _commit
|
||||
|
||||
struct timezone;
|
||||
|
||||
#ifdef __MINGW32__
|
||||
#undef isascii
|
||||
#define isascii __isascii
|
||||
#endif
|
||||
|
||||
struct iovec {
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
struct msghdr {
|
||||
void *msg_name;
|
||||
int msg_namelen;
|
||||
struct iovec *msg_iov;
|
||||
int msg_iovlen;
|
||||
void *msg_control;
|
||||
int msg_controllen;
|
||||
int msg_flags;
|
||||
};
|
||||
|
||||
/* for getifaddrs() and others */
|
||||
struct ifaddrs {
|
||||
struct ifaddrs *ifa_next;
|
||||
char *ifa_name;
|
||||
u_int ifa_flags;
|
||||
struct sockaddr *ifa_addr;
|
||||
struct sockaddr *ifa_netmask;
|
||||
struct sockaddr *ifa_broadaddr;
|
||||
struct sockaddr *ifa_dstaddr;
|
||||
void *ifa_data;
|
||||
};
|
||||
#ifdef IF_NAMESIZE
|
||||
#define IFNAMSIZ IF_NAMESIZE
|
||||
#else
|
||||
#define IFNAMSIZ 256
|
||||
#endif
|
||||
#ifdef IFF_POINTTOPOINT
|
||||
#define IFF_POINTOPOINT IFF_POINTTOPOINT
|
||||
#endif
|
||||
|
||||
extern DWORD rb_w32_osid(void);
|
||||
extern int rb_w32_cmdvector(const char *, char ***);
|
||||
extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *, int *);
|
||||
extern int flock(int fd, int oper);
|
||||
extern int rb_w32_io_cancelable_p(int);
|
||||
extern int rb_w32_is_socket(int);
|
||||
extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *);
|
||||
extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int);
|
||||
extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int);
|
||||
extern void rb_w32_fdset(int, fd_set*);
|
||||
extern void rb_w32_fdclr(int, fd_set*);
|
||||
extern int rb_w32_fdisset(int, fd_set*);
|
||||
extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
|
||||
extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *);
|
||||
extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *);
|
||||
extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *);
|
||||
extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *);
|
||||
extern int WSAAPI rb_w32_listen(int, int);
|
||||
extern int WSAAPI rb_w32_recv(int, char *, int, int);
|
||||
extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *);
|
||||
extern int WSAAPI rb_w32_send(int, const char *, int, int);
|
||||
extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int);
|
||||
extern int recvmsg(int, struct msghdr *, int);
|
||||
extern int sendmsg(int, const struct msghdr *, int);
|
||||
extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int);
|
||||
extern int WSAAPI rb_w32_shutdown(int, int);
|
||||
extern int WSAAPI rb_w32_socket(int, int, int);
|
||||
extern SOCKET rb_w32_get_osfhandle(int);
|
||||
extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int);
|
||||
extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *);
|
||||
extern int WSAAPI rb_w32_gethostname(char *, int);
|
||||
extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *);
|
||||
extern struct protoent *WSAAPI rb_w32_getprotobynumber(int);
|
||||
extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *);
|
||||
extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *);
|
||||
extern int socketpair(int, int, int, int *);
|
||||
extern int getifaddrs(struct ifaddrs **);
|
||||
extern void freeifaddrs(struct ifaddrs *);
|
||||
extern char * rb_w32_getcwd(char *, int);
|
||||
extern char * rb_w32_ugetenv(const char *);
|
||||
extern char * rb_w32_getenv(const char *);
|
||||
extern int rb_w32_rename(const char *, const char *);
|
||||
extern int rb_w32_urename(const char *, const char *);
|
||||
extern char **rb_w32_get_environ(void);
|
||||
extern void rb_w32_free_environ(char **);
|
||||
extern int rb_w32_map_errno(DWORD);
|
||||
extern const char *WSAAPI rb_w32_inet_ntop(int,const void *,char *,size_t);
|
||||
extern int WSAAPI rb_w32_inet_pton(int,const char *,void *);
|
||||
extern DWORD rb_w32_osver(void);
|
||||
|
||||
extern int chown(const char *, int, int);
|
||||
extern int rb_w32_uchown(const char *, int, int);
|
||||
extern int link(const char *, const char *);
|
||||
extern int rb_w32_ulink(const char *, const char *);
|
||||
extern int gettimeofday(struct timeval *, struct timezone *);
|
||||
extern int clock_gettime(clockid_t, struct timespec *);
|
||||
extern int clock_getres(clockid_t, struct timespec *);
|
||||
extern rb_pid_t waitpid (rb_pid_t, int *, int);
|
||||
extern rb_pid_t rb_w32_spawn(int, const char *, const char*);
|
||||
extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *);
|
||||
extern rb_pid_t rb_w32_aspawn_flags(int, const char *, char *const *, DWORD);
|
||||
extern rb_pid_t rb_w32_uspawn(int, const char *, const char*);
|
||||
extern rb_pid_t rb_w32_uaspawn(int, const char *, char *const *);
|
||||
extern rb_pid_t rb_w32_uaspawn_flags(int, const char *, char *const *, DWORD);
|
||||
extern int kill(int, int);
|
||||
extern int fcntl(int, int, ...);
|
||||
extern rb_pid_t rb_w32_getpid(void);
|
||||
extern rb_pid_t rb_w32_getppid(void);
|
||||
#if !defined(__BORLANDC__)
|
||||
extern int rb_w32_isatty(int);
|
||||
#endif
|
||||
extern int rb_w32_uchdir(const char *);
|
||||
extern int rb_w32_mkdir(const char *, int);
|
||||
extern int rb_w32_umkdir(const char *, int);
|
||||
extern int rb_w32_rmdir(const char *);
|
||||
extern int rb_w32_urmdir(const char *);
|
||||
extern int rb_w32_unlink(const char *);
|
||||
extern int rb_w32_uunlink(const char *);
|
||||
extern int rb_w32_uchmod(const char *, int);
|
||||
extern int rb_w32_stati64(const char *, struct stati64 *);
|
||||
extern int rb_w32_ustati64(const char *, struct stati64 *);
|
||||
extern int rb_w32_access(const char *, int);
|
||||
extern int rb_w32_uaccess(const char *, int);
|
||||
extern char rb_w32_fd_is_text(int);
|
||||
extern int rb_w32_fstati64(int, struct stati64 *);
|
||||
extern int rb_w32_dup2(int, int);
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
extern off_t _lseeki64(int, off_t, int);
|
||||
extern FILE *rb_w32_fopen(const char *, const char *);
|
||||
extern FILE *rb_w32_fdopen(int, const char *);
|
||||
extern FILE *rb_w32_fsopen(const char *, const char *, int);
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1800 && defined INFINITY
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4756)
|
||||
static inline float
|
||||
rb_infinity_float(void)
|
||||
{
|
||||
return INFINITY;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
#undef INFINITY
|
||||
#define INFINITY rb_infinity_float()
|
||||
#endif
|
||||
|
||||
#if !defined __MINGW32__ || defined __NO_ISOCEXT
|
||||
#ifndef isnan
|
||||
#define isnan(x) _isnan(x)
|
||||
#endif
|
||||
static inline int
|
||||
finite(double x)
|
||||
{
|
||||
return _finite(x);
|
||||
}
|
||||
#ifndef copysign
|
||||
#define copysign(a, b) _copysign(a, b)
|
||||
#endif
|
||||
static inline double
|
||||
scalb(double a, long b)
|
||||
{
|
||||
return _scalb(a, b);
|
||||
}
|
||||
#else
|
||||
__declspec(dllimport) extern int finite(double);
|
||||
#endif
|
||||
|
||||
#if !defined S_IFIFO && defined _S_IFIFO
|
||||
#define S_IFIFO _S_IFIFO
|
||||
#endif
|
||||
|
||||
#if 0 && defined __BORLANDC__
|
||||
#undef S_ISDIR
|
||||
#undef S_ISFIFO
|
||||
#undef S_ISBLK
|
||||
#undef S_ISCHR
|
||||
#undef S_ISREG
|
||||
#define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO)
|
||||
#define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK)
|
||||
#define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR)
|
||||
#define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
#if !defined S_IRUSR && !defined __MINGW32__
|
||||
#define S_IRUSR 0400
|
||||
#endif
|
||||
#ifndef S_IRGRP
|
||||
#define S_IRGRP 0040
|
||||
#endif
|
||||
#ifndef S_IROTH
|
||||
#define S_IROTH 0004
|
||||
#endif
|
||||
|
||||
#if !defined S_IWUSR && !defined __MINGW32__
|
||||
#define S_IWUSR 0200
|
||||
#endif
|
||||
#ifndef S_IWGRP
|
||||
#define S_IWGRP 0020
|
||||
#endif
|
||||
#ifndef S_IWOTH
|
||||
#define S_IWOTH 0002
|
||||
#endif
|
||||
|
||||
#if !defined S_IXUSR && !defined __MINGW32__
|
||||
#define S_IXUSR 0100
|
||||
#endif
|
||||
#ifndef S_IXGRP
|
||||
#define S_IXGRP 0010
|
||||
#endif
|
||||
#ifndef S_IXOTH
|
||||
#define S_IXOTH 0001
|
||||
#endif
|
||||
|
||||
/*
|
||||
* define this so we can do inplace editing
|
||||
*/
|
||||
|
||||
#define SUFFIX
|
||||
|
||||
extern int rb_w32_ftruncate(int fd, off_t length);
|
||||
extern int rb_w32_truncate(const char *path, off_t length);
|
||||
|
||||
#undef HAVE_FTRUNCATE
|
||||
#define HAVE_FTRUNCATE 1
|
||||
#if defined HAVE_FTRUNCATE64
|
||||
#define ftruncate ftruncate64
|
||||
#else
|
||||
#define ftruncate rb_w32_ftruncate
|
||||
#endif
|
||||
|
||||
#undef HAVE_TRUNCATE
|
||||
#define HAVE_TRUNCATE 1
|
||||
#if defined HAVE_TRUNCATE64
|
||||
#define truncate truncate64
|
||||
#else
|
||||
#define truncate rb_w32_truncate
|
||||
#endif
|
||||
|
||||
/*
|
||||
* stubs
|
||||
*/
|
||||
extern int ioctl (int, int, ...);
|
||||
extern rb_uid_t getuid (void);
|
||||
extern rb_uid_t geteuid (void);
|
||||
extern rb_gid_t getgid (void);
|
||||
extern rb_gid_t getegid (void);
|
||||
extern int setuid (rb_uid_t);
|
||||
extern int setgid (rb_gid_t);
|
||||
|
||||
extern int fstati64(int, struct stati64 *);
|
||||
|
||||
extern char *rb_w32_strerror(int);
|
||||
|
||||
#ifdef RUBY_EXPORT
|
||||
#define strerror(e) rb_w32_strerror(e)
|
||||
#endif
|
||||
|
||||
#define PIPE_BUF 1024
|
||||
|
||||
#define LOCK_SH 1
|
||||
#define LOCK_EX 2
|
||||
#define LOCK_NB 4
|
||||
#define LOCK_UN 8
|
||||
|
||||
|
||||
#ifndef SIGINT
|
||||
#define SIGINT 2
|
||||
#endif
|
||||
#ifndef SIGKILL
|
||||
#define SIGKILL 9
|
||||
#endif
|
||||
|
||||
|
||||
/* #undef va_start */
|
||||
/* #undef va_end */
|
||||
|
||||
/* winsock error map */
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef EWOULDBLOCK
|
||||
# define EWOULDBLOCK WSAEWOULDBLOCK
|
||||
#endif
|
||||
#ifndef EINPROGRESS
|
||||
# define EINPROGRESS WSAEINPROGRESS
|
||||
#endif
|
||||
#ifndef EALREADY
|
||||
# define EALREADY WSAEALREADY
|
||||
#endif
|
||||
#ifndef ENOTSOCK
|
||||
# define ENOTSOCK WSAENOTSOCK
|
||||
#endif
|
||||
#ifndef EDESTADDRREQ
|
||||
# define EDESTADDRREQ WSAEDESTADDRREQ
|
||||
#endif
|
||||
#ifndef EMSGSIZE
|
||||
# define EMSGSIZE WSAEMSGSIZE
|
||||
#endif
|
||||
#ifndef EPROTOTYPE
|
||||
# define EPROTOTYPE WSAEPROTOTYPE
|
||||
#endif
|
||||
#ifndef ENOPROTOOPT
|
||||
# define ENOPROTOOPT WSAENOPROTOOPT
|
||||
#endif
|
||||
#ifndef EPROTONOSUPPORT
|
||||
# define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
||||
#endif
|
||||
#ifndef ESOCKTNOSUPPORT
|
||||
# define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
||||
#endif
|
||||
#ifndef EOPNOTSUPP
|
||||
# define EOPNOTSUPP WSAEOPNOTSUPP
|
||||
#endif
|
||||
#ifndef EPFNOSUPPORT
|
||||
# define EPFNOSUPPORT WSAEPFNOSUPPORT
|
||||
#endif
|
||||
#ifndef EAFNOSUPPORT
|
||||
# define EAFNOSUPPORT WSAEAFNOSUPPORT
|
||||
#endif
|
||||
#ifndef EADDRINUSE
|
||||
# define EADDRINUSE WSAEADDRINUSE
|
||||
#endif
|
||||
#ifndef EADDRNOTAVAIL
|
||||
# define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
||||
#endif
|
||||
#ifndef ENETDOWN
|
||||
# define ENETDOWN WSAENETDOWN
|
||||
#endif
|
||||
#ifndef ENETUNREACH
|
||||
# define ENETUNREACH WSAENETUNREACH
|
||||
#endif
|
||||
#ifndef ENETRESET
|
||||
# define ENETRESET WSAENETRESET
|
||||
#endif
|
||||
#ifndef ECONNABORTED
|
||||
# define ECONNABORTED WSAECONNABORTED
|
||||
#endif
|
||||
#ifndef ECONNRESET
|
||||
# define ECONNRESET WSAECONNRESET
|
||||
#endif
|
||||
#ifndef ENOBUFS
|
||||
# define ENOBUFS WSAENOBUFS
|
||||
#endif
|
||||
#ifndef EISCONN
|
||||
# define EISCONN WSAEISCONN
|
||||
#endif
|
||||
#ifndef ENOTCONN
|
||||
# define ENOTCONN WSAENOTCONN
|
||||
#endif
|
||||
#ifndef ESHUTDOWN
|
||||
# define ESHUTDOWN WSAESHUTDOWN
|
||||
#endif
|
||||
#ifndef ETOOMANYREFS
|
||||
# define ETOOMANYREFS WSAETOOMANYREFS
|
||||
#endif
|
||||
#ifndef ETIMEDOUT
|
||||
# define ETIMEDOUT WSAETIMEDOUT
|
||||
#endif
|
||||
#ifndef ECONNREFUSED
|
||||
# define ECONNREFUSED WSAECONNREFUSED
|
||||
#endif
|
||||
#ifndef ELOOP
|
||||
# define ELOOP WSAELOOP
|
||||
#endif
|
||||
/*#define ENAMETOOLONG WSAENAMETOOLONG*/
|
||||
#ifndef EHOSTDOWN
|
||||
# define EHOSTDOWN WSAEHOSTDOWN
|
||||
#endif
|
||||
#ifndef EHOSTUNREACH
|
||||
# define EHOSTUNREACH WSAEHOSTUNREACH
|
||||
#endif
|
||||
/*#define ENOTEMPTY WSAENOTEMPTY*/
|
||||
#ifndef EPROCLIM
|
||||
# define EPROCLIM WSAEPROCLIM
|
||||
#endif
|
||||
#ifndef EUSERS
|
||||
# define EUSERS WSAEUSERS
|
||||
#endif
|
||||
#ifndef EDQUOT
|
||||
# define EDQUOT WSAEDQUOT
|
||||
#endif
|
||||
#ifndef ESTALE
|
||||
# define ESTALE WSAESTALE
|
||||
#endif
|
||||
#ifndef EREMOTE
|
||||
# define EREMOTE WSAEREMOTE
|
||||
#endif
|
||||
|
||||
#define F_DUPFD 0
|
||||
#if 0
|
||||
#define F_GETFD 1
|
||||
#define F_SETFD 2
|
||||
#define F_GETFL 3
|
||||
#endif
|
||||
#define F_SETFL 4
|
||||
#if 0
|
||||
#define FD_CLOEXEC 1 /* F_GETFD, F_SETFD */
|
||||
#endif
|
||||
#define O_NONBLOCK 1
|
||||
|
||||
#undef FD_SET
|
||||
#define FD_SET(fd, set) do {\
|
||||
unsigned int i;\
|
||||
SOCKET s = _get_osfhandle(fd);\
|
||||
\
|
||||
for (i = 0; i < (set)->fd_count; i++) {\
|
||||
if ((set)->fd_array[i] == s) {\
|
||||
break;\
|
||||
}\
|
||||
}\
|
||||
if (i == (set)->fd_count) {\
|
||||
if ((set)->fd_count < FD_SETSIZE) {\
|
||||
(set)->fd_array[i] = s;\
|
||||
(set)->fd_count++;\
|
||||
}\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
#undef FD_CLR
|
||||
#define FD_CLR(f, s) rb_w32_fdclr(f, s)
|
||||
|
||||
#undef FD_ISSET
|
||||
#define FD_ISSET(f, s) rb_w32_fdisset(f, s)
|
||||
|
||||
#ifdef RUBY_EXPORT
|
||||
#undef inet_ntop
|
||||
#define inet_ntop(f,a,n,l) rb_w32_inet_ntop(f,a,n,l)
|
||||
|
||||
#undef inet_pton
|
||||
#define inet_pton(f,s,d) rb_w32_inet_pton(f,s,d)
|
||||
|
||||
#undef accept
|
||||
#define accept(s, a, l) rb_w32_accept(s, a, l)
|
||||
|
||||
#undef bind
|
||||
#define bind(s, a, l) rb_w32_bind(s, a, l)
|
||||
|
||||
#undef connect
|
||||
#define connect(s, a, l) rb_w32_connect(s, a, l)
|
||||
|
||||
#undef select
|
||||
#define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t)
|
||||
|
||||
#undef getpeername
|
||||
#define getpeername(s, a, l) rb_w32_getpeername(s, a, l)
|
||||
|
||||
#undef getsockname
|
||||
#define getsockname(s, a, l) rb_w32_getsockname(s, a, l)
|
||||
|
||||
#undef getsockopt
|
||||
#define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l)
|
||||
|
||||
#undef ioctlsocket
|
||||
#define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a)
|
||||
|
||||
#undef listen
|
||||
#define listen(s, b) rb_w32_listen(s, b)
|
||||
|
||||
#undef recv
|
||||
#define recv(s, b, l, f) rb_w32_recv(s, b, l, f)
|
||||
|
||||
#undef recvfrom
|
||||
#define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl)
|
||||
|
||||
#undef send
|
||||
#define send(s, b, l, f) rb_w32_send(s, b, l, f)
|
||||
|
||||
#undef sendto
|
||||
#define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl)
|
||||
|
||||
#undef setsockopt
|
||||
#define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l)
|
||||
|
||||
#undef shutdown
|
||||
#define shutdown(s, h) rb_w32_shutdown(s, h)
|
||||
|
||||
#undef socket
|
||||
#define socket(s, t, p) rb_w32_socket(s, t, p)
|
||||
|
||||
#undef gethostbyaddr
|
||||
#define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t)
|
||||
|
||||
#undef gethostbyname
|
||||
#define gethostbyname(n) rb_w32_gethostbyname(n)
|
||||
|
||||
#undef gethostname
|
||||
#define gethostname(n, l) rb_w32_gethostname(n, l)
|
||||
|
||||
#undef getprotobyname
|
||||
#define getprotobyname(n) rb_w32_getprotobyname(n)
|
||||
|
||||
#undef getprotobynumber
|
||||
#define getprotobynumber(n) rb_w32_getprotobynumber(n)
|
||||
|
||||
#undef getservbyname
|
||||
#define getservbyname(n, p) rb_w32_getservbyname(n, p)
|
||||
|
||||
#undef getservbyport
|
||||
#define getservbyport(p, pr) rb_w32_getservbyport(p, pr)
|
||||
|
||||
#undef get_osfhandle
|
||||
#define get_osfhandle(h) rb_w32_get_osfhandle(h)
|
||||
|
||||
#undef getcwd
|
||||
#define getcwd(b, s) rb_w32_getcwd(b, s)
|
||||
|
||||
#undef getenv
|
||||
#define getenv(n) rb_w32_getenv(n)
|
||||
|
||||
#undef rename
|
||||
#define rename(o, n) rb_w32_rename(o, n)
|
||||
|
||||
#undef times
|
||||
#define times(t) rb_w32_times(t)
|
||||
|
||||
#undef dup2
|
||||
#define dup2(o, n) rb_w32_dup2(o, n)
|
||||
#endif
|
||||
|
||||
struct tms {
|
||||
long tms_utime;
|
||||
long tms_stime;
|
||||
long tms_cutime;
|
||||
long tms_cstime;
|
||||
};
|
||||
|
||||
int rb_w32_times(struct tms *);
|
||||
|
||||
struct tm *gmtime_r(const time_t *, struct tm *);
|
||||
struct tm *localtime_r(const time_t *, struct tm *);
|
||||
|
||||
/* thread stuff */
|
||||
int rb_w32_sleep(unsigned long msec);
|
||||
int rb_w32_putc(int, FILE*);
|
||||
int rb_w32_getc(FILE*);
|
||||
int rb_w32_open(const char *, int, ...);
|
||||
int rb_w32_uopen(const char *, int, ...);
|
||||
int rb_w32_wopen(const WCHAR *, int, ...);
|
||||
int rb_w32_close(int);
|
||||
int rb_w32_fclose(FILE*);
|
||||
int rb_w32_pipe(int[2]);
|
||||
ssize_t rb_w32_read(int, void *, size_t);
|
||||
ssize_t rb_w32_write(int, const void *, size_t);
|
||||
int rb_w32_utime(const char *, const struct utimbuf *);
|
||||
int rb_w32_uutime(const char *, const struct utimbuf *);
|
||||
long rb_w32_write_console(uintptr_t, int); /* use uintptr_t instead of VALUE because it's not defined yet here */
|
||||
int WINAPI rb_w32_Sleep(unsigned long msec);
|
||||
int rb_w32_wait_events_blocking(HANDLE *events, int num, DWORD timeout);
|
||||
int rb_w32_time_subtract(struct timeval *rest, const struct timeval *wait);
|
||||
int rb_w32_wrap_io_handle(HANDLE, int);
|
||||
int rb_w32_unwrap_io_handle(int);
|
||||
WCHAR *rb_w32_mbstr_to_wstr(UINT, const char *, int, long *);
|
||||
char *rb_w32_wstr_to_mbstr(UINT, const WCHAR *, int, long *);
|
||||
|
||||
/*
|
||||
== ***CAUTION***
|
||||
Since this function is very dangerous, ((*NEVER*))
|
||||
* lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or,
|
||||
* use anything like TRAP_BEG...TRAP_END block structure,
|
||||
in asynchronous_func_t.
|
||||
*/
|
||||
typedef uintptr_t (*asynchronous_func_t)(uintptr_t self, int argc, uintptr_t* argv);
|
||||
uintptr_t rb_w32_asynchronize(asynchronous_func_t func, uintptr_t self, int argc, uintptr_t* argv, uintptr_t intrval);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
||||
#ifdef __MINGW_ATTRIB_PURE
|
||||
/* License: Ruby's */
|
||||
/* get rid of bugs in math.h of mingw */
|
||||
#define frexp(_X, _Y) __extension__ ({\
|
||||
int intpart_frexp_bug = intpart_frexp_bug;\
|
||||
double result_frexp_bug = frexp((_X), &intpart_frexp_bug);\
|
||||
*(_Y) = intpart_frexp_bug;\
|
||||
result_frexp_bug;\
|
||||
})
|
||||
/* License: Ruby's */
|
||||
#define modf(_X, _Y) __extension__ ({\
|
||||
double intpart_modf_bug = intpart_modf_bug;\
|
||||
double result_modf_bug = modf((_X), &intpart_modf_bug);\
|
||||
*(_Y) = intpart_modf_bug;\
|
||||
result_modf_bug;\
|
||||
})
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#if 0
|
||||
{ /* satisfy cc-mode */
|
||||
#endif
|
||||
} /* extern "C" { */
|
||||
#endif
|
||||
|
||||
#if defined(__MINGW64__)
|
||||
/*
|
||||
* Use powl() instead of broken pow() of x86_64-w64-mingw32.
|
||||
* This workaround will fix test failures in test_bignum.rb,
|
||||
* test_fixnum.rb and test_float.rb etc.
|
||||
*/
|
||||
static inline double
|
||||
rb_w32_pow(double x, double y)
|
||||
{
|
||||
return powl(x, y);
|
||||
}
|
||||
#elif defined(__MINGW64_VERSION_MAJOR)
|
||||
double rb_w32_pow(double x, double y);
|
||||
#endif
|
||||
#if defined(__MINGW64_VERSION_MAJOR) || defined(__MINGW64__)
|
||||
#define pow rb_w32_pow
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_WIN32_H */
|
||||
BIN
ruby/lib/libmsvcrt-ruby210-static.a
Normal file
BIN
ruby/lib/libmsvcrt-ruby210-static.a
Normal file
Binary file not shown.
BIN
ruby/lib/libmsvcrt-ruby210.dll.a
Normal file
BIN
ruby/lib/libmsvcrt-ruby210.dll.a
Normal file
Binary file not shown.
56
ruby/lib/pkgconfig/ruby-2.1.pc
Normal file
56
ruby/lib/pkgconfig/ruby-2.1.pc
Normal file
@@ -0,0 +1,56 @@
|
||||
arch=i386-mingw32
|
||||
sitearch=i386-msvcrt
|
||||
prefix=C:/Users/Luis/Code/oneclick/rubyinstaller/sandbox/ruby21_mingw
|
||||
exec_prefix=${prefix}
|
||||
bindir=${exec_prefix}/bin
|
||||
libdir=${exec_prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
MAJOR=2
|
||||
MINOR=1
|
||||
TEENY=0
|
||||
ruby_version=2.1.0
|
||||
RUBY_PROGRAM_VERSION=2.1.3
|
||||
RUBY_BASE_NAME=ruby
|
||||
RUBY_VERSION_NAME=${RUBY_BASE_NAME}-${ruby_version}
|
||||
RUBY_SO_NAME=msvcrt-${RUBY_BASE_NAME}${MAJOR}${MINOR}${TEENY}
|
||||
RUBY_INSTALL_NAME=${RUBY_BASE_NAME}
|
||||
DEFFILE=
|
||||
archlibdir=${libdir}/${arch}
|
||||
sitearchlibdir=${libdir}/${sitearch}
|
||||
archincludedir=${includedir}/${arch}
|
||||
sitearchincludedir=${includedir}/${sitearch}
|
||||
ruby=${bindir}/${RUBY_INSTALL_NAME}.exe
|
||||
rubylibprefix=${libdir}/${RUBY_BASE_NAME}
|
||||
rubyarchprefix=${rubylibprefix}/${arch}
|
||||
rubysitearchprefix=${rubylibprefix}/${sitearch}
|
||||
rubylibdir=${rubylibprefix}/${ruby_version}
|
||||
vendordir=${rubylibprefix}/vendor_ruby
|
||||
sitedir=${rubylibprefix}/site_ruby
|
||||
vendorlibdir=${vendordir}/${ruby_version}
|
||||
sitelibdir=${sitedir}/${ruby_version}
|
||||
rubyarchdir=${rubylibdir}/${arch}
|
||||
vendorarchdir=${vendorlibdir}/${sitearch}
|
||||
sitearchdir=${sitelibdir}/${sitearch}
|
||||
rubyhdrdir=${includedir}/${RUBY_VERSION_NAME}
|
||||
vendorhdrdir=${rubyhdrdir}/vendor_ruby
|
||||
sitehdrdir=${rubyhdrdir}/site_ruby
|
||||
rubyarchhdrdir=${rubyhdrdir}/${arch}
|
||||
vendorarchhdrdir=${vendorhdrdir}/${sitearch}
|
||||
sitearchhdrdir=${sitehdrdir}/${sitearch}
|
||||
LIBPATH=
|
||||
LIBRUBY_A=lib${RUBY_SO_NAME}-static.a
|
||||
LIBRUBY_SO=${RUBY_SO_NAME}.dll
|
||||
LIBRUBY=lib${RUBY_SO_NAME}.dll.a
|
||||
LIBRUBYARG_SHARED=-l${RUBY_SO_NAME}
|
||||
LIBRUBYARG_STATIC=-l${RUBY_SO_NAME}-static
|
||||
LIBRUBYARG=${LIBRUBYARG_SHARED}
|
||||
LIBS=-lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi
|
||||
DLDFLAGS= -Wl,--enable-auto-image-base,--enable-auto-import ${DEFFILE}
|
||||
|
||||
Name: Ruby
|
||||
Description: Object Oriented Script Language
|
||||
Version: ${ruby_version}
|
||||
URL: http://www.ruby-lang.org
|
||||
Cflags: -I${rubyarchhdrdir} -I${rubyhdrdir}
|
||||
Libs: ${DLDFLAGS} ${LIBRUBYARG_SHARED} ${LIBS}
|
||||
Requires:
|
||||
185
ruby/lib/ruby/2.1.0/English.rb
Normal file
185
ruby/lib/ruby/2.1.0/English.rb
Normal file
@@ -0,0 +1,185 @@
|
||||
# Include the English library file in a Ruby script, and you can
|
||||
# reference the global variables such as \VAR{\$\_} using less
|
||||
# cryptic names, listed in the following table.% \vref{tab:english}.
|
||||
#
|
||||
# Without 'English':
|
||||
#
|
||||
# $\ = ' -- '
|
||||
# "waterbuffalo" =~ /buff/
|
||||
# print $", $', $$, "\n"
|
||||
#
|
||||
# With English:
|
||||
#
|
||||
# require "English"
|
||||
#
|
||||
# $OUTPUT_FIELD_SEPARATOR = ' -- '
|
||||
# "waterbuffalo" =~ /buff/
|
||||
# print $LOADED_FEATURES, $POSTMATCH, $PID, "\n"
|
||||
#
|
||||
# Below is a full list of descriptive aliases and their associated global
|
||||
# variable:
|
||||
#
|
||||
# $ERROR_INFO:: $!
|
||||
# $ERROR_POSITION:: $@
|
||||
# $FS:: $;
|
||||
# $FIELD_SEPARATOR:: $;
|
||||
# $OFS:: $,
|
||||
# $OUTPUT_FIELD_SEPARATOR:: $,
|
||||
# $RS:: $/
|
||||
# $INPUT_RECORD_SEPARATOR:: $/
|
||||
# $ORS:: $\
|
||||
# $OUTPUT_RECORD_SEPARATOR:: $\
|
||||
# $INPUT_LINE_NUMBER:: $.
|
||||
# $NR:: $.
|
||||
# $LAST_READ_LINE:: $_
|
||||
# $DEFAULT_OUTPUT:: $>
|
||||
# $DEFAULT_INPUT:: $<
|
||||
# $PID:: $$
|
||||
# $PROCESS_ID:: $$
|
||||
# $CHILD_STATUS:: $?
|
||||
# $LAST_MATCH_INFO:: $~
|
||||
# $IGNORECASE:: $=
|
||||
# $ARGV:: $*
|
||||
# $MATCH:: $&
|
||||
# $PREMATCH:: $`
|
||||
# $POSTMATCH:: $'
|
||||
# $LAST_PAREN_MATCH:: $+
|
||||
#
|
||||
module English end if false
|
||||
|
||||
# The exception object passed to +raise+.
|
||||
alias $ERROR_INFO $!
|
||||
|
||||
# The stack backtrace generated by the last
|
||||
# exception. <tt>See Kernel.caller</tt> for details. Thread local.
|
||||
alias $ERROR_POSITION $@
|
||||
|
||||
# The default separator pattern used by <tt>String.split</tt>. May be
|
||||
# set from the command line using the <tt>-F</tt> flag.
|
||||
alias $FS $;
|
||||
|
||||
# The default separator pattern used by <tt>String.split</tt>. May be
|
||||
# set from the command line using the <tt>-F</tt> flag.
|
||||
alias $FIELD_SEPARATOR $;
|
||||
|
||||
# The separator string output between the parameters to methods such
|
||||
# as <tt>Kernel.print</tt> and <tt>Array.join</tt>. Defaults to +nil+,
|
||||
# which adds no text.
|
||||
alias $OFS $,
|
||||
|
||||
# The separator string output between the parameters to methods such
|
||||
# as <tt>Kernel.print</tt> and <tt>Array.join</tt>. Defaults to +nil+,
|
||||
# which adds no text.
|
||||
alias $OUTPUT_FIELD_SEPARATOR $,
|
||||
|
||||
# The input record separator (newline by default). This is the value
|
||||
# that routines such as <tt>Kernel.gets</tt> use to determine record
|
||||
# boundaries. If set to +nil+, +gets+ will read the entire file.
|
||||
alias $RS $/
|
||||
|
||||
# The input record separator (newline by default). This is the value
|
||||
# that routines such as <tt>Kernel.gets</tt> use to determine record
|
||||
# boundaries. If set to +nil+, +gets+ will read the entire file.
|
||||
alias $INPUT_RECORD_SEPARATOR $/
|
||||
|
||||
# The string appended to the output of every call to methods such as
|
||||
# <tt>Kernel.print</tt> and <tt>IO.write</tt>. The default value is
|
||||
# +nil+.
|
||||
alias $ORS $\
|
||||
|
||||
# The string appended to the output of every call to methods such as
|
||||
# <tt>Kernel.print</tt> and <tt>IO.write</tt>. The default value is
|
||||
# +nil+.
|
||||
alias $OUTPUT_RECORD_SEPARATOR $\
|
||||
|
||||
# The number of the last line read from the current input file.
|
||||
alias $INPUT_LINE_NUMBER $.
|
||||
|
||||
# The number of the last line read from the current input file.
|
||||
alias $NR $.
|
||||
|
||||
# The last line read by <tt>Kernel.gets</tt> or
|
||||
# <tt>Kernel.readline</tt>. Many string-related functions in the
|
||||
# +Kernel+ module operate on <tt>$_</tt> by default. The variable is
|
||||
# local to the current scope. Thread local.
|
||||
alias $LAST_READ_LINE $_
|
||||
|
||||
# The destination of output for <tt>Kernel.print</tt>
|
||||
# and <tt>Kernel.printf</tt>. The default value is
|
||||
# <tt>$stdout</tt>.
|
||||
alias $DEFAULT_OUTPUT $>
|
||||
|
||||
# An object that provides access to the concatenation
|
||||
# of the contents of all the files
|
||||
# given as command-line arguments, or <tt>$stdin</tt>
|
||||
# (in the case where there are no
|
||||
# arguments). <tt>$<</tt> supports methods similar to a
|
||||
# +File+ object:
|
||||
# +inmode+, +close+,
|
||||
# <tt>closed?</tt>, +each+,
|
||||
# <tt>each_byte</tt>, <tt>each_line</tt>,
|
||||
# +eof+, <tt>eof?</tt>, +file+,
|
||||
# +filename+, +fileno+,
|
||||
# +getc+, +gets+, +lineno+,
|
||||
# <tt>lineno=</tt>, +path+,
|
||||
# +pos+, <tt>pos=</tt>,
|
||||
# +read+, +readchar+,
|
||||
# +readline+, +readlines+,
|
||||
# +rewind+, +seek+, +skip+,
|
||||
# +tell+, <tt>to_a</tt>, <tt>to_i</tt>,
|
||||
# <tt>to_io</tt>, <tt>to_s</tt>, along with the
|
||||
# methods in +Enumerable+. The method +file+
|
||||
# returns a +File+ object for the file currently
|
||||
# being read. This may change as <tt>$<</tt> reads
|
||||
# through the files on the command line. Read only.
|
||||
alias $DEFAULT_INPUT $<
|
||||
|
||||
# The process number of the program being executed. Read only.
|
||||
alias $PID $$
|
||||
|
||||
# The process number of the program being executed. Read only.
|
||||
alias $PROCESS_ID $$
|
||||
|
||||
# The exit status of the last child process to terminate. Read
|
||||
# only. Thread local.
|
||||
alias $CHILD_STATUS $?
|
||||
|
||||
# A +MatchData+ object that encapsulates the results of a successful
|
||||
# pattern match. The variables <tt>$&</tt>, <tt>$`</tt>, <tt>$'</tt>,
|
||||
# and <tt>$1</tt> to <tt>$9</tt> are all derived from
|
||||
# <tt>$~</tt>. Assigning to <tt>$~</tt> changes the values of these
|
||||
# derived variables. This variable is local to the current
|
||||
# scope.
|
||||
alias $LAST_MATCH_INFO $~
|
||||
|
||||
# If set to any value apart from +nil+ or +false+, all pattern matches
|
||||
# will be case insensitive, string comparisons will ignore case, and
|
||||
# string hash values will be case insensitive. Deprecated
|
||||
alias $IGNORECASE $=
|
||||
|
||||
# An array of strings containing the command-line
|
||||
# options from the invocation of the program. Options
|
||||
# used by the Ruby interpreter will have been
|
||||
# removed. Read only. Also known simply as +ARGV+.
|
||||
alias $ARGV $*
|
||||
|
||||
# The string matched by the last successful pattern
|
||||
# match. This variable is local to the current
|
||||
# scope. Read only.
|
||||
alias $MATCH $&
|
||||
|
||||
# The string preceding the match in the last
|
||||
# successful pattern match. This variable is local to
|
||||
# the current scope. Read only.
|
||||
alias $PREMATCH $`
|
||||
|
||||
# The string following the match in the last
|
||||
# successful pattern match. This variable is local to
|
||||
# the current scope. Read only.
|
||||
alias $POSTMATCH $'
|
||||
|
||||
# The contents of the highest-numbered group matched in the last
|
||||
# successful pattern match. Thus, in <tt>"cat" =~ /(c|a)(t|z)/</tt>,
|
||||
# <tt>$+</tt> will be set to "t". This variable is local to the
|
||||
# current scope. Read only.
|
||||
alias $LAST_PAREN_MATCH $+
|
||||
31
ruby/lib/ruby/2.1.0/Win32API.rb
Normal file
31
ruby/lib/ruby/2.1.0/Win32API.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- ruby -*-
|
||||
# for backward compatibility
|
||||
warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: Win32API is deprecated after Ruby 1.9.1; use dl directly instead" if $VERBOSE
|
||||
|
||||
require 'dl'
|
||||
|
||||
class Win32API
|
||||
DLL = {}
|
||||
TYPEMAP = {"0" => DL::TYPE_VOID, "S" => DL::TYPE_VOIDP, "I" => DL::TYPE_LONG}
|
||||
POINTER_TYPE = DL::SIZEOF_VOIDP == DL::SIZEOF_LONG_LONG ? 'q*' : 'l!*'
|
||||
|
||||
def initialize(dllname, func, import, export = "0", calltype = :stdcall)
|
||||
@proto = [import].join.tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
|
||||
handle = DLL[dllname] ||= DL.dlopen(dllname)
|
||||
@func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, calltype)
|
||||
rescue DL::DLError => e
|
||||
raise LoadError, e.message, e.backtrace
|
||||
end
|
||||
|
||||
def call(*args)
|
||||
import = @proto.split("")
|
||||
args.each_with_index do |x, i|
|
||||
args[i], = [x == 0 ? nil : x].pack("p").unpack(POINTER_TYPE) if import[i] == "S"
|
||||
args[i], = [x].pack("I").unpack("i") if import[i] == "I"
|
||||
end
|
||||
ret, = @func.call(args)
|
||||
return ret || 0
|
||||
end
|
||||
|
||||
alias Call call
|
||||
end
|
||||
136
ruby/lib/ruby/2.1.0/abbrev.rb
Normal file
136
ruby/lib/ruby/2.1.0/abbrev.rb
Normal file
@@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env ruby
|
||||
#--
|
||||
# Copyright (c) 2001,2003 Akinori MUSHA <knu@iDaemons.org>
|
||||
#
|
||||
# All rights reserved. You can redistribute and/or modify it under
|
||||
# the same terms as Ruby.
|
||||
#
|
||||
# $Idaemons: /home/cvs/rb/abbrev.rb,v 1.2 2001/05/30 09:37:45 knu Exp $
|
||||
# $RoughId: abbrev.rb,v 1.4 2003/10/14 19:45:42 knu Exp $
|
||||
# $Id: abbrev.rb 39362 2013-02-21 17:35:32Z zzak $
|
||||
#++
|
||||
|
||||
##
|
||||
# Calculates the set of unique abbreviations for a given set of strings.
|
||||
#
|
||||
# require 'abbrev'
|
||||
# require 'pp'
|
||||
#
|
||||
# pp Abbrev.abbrev(['ruby', 'rules'])
|
||||
#
|
||||
# Generates:
|
||||
#
|
||||
# { "rub" => "ruby",
|
||||
# "ruby" => "ruby",
|
||||
# "rul" => "rules",
|
||||
# "rule" => "rules",
|
||||
# "rules" => "rules" }
|
||||
#
|
||||
# It also provides an array core extension, Array#abbrev.
|
||||
#
|
||||
# pp %w{summer winter}.abbrev
|
||||
# #=> {"summe"=>"summer",
|
||||
# "summ"=>"summer",
|
||||
# "sum"=>"summer",
|
||||
# "su"=>"summer",
|
||||
# "s"=>"summer",
|
||||
# "winte"=>"winter",
|
||||
# "wint"=>"winter",
|
||||
# "win"=>"winter",
|
||||
# "wi"=>"winter",
|
||||
# "w"=>"winter",
|
||||
# "summer"=>"summer",
|
||||
# "winter"=>"winter"}
|
||||
|
||||
module Abbrev
|
||||
|
||||
# Given a set of strings, calculate the set of unambiguous
|
||||
# abbreviations for those strings, and return a hash where the keys
|
||||
# are all the possible abbreviations and the values are the full
|
||||
# strings.
|
||||
#
|
||||
# Thus, given +words+ is "car" and "cone", the keys pointing to "car" would
|
||||
# be "ca" and "car", while those pointing to "cone" would be "co", "con", and
|
||||
# "cone".
|
||||
#
|
||||
# require 'abbrev'
|
||||
#
|
||||
# Abbrev.abbrev(['car', 'cone'])
|
||||
# #=> {"ca"=>"car", "con"=>"cone", "co"=>"cone", "car"=>"car", "cone"=>"cone"}
|
||||
#
|
||||
# The optional +pattern+ parameter is a pattern or a string. Only
|
||||
# input strings that match the pattern or start with the string
|
||||
# are included in the output hash.
|
||||
#
|
||||
# Abbrev.abbrev(%w{car box cone}, /b/)
|
||||
# #=> {"bo"=>"box", "b"=>"box", "box"=>"box"}
|
||||
def abbrev(words, pattern = nil)
|
||||
table = {}
|
||||
seen = Hash.new(0)
|
||||
|
||||
if pattern.is_a?(String)
|
||||
pattern = /\A#{Regexp.quote(pattern)}/ # regard as a prefix
|
||||
end
|
||||
|
||||
words.each do |word|
|
||||
next if word.empty?
|
||||
word.size.downto(1) { |len|
|
||||
abbrev = word[0...len]
|
||||
|
||||
next if pattern && pattern !~ abbrev
|
||||
|
||||
case seen[abbrev] += 1
|
||||
when 1
|
||||
table[abbrev] = word
|
||||
when 2
|
||||
table.delete(abbrev)
|
||||
else
|
||||
break
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
words.each do |word|
|
||||
next if pattern && pattern !~ word
|
||||
|
||||
table[word] = word
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
module_function :abbrev
|
||||
end
|
||||
|
||||
class Array
|
||||
# Calculates the set of unambiguous abbreviations for the strings in
|
||||
# +self+.
|
||||
#
|
||||
# require 'abbrev'
|
||||
# %w{ car cone }.abbrev
|
||||
# #=> {"ca" => "car", "con"=>"cone", "co" => "cone",
|
||||
# "car"=>"car", "cone" => "cone"}
|
||||
#
|
||||
# The optional +pattern+ parameter is a pattern or a string. Only
|
||||
# input strings that match the pattern or start with the string
|
||||
# are included in the output hash.
|
||||
#
|
||||
# %w{ fast boat day }.abbrev(/^.a/)
|
||||
# #=> {"fas"=>"fast", "fa"=>"fast", "da"=>"day",
|
||||
# "fast"=>"fast", "day"=>"day"}
|
||||
#
|
||||
# See also Abbrev.abbrev
|
||||
def abbrev(pattern = nil)
|
||||
Abbrev::abbrev(self, pattern)
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
while line = gets
|
||||
hash = line.split.abbrev
|
||||
|
||||
hash.sort.each do |k, v|
|
||||
puts "#{k} => #{v}"
|
||||
end
|
||||
end
|
||||
end
|
||||
91
ruby/lib/ruby/2.1.0/base64.rb
Normal file
91
ruby/lib/ruby/2.1.0/base64.rb
Normal file
@@ -0,0 +1,91 @@
|
||||
#
|
||||
# = base64.rb: methods for base64-encoding and -decoding strings
|
||||
#
|
||||
|
||||
# The Base64 module provides for the encoding (#encode64, #strict_encode64,
|
||||
# #urlsafe_encode64) and decoding (#decode64, #strict_decode64,
|
||||
# #urlsafe_decode64) of binary data using a Base64 representation.
|
||||
#
|
||||
# == Example
|
||||
#
|
||||
# A simple encoding and decoding.
|
||||
#
|
||||
# require "base64"
|
||||
#
|
||||
# enc = Base64.encode64('Send reinforcements')
|
||||
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
||||
# plain = Base64.decode64(enc)
|
||||
# # -> "Send reinforcements"
|
||||
#
|
||||
# The purpose of using base64 to encode data is that it translates any
|
||||
# binary data into purely printable characters.
|
||||
|
||||
module Base64
|
||||
module_function
|
||||
|
||||
# Returns the Base64-encoded version of +bin+.
|
||||
# This method complies with RFC 2045.
|
||||
# Line feeds are added to every 60 encoded characters.
|
||||
#
|
||||
# require 'base64'
|
||||
# Base64.encode64("Now is the time for all good coders\nto learn Ruby")
|
||||
#
|
||||
# <i>Generates:</i>
|
||||
#
|
||||
# Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g
|
||||
# UnVieQ==
|
||||
def encode64(bin)
|
||||
[bin].pack("m")
|
||||
end
|
||||
|
||||
# Returns the Base64-decoded version of +str+.
|
||||
# This method complies with RFC 2045.
|
||||
# Characters outside the base alphabet are ignored.
|
||||
#
|
||||
# require 'base64'
|
||||
# str = 'VGhpcyBpcyBsaW5lIG9uZQpUaGlzIG' +
|
||||
# 'lzIGxpbmUgdHdvClRoaXMgaXMgbGlu' +
|
||||
# 'ZSB0aHJlZQpBbmQgc28gb24uLi4K'
|
||||
# puts Base64.decode64(str)
|
||||
#
|
||||
# <i>Generates:</i>
|
||||
#
|
||||
# This is line one
|
||||
# This is line two
|
||||
# This is line three
|
||||
# And so on...
|
||||
def decode64(str)
|
||||
str.unpack("m").first
|
||||
end
|
||||
|
||||
# Returns the Base64-encoded version of +bin+.
|
||||
# This method complies with RFC 4648.
|
||||
# No line feeds are added.
|
||||
def strict_encode64(bin)
|
||||
[bin].pack("m0")
|
||||
end
|
||||
|
||||
# Returns the Base64-decoded version of +str+.
|
||||
# This method complies with RFC 4648.
|
||||
# ArgumentError is raised if +str+ is incorrectly padded or contains
|
||||
# non-alphabet characters. Note that CR or LF are also rejected.
|
||||
def strict_decode64(str)
|
||||
str.unpack("m0").first
|
||||
end
|
||||
|
||||
# Returns the Base64-encoded version of +bin+.
|
||||
# This method complies with ``Base 64 Encoding with URL and Filename Safe
|
||||
# Alphabet'' in RFC 4648.
|
||||
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
|
||||
def urlsafe_encode64(bin)
|
||||
strict_encode64(bin).tr("+/", "-_")
|
||||
end
|
||||
|
||||
# Returns the Base64-decoded version of +str+.
|
||||
# This method complies with ``Base 64 Encoding with URL and Filename Safe
|
||||
# Alphabet'' in RFC 4648.
|
||||
# The alphabet uses '-' instead of '+' and '_' instead of '/'.
|
||||
def urlsafe_decode64(str)
|
||||
strict_decode64(str.tr("-_", "+/"))
|
||||
end
|
||||
end
|
||||
568
ruby/lib/ruby/2.1.0/benchmark.rb
Normal file
568
ruby/lib/ruby/2.1.0/benchmark.rb
Normal file
@@ -0,0 +1,568 @@
|
||||
#--
|
||||
# benchmark.rb - a performance benchmarking library
|
||||
#
|
||||
# $Id: benchmark.rb 43002 2013-09-20 16:05:48Z zzak $
|
||||
#
|
||||
# Created by Gotoken (gotoken@notwork.org).
|
||||
#
|
||||
# Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
|
||||
# Gavin Sinclair (editing).
|
||||
#++
|
||||
#
|
||||
# == Overview
|
||||
#
|
||||
# The Benchmark module provides methods for benchmarking Ruby code, giving
|
||||
# detailed reports on the time taken for each task.
|
||||
#
|
||||
|
||||
# The Benchmark module provides methods to measure and report the time
|
||||
# used to execute Ruby code.
|
||||
#
|
||||
# * Measure the time to construct the string given by the expression
|
||||
# <code>"a"*1_000_000_000</code>:
|
||||
#
|
||||
# require 'benchmark'
|
||||
#
|
||||
# puts Benchmark.measure { "a"*1_000_000_000 }
|
||||
#
|
||||
# On my machine (OSX 10.8.3 on i5 1.7 Ghz) this generates:
|
||||
#
|
||||
# 0.350000 0.400000 0.750000 ( 0.835234)
|
||||
#
|
||||
# This report shows the user CPU time, system CPU time, the sum of
|
||||
# the user and system CPU times, and the elapsed real time. The unit
|
||||
# of time is seconds.
|
||||
#
|
||||
# * Do some experiments sequentially using the #bm method:
|
||||
#
|
||||
# require 'benchmark'
|
||||
#
|
||||
# n = 5000000
|
||||
# Benchmark.bm do |x|
|
||||
# x.report { for i in 1..n; a = "1"; end }
|
||||
# x.report { n.times do ; a = "1"; end }
|
||||
# x.report { 1.upto(n) do ; a = "1"; end }
|
||||
# end
|
||||
#
|
||||
# The result:
|
||||
#
|
||||
# user system total real
|
||||
# 1.010000 0.000000 1.010000 ( 1.014479)
|
||||
# 1.000000 0.000000 1.000000 ( 0.998261)
|
||||
# 0.980000 0.000000 0.980000 ( 0.981335)
|
||||
#
|
||||
# * Continuing the previous example, put a label in each report:
|
||||
#
|
||||
# require 'benchmark'
|
||||
#
|
||||
# n = 5000000
|
||||
# Benchmark.bm(7) do |x|
|
||||
# x.report("for:") { for i in 1..n; a = "1"; end }
|
||||
# x.report("times:") { n.times do ; a = "1"; end }
|
||||
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||
# end
|
||||
#
|
||||
# The result:
|
||||
#
|
||||
# user system total real
|
||||
# for: 1.010000 0.000000 1.010000 ( 1.015688)
|
||||
# times: 1.000000 0.000000 1.000000 ( 1.003611)
|
||||
# upto: 1.030000 0.000000 1.030000 ( 1.028098)
|
||||
#
|
||||
# * The times for some benchmarks depend on the order in which items
|
||||
# are run. These differences are due to the cost of memory
|
||||
# allocation and garbage collection. To avoid these discrepancies,
|
||||
# the #bmbm method is provided. For example, to compare ways to
|
||||
# sort an array of floats:
|
||||
#
|
||||
# require 'benchmark'
|
||||
#
|
||||
# array = (1..1000000).map { rand }
|
||||
#
|
||||
# Benchmark.bmbm do |x|
|
||||
# x.report("sort!") { array.dup.sort! }
|
||||
# x.report("sort") { array.dup.sort }
|
||||
# end
|
||||
#
|
||||
# The result:
|
||||
#
|
||||
# Rehearsal -----------------------------------------
|
||||
# sort! 1.490000 0.010000 1.500000 ( 1.490520)
|
||||
# sort 1.460000 0.000000 1.460000 ( 1.463025)
|
||||
# -------------------------------- total: 2.960000sec
|
||||
#
|
||||
# user system total real
|
||||
# sort! 1.460000 0.000000 1.460000 ( 1.460465)
|
||||
# sort 1.450000 0.010000 1.460000 ( 1.448327)
|
||||
#
|
||||
# * Report statistics of sequential experiments with unique labels,
|
||||
# using the #benchmark method:
|
||||
#
|
||||
# require 'benchmark'
|
||||
# include Benchmark # we need the CAPTION and FORMAT constants
|
||||
#
|
||||
# n = 5000000
|
||||
# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
|
||||
# tf = x.report("for:") { for i in 1..n; a = "1"; end }
|
||||
# tt = x.report("times:") { n.times do ; a = "1"; end }
|
||||
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||
# [tf+tt+tu, (tf+tt+tu)/3]
|
||||
# end
|
||||
#
|
||||
# The result:
|
||||
#
|
||||
# user system total real
|
||||
# for: 0.950000 0.000000 0.950000 ( 0.952039)
|
||||
# times: 0.980000 0.000000 0.980000 ( 0.984938)
|
||||
# upto: 0.950000 0.000000 0.950000 ( 0.946787)
|
||||
# >total: 2.880000 0.000000 2.880000 ( 2.883764)
|
||||
# >avg: 0.960000 0.000000 0.960000 ( 0.961255)
|
||||
|
||||
module Benchmark
|
||||
|
||||
BENCHMARK_VERSION = "2002-04-25" # :nodoc:
|
||||
|
||||
# Invokes the block with a Benchmark::Report object, which
|
||||
# may be used to collect and report on the results of individual
|
||||
# benchmark tests. Reserves +label_width+ leading spaces for
|
||||
# labels on each line. Prints +caption+ at the top of the
|
||||
# report, and uses +format+ to format each line.
|
||||
# Returns an array of Benchmark::Tms objects.
|
||||
#
|
||||
# If the block returns an array of
|
||||
# Benchmark::Tms objects, these will be used to format
|
||||
# additional lines of output. If +label+ parameters are
|
||||
# given, these are used to label these extra lines.
|
||||
#
|
||||
# _Note_: Other methods provide a simpler interface to this one, and are
|
||||
# suitable for nearly all benchmarking requirements. See the examples in
|
||||
# Benchmark, and the #bm and #bmbm methods.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# require 'benchmark'
|
||||
# include Benchmark # we need the CAPTION and FORMAT constants
|
||||
#
|
||||
# n = 5000000
|
||||
# Benchmark.benchmark(CAPTION, 7, FORMAT, ">total:", ">avg:") do |x|
|
||||
# tf = x.report("for:") { for i in 1..n; a = "1"; end }
|
||||
# tt = x.report("times:") { n.times do ; a = "1"; end }
|
||||
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||
# [tf+tt+tu, (tf+tt+tu)/3]
|
||||
# end
|
||||
#
|
||||
# Generates:
|
||||
#
|
||||
# user system total real
|
||||
# for: 0.970000 0.000000 0.970000 ( 0.970493)
|
||||
# times: 0.990000 0.000000 0.990000 ( 0.989542)
|
||||
# upto: 0.970000 0.000000 0.970000 ( 0.972854)
|
||||
# >total: 2.930000 0.000000 2.930000 ( 2.932889)
|
||||
# >avg: 0.976667 0.000000 0.976667 ( 0.977630)
|
||||
#
|
||||
|
||||
def benchmark(caption = "", label_width = nil, format = nil, *labels) # :yield: report
|
||||
sync = STDOUT.sync
|
||||
STDOUT.sync = true
|
||||
label_width ||= 0
|
||||
label_width += 1
|
||||
format ||= FORMAT
|
||||
print ' '*label_width + caption unless caption.empty?
|
||||
report = Report.new(label_width, format)
|
||||
results = yield(report)
|
||||
Array === results and results.grep(Tms).each {|t|
|
||||
print((labels.shift || t.label || "").ljust(label_width), t.format(format))
|
||||
}
|
||||
report.list
|
||||
ensure
|
||||
STDOUT.sync = sync unless sync.nil?
|
||||
end
|
||||
|
||||
|
||||
# A simple interface to the #benchmark method, #bm generates sequential
|
||||
# reports with labels. The parameters have the same meaning as for
|
||||
# #benchmark.
|
||||
#
|
||||
# require 'benchmark'
|
||||
#
|
||||
# n = 5000000
|
||||
# Benchmark.bm(7) do |x|
|
||||
# x.report("for:") { for i in 1..n; a = "1"; end }
|
||||
# x.report("times:") { n.times do ; a = "1"; end }
|
||||
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||
# end
|
||||
#
|
||||
# Generates:
|
||||
#
|
||||
# user system total real
|
||||
# for: 0.960000 0.000000 0.960000 ( 0.957966)
|
||||
# times: 0.960000 0.000000 0.960000 ( 0.960423)
|
||||
# upto: 0.950000 0.000000 0.950000 ( 0.954864)
|
||||
#
|
||||
|
||||
def bm(label_width = 0, *labels, &blk) # :yield: report
|
||||
benchmark(CAPTION, label_width, FORMAT, *labels, &blk)
|
||||
end
|
||||
|
||||
|
||||
# Sometimes benchmark results are skewed because code executed
|
||||
# earlier encounters different garbage collection overheads than
|
||||
# that run later. #bmbm attempts to minimize this effect by running
|
||||
# the tests twice, the first time as a rehearsal in order to get the
|
||||
# runtime environment stable, the second time for
|
||||
# real. GC.start is executed before the start of each of
|
||||
# the real timings; the cost of this is not included in the
|
||||
# timings. In reality, though, there's only so much that #bmbm can
|
||||
# do, and the results are not guaranteed to be isolated from garbage
|
||||
# collection and other effects.
|
||||
#
|
||||
# Because #bmbm takes two passes through the tests, it can
|
||||
# calculate the required label width.
|
||||
#
|
||||
# require 'benchmark'
|
||||
#
|
||||
# array = (1..1000000).map { rand }
|
||||
#
|
||||
# Benchmark.bmbm do |x|
|
||||
# x.report("sort!") { array.dup.sort! }
|
||||
# x.report("sort") { array.dup.sort }
|
||||
# end
|
||||
#
|
||||
# Generates:
|
||||
#
|
||||
# Rehearsal -----------------------------------------
|
||||
# sort! 1.440000 0.010000 1.450000 ( 1.446833)
|
||||
# sort 1.440000 0.000000 1.440000 ( 1.448257)
|
||||
# -------------------------------- total: 2.890000sec
|
||||
#
|
||||
# user system total real
|
||||
# sort! 1.460000 0.000000 1.460000 ( 1.458065)
|
||||
# sort 1.450000 0.000000 1.450000 ( 1.455963)
|
||||
#
|
||||
# #bmbm yields a Benchmark::Job object and returns an array of
|
||||
# Benchmark::Tms objects.
|
||||
#
|
||||
def bmbm(width = 0) # :yield: job
|
||||
job = Job.new(width)
|
||||
yield(job)
|
||||
width = job.width + 1
|
||||
sync = STDOUT.sync
|
||||
STDOUT.sync = true
|
||||
|
||||
# rehearsal
|
||||
puts 'Rehearsal '.ljust(width+CAPTION.length,'-')
|
||||
ets = job.list.inject(Tms.new) { |sum,(label,item)|
|
||||
print label.ljust(width)
|
||||
res = Benchmark.measure(&item)
|
||||
print res.format
|
||||
sum + res
|
||||
}.format("total: %tsec")
|
||||
print " #{ets}\n\n".rjust(width+CAPTION.length+2,'-')
|
||||
|
||||
# take
|
||||
print ' '*width + CAPTION
|
||||
job.list.map { |label,item|
|
||||
GC.start
|
||||
print label.ljust(width)
|
||||
Benchmark.measure(label, &item).tap { |res| print res }
|
||||
}
|
||||
ensure
|
||||
STDOUT.sync = sync unless sync.nil?
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the time used to execute the given block as a
|
||||
# Benchmark::Tms object.
|
||||
#
|
||||
def measure(label = "") # :yield:
|
||||
t0, r0 = Process.times, Time.now
|
||||
yield
|
||||
t1, r1 = Process.times, Time.now
|
||||
Benchmark::Tms.new(t1.utime - t0.utime,
|
||||
t1.stime - t0.stime,
|
||||
t1.cutime - t0.cutime,
|
||||
t1.cstime - t0.cstime,
|
||||
r1 - r0,
|
||||
label)
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the elapsed real time used to execute the given block.
|
||||
#
|
||||
def realtime # :yield:
|
||||
r0 = Time.now
|
||||
yield
|
||||
Time.now - r0
|
||||
end
|
||||
|
||||
module_function :benchmark, :measure, :realtime, :bm, :bmbm
|
||||
|
||||
#
|
||||
# A Job is a sequence of labelled blocks to be processed by the
|
||||
# Benchmark.bmbm method. It is of little direct interest to the user.
|
||||
#
|
||||
class Job # :nodoc:
|
||||
#
|
||||
# Returns an initialized Job instance.
|
||||
# Usually, one doesn't call this method directly, as new
|
||||
# Job objects are created by the #bmbm method.
|
||||
# +width+ is a initial value for the label offset used in formatting;
|
||||
# the #bmbm method passes its +width+ argument to this constructor.
|
||||
#
|
||||
def initialize(width)
|
||||
@width = width
|
||||
@list = []
|
||||
end
|
||||
|
||||
#
|
||||
# Registers the given label and block pair in the job list.
|
||||
#
|
||||
def item(label = "", &blk) # :yield:
|
||||
raise ArgumentError, "no block" unless block_given?
|
||||
label = label.to_s
|
||||
w = label.length
|
||||
@width = w if @width < w
|
||||
@list << [label, blk]
|
||||
self
|
||||
end
|
||||
|
||||
alias report item
|
||||
|
||||
# An array of 2-element arrays, consisting of label and block pairs.
|
||||
attr_reader :list
|
||||
|
||||
# Length of the widest label in the #list.
|
||||
attr_reader :width
|
||||
end
|
||||
|
||||
#
|
||||
# This class is used by the Benchmark.benchmark and Benchmark.bm methods.
|
||||
# It is of little direct interest to the user.
|
||||
#
|
||||
class Report # :nodoc:
|
||||
#
|
||||
# Returns an initialized Report instance.
|
||||
# Usually, one doesn't call this method directly, as new
|
||||
# Report objects are created by the #benchmark and #bm methods.
|
||||
# +width+ and +format+ are the label offset and
|
||||
# format string used by Tms#format.
|
||||
#
|
||||
def initialize(width = 0, format = nil)
|
||||
@width, @format, @list = width, format, []
|
||||
end
|
||||
|
||||
#
|
||||
# Prints the +label+ and measured time for the block,
|
||||
# formatted by +format+. See Tms#format for the
|
||||
# formatting rules.
|
||||
#
|
||||
def item(label = "", *format, &blk) # :yield:
|
||||
print label.to_s.ljust(@width)
|
||||
@list << res = Benchmark.measure(label, &blk)
|
||||
print res.format(@format, *format)
|
||||
res
|
||||
end
|
||||
|
||||
alias report item
|
||||
|
||||
# An array of Benchmark::Tms objects representing each item.
|
||||
attr_reader :list
|
||||
end
|
||||
|
||||
|
||||
|
||||
#
|
||||
# A data object, representing the times associated with a benchmark
|
||||
# measurement.
|
||||
#
|
||||
class Tms
|
||||
|
||||
# Default caption, see also Benchmark::CAPTION
|
||||
CAPTION = " user system total real\n"
|
||||
|
||||
# Default format string, see also Benchmark::FORMAT
|
||||
FORMAT = "%10.6u %10.6y %10.6t %10.6r\n"
|
||||
|
||||
# User CPU time
|
||||
attr_reader :utime
|
||||
|
||||
# System CPU time
|
||||
attr_reader :stime
|
||||
|
||||
# User CPU time of children
|
||||
attr_reader :cutime
|
||||
|
||||
# System CPU time of children
|
||||
attr_reader :cstime
|
||||
|
||||
# Elapsed real time
|
||||
attr_reader :real
|
||||
|
||||
# Total time, that is +utime+ + +stime+ + +cutime+ + +cstime+
|
||||
attr_reader :total
|
||||
|
||||
# Label
|
||||
attr_reader :label
|
||||
|
||||
#
|
||||
# Returns an initialized Tms object which has
|
||||
# +utime+ as the user CPU time, +stime+ as the system CPU time,
|
||||
# +cutime+ as the children's user CPU time, +cstime+ as the children's
|
||||
# system CPU time, +real+ as the elapsed real time and +label+ as the label.
|
||||
#
|
||||
def initialize(utime = 0.0, stime = 0.0, cutime = 0.0, cstime = 0.0, real = 0.0, label = nil)
|
||||
@utime, @stime, @cutime, @cstime, @real, @label = utime, stime, cutime, cstime, real, label.to_s
|
||||
@total = @utime + @stime + @cutime + @cstime
|
||||
end
|
||||
|
||||
#
|
||||
# Returns a new Tms object whose times are the sum of the times for this
|
||||
# Tms object, plus the time required to execute the code block (+blk+).
|
||||
#
|
||||
def add(&blk) # :yield:
|
||||
self + Benchmark.measure(&blk)
|
||||
end
|
||||
|
||||
#
|
||||
# An in-place version of #add.
|
||||
#
|
||||
def add!(&blk)
|
||||
t = Benchmark.measure(&blk)
|
||||
@utime = utime + t.utime
|
||||
@stime = stime + t.stime
|
||||
@cutime = cutime + t.cutime
|
||||
@cstime = cstime + t.cstime
|
||||
@real = real + t.real
|
||||
self
|
||||
end
|
||||
|
||||
#
|
||||
# Returns a new Tms object obtained by memberwise summation
|
||||
# of the individual times for this Tms object with those of the other
|
||||
# Tms object.
|
||||
# This method and #/() are useful for taking statistics.
|
||||
#
|
||||
def +(other); memberwise(:+, other) end
|
||||
|
||||
#
|
||||
# Returns a new Tms object obtained by memberwise subtraction
|
||||
# of the individual times for the other Tms object from those of this
|
||||
# Tms object.
|
||||
#
|
||||
def -(other); memberwise(:-, other) end
|
||||
|
||||
#
|
||||
# Returns a new Tms object obtained by memberwise multiplication
|
||||
# of the individual times for this Tms object by _x_.
|
||||
#
|
||||
def *(x); memberwise(:*, x) end
|
||||
|
||||
#
|
||||
# Returns a new Tms object obtained by memberwise division
|
||||
# of the individual times for this Tms object by _x_.
|
||||
# This method and #+() are useful for taking statistics.
|
||||
#
|
||||
def /(x); memberwise(:/, x) end
|
||||
|
||||
#
|
||||
# Returns the contents of this Tms object as
|
||||
# a formatted string, according to a format string
|
||||
# like that passed to Kernel.format. In addition, #format
|
||||
# accepts the following extensions:
|
||||
#
|
||||
# <tt>%u</tt>:: Replaced by the user CPU time, as reported by Tms#utime.
|
||||
# <tt>%y</tt>:: Replaced by the system CPU time, as reported by #stime (Mnemonic: y of "s*y*stem")
|
||||
# <tt>%U</tt>:: Replaced by the children's user CPU time, as reported by Tms#cutime
|
||||
# <tt>%Y</tt>:: Replaced by the children's system CPU time, as reported by Tms#cstime
|
||||
# <tt>%t</tt>:: Replaced by the total CPU time, as reported by Tms#total
|
||||
# <tt>%r</tt>:: Replaced by the elapsed real time, as reported by Tms#real
|
||||
# <tt>%n</tt>:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame")
|
||||
#
|
||||
# If _format_ is not given, FORMAT is used as default value, detailing the
|
||||
# user, system and real elapsed time.
|
||||
#
|
||||
def format(format = nil, *args)
|
||||
str = (format || FORMAT).dup
|
||||
str.gsub!(/(%[-+.\d]*)n/) { "#{$1}s" % label }
|
||||
str.gsub!(/(%[-+.\d]*)u/) { "#{$1}f" % utime }
|
||||
str.gsub!(/(%[-+.\d]*)y/) { "#{$1}f" % stime }
|
||||
str.gsub!(/(%[-+.\d]*)U/) { "#{$1}f" % cutime }
|
||||
str.gsub!(/(%[-+.\d]*)Y/) { "#{$1}f" % cstime }
|
||||
str.gsub!(/(%[-+.\d]*)t/) { "#{$1}f" % total }
|
||||
str.gsub!(/(%[-+.\d]*)r/) { "(#{$1}f)" % real }
|
||||
format ? str % args : str
|
||||
end
|
||||
|
||||
#
|
||||
# Same as #format.
|
||||
#
|
||||
def to_s
|
||||
format
|
||||
end
|
||||
|
||||
#
|
||||
# Returns a new 6-element array, consisting of the
|
||||
# label, user CPU time, system CPU time, children's
|
||||
# user CPU time, children's system CPU time and elapsed
|
||||
# real time.
|
||||
#
|
||||
def to_a
|
||||
[@label, @utime, @stime, @cutime, @cstime, @real]
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
#
|
||||
# Returns a new Tms object obtained by memberwise operation +op+
|
||||
# of the individual times for this Tms object with those of the other
|
||||
# Tms object.
|
||||
#
|
||||
# +op+ can be a mathematical operation such as <tt>+</tt>, <tt>-</tt>,
|
||||
# <tt>*</tt>, <tt>/</tt>
|
||||
#
|
||||
def memberwise(op, x)
|
||||
case x
|
||||
when Benchmark::Tms
|
||||
Benchmark::Tms.new(utime.__send__(op, x.utime),
|
||||
stime.__send__(op, x.stime),
|
||||
cutime.__send__(op, x.cutime),
|
||||
cstime.__send__(op, x.cstime),
|
||||
real.__send__(op, x.real)
|
||||
)
|
||||
else
|
||||
Benchmark::Tms.new(utime.__send__(op, x),
|
||||
stime.__send__(op, x),
|
||||
cutime.__send__(op, x),
|
||||
cstime.__send__(op, x),
|
||||
real.__send__(op, x)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# The default caption string (heading above the output times).
|
||||
CAPTION = Benchmark::Tms::CAPTION
|
||||
|
||||
# The default format string used to display times. See also Benchmark::Tms#format.
|
||||
FORMAT = Benchmark::Tms::FORMAT
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
include Benchmark
|
||||
|
||||
n = ARGV[0].to_i.nonzero? || 50000
|
||||
puts %Q([#{n} times iterations of `a = "1"'])
|
||||
benchmark(CAPTION, 7, FORMAT) do |x|
|
||||
x.report("for:") {for _ in 1..n; _ = "1"; end} # Benchmark.measure
|
||||
x.report("times:") {n.times do ; _ = "1"; end}
|
||||
x.report("upto:") {1.upto(n) do ; _ = "1"; end}
|
||||
end
|
||||
|
||||
benchmark do
|
||||
[
|
||||
measure{for _ in 1..n; _ = "1"; end}, # Benchmark.measure
|
||||
measure{n.times do ; _ = "1"; end},
|
||||
measure{1.upto(n) do ; _ = "1"; end}
|
||||
]
|
||||
end
|
||||
end
|
||||
87
ruby/lib/ruby/2.1.0/bigdecimal/jacobian.rb
Normal file
87
ruby/lib/ruby/2.1.0/bigdecimal/jacobian.rb
Normal file
@@ -0,0 +1,87 @@
|
||||
#
|
||||
# require 'bigdecimal/jacobian'
|
||||
#
|
||||
# Provides methods to compute the Jacobian matrix of a set of equations at a
|
||||
# point x. In the methods below:
|
||||
#
|
||||
# f is an Object which is used to compute the Jacobian matrix of the equations.
|
||||
# It must provide the following methods:
|
||||
#
|
||||
# f.values(x):: returns the values of all functions at x
|
||||
#
|
||||
# f.zero:: returns 0.0
|
||||
# f.one:: returns 1.0
|
||||
# f.two:: returns 2.0
|
||||
# f.ten:: returns 10.0
|
||||
#
|
||||
# f.eps:: returns the convergence criterion (epsilon value) used to determine whether two values are considered equal. If |a-b| < epsilon, the two values are considered equal.
|
||||
#
|
||||
# x is the point at which to compute the Jacobian.
|
||||
#
|
||||
# fx is f.values(x).
|
||||
#
|
||||
module Jacobian
|
||||
module_function
|
||||
|
||||
# Determines the equality of two numbers by comparing to zero, or using the epsilon value
|
||||
def isEqual(a,b,zero=0.0,e=1.0e-8)
|
||||
aa = a.abs
|
||||
bb = b.abs
|
||||
if aa == zero && bb == zero then
|
||||
true
|
||||
else
|
||||
if ((a-b)/(aa+bb)).abs < e then
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Computes the derivative of f[i] at x[i].
|
||||
# fx is the value of f at x.
|
||||
def dfdxi(f,fx,x,i)
|
||||
nRetry = 0
|
||||
n = x.size
|
||||
xSave = x[i]
|
||||
ok = 0
|
||||
ratio = f.ten*f.ten*f.ten
|
||||
dx = x[i].abs/ratio
|
||||
dx = fx[i].abs/ratio if isEqual(dx,f.zero,f.zero,f.eps)
|
||||
dx = f.one/f.ten if isEqual(dx,f.zero,f.zero,f.eps)
|
||||
until ok>0 do
|
||||
deriv = []
|
||||
nRetry += 1
|
||||
if nRetry > 100
|
||||
raise "Singular Jacobian matrix. No change at x[" + i.to_s + "]"
|
||||
end
|
||||
dx = dx*f.two
|
||||
x[i] += dx
|
||||
fxNew = f.values(x)
|
||||
for j in 0...n do
|
||||
if !isEqual(fxNew[j],fx[j],f.zero,f.eps) then
|
||||
ok += 1
|
||||
deriv <<= (fxNew[j]-fx[j])/dx
|
||||
else
|
||||
deriv <<= f.zero
|
||||
end
|
||||
end
|
||||
x[i] = xSave
|
||||
end
|
||||
deriv
|
||||
end
|
||||
|
||||
# Computes the Jacobian of f at x. fx is the value of f at x.
|
||||
def jacobian(f,fx,x)
|
||||
n = x.size
|
||||
dfdx = Array::new(n*n)
|
||||
for i in 0...n do
|
||||
df = dfdxi(f,fx,x,i)
|
||||
for j in 0...n do
|
||||
dfdx[j*n+i] = df[j]
|
||||
end
|
||||
end
|
||||
dfdx
|
||||
end
|
||||
end
|
||||
88
ruby/lib/ruby/2.1.0/bigdecimal/ludcmp.rb
Normal file
88
ruby/lib/ruby/2.1.0/bigdecimal/ludcmp.rb
Normal file
@@ -0,0 +1,88 @@
|
||||
require 'bigdecimal'
|
||||
|
||||
#
|
||||
# Solves a*x = b for x, using LU decomposition.
|
||||
#
|
||||
module LUSolve
|
||||
module_function
|
||||
|
||||
# Performs LU decomposition of the n by n matrix a.
|
||||
def ludecomp(a,n,zero=0,one=1)
|
||||
prec = BigDecimal.limit(nil)
|
||||
ps = []
|
||||
scales = []
|
||||
for i in 0...n do # pick up largest(abs. val.) element in each row.
|
||||
ps <<= i
|
||||
nrmrow = zero
|
||||
ixn = i*n
|
||||
for j in 0...n do
|
||||
biggst = a[ixn+j].abs
|
||||
nrmrow = biggst if biggst>nrmrow
|
||||
end
|
||||
if nrmrow>zero then
|
||||
scales <<= one.div(nrmrow,prec)
|
||||
else
|
||||
raise "Singular matrix"
|
||||
end
|
||||
end
|
||||
n1 = n - 1
|
||||
for k in 0...n1 do # Gaussian elimination with partial pivoting.
|
||||
biggst = zero;
|
||||
for i in k...n do
|
||||
size = a[ps[i]*n+k].abs*scales[ps[i]]
|
||||
if size>biggst then
|
||||
biggst = size
|
||||
pividx = i
|
||||
end
|
||||
end
|
||||
raise "Singular matrix" if biggst<=zero
|
||||
if pividx!=k then
|
||||
j = ps[k]
|
||||
ps[k] = ps[pividx]
|
||||
ps[pividx] = j
|
||||
end
|
||||
pivot = a[ps[k]*n+k]
|
||||
for i in (k+1)...n do
|
||||
psin = ps[i]*n
|
||||
a[psin+k] = mult = a[psin+k].div(pivot,prec)
|
||||
if mult!=zero then
|
||||
pskn = ps[k]*n
|
||||
for j in (k+1)...n do
|
||||
a[psin+j] -= mult.mult(a[pskn+j],prec)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
raise "Singular matrix" if a[ps[n1]*n+n1] == zero
|
||||
ps
|
||||
end
|
||||
|
||||
# Solves a*x = b for x, using LU decomposition.
|
||||
#
|
||||
# a is a matrix, b is a constant vector, x is the solution vector.
|
||||
#
|
||||
# ps is the pivot, a vector which indicates the permutation of rows performed
|
||||
# during LU decomposition.
|
||||
def lusolve(a,b,ps,zero=0.0)
|
||||
prec = BigDecimal.limit(nil)
|
||||
n = ps.size
|
||||
x = []
|
||||
for i in 0...n do
|
||||
dot = zero
|
||||
psin = ps[i]*n
|
||||
for j in 0...i do
|
||||
dot = a[psin+j].mult(x[j],prec) + dot
|
||||
end
|
||||
x <<= b[ps[i]] - dot
|
||||
end
|
||||
(n-1).downto(0) do |i|
|
||||
dot = zero
|
||||
psin = ps[i]*n
|
||||
for j in (i+1)...n do
|
||||
dot = a[psin+j].mult(x[j],prec) + dot
|
||||
end
|
||||
x[i] = (x[i]-dot).div(a[psin+i],prec)
|
||||
end
|
||||
x
|
||||
end
|
||||
end
|
||||
231
ruby/lib/ruby/2.1.0/bigdecimal/math.rb
Normal file
231
ruby/lib/ruby/2.1.0/bigdecimal/math.rb
Normal file
@@ -0,0 +1,231 @@
|
||||
require 'bigdecimal'
|
||||
|
||||
#
|
||||
#--
|
||||
# Contents:
|
||||
# sqrt(x, prec)
|
||||
# sin (x, prec)
|
||||
# cos (x, prec)
|
||||
# atan(x, prec) Note: |x|<1, x=0.9999 may not converge.
|
||||
# PI (prec)
|
||||
# E (prec) == exp(1.0,prec)
|
||||
#
|
||||
# where:
|
||||
# x ... BigDecimal number to be computed.
|
||||
# |x| must be small enough to get convergence.
|
||||
# prec ... Number of digits to be obtained.
|
||||
#++
|
||||
#
|
||||
# Provides mathematical functions.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# require "bigdecimal/math"
|
||||
#
|
||||
# include BigMath
|
||||
#
|
||||
# a = BigDecimal((PI(100)/2).to_s)
|
||||
# puts sin(a,100) # => 0.10000000000000000000......E1
|
||||
#
|
||||
module BigMath
|
||||
module_function
|
||||
|
||||
# call-seq:
|
||||
# sqrt(decimal, numeric) -> BigDecimal
|
||||
#
|
||||
# Computes the square root of +decimal+ to the specified number of digits of
|
||||
# precision, +numeric+.
|
||||
#
|
||||
# BigMath::sqrt(BigDecimal.new('2'), 16).to_s
|
||||
# #=> "0.14142135623730950488016887242096975E1"
|
||||
#
|
||||
def sqrt(x, prec)
|
||||
x.sqrt(prec)
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# sin(decimal, numeric) -> BigDecimal
|
||||
#
|
||||
# Computes the sine of +decimal+ to the specified number of digits of
|
||||
# precision, +numeric+.
|
||||
#
|
||||
# If +decimal+ is Infinity or NaN, returns NaN.
|
||||
#
|
||||
# BigMath::sin(BigMath::PI(5)/4, 5).to_s
|
||||
# #=> "0.70710678118654752440082036563292800375E0"
|
||||
#
|
||||
def sin(x, prec)
|
||||
raise ArgumentError, "Zero or negative precision for sin" if prec <= 0
|
||||
return BigDecimal("NaN") if x.infinite? || x.nan?
|
||||
n = prec + BigDecimal.double_fig
|
||||
one = BigDecimal("1")
|
||||
two = BigDecimal("2")
|
||||
x = -x if neg = x < 0
|
||||
if x > (twopi = two * BigMath.PI(prec))
|
||||
if x > 30
|
||||
x %= twopi
|
||||
else
|
||||
x -= twopi while x > twopi
|
||||
end
|
||||
end
|
||||
x1 = x
|
||||
x2 = x.mult(x,n)
|
||||
sign = 1
|
||||
y = x
|
||||
d = y
|
||||
i = one
|
||||
z = one
|
||||
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
||||
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
||||
sign = -sign
|
||||
x1 = x2.mult(x1,n)
|
||||
i += two
|
||||
z *= (i-one) * i
|
||||
d = sign * x1.div(z,m)
|
||||
y += d
|
||||
end
|
||||
neg ? -y : y
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# cos(decimal, numeric) -> BigDecimal
|
||||
#
|
||||
# Computes the cosine of +decimal+ to the specified number of digits of
|
||||
# precision, +numeric+.
|
||||
#
|
||||
# If +decimal+ is Infinity or NaN, returns NaN.
|
||||
#
|
||||
# BigMath::cos(BigMath::PI(4), 16).to_s
|
||||
# #=> "-0.999999999999999999999999999999856613163740061349E0"
|
||||
#
|
||||
def cos(x, prec)
|
||||
raise ArgumentError, "Zero or negative precision for cos" if prec <= 0
|
||||
return BigDecimal("NaN") if x.infinite? || x.nan?
|
||||
n = prec + BigDecimal.double_fig
|
||||
one = BigDecimal("1")
|
||||
two = BigDecimal("2")
|
||||
x = -x if x < 0
|
||||
if x > (twopi = two * BigMath.PI(prec))
|
||||
if x > 30
|
||||
x %= twopi
|
||||
else
|
||||
x -= twopi while x > twopi
|
||||
end
|
||||
end
|
||||
x1 = one
|
||||
x2 = x.mult(x,n)
|
||||
sign = 1
|
||||
y = one
|
||||
d = y
|
||||
i = BigDecimal("0")
|
||||
z = one
|
||||
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
||||
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
||||
sign = -sign
|
||||
x1 = x2.mult(x1,n)
|
||||
i += two
|
||||
z *= (i-one) * i
|
||||
d = sign * x1.div(z,m)
|
||||
y += d
|
||||
end
|
||||
y
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# atan(decimal, numeric) -> BigDecimal
|
||||
#
|
||||
# Computes the arctangent of +decimal+ to the specified number of digits of
|
||||
# precision, +numeric+.
|
||||
#
|
||||
# If +decimal+ is NaN, returns NaN.
|
||||
#
|
||||
# BigMath::atan(BigDecimal.new('-1'), 16).to_s
|
||||
# #=> "-0.785398163397448309615660845819878471907514682065E0"
|
||||
#
|
||||
def atan(x, prec)
|
||||
raise ArgumentError, "Zero or negative precision for atan" if prec <= 0
|
||||
return BigDecimal("NaN") if x.nan?
|
||||
pi = PI(prec)
|
||||
x = -x if neg = x < 0
|
||||
return pi.div(neg ? -2 : 2, prec) if x.infinite?
|
||||
return pi / (neg ? -4 : 4) if x.round(prec) == 1
|
||||
x = BigDecimal("1").div(x, prec) if inv = x > 1
|
||||
x = (-1 + sqrt(1 + x**2, prec))/x if dbl = x > 0.5
|
||||
n = prec + BigDecimal.double_fig
|
||||
y = x
|
||||
d = y
|
||||
t = x
|
||||
r = BigDecimal("3")
|
||||
x2 = x.mult(x,n)
|
||||
while d.nonzero? && ((m = n - (y.exponent - d.exponent).abs) > 0)
|
||||
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
||||
t = -t.mult(x2,n)
|
||||
d = t.div(r,m)
|
||||
y += d
|
||||
r += 2
|
||||
end
|
||||
y *= 2 if dbl
|
||||
y = pi / 2 - y if inv
|
||||
y = -y if neg
|
||||
y
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# PI(numeric) -> BigDecimal
|
||||
#
|
||||
# Computes the value of pi to the specified number of digits of precision,
|
||||
# +numeric+.
|
||||
#
|
||||
# BigMath::PI(10).to_s
|
||||
# #=> "0.3141592653589793238462643388813853786957412E1"
|
||||
#
|
||||
def PI(prec)
|
||||
raise ArgumentError, "Zero or negative argument for PI" if prec <= 0
|
||||
n = prec + BigDecimal.double_fig
|
||||
zero = BigDecimal("0")
|
||||
one = BigDecimal("1")
|
||||
two = BigDecimal("2")
|
||||
|
||||
m25 = BigDecimal("-0.04")
|
||||
m57121 = BigDecimal("-57121")
|
||||
|
||||
pi = zero
|
||||
|
||||
d = one
|
||||
k = one
|
||||
t = BigDecimal("-80")
|
||||
while d.nonzero? && ((m = n - (pi.exponent - d.exponent).abs) > 0)
|
||||
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
||||
t = t*m25
|
||||
d = t.div(k,m)
|
||||
k = k+two
|
||||
pi = pi + d
|
||||
end
|
||||
|
||||
d = one
|
||||
k = one
|
||||
t = BigDecimal("956")
|
||||
while d.nonzero? && ((m = n - (pi.exponent - d.exponent).abs) > 0)
|
||||
m = BigDecimal.double_fig if m < BigDecimal.double_fig
|
||||
t = t.div(m57121,n)
|
||||
d = t.div(k,m)
|
||||
pi = pi + d
|
||||
k = k+two
|
||||
end
|
||||
pi
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# E(numeric) -> BigDecimal
|
||||
#
|
||||
# Computes e (the base of natural logarithms) to the specified number of
|
||||
# digits of precision, +numeric+.
|
||||
#
|
||||
# BigMath::E(10).to_s
|
||||
# #=> "0.271828182845904523536028752390026306410273E1"
|
||||
#
|
||||
def E(prec)
|
||||
raise ArgumentError, "Zero or negative precision for E" if prec <= 0
|
||||
BigMath.exp(1, prec)
|
||||
end
|
||||
end
|
||||
79
ruby/lib/ruby/2.1.0/bigdecimal/newton.rb
Normal file
79
ruby/lib/ruby/2.1.0/bigdecimal/newton.rb
Normal file
@@ -0,0 +1,79 @@
|
||||
require "bigdecimal/ludcmp"
|
||||
require "bigdecimal/jacobian"
|
||||
|
||||
#
|
||||
# newton.rb
|
||||
#
|
||||
# Solves the nonlinear algebraic equation system f = 0 by Newton's method.
|
||||
# This program is not dependent on BigDecimal.
|
||||
#
|
||||
# To call:
|
||||
# n = nlsolve(f,x)
|
||||
# where n is the number of iterations required,
|
||||
# x is the initial value vector
|
||||
# f is an Object which is used to compute the values of the equations to be solved.
|
||||
# It must provide the following methods:
|
||||
#
|
||||
# f.values(x):: returns the values of all functions at x
|
||||
#
|
||||
# f.zero:: returns 0.0
|
||||
# f.one:: returns 1.0
|
||||
# f.two:: returns 2.0
|
||||
# f.ten:: returns 10.0
|
||||
#
|
||||
# f.eps:: returns the convergence criterion (epsilon value) used to determine whether two values are considered equal. If |a-b| < epsilon, the two values are considered equal.
|
||||
#
|
||||
# On exit, x is the solution vector.
|
||||
#
|
||||
module Newton
|
||||
include LUSolve
|
||||
include Jacobian
|
||||
module_function
|
||||
|
||||
def norm(fv,zero=0.0) # :nodoc:
|
||||
s = zero
|
||||
n = fv.size
|
||||
for i in 0...n do
|
||||
s += fv[i]*fv[i]
|
||||
end
|
||||
s
|
||||
end
|
||||
|
||||
# See also Newton
|
||||
def nlsolve(f,x)
|
||||
nRetry = 0
|
||||
n = x.size
|
||||
|
||||
f0 = f.values(x)
|
||||
zero = f.zero
|
||||
one = f.one
|
||||
two = f.two
|
||||
p5 = one/two
|
||||
d = norm(f0,zero)
|
||||
minfact = f.ten*f.ten*f.ten
|
||||
minfact = one/minfact
|
||||
e = f.eps
|
||||
while d >= e do
|
||||
nRetry += 1
|
||||
# Not yet converged. => Compute Jacobian matrix
|
||||
dfdx = jacobian(f,f0,x)
|
||||
# Solve dfdx*dx = -f0 to estimate dx
|
||||
dx = lusolve(dfdx,f0,ludecomp(dfdx,n,zero,one),zero)
|
||||
fact = two
|
||||
xs = x.dup
|
||||
begin
|
||||
fact *= p5
|
||||
if fact < minfact then
|
||||
raise "Failed to reduce function values."
|
||||
end
|
||||
for i in 0...n do
|
||||
x[i] = xs[i] - dx[i]*fact
|
||||
end
|
||||
f0 = f.values(x)
|
||||
dn = norm(f0,zero)
|
||||
end while(dn>=d)
|
||||
d = dn
|
||||
end
|
||||
nRetry
|
||||
end
|
||||
end
|
||||
127
ruby/lib/ruby/2.1.0/bigdecimal/util.rb
Normal file
127
ruby/lib/ruby/2.1.0/bigdecimal/util.rb
Normal file
@@ -0,0 +1,127 @@
|
||||
# BigDecimal extends the native Integer class to provide the #to_d method.
|
||||
#
|
||||
# When you require the BigDecimal library in your application, this methodwill
|
||||
# be available on Integer objects.
|
||||
class Integer < Numeric
|
||||
# call-seq:
|
||||
# int.to_d -> bigdecimal
|
||||
#
|
||||
# Convert +int+ to a BigDecimal and return it.
|
||||
#
|
||||
# require 'bigdecimal'
|
||||
# require 'bigdecimal/util'
|
||||
#
|
||||
# 42.to_d
|
||||
# # => #<BigDecimal:1008ef070,'0.42E2',9(36)>
|
||||
#
|
||||
def to_d
|
||||
BigDecimal(self)
|
||||
end
|
||||
end
|
||||
|
||||
# BigDecimal extends the native Float class to provide the #to_d method.
|
||||
#
|
||||
# When you require BigDecimal in your application, this method will be
|
||||
# available on Float objects.
|
||||
class Float < Numeric
|
||||
# call-seq:
|
||||
# flt.to_d -> bigdecimal
|
||||
#
|
||||
# Convert +flt+ to a BigDecimal and return it.
|
||||
#
|
||||
# require 'bigdecimal'
|
||||
# require 'bigdecimal/util'
|
||||
#
|
||||
# 0.5.to_d
|
||||
# # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
|
||||
#
|
||||
def to_d(precision=nil)
|
||||
BigDecimal(self, precision || Float::DIG)
|
||||
end
|
||||
end
|
||||
|
||||
# BigDecimal extends the native String class to provide the #to_d method.
|
||||
#
|
||||
# When you require BigDecimal in your application, this method will be
|
||||
# available on String objects.
|
||||
class String
|
||||
# call-seq:
|
||||
# string.to_d -> bigdecimal
|
||||
#
|
||||
# Convert +string+ to a BigDecimal and return it.
|
||||
#
|
||||
# require 'bigdecimal'
|
||||
# require 'bigdecimal/util'
|
||||
#
|
||||
# "0.5".to_d
|
||||
# # => #<BigDecimal:1dc69e0,'0.5E0',9(18)>
|
||||
#
|
||||
def to_d
|
||||
BigDecimal(self)
|
||||
end
|
||||
end
|
||||
|
||||
# BigDecimal extends the native Numeric class to provide the #to_digits and
|
||||
# #to_d methods.
|
||||
#
|
||||
# When you require BigDecimal in your application, this method will be
|
||||
# available on BigDecimal objects.
|
||||
class BigDecimal < Numeric
|
||||
# call-seq:
|
||||
# a.to_digits -> string
|
||||
#
|
||||
# Converts a BigDecimal to a String of the form "nnnnnn.mmm".
|
||||
# This method is deprecated; use BigDecimal#to_s("F") instead.
|
||||
#
|
||||
# require 'bigdecimal'
|
||||
# require 'bigdecimal/util'
|
||||
#
|
||||
# d = BigDecimal.new("3.14")
|
||||
# d.to_digits
|
||||
# # => "3.14"
|
||||
def to_digits
|
||||
if self.nan? || self.infinite? || self.zero?
|
||||
self.to_s
|
||||
else
|
||||
i = self.to_i.to_s
|
||||
_,f,_,z = self.frac.split
|
||||
i + "." + ("0"*(-z)) + f
|
||||
end
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# a.to_d -> bigdecimal
|
||||
#
|
||||
# Returns self.
|
||||
def to_d
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
# BigDecimal extends the native Rational class to provide the #to_d method.
|
||||
#
|
||||
# When you require BigDecimal in your application, this method will be
|
||||
# available on Rational objects.
|
||||
class Rational < Numeric
|
||||
# call-seq:
|
||||
# r.to_d(precision) -> bigdecimal
|
||||
#
|
||||
# Converts a Rational to a BigDecimal.
|
||||
#
|
||||
# The required +precision+ parameter is used to determine the amount of
|
||||
# significant digits for the result. See BigDecimal#div for more information,
|
||||
# as it is used along with the #denominator and the +precision+ for
|
||||
# parameters.
|
||||
#
|
||||
# r = (22/7.0).to_r
|
||||
# # => (7077085128725065/2251799813685248)
|
||||
# r.to_d(3)
|
||||
# # => #<BigDecimal:1a44d08,'0.314E1',18(36)>
|
||||
def to_d(precision)
|
||||
if precision <= 0
|
||||
raise ArgumentError, "negative precision"
|
||||
end
|
||||
num = self.numerator
|
||||
BigDecimal(num).div(self.denominator, precision)
|
||||
end
|
||||
end
|
||||
297
ruby/lib/ruby/2.1.0/cgi.rb
Normal file
297
ruby/lib/ruby/2.1.0/cgi.rb
Normal file
@@ -0,0 +1,297 @@
|
||||
#
|
||||
# cgi.rb - cgi support library
|
||||
#
|
||||
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
#
|
||||
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
#
|
||||
# Author: Wakou Aoyama <wakou@ruby-lang.org>
|
||||
#
|
||||
# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
|
||||
#
|
||||
|
||||
raise "Please, use ruby 1.9.0 or later." if RUBY_VERSION < "1.9.0"
|
||||
|
||||
# == Overview
|
||||
#
|
||||
# The Common Gateway Interface (CGI) is a simple protocol for passing an HTTP
|
||||
# request from a web server to a standalone program, and returning the output
|
||||
# to the web browser. Basically, a CGI program is called with the parameters
|
||||
# of the request passed in either in the environment (GET) or via $stdin
|
||||
# (POST), and everything it prints to $stdout is returned to the client.
|
||||
#
|
||||
# This file holds the CGI class. This class provides functionality for
|
||||
# retrieving HTTP request parameters, managing cookies, and generating HTML
|
||||
# output.
|
||||
#
|
||||
# The file CGI::Session provides session management functionality; see that
|
||||
# class for more details.
|
||||
#
|
||||
# See http://www.w3.org/CGI/ for more information on the CGI protocol.
|
||||
#
|
||||
# == Introduction
|
||||
#
|
||||
# CGI is a large class, providing several categories of methods, many of which
|
||||
# are mixed in from other modules. Some of the documentation is in this class,
|
||||
# some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
|
||||
# CGI::Cookie for specific information on handling cookies, and cgi/session.rb
|
||||
# (CGI::Session) for information on sessions.
|
||||
#
|
||||
# For queries, CGI provides methods to get at environmental variables,
|
||||
# parameters, cookies, and multipart request data. For responses, CGI provides
|
||||
# methods for writing output and generating HTML.
|
||||
#
|
||||
# Read on for more details. Examples are provided at the bottom.
|
||||
#
|
||||
# == Queries
|
||||
#
|
||||
# The CGI class dynamically mixes in parameter and cookie-parsing
|
||||
# functionality, environmental variable access, and support for
|
||||
# parsing multipart requests (including uploaded files) from the
|
||||
# CGI::QueryExtension module.
|
||||
#
|
||||
# === Environmental Variables
|
||||
#
|
||||
# The standard CGI environmental variables are available as read-only
|
||||
# attributes of a CGI object. The following is a list of these variables:
|
||||
#
|
||||
#
|
||||
# AUTH_TYPE HTTP_HOST REMOTE_IDENT
|
||||
# CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
|
||||
# CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
|
||||
# GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
|
||||
# HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
|
||||
# HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
|
||||
# HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
|
||||
# HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
|
||||
# HTTP_CACHE_CONTROL REMOTE_ADDR
|
||||
# HTTP_FROM REMOTE_HOST
|
||||
#
|
||||
#
|
||||
# For each of these variables, there is a corresponding attribute with the
|
||||
# same name, except all lower case and without a preceding HTTP_.
|
||||
# +content_length+ and +server_port+ are integers; the rest are strings.
|
||||
#
|
||||
# === Parameters
|
||||
#
|
||||
# The method #params() returns a hash of all parameters in the request as
|
||||
# name/value-list pairs, where the value-list is an Array of one or more
|
||||
# values. The CGI object itself also behaves as a hash of parameter names
|
||||
# to values, but only returns a single value (as a String) for each
|
||||
# parameter name.
|
||||
#
|
||||
# For instance, suppose the request contains the parameter
|
||||
# "favourite_colours" with the multiple values "blue" and "green". The
|
||||
# following behaviour would occur:
|
||||
#
|
||||
# cgi.params["favourite_colours"] # => ["blue", "green"]
|
||||
# cgi["favourite_colours"] # => "blue"
|
||||
#
|
||||
# If a parameter does not exist, the former method will return an empty
|
||||
# array, the latter an empty string. The simplest way to test for existence
|
||||
# of a parameter is by the #has_key? method.
|
||||
#
|
||||
# === Cookies
|
||||
#
|
||||
# HTTP Cookies are automatically parsed from the request. They are available
|
||||
# from the #cookies() accessor, which returns a hash from cookie name to
|
||||
# CGI::Cookie object.
|
||||
#
|
||||
# === Multipart requests
|
||||
#
|
||||
# If a request's method is POST and its content type is multipart/form-data,
|
||||
# then it may contain uploaded files. These are stored by the QueryExtension
|
||||
# module in the parameters of the request. The parameter name is the name
|
||||
# attribute of the file input field, as usual. However, the value is not
|
||||
# a string, but an IO object, either an IOString for small files, or a
|
||||
# Tempfile for larger ones. This object also has the additional singleton
|
||||
# methods:
|
||||
#
|
||||
# #local_path():: the path of the uploaded file on the local filesystem
|
||||
# #original_filename():: the name of the file on the client computer
|
||||
# #content_type():: the content type of the file
|
||||
#
|
||||
# == Responses
|
||||
#
|
||||
# The CGI class provides methods for sending header and content output to
|
||||
# the HTTP client, and mixes in methods for programmatic HTML generation
|
||||
# from CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML
|
||||
# to use for HTML generation is specified at object creation time.
|
||||
#
|
||||
# === Writing output
|
||||
#
|
||||
# The simplest way to send output to the HTTP client is using the #out() method.
|
||||
# This takes the HTTP headers as a hash parameter, and the body content
|
||||
# via a block. The headers can be generated as a string using the #http_header()
|
||||
# method. The output stream can be written directly to using the #print()
|
||||
# method.
|
||||
#
|
||||
# === Generating HTML
|
||||
#
|
||||
# Each HTML element has a corresponding method for generating that
|
||||
# element as a String. The name of this method is the same as that
|
||||
# of the element, all lowercase. The attributes of the element are
|
||||
# passed in as a hash, and the body as a no-argument block that evaluates
|
||||
# to a String. The HTML generation module knows which elements are
|
||||
# always empty, and silently drops any passed-in body. It also knows
|
||||
# which elements require matching closing tags and which don't. However,
|
||||
# it does not know what attributes are legal for which elements.
|
||||
#
|
||||
# There are also some additional HTML generation methods mixed in from
|
||||
# the CGI::HtmlExtension module. These include individual methods for the
|
||||
# different types of form inputs, and methods for elements that commonly
|
||||
# take particular attributes where the attributes can be directly specified
|
||||
# as arguments, rather than via a hash.
|
||||
#
|
||||
# === Utility HTML escape and other methods like a function.
|
||||
#
|
||||
# There are some utility tool defined in cgi/util.rb .
|
||||
# And when include, you can use utility methods like a function.
|
||||
#
|
||||
# == Examples of use
|
||||
#
|
||||
# === Get form values
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new
|
||||
# value = cgi['field_name'] # <== value string for 'field_name'
|
||||
# # if not 'field_name' included, then return "".
|
||||
# fields = cgi.keys # <== array of field names
|
||||
#
|
||||
# # returns true if form has 'field_name'
|
||||
# cgi.has_key?('field_name')
|
||||
# cgi.has_key?('field_name')
|
||||
# cgi.include?('field_name')
|
||||
#
|
||||
# CAUTION! cgi['field_name'] returned an Array with the old
|
||||
# cgi.rb(included in Ruby 1.6)
|
||||
#
|
||||
# === Get form values as hash
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new
|
||||
# params = cgi.params
|
||||
#
|
||||
# cgi.params is a hash.
|
||||
#
|
||||
# cgi.params['new_field_name'] = ["value"] # add new param
|
||||
# cgi.params['field_name'] = ["new_value"] # change value
|
||||
# cgi.params.delete('field_name') # delete param
|
||||
# cgi.params.clear # delete all params
|
||||
#
|
||||
#
|
||||
# === Save form values to file
|
||||
#
|
||||
# require "pstore"
|
||||
# db = PStore.new("query.db")
|
||||
# db.transaction do
|
||||
# db["params"] = cgi.params
|
||||
# end
|
||||
#
|
||||
#
|
||||
# === Restore form values from file
|
||||
#
|
||||
# require "pstore"
|
||||
# db = PStore.new("query.db")
|
||||
# db.transaction do
|
||||
# cgi.params = db["params"]
|
||||
# end
|
||||
#
|
||||
#
|
||||
# === Get multipart form values
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new
|
||||
# value = cgi['field_name'] # <== value string for 'field_name'
|
||||
# value.read # <== body of value
|
||||
# value.local_path # <== path to local file of value
|
||||
# value.original_filename # <== original filename of value
|
||||
# value.content_type # <== content_type of value
|
||||
#
|
||||
# and value has StringIO or Tempfile class methods.
|
||||
#
|
||||
# === Get cookie values
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new
|
||||
# values = cgi.cookies['name'] # <== array of 'name'
|
||||
# # if not 'name' included, then return [].
|
||||
# names = cgi.cookies.keys # <== array of cookie names
|
||||
#
|
||||
# and cgi.cookies is a hash.
|
||||
#
|
||||
# === Get cookie objects
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new
|
||||
# for name, cookie in cgi.cookies
|
||||
# cookie.expires = Time.now + 30
|
||||
# end
|
||||
# cgi.out("cookie" => cgi.cookies) {"string"}
|
||||
#
|
||||
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new
|
||||
# cgi.cookies['name'].expires = Time.now + 30
|
||||
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
|
||||
#
|
||||
# === Print http header and html string to $DEFAULT_OUTPUT ($>)
|
||||
#
|
||||
# require "cgi"
|
||||
# cgi = CGI.new("html4") # add HTML generation methods
|
||||
# cgi.out do
|
||||
# cgi.html do
|
||||
# cgi.head do
|
||||
# cgi.title { "TITLE" }
|
||||
# end +
|
||||
# cgi.body do
|
||||
# cgi.form("ACTION" => "uri") do
|
||||
# cgi.p do
|
||||
# cgi.textarea("get_text") +
|
||||
# cgi.br +
|
||||
# cgi.submit
|
||||
# end
|
||||
# end +
|
||||
# cgi.pre do
|
||||
# CGI::escapeHTML(
|
||||
# "params: #{cgi.params.inspect}\n" +
|
||||
# "cookies: #{cgi.cookies.inspect}\n" +
|
||||
# ENV.collect do |key, value|
|
||||
# "#{key} --> #{value}\n"
|
||||
# end.join("")
|
||||
# )
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# # add HTML generation methods
|
||||
# CGI.new("html3") # html3.2
|
||||
# CGI.new("html4") # html4.01 (Strict)
|
||||
# CGI.new("html4Tr") # html4.01 Transitional
|
||||
# CGI.new("html4Fr") # html4.01 Frameset
|
||||
# CGI.new("html5") # html5
|
||||
#
|
||||
# === Some utility methods
|
||||
#
|
||||
# require 'cgi/util'
|
||||
# CGI.escapeHTML('Usage: foo "bar" <baz>')
|
||||
#
|
||||
#
|
||||
# === Some utility methods like a function
|
||||
#
|
||||
# require 'cgi/util'
|
||||
# include CGI::Util
|
||||
# escapeHTML('Usage: foo "bar" <baz>')
|
||||
# h('Usage: foo "bar" <baz>') # alias
|
||||
#
|
||||
#
|
||||
|
||||
class CGI
|
||||
end
|
||||
|
||||
require 'cgi/core'
|
||||
require 'cgi/cookie'
|
||||
require 'cgi/util'
|
||||
CGI.autoload(:HtmlExtension, 'cgi/html')
|
||||
170
ruby/lib/ruby/2.1.0/cgi/cookie.rb
Normal file
170
ruby/lib/ruby/2.1.0/cgi/cookie.rb
Normal file
@@ -0,0 +1,170 @@
|
||||
require 'cgi/util'
|
||||
class CGI
|
||||
# Class representing an HTTP cookie.
|
||||
#
|
||||
# In addition to its specific fields and methods, a Cookie instance
|
||||
# is a delegator to the array of its values.
|
||||
#
|
||||
# See RFC 2965.
|
||||
#
|
||||
# == Examples of use
|
||||
# cookie1 = CGI::Cookie.new("name", "value1", "value2", ...)
|
||||
# cookie1 = CGI::Cookie.new("name" => "name", "value" => "value")
|
||||
# cookie1 = CGI::Cookie.new('name' => 'name',
|
||||
# 'value' => ['value1', 'value2', ...],
|
||||
# 'path' => 'path', # optional
|
||||
# 'domain' => 'domain', # optional
|
||||
# 'expires' => Time.now, # optional
|
||||
# 'secure' => true # optional
|
||||
# )
|
||||
#
|
||||
# cgi.out("cookie" => [cookie1, cookie2]) { "string" }
|
||||
#
|
||||
# name = cookie1.name
|
||||
# values = cookie1.value
|
||||
# path = cookie1.path
|
||||
# domain = cookie1.domain
|
||||
# expires = cookie1.expires
|
||||
# secure = cookie1.secure
|
||||
#
|
||||
# cookie1.name = 'name'
|
||||
# cookie1.value = ['value1', 'value2', ...]
|
||||
# cookie1.path = 'path'
|
||||
# cookie1.domain = 'domain'
|
||||
# cookie1.expires = Time.now + 30
|
||||
# cookie1.secure = true
|
||||
class Cookie < Array
|
||||
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
||||
|
||||
# Create a new CGI::Cookie object.
|
||||
#
|
||||
# :call-seq:
|
||||
# Cookie.new(name_string,*value)
|
||||
# Cookie.new(options_hash)
|
||||
#
|
||||
# +name_string+::
|
||||
# The name of the cookie; in this form, there is no #domain or
|
||||
# #expiration. The #path is gleaned from the +SCRIPT_NAME+ environment
|
||||
# variable, and #secure is false.
|
||||
# <tt>*value</tt>::
|
||||
# value or list of values of the cookie
|
||||
# +options_hash+::
|
||||
# A Hash of options to initialize this Cookie. Possible options are:
|
||||
#
|
||||
# name:: the name of the cookie. Required.
|
||||
# value:: the cookie's value or list of values.
|
||||
# path:: the path for which this cookie applies. Defaults to the
|
||||
# the value of the +SCRIPT_NAME+ environment variable.
|
||||
# domain:: the domain for which this cookie applies.
|
||||
# expires:: the time at which this cookie expires, as a +Time+ object.
|
||||
# secure:: whether this cookie is a secure cookie or not (default to
|
||||
# false). Secure cookies are only transmitted to HTTPS
|
||||
# servers.
|
||||
#
|
||||
# These keywords correspond to attributes of the cookie object.
|
||||
def initialize(name = "", *value)
|
||||
@domain = nil
|
||||
@expires = nil
|
||||
if name.kind_of?(String)
|
||||
@name = name
|
||||
%r|^(.*/)|.match(ENV["SCRIPT_NAME"])
|
||||
@path = ($1 or "")
|
||||
@secure = false
|
||||
return super(value)
|
||||
end
|
||||
|
||||
options = name
|
||||
unless options.has_key?("name")
|
||||
raise ArgumentError, "`name' required"
|
||||
end
|
||||
|
||||
@name = options["name"]
|
||||
value = Array(options["value"])
|
||||
# simple support for IE
|
||||
if options["path"]
|
||||
@path = options["path"]
|
||||
else
|
||||
%r|^(.*/)|.match(ENV["SCRIPT_NAME"])
|
||||
@path = ($1 or "")
|
||||
end
|
||||
@domain = options["domain"]
|
||||
@expires = options["expires"]
|
||||
@secure = options["secure"] == true ? true : false
|
||||
|
||||
super(value)
|
||||
end
|
||||
|
||||
# Name of this cookie, as a +String+
|
||||
attr_accessor :name
|
||||
# Path for which this cookie applies, as a +String+
|
||||
attr_accessor :path
|
||||
# Domain for which this cookie applies, as a +String+
|
||||
attr_accessor :domain
|
||||
# Time at which this cookie expires, as a +Time+
|
||||
attr_accessor :expires
|
||||
# True if this cookie is secure; false otherwise
|
||||
attr_reader("secure")
|
||||
|
||||
# Returns the value or list of values for this cookie.
|
||||
def value
|
||||
self
|
||||
end
|
||||
|
||||
# Replaces the value of this cookie with a new value or list of values.
|
||||
def value=(val)
|
||||
replace(Array(val))
|
||||
end
|
||||
|
||||
# Set whether the Cookie is a secure cookie or not.
|
||||
#
|
||||
# +val+ must be a boolean.
|
||||
def secure=(val)
|
||||
@secure = val if val == true or val == false
|
||||
@secure
|
||||
end
|
||||
|
||||
# Convert the Cookie to its string representation.
|
||||
def to_s
|
||||
val = collect{|v| CGI.escape(v) }.join("&")
|
||||
buf = "#{@name}=#{val}"
|
||||
buf << "; domain=#{@domain}" if @domain
|
||||
buf << "; path=#{@path}" if @path
|
||||
buf << "; expires=#{CGI::rfc1123_date(@expires)}" if @expires
|
||||
buf << "; secure" if @secure == true
|
||||
buf
|
||||
end
|
||||
|
||||
# Parse a raw cookie string into a hash of cookie-name=>Cookie
|
||||
# pairs.
|
||||
#
|
||||
# cookies = CGI::Cookie.parse("raw_cookie_string")
|
||||
# # { "name1" => cookie1, "name2" => cookie2, ... }
|
||||
#
|
||||
def self.parse(raw_cookie)
|
||||
cookies = Hash.new([])
|
||||
return cookies unless raw_cookie
|
||||
|
||||
raw_cookie.split(/[;,]\s?/).each do |pairs|
|
||||
name, values = pairs.split('=',2)
|
||||
next unless name and values
|
||||
name = CGI.unescape(name)
|
||||
values ||= ""
|
||||
values = values.split('&').collect{|v| CGI.unescape(v,@@accept_charset) }
|
||||
if cookies.has_key?(name)
|
||||
values = cookies[name].value + values
|
||||
end
|
||||
cookies[name] = Cookie.new(name, *values)
|
||||
end
|
||||
|
||||
cookies
|
||||
end
|
||||
|
||||
# A summary of cookie string.
|
||||
def inspect
|
||||
"#<CGI::Cookie: #{self.to_s.inspect}>"
|
||||
end
|
||||
|
||||
end # class Cookie
|
||||
end
|
||||
|
||||
|
||||
859
ruby/lib/ruby/2.1.0/cgi/core.rb
Normal file
859
ruby/lib/ruby/2.1.0/cgi/core.rb
Normal file
@@ -0,0 +1,859 @@
|
||||
#--
|
||||
# Methods for generating HTML, parsing CGI-related parameters, and
|
||||
# generating HTTP responses.
|
||||
#++
|
||||
class CGI
|
||||
|
||||
$CGI_ENV = ENV # for FCGI support
|
||||
|
||||
# String for carriage return
|
||||
CR = "\015"
|
||||
|
||||
# String for linefeed
|
||||
LF = "\012"
|
||||
|
||||
# Standard internet newline sequence
|
||||
EOL = CR + LF
|
||||
|
||||
REVISION = '$Id: core.rb 44184 2013-12-13 16:11:12Z akr $' #:nodoc:
|
||||
|
||||
# Whether processing will be required in binary vs text
|
||||
NEEDS_BINMODE = File::BINARY != 0
|
||||
|
||||
# Path separators in different environments.
|
||||
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
|
||||
|
||||
# HTTP status codes.
|
||||
HTTP_STATUS = {
|
||||
"OK" => "200 OK",
|
||||
"PARTIAL_CONTENT" => "206 Partial Content",
|
||||
"MULTIPLE_CHOICES" => "300 Multiple Choices",
|
||||
"MOVED" => "301 Moved Permanently",
|
||||
"REDIRECT" => "302 Found",
|
||||
"NOT_MODIFIED" => "304 Not Modified",
|
||||
"BAD_REQUEST" => "400 Bad Request",
|
||||
"AUTH_REQUIRED" => "401 Authorization Required",
|
||||
"FORBIDDEN" => "403 Forbidden",
|
||||
"NOT_FOUND" => "404 Not Found",
|
||||
"METHOD_NOT_ALLOWED" => "405 Method Not Allowed",
|
||||
"NOT_ACCEPTABLE" => "406 Not Acceptable",
|
||||
"LENGTH_REQUIRED" => "411 Length Required",
|
||||
"PRECONDITION_FAILED" => "412 Precondition Failed",
|
||||
"SERVER_ERROR" => "500 Internal Server Error",
|
||||
"NOT_IMPLEMENTED" => "501 Method Not Implemented",
|
||||
"BAD_GATEWAY" => "502 Bad Gateway",
|
||||
"VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"
|
||||
}
|
||||
|
||||
# :startdoc:
|
||||
|
||||
# Synonym for ENV.
|
||||
def env_table
|
||||
ENV
|
||||
end
|
||||
|
||||
# Synonym for $stdin.
|
||||
def stdinput
|
||||
$stdin
|
||||
end
|
||||
|
||||
# Synonym for $stdout.
|
||||
def stdoutput
|
||||
$stdout
|
||||
end
|
||||
|
||||
private :env_table, :stdinput, :stdoutput
|
||||
|
||||
# Create an HTTP header block as a string.
|
||||
#
|
||||
# :call-seq:
|
||||
# http_header(content_type_string="text/html")
|
||||
# http_header(headers_hash)
|
||||
#
|
||||
# Includes the empty line that ends the header block.
|
||||
#
|
||||
# +content_type_string+::
|
||||
# If this form is used, this string is the <tt>Content-Type</tt>
|
||||
# +headers_hash+::
|
||||
# A Hash of header values. The following header keys are recognized:
|
||||
#
|
||||
# type:: The Content-Type header. Defaults to "text/html"
|
||||
# charset:: The charset of the body, appended to the Content-Type header.
|
||||
# nph:: A boolean value. If true, prepend protocol string and status
|
||||
# code, and date; and sets default values for "server" and
|
||||
# "connection" if not explicitly set.
|
||||
# status::
|
||||
# The HTTP status code as a String, returned as the Status header. The
|
||||
# values are:
|
||||
#
|
||||
# OK:: 200 OK
|
||||
# PARTIAL_CONTENT:: 206 Partial Content
|
||||
# MULTIPLE_CHOICES:: 300 Multiple Choices
|
||||
# MOVED:: 301 Moved Permanently
|
||||
# REDIRECT:: 302 Found
|
||||
# NOT_MODIFIED:: 304 Not Modified
|
||||
# BAD_REQUEST:: 400 Bad Request
|
||||
# AUTH_REQUIRED:: 401 Authorization Required
|
||||
# FORBIDDEN:: 403 Forbidden
|
||||
# NOT_FOUND:: 404 Not Found
|
||||
# METHOD_NOT_ALLOWED:: 405 Method Not Allowed
|
||||
# NOT_ACCEPTABLE:: 406 Not Acceptable
|
||||
# LENGTH_REQUIRED:: 411 Length Required
|
||||
# PRECONDITION_FAILED:: 412 Precondition Failed
|
||||
# SERVER_ERROR:: 500 Internal Server Error
|
||||
# NOT_IMPLEMENTED:: 501 Method Not Implemented
|
||||
# BAD_GATEWAY:: 502 Bad Gateway
|
||||
# VARIANT_ALSO_VARIES:: 506 Variant Also Negotiates
|
||||
#
|
||||
# server:: The server software, returned as the Server header.
|
||||
# connection:: The connection type, returned as the Connection header (for
|
||||
# instance, "close".
|
||||
# length:: The length of the content that will be sent, returned as the
|
||||
# Content-Length header.
|
||||
# language:: The language of the content, returned as the Content-Language
|
||||
# header.
|
||||
# expires:: The time on which the current content expires, as a +Time+
|
||||
# object, returned as the Expires header.
|
||||
# cookie::
|
||||
# A cookie or cookies, returned as one or more Set-Cookie headers. The
|
||||
# value can be the literal string of the cookie; a CGI::Cookie object;
|
||||
# an Array of literal cookie strings or Cookie objects; or a hash all of
|
||||
# whose values are literal cookie strings or Cookie objects.
|
||||
#
|
||||
# These cookies are in addition to the cookies held in the
|
||||
# @output_cookies field.
|
||||
#
|
||||
# Other headers can also be set; they are appended as key: value.
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# http_header
|
||||
# # Content-Type: text/html
|
||||
#
|
||||
# http_header("text/plain")
|
||||
# # Content-Type: text/plain
|
||||
#
|
||||
# http_header("nph" => true,
|
||||
# "status" => "OK", # == "200 OK"
|
||||
# # "status" => "200 GOOD",
|
||||
# "server" => ENV['SERVER_SOFTWARE'],
|
||||
# "connection" => "close",
|
||||
# "type" => "text/html",
|
||||
# "charset" => "iso-2022-jp",
|
||||
# # Content-Type: text/html; charset=iso-2022-jp
|
||||
# "length" => 103,
|
||||
# "language" => "ja",
|
||||
# "expires" => Time.now + 30,
|
||||
# "cookie" => [cookie1, cookie2],
|
||||
# "my_header1" => "my_value"
|
||||
# "my_header2" => "my_value")
|
||||
#
|
||||
# This method does not perform charset conversion.
|
||||
def http_header(options='text/html')
|
||||
if options.is_a?(String)
|
||||
content_type = options
|
||||
buf = _header_for_string(content_type)
|
||||
elsif options.is_a?(Hash)
|
||||
if options.size == 1 && options.has_key?('type')
|
||||
content_type = options['type']
|
||||
buf = _header_for_string(content_type)
|
||||
else
|
||||
buf = _header_for_hash(options.dup)
|
||||
end
|
||||
else
|
||||
raise ArgumentError.new("expected String or Hash but got #{options.class}")
|
||||
end
|
||||
if defined?(MOD_RUBY)
|
||||
_header_for_modruby(buf)
|
||||
return ''
|
||||
else
|
||||
buf << EOL # empty line of separator
|
||||
return buf
|
||||
end
|
||||
end # http_header()
|
||||
|
||||
# This method is an alias for #http_header, when HTML5 tag maker is inactive.
|
||||
#
|
||||
# NOTE: use #http_header to create HTTP header blocks, this alias is only
|
||||
# provided for backwards compatibility.
|
||||
#
|
||||
# Using #header with the HTML5 tag maker will create a <header> element.
|
||||
alias :header :http_header
|
||||
|
||||
def _header_for_string(content_type) #:nodoc:
|
||||
buf = ''
|
||||
if nph?()
|
||||
buf << "#{$CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'} 200 OK#{EOL}"
|
||||
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
|
||||
buf << "Server: #{$CGI_ENV['SERVER_SOFTWARE']}#{EOL}"
|
||||
buf << "Connection: close#{EOL}"
|
||||
end
|
||||
buf << "Content-Type: #{content_type}#{EOL}"
|
||||
if @output_cookies
|
||||
@output_cookies.each {|cookie| buf << "Set-Cookie: #{cookie}#{EOL}" }
|
||||
end
|
||||
return buf
|
||||
end # _header_for_string
|
||||
private :_header_for_string
|
||||
|
||||
def _header_for_hash(options) #:nodoc:
|
||||
buf = ''
|
||||
## add charset to option['type']
|
||||
options['type'] ||= 'text/html'
|
||||
charset = options.delete('charset')
|
||||
options['type'] += "; charset=#{charset}" if charset
|
||||
## NPH
|
||||
options.delete('nph') if defined?(MOD_RUBY)
|
||||
if options.delete('nph') || nph?()
|
||||
protocol = $CGI_ENV['SERVER_PROTOCOL'] || 'HTTP/1.0'
|
||||
status = options.delete('status')
|
||||
status = HTTP_STATUS[status] || status || '200 OK'
|
||||
buf << "#{protocol} #{status}#{EOL}"
|
||||
buf << "Date: #{CGI.rfc1123_date(Time.now)}#{EOL}"
|
||||
options['server'] ||= $CGI_ENV['SERVER_SOFTWARE'] || ''
|
||||
options['connection'] ||= 'close'
|
||||
end
|
||||
## common headers
|
||||
status = options.delete('status')
|
||||
buf << "Status: #{HTTP_STATUS[status] || status}#{EOL}" if status
|
||||
server = options.delete('server')
|
||||
buf << "Server: #{server}#{EOL}" if server
|
||||
connection = options.delete('connection')
|
||||
buf << "Connection: #{connection}#{EOL}" if connection
|
||||
type = options.delete('type')
|
||||
buf << "Content-Type: #{type}#{EOL}" #if type
|
||||
length = options.delete('length')
|
||||
buf << "Content-Length: #{length}#{EOL}" if length
|
||||
language = options.delete('language')
|
||||
buf << "Content-Language: #{language}#{EOL}" if language
|
||||
expires = options.delete('expires')
|
||||
buf << "Expires: #{CGI.rfc1123_date(expires)}#{EOL}" if expires
|
||||
## cookie
|
||||
if cookie = options.delete('cookie')
|
||||
case cookie
|
||||
when String, Cookie
|
||||
buf << "Set-Cookie: #{cookie}#{EOL}"
|
||||
when Array
|
||||
arr = cookie
|
||||
arr.each {|c| buf << "Set-Cookie: #{c}#{EOL}" }
|
||||
when Hash
|
||||
hash = cookie
|
||||
hash.each_value {|c| buf << "Set-Cookie: #{c}#{EOL}" }
|
||||
end
|
||||
end
|
||||
if @output_cookies
|
||||
@output_cookies.each {|c| buf << "Set-Cookie: #{c}#{EOL}" }
|
||||
end
|
||||
## other headers
|
||||
options.each do |key, value|
|
||||
buf << "#{key}: #{value}#{EOL}"
|
||||
end
|
||||
return buf
|
||||
end # _header_for_hash
|
||||
private :_header_for_hash
|
||||
|
||||
def nph? #:nodoc:
|
||||
return /IIS\/(\d+)/.match($CGI_ENV['SERVER_SOFTWARE']) && $1.to_i < 5
|
||||
end
|
||||
|
||||
def _header_for_modruby(buf) #:nodoc:
|
||||
request = Apache::request
|
||||
buf.scan(/([^:]+): (.+)#{EOL}/o) do |name, value|
|
||||
warn sprintf("name:%s value:%s\n", name, value) if $DEBUG
|
||||
case name
|
||||
when 'Set-Cookie'
|
||||
request.headers_out.add(name, value)
|
||||
when /^status$/i
|
||||
request.status_line = value
|
||||
request.status = value.to_i
|
||||
when /^content-type$/i
|
||||
request.content_type = value
|
||||
when /^content-encoding$/i
|
||||
request.content_encoding = value
|
||||
when /^location$/i
|
||||
request.status = 302 if request.status == 200
|
||||
request.headers_out[name] = value
|
||||
else
|
||||
request.headers_out[name] = value
|
||||
end
|
||||
end
|
||||
request.send_http_header
|
||||
return ''
|
||||
end
|
||||
private :_header_for_modruby
|
||||
|
||||
# Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
|
||||
#
|
||||
# :call-seq:
|
||||
# cgi.out(content_type_string='text/html')
|
||||
# cgi.out(headers_hash)
|
||||
#
|
||||
# +content_type_string+::
|
||||
# If a string is passed, it is assumed to be the content type.
|
||||
# +headers_hash+::
|
||||
# This is a Hash of headers, similar to that used by #http_header.
|
||||
# +block+::
|
||||
# A block is required and should evaluate to the body of the response.
|
||||
#
|
||||
# <tt>Content-Length</tt> is automatically calculated from the size of
|
||||
# the String returned by the content block.
|
||||
#
|
||||
# If <tt>ENV['REQUEST_METHOD'] == "HEAD"</tt>, then only the header
|
||||
# is output (the content block is still required, but it is ignored).
|
||||
#
|
||||
# If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then the
|
||||
# content is converted to this charset, and the language is set to "ja".
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# cgi = CGI.new
|
||||
# cgi.out{ "string" }
|
||||
# # Content-Type: text/html
|
||||
# # Content-Length: 6
|
||||
# #
|
||||
# # string
|
||||
#
|
||||
# cgi.out("text/plain") { "string" }
|
||||
# # Content-Type: text/plain
|
||||
# # Content-Length: 6
|
||||
# #
|
||||
# # string
|
||||
#
|
||||
# cgi.out("nph" => true,
|
||||
# "status" => "OK", # == "200 OK"
|
||||
# "server" => ENV['SERVER_SOFTWARE'],
|
||||
# "connection" => "close",
|
||||
# "type" => "text/html",
|
||||
# "charset" => "iso-2022-jp",
|
||||
# # Content-Type: text/html; charset=iso-2022-jp
|
||||
# "language" => "ja",
|
||||
# "expires" => Time.now + (3600 * 24 * 30),
|
||||
# "cookie" => [cookie1, cookie2],
|
||||
# "my_header1" => "my_value",
|
||||
# "my_header2" => "my_value") { "string" }
|
||||
# # HTTP/1.1 200 OK
|
||||
# # Date: Sun, 15 May 2011 17:35:54 GMT
|
||||
# # Server: Apache 2.2.0
|
||||
# # Connection: close
|
||||
# # Content-Type: text/html; charset=iso-2022-jp
|
||||
# # Content-Length: 6
|
||||
# # Content-Language: ja
|
||||
# # Expires: Tue, 14 Jun 2011 17:35:54 GMT
|
||||
# # Set-Cookie: foo
|
||||
# # Set-Cookie: bar
|
||||
# # my_header1: my_value
|
||||
# # my_header2: my_value
|
||||
# #
|
||||
# # string
|
||||
def out(options = "text/html") # :yield:
|
||||
|
||||
options = { "type" => options } if options.kind_of?(String)
|
||||
content = yield
|
||||
options["length"] = content.bytesize.to_s
|
||||
output = stdoutput
|
||||
output.binmode if defined? output.binmode
|
||||
output.print http_header(options)
|
||||
output.print content unless "HEAD" == env_table['REQUEST_METHOD']
|
||||
end
|
||||
|
||||
|
||||
# Print an argument or list of arguments to the default output stream
|
||||
#
|
||||
# cgi = CGI.new
|
||||
# cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
|
||||
def print(*options)
|
||||
stdoutput.print(*options)
|
||||
end
|
||||
|
||||
# Parse an HTTP query string into a hash of key=>value pairs.
|
||||
#
|
||||
# params = CGI::parse("query_string")
|
||||
# # {"name1" => ["value1", "value2", ...],
|
||||
# # "name2" => ["value1", "value2", ...], ... }
|
||||
#
|
||||
def CGI::parse(query)
|
||||
params = {}
|
||||
query.split(/[&;]/).each do |pairs|
|
||||
key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
|
||||
|
||||
next unless key
|
||||
|
||||
params[key] ||= []
|
||||
params[key].push(value) if value
|
||||
end
|
||||
|
||||
params.default=[].freeze
|
||||
params
|
||||
end
|
||||
|
||||
# Maximum content length of post data
|
||||
##MAX_CONTENT_LENGTH = 2 * 1024 * 1024
|
||||
|
||||
# Maximum content length of multipart data
|
||||
MAX_MULTIPART_LENGTH = 128 * 1024 * 1024
|
||||
|
||||
# Maximum number of request parameters when multipart
|
||||
MAX_MULTIPART_COUNT = 128
|
||||
|
||||
# Mixin module that provides the following:
|
||||
#
|
||||
# 1. Access to the CGI environment variables as methods. See
|
||||
# documentation to the CGI class for a list of these variables. The
|
||||
# methods are exposed by removing the leading +HTTP_+ (if it exists) and
|
||||
# downcasing the name. For example, +auth_type+ will return the
|
||||
# environment variable +AUTH_TYPE+, and +accept+ will return the value
|
||||
# for +HTTP_ACCEPT+.
|
||||
#
|
||||
# 2. Access to cookies, including the cookies attribute.
|
||||
#
|
||||
# 3. Access to parameters, including the params attribute, and overloading
|
||||
# #[] to perform parameter value lookup by key.
|
||||
#
|
||||
# 4. The initialize_query method, for initializing the above
|
||||
# mechanisms, handling multipart forms, and allowing the
|
||||
# class to be used in "offline" mode.
|
||||
#
|
||||
module QueryExtension
|
||||
|
||||
%w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
|
||||
define_method(env.sub(/^HTTP_/, '').downcase) do
|
||||
(val = env_table[env]) && Integer(val)
|
||||
end
|
||||
end
|
||||
|
||||
%w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
|
||||
PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST
|
||||
REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME
|
||||
SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE
|
||||
|
||||
HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
|
||||
HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST
|
||||
HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env|
|
||||
define_method(env.sub(/^HTTP_/, '').downcase) do
|
||||
env_table[env]
|
||||
end
|
||||
end
|
||||
|
||||
# Get the raw cookies as a string.
|
||||
def raw_cookie
|
||||
env_table["HTTP_COOKIE"]
|
||||
end
|
||||
|
||||
# Get the raw RFC2965 cookies as a string.
|
||||
def raw_cookie2
|
||||
env_table["HTTP_COOKIE2"]
|
||||
end
|
||||
|
||||
# Get the cookies as a hash of cookie-name=>Cookie pairs.
|
||||
attr_accessor :cookies
|
||||
|
||||
# Get the parameters as a hash of name=>values pairs, where
|
||||
# values is an Array.
|
||||
attr_reader :params
|
||||
|
||||
# Get the uploaded files as a hash of name=>values pairs
|
||||
attr_reader :files
|
||||
|
||||
# Set all the parameters.
|
||||
def params=(hash)
|
||||
@params.clear
|
||||
@params.update(hash)
|
||||
end
|
||||
|
||||
##
|
||||
# Parses multipart form elements according to
|
||||
# http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2
|
||||
#
|
||||
# Returns a hash of multipart form parameters with bodies of type StringIO or
|
||||
# Tempfile depending on whether the multipart form element exceeds 10 KB
|
||||
#
|
||||
# params[name => body]
|
||||
#
|
||||
def read_multipart(boundary, content_length)
|
||||
## read first boundary
|
||||
stdin = stdinput
|
||||
first_line = "--#{boundary}#{EOL}"
|
||||
content_length -= first_line.bytesize
|
||||
status = stdin.read(first_line.bytesize)
|
||||
raise EOFError.new("no content body") unless status
|
||||
raise EOFError.new("bad content body") unless first_line == status
|
||||
## parse and set params
|
||||
params = {}
|
||||
@files = {}
|
||||
boundary_rexp = /--#{Regexp.quote(boundary)}(#{EOL}|--)/
|
||||
boundary_size = "#{EOL}--#{boundary}#{EOL}".bytesize
|
||||
boundary_end = nil
|
||||
buf = ''
|
||||
bufsize = 10 * 1024
|
||||
max_count = MAX_MULTIPART_COUNT
|
||||
n = 0
|
||||
tempfiles = []
|
||||
while true
|
||||
(n += 1) < max_count or raise StandardError.new("too many parameters.")
|
||||
## create body (StringIO or Tempfile)
|
||||
body = create_body(bufsize < content_length)
|
||||
tempfiles << body if defined?(Tempfile) && body.kind_of?(Tempfile)
|
||||
class << body
|
||||
if method_defined?(:path)
|
||||
alias local_path path
|
||||
else
|
||||
def local_path
|
||||
nil
|
||||
end
|
||||
end
|
||||
attr_reader :original_filename, :content_type
|
||||
end
|
||||
## find head and boundary
|
||||
head = nil
|
||||
separator = EOL * 2
|
||||
until head && matched = boundary_rexp.match(buf)
|
||||
if !head && pos = buf.index(separator)
|
||||
len = pos + EOL.bytesize
|
||||
head = buf[0, len]
|
||||
buf = buf[(pos+separator.bytesize)..-1]
|
||||
else
|
||||
if head && buf.size > boundary_size
|
||||
len = buf.size - boundary_size
|
||||
body.print(buf[0, len])
|
||||
buf[0, len] = ''
|
||||
end
|
||||
c = stdin.read(bufsize < content_length ? bufsize : content_length)
|
||||
raise EOFError.new("bad content body") if c.nil? || c.empty?
|
||||
buf << c
|
||||
content_length -= c.bytesize
|
||||
end
|
||||
end
|
||||
## read to end of boundary
|
||||
m = matched
|
||||
len = m.begin(0)
|
||||
s = buf[0, len]
|
||||
if s =~ /(\r?\n)\z/
|
||||
s = buf[0, len - $1.bytesize]
|
||||
end
|
||||
body.print(s)
|
||||
buf = buf[m.end(0)..-1]
|
||||
boundary_end = m[1]
|
||||
content_length = -1 if boundary_end == '--'
|
||||
## reset file cursor position
|
||||
body.rewind
|
||||
## original filename
|
||||
/Content-Disposition:.* filename=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
|
||||
filename = $1 || $2 || ''
|
||||
filename = CGI.unescape(filename) if unescape_filename?()
|
||||
body.instance_variable_set(:@original_filename, filename.taint)
|
||||
## content type
|
||||
/Content-Type: (.*)/i.match(head)
|
||||
(content_type = $1 || '').chomp!
|
||||
body.instance_variable_set(:@content_type, content_type.taint)
|
||||
## query parameter name
|
||||
/Content-Disposition:.* name=(?:"(.*?)"|([^;\r\n]*))/i.match(head)
|
||||
name = $1 || $2 || ''
|
||||
if body.original_filename.empty?
|
||||
value=body.read.dup.force_encoding(@accept_charset)
|
||||
body.unlink if defined?(Tempfile) && body.kind_of?(Tempfile)
|
||||
(params[name] ||= []) << value
|
||||
unless value.valid_encoding?
|
||||
if @accept_charset_error_block
|
||||
@accept_charset_error_block.call(name,value)
|
||||
else
|
||||
raise InvalidEncoding,"Accept-Charset encoding error"
|
||||
end
|
||||
end
|
||||
class << params[name].last;self;end.class_eval do
|
||||
define_method(:read){self}
|
||||
define_method(:original_filename){""}
|
||||
define_method(:content_type){""}
|
||||
end
|
||||
else
|
||||
(params[name] ||= []) << body
|
||||
@files[name]=body
|
||||
end
|
||||
## break loop
|
||||
break if content_length == -1
|
||||
end
|
||||
raise EOFError, "bad boundary end of body part" unless boundary_end =~ /--/
|
||||
params.default = []
|
||||
params
|
||||
rescue Exception
|
||||
if tempfiles
|
||||
tempfiles.each {|t|
|
||||
if t.path
|
||||
t.unlink
|
||||
end
|
||||
}
|
||||
end
|
||||
raise
|
||||
end # read_multipart
|
||||
private :read_multipart
|
||||
def create_body(is_large) #:nodoc:
|
||||
if is_large
|
||||
require 'tempfile'
|
||||
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
|
||||
else
|
||||
begin
|
||||
require 'stringio'
|
||||
body = StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
|
||||
rescue LoadError
|
||||
require 'tempfile'
|
||||
body = Tempfile.new('CGI', encoding: Encoding::ASCII_8BIT)
|
||||
end
|
||||
end
|
||||
body.binmode if defined? body.binmode
|
||||
return body
|
||||
end
|
||||
def unescape_filename? #:nodoc:
|
||||
user_agent = $CGI_ENV['HTTP_USER_AGENT']
|
||||
return /Mac/i.match(user_agent) && /Mozilla/i.match(user_agent) && !/MSIE/i.match(user_agent)
|
||||
end
|
||||
|
||||
# offline mode. read name=value pairs on standard input.
|
||||
def read_from_cmdline
|
||||
require "shellwords"
|
||||
|
||||
string = unless ARGV.empty?
|
||||
ARGV.join(' ')
|
||||
else
|
||||
if STDIN.tty?
|
||||
STDERR.print(
|
||||
%|(offline mode: enter name=value pairs on standard input)\n|
|
||||
)
|
||||
end
|
||||
array = readlines rescue nil
|
||||
if not array.nil?
|
||||
array.join(' ').gsub(/\n/n, '')
|
||||
else
|
||||
""
|
||||
end
|
||||
end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
|
||||
|
||||
words = Shellwords.shellwords(string)
|
||||
|
||||
if words.find{|x| /=/n.match(x) }
|
||||
words.join('&')
|
||||
else
|
||||
words.join('+')
|
||||
end
|
||||
end
|
||||
private :read_from_cmdline
|
||||
|
||||
# A wrapper class to use a StringIO object as the body and switch
|
||||
# to a TempFile when the passed threshold is passed.
|
||||
# Initialize the data from the query.
|
||||
#
|
||||
# Handles multipart forms (in particular, forms that involve file uploads).
|
||||
# Reads query parameters in the @params field, and cookies into @cookies.
|
||||
def initialize_query()
|
||||
if ("POST" == env_table['REQUEST_METHOD']) and
|
||||
%r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|.match(env_table['CONTENT_TYPE'])
|
||||
raise StandardError.new("too large multipart data.") if env_table['CONTENT_LENGTH'].to_i > MAX_MULTIPART_LENGTH
|
||||
boundary = $1.dup
|
||||
@multipart = true
|
||||
@params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
|
||||
else
|
||||
@multipart = false
|
||||
@params = CGI::parse(
|
||||
case env_table['REQUEST_METHOD']
|
||||
when "GET", "HEAD"
|
||||
if defined?(MOD_RUBY)
|
||||
Apache::request.args or ""
|
||||
else
|
||||
env_table['QUERY_STRING'] or ""
|
||||
end
|
||||
when "POST"
|
||||
stdinput.binmode if defined? stdinput.binmode
|
||||
stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or ''
|
||||
else
|
||||
read_from_cmdline
|
||||
end.dup.force_encoding(@accept_charset)
|
||||
)
|
||||
unless Encoding.find(@accept_charset) == Encoding::ASCII_8BIT
|
||||
@params.each do |key,values|
|
||||
values.each do |value|
|
||||
unless value.valid_encoding?
|
||||
if @accept_charset_error_block
|
||||
@accept_charset_error_block.call(key,value)
|
||||
else
|
||||
raise InvalidEncoding,"Accept-Charset encoding error"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))
|
||||
end
|
||||
private :initialize_query
|
||||
|
||||
# Returns whether the form contained multipart/form-data
|
||||
def multipart?
|
||||
@multipart
|
||||
end
|
||||
|
||||
# Get the value for the parameter with a given key.
|
||||
#
|
||||
# If the parameter has multiple values, only the first will be
|
||||
# retrieved; use #params to get the array of values.
|
||||
def [](key)
|
||||
params = @params[key]
|
||||
return '' unless params
|
||||
value = params[0]
|
||||
if @multipart
|
||||
if value
|
||||
return value
|
||||
elsif defined? StringIO
|
||||
StringIO.new("".force_encoding(Encoding::ASCII_8BIT))
|
||||
else
|
||||
Tempfile.new("CGI",encoding: Encoding::ASCII_8BIT)
|
||||
end
|
||||
else
|
||||
str = if value then value.dup else "" end
|
||||
str
|
||||
end
|
||||
end
|
||||
|
||||
# Return all query parameter names as an array of String.
|
||||
def keys(*args)
|
||||
@params.keys(*args)
|
||||
end
|
||||
|
||||
# Returns true if a given query string parameter exists.
|
||||
def has_key?(*args)
|
||||
@params.has_key?(*args)
|
||||
end
|
||||
alias key? has_key?
|
||||
alias include? has_key?
|
||||
|
||||
end # QueryExtension
|
||||
|
||||
# Exception raised when there is an invalid encoding detected
|
||||
class InvalidEncoding < Exception; end
|
||||
|
||||
# @@accept_charset is default accept character set.
|
||||
# This default value default is "UTF-8"
|
||||
# If you want to change the default accept character set
|
||||
# when create a new CGI instance, set this:
|
||||
#
|
||||
# CGI.accept_charset = "EUC-JP"
|
||||
#
|
||||
@@accept_charset="UTF-8"
|
||||
|
||||
# Return the accept character set for all new CGI instances.
|
||||
def self.accept_charset
|
||||
@@accept_charset
|
||||
end
|
||||
|
||||
# Set the accept character set for all new CGI instances.
|
||||
def self.accept_charset=(accept_charset)
|
||||
@@accept_charset=accept_charset
|
||||
end
|
||||
|
||||
# Return the accept character set for this CGI instance.
|
||||
attr_reader :accept_charset
|
||||
|
||||
# Create a new CGI instance.
|
||||
#
|
||||
# :call-seq:
|
||||
# CGI.new(tag_maker) { block }
|
||||
# CGI.new(options_hash = {}) { block }
|
||||
#
|
||||
#
|
||||
# <tt>tag_maker</tt>::
|
||||
# This is the same as using the +options_hash+ form with the value <tt>{
|
||||
# :tag_maker => tag_maker }</tt> Note that it is recommended to use the
|
||||
# +options_hash+ form, since it also allows you specify the charset you
|
||||
# will accept.
|
||||
# <tt>options_hash</tt>::
|
||||
# A Hash that recognizes two options:
|
||||
#
|
||||
# <tt>:accept_charset</tt>::
|
||||
# specifies encoding of received query string. If omitted,
|
||||
# <tt>@@accept_charset</tt> is used. If the encoding is not valid, a
|
||||
# CGI::InvalidEncoding will be raised.
|
||||
#
|
||||
# Example. Suppose <tt>@@accept_charset</tt> is "UTF-8"
|
||||
#
|
||||
# when not specified:
|
||||
#
|
||||
# cgi=CGI.new # @accept_charset # => "UTF-8"
|
||||
#
|
||||
# when specified as "EUC-JP":
|
||||
#
|
||||
# cgi=CGI.new(:accept_charset => "EUC-JP") # => "EUC-JP"
|
||||
#
|
||||
# <tt>:tag_maker</tt>::
|
||||
# String that specifies which version of the HTML generation methods to
|
||||
# use. If not specified, no HTML generation methods will be loaded.
|
||||
#
|
||||
# The following values are supported:
|
||||
#
|
||||
# "html3":: HTML 3.x
|
||||
# "html4":: HTML 4.0
|
||||
# "html4Tr":: HTML 4.0 Transitional
|
||||
# "html4Fr":: HTML 4.0 with Framesets
|
||||
# "html5":: HTML 5
|
||||
#
|
||||
# <tt>block</tt>::
|
||||
# If provided, the block is called when an invalid encoding is
|
||||
# encountered. For example:
|
||||
#
|
||||
# encoding_errors={}
|
||||
# cgi=CGI.new(:accept_charset=>"EUC-JP") do |name,value|
|
||||
# encoding_errors[name] = value
|
||||
# end
|
||||
#
|
||||
# Finally, if the CGI object is not created in a standard CGI call
|
||||
# environment (that is, it can't locate REQUEST_METHOD in its environment),
|
||||
# then it will run in "offline" mode. In this mode, it reads its parameters
|
||||
# from the command line or (failing that) from standard input. Otherwise,
|
||||
# cookies and other parameters are parsed automatically from the standard
|
||||
# CGI locations, which varies according to the REQUEST_METHOD.
|
||||
def initialize(options = {}, &block) # :yields: name, value
|
||||
@accept_charset_error_block = block_given? ? block : nil
|
||||
@options={:accept_charset=>@@accept_charset}
|
||||
case options
|
||||
when Hash
|
||||
@options.merge!(options)
|
||||
when String
|
||||
@options[:tag_maker]=options
|
||||
end
|
||||
@accept_charset=@options[:accept_charset]
|
||||
if defined?(MOD_RUBY) && !ENV.key?("GATEWAY_INTERFACE")
|
||||
Apache.request.setup_cgi_env
|
||||
end
|
||||
|
||||
extend QueryExtension
|
||||
@multipart = false
|
||||
|
||||
initialize_query() # set @params, @cookies
|
||||
@output_cookies = nil
|
||||
@output_hidden = nil
|
||||
|
||||
case @options[:tag_maker]
|
||||
when "html3"
|
||||
require 'cgi/html'
|
||||
extend Html3
|
||||
extend HtmlExtension
|
||||
when "html4"
|
||||
require 'cgi/html'
|
||||
extend Html4
|
||||
extend HtmlExtension
|
||||
when "html4Tr"
|
||||
require 'cgi/html'
|
||||
extend Html4Tr
|
||||
extend HtmlExtension
|
||||
when "html4Fr"
|
||||
require 'cgi/html'
|
||||
extend Html4Tr
|
||||
extend Html4Fr
|
||||
extend HtmlExtension
|
||||
when "html5"
|
||||
require 'cgi/html'
|
||||
extend Html5
|
||||
extend HtmlExtension
|
||||
end
|
||||
end
|
||||
|
||||
end # class CGI
|
||||
|
||||
|
||||
1034
ruby/lib/ruby/2.1.0/cgi/html.rb
Normal file
1034
ruby/lib/ruby/2.1.0/cgi/html.rb
Normal file
File diff suppressed because it is too large
Load Diff
531
ruby/lib/ruby/2.1.0/cgi/session.rb
Normal file
531
ruby/lib/ruby/2.1.0/cgi/session.rb
Normal file
@@ -0,0 +1,531 @@
|
||||
#
|
||||
# cgi/session.rb - session support for cgi scripts
|
||||
#
|
||||
# Copyright (C) 2001 Yukihiro "Matz" Matsumoto
|
||||
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
#
|
||||
# Author: Yukihiro "Matz" Matsumoto
|
||||
#
|
||||
# Documentation: William Webber (william@williamwebber.com)
|
||||
|
||||
require 'cgi'
|
||||
require 'tmpdir'
|
||||
|
||||
class CGI
|
||||
|
||||
# == Overview
|
||||
#
|
||||
# This file provides the CGI::Session class, which provides session
|
||||
# support for CGI scripts. A session is a sequence of HTTP requests
|
||||
# and responses linked together and associated with a single client.
|
||||
# Information associated with the session is stored
|
||||
# on the server between requests. A session id is passed between client
|
||||
# and server with every request and response, transparently
|
||||
# to the user. This adds state information to the otherwise stateless
|
||||
# HTTP request/response protocol.
|
||||
#
|
||||
# == Lifecycle
|
||||
#
|
||||
# A CGI::Session instance is created from a CGI object. By default,
|
||||
# this CGI::Session instance will start a new session if none currently
|
||||
# exists, or continue the current session for this client if one does
|
||||
# exist. The +new_session+ option can be used to either always or
|
||||
# never create a new session. See #new() for more details.
|
||||
#
|
||||
# #delete() deletes a session from session storage. It
|
||||
# does not however remove the session id from the client. If the client
|
||||
# makes another request with the same id, the effect will be to start
|
||||
# a new session with the old session's id.
|
||||
#
|
||||
# == Setting and retrieving session data.
|
||||
#
|
||||
# The Session class associates data with a session as key-value pairs.
|
||||
# This data can be set and retrieved by indexing the Session instance
|
||||
# using '[]', much the same as hashes (although other hash methods
|
||||
# are not supported).
|
||||
#
|
||||
# When session processing has been completed for a request, the
|
||||
# session should be closed using the close() method. This will
|
||||
# store the session's state to persistent storage. If you want
|
||||
# to store the session's state to persistent storage without
|
||||
# finishing session processing for this request, call the update()
|
||||
# method.
|
||||
#
|
||||
# == Storing session state
|
||||
#
|
||||
# The caller can specify what form of storage to use for the session's
|
||||
# data with the +database_manager+ option to CGI::Session::new. The
|
||||
# following storage classes are provided as part of the standard library:
|
||||
#
|
||||
# CGI::Session::FileStore:: stores data as plain text in a flat file. Only
|
||||
# works with String data. This is the default
|
||||
# storage type.
|
||||
# CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
|
||||
# only persists for as long as the current Ruby
|
||||
# interpreter instance does.
|
||||
# CGI::Session::PStore:: stores data in Marshalled format. Provided by
|
||||
# cgi/session/pstore.rb. Supports data of any type,
|
||||
# and provides file-locking and transaction support.
|
||||
#
|
||||
# Custom storage types can also be created by defining a class with
|
||||
# the following methods:
|
||||
#
|
||||
# new(session, options)
|
||||
# restore # returns hash of session data.
|
||||
# update
|
||||
# close
|
||||
# delete
|
||||
#
|
||||
# Changing storage type mid-session does not work. Note in particular
|
||||
# that by default the FileStore and PStore session data files have the
|
||||
# same name. If your application switches from one to the other without
|
||||
# making sure that filenames will be different
|
||||
# and clients still have old sessions lying around in cookies, then
|
||||
# things will break nastily!
|
||||
#
|
||||
# == Maintaining the session id.
|
||||
#
|
||||
# Most session state is maintained on the server. However, a session
|
||||
# id must be passed backwards and forwards between client and server
|
||||
# to maintain a reference to this session state.
|
||||
#
|
||||
# The simplest way to do this is via cookies. The CGI::Session class
|
||||
# provides transparent support for session id communication via cookies
|
||||
# if the client has cookies enabled.
|
||||
#
|
||||
# If the client has cookies disabled, the session id must be included
|
||||
# as a parameter of all requests sent by the client to the server. The
|
||||
# CGI::Session class in conjunction with the CGI class will transparently
|
||||
# add the session id as a hidden input field to all forms generated
|
||||
# using the CGI#form() HTML generation method. No built-in support is
|
||||
# provided for other mechanisms, such as URL re-writing. The caller is
|
||||
# responsible for extracting the session id from the session_id
|
||||
# attribute and manually encoding it in URLs and adding it as a hidden
|
||||
# input to HTML forms created by other mechanisms. Also, session expiry
|
||||
# is not automatically handled.
|
||||
#
|
||||
# == Examples of use
|
||||
#
|
||||
# === Setting the user's name
|
||||
#
|
||||
# require 'cgi'
|
||||
# require 'cgi/session'
|
||||
# require 'cgi/session/pstore' # provides CGI::Session::PStore
|
||||
#
|
||||
# cgi = CGI.new("html4")
|
||||
#
|
||||
# session = CGI::Session.new(cgi,
|
||||
# 'database_manager' => CGI::Session::PStore, # use PStore
|
||||
# 'session_key' => '_rb_sess_id', # custom session key
|
||||
# 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
|
||||
# 'prefix' => 'pstore_sid_') # PStore option
|
||||
# if cgi.has_key?('user_name') and cgi['user_name'] != ''
|
||||
# # coerce to String: cgi[] returns the
|
||||
# # string-like CGI::QueryExtension::Value
|
||||
# session['user_name'] = cgi['user_name'].to_s
|
||||
# elsif !session['user_name']
|
||||
# session['user_name'] = "guest"
|
||||
# end
|
||||
# session.close
|
||||
#
|
||||
# === Creating a new session safely
|
||||
#
|
||||
# require 'cgi'
|
||||
# require 'cgi/session'
|
||||
#
|
||||
# cgi = CGI.new("html4")
|
||||
#
|
||||
# # We make sure to delete an old session if one exists,
|
||||
# # not just to free resources, but to prevent the session
|
||||
# # from being maliciously hijacked later on.
|
||||
# begin
|
||||
# session = CGI::Session.new(cgi, 'new_session' => false)
|
||||
# session.delete
|
||||
# rescue ArgumentError # if no old session
|
||||
# end
|
||||
# session = CGI::Session.new(cgi, 'new_session' => true)
|
||||
# session.close
|
||||
#
|
||||
class Session
|
||||
|
||||
class NoSession < RuntimeError #:nodoc:
|
||||
end
|
||||
|
||||
# The id of this session.
|
||||
attr_reader :session_id, :new_session
|
||||
|
||||
def Session::callback(dbman) #:nodoc:
|
||||
Proc.new{
|
||||
dbman[0].close unless dbman.empty?
|
||||
}
|
||||
end
|
||||
|
||||
# Create a new session id.
|
||||
#
|
||||
# The session id is an MD5 hash based upon the time,
|
||||
# a random number, and a constant string. This routine
|
||||
# is used internally for automatically generated
|
||||
# session ids.
|
||||
def create_new_id
|
||||
require 'securerandom'
|
||||
begin
|
||||
session_id = SecureRandom.hex(16)
|
||||
rescue NotImplementedError
|
||||
require 'digest/md5'
|
||||
md5 = Digest::MD5::new
|
||||
now = Time::now
|
||||
md5.update(now.to_s)
|
||||
md5.update(String(now.usec))
|
||||
md5.update(String(rand(0)))
|
||||
md5.update(String($$))
|
||||
md5.update('foobar')
|
||||
session_id = md5.hexdigest
|
||||
end
|
||||
session_id
|
||||
end
|
||||
private :create_new_id
|
||||
|
||||
# Create a new CGI::Session object for +request+.
|
||||
#
|
||||
# +request+ is an instance of the +CGI+ class (see cgi.rb).
|
||||
# +option+ is a hash of options for initialising this
|
||||
# CGI::Session instance. The following options are
|
||||
# recognised:
|
||||
#
|
||||
# session_key:: the parameter name used for the session id.
|
||||
# Defaults to '_session_id'.
|
||||
# session_id:: the session id to use. If not provided, then
|
||||
# it is retrieved from the +session_key+ parameter
|
||||
# of the request, or automatically generated for
|
||||
# a new session.
|
||||
# new_session:: if true, force creation of a new session. If not set,
|
||||
# a new session is only created if none currently
|
||||
# exists. If false, a new session is never created,
|
||||
# and if none currently exists and the +session_id+
|
||||
# option is not set, an ArgumentError is raised.
|
||||
# database_manager:: the name of the class providing storage facilities
|
||||
# for session state persistence. Built-in support
|
||||
# is provided for +FileStore+ (the default),
|
||||
# +MemoryStore+, and +PStore+ (from
|
||||
# cgi/session/pstore.rb). See the documentation for
|
||||
# these classes for more details.
|
||||
#
|
||||
# The following options are also recognised, but only apply if the
|
||||
# session id is stored in a cookie.
|
||||
#
|
||||
# session_expires:: the time the current session expires, as a
|
||||
# +Time+ object. If not set, the session will terminate
|
||||
# when the user's browser is closed.
|
||||
# session_domain:: the hostname domain for which this session is valid.
|
||||
# If not set, defaults to the hostname of the server.
|
||||
# session_secure:: if +true+, this session will only work over HTTPS.
|
||||
# session_path:: the path for which this session applies. Defaults
|
||||
# to the directory of the CGI script.
|
||||
#
|
||||
# +option+ is also passed on to the session storage class initializer; see
|
||||
# the documentation for each session storage class for the options
|
||||
# they support.
|
||||
#
|
||||
# The retrieved or created session is automatically added to +request+
|
||||
# as a cookie, and also to its +output_hidden+ table, which is used
|
||||
# to add hidden input elements to forms.
|
||||
#
|
||||
# *WARNING* the +output_hidden+
|
||||
# fields are surrounded by a <fieldset> tag in HTML 4 generation, which
|
||||
# is _not_ invisible on many browsers; you may wish to disable the
|
||||
# use of fieldsets with code similar to the following
|
||||
# (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-list/37805)
|
||||
#
|
||||
# cgi = CGI.new("html4")
|
||||
# class << cgi
|
||||
# undef_method :fieldset
|
||||
# end
|
||||
#
|
||||
def initialize(request, option={})
|
||||
@new_session = false
|
||||
session_key = option['session_key'] || '_session_id'
|
||||
session_id = option['session_id']
|
||||
unless session_id
|
||||
if option['new_session']
|
||||
session_id = create_new_id
|
||||
@new_session = true
|
||||
end
|
||||
end
|
||||
unless session_id
|
||||
if request.key?(session_key)
|
||||
session_id = request[session_key]
|
||||
session_id = session_id.read if session_id.respond_to?(:read)
|
||||
end
|
||||
unless session_id
|
||||
session_id, = request.cookies[session_key]
|
||||
end
|
||||
unless session_id
|
||||
unless option.fetch('new_session', true)
|
||||
raise ArgumentError, "session_key `%s' should be supplied"%session_key
|
||||
end
|
||||
session_id = create_new_id
|
||||
@new_session = true
|
||||
end
|
||||
end
|
||||
@session_id = session_id
|
||||
dbman = option['database_manager'] || FileStore
|
||||
begin
|
||||
@dbman = dbman::new(self, option)
|
||||
rescue NoSession
|
||||
unless option.fetch('new_session', true)
|
||||
raise ArgumentError, "invalid session_id `%s'"%session_id
|
||||
end
|
||||
session_id = @session_id = create_new_id unless session_id
|
||||
@new_session=true
|
||||
retry
|
||||
end
|
||||
request.instance_eval do
|
||||
@output_hidden = {session_key => session_id} unless option['no_hidden']
|
||||
@output_cookies = [
|
||||
Cookie::new("name" => session_key,
|
||||
"value" => session_id,
|
||||
"expires" => option['session_expires'],
|
||||
"domain" => option['session_domain'],
|
||||
"secure" => option['session_secure'],
|
||||
"path" =>
|
||||
if option['session_path']
|
||||
option['session_path']
|
||||
elsif ENV["SCRIPT_NAME"]
|
||||
File::dirname(ENV["SCRIPT_NAME"])
|
||||
else
|
||||
""
|
||||
end)
|
||||
] unless option['no_cookies']
|
||||
end
|
||||
@dbprot = [@dbman]
|
||||
ObjectSpace::define_finalizer(self, Session::callback(@dbprot))
|
||||
end
|
||||
|
||||
# Retrieve the session data for key +key+.
|
||||
def [](key)
|
||||
@data ||= @dbman.restore
|
||||
@data[key]
|
||||
end
|
||||
|
||||
# Set the session data for key +key+.
|
||||
def []=(key, val)
|
||||
@write_lock ||= true
|
||||
@data ||= @dbman.restore
|
||||
@data[key] = val
|
||||
end
|
||||
|
||||
# Store session data on the server. For some session storage types,
|
||||
# this is a no-op.
|
||||
def update
|
||||
@dbman.update
|
||||
end
|
||||
|
||||
# Store session data on the server and close the session storage.
|
||||
# For some session storage types, this is a no-op.
|
||||
def close
|
||||
@dbman.close
|
||||
@dbprot.clear
|
||||
end
|
||||
|
||||
# Delete the session from storage. Also closes the storage.
|
||||
#
|
||||
# Note that the session's data is _not_ automatically deleted
|
||||
# upon the session expiring.
|
||||
def delete
|
||||
@dbman.delete
|
||||
@dbprot.clear
|
||||
end
|
||||
|
||||
# File-based session storage class.
|
||||
#
|
||||
# Implements session storage as a flat file of 'key=value' values.
|
||||
# This storage type only works directly with String values; the
|
||||
# user is responsible for converting other types to Strings when
|
||||
# storing and from Strings when retrieving.
|
||||
class FileStore
|
||||
# Create a new FileStore instance.
|
||||
#
|
||||
# This constructor is used internally by CGI::Session. The
|
||||
# user does not generally need to call it directly.
|
||||
#
|
||||
# +session+ is the session for which this instance is being
|
||||
# created. The session id must only contain alphanumeric
|
||||
# characters; automatically generated session ids observe
|
||||
# this requirement.
|
||||
#
|
||||
# +option+ is a hash of options for the initializer. The
|
||||
# following options are recognised:
|
||||
#
|
||||
# tmpdir:: the directory to use for storing the FileStore
|
||||
# file. Defaults to Dir::tmpdir (generally "/tmp"
|
||||
# on Unix systems).
|
||||
# prefix:: the prefix to add to the session id when generating
|
||||
# the filename for this session's FileStore file.
|
||||
# Defaults to "cgi_sid_".
|
||||
# suffix:: the prefix to add to the session id when generating
|
||||
# the filename for this session's FileStore file.
|
||||
# Defaults to the empty string.
|
||||
#
|
||||
# This session's FileStore file will be created if it does
|
||||
# not exist, or opened if it does.
|
||||
def initialize(session, option={})
|
||||
dir = option['tmpdir'] || Dir::tmpdir
|
||||
prefix = option['prefix'] || 'cgi_sid_'
|
||||
suffix = option['suffix'] || ''
|
||||
id = session.session_id
|
||||
require 'digest/md5'
|
||||
md5 = Digest::MD5.hexdigest(id)[0,16]
|
||||
@path = dir+"/"+prefix+md5+suffix
|
||||
if File::exist? @path
|
||||
@hash = nil
|
||||
else
|
||||
unless session.new_session
|
||||
raise CGI::Session::NoSession, "uninitialized session"
|
||||
end
|
||||
@hash = {}
|
||||
end
|
||||
end
|
||||
|
||||
# Restore session state from the session's FileStore file.
|
||||
#
|
||||
# Returns the session state as a hash.
|
||||
def restore
|
||||
unless @hash
|
||||
@hash = {}
|
||||
begin
|
||||
lockf = File.open(@path+".lock", "r")
|
||||
lockf.flock File::LOCK_SH
|
||||
f = File.open(@path, 'r')
|
||||
for line in f
|
||||
line.chomp!
|
||||
k, v = line.split('=',2)
|
||||
@hash[CGI::unescape(k)] = Marshal.restore(CGI::unescape(v))
|
||||
end
|
||||
ensure
|
||||
f.close unless f.nil?
|
||||
lockf.close if lockf
|
||||
end
|
||||
end
|
||||
@hash
|
||||
end
|
||||
|
||||
# Save session state to the session's FileStore file.
|
||||
def update
|
||||
return unless @hash
|
||||
begin
|
||||
lockf = File.open(@path+".lock", File::CREAT|File::RDWR, 0600)
|
||||
lockf.flock File::LOCK_EX
|
||||
f = File.open(@path+".new", File::CREAT|File::TRUNC|File::WRONLY, 0600)
|
||||
for k,v in @hash
|
||||
f.printf "%s=%s\n", CGI::escape(k), CGI::escape(String(Marshal.dump(v)))
|
||||
end
|
||||
f.close
|
||||
File.rename @path+".new", @path
|
||||
ensure
|
||||
f.close if f and !f.closed?
|
||||
lockf.close if lockf
|
||||
end
|
||||
end
|
||||
|
||||
# Update and close the session's FileStore file.
|
||||
def close
|
||||
update
|
||||
end
|
||||
|
||||
# Close and delete the session's FileStore file.
|
||||
def delete
|
||||
File::unlink @path+".lock" rescue nil
|
||||
File::unlink @path+".new" rescue nil
|
||||
File::unlink @path rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
# In-memory session storage class.
|
||||
#
|
||||
# Implements session storage as a global in-memory hash. Session
|
||||
# data will only persist for as long as the Ruby interpreter
|
||||
# instance does.
|
||||
class MemoryStore
|
||||
GLOBAL_HASH_TABLE = {} #:nodoc:
|
||||
|
||||
# Create a new MemoryStore instance.
|
||||
#
|
||||
# +session+ is the session this instance is associated with.
|
||||
# +option+ is a list of initialisation options. None are
|
||||
# currently recognised.
|
||||
def initialize(session, option=nil)
|
||||
@session_id = session.session_id
|
||||
unless GLOBAL_HASH_TABLE.key?(@session_id)
|
||||
unless session.new_session
|
||||
raise CGI::Session::NoSession, "uninitialized session"
|
||||
end
|
||||
GLOBAL_HASH_TABLE[@session_id] = {}
|
||||
end
|
||||
end
|
||||
|
||||
# Restore session state.
|
||||
#
|
||||
# Returns session data as a hash.
|
||||
def restore
|
||||
GLOBAL_HASH_TABLE[@session_id]
|
||||
end
|
||||
|
||||
# Update session state.
|
||||
#
|
||||
# A no-op.
|
||||
def update
|
||||
# don't need to update; hash is shared
|
||||
end
|
||||
|
||||
# Close session storage.
|
||||
#
|
||||
# A no-op.
|
||||
def close
|
||||
# don't need to close
|
||||
end
|
||||
|
||||
# Delete the session state.
|
||||
def delete
|
||||
GLOBAL_HASH_TABLE.delete(@session_id)
|
||||
end
|
||||
end
|
||||
|
||||
# Dummy session storage class.
|
||||
#
|
||||
# Implements session storage place holder. No actual storage
|
||||
# will be done.
|
||||
class NullStore
|
||||
# Create a new NullStore instance.
|
||||
#
|
||||
# +session+ is the session this instance is associated with.
|
||||
# +option+ is a list of initialisation options. None are
|
||||
# currently recognised.
|
||||
def initialize(session, option=nil)
|
||||
end
|
||||
|
||||
# Restore (empty) session state.
|
||||
def restore
|
||||
{}
|
||||
end
|
||||
|
||||
# Update session state.
|
||||
#
|
||||
# A no-op.
|
||||
def update
|
||||
end
|
||||
|
||||
# Close session storage.
|
||||
#
|
||||
# A no-op.
|
||||
def close
|
||||
end
|
||||
|
||||
# Delete the session state.
|
||||
#
|
||||
# A no-op.
|
||||
def delete
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
111
ruby/lib/ruby/2.1.0/cgi/session/pstore.rb
Normal file
111
ruby/lib/ruby/2.1.0/cgi/session/pstore.rb
Normal file
@@ -0,0 +1,111 @@
|
||||
#
|
||||
# cgi/session/pstore.rb - persistent storage of marshalled session data
|
||||
#
|
||||
# Documentation: William Webber (william@williamwebber.com)
|
||||
#
|
||||
# == Overview
|
||||
#
|
||||
# This file provides the CGI::Session::PStore class, which builds
|
||||
# persistent of session data on top of the pstore library. See
|
||||
# cgi/session.rb for more details on session storage managers.
|
||||
|
||||
require 'cgi/session'
|
||||
require 'pstore'
|
||||
|
||||
class CGI
|
||||
class Session
|
||||
# PStore-based session storage class.
|
||||
#
|
||||
# This builds upon the top-level PStore class provided by the
|
||||
# library file pstore.rb. Session data is marshalled and stored
|
||||
# in a file. File locking and transaction services are provided.
|
||||
class PStore
|
||||
# Create a new CGI::Session::PStore instance
|
||||
#
|
||||
# This constructor is used internally by CGI::Session. The
|
||||
# user does not generally need to call it directly.
|
||||
#
|
||||
# +session+ is the session for which this instance is being
|
||||
# created. The session id must only contain alphanumeric
|
||||
# characters; automatically generated session ids observe
|
||||
# this requirement.
|
||||
#
|
||||
# +option+ is a hash of options for the initializer. The
|
||||
# following options are recognised:
|
||||
#
|
||||
# tmpdir:: the directory to use for storing the PStore
|
||||
# file. Defaults to Dir::tmpdir (generally "/tmp"
|
||||
# on Unix systems).
|
||||
# prefix:: the prefix to add to the session id when generating
|
||||
# the filename for this session's PStore file.
|
||||
# Defaults to the empty string.
|
||||
#
|
||||
# This session's PStore file will be created if it does
|
||||
# not exist, or opened if it does.
|
||||
def initialize(session, option={})
|
||||
dir = option['tmpdir'] || Dir::tmpdir
|
||||
prefix = option['prefix'] || ''
|
||||
id = session.session_id
|
||||
require 'digest/md5'
|
||||
md5 = Digest::MD5.hexdigest(id)[0,16]
|
||||
path = dir+"/"+prefix+md5
|
||||
path.untaint
|
||||
if File::exist?(path)
|
||||
@hash = nil
|
||||
else
|
||||
unless session.new_session
|
||||
raise CGI::Session::NoSession, "uninitialized session"
|
||||
end
|
||||
@hash = {}
|
||||
end
|
||||
@p = ::PStore.new(path)
|
||||
@p.transaction do |p|
|
||||
File.chmod(0600, p.path)
|
||||
end
|
||||
end
|
||||
|
||||
# Restore session state from the session's PStore file.
|
||||
#
|
||||
# Returns the session state as a hash.
|
||||
def restore
|
||||
unless @hash
|
||||
@p.transaction do
|
||||
@hash = @p['hash'] || {}
|
||||
end
|
||||
end
|
||||
@hash
|
||||
end
|
||||
|
||||
# Save session state to the session's PStore file.
|
||||
def update
|
||||
@p.transaction do
|
||||
@p['hash'] = @hash
|
||||
end
|
||||
end
|
||||
|
||||
# Update and close the session's PStore file.
|
||||
def close
|
||||
update
|
||||
end
|
||||
|
||||
# Close and delete the session's PStore file.
|
||||
def delete
|
||||
path = @p.path
|
||||
File::unlink path
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
# :enddoc:
|
||||
STDIN.reopen("/dev/null")
|
||||
cgi = CGI.new
|
||||
session = CGI::Session.new(cgi, 'database_manager' => CGI::Session::PStore)
|
||||
session['key'] = {'k' => 'v'}
|
||||
puts session['key'].class
|
||||
fail unless Hash === session['key']
|
||||
puts session['key'].inspect
|
||||
fail unless session['key'].inspect == '{"k"=>"v"}'
|
||||
end
|
||||
202
ruby/lib/ruby/2.1.0/cgi/util.rb
Normal file
202
ruby/lib/ruby/2.1.0/cgi/util.rb
Normal file
@@ -0,0 +1,202 @@
|
||||
class CGI; module Util; end; extend Util; end
|
||||
module CGI::Util
|
||||
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
|
||||
# URL-encode a string.
|
||||
# url_encoded_string = CGI::escape("'Stop!' said Fred")
|
||||
# # => "%27Stop%21%27+said+Fred"
|
||||
def escape(string)
|
||||
encoding = string.encoding
|
||||
string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
|
||||
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
||||
end.tr(' ', '+').force_encoding(encoding)
|
||||
end
|
||||
|
||||
# URL-decode a string with encoding(optional).
|
||||
# string = CGI::unescape("%27Stop%21%27+said+Fred")
|
||||
# # => "'Stop!' said Fred"
|
||||
def unescape(string,encoding=@@accept_charset)
|
||||
str=string.tr('+', ' ').b.gsub(/((?:%[0-9a-fA-F]{2})+)/) do |m|
|
||||
[m.delete('%')].pack('H*')
|
||||
end.force_encoding(encoding)
|
||||
str.valid_encoding? ? str : str.force_encoding(string.encoding)
|
||||
end
|
||||
|
||||
# The set of special characters and their escaped values
|
||||
TABLE_FOR_ESCAPE_HTML__ = {
|
||||
"'" => ''',
|
||||
'&' => '&',
|
||||
'"' => '"',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
}
|
||||
|
||||
# Escape special characters in HTML, namely &\"<>
|
||||
# CGI::escapeHTML('Usage: foo "bar" <baz>')
|
||||
# # => "Usage: foo "bar" <baz>"
|
||||
def escapeHTML(string)
|
||||
string.gsub(/['&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
|
||||
end
|
||||
|
||||
# Unescape a string that has been HTML-escaped
|
||||
# CGI::unescapeHTML("Usage: foo "bar" <baz>")
|
||||
# # => "Usage: foo \"bar\" <baz>"
|
||||
def unescapeHTML(string)
|
||||
return string unless string.include? '&'
|
||||
enc = string.encoding
|
||||
if enc != Encoding::UTF_8 && [Encoding::UTF_16BE, Encoding::UTF_16LE, Encoding::UTF_32BE, Encoding::UTF_32LE].include?(enc)
|
||||
return string.gsub(Regexp.new('&(apos|amp|quot|gt|lt|#[0-9]+|#x[0-9A-Fa-f]+);'.encode(enc))) do
|
||||
case $1.encode(Encoding::US_ASCII)
|
||||
when 'apos' then "'".encode(enc)
|
||||
when 'amp' then '&'.encode(enc)
|
||||
when 'quot' then '"'.encode(enc)
|
||||
when 'gt' then '>'.encode(enc)
|
||||
when 'lt' then '<'.encode(enc)
|
||||
when /\A#0*(\d+)\z/ then $1.to_i.chr(enc)
|
||||
when /\A#x([0-9a-f]+)\z/i then $1.hex.chr(enc)
|
||||
end
|
||||
end
|
||||
end
|
||||
asciicompat = Encoding.compatible?(string, "a")
|
||||
string.gsub(/&(apos|amp|quot|gt|lt|\#[0-9]+|\#[xX][0-9A-Fa-f]+);/) do
|
||||
match = $1.dup
|
||||
case match
|
||||
when 'apos' then "'"
|
||||
when 'amp' then '&'
|
||||
when 'quot' then '"'
|
||||
when 'gt' then '>'
|
||||
when 'lt' then '<'
|
||||
when /\A#0*(\d+)\z/
|
||||
n = $1.to_i
|
||||
if enc == Encoding::UTF_8 or
|
||||
enc == Encoding::ISO_8859_1 && n < 256 or
|
||||
asciicompat && n < 128
|
||||
n.chr(enc)
|
||||
else
|
||||
"&##{$1};"
|
||||
end
|
||||
when /\A#x([0-9a-f]+)\z/i
|
||||
n = $1.hex
|
||||
if enc == Encoding::UTF_8 or
|
||||
enc == Encoding::ISO_8859_1 && n < 256 or
|
||||
asciicompat && n < 128
|
||||
n.chr(enc)
|
||||
else
|
||||
"&#x#{$1};"
|
||||
end
|
||||
else
|
||||
"&#{match};"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Synonym for CGI::escapeHTML(str)
|
||||
def escape_html(str)
|
||||
escapeHTML(str)
|
||||
end
|
||||
|
||||
# Synonym for CGI::unescapeHTML(str)
|
||||
def unescape_html(str)
|
||||
unescapeHTML(str)
|
||||
end
|
||||
|
||||
# Escape only the tags of certain HTML elements in +string+.
|
||||
#
|
||||
# Takes an element or elements or array of elements. Each element
|
||||
# is specified by the name of the element, without angle brackets.
|
||||
# This matches both the start and the end tag of that element.
|
||||
# The attribute list of the open tag will also be escaped (for
|
||||
# instance, the double-quotes surrounding attribute values).
|
||||
#
|
||||
# print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
|
||||
# # "<BR><A HREF="url"></A>"
|
||||
#
|
||||
# print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
|
||||
# # "<BR><A HREF="url"></A>"
|
||||
def escapeElement(string, *elements)
|
||||
elements = elements[0] if elements[0].kind_of?(Array)
|
||||
unless elements.empty?
|
||||
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
|
||||
CGI::escapeHTML($&)
|
||||
end
|
||||
else
|
||||
string
|
||||
end
|
||||
end
|
||||
|
||||
# Undo escaping such as that done by CGI::escapeElement()
|
||||
#
|
||||
# print CGI::unescapeElement(
|
||||
# CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
||||
# # "<BR><A HREF="url"></A>"
|
||||
#
|
||||
# print CGI::unescapeElement(
|
||||
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
||||
# # "<BR><A HREF="url"></A>"
|
||||
def unescapeElement(string, *elements)
|
||||
elements = elements[0] if elements[0].kind_of?(Array)
|
||||
unless elements.empty?
|
||||
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/i) do
|
||||
unescapeHTML($&)
|
||||
end
|
||||
else
|
||||
string
|
||||
end
|
||||
end
|
||||
|
||||
# Synonym for CGI::escapeElement(str)
|
||||
def escape_element(str)
|
||||
escapeElement(str)
|
||||
end
|
||||
|
||||
# Synonym for CGI::unescapeElement(str)
|
||||
def unescape_element(str)
|
||||
unescapeElement(str)
|
||||
end
|
||||
|
||||
# Abbreviated day-of-week names specified by RFC 822
|
||||
RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
|
||||
|
||||
# Abbreviated month names specified by RFC 822
|
||||
RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
|
||||
|
||||
# Format a +Time+ object as a String using the format specified by RFC 1123.
|
||||
#
|
||||
# CGI::rfc1123_date(Time.now)
|
||||
# # Sat, 01 Jan 2000 00:00:00 GMT
|
||||
def rfc1123_date(time)
|
||||
t = time.clone.gmtime
|
||||
return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
|
||||
RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
|
||||
t.hour, t.min, t.sec)
|
||||
end
|
||||
|
||||
# Prettify (indent) an HTML string.
|
||||
#
|
||||
# +string+ is the HTML string to indent. +shift+ is the indentation
|
||||
# unit to use; it defaults to two spaces.
|
||||
#
|
||||
# print CGI::pretty("<HTML><BODY></BODY></HTML>")
|
||||
# # <HTML>
|
||||
# # <BODY>
|
||||
# # </BODY>
|
||||
# # </HTML>
|
||||
#
|
||||
# print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
|
||||
# # <HTML>
|
||||
# # <BODY>
|
||||
# # </BODY>
|
||||
# # </HTML>
|
||||
#
|
||||
def pretty(string, shift = " ")
|
||||
lines = string.gsub(/(?!\A)<.*?>/m, "\n\\0").gsub(/<.*?>(?!\n)/m, "\\0\n")
|
||||
end_pos = 0
|
||||
while end_pos = lines.index(/^<\/(\w+)/, end_pos)
|
||||
element = $1.dup
|
||||
start_pos = lines.rindex(/^\s*<#{element}/i, end_pos)
|
||||
lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/, "\n" + shift) + "__"
|
||||
end
|
||||
lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/, '\1')
|
||||
end
|
||||
|
||||
alias h escapeHTML
|
||||
end
|
||||
400
ruby/lib/ruby/2.1.0/cmath.rb
Normal file
400
ruby/lib/ruby/2.1.0/cmath.rb
Normal file
@@ -0,0 +1,400 @@
|
||||
##
|
||||
# CMath is a library that provides trigonometric and transcendental
|
||||
# functions for complex numbers.
|
||||
#
|
||||
# == Usage
|
||||
#
|
||||
# To start using this library, simply:
|
||||
#
|
||||
# require "cmath"
|
||||
#
|
||||
# Square root of a negative number is a complex number.
|
||||
#
|
||||
# CMath.sqrt(-9) #=> 0+3.0i
|
||||
#
|
||||
|
||||
module CMath
|
||||
|
||||
include Math
|
||||
|
||||
alias exp! exp
|
||||
alias log! log
|
||||
alias log2! log2
|
||||
alias log10! log10
|
||||
alias sqrt! sqrt
|
||||
alias cbrt! cbrt
|
||||
|
||||
alias sin! sin
|
||||
alias cos! cos
|
||||
alias tan! tan
|
||||
|
||||
alias sinh! sinh
|
||||
alias cosh! cosh
|
||||
alias tanh! tanh
|
||||
|
||||
alias asin! asin
|
||||
alias acos! acos
|
||||
alias atan! atan
|
||||
alias atan2! atan2
|
||||
|
||||
alias asinh! asinh
|
||||
alias acosh! acosh
|
||||
alias atanh! atanh
|
||||
|
||||
##
|
||||
# Math::E raised to the +z+ power
|
||||
#
|
||||
# exp(Complex(0,0)) #=> 1.0+0.0i
|
||||
# exp(Complex(0,PI)) #=> -1.0+1.2246467991473532e-16i
|
||||
# exp(Complex(0,PI/2.0)) #=> 6.123233995736766e-17+1.0i
|
||||
def exp(z)
|
||||
begin
|
||||
if z.real?
|
||||
exp!(z)
|
||||
else
|
||||
ere = exp!(z.real)
|
||||
Complex(ere * cos!(z.imag),
|
||||
ere * sin!(z.imag))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the natural logarithm of Complex. If a second argument is given,
|
||||
# it will be the base of logarithm.
|
||||
#
|
||||
# log(Complex(0,0)) #=> -Infinity+0.0i
|
||||
def log(*args)
|
||||
begin
|
||||
z, b = args
|
||||
unless b.nil? || b.kind_of?(Numeric)
|
||||
raise TypeError, "Numeric Number required"
|
||||
end
|
||||
if z.real? and z >= 0 and (b.nil? or b >= 0)
|
||||
log!(*args)
|
||||
else
|
||||
a = Complex(log!(z.abs), z.arg)
|
||||
if b
|
||||
a /= log(b)
|
||||
end
|
||||
a
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the base 2 logarithm of +z+
|
||||
def log2(z)
|
||||
begin
|
||||
if z.real? and z >= 0
|
||||
log2!(z)
|
||||
else
|
||||
log(z) / log!(2)
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the base 10 logarithm of +z+
|
||||
def log10(z)
|
||||
begin
|
||||
if z.real? and z >= 0
|
||||
log10!(z)
|
||||
else
|
||||
log(z) / log!(10)
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Returns the non-negative square root of Complex.
|
||||
# sqrt(-1) #=> 0+1.0i
|
||||
# sqrt(Complex(-1,0)) #=> 0.0+1.0i
|
||||
# sqrt(Complex(0,8)) #=> 2.0+2.0i
|
||||
def sqrt(z)
|
||||
begin
|
||||
if z.real?
|
||||
if z < 0
|
||||
Complex(0, sqrt!(-z))
|
||||
else
|
||||
sqrt!(z)
|
||||
end
|
||||
else
|
||||
if z.imag < 0 ||
|
||||
(z.imag == 0 && z.imag.to_s[0] == '-')
|
||||
sqrt(z.conjugate).conjugate
|
||||
else
|
||||
r = z.abs
|
||||
x = z.real
|
||||
Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
|
||||
end
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the principal value of the cube root of +z+
|
||||
def cbrt(z)
|
||||
z ** (1.0/3)
|
||||
end
|
||||
|
||||
##
|
||||
# returns the sine of +z+, where +z+ is given in radians
|
||||
def sin(z)
|
||||
begin
|
||||
if z.real?
|
||||
sin!(z)
|
||||
else
|
||||
Complex(sin!(z.real) * cosh!(z.imag),
|
||||
cos!(z.real) * sinh!(z.imag))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the cosine of +z+, where +z+ is given in radians
|
||||
def cos(z)
|
||||
begin
|
||||
if z.real?
|
||||
cos!(z)
|
||||
else
|
||||
Complex(cos!(z.real) * cosh!(z.imag),
|
||||
-sin!(z.real) * sinh!(z.imag))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the tangent of +z+, where +z+ is given in radians
|
||||
def tan(z)
|
||||
begin
|
||||
if z.real?
|
||||
tan!(z)
|
||||
else
|
||||
sin(z) / cos(z)
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the hyperbolic sine of +z+, where +z+ is given in radians
|
||||
def sinh(z)
|
||||
begin
|
||||
if z.real?
|
||||
sinh!(z)
|
||||
else
|
||||
Complex(sinh!(z.real) * cos!(z.imag),
|
||||
cosh!(z.real) * sin!(z.imag))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the hyperbolic cosine of +z+, where +z+ is given in radians
|
||||
def cosh(z)
|
||||
begin
|
||||
if z.real?
|
||||
cosh!(z)
|
||||
else
|
||||
Complex(cosh!(z.real) * cos!(z.imag),
|
||||
sinh!(z.real) * sin!(z.imag))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the hyperbolic tangent of +z+, where +z+ is given in radians
|
||||
def tanh(z)
|
||||
begin
|
||||
if z.real?
|
||||
tanh!(z)
|
||||
else
|
||||
sinh(z) / cosh(z)
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the arc sine of +z+
|
||||
def asin(z)
|
||||
begin
|
||||
if z.real? and z >= -1 and z <= 1
|
||||
asin!(z)
|
||||
else
|
||||
(-1.0).i * log(1.0.i * z + sqrt(1.0 - z * z))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the arc cosine of +z+
|
||||
def acos(z)
|
||||
begin
|
||||
if z.real? and z >= -1 and z <= 1
|
||||
acos!(z)
|
||||
else
|
||||
(-1.0).i * log(z + 1.0.i * sqrt(1.0 - z * z))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the arc tangent of +z+
|
||||
def atan(z)
|
||||
begin
|
||||
if z.real?
|
||||
atan!(z)
|
||||
else
|
||||
1.0.i * log((1.0.i + z) / (1.0.i - z)) / 2.0
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the arc tangent of +y+ divided by +x+ using the signs of +y+ and
|
||||
# +x+ to determine the quadrant
|
||||
def atan2(y,x)
|
||||
begin
|
||||
if y.real? and x.real?
|
||||
atan2!(y,x)
|
||||
else
|
||||
(-1.0).i * log((x + 1.0.i * y) / sqrt(x * x + y * y))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the inverse hyperbolic sine of +z+
|
||||
def asinh(z)
|
||||
begin
|
||||
if z.real?
|
||||
asinh!(z)
|
||||
else
|
||||
log(z + sqrt(1.0 + z * z))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the inverse hyperbolic cosine of +z+
|
||||
def acosh(z)
|
||||
begin
|
||||
if z.real? and z >= 1
|
||||
acosh!(z)
|
||||
else
|
||||
log(z + sqrt(z * z - 1.0))
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# returns the inverse hyperbolic tangent of +z+
|
||||
def atanh(z)
|
||||
begin
|
||||
if z.real? and z >= -1 and z <= 1
|
||||
atanh!(z)
|
||||
else
|
||||
log((1.0 + z) / (1.0 - z)) / 2.0
|
||||
end
|
||||
rescue NoMethodError
|
||||
handle_no_method_error
|
||||
end
|
||||
end
|
||||
|
||||
module_function :exp!
|
||||
module_function :exp
|
||||
module_function :log!
|
||||
module_function :log
|
||||
module_function :log2!
|
||||
module_function :log2
|
||||
module_function :log10!
|
||||
module_function :log10
|
||||
module_function :sqrt!
|
||||
module_function :sqrt
|
||||
module_function :cbrt!
|
||||
module_function :cbrt
|
||||
|
||||
module_function :sin!
|
||||
module_function :sin
|
||||
module_function :cos!
|
||||
module_function :cos
|
||||
module_function :tan!
|
||||
module_function :tan
|
||||
|
||||
module_function :sinh!
|
||||
module_function :sinh
|
||||
module_function :cosh!
|
||||
module_function :cosh
|
||||
module_function :tanh!
|
||||
module_function :tanh
|
||||
|
||||
module_function :asin!
|
||||
module_function :asin
|
||||
module_function :acos!
|
||||
module_function :acos
|
||||
module_function :atan!
|
||||
module_function :atan
|
||||
module_function :atan2!
|
||||
module_function :atan2
|
||||
|
||||
module_function :asinh!
|
||||
module_function :asinh
|
||||
module_function :acosh!
|
||||
module_function :acosh
|
||||
module_function :atanh!
|
||||
module_function :atanh
|
||||
|
||||
module_function :frexp
|
||||
module_function :ldexp
|
||||
module_function :hypot
|
||||
module_function :erf
|
||||
module_function :erfc
|
||||
module_function :gamma
|
||||
module_function :lgamma
|
||||
|
||||
private
|
||||
def handle_no_method_error # :nodoc:
|
||||
if $!.name == :real?
|
||||
raise TypeError, "Numeric Number required"
|
||||
else
|
||||
raise
|
||||
end
|
||||
end
|
||||
module_function :handle_no_method_error
|
||||
|
||||
end
|
||||
|
||||
28
ruby/lib/ruby/2.1.0/complex.rb
Normal file
28
ruby/lib/ruby/2.1.0/complex.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# :enddoc:
|
||||
|
||||
warn('lib/complex.rb is deprecated') if $VERBOSE
|
||||
|
||||
require 'cmath'
|
||||
|
||||
unless defined?(Math.exp!)
|
||||
Object.instance_eval{remove_const :Math}
|
||||
Math = CMath
|
||||
end
|
||||
|
||||
def Complex.generic? (other)
|
||||
other.kind_of?(Integer) ||
|
||||
other.kind_of?(Float) ||
|
||||
other.kind_of?(Rational)
|
||||
end
|
||||
|
||||
class Complex
|
||||
|
||||
alias image imag
|
||||
|
||||
end
|
||||
|
||||
class Numeric
|
||||
|
||||
def im() Complex(0, self) end
|
||||
|
||||
end
|
||||
2323
ruby/lib/ruby/2.1.0/csv.rb
Normal file
2323
ruby/lib/ruby/2.1.0/csv.rb
Normal file
File diff suppressed because it is too large
Load Diff
61
ruby/lib/ruby/2.1.0/date.rb
Normal file
61
ruby/lib/ruby/2.1.0/date.rb
Normal file
@@ -0,0 +1,61 @@
|
||||
# date.rb: Written by Tadayoshi Funaba 1998-2011
|
||||
|
||||
require 'date_core'
|
||||
require 'date/format'
|
||||
|
||||
class Date
|
||||
|
||||
class Infinity < Numeric # :nodoc:
|
||||
|
||||
include Comparable
|
||||
|
||||
def initialize(d=1) @d = d <=> 0 end
|
||||
|
||||
def d() @d end
|
||||
|
||||
protected :d
|
||||
|
||||
def zero? () false end
|
||||
def finite? () false end
|
||||
def infinite? () d.nonzero? end
|
||||
def nan? () d.zero? end
|
||||
|
||||
def abs() self.class.new end
|
||||
|
||||
def -@ () self.class.new(-d) end
|
||||
def +@ () self.class.new(+d) end
|
||||
|
||||
def <=> (other)
|
||||
case other
|
||||
when Infinity; return d <=> other.d
|
||||
when Numeric; return d
|
||||
else
|
||||
begin
|
||||
l, r = other.coerce(self)
|
||||
return l <=> r
|
||||
rescue NoMethodError
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def coerce(other)
|
||||
case other
|
||||
when Numeric; return -d, d
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def to_f
|
||||
return 0 if @d == 0
|
||||
if @d > 0
|
||||
Float::INFINITY
|
||||
else
|
||||
-Float::INFINITY
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
1
ruby/lib/ruby/2.1.0/date/format.rb
Normal file
1
ruby/lib/ruby/2.1.0/date/format.rb
Normal file
@@ -0,0 +1 @@
|
||||
# format.rb: Written by Tadayoshi Funaba 1999-2011
|
||||
1087
ruby/lib/ruby/2.1.0/debug.rb
Normal file
1087
ruby/lib/ruby/2.1.0/debug.rb
Normal file
File diff suppressed because it is too large
Load Diff
445
ruby/lib/ruby/2.1.0/delegate.rb
Normal file
445
ruby/lib/ruby/2.1.0/delegate.rb
Normal file
@@ -0,0 +1,445 @@
|
||||
# = delegate -- Support for the Delegation Pattern
|
||||
#
|
||||
# Documentation by James Edward Gray II and Gavin Sinclair
|
||||
|
||||
##
|
||||
# This library provides three different ways to delegate method calls to an
|
||||
# object. The easiest to use is SimpleDelegator. Pass an object to the
|
||||
# constructor and all methods supported by the object will be delegated. This
|
||||
# object can be changed later.
|
||||
#
|
||||
# Going a step further, the top level DelegateClass method allows you to easily
|
||||
# setup delegation through class inheritance. This is considerably more
|
||||
# flexible and thus probably the most common use for this library.
|
||||
#
|
||||
# Finally, if you need full control over the delegation scheme, you can inherit
|
||||
# from the abstract class Delegator and customize as needed. (If you find
|
||||
# yourself needing this control, have a look at Forwardable which is also in
|
||||
# the standard library. It may suit your needs better.)
|
||||
#
|
||||
# SimpleDelegator's implementation serves as a nice example if the use of
|
||||
# Delegator:
|
||||
#
|
||||
# class SimpleDelegator < Delegator
|
||||
# def initialize(obj)
|
||||
# super # pass obj to Delegator constructor, required
|
||||
# @delegate_sd_obj = obj # store obj for future use
|
||||
# end
|
||||
#
|
||||
# def __getobj__
|
||||
# @delegate_sd_obj # return object we are delegating to, required
|
||||
# end
|
||||
#
|
||||
# def __setobj__(obj)
|
||||
# @delegate_sd_obj = obj # change delegation object,
|
||||
# # a feature we're providing
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# == Notes
|
||||
#
|
||||
# Be advised, RDoc will not detect delegated methods.
|
||||
#
|
||||
class Delegator < BasicObject
|
||||
kernel = ::Kernel.dup
|
||||
kernel.class_eval do
|
||||
alias __raise__ raise
|
||||
[:to_s,:inspect,:=~,:!~,:===,:<=>,:eql?,:hash].each do |m|
|
||||
undef_method m
|
||||
end
|
||||
private_instance_methods.each do |m|
|
||||
if /\Ablock_given\?\z|iterator\?\z|\A__.*__\z/ =~ m
|
||||
next
|
||||
end
|
||||
undef_method m
|
||||
end
|
||||
end
|
||||
include kernel
|
||||
|
||||
# :stopdoc:
|
||||
def self.const_missing(n)
|
||||
::Object.const_get(n)
|
||||
end
|
||||
# :startdoc:
|
||||
|
||||
#
|
||||
# Pass in the _obj_ to delegate method calls to. All methods supported by
|
||||
# _obj_ will be delegated to.
|
||||
#
|
||||
def initialize(obj)
|
||||
__setobj__(obj)
|
||||
end
|
||||
|
||||
#
|
||||
# Handles the magic of delegation through \_\_getobj\_\_.
|
||||
#
|
||||
def method_missing(m, *args, &block)
|
||||
r = true
|
||||
target = self.__getobj__ {r = false}
|
||||
begin
|
||||
if r && target.respond_to?(m)
|
||||
target.__send__(m, *args, &block)
|
||||
elsif ::Kernel.respond_to?(m, true)
|
||||
::Kernel.instance_method(m).bind(self).(*args, &block)
|
||||
else
|
||||
super(m, *args, &block)
|
||||
end
|
||||
ensure
|
||||
$@.delete_if {|t| %r"\A#{Regexp.quote(__FILE__)}:(?:#{[__LINE__-7, __LINE__-5, __LINE__-3].join('|')}):"o =~ t} if $@
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Checks for a method provided by this the delegate object by forwarding the
|
||||
# call through \_\_getobj\_\_.
|
||||
#
|
||||
def respond_to_missing?(m, include_private)
|
||||
r = true
|
||||
target = self.__getobj__ {r = false}
|
||||
r &&= target.respond_to?(m, include_private)
|
||||
if r && include_private && !target.respond_to?(m, false)
|
||||
warn "#{caller(3)[0]}: delegator does not forward private method \##{m}"
|
||||
return false
|
||||
end
|
||||
r
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the methods available to this delegate object as the union
|
||||
# of this object's and \_\_getobj\_\_ methods.
|
||||
#
|
||||
def methods(all=true)
|
||||
__getobj__.methods(all) | super
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the methods available to this delegate object as the union
|
||||
# of this object's and \_\_getobj\_\_ public methods.
|
||||
#
|
||||
def public_methods(all=true)
|
||||
__getobj__.public_methods(all) | super
|
||||
end
|
||||
|
||||
#
|
||||
# Returns the methods available to this delegate object as the union
|
||||
# of this object's and \_\_getobj\_\_ protected methods.
|
||||
#
|
||||
def protected_methods(all=true)
|
||||
__getobj__.protected_methods(all) | super
|
||||
end
|
||||
|
||||
# Note: no need to specialize private_methods, since they are not forwarded
|
||||
|
||||
#
|
||||
# Returns true if two objects are considered of equal value.
|
||||
#
|
||||
def ==(obj)
|
||||
return true if obj.equal?(self)
|
||||
self.__getobj__ == obj
|
||||
end
|
||||
|
||||
#
|
||||
# Returns true if two objects are not considered of equal value.
|
||||
#
|
||||
def !=(obj)
|
||||
return false if obj.equal?(self)
|
||||
__getobj__ != obj
|
||||
end
|
||||
|
||||
#
|
||||
# Delegates ! to the \_\_getobj\_\_
|
||||
#
|
||||
def !
|
||||
!__getobj__
|
||||
end
|
||||
|
||||
#
|
||||
# This method must be overridden by subclasses and should return the object
|
||||
# method calls are being delegated to.
|
||||
#
|
||||
def __getobj__
|
||||
__raise__ ::NotImplementedError, "need to define `__getobj__'"
|
||||
end
|
||||
|
||||
#
|
||||
# This method must be overridden by subclasses and change the object delegate
|
||||
# to _obj_.
|
||||
#
|
||||
def __setobj__(obj)
|
||||
__raise__ ::NotImplementedError, "need to define `__setobj__'"
|
||||
end
|
||||
|
||||
#
|
||||
# Serialization support for the object returned by \_\_getobj\_\_.
|
||||
#
|
||||
def marshal_dump
|
||||
ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
|
||||
[
|
||||
:__v2__,
|
||||
ivars, ivars.map{|var| instance_variable_get(var)},
|
||||
__getobj__
|
||||
]
|
||||
end
|
||||
|
||||
#
|
||||
# Reinitializes delegation from a serialized object.
|
||||
#
|
||||
def marshal_load(data)
|
||||
version, vars, values, obj = data
|
||||
if version == :__v2__
|
||||
vars.each_with_index{|var, i| instance_variable_set(var, values[i])}
|
||||
__setobj__(obj)
|
||||
else
|
||||
__setobj__(data)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_clone(obj) # :nodoc:
|
||||
self.__setobj__(obj.__getobj__.clone)
|
||||
end
|
||||
def initialize_dup(obj) # :nodoc:
|
||||
self.__setobj__(obj.__getobj__.dup)
|
||||
end
|
||||
private :initialize_clone, :initialize_dup
|
||||
|
||||
##
|
||||
# :method: trust
|
||||
# Trust both the object returned by \_\_getobj\_\_ and self.
|
||||
#
|
||||
|
||||
##
|
||||
# :method: untrust
|
||||
# Untrust both the object returned by \_\_getobj\_\_ and self.
|
||||
#
|
||||
|
||||
##
|
||||
# :method: taint
|
||||
# Taint both the object returned by \_\_getobj\_\_ and self.
|
||||
#
|
||||
|
||||
##
|
||||
# :method: untaint
|
||||
# Untaint both the object returned by \_\_getobj\_\_ and self.
|
||||
#
|
||||
|
||||
##
|
||||
# :method: freeze
|
||||
# Freeze both the object returned by \_\_getobj\_\_ and self.
|
||||
#
|
||||
|
||||
[:trust, :untrust, :taint, :untaint, :freeze].each do |method|
|
||||
define_method method do
|
||||
__getobj__.send(method)
|
||||
super()
|
||||
end
|
||||
end
|
||||
|
||||
@delegator_api = self.public_instance_methods
|
||||
def self.public_api # :nodoc:
|
||||
@delegator_api
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# A concrete implementation of Delegator, this class provides the means to
|
||||
# delegate all supported method calls to the object passed into the constructor
|
||||
# and even to change the object being delegated to at a later time with
|
||||
# #__setobj__.
|
||||
#
|
||||
# class User
|
||||
# def born_on
|
||||
# Date.new(1989, 09, 10)
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# class UserDecorator < SimpleDelegator
|
||||
# def birth_year
|
||||
# born_on.year
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# decorated_user = UserDecorator.new(User.new)
|
||||
# decorated_user.birth_year #=> 1989
|
||||
# decorated_user.__getobj__ #=> #<User: ...>
|
||||
#
|
||||
# A SimpleDelegator instance can take advantage of the fact that SimpleDelegator
|
||||
# is a subclass of +Delegator+ to call <tt>super</tt> to have methods called on
|
||||
# the object being delegated to.
|
||||
#
|
||||
# class SuperArray < SimpleDelegator
|
||||
# def [](*args)
|
||||
# super + 1
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# SuperArray.new([1])[0] #=> 2
|
||||
#
|
||||
# Here's a simple example that takes advantage of the fact that
|
||||
# SimpleDelegator's delegation object can be changed at any time.
|
||||
#
|
||||
# class Stats
|
||||
# def initialize
|
||||
# @source = SimpleDelegator.new([])
|
||||
# end
|
||||
#
|
||||
# def stats(records)
|
||||
# @source.__setobj__(records)
|
||||
#
|
||||
# "Elements: #{@source.size}\n" +
|
||||
# " Non-Nil: #{@source.compact.size}\n" +
|
||||
# " Unique: #{@source.uniq.size}\n"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# s = Stats.new
|
||||
# puts s.stats(%w{James Edward Gray II})
|
||||
# puts
|
||||
# puts s.stats([1, 2, 3, nil, 4, 5, 1, 2])
|
||||
#
|
||||
# Prints:
|
||||
#
|
||||
# Elements: 4
|
||||
# Non-Nil: 4
|
||||
# Unique: 4
|
||||
#
|
||||
# Elements: 8
|
||||
# Non-Nil: 7
|
||||
# Unique: 6
|
||||
#
|
||||
class SimpleDelegator<Delegator
|
||||
# Returns the current object method calls are being delegated to.
|
||||
def __getobj__
|
||||
unless defined?(@delegate_sd_obj)
|
||||
return yield if block_given?
|
||||
__raise__ ::ArgumentError, "not delegated"
|
||||
end
|
||||
@delegate_sd_obj
|
||||
end
|
||||
|
||||
#
|
||||
# Changes the delegate object to _obj_.
|
||||
#
|
||||
# It's important to note that this does *not* cause SimpleDelegator's methods
|
||||
# to change. Because of this, you probably only want to change delegation
|
||||
# to objects of the same type as the original delegate.
|
||||
#
|
||||
# Here's an example of changing the delegation object.
|
||||
#
|
||||
# names = SimpleDelegator.new(%w{James Edward Gray II})
|
||||
# puts names[1] # => Edward
|
||||
# names.__setobj__(%w{Gavin Sinclair})
|
||||
# puts names[1] # => Sinclair
|
||||
#
|
||||
def __setobj__(obj)
|
||||
__raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
|
||||
@delegate_sd_obj = obj
|
||||
end
|
||||
end
|
||||
|
||||
def Delegator.delegating_block(mid) # :nodoc:
|
||||
lambda do |*args, &block|
|
||||
target = self.__getobj__
|
||||
begin
|
||||
target.__send__(mid, *args, &block)
|
||||
ensure
|
||||
$@.delete_if {|t| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}:/o =~ t} if $@
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# The primary interface to this library. Use to setup delegation when defining
|
||||
# your class.
|
||||
#
|
||||
# class MyClass < DelegateClass(ClassToDelegateTo) # Step 1
|
||||
# def initialize
|
||||
# super(obj_of_ClassToDelegateTo) # Step 2
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Here's a sample of use from Tempfile which is really a File object with a
|
||||
# few special rules about storage location and when the File should be
|
||||
# deleted. That makes for an almost textbook perfect example of how to use
|
||||
# delegation.
|
||||
#
|
||||
# class Tempfile < DelegateClass(File)
|
||||
# # constant and class member data initialization...
|
||||
#
|
||||
# def initialize(basename, tmpdir=Dir::tmpdir)
|
||||
# # build up file path/name in var tmpname...
|
||||
#
|
||||
# @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
|
||||
#
|
||||
# # ...
|
||||
#
|
||||
# super(@tmpfile)
|
||||
#
|
||||
# # below this point, all methods of File are supported...
|
||||
# end
|
||||
#
|
||||
# # ...
|
||||
# end
|
||||
#
|
||||
def DelegateClass(superclass)
|
||||
klass = Class.new(Delegator)
|
||||
methods = superclass.instance_methods
|
||||
methods -= ::Delegator.public_api
|
||||
methods -= [:to_s,:inspect,:=~,:!~,:===]
|
||||
klass.module_eval do
|
||||
def __getobj__ # :nodoc:
|
||||
unless defined?(@delegate_dc_obj)
|
||||
return yield if block_given?
|
||||
__raise__ ::ArgumentError, "not delegated"
|
||||
end
|
||||
@delegate_dc_obj
|
||||
end
|
||||
def __setobj__(obj) # :nodoc:
|
||||
__raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
|
||||
@delegate_dc_obj = obj
|
||||
end
|
||||
methods.each do |method|
|
||||
define_method(method, Delegator.delegating_block(method))
|
||||
end
|
||||
end
|
||||
klass.define_singleton_method :public_instance_methods do |all=true|
|
||||
super(all) - superclass.protected_instance_methods
|
||||
end
|
||||
klass.define_singleton_method :protected_instance_methods do |all=true|
|
||||
super(all) | superclass.protected_instance_methods
|
||||
end
|
||||
return klass
|
||||
end
|
||||
|
||||
# :enddoc:
|
||||
|
||||
if __FILE__ == $0
|
||||
class ExtArray<DelegateClass(Array)
|
||||
def initialize()
|
||||
super([])
|
||||
end
|
||||
end
|
||||
|
||||
ary = ExtArray.new
|
||||
p ary.class
|
||||
ary.push 25
|
||||
p ary
|
||||
ary.push 42
|
||||
ary.each {|x| p x}
|
||||
|
||||
foo = Object.new
|
||||
def foo.test
|
||||
25
|
||||
end
|
||||
def foo.iter
|
||||
yield self
|
||||
end
|
||||
def foo.error
|
||||
raise 'this is OK'
|
||||
end
|
||||
foo2 = SimpleDelegator.new(foo)
|
||||
p foo2
|
||||
foo2.instance_eval{print "foo\n"}
|
||||
p foo.test == foo2.test # => true
|
||||
p foo2.iter{[55,true]} # => true
|
||||
foo2.error # raise error!
|
||||
end
|
||||
90
ruby/lib/ruby/2.1.0/digest.rb
Normal file
90
ruby/lib/ruby/2.1.0/digest.rb
Normal file
@@ -0,0 +1,90 @@
|
||||
require 'digest.so'
|
||||
|
||||
module Digest
|
||||
def self.const_missing(name) # :nodoc:
|
||||
case name
|
||||
when :SHA256, :SHA384, :SHA512
|
||||
lib = 'digest/sha2.so'
|
||||
else
|
||||
lib = File.join('digest', name.to_s.downcase)
|
||||
end
|
||||
|
||||
begin
|
||||
require lib
|
||||
rescue LoadError
|
||||
raise LoadError, "library not found for class Digest::#{name} -- #{lib}", caller(1)
|
||||
end
|
||||
unless Digest.const_defined?(name)
|
||||
raise NameError, "uninitialized constant Digest::#{name}", caller(1)
|
||||
end
|
||||
Digest.const_get(name)
|
||||
end
|
||||
|
||||
class ::Digest::Class
|
||||
# Creates a digest object and reads a given file, _name_.
|
||||
# Optional arguments are passed to the constructor of the digest
|
||||
# class.
|
||||
#
|
||||
# p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
|
||||
# # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
|
||||
def self.file(name, *args)
|
||||
new(*args).file(name)
|
||||
end
|
||||
|
||||
# Returns the base64 encoded hash value of a given _string_. The
|
||||
# return value is properly padded with '=' and contains no line
|
||||
# feeds.
|
||||
def self.base64digest(str, *args)
|
||||
[digest(str, *args)].pack('m0')
|
||||
end
|
||||
end
|
||||
|
||||
module Instance
|
||||
# Updates the digest with the contents of a given file _name_ and
|
||||
# returns self.
|
||||
def file(name)
|
||||
File.open(name, "rb") {|f|
|
||||
buf = ""
|
||||
while f.read(16384, buf)
|
||||
update buf
|
||||
end
|
||||
}
|
||||
self
|
||||
end
|
||||
|
||||
# If none is given, returns the resulting hash value of the digest
|
||||
# in a base64 encoded form, keeping the digest's state.
|
||||
#
|
||||
# If a +string+ is given, returns the hash value for the given
|
||||
# +string+ in a base64 encoded form, resetting the digest to the
|
||||
# initial state before and after the process.
|
||||
#
|
||||
# In either case, the return value is properly padded with '=' and
|
||||
# contains no line feeds.
|
||||
def base64digest(str = nil)
|
||||
[str ? digest(str) : digest].pack('m0')
|
||||
end
|
||||
|
||||
# Returns the resulting hash value and resets the digest to the
|
||||
# initial state.
|
||||
def base64digest!
|
||||
[digest!].pack('m0')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# Digest(name) -> digest_subclass
|
||||
#
|
||||
# Returns a Digest subclass by +name+.
|
||||
#
|
||||
# require 'digest'
|
||||
#
|
||||
# Digest("MD5")
|
||||
# # => Digest::MD5
|
||||
#
|
||||
# Digest("Foo")
|
||||
# # => LoadError: library not found for class Digest::Foo -- digest/foo
|
||||
def Digest(name)
|
||||
Digest.const_get(name)
|
||||
end
|
||||
302
ruby/lib/ruby/2.1.0/digest/hmac.rb
Normal file
302
ruby/lib/ruby/2.1.0/digest/hmac.rb
Normal file
@@ -0,0 +1,302 @@
|
||||
# == License
|
||||
#
|
||||
# Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
|
||||
#
|
||||
# Documentation by Akinori MUSHA
|
||||
#
|
||||
# All rights reserved. You can redistribute and/or modify it under
|
||||
# the same terms as Ruby.
|
||||
#
|
||||
# $Id: hmac.rb 43668 2013-11-13 10:09:28Z zzak $
|
||||
#
|
||||
|
||||
warn "use of the experimetal library 'digest/hmac' is discouraged; require 'openssl' and use OpenSSL::HMAC instead." if $VERBOSE
|
||||
|
||||
require 'digest'
|
||||
|
||||
module Digest
|
||||
# = digest/hmac.rb
|
||||
#
|
||||
# An experimental implementation of HMAC keyed-hashing algorithm
|
||||
#
|
||||
# == Overview
|
||||
#
|
||||
# CAUTION: Use of this library is discouraged, because this
|
||||
# implementation was meant to be experimental but somehow got into the
|
||||
# 1.9 series without being noticed. Please use OpenSSL::HMAC in the
|
||||
# "openssl" library instead.
|
||||
#
|
||||
# == Examples
|
||||
#
|
||||
# require 'digest/hmac'
|
||||
#
|
||||
# # one-liner example
|
||||
# puts Digest::HMAC.hexdigest("data", "hash key", Digest::SHA1)
|
||||
#
|
||||
# # rather longer one
|
||||
# hmac = Digest::HMAC.new("foo", Digest::RMD160)
|
||||
#
|
||||
# buf = ""
|
||||
# while stream.read(16384, buf)
|
||||
# hmac.update(buf)
|
||||
# end
|
||||
#
|
||||
# puts hmac.hexdigest
|
||||
#
|
||||
class HMAC < Digest::Class
|
||||
|
||||
# Creates a Digest::HMAC instance.
|
||||
|
||||
def initialize(key, digester)
|
||||
@md = digester.new
|
||||
|
||||
block_len = @md.block_length
|
||||
|
||||
if key.bytesize > block_len
|
||||
key = @md.digest(key)
|
||||
end
|
||||
|
||||
ipad = Array.new(block_len, 0x36)
|
||||
opad = Array.new(block_len, 0x5c)
|
||||
|
||||
key.bytes.each_with_index { |c, i|
|
||||
ipad[i] ^= c
|
||||
opad[i] ^= c
|
||||
}
|
||||
|
||||
@key = key.freeze
|
||||
@ipad = ipad.pack('C*').freeze
|
||||
@opad = opad.pack('C*').freeze
|
||||
@md.update(@ipad)
|
||||
end
|
||||
|
||||
def initialize_copy(other) # :nodoc:
|
||||
@md = other.instance_eval { @md.clone }
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# hmac.update(string) -> hmac
|
||||
# hmac << string -> hmac
|
||||
#
|
||||
# Updates the hmac using a given +string+ and returns self.
|
||||
def update(text)
|
||||
@md.update(text)
|
||||
self
|
||||
end
|
||||
alias << update
|
||||
|
||||
# call-seq:
|
||||
# hmac.reset -> hmac
|
||||
#
|
||||
# Resets the hmac to the initial state and returns self.
|
||||
def reset
|
||||
@md.reset
|
||||
@md.update(@ipad)
|
||||
self
|
||||
end
|
||||
|
||||
def finish # :nodoc:
|
||||
d = @md.digest!
|
||||
@md.update(@opad)
|
||||
@md.update(d)
|
||||
@md.digest!
|
||||
end
|
||||
private :finish
|
||||
|
||||
# call-seq:
|
||||
# hmac.digest_length -> Integer
|
||||
#
|
||||
# Returns the length in bytes of the hash value of the digest.
|
||||
def digest_length
|
||||
@md.digest_length
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# hmac.block_length -> Integer
|
||||
#
|
||||
# Returns the block length in bytes of the hmac.
|
||||
def block_length
|
||||
@md.block_length
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# hmac.inspect -> string
|
||||
#
|
||||
# Creates a printable version of the hmac object.
|
||||
def inspect
|
||||
sprintf('#<%s: key=%s, digest=%s>', self.class.name, @key.inspect, @md.inspect.sub(/^\#<(.*)>$/) { $1 });
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
eval DATA.gets(nil), nil, $0, DATA.lineno
|
||||
end
|
||||
|
||||
__END__
|
||||
|
||||
require 'test/unit'
|
||||
|
||||
module TM_HMAC
|
||||
def test_s_hexdigest
|
||||
cases.each { |h|
|
||||
digesters.each { |d|
|
||||
assert_equal(h[:hexdigest], Digest::HMAC.hexdigest(h[:data], h[:key], d))
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_hexdigest
|
||||
cases.each { |h|
|
||||
digesters.each { |d|
|
||||
hmac = Digest::HMAC.new(h[:key], d)
|
||||
|
||||
hmac.update(h[:data])
|
||||
|
||||
assert_equal(h[:hexdigest], hmac.hexdigest)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def test_reset
|
||||
cases.each { |h|
|
||||
digesters.each { |d|
|
||||
hmac = Digest::HMAC.new(h[:key], d)
|
||||
hmac.update("test")
|
||||
hmac.reset
|
||||
hmac.update(h[:data])
|
||||
|
||||
assert_equal(h[:hexdigest], hmac.hexdigest)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
class TC_HMAC_MD5 < Test::Unit::TestCase
|
||||
include TM_HMAC
|
||||
|
||||
def digesters
|
||||
[Digest::MD5, Digest::MD5.new]
|
||||
end
|
||||
|
||||
# Taken from RFC 2202: Test Cases for HMAC-MD5 and HMAC-SHA-1
|
||||
def cases
|
||||
[
|
||||
{
|
||||
:key => "\x0b" * 16,
|
||||
:data => "Hi There",
|
||||
:hexdigest => "9294727a3638bb1c13f48ef8158bfc9d",
|
||||
}, {
|
||||
:key => "Jefe",
|
||||
:data => "what do ya want for nothing?",
|
||||
:hexdigest => "750c783e6ab0b503eaa86e310a5db738",
|
||||
}, {
|
||||
:key => "\xaa" * 16,
|
||||
:data => "\xdd" * 50,
|
||||
:hexdigest => "56be34521d144c88dbb8c733f0e8b3f6",
|
||||
}, {
|
||||
:key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
|
||||
:data => "\xcd" * 50,
|
||||
:hexdigest => "697eaf0aca3a3aea3a75164746ffaa79",
|
||||
}, {
|
||||
:key => "\x0c" * 16,
|
||||
:data => "Test With Truncation",
|
||||
:hexdigest => "56461ef2342edc00f9bab995690efd4c",
|
||||
}, {
|
||||
:key => "\xaa" * 80,
|
||||
:data => "Test Using Larger Than Block-Size Key - Hash Key First",
|
||||
:hexdigest => "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd",
|
||||
}, {
|
||||
:key => "\xaa" * 80,
|
||||
:data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
|
||||
:hexdigest => "6f630fad67cda0ee1fb1f562db3aa53e",
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
class TC_HMAC_SHA1 < Test::Unit::TestCase
|
||||
include TM_HMAC
|
||||
|
||||
def digesters
|
||||
[Digest::SHA1, Digest::SHA1.new]
|
||||
end
|
||||
|
||||
# Taken from RFC 2202: Test Cases for HMAC-MD5 and HMAC-SHA-1
|
||||
def cases
|
||||
[
|
||||
{
|
||||
:key => "\x0b" * 20,
|
||||
:data => "Hi There",
|
||||
:hexdigest => "b617318655057264e28bc0b6fb378c8ef146be00",
|
||||
}, {
|
||||
:key => "Jefe",
|
||||
:data => "what do ya want for nothing?",
|
||||
:hexdigest => "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
|
||||
}, {
|
||||
:key => "\xaa" * 20,
|
||||
:data => "\xdd" * 50,
|
||||
:hexdigest => "125d7342b9ac11cd91a39af48aa17b4f63f175d3",
|
||||
}, {
|
||||
:key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
|
||||
:data => "\xcd" * 50,
|
||||
:hexdigest => "4c9007f4026250c6bc8414f9bf50c86c2d7235da",
|
||||
}, {
|
||||
:key => "\x0c" * 20,
|
||||
:data => "Test With Truncation",
|
||||
:hexdigest => "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04",
|
||||
}, {
|
||||
:key => "\xaa" * 80,
|
||||
:data => "Test Using Larger Than Block-Size Key - Hash Key First",
|
||||
:hexdigest => "aa4ae5e15272d00e95705637ce8a3b55ed402112",
|
||||
}, {
|
||||
:key => "\xaa" * 80,
|
||||
:data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
|
||||
:hexdigest => "e8e99d0f45237d786d6bbaa7965c7808bbff1a91",
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
class TC_HMAC_RMD160 < Test::Unit::TestCase
|
||||
include TM_HMAC
|
||||
|
||||
def digesters
|
||||
[Digest::RMD160, Digest::RMD160.new]
|
||||
end
|
||||
|
||||
# Taken from RFC 2286: Test Cases for HMAC-RIPEMD160 and HMAC-RIPEMD128
|
||||
def cases
|
||||
[
|
||||
{
|
||||
:key => "\x0b" * 20,
|
||||
:data => "Hi There",
|
||||
:hexdigest => "24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668",
|
||||
}, {
|
||||
:key => "Jefe",
|
||||
:data => "what do ya want for nothing?",
|
||||
:hexdigest => "dda6c0213a485a9e24f4742064a7f033b43c4069",
|
||||
}, {
|
||||
:key => "\xaa" * 20,
|
||||
:data => "\xdd" * 50,
|
||||
:hexdigest => "b0b105360de759960ab4f35298e116e295d8e7c1",
|
||||
}, {
|
||||
:key => "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19",
|
||||
:data => "\xcd" * 50,
|
||||
:hexdigest => "d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4",
|
||||
}, {
|
||||
:key => "\x0c" * 20,
|
||||
:data => "Test With Truncation",
|
||||
:hexdigest => "7619693978f91d90539ae786500ff3d8e0518e39",
|
||||
}, {
|
||||
:key => "\xaa" * 80,
|
||||
:data => "Test Using Larger Than Block-Size Key - Hash Key First",
|
||||
:hexdigest => "6466ca07ac5eac29e1bd523e5ada7605b791fd8b",
|
||||
}, {
|
||||
:key => "\xaa" * 80,
|
||||
:data => "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
|
||||
:hexdigest => "69ea60798d71616cce5fd0871e23754cd75d5a0a",
|
||||
}
|
||||
]
|
||||
end
|
||||
end
|
||||
107
ruby/lib/ruby/2.1.0/digest/sha2.rb
Normal file
107
ruby/lib/ruby/2.1.0/digest/sha2.rb
Normal file
@@ -0,0 +1,107 @@
|
||||
#--
|
||||
# sha2.rb - defines Digest::SHA2 class which wraps up the SHA256,
|
||||
# SHA384, and SHA512 classes.
|
||||
#++
|
||||
# Copyright (c) 2006 Akinori MUSHA <knu@iDaemons.org>
|
||||
#
|
||||
# All rights reserved. You can redistribute and/or modify it under the same
|
||||
# terms as Ruby.
|
||||
#
|
||||
# $Id: sha2.rb 35293 2012-04-10 22:41:04Z drbrain $
|
||||
|
||||
require 'digest'
|
||||
require 'digest/sha2.so'
|
||||
|
||||
module Digest
|
||||
#
|
||||
# A meta digest provider class for SHA256, SHA384 and SHA512.
|
||||
#
|
||||
class SHA2 < Digest::Class
|
||||
# call-seq:
|
||||
# Digest::SHA2.new(bitlen = 256) -> digest_obj
|
||||
#
|
||||
# Creates a new SHA2 hash object with a given bit length.
|
||||
#
|
||||
# Valid bit lengths are 256, 384 and 512.
|
||||
def initialize(bitlen = 256)
|
||||
case bitlen
|
||||
when 256
|
||||
@sha2 = Digest::SHA256.new
|
||||
when 384
|
||||
@sha2 = Digest::SHA384.new
|
||||
when 512
|
||||
@sha2 = Digest::SHA512.new
|
||||
else
|
||||
raise ArgumentError, "unsupported bit length: %s" % bitlen.inspect
|
||||
end
|
||||
@bitlen = bitlen
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# digest_obj.reset -> digest_obj
|
||||
#
|
||||
# Resets the digest to the initial state and returns self.
|
||||
def reset
|
||||
@sha2.reset
|
||||
self
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# digest_obj.update(string) -> digest_obj
|
||||
# digest_obj << string -> digest_obj
|
||||
#
|
||||
# Updates the digest using a given _string_ and returns self.
|
||||
def update(str)
|
||||
@sha2.update(str)
|
||||
self
|
||||
end
|
||||
alias << update
|
||||
|
||||
def finish # :nodoc:
|
||||
@sha2.digest!
|
||||
end
|
||||
private :finish
|
||||
|
||||
|
||||
# call-seq:
|
||||
# digest_obj.block_length -> Integer
|
||||
#
|
||||
# Returns the block length of the digest in bytes.
|
||||
#
|
||||
# Digest::SHA256.new.block_length * 8
|
||||
# # => 512
|
||||
# Digest::SHA384.new.block_length * 8
|
||||
# # => 1024
|
||||
# Digest::SHA512.new.block_length * 8
|
||||
# # => 1024
|
||||
def block_length
|
||||
@sha2.block_length
|
||||
end
|
||||
|
||||
# call-seq:
|
||||
# digest_obj.digest_length -> Integer
|
||||
#
|
||||
# Returns the length of the hash value of the digest in bytes.
|
||||
#
|
||||
# Digest::SHA256.new.digest_length * 8
|
||||
# # => 256
|
||||
# Digest::SHA384.new.digest_length * 8
|
||||
# # => 384
|
||||
# Digest::SHA512.new.digest_length * 8
|
||||
# # => 512
|
||||
#
|
||||
# For example, digests produced by Digest::SHA256 will always be 32 bytes
|
||||
# (256 bits) in size.
|
||||
def digest_length
|
||||
@sha2.digest_length
|
||||
end
|
||||
|
||||
def initialize_copy(other) # :nodoc:
|
||||
@sha2 = other.instance_eval { @sha2.clone }
|
||||
end
|
||||
|
||||
def inspect # :nodoc:
|
||||
"#<%s:%d %s>" % [self.class.name, @bitlen, hexdigest]
|
||||
end
|
||||
end
|
||||
end
|
||||
15
ruby/lib/ruby/2.1.0/dl.rb
Normal file
15
ruby/lib/ruby/2.1.0/dl.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'dl.so'
|
||||
|
||||
begin
|
||||
require 'fiddle' unless Object.const_defined?(:Fiddle)
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
warn "DL is deprecated, please use Fiddle"
|
||||
|
||||
module DL
|
||||
# Returns true if DL is using Fiddle, the libffi wrapper.
|
||||
def self.fiddle?
|
||||
Object.const_defined?(:Fiddle)
|
||||
end
|
||||
end
|
||||
112
ruby/lib/ruby/2.1.0/dl/callback.rb
Normal file
112
ruby/lib/ruby/2.1.0/dl/callback.rb
Normal file
@@ -0,0 +1,112 @@
|
||||
require 'dl'
|
||||
require 'thread'
|
||||
|
||||
module DL
|
||||
# The mutual exclusion (Mutex) semaphore for the DL module
|
||||
SEM = Mutex.new # :nodoc:
|
||||
|
||||
if DL.fiddle?
|
||||
# A Hash of callback Procs
|
||||
#
|
||||
# Uses Fiddle
|
||||
CdeclCallbackProcs = {} # :nodoc:
|
||||
|
||||
# A Hash of the addresses of callback Proc
|
||||
#
|
||||
# Uses Fiddle
|
||||
CdeclCallbackAddrs = {} # :nodoc:
|
||||
|
||||
# A Hash of Stdcall callback Procs
|
||||
#
|
||||
# Uses Fiddle on win32
|
||||
StdcallCallbackProcs = {} # :nodoc:
|
||||
|
||||
# A Hash of the addresses of Stdcall callback Procs
|
||||
#
|
||||
# Uses Fiddle on win32
|
||||
StdcallCallbackAddrs = {} # :nodoc:
|
||||
end
|
||||
|
||||
def set_callback_internal(proc_entry, addr_entry, argc, ty, abi = nil, &cbp)
|
||||
if( argc < 0 )
|
||||
raise(ArgumentError, "arity should not be less than 0.")
|
||||
end
|
||||
addr = nil
|
||||
|
||||
if DL.fiddle?
|
||||
abi ||= Fiddle::Function::DEFAULT
|
||||
closure = Fiddle::Closure::BlockCaller.new(ty, [TYPE_VOIDP] * argc, abi, &cbp)
|
||||
proc_entry[closure.to_i] = closure
|
||||
addr = closure.to_i
|
||||
else
|
||||
SEM.synchronize{
|
||||
ary = proc_entry[ty]
|
||||
(0...MAX_CALLBACK).each{|n|
|
||||
idx = (n * DLSTACK_SIZE) + argc
|
||||
if( ary[idx].nil? )
|
||||
ary[idx] = cbp
|
||||
addr = addr_entry[ty][idx]
|
||||
break
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
addr
|
||||
end
|
||||
|
||||
def set_cdecl_callback(ty, argc, &cbp)
|
||||
set_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, argc, ty, &cbp)
|
||||
end
|
||||
|
||||
def set_stdcall_callback(ty, argc, &cbp)
|
||||
if DL.fiddle?
|
||||
set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, Fiddle::Function::STDCALL, &cbp)
|
||||
else
|
||||
set_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, argc, ty, &cbp)
|
||||
end
|
||||
end
|
||||
|
||||
def remove_callback_internal(proc_entry, addr_entry, addr, ctype = nil)
|
||||
if DL.fiddle?
|
||||
addr = addr.to_i
|
||||
return false unless proc_entry.key?(addr)
|
||||
proc_entry.delete(addr)
|
||||
true
|
||||
else
|
||||
index = nil
|
||||
if( ctype )
|
||||
addr_entry[ctype].each_with_index{|xaddr, idx|
|
||||
if( xaddr == addr )
|
||||
index = idx
|
||||
end
|
||||
}
|
||||
else
|
||||
addr_entry.each{|ty,entry|
|
||||
entry.each_with_index{|xaddr, idx|
|
||||
if( xaddr == addr )
|
||||
index = idx
|
||||
end
|
||||
}
|
||||
}
|
||||
end
|
||||
if( index and proc_entry[ctype][index] )
|
||||
proc_entry[ctype][index] = nil
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def remove_cdecl_callback(addr, ctype = nil)
|
||||
remove_callback_internal(CdeclCallbackProcs, CdeclCallbackAddrs, addr, ctype)
|
||||
end
|
||||
|
||||
def remove_stdcall_callback(addr, ctype = nil)
|
||||
remove_callback_internal(StdcallCallbackProcs, StdcallCallbackAddrs, addr, ctype)
|
||||
end
|
||||
|
||||
alias set_callback set_cdecl_callback
|
||||
alias remove_callback remove_cdecl_callback
|
||||
end
|
||||
156
ruby/lib/ruby/2.1.0/dl/cparser.rb
Normal file
156
ruby/lib/ruby/2.1.0/dl/cparser.rb
Normal file
@@ -0,0 +1,156 @@
|
||||
module DL
|
||||
# Methods for parsing C struct and C prototype signatures.
|
||||
module CParser
|
||||
# Parses a C struct's members
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# parse_struct_signature(['int i', 'char c'])
|
||||
# => [[DL::TYPE_INT, DL::TYPE_CHAR], ["i", "c"]]
|
||||
#
|
||||
def parse_struct_signature(signature, tymap=nil)
|
||||
if( signature.is_a?(String) )
|
||||
signature = signature.split(/\s*,\s*/)
|
||||
end
|
||||
mems = []
|
||||
tys = []
|
||||
signature.each{|msig|
|
||||
tks = msig.split(/\s+(\*)?/)
|
||||
ty = tks[0..-2].join(" ")
|
||||
member = tks[-1]
|
||||
|
||||
case ty
|
||||
when /\[(\d+)\]/
|
||||
n = $1.to_i
|
||||
ty.gsub!(/\s*\[\d+\]/,"")
|
||||
ty = [ty, n]
|
||||
when /\[\]/
|
||||
ty.gsub!(/\s*\[\]/, "*")
|
||||
end
|
||||
|
||||
case member
|
||||
when /\[(\d+)\]/
|
||||
ty = [ty, $1.to_i]
|
||||
member.gsub!(/\s*\[\d+\]/,"")
|
||||
when /\[\]/
|
||||
ty = ty + "*"
|
||||
member.gsub!(/\s*\[\]/, "")
|
||||
end
|
||||
|
||||
mems.push(member)
|
||||
tys.push(parse_ctype(ty,tymap))
|
||||
}
|
||||
return tys, mems
|
||||
end
|
||||
|
||||
# Parses a C prototype signature
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# include DL::CParser
|
||||
# => Object
|
||||
#
|
||||
# parse_signature('double sum(double, double)')
|
||||
# => ["sum", DL::TYPE_DOUBLE, [DL::TYPE_DOUBLE, DL::TYPE_DOUBLE]]
|
||||
#
|
||||
def parse_signature(signature, tymap=nil)
|
||||
tymap ||= {}
|
||||
signature = signature.gsub(/\s+/, " ").strip
|
||||
case signature
|
||||
when /^([\w@\*\s]+)\(([\w\*\s\,\[\]]*)\)$/
|
||||
ret = $1
|
||||
(args = $2).strip!
|
||||
ret = ret.split(/\s+/)
|
||||
args = args.split(/\s*,\s*/)
|
||||
func = ret.pop
|
||||
if( func =~ /^\*/ )
|
||||
func.gsub!(/^\*+/,"")
|
||||
ret.push("*")
|
||||
end
|
||||
ret = ret.join(" ")
|
||||
return [func, parse_ctype(ret, tymap), args.collect{|arg| parse_ctype(arg, tymap)}]
|
||||
else
|
||||
raise(RuntimeError,"can't parse the function prototype: #{signature}")
|
||||
end
|
||||
end
|
||||
|
||||
# Given a String of C type +ty+, return the corresponding DL constant.
|
||||
#
|
||||
# +ty+ can also accept an Array of C type Strings, and will returned in a
|
||||
# corresponding Array.
|
||||
#
|
||||
# If Hash +tymap+ is provided, +ty+ is expected to be the key, and the
|
||||
# value will be the C type to be looked up.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# parse_ctype('int')
|
||||
# => DL::TYPE_INT
|
||||
#
|
||||
# parse_ctype('double')
|
||||
# => DL::TYPE_DOUBLE
|
||||
#
|
||||
# parse_ctype('unsigned char')
|
||||
# => -DL::TYPE_CHAR
|
||||
#
|
||||
def parse_ctype(ty, tymap=nil)
|
||||
tymap ||= {}
|
||||
case ty
|
||||
when Array
|
||||
return [parse_ctype(ty[0], tymap), ty[1]]
|
||||
when "void"
|
||||
return TYPE_VOID
|
||||
when "char"
|
||||
return TYPE_CHAR
|
||||
when "unsigned char"
|
||||
return -TYPE_CHAR
|
||||
when "short"
|
||||
return TYPE_SHORT
|
||||
when "unsigned short"
|
||||
return -TYPE_SHORT
|
||||
when "int"
|
||||
return TYPE_INT
|
||||
when "unsigned int", 'uint'
|
||||
return -TYPE_INT
|
||||
when "long"
|
||||
return TYPE_LONG
|
||||
when "unsigned long"
|
||||
return -TYPE_LONG
|
||||
when "long long"
|
||||
if( defined?(TYPE_LONG_LONG) )
|
||||
return TYPE_LONG_LONG
|
||||
else
|
||||
raise(RuntimeError, "unsupported type: #{ty}")
|
||||
end
|
||||
when "unsigned long long"
|
||||
if( defined?(TYPE_LONG_LONG) )
|
||||
return -TYPE_LONG_LONG
|
||||
else
|
||||
raise(RuntimeError, "unsupported type: #{ty}")
|
||||
end
|
||||
when "float"
|
||||
return TYPE_FLOAT
|
||||
when "double"
|
||||
return TYPE_DOUBLE
|
||||
when "size_t"
|
||||
return TYPE_SIZE_T
|
||||
when "ssize_t"
|
||||
return TYPE_SSIZE_T
|
||||
when "ptrdiff_t"
|
||||
return TYPE_PTRDIFF_T
|
||||
when "intptr_t"
|
||||
return TYPE_INTPTR_T
|
||||
when "uintptr_t"
|
||||
return TYPE_UINTPTR_T
|
||||
when /\*/, /\[\s*\]/
|
||||
return TYPE_VOIDP
|
||||
else
|
||||
if( tymap[ty] )
|
||||
return parse_ctype(tymap[ty], tymap)
|
||||
else
|
||||
raise(DLError, "unknown type: #{ty}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
251
ruby/lib/ruby/2.1.0/dl/func.rb
Normal file
251
ruby/lib/ruby/2.1.0/dl/func.rb
Normal file
@@ -0,0 +1,251 @@
|
||||
require 'dl'
|
||||
require 'dl/callback'
|
||||
require 'dl/stack'
|
||||
require 'dl/value'
|
||||
require 'thread'
|
||||
|
||||
module DL
|
||||
parent = DL.fiddle? ? Fiddle::Function : Object
|
||||
|
||||
class Function < parent
|
||||
include DL
|
||||
include ValueUtil
|
||||
|
||||
if DL.fiddle?
|
||||
# :stopdoc:
|
||||
CALL_TYPE_TO_ABI = Hash.new { |h, k|
|
||||
raise RuntimeError, "unsupported call type: #{k}"
|
||||
}.merge({ :stdcall =>
|
||||
(Fiddle::Function::STDCALL rescue Fiddle::Function::DEFAULT),
|
||||
:cdecl => Fiddle::Function::DEFAULT,
|
||||
nil => Fiddle::Function::DEFAULT
|
||||
}).freeze
|
||||
private_constant :CALL_TYPE_TO_ABI
|
||||
# :startdoc:
|
||||
|
||||
def self.call_type_to_abi(call_type) # :nodoc:
|
||||
CALL_TYPE_TO_ABI[call_type]
|
||||
end
|
||||
private_class_method :call_type_to_abi
|
||||
|
||||
class FiddleClosureCFunc < Fiddle::Closure # :nodoc: all
|
||||
def initialize ctype, arg, abi, name
|
||||
@name = name
|
||||
super(ctype, arg, abi)
|
||||
end
|
||||
def name
|
||||
@name
|
||||
end
|
||||
def ptr
|
||||
to_i
|
||||
end
|
||||
end
|
||||
private_constant :FiddleClosureCFunc
|
||||
|
||||
def self.class_fiddle_closure_cfunc # :nodoc:
|
||||
FiddleClosureCFunc
|
||||
end
|
||||
private_class_method :class_fiddle_closure_cfunc
|
||||
end
|
||||
|
||||
def initialize cfunc, argtypes, abi = nil, &block
|
||||
if DL.fiddle?
|
||||
abi ||= CALL_TYPE_TO_ABI[(cfunc.calltype rescue nil)]
|
||||
if block_given?
|
||||
@cfunc = Class.new(FiddleClosureCFunc) {
|
||||
define_method(:call, block)
|
||||
}.new(cfunc.ctype, argtypes, abi, cfunc.name)
|
||||
else
|
||||
@cfunc = cfunc
|
||||
end
|
||||
|
||||
@args = argtypes
|
||||
super(@cfunc, @args.reject { |x| x == TYPE_VOID }, cfunc.ctype, abi)
|
||||
else
|
||||
@cfunc = cfunc
|
||||
@stack = Stack.new(argtypes.collect{|ty| ty.abs})
|
||||
if( @cfunc.ctype < 0 )
|
||||
@cfunc.ctype = @cfunc.ctype.abs
|
||||
@unsigned = true
|
||||
else
|
||||
@unsigned = false
|
||||
end
|
||||
if block_given?
|
||||
bind(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def to_i()
|
||||
@cfunc.to_i
|
||||
end
|
||||
|
||||
def name
|
||||
@cfunc.name
|
||||
end
|
||||
|
||||
def call(*args, &block)
|
||||
if DL.fiddle?
|
||||
if block_given?
|
||||
args.find { |a| DL::Function === a }.bind_at_call(&block)
|
||||
end
|
||||
super
|
||||
else
|
||||
funcs = []
|
||||
if $SAFE >= 1 && args.any? { |x| x.tainted? }
|
||||
raise SecurityError, "tainted parameter not allowed"
|
||||
end
|
||||
_args = wrap_args(args, @stack.types, funcs, &block)
|
||||
r = @cfunc.call(@stack.pack(_args))
|
||||
funcs.each{|f| f.unbind_at_call()}
|
||||
return wrap_result(r)
|
||||
end
|
||||
end
|
||||
|
||||
def wrap_result(r)
|
||||
case @cfunc.ctype
|
||||
when TYPE_VOIDP
|
||||
r = CPtr.new(r)
|
||||
else
|
||||
if( @unsigned )
|
||||
r = unsigned_value(r, @cfunc.ctype)
|
||||
end
|
||||
end
|
||||
r
|
||||
end
|
||||
|
||||
def bind(&block)
|
||||
if DL.fiddle?
|
||||
@cfunc = Class.new(FiddleClosureCFunc) {
|
||||
def initialize ctype, args, abi, name, block
|
||||
super(ctype, args, abi, name)
|
||||
@block = block
|
||||
end
|
||||
|
||||
def call *args
|
||||
@block.call(*args)
|
||||
end
|
||||
}.new(@cfunc.ctype, @args, abi, name, block)
|
||||
@ptr = @cfunc
|
||||
return nil
|
||||
else
|
||||
if( !block )
|
||||
raise(RuntimeError, "block must be given.")
|
||||
end
|
||||
unless block.lambda?
|
||||
block = Class.new(self.class){define_method(:call, block); def initialize(obj); obj.instance_variables.each{|s| instance_variable_set(s, obj.instance_variable_get(s))}; end}.new(self).method(:call)
|
||||
end
|
||||
if( @cfunc.ptr == 0 )
|
||||
cb = Proc.new{|*args|
|
||||
ary = @stack.unpack(args)
|
||||
@stack.types.each_with_index{|ty, idx|
|
||||
case ty
|
||||
when TYPE_VOIDP
|
||||
ary[idx] = CPtr.new(ary[idx])
|
||||
end
|
||||
}
|
||||
r = block.call(*ary)
|
||||
wrap_arg(r, @cfunc.ctype, [])
|
||||
}
|
||||
case @cfunc.calltype
|
||||
when :cdecl
|
||||
@cfunc.ptr = set_cdecl_callback(@cfunc.ctype, @stack.size, &cb)
|
||||
when :stdcall
|
||||
@cfunc.ptr = set_stdcall_callback(@cfunc.ctype, @stack.size, &cb)
|
||||
else
|
||||
raise(RuntimeError, "unsupported calltype: #{@cfunc.calltype}")
|
||||
end
|
||||
if( @cfunc.ptr == 0 )
|
||||
raise(RuntimeException, "can't bind C function.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def unbind()
|
||||
if DL.fiddle? then
|
||||
if @cfunc.kind_of?(Fiddle::Closure) and @cfunc.ptr != 0 then
|
||||
call_type = case abi
|
||||
when CALL_TYPE_TO_ABI[nil]
|
||||
nil
|
||||
when CALL_TYPE_TO_ABI[:stdcall]
|
||||
:stdcall
|
||||
else
|
||||
raise(RuntimeError, "unsupported abi: #{abi}")
|
||||
end
|
||||
@cfunc = CFunc.new(0, @cfunc.ctype, name, call_type)
|
||||
return 0
|
||||
elsif @cfunc.ptr != 0 then
|
||||
@cfunc.ptr = 0
|
||||
return 0
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
if( @cfunc.ptr != 0 )
|
||||
case @cfunc.calltype
|
||||
when :cdecl
|
||||
remove_cdecl_callback(@cfunc.ptr, @cfunc.ctype)
|
||||
when :stdcall
|
||||
remove_stdcall_callback(@cfunc.ptr, @cfunc.ctype)
|
||||
else
|
||||
raise(RuntimeError, "unsupported calltype: #{@cfunc.calltype}")
|
||||
end
|
||||
@cfunc.ptr = 0
|
||||
end
|
||||
end
|
||||
|
||||
def bound?()
|
||||
@cfunc.ptr != 0
|
||||
end
|
||||
|
||||
def bind_at_call(&block)
|
||||
bind(&block)
|
||||
end
|
||||
|
||||
def unbind_at_call()
|
||||
end
|
||||
end
|
||||
|
||||
class TempFunction < Function
|
||||
def bind_at_call(&block)
|
||||
bind(&block)
|
||||
end
|
||||
|
||||
def unbind_at_call()
|
||||
unbind()
|
||||
end
|
||||
end
|
||||
|
||||
class CarriedFunction < Function
|
||||
def initialize(cfunc, argtypes, n)
|
||||
super(cfunc, argtypes)
|
||||
@carrier = []
|
||||
@index = n
|
||||
@mutex = Mutex.new
|
||||
end
|
||||
|
||||
def create_carrier(data)
|
||||
ary = []
|
||||
userdata = [ary, data]
|
||||
@mutex.lock()
|
||||
@carrier.push(userdata)
|
||||
return dlwrap(userdata)
|
||||
end
|
||||
|
||||
def bind_at_call(&block)
|
||||
userdata = @carrier[-1]
|
||||
userdata[0].push(block)
|
||||
bind{|*args|
|
||||
ptr = args[@index]
|
||||
if( !ptr )
|
||||
raise(RuntimeError, "The index of userdata should be lower than #{args.size}.")
|
||||
end
|
||||
userdata = dlunwrap(Integer(ptr))
|
||||
args[@index] = userdata[1]
|
||||
userdata[0][0].call(*args)
|
||||
}
|
||||
@mutex.unlock()
|
||||
end
|
||||
end
|
||||
end
|
||||
268
ruby/lib/ruby/2.1.0/dl/import.rb
Normal file
268
ruby/lib/ruby/2.1.0/dl/import.rb
Normal file
@@ -0,0 +1,268 @@
|
||||
require 'dl'
|
||||
require 'dl/func.rb'
|
||||
require 'dl/struct.rb'
|
||||
require 'dl/cparser.rb'
|
||||
|
||||
module DL
|
||||
class CompositeHandler
|
||||
def initialize(handlers)
|
||||
@handlers = handlers
|
||||
end
|
||||
|
||||
def handlers()
|
||||
@handlers
|
||||
end
|
||||
|
||||
def sym(symbol)
|
||||
@handlers.each{|handle|
|
||||
if( handle )
|
||||
begin
|
||||
addr = handle.sym(symbol)
|
||||
return addr
|
||||
rescue DLError
|
||||
end
|
||||
end
|
||||
}
|
||||
return nil
|
||||
end
|
||||
|
||||
def [](symbol)
|
||||
sym(symbol)
|
||||
end
|
||||
end
|
||||
|
||||
# DL::Importer includes the means to dynamically load libraries and build
|
||||
# modules around them including calling extern functions within the C
|
||||
# library that has been loaded.
|
||||
#
|
||||
# == Example
|
||||
#
|
||||
# require 'dl'
|
||||
# require 'dl/import'
|
||||
#
|
||||
# module LibSum
|
||||
# extend DL::Importer
|
||||
# dlload './libsum.so'
|
||||
# extern 'double sum(double*, int)'
|
||||
# extern 'double split(double)'
|
||||
# end
|
||||
#
|
||||
module Importer
|
||||
include DL
|
||||
include CParser
|
||||
extend Importer
|
||||
|
||||
def dlload(*libs)
|
||||
handles = libs.collect{|lib|
|
||||
case lib
|
||||
when nil
|
||||
nil
|
||||
when Handle
|
||||
lib
|
||||
when Importer
|
||||
lib.handlers
|
||||
else
|
||||
begin
|
||||
DL.dlopen(lib)
|
||||
rescue DLError
|
||||
raise(DLError, "can't load #{lib}")
|
||||
end
|
||||
end
|
||||
}.flatten()
|
||||
@handler = CompositeHandler.new(handles)
|
||||
@func_map = {}
|
||||
@type_alias = {}
|
||||
end
|
||||
|
||||
def typealias(alias_type, orig_type)
|
||||
@type_alias[alias_type] = orig_type
|
||||
end
|
||||
|
||||
def sizeof(ty)
|
||||
@type_alias ||= nil
|
||||
case ty
|
||||
when String
|
||||
ty = parse_ctype(ty, @type_alias).abs()
|
||||
case ty
|
||||
when TYPE_CHAR
|
||||
return SIZEOF_CHAR
|
||||
when TYPE_SHORT
|
||||
return SIZEOF_SHORT
|
||||
when TYPE_INT
|
||||
return SIZEOF_INT
|
||||
when TYPE_LONG
|
||||
return SIZEOF_LONG
|
||||
when TYPE_LONG_LONG
|
||||
return SIZEOF_LONG_LON
|
||||
when TYPE_FLOAT
|
||||
return SIZEOF_FLOAT
|
||||
when TYPE_DOUBLE
|
||||
return SIZEOF_DOUBLE
|
||||
when TYPE_VOIDP
|
||||
return SIZEOF_VOIDP
|
||||
else
|
||||
raise(DLError, "unknown type: #{ty}")
|
||||
end
|
||||
when Class
|
||||
if( ty.instance_methods().include?(:to_ptr) )
|
||||
return ty.size()
|
||||
end
|
||||
end
|
||||
return CPtr[ty].size()
|
||||
end
|
||||
|
||||
def parse_bind_options(opts)
|
||||
h = {}
|
||||
while( opt = opts.shift() )
|
||||
case opt
|
||||
when :stdcall, :cdecl
|
||||
h[:call_type] = opt
|
||||
when :carried, :temp, :temporal, :bind
|
||||
h[:callback_type] = opt
|
||||
h[:carrier] = opts.shift()
|
||||
else
|
||||
h[opt] = true
|
||||
end
|
||||
end
|
||||
h
|
||||
end
|
||||
private :parse_bind_options
|
||||
|
||||
def extern(signature, *opts)
|
||||
@type_alias ||= nil
|
||||
symname, ctype, argtype = parse_signature(signature, @type_alias)
|
||||
opt = parse_bind_options(opts)
|
||||
f = import_function(symname, ctype, argtype, opt[:call_type])
|
||||
name = symname.gsub(/@.+/,'')
|
||||
@func_map[name] = f
|
||||
# define_method(name){|*args,&block| f.call(*args,&block)}
|
||||
begin
|
||||
/^(.+?):(\d+)/ =~ caller.first
|
||||
file, line = $1, $2.to_i
|
||||
rescue
|
||||
file, line = __FILE__, __LINE__+3
|
||||
end
|
||||
module_eval(<<-EOS, file, line)
|
||||
def #{name}(*args, &block)
|
||||
@func_map['#{name}'].call(*args,&block)
|
||||
end
|
||||
EOS
|
||||
module_function(name)
|
||||
f
|
||||
end
|
||||
|
||||
def bind(signature, *opts, &blk)
|
||||
@type_alias ||= nil
|
||||
name, ctype, argtype = parse_signature(signature, @type_alias)
|
||||
h = parse_bind_options(opts)
|
||||
case h[:callback_type]
|
||||
when :bind, nil
|
||||
f = bind_function(name, ctype, argtype, h[:call_type], &blk)
|
||||
when :temp, :temporal
|
||||
f = create_temp_function(name, ctype, argtype, h[:call_type])
|
||||
when :carried
|
||||
f = create_carried_function(name, ctype, argtype, h[:call_type], h[:carrier])
|
||||
else
|
||||
raise(RuntimeError, "unknown callback type: #{h[:callback_type]}")
|
||||
end
|
||||
@func_map[name] = f
|
||||
#define_method(name){|*args,&block| f.call(*args,&block)}
|
||||
begin
|
||||
/^(.+?):(\d+)/ =~ caller.first
|
||||
file, line = $1, $2.to_i
|
||||
rescue
|
||||
file, line = __FILE__, __LINE__+3
|
||||
end
|
||||
module_eval(<<-EOS, file, line)
|
||||
def #{name}(*args,&block)
|
||||
@func_map['#{name}'].call(*args,&block)
|
||||
end
|
||||
EOS
|
||||
module_function(name)
|
||||
f
|
||||
end
|
||||
|
||||
# Creates a class to wrap the C struct described by +signature+.
|
||||
#
|
||||
# MyStruct = struct ['int i', 'char c']
|
||||
def struct(signature)
|
||||
@type_alias ||= nil
|
||||
tys, mems = parse_struct_signature(signature, @type_alias)
|
||||
DL::CStructBuilder.create(CStruct, tys, mems)
|
||||
end
|
||||
|
||||
# Creates a class to wrap the C union described by +signature+.
|
||||
#
|
||||
# MyUnion = union ['int i', 'char c']
|
||||
def union(signature)
|
||||
@type_alias ||= nil
|
||||
tys, mems = parse_struct_signature(signature, @type_alias)
|
||||
DL::CStructBuilder.create(CUnion, tys, mems)
|
||||
end
|
||||
|
||||
def [](name)
|
||||
@func_map[name]
|
||||
end
|
||||
|
||||
def create_value(ty, val=nil)
|
||||
s = struct([ty + " value"])
|
||||
ptr = s.malloc()
|
||||
if( val )
|
||||
ptr.value = val
|
||||
end
|
||||
return ptr
|
||||
end
|
||||
alias value create_value
|
||||
|
||||
def import_value(ty, addr)
|
||||
s = struct([ty + " value"])
|
||||
ptr = s.new(addr)
|
||||
return ptr
|
||||
end
|
||||
|
||||
def handler
|
||||
defined?(@handler) or raise "call dlload before importing symbols and functions"
|
||||
@handler
|
||||
end
|
||||
|
||||
def import_symbol(name)
|
||||
addr = handler.sym(name)
|
||||
if( !addr )
|
||||
raise(DLError, "cannot find the symbol: #{name}")
|
||||
end
|
||||
CPtr.new(addr)
|
||||
end
|
||||
|
||||
def import_function(name, ctype, argtype, call_type = nil)
|
||||
addr = handler.sym(name)
|
||||
if( !addr )
|
||||
raise(DLError, "cannot find the function: #{name}()")
|
||||
end
|
||||
Function.new(CFunc.new(addr, ctype, name, call_type || :cdecl), argtype)
|
||||
end
|
||||
|
||||
def bind_function(name, ctype, argtype, call_type = nil, &block)
|
||||
if DL.fiddle?
|
||||
klass = Function.instance_eval { class_fiddle_closure_cfunc }
|
||||
abi = Function.instance_eval { call_type_to_abi(call_type) }
|
||||
closure = Class.new(klass) {
|
||||
define_method(:call, block)
|
||||
}.new(ctype, argtype, abi, name)
|
||||
|
||||
Function.new(closure, argtype, abi)
|
||||
else
|
||||
f = Function.new(CFunc.new(0, ctype, name, call_type || :cdecl), argtype)
|
||||
f.bind(&block)
|
||||
f
|
||||
end
|
||||
end
|
||||
|
||||
def create_temp_function(name, ctype, argtype, call_type = nil)
|
||||
TempFunction.new(CFunc.new(0, ctype, name, call_type || :cdecl), argtype)
|
||||
end
|
||||
|
||||
def create_carried_function(name, ctype, argtype, call_type = nil, n = 0)
|
||||
CarriedFunction.new(CFunc.new(0, ctype, name, call_type || :cdecl), argtype, n)
|
||||
end
|
||||
end
|
||||
end
|
||||
128
ruby/lib/ruby/2.1.0/dl/pack.rb
Normal file
128
ruby/lib/ruby/2.1.0/dl/pack.rb
Normal file
@@ -0,0 +1,128 @@
|
||||
require 'dl'
|
||||
|
||||
module DL
|
||||
module PackInfo
|
||||
ALIGN_MAP = {
|
||||
TYPE_VOIDP => ALIGN_VOIDP,
|
||||
TYPE_CHAR => ALIGN_CHAR,
|
||||
TYPE_SHORT => ALIGN_SHORT,
|
||||
TYPE_INT => ALIGN_INT,
|
||||
TYPE_LONG => ALIGN_LONG,
|
||||
TYPE_FLOAT => ALIGN_FLOAT,
|
||||
TYPE_DOUBLE => ALIGN_DOUBLE,
|
||||
-TYPE_CHAR => ALIGN_CHAR,
|
||||
-TYPE_SHORT => ALIGN_SHORT,
|
||||
-TYPE_INT => ALIGN_INT,
|
||||
-TYPE_LONG => ALIGN_LONG,
|
||||
}
|
||||
|
||||
PACK_MAP = {
|
||||
TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG) ? "q" : "l!"),
|
||||
TYPE_CHAR => "c",
|
||||
TYPE_SHORT => "s!",
|
||||
TYPE_INT => "i!",
|
||||
TYPE_LONG => "l!",
|
||||
TYPE_FLOAT => "f",
|
||||
TYPE_DOUBLE => "d",
|
||||
-TYPE_CHAR => "c",
|
||||
-TYPE_SHORT => "s!",
|
||||
-TYPE_INT => "i!",
|
||||
-TYPE_LONG => "l!",
|
||||
}
|
||||
|
||||
SIZE_MAP = {
|
||||
TYPE_VOIDP => SIZEOF_VOIDP,
|
||||
TYPE_CHAR => SIZEOF_CHAR,
|
||||
TYPE_SHORT => SIZEOF_SHORT,
|
||||
TYPE_INT => SIZEOF_INT,
|
||||
TYPE_LONG => SIZEOF_LONG,
|
||||
TYPE_FLOAT => SIZEOF_FLOAT,
|
||||
TYPE_DOUBLE => SIZEOF_DOUBLE,
|
||||
-TYPE_CHAR => SIZEOF_CHAR,
|
||||
-TYPE_SHORT => SIZEOF_SHORT,
|
||||
-TYPE_INT => SIZEOF_INT,
|
||||
-TYPE_LONG => SIZEOF_LONG,
|
||||
}
|
||||
if defined?(TYPE_LONG_LONG)
|
||||
ALIGN_MAP[TYPE_LONG_LONG] = ALIGN_MAP[-TYPE_LONG_LONG] = ALIGN_LONG_LONG
|
||||
PACK_MAP[TYPE_LONG_LONG] = PACK_MAP[-TYPE_LONG_LONG] = "q"
|
||||
SIZE_MAP[TYPE_LONG_LONG] = SIZE_MAP[-TYPE_LONG_LONG] = SIZEOF_LONG_LONG
|
||||
end
|
||||
|
||||
def align(addr, align)
|
||||
d = addr % align
|
||||
if( d == 0 )
|
||||
addr
|
||||
else
|
||||
addr + (align - d)
|
||||
end
|
||||
end
|
||||
module_function :align
|
||||
end
|
||||
|
||||
class Packer
|
||||
include PackInfo
|
||||
|
||||
def self.[](*types)
|
||||
new(types)
|
||||
end
|
||||
|
||||
def initialize(types)
|
||||
parse_types(types)
|
||||
end
|
||||
|
||||
def size()
|
||||
@size
|
||||
end
|
||||
|
||||
def pack(ary)
|
||||
case SIZEOF_VOIDP
|
||||
when SIZEOF_LONG
|
||||
ary.pack(@template)
|
||||
when SIZEOF_LONG_LONG
|
||||
ary.pack(@template)
|
||||
else
|
||||
raise(RuntimeError, "sizeof(void*)?")
|
||||
end
|
||||
end
|
||||
|
||||
def unpack(ary)
|
||||
case SIZEOF_VOIDP
|
||||
when SIZEOF_LONG
|
||||
ary.join().unpack(@template)
|
||||
when SIZEOF_LONG_LONG
|
||||
ary.join().unpack(@template)
|
||||
else
|
||||
raise(RuntimeError, "sizeof(void*)?")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_types(types)
|
||||
@template = ""
|
||||
addr = 0
|
||||
types.each{|t|
|
||||
orig_addr = addr
|
||||
if( t.is_a?(Array) )
|
||||
addr = align(orig_addr, ALIGN_MAP[TYPE_VOIDP])
|
||||
else
|
||||
addr = align(orig_addr, ALIGN_MAP[t])
|
||||
end
|
||||
d = addr - orig_addr
|
||||
if( d > 0 )
|
||||
@template << "x#{d}"
|
||||
end
|
||||
if( t.is_a?(Array) )
|
||||
@template << (PACK_MAP[t[0]] * t[1])
|
||||
addr += (SIZE_MAP[t[0]] * t[1])
|
||||
else
|
||||
@template << PACK_MAP[t]
|
||||
addr += SIZE_MAP[t]
|
||||
end
|
||||
}
|
||||
addr = align(addr, ALIGN_MAP[TYPE_VOIDP])
|
||||
@size = addr
|
||||
end
|
||||
end
|
||||
end
|
||||
116
ruby/lib/ruby/2.1.0/dl/stack.rb
Normal file
116
ruby/lib/ruby/2.1.0/dl/stack.rb
Normal file
@@ -0,0 +1,116 @@
|
||||
require 'dl'
|
||||
|
||||
module DL
|
||||
class Stack
|
||||
def self.[](*types)
|
||||
new(types)
|
||||
end
|
||||
|
||||
def initialize(types)
|
||||
parse_types(types)
|
||||
end
|
||||
|
||||
def size()
|
||||
@size
|
||||
end
|
||||
|
||||
def types()
|
||||
@types
|
||||
end
|
||||
|
||||
def pack(ary)
|
||||
case SIZEOF_VOIDP
|
||||
when SIZEOF_LONG
|
||||
ary.pack(@template).unpack('l!*')
|
||||
when SIZEOF_LONG_LONG
|
||||
ary.pack(@template).unpack('q*')
|
||||
else
|
||||
raise(RuntimeError, "sizeof(void*)?")
|
||||
end
|
||||
end
|
||||
|
||||
def unpack(ary)
|
||||
case SIZEOF_VOIDP
|
||||
when SIZEOF_LONG
|
||||
ary.pack('l!*').unpack(@template)
|
||||
when SIZEOF_LONG_LONG
|
||||
ary.pack('q*').unpack(@template)
|
||||
else
|
||||
raise(RuntimeError, "sizeof(void*)?")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def align(addr, align)
|
||||
d = addr % align
|
||||
if( d == 0 )
|
||||
addr
|
||||
else
|
||||
addr + (align - d)
|
||||
end
|
||||
end
|
||||
|
||||
ALIGN_MAP = {
|
||||
TYPE_VOIDP => ALIGN_VOIDP,
|
||||
TYPE_CHAR => ALIGN_VOIDP,
|
||||
TYPE_SHORT => ALIGN_VOIDP,
|
||||
TYPE_INT => ALIGN_VOIDP,
|
||||
TYPE_LONG => ALIGN_VOIDP,
|
||||
TYPE_FLOAT => ALIGN_FLOAT,
|
||||
TYPE_DOUBLE => ALIGN_DOUBLE,
|
||||
}
|
||||
|
||||
PACK_MAP = {
|
||||
TYPE_VOIDP => ((SIZEOF_VOIDP == SIZEOF_LONG_LONG)? "q" : "l!"),
|
||||
TYPE_CHAR => "c",
|
||||
TYPE_SHORT => "s!",
|
||||
TYPE_INT => "i!",
|
||||
TYPE_LONG => "l!",
|
||||
TYPE_FLOAT => "f",
|
||||
TYPE_DOUBLE => "d",
|
||||
}
|
||||
|
||||
SIZE_MAP = {
|
||||
TYPE_VOIDP => SIZEOF_VOIDP,
|
||||
TYPE_CHAR => SIZEOF_CHAR,
|
||||
TYPE_SHORT => SIZEOF_SHORT,
|
||||
TYPE_INT => SIZEOF_INT,
|
||||
TYPE_LONG => SIZEOF_LONG,
|
||||
TYPE_FLOAT => SIZEOF_FLOAT,
|
||||
TYPE_DOUBLE => SIZEOF_DOUBLE,
|
||||
}
|
||||
if defined?(TYPE_LONG_LONG)
|
||||
ALIGN_MAP[TYPE_LONG_LONG] = ALIGN_LONG_LONG
|
||||
PACK_MAP[TYPE_LONG_LONG] = "q"
|
||||
SIZE_MAP[TYPE_LONG_LONG] = SIZEOF_LONG_LONG
|
||||
end
|
||||
|
||||
def parse_types(types)
|
||||
@types = types
|
||||
@template = ""
|
||||
addr = 0
|
||||
types.each{|t|
|
||||
addr = add_padding(addr, ALIGN_MAP[t])
|
||||
@template << PACK_MAP[t]
|
||||
addr += SIZE_MAP[t]
|
||||
}
|
||||
addr = add_padding(addr, ALIGN_MAP[SIZEOF_VOIDP])
|
||||
if( addr % SIZEOF_VOIDP == 0 )
|
||||
@size = addr / SIZEOF_VOIDP
|
||||
else
|
||||
@size = (addr / SIZEOF_VOIDP) + 1
|
||||
end
|
||||
end
|
||||
|
||||
def add_padding(addr, align)
|
||||
orig_addr = addr
|
||||
addr = align(orig_addr, align)
|
||||
d = addr - orig_addr
|
||||
if( d > 0 )
|
||||
@template << "x#{d}"
|
||||
end
|
||||
addr
|
||||
end
|
||||
end
|
||||
end
|
||||
236
ruby/lib/ruby/2.1.0/dl/struct.rb
Normal file
236
ruby/lib/ruby/2.1.0/dl/struct.rb
Normal file
@@ -0,0 +1,236 @@
|
||||
require 'dl'
|
||||
require 'dl/value'
|
||||
require 'dl/pack.rb'
|
||||
|
||||
module DL
|
||||
# C struct shell
|
||||
class CStruct
|
||||
# accessor to DL::CStructEntity
|
||||
def CStruct.entity_class()
|
||||
CStructEntity
|
||||
end
|
||||
end
|
||||
|
||||
# C union shell
|
||||
class CUnion
|
||||
# accessor to DL::CUnionEntity
|
||||
def CUnion.entity_class()
|
||||
CUnionEntity
|
||||
end
|
||||
end
|
||||
|
||||
# Used to construct C classes (CUnion, CStruct, etc)
|
||||
#
|
||||
# DL::Importer#struct and DL::Importer#union wrap this functionality in an
|
||||
# easy-to-use manner.
|
||||
module CStructBuilder
|
||||
# Construct a new class given a C:
|
||||
# * class +klass+ (CUnion, CStruct, or other that provide an
|
||||
# #entity_class)
|
||||
# * +types+ (DL:TYPE_INT, DL::TYPE_SIZE_T, etc., see the C types
|
||||
# constants)
|
||||
# * corresponding +members+
|
||||
#
|
||||
# DL::Importer#struct and DL::Importer#union wrap this functionality in an
|
||||
# easy-to-use manner.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# require 'dl/struct'
|
||||
# require 'dl/cparser'
|
||||
#
|
||||
# include DL::CParser
|
||||
#
|
||||
# types, members = parse_struct_signature(['int i','char c'])
|
||||
#
|
||||
# MyStruct = DL::CStructBuilder.create(CUnion, types, members)
|
||||
#
|
||||
# obj = MyStruct.allocate
|
||||
#
|
||||
def create(klass, types, members)
|
||||
new_class = Class.new(klass){
|
||||
define_method(:initialize){|addr|
|
||||
@entity = klass.entity_class.new(addr, types)
|
||||
@entity.assign_names(members)
|
||||
}
|
||||
define_method(:to_ptr){ @entity }
|
||||
define_method(:to_i){ @entity.to_i }
|
||||
members.each{|name|
|
||||
define_method(name){ @entity[name] }
|
||||
define_method(name + "="){|val| @entity[name] = val }
|
||||
}
|
||||
}
|
||||
size = klass.entity_class.size(types)
|
||||
new_class.module_eval(<<-EOS, __FILE__, __LINE__+1)
|
||||
def new_class.size()
|
||||
#{size}
|
||||
end
|
||||
def new_class.malloc()
|
||||
addr = DL.malloc(#{size})
|
||||
new(addr)
|
||||
end
|
||||
EOS
|
||||
return new_class
|
||||
end
|
||||
module_function :create
|
||||
end
|
||||
|
||||
# A C struct wrapper
|
||||
class CStructEntity < (DL.fiddle? ? Fiddle::Pointer : CPtr)
|
||||
include PackInfo
|
||||
include ValueUtil
|
||||
|
||||
# Allocates a C struct the +types+ provided. The C function +func+ is
|
||||
# called when the instance is garbage collected.
|
||||
def CStructEntity.malloc(types, func = nil)
|
||||
addr = DL.malloc(CStructEntity.size(types))
|
||||
CStructEntity.new(addr, types, func)
|
||||
end
|
||||
|
||||
# Given +types+, returns the offset for the packed sizes of those types
|
||||
#
|
||||
# DL::CStructEntity.size([DL::TYPE_DOUBLE, DL::TYPE_INT, DL::TYPE_CHAR,
|
||||
# DL::TYPE_VOIDP])
|
||||
# => 24
|
||||
def CStructEntity.size(types)
|
||||
offset = 0
|
||||
|
||||
max_align = types.map { |type, count = 1|
|
||||
last_offset = offset
|
||||
|
||||
align = PackInfo::ALIGN_MAP[type]
|
||||
offset = PackInfo.align(last_offset, align) +
|
||||
(PackInfo::SIZE_MAP[type] * count)
|
||||
|
||||
align
|
||||
}.max
|
||||
|
||||
PackInfo.align(offset, max_align)
|
||||
end
|
||||
|
||||
# Wraps the C pointer +addr+ as a C struct with the given +types+. The C
|
||||
# function +func+ is called when the instance is garbage collected.
|
||||
#
|
||||
# See also DL::CPtr.new
|
||||
def initialize(addr, types, func = nil)
|
||||
set_ctypes(types)
|
||||
super(addr, @size, func)
|
||||
end
|
||||
|
||||
# Set the names of the +members+ in this C struct
|
||||
def assign_names(members)
|
||||
@members = members
|
||||
end
|
||||
|
||||
# Given +types+, calculate the offsets and sizes for the types in the
|
||||
# struct.
|
||||
def set_ctypes(types)
|
||||
@ctypes = types
|
||||
@offset = []
|
||||
offset = 0
|
||||
|
||||
max_align = types.map { |type, count = 1|
|
||||
orig_offset = offset
|
||||
align = ALIGN_MAP[type]
|
||||
offset = PackInfo.align(orig_offset, align)
|
||||
|
||||
@offset << offset
|
||||
|
||||
offset += (SIZE_MAP[type] * count)
|
||||
|
||||
align
|
||||
}.max
|
||||
|
||||
@size = PackInfo.align(offset, max_align)
|
||||
end
|
||||
|
||||
# Fetch struct member +name+
|
||||
def [](name)
|
||||
idx = @members.index(name)
|
||||
if( idx.nil? )
|
||||
raise(ArgumentError, "no such member: #{name}")
|
||||
end
|
||||
ty = @ctypes[idx]
|
||||
if( ty.is_a?(Array) )
|
||||
r = super(@offset[idx], SIZE_MAP[ty[0]] * ty[1])
|
||||
else
|
||||
r = super(@offset[idx], SIZE_MAP[ty.abs])
|
||||
end
|
||||
packer = Packer.new([ty])
|
||||
val = packer.unpack([r])
|
||||
case ty
|
||||
when Array
|
||||
case ty[0]
|
||||
when TYPE_VOIDP
|
||||
val = val.collect{|v| CPtr.new(v)}
|
||||
end
|
||||
when TYPE_VOIDP
|
||||
val = CPtr.new(val[0])
|
||||
else
|
||||
val = val[0]
|
||||
end
|
||||
if( ty.is_a?(Integer) && (ty < 0) )
|
||||
return unsigned_value(val, ty)
|
||||
elsif( ty.is_a?(Array) && (ty[0] < 0) )
|
||||
return val.collect{|v| unsigned_value(v,ty[0])}
|
||||
else
|
||||
return val
|
||||
end
|
||||
end
|
||||
|
||||
# Set struct member +name+, to value +val+
|
||||
def []=(name, val)
|
||||
idx = @members.index(name)
|
||||
if( idx.nil? )
|
||||
raise(ArgumentError, "no such member: #{name}")
|
||||
end
|
||||
ty = @ctypes[idx]
|
||||
packer = Packer.new([ty])
|
||||
val = wrap_arg(val, ty, [])
|
||||
buff = packer.pack([val].flatten())
|
||||
super(@offset[idx], buff.size, buff)
|
||||
if( ty.is_a?(Integer) && (ty < 0) )
|
||||
return unsigned_value(val, ty)
|
||||
elsif( ty.is_a?(Array) && (ty[0] < 0) )
|
||||
return val.collect{|v| unsigned_value(v,ty[0])}
|
||||
else
|
||||
return val
|
||||
end
|
||||
end
|
||||
|
||||
def to_s() # :nodoc:
|
||||
super(@size)
|
||||
end
|
||||
end
|
||||
|
||||
# A C union wrapper
|
||||
class CUnionEntity < CStructEntity
|
||||
include PackInfo
|
||||
|
||||
# Allocates a C union the +types+ provided. The C function +func+ is
|
||||
# called when the instance is garbage collected.
|
||||
def CUnionEntity.malloc(types, func=nil)
|
||||
addr = DL.malloc(CUnionEntity.size(types))
|
||||
CUnionEntity.new(addr, types, func)
|
||||
end
|
||||
|
||||
# Given +types+, returns the size needed for the union.
|
||||
#
|
||||
# DL::CUnionEntity.size([DL::TYPE_DOUBLE, DL::TYPE_INT, DL::TYPE_CHAR,
|
||||
# DL::TYPE_VOIDP])
|
||||
# => 8
|
||||
def CUnionEntity.size(types)
|
||||
types.map { |type, count = 1|
|
||||
PackInfo::SIZE_MAP[type] * count
|
||||
}.max
|
||||
end
|
||||
|
||||
# Given +types+, calculate the necessary offset and for each union member
|
||||
def set_ctypes(types)
|
||||
@ctypes = types
|
||||
@offset = Array.new(types.length, 0)
|
||||
@size = self.class.size types
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
71
ruby/lib/ruby/2.1.0/dl/types.rb
Normal file
71
ruby/lib/ruby/2.1.0/dl/types.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
module DL
|
||||
# Adds Windows type aliases to the including class for use with
|
||||
# DL::Importer.
|
||||
#
|
||||
# The aliases added are:
|
||||
# * ATOM
|
||||
# * BOOL
|
||||
# * BYTE
|
||||
# * DWORD
|
||||
# * DWORD32
|
||||
# * DWORD64
|
||||
# * HANDLE
|
||||
# * HDC
|
||||
# * HINSTANCE
|
||||
# * HWND
|
||||
# * LPCSTR
|
||||
# * LPSTR
|
||||
# * PBYTE
|
||||
# * PDWORD
|
||||
# * PHANDLE
|
||||
# * PVOID
|
||||
# * PWORD
|
||||
# * UCHAR
|
||||
# * UINT
|
||||
# * ULONG
|
||||
# * WORD
|
||||
module Win32Types
|
||||
def included(m) # :nodoc:
|
||||
m.module_eval{
|
||||
typealias "DWORD", "unsigned long"
|
||||
typealias "PDWORD", "unsigned long *"
|
||||
typealias "DWORD32", "unsigned long"
|
||||
typealias "DWORD64", "unsigned long long"
|
||||
typealias "WORD", "unsigned short"
|
||||
typealias "PWORD", "unsigned short *"
|
||||
typealias "BOOL", "int"
|
||||
typealias "ATOM", "int"
|
||||
typealias "BYTE", "unsigned char"
|
||||
typealias "PBYTE", "unsigned char *"
|
||||
typealias "UINT", "unsigned int"
|
||||
typealias "ULONG", "unsigned long"
|
||||
typealias "UCHAR", "unsigned char"
|
||||
typealias "HANDLE", "uintptr_t"
|
||||
typealias "PHANDLE", "void*"
|
||||
typealias "PVOID", "void*"
|
||||
typealias "LPCSTR", "char*"
|
||||
typealias "LPSTR", "char*"
|
||||
typealias "HINSTANCE", "unsigned int"
|
||||
typealias "HDC", "unsigned int"
|
||||
typealias "HWND", "unsigned int"
|
||||
}
|
||||
end
|
||||
module_function :included
|
||||
end
|
||||
|
||||
# Adds basic type aliases to the including class for use with DL::Importer.
|
||||
#
|
||||
# The aliases added are +uint+ and +u_int+ (<tt>unsigned int</tt>) and
|
||||
# +ulong+ and +u_long+ (<tt>unsigned long</tt>)
|
||||
module BasicTypes
|
||||
def included(m) # :nodoc:
|
||||
m.module_eval{
|
||||
typealias "uint", "unsigned int"
|
||||
typealias "u_int", "unsigned int"
|
||||
typealias "ulong", "unsigned long"
|
||||
typealias "u_long", "unsigned long"
|
||||
}
|
||||
end
|
||||
module_function :included
|
||||
end
|
||||
end
|
||||
114
ruby/lib/ruby/2.1.0/dl/value.rb
Normal file
114
ruby/lib/ruby/2.1.0/dl/value.rb
Normal file
@@ -0,0 +1,114 @@
|
||||
require 'dl'
|
||||
|
||||
module DL
|
||||
module ValueUtil
|
||||
def unsigned_value(val, ty)
|
||||
case ty.abs
|
||||
when TYPE_CHAR
|
||||
[val].pack("c").unpack("C")[0]
|
||||
when TYPE_SHORT
|
||||
[val].pack("s!").unpack("S!")[0]
|
||||
when TYPE_INT
|
||||
[val].pack("i!").unpack("I!")[0]
|
||||
when TYPE_LONG
|
||||
[val].pack("l!").unpack("L!")[0]
|
||||
when TYPE_LONG_LONG
|
||||
[val].pack("q").unpack("Q")[0]
|
||||
else
|
||||
val
|
||||
end
|
||||
end
|
||||
|
||||
def signed_value(val, ty)
|
||||
case ty.abs
|
||||
when TYPE_CHAR
|
||||
[val].pack("C").unpack("c")[0]
|
||||
when TYPE_SHORT
|
||||
[val].pack("S!").unpack("s!")[0]
|
||||
when TYPE_INT
|
||||
[val].pack("I!").unpack("i!")[0]
|
||||
when TYPE_LONG
|
||||
[val].pack("L!").unpack("l!")[0]
|
||||
when TYPE_LONG_LONG
|
||||
[val].pack("Q").unpack("q")[0]
|
||||
else
|
||||
val
|
||||
end
|
||||
end
|
||||
|
||||
def wrap_args(args, tys, funcs, &block)
|
||||
result = []
|
||||
tys ||= []
|
||||
args.each_with_index{|arg, idx|
|
||||
result.push(wrap_arg(arg, tys[idx], funcs, &block))
|
||||
}
|
||||
result
|
||||
end
|
||||
|
||||
def wrap_arg(arg, ty, funcs = [], &block)
|
||||
require 'dl/func'
|
||||
|
||||
funcs ||= []
|
||||
case arg
|
||||
when nil
|
||||
return 0
|
||||
when CPtr
|
||||
return arg.to_i
|
||||
when IO
|
||||
case ty
|
||||
when TYPE_VOIDP
|
||||
return CPtr[arg].to_i
|
||||
else
|
||||
return arg.to_i
|
||||
end
|
||||
when Function
|
||||
if( block )
|
||||
arg.bind_at_call(&block)
|
||||
funcs.push(arg)
|
||||
elsif !arg.bound?
|
||||
raise(RuntimeError, "block must be given.")
|
||||
end
|
||||
return arg.to_i
|
||||
when String
|
||||
if( ty.is_a?(Array) )
|
||||
return arg.unpack('C*')
|
||||
else
|
||||
case SIZEOF_VOIDP
|
||||
when SIZEOF_LONG
|
||||
return [arg].pack("p").unpack("l!")[0]
|
||||
when SIZEOF_LONG_LONG
|
||||
return [arg].pack("p").unpack("q")[0]
|
||||
else
|
||||
raise(RuntimeError, "sizeof(void*)?")
|
||||
end
|
||||
end
|
||||
when Float, Integer
|
||||
return arg
|
||||
when Array
|
||||
if( ty.is_a?(Array) ) # used only by struct
|
||||
case ty[0]
|
||||
when TYPE_VOIDP
|
||||
return arg.collect{|v| Integer(v)}
|
||||
when TYPE_CHAR
|
||||
if( arg.is_a?(String) )
|
||||
return val.unpack('C*')
|
||||
end
|
||||
end
|
||||
return arg
|
||||
else
|
||||
return arg
|
||||
end
|
||||
else
|
||||
if( arg.respond_to?(:to_ptr) )
|
||||
return arg.to_ptr.to_i
|
||||
else
|
||||
begin
|
||||
return Integer(arg)
|
||||
rescue
|
||||
raise(ArgumentError, "unknown argument type: #{arg.class}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
2
ruby/lib/ruby/2.1.0/drb.rb
Normal file
2
ruby/lib/ruby/2.1.0/drb.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
require 'drb/drb'
|
||||
|
||||
250
ruby/lib/ruby/2.1.0/drb/acl.rb
Normal file
250
ruby/lib/ruby/2.1.0/drb/acl.rb
Normal file
@@ -0,0 +1,250 @@
|
||||
# Copyright (c) 2000,2002,2003 Masatoshi SEKI
|
||||
#
|
||||
# acl.rb is copyrighted free software by Masatoshi SEKI.
|
||||
# You can redistribute it and/or modify it under the same terms as Ruby.
|
||||
|
||||
require 'ipaddr'
|
||||
|
||||
##
|
||||
# Simple Access Control Lists.
|
||||
#
|
||||
# Access control lists are composed of "allow" and "deny" halves to control
|
||||
# access. Use "all" or "*" to match any address. To match a specific address
|
||||
# use any address or address mask that IPAddr can understand.
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# list = %w[
|
||||
# deny all
|
||||
# allow 192.168.1.1
|
||||
# allow ::ffff:192.168.1.2
|
||||
# allow 192.168.1.3
|
||||
# ]
|
||||
#
|
||||
# # From Socket#peeraddr, see also ACL#allow_socket?
|
||||
# addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
|
||||
#
|
||||
# acl = ACL.new
|
||||
# p acl.allow_addr?(addr) # => true
|
||||
#
|
||||
# acl = ACL.new(list, ACL::DENY_ALLOW)
|
||||
# p acl.allow_addr?(addr) # => true
|
||||
|
||||
class ACL
|
||||
|
||||
##
|
||||
# The current version of ACL
|
||||
|
||||
VERSION=["2.0.0"]
|
||||
|
||||
##
|
||||
# An entry in an ACL
|
||||
|
||||
class ACLEntry
|
||||
|
||||
##
|
||||
# Creates a new entry using +str+.
|
||||
#
|
||||
# +str+ may be "*" or "all" to match any address, an IP address string
|
||||
# to match a specific address, an IP address mask per IPAddr, or one
|
||||
# containing "*" to match part of an IPv4 address.
|
||||
|
||||
def initialize(str)
|
||||
if str == '*' or str == 'all'
|
||||
@pat = [:all]
|
||||
elsif str.include?('*')
|
||||
@pat = [:name, dot_pat(str)]
|
||||
else
|
||||
begin
|
||||
@pat = [:ip, IPAddr.new(str)]
|
||||
rescue ArgumentError
|
||||
@pat = [:name, dot_pat(str)]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Creates a regular expression to match IPv4 addresses
|
||||
|
||||
def dot_pat_str(str)
|
||||
list = str.split('.').collect { |s|
|
||||
(s == '*') ? '.+' : s
|
||||
}
|
||||
list.join("\\.")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Creates a Regexp to match an address.
|
||||
|
||||
def dot_pat(str)
|
||||
exp = "^" + dot_pat_str(str) + "$"
|
||||
Regexp.new(exp)
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
##
|
||||
# Matches +addr+ against this entry.
|
||||
|
||||
def match(addr)
|
||||
case @pat[0]
|
||||
when :all
|
||||
true
|
||||
when :ip
|
||||
begin
|
||||
ipaddr = IPAddr.new(addr[3])
|
||||
ipaddr = ipaddr.ipv4_mapped if @pat[1].ipv6? && ipaddr.ipv4?
|
||||
rescue ArgumentError
|
||||
return false
|
||||
end
|
||||
(@pat[1].include?(ipaddr)) ? true : false
|
||||
when :name
|
||||
(@pat[1] =~ addr[2]) ? true : false
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# A list of ACLEntry objects. Used to implement the allow and deny halves
|
||||
# of an ACL
|
||||
|
||||
class ACLList
|
||||
|
||||
##
|
||||
# Creates an empty ACLList
|
||||
|
||||
def initialize
|
||||
@list = []
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
##
|
||||
# Matches +addr+ against each ACLEntry in this list.
|
||||
|
||||
def match(addr)
|
||||
@list.each do |e|
|
||||
return true if e.match(addr)
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
##
|
||||
# Adds +str+ as an ACLEntry in this list
|
||||
|
||||
def add(str)
|
||||
@list.push(ACLEntry.new(str))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
##
|
||||
# Default to deny
|
||||
|
||||
DENY_ALLOW = 0
|
||||
|
||||
##
|
||||
# Default to allow
|
||||
|
||||
ALLOW_DENY = 1
|
||||
|
||||
##
|
||||
# Creates a new ACL from +list+ with an evaluation +order+ of DENY_ALLOW or
|
||||
# ALLOW_DENY.
|
||||
#
|
||||
# An ACL +list+ is an Array of "allow" or "deny" and an address or address
|
||||
# mask or "all" or "*" to match any address:
|
||||
#
|
||||
# %w[
|
||||
# deny all
|
||||
# allow 192.0.2.2
|
||||
# allow 192.0.2.128/26
|
||||
# ]
|
||||
|
||||
def initialize(list=nil, order = DENY_ALLOW)
|
||||
@order = order
|
||||
@deny = ACLList.new
|
||||
@allow = ACLList.new
|
||||
install_list(list) if list
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
##
|
||||
# Allow connections from Socket +soc+?
|
||||
|
||||
def allow_socket?(soc)
|
||||
allow_addr?(soc.peeraddr)
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
##
|
||||
# Allow connections from addrinfo +addr+? It must be formatted like
|
||||
# Socket#peeraddr:
|
||||
#
|
||||
# ["AF_INET", 10, "lc630", "192.0.2.1"]
|
||||
|
||||
def allow_addr?(addr)
|
||||
case @order
|
||||
when DENY_ALLOW
|
||||
return true if @allow.match(addr)
|
||||
return false if @deny.match(addr)
|
||||
return true
|
||||
when ALLOW_DENY
|
||||
return false if @deny.match(addr)
|
||||
return true if @allow.match(addr)
|
||||
return false
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
public
|
||||
|
||||
##
|
||||
# Adds +list+ of ACL entries to this ACL.
|
||||
|
||||
def install_list(list)
|
||||
i = 0
|
||||
while i < list.size
|
||||
permission, domain = list.slice(i,2)
|
||||
case permission.downcase
|
||||
when 'allow'
|
||||
@allow.add(domain)
|
||||
when 'deny'
|
||||
@deny.add(domain)
|
||||
else
|
||||
raise "Invalid ACL entry #{list.to_s}"
|
||||
end
|
||||
i += 2
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
# example
|
||||
list = %w(deny all
|
||||
allow 192.168.1.1
|
||||
allow ::ffff:192.168.1.2
|
||||
allow 192.168.1.3
|
||||
)
|
||||
|
||||
addr = ["AF_INET", 10, "lc630", "192.168.1.3"]
|
||||
|
||||
acl = ACL.new
|
||||
p acl.allow_addr?(addr)
|
||||
|
||||
acl = ACL.new(list, ACL::DENY_ALLOW)
|
||||
p acl.allow_addr?(addr)
|
||||
end
|
||||
|
||||
1833
ruby/lib/ruby/2.1.0/drb/drb.rb
Normal file
1833
ruby/lib/ruby/2.1.0/drb/drb.rb
Normal file
File diff suppressed because it is too large
Load Diff
14
ruby/lib/ruby/2.1.0/drb/eq.rb
Normal file
14
ruby/lib/ruby/2.1.0/drb/eq.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
module DRb
|
||||
class DRbObject # :nodoc:
|
||||
def ==(other)
|
||||
return false unless DRbObject === other
|
||||
(@ref == other.__drbref) && (@uri == other.__drburi)
|
||||
end
|
||||
|
||||
def hash
|
||||
[@uri, @ref].hash
|
||||
end
|
||||
|
||||
alias eql? ==
|
||||
end
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user