mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27366 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c89882197e
commit
75c1cac7f3
442 changed files with 4654 additions and 4654 deletions
|
@ -11,10 +11,10 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
reg['foo'] = 'bar' # write a value
|
reg['foo'] = 'bar' # write a value
|
||||||
reg['foo', Win32::Registry::REG_SZ] = 'bar' # write a value with type
|
reg['foo', Win32::Registry::REG_SZ] = 'bar' # write a value with type
|
||||||
reg.write('foo', Win32::Registry::REG_SZ, 'bar') # write a value
|
reg.write('foo', Win32::Registry::REG_SZ, 'bar') # write a value
|
||||||
|
|
||||||
reg.each_value { |name, type, data| ... } # Enumerate values
|
reg.each_value { |name, type, data| ... } # Enumerate values
|
||||||
reg.each_key { |key, wtime| ... } # Enumerate subkeys
|
reg.each_key { |key, wtime| ... } # Enumerate subkeys
|
||||||
|
|
||||||
reg.delete_value(name) # Delete a value
|
reg.delete_value(name) # Delete a value
|
||||||
reg.delete_key(name) # Delete a subkey
|
reg.delete_key(name) # Delete a subkey
|
||||||
reg.delete_key(name, true) # Delete a subkey recursively
|
reg.delete_key(name, true) # Delete a subkey recursively
|
||||||
|
@ -35,26 +35,26 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
Open the registry key ((|subkey|)) under ((|key|)).
|
Open the registry key ((|subkey|)) under ((|key|)).
|
||||||
((|key|)) is Win32::Registry object of parent key.
|
((|key|)) is Win32::Registry object of parent key.
|
||||||
You can use predefined key HKEY_* (see ((<constants>)))
|
You can use predefined key HKEY_* (see ((<constants>)))
|
||||||
|
|
||||||
((|desired|)) and ((|opt|)) is access mask and key option.
|
((|desired|)) and ((|opt|)) is access mask and key option.
|
||||||
For detail, see ((<MSDN Library|URL:http://msdn.microsoft.com/library/en-us/sysinfo/base/regopenkeyex.asp>)).
|
For detail, see ((<MSDN Library|URL:http://msdn.microsoft.com/library/en-us/sysinfo/base/regopenkeyex.asp>)).
|
||||||
|
|
||||||
If block is given, the key is closed automatically.
|
If block is given, the key is closed automatically.
|
||||||
|
|
||||||
--- Registry.create(key, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED)
|
--- Registry.create(key, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED)
|
||||||
--- Registry.create(key, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED) { |reg| ... }
|
--- Registry.create(key, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED) { |reg| ... }
|
||||||
Create or open the registry key ((|subkey|)) under ((|key|)).
|
Create or open the registry key ((|subkey|)) under ((|key|)).
|
||||||
You can use predefined key HKEY_* (see ((<constants>)))
|
You can use predefined key HKEY_* (see ((<constants>)))
|
||||||
|
|
||||||
If subkey is already exists, key is opened and Registry#((<created?>))
|
If subkey is already exists, key is opened and Registry#((<created?>))
|
||||||
method will return false.
|
method will return false.
|
||||||
|
|
||||||
If block is given, the key is closed automatically.
|
If block is given, the key is closed automatically.
|
||||||
|
|
||||||
--- Registry.expand_environ(str)
|
--- Registry.expand_environ(str)
|
||||||
Replace (({%\w+%})) into the environment value of ((|str|)).
|
Replace (({%\w+%})) into the environment value of ((|str|)).
|
||||||
This method is used for REG_EXPAND_SZ.
|
This method is used for REG_EXPAND_SZ.
|
||||||
|
|
||||||
For detail, see ((<ExpandEnvironmentStrings|URL:http://msdn.microsoft.com/library/en-us/sysinfo/base/expandenvironmentstrings.asp>)) Win32 API.
|
For detail, see ((<ExpandEnvironmentStrings|URL:http://msdn.microsoft.com/library/en-us/sysinfo/base/expandenvironmentstrings.asp>)) Win32 API.
|
||||||
|
|
||||||
--- Registry.type2name(type)
|
--- Registry.type2name(type)
|
||||||
|
@ -75,14 +75,14 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
|
|
||||||
--- close
|
--- close
|
||||||
Close key.
|
Close key.
|
||||||
|
|
||||||
After closed, most method raises error.
|
After closed, most method raises error.
|
||||||
|
|
||||||
--- read(name, *rtype)
|
--- read(name, *rtype)
|
||||||
Read a registry value named ((|name|)) and return array of
|
Read a registry value named ((|name|)) and return array of
|
||||||
[ ((|type|)), ((|data|)) ].
|
[ ((|type|)), ((|data|)) ].
|
||||||
When name is nil, the `default' value is read.
|
When name is nil, the `default' value is read.
|
||||||
|
|
||||||
((|type|)) is value type. (see ((<Win32::Registry::Constants module>)))
|
((|type|)) is value type. (see ((<Win32::Registry::Constants module>)))
|
||||||
((|data|)) is value data, its class is:
|
((|data|)) is value data, its class is:
|
||||||
:REG_SZ, REG_EXPAND_SZ
|
:REG_SZ, REG_EXPAND_SZ
|
||||||
|
@ -93,19 +93,19 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
Integer
|
Integer
|
||||||
:REG_BINARY
|
:REG_BINARY
|
||||||
String (contains binary data)
|
String (contains binary data)
|
||||||
|
|
||||||
When ((|rtype|)) is specified, the value type must be included by
|
When ((|rtype|)) is specified, the value type must be included by
|
||||||
((|rtype|)) array, or TypeError is raised.
|
((|rtype|)) array, or TypeError is raised.
|
||||||
|
|
||||||
--- self[name, *rtype]
|
--- self[name, *rtype]
|
||||||
Read a registry value named ((|name|)) and return its value data.
|
Read a registry value named ((|name|)) and return its value data.
|
||||||
The class of value is same as ((<read>)) method returns.
|
The class of value is same as ((<read>)) method returns.
|
||||||
|
|
||||||
If the value type is REG_EXPAND_SZ, returns value data whose environment
|
If the value type is REG_EXPAND_SZ, returns value data whose environment
|
||||||
variables are replaced.
|
variables are replaced.
|
||||||
If the value type is neither REG_SZ, REG_MULTI_SZ, REG_DWORD,
|
If the value type is neither REG_SZ, REG_MULTI_SZ, REG_DWORD,
|
||||||
REG_DWORD_BIG_ENDIAN, nor REG_QWORD, TypeError is raised.
|
REG_DWORD_BIG_ENDIAN, nor REG_QWORD, TypeError is raised.
|
||||||
|
|
||||||
The meaning of ((|rtype|)) is same as ((<read>)) method.
|
The meaning of ((|rtype|)) is same as ((<read>)) method.
|
||||||
|
|
||||||
--- read_s(name)
|
--- read_s(name)
|
||||||
|
@ -113,26 +113,26 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
--- read_bin(name)
|
--- read_bin(name)
|
||||||
Read a REG_SZ(read_s), REG_DWORD(read_i), or REG_BINARY(read_bin)
|
Read a REG_SZ(read_s), REG_DWORD(read_i), or REG_BINARY(read_bin)
|
||||||
registry value named ((|name|)).
|
registry value named ((|name|)).
|
||||||
|
|
||||||
If the values type does not match, TypeError is raised.
|
If the values type does not match, TypeError is raised.
|
||||||
|
|
||||||
--- read_s_expand(name)
|
--- read_s_expand(name)
|
||||||
Read a REG_SZ or REG_EXPAND_SZ registry value named ((|name|)).
|
Read a REG_SZ or REG_EXPAND_SZ registry value named ((|name|)).
|
||||||
|
|
||||||
If the value type is REG_EXPAND_SZ, environment variables are replaced.
|
If the value type is REG_EXPAND_SZ, environment variables are replaced.
|
||||||
Unless the value type is REG_SZ or REG_EXPAND_SZ, TypeError is raised.
|
Unless the value type is REG_SZ or REG_EXPAND_SZ, TypeError is raised.
|
||||||
|
|
||||||
--- write(name, type, data)
|
--- write(name, type, data)
|
||||||
Write ((|data|)) to a registry value named ((|name|)).
|
Write ((|data|)) to a registry value named ((|name|)).
|
||||||
When name is nil, write to the `default' value.
|
When name is nil, write to the `default' value.
|
||||||
|
|
||||||
((|type|)) is type value. (see ((<Registry::Constants module>)))
|
((|type|)) is type value. (see ((<Registry::Constants module>)))
|
||||||
Class of ((|data|)) must be same as which ((<read>))
|
Class of ((|data|)) must be same as which ((<read>))
|
||||||
method returns.
|
method returns.
|
||||||
|
|
||||||
--- self[name, wtype = nil] = value
|
--- self[name, wtype = nil] = value
|
||||||
Write ((|value|)) to a registry value named ((|name|)).
|
Write ((|value|)) to a registry value named ((|name|)).
|
||||||
|
|
||||||
If ((|wtype|)) is specified, the value type is it.
|
If ((|wtype|)) is specified, the value type is it.
|
||||||
Otherwise, the value type is depend on class of ((|value|)):
|
Otherwise, the value type is depend on class of ((|value|)):
|
||||||
:Integer
|
:Integer
|
||||||
|
@ -146,7 +146,7 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
--- write_i(name, value)
|
--- write_i(name, value)
|
||||||
--- write_bin(name, value)
|
--- write_bin(name, value)
|
||||||
Write ((|value|)) to a registry value named ((|name|)).
|
Write ((|value|)) to a registry value named ((|name|)).
|
||||||
|
|
||||||
The value type is REG_SZ(write_s), REG_DWORD(write_i), or
|
The value type is REG_SZ(write_s), REG_DWORD(write_i), or
|
||||||
REG_BINARY(write_bin).
|
REG_BINARY(write_bin).
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
|
|
||||||
--- each_key { |subkey, wtime| ... }
|
--- each_key { |subkey, wtime| ... }
|
||||||
Enumerate subkeys.
|
Enumerate subkeys.
|
||||||
|
|
||||||
((|subkey|)) is String which contains name of subkey.
|
((|subkey|)) is String which contains name of subkey.
|
||||||
((|wtime|)) is last write time as FILETIME (64-bit integer).
|
((|wtime|)) is last write time as FILETIME (64-bit integer).
|
||||||
(see ((<Registry.wtime2time>)))
|
(see ((<Registry.wtime2time>)))
|
||||||
|
@ -168,7 +168,7 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
|
|
||||||
--- delete_key(name, recursive = false)
|
--- delete_key(name, recursive = false)
|
||||||
Delete a subkey named ((|name|)) and all its values.
|
Delete a subkey named ((|name|)) and all its values.
|
||||||
|
|
||||||
If ((|recursive|)) is false, the subkey must not have subkeys.
|
If ((|recursive|)) is false, the subkey must not have subkeys.
|
||||||
Otherwise, this method deletes all subkeys and values recursively.
|
Otherwise, this method deletes all subkeys and values recursively.
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ It uses Win32API to call Win32 Registry APIs.
|
||||||
Length of security descriptor.
|
Length of security descriptor.
|
||||||
:wtime
|
:wtime
|
||||||
Last write time as FILETIME(64-bit integer)
|
Last write time as FILETIME(64-bit integer)
|
||||||
|
|
||||||
For detail, see ((<RegQueryInfoKey|URL:http://msdn.microsoft.com/library/en-us/sysinfo/base/regqueryinfokey.asp>)) Win32 API.
|
For detail, see ((<RegQueryInfoKey|URL:http://msdn.microsoft.com/library/en-us/sysinfo/base/regqueryinfokey.asp>)) Win32 API.
|
||||||
|
|
||||||
--- num_keys
|
--- num_keys
|
||||||
|
@ -275,7 +275,7 @@ module Win32
|
||||||
HKEY_PERFORMANCE_NLSTEXT = 0x80000060
|
HKEY_PERFORMANCE_NLSTEXT = 0x80000060
|
||||||
HKEY_CURRENT_CONFIG = 0x80000005
|
HKEY_CURRENT_CONFIG = 0x80000005
|
||||||
HKEY_DYN_DATA = 0x80000006
|
HKEY_DYN_DATA = 0x80000006
|
||||||
|
|
||||||
REG_NONE = 0
|
REG_NONE = 0
|
||||||
REG_SZ = 1
|
REG_SZ = 1
|
||||||
REG_EXPAND_SZ = 2
|
REG_EXPAND_SZ = 2
|
||||||
|
@ -290,7 +290,7 @@ module Win32
|
||||||
REG_RESOURCE_REQUIREMENTS_LIST = 10
|
REG_RESOURCE_REQUIREMENTS_LIST = 10
|
||||||
REG_QWORD = 11
|
REG_QWORD = 11
|
||||||
REG_QWORD_LITTLE_ENDIAN = 11
|
REG_QWORD_LITTLE_ENDIAN = 11
|
||||||
|
|
||||||
STANDARD_RIGHTS_READ = 0x00020000
|
STANDARD_RIGHTS_READ = 0x00020000
|
||||||
STANDARD_RIGHTS_WRITE = 0x00020000
|
STANDARD_RIGHTS_WRITE = 0x00020000
|
||||||
KEY_QUERY_VALUE = 0x0001
|
KEY_QUERY_VALUE = 0x0001
|
||||||
|
@ -305,7 +305,7 @@ module Win32
|
||||||
KEY_SET_VALUE | KEY_CREATE_SUB_KEY
|
KEY_SET_VALUE | KEY_CREATE_SUB_KEY
|
||||||
KEY_EXECUTE = KEY_READ
|
KEY_EXECUTE = KEY_READ
|
||||||
KEY_ALL_ACCESS = KEY_READ | KEY_WRITE | KEY_CREATE_LINK
|
KEY_ALL_ACCESS = KEY_READ | KEY_WRITE | KEY_CREATE_LINK
|
||||||
|
|
||||||
REG_OPTION_RESERVED = 0x0000
|
REG_OPTION_RESERVED = 0x0000
|
||||||
REG_OPTION_NON_VOLATILE = 0x0000
|
REG_OPTION_NON_VOLATILE = 0x0000
|
||||||
REG_OPTION_VOLATILE = 0x0001
|
REG_OPTION_VOLATILE = 0x0001
|
||||||
|
@ -315,21 +315,21 @@ module Win32
|
||||||
REG_LEGAL_OPTION = REG_OPTION_RESERVED |
|
REG_LEGAL_OPTION = REG_OPTION_RESERVED |
|
||||||
REG_OPTION_NON_VOLATILE | REG_OPTION_CREATE_LINK |
|
REG_OPTION_NON_VOLATILE | REG_OPTION_CREATE_LINK |
|
||||||
REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK
|
REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK
|
||||||
|
|
||||||
REG_CREATED_NEW_KEY = 1
|
REG_CREATED_NEW_KEY = 1
|
||||||
REG_OPENED_EXISTING_KEY = 2
|
REG_OPENED_EXISTING_KEY = 2
|
||||||
|
|
||||||
REG_WHOLE_HIVE_VOLATILE = 0x0001
|
REG_WHOLE_HIVE_VOLATILE = 0x0001
|
||||||
REG_REFRESH_HIVE = 0x0002
|
REG_REFRESH_HIVE = 0x0002
|
||||||
REG_NO_LAZY_FLUSH = 0x0004
|
REG_NO_LAZY_FLUSH = 0x0004
|
||||||
REG_FORCE_RESTORE = 0x0008
|
REG_FORCE_RESTORE = 0x0008
|
||||||
|
|
||||||
MAX_KEY_LENGTH = 514
|
MAX_KEY_LENGTH = 514
|
||||||
MAX_VALUE_LENGTH = 32768
|
MAX_VALUE_LENGTH = 32768
|
||||||
end
|
end
|
||||||
include Constants
|
include Constants
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
#
|
#
|
||||||
# Error
|
# Error
|
||||||
#
|
#
|
||||||
|
@ -343,7 +343,7 @@ module Win32
|
||||||
end
|
end
|
||||||
attr_reader :code
|
attr_reader :code
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Predefined Keys
|
# Predefined Keys
|
||||||
#
|
#
|
||||||
|
@ -354,23 +354,23 @@ module Win32
|
||||||
@keyname = keyname
|
@keyname = keyname
|
||||||
@disposition = REG_OPENED_EXISTING_KEY
|
@disposition = REG_OPENED_EXISTING_KEY
|
||||||
end
|
end
|
||||||
|
|
||||||
# Predefined keys cannot be closed
|
# Predefined keys cannot be closed
|
||||||
def close
|
def close
|
||||||
raise Error.new(5) ## ERROR_ACCESS_DENIED
|
raise Error.new(5) ## ERROR_ACCESS_DENIED
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fake class for Registry#open, Registry#create
|
# Fake class for Registry#open, Registry#create
|
||||||
def class
|
def class
|
||||||
Registry
|
Registry
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make all
|
# Make all
|
||||||
Constants.constants.grep(/^HKEY_/) do |c|
|
Constants.constants.grep(/^HKEY_/) do |c|
|
||||||
Registry.const_set c, new(Constants.const_get(c), c)
|
Registry.const_set c, new(Constants.const_get(c), c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Win32 APIs
|
# Win32 APIs
|
||||||
#
|
#
|
||||||
|
@ -390,37 +390,37 @@ module Win32
|
||||||
].each do |fn|
|
].each do |fn|
|
||||||
const_set fn[0].intern, Win32API.new('advapi32.dll', *fn)
|
const_set fn[0].intern, Win32API.new('advapi32.dll', *fn)
|
||||||
end
|
end
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def check(result)
|
def check(result)
|
||||||
raise Error, result, caller(2) if result != 0
|
raise Error, result, caller(2) if result != 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def packdw(dw)
|
def packdw(dw)
|
||||||
[dw].pack('V')
|
[dw].pack('V')
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpackdw(dw)
|
def unpackdw(dw)
|
||||||
dw += [0].pack('V')
|
dw += [0].pack('V')
|
||||||
dw.unpack('V')[0]
|
dw.unpack('V')[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def packqw(qw)
|
def packqw(qw)
|
||||||
[ qw & 0xFFFFFFFF, qw >> 32 ].pack('VV')
|
[ qw & 0xFFFFFFFF, qw >> 32 ].pack('VV')
|
||||||
end
|
end
|
||||||
|
|
||||||
def unpackqw(qw)
|
def unpackqw(qw)
|
||||||
qw = qw.unpack('VV')
|
qw = qw.unpack('VV')
|
||||||
(qw[1] << 32) | qw[0]
|
(qw[1] << 32) | qw[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
def OpenKey(hkey, name, opt, desired)
|
def OpenKey(hkey, name, opt, desired)
|
||||||
result = packdw(0)
|
result = packdw(0)
|
||||||
check RegOpenKeyExA.call(hkey, name, opt, desired, result)
|
check RegOpenKeyExA.call(hkey, name, opt, desired, result)
|
||||||
unpackdw(result)
|
unpackdw(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
def CreateKey(hkey, name, opt, desired)
|
def CreateKey(hkey, name, opt, desired)
|
||||||
result = packdw(0)
|
result = packdw(0)
|
||||||
disp = packdw(0)
|
disp = packdw(0)
|
||||||
|
@ -428,14 +428,14 @@ module Win32
|
||||||
0, result, disp)
|
0, result, disp)
|
||||||
[ unpackdw(result), unpackdw(disp) ]
|
[ unpackdw(result), unpackdw(disp) ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def EnumValue(hkey, index)
|
def EnumValue(hkey, index)
|
||||||
name = ' ' * Constants::MAX_KEY_LENGTH
|
name = ' ' * Constants::MAX_KEY_LENGTH
|
||||||
size = packdw(Constants::MAX_KEY_LENGTH)
|
size = packdw(Constants::MAX_KEY_LENGTH)
|
||||||
check RegEnumValueA.call(hkey, index, name, size, 0, 0, 0, 0)
|
check RegEnumValueA.call(hkey, index, name, size, 0, 0, 0, 0)
|
||||||
name[0, unpackdw(size)]
|
name[0, unpackdw(size)]
|
||||||
end
|
end
|
||||||
|
|
||||||
def EnumKey(hkey, index)
|
def EnumKey(hkey, index)
|
||||||
name = ' ' * Constants::MAX_KEY_LENGTH
|
name = ' ' * Constants::MAX_KEY_LENGTH
|
||||||
size = packdw(Constants::MAX_KEY_LENGTH)
|
size = packdw(Constants::MAX_KEY_LENGTH)
|
||||||
|
@ -443,7 +443,7 @@ module Win32
|
||||||
check RegEnumKeyExA.call(hkey, index, name, size, 0, 0, 0, wtime)
|
check RegEnumKeyExA.call(hkey, index, name, size, 0, 0, 0, wtime)
|
||||||
[ name[0, unpackdw(size)], unpackqw(wtime) ]
|
[ name[0, unpackdw(size)], unpackqw(wtime) ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def QueryValue(hkey, name)
|
def QueryValue(hkey, name)
|
||||||
type = packdw(0)
|
type = packdw(0)
|
||||||
size = packdw(0)
|
size = packdw(0)
|
||||||
|
@ -452,27 +452,27 @@ module Win32
|
||||||
check RegQueryValueExA.call(hkey, name, 0, type, data, size)
|
check RegQueryValueExA.call(hkey, name, 0, type, data, size)
|
||||||
[ unpackdw(type), data[0, unpackdw(size)] ]
|
[ unpackdw(type), data[0, unpackdw(size)] ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def SetValue(hkey, name, type, data, size)
|
def SetValue(hkey, name, type, data, size)
|
||||||
check RegSetValueExA.call(hkey, name, 0, type, data, size)
|
check RegSetValueExA.call(hkey, name, 0, type, data, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def DeleteValue(hkey, name)
|
def DeleteValue(hkey, name)
|
||||||
check RegDeleteValue.call(hkey, name)
|
check RegDeleteValue.call(hkey, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def DeleteKey(hkey, name)
|
def DeleteKey(hkey, name)
|
||||||
check RegDeleteKey.call(hkey, name)
|
check RegDeleteKey.call(hkey, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def FlushKey(hkey)
|
def FlushKey(hkey)
|
||||||
check RegFlushKey.call(hkey)
|
check RegFlushKey.call(hkey)
|
||||||
end
|
end
|
||||||
|
|
||||||
def CloseKey(hkey)
|
def CloseKey(hkey)
|
||||||
check RegCloseKey.call(hkey)
|
check RegCloseKey.call(hkey)
|
||||||
end
|
end
|
||||||
|
|
||||||
def QueryInfoKey(hkey)
|
def QueryInfoKey(hkey)
|
||||||
subkeys = packdw(0)
|
subkeys = packdw(0)
|
||||||
maxsubkeylen = packdw(0)
|
maxsubkeylen = packdw(0)
|
||||||
|
@ -488,14 +488,14 @@ module Win32
|
||||||
unpackdw(secdescs), unpackqw(wtime) ]
|
unpackdw(secdescs), unpackqw(wtime) ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# utility functions
|
# utility functions
|
||||||
#
|
#
|
||||||
def self.expand_environ(str)
|
def self.expand_environ(str)
|
||||||
str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
|
str.gsub(/%([^%]+)%/) { ENV[$1] || ENV[$1.upcase] || $& }
|
||||||
end
|
end
|
||||||
|
|
||||||
@@type2name = { }
|
@@type2name = { }
|
||||||
%w[
|
%w[
|
||||||
REG_NONE REG_SZ REG_EXPAND_SZ REG_BINARY REG_DWORD
|
REG_NONE REG_SZ REG_EXPAND_SZ REG_BINARY REG_DWORD
|
||||||
|
@ -505,24 +505,24 @@ module Win32
|
||||||
].each do |type|
|
].each do |type|
|
||||||
@@type2name[Constants.const_get(type)] = type
|
@@type2name[Constants.const_get(type)] = type
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.type2name(type)
|
def self.type2name(type)
|
||||||
@@type2name[type] || type.to_s
|
@@type2name[type] || type.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.wtime2time(wtime)
|
def self.wtime2time(wtime)
|
||||||
Time.at((wtime - 116444736000000000) / 10000000)
|
Time.at((wtime - 116444736000000000) / 10000000)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.time2wtime(time)
|
def self.time2wtime(time)
|
||||||
time.to_i * 10000000 + 116444736000000000
|
time.to_i * 10000000 + 116444736000000000
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# constructors
|
# constructors
|
||||||
#
|
#
|
||||||
private_class_method :new
|
private_class_method :new
|
||||||
|
|
||||||
def self.open(hkey, subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED)
|
def self.open(hkey, subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED)
|
||||||
subkey = subkey.chomp('\\')
|
subkey = subkey.chomp('\\')
|
||||||
newkey = API.OpenKey(hkey.hkey, subkey, opt, desired)
|
newkey = API.OpenKey(hkey.hkey, subkey, opt, desired)
|
||||||
|
@ -537,7 +537,7 @@ module Win32
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.create(hkey, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED)
|
def self.create(hkey, subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED)
|
||||||
newkey, disp = API.CreateKey(hkey.hkey, subkey, opt, desired)
|
newkey, disp = API.CreateKey(hkey.hkey, subkey, opt, desired)
|
||||||
obj = new(newkey, hkey, subkey, disp)
|
obj = new(newkey, hkey, subkey, disp)
|
||||||
|
@ -551,12 +551,12 @@ module Win32
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# finalizer
|
# finalizer
|
||||||
#
|
#
|
||||||
@@final = proc { |hkey| proc { API.CloseKey(hkey[0]) if hkey[0] } }
|
@@final = proc { |hkey| proc { API.CloseKey(hkey[0]) if hkey[0] } }
|
||||||
|
|
||||||
#
|
#
|
||||||
# initialize
|
# initialize
|
||||||
#
|
#
|
||||||
|
@ -569,18 +569,18 @@ module Win32
|
||||||
ObjectSpace.define_finalizer self, @@final.call(@hkeyfinal)
|
ObjectSpace.define_finalizer self, @@final.call(@hkeyfinal)
|
||||||
end
|
end
|
||||||
attr_reader :hkey, :parent, :keyname, :disposition
|
attr_reader :hkey, :parent, :keyname, :disposition
|
||||||
|
|
||||||
#
|
#
|
||||||
# attributes
|
# attributes
|
||||||
#
|
#
|
||||||
def created?
|
def created?
|
||||||
@disposition == REG_CREATED_NEW_KEY
|
@disposition == REG_CREATED_NEW_KEY
|
||||||
end
|
end
|
||||||
|
|
||||||
def open?
|
def open?
|
||||||
!@hkey.nil?
|
!@hkey.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
parent = self
|
parent = self
|
||||||
name = @keyname
|
name = @keyname
|
||||||
|
@ -589,35 +589,35 @@ module Win32
|
||||||
end
|
end
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
"\#<Win32::Registry key=#{name.inspect}>"
|
"\#<Win32::Registry key=#{name.inspect}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# marshalling
|
# marshalling
|
||||||
#
|
#
|
||||||
def _dump(depth)
|
def _dump(depth)
|
||||||
raise TypeError, "can't dump Win32::Registry"
|
raise TypeError, "can't dump Win32::Registry"
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# open/close
|
# open/close
|
||||||
#
|
#
|
||||||
def open(subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED, &blk)
|
def open(subkey, desired = KEY_READ, opt = REG_OPTION_RESERVED, &blk)
|
||||||
self.class.open(self, subkey, desired, opt, &blk)
|
self.class.open(self, subkey, desired, opt, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED, &blk)
|
def create(subkey, desired = KEY_ALL_ACCESS, opt = REG_OPTION_RESERVED, &blk)
|
||||||
self.class.create(self, subkey, desired, opt, &blk)
|
self.class.create(self, subkey, desired, opt, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
API.CloseKey(@hkey)
|
API.CloseKey(@hkey)
|
||||||
@hkey = @parent = @keyname = nil
|
@hkey = @parent = @keyname = nil
|
||||||
@hkeyfinal[0] = nil
|
@hkeyfinal[0] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# iterator
|
# iterator
|
||||||
#
|
#
|
||||||
|
@ -640,7 +640,7 @@ module Win32
|
||||||
index
|
index
|
||||||
end
|
end
|
||||||
alias each each_value
|
alias each each_value
|
||||||
|
|
||||||
def each_key
|
def each_key
|
||||||
index = 0
|
index = 0
|
||||||
while true
|
while true
|
||||||
|
@ -654,13 +654,13 @@ module Win32
|
||||||
end
|
end
|
||||||
index
|
index
|
||||||
end
|
end
|
||||||
|
|
||||||
def keys
|
def keys
|
||||||
keys_ary = []
|
keys_ary = []
|
||||||
each_key { |key,| keys_ary << key }
|
each_key { |key,| keys_ary << key }
|
||||||
keys_ary
|
keys_ary
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# reader
|
# reader
|
||||||
#
|
#
|
||||||
|
@ -686,7 +686,7 @@ module Win32
|
||||||
raise TypeError, "Type #{type} is not supported."
|
raise TypeError, "Type #{type} is not supported."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](name, *rtype)
|
def [](name, *rtype)
|
||||||
type, data = read(name, *rtype)
|
type, data = read(name, *rtype)
|
||||||
case type
|
case type
|
||||||
|
@ -698,11 +698,11 @@ module Win32
|
||||||
raise TypeError, "Type #{type} is not supported."
|
raise TypeError, "Type #{type} is not supported."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_s(name)
|
def read_s(name)
|
||||||
read(name, REG_SZ)[1]
|
read(name, REG_SZ)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_s_expand(name)
|
def read_s_expand(name)
|
||||||
type, data = read(name, REG_SZ, REG_EXPAND_SZ)
|
type, data = read(name, REG_SZ, REG_EXPAND_SZ)
|
||||||
if type == REG_EXPAND_SZ
|
if type == REG_EXPAND_SZ
|
||||||
|
@ -711,15 +711,15 @@ module Win32
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_i(name)
|
def read_i(name)
|
||||||
read(name, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_QWORD)[1]
|
read(name, REG_DWORD, REG_DWORD_BIG_ENDIAN, REG_QWORD)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_bin(name)
|
def read_bin(name)
|
||||||
read(name, REG_BINARY)[1]
|
read(name, REG_BINARY)[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# writer
|
# writer
|
||||||
#
|
#
|
||||||
|
@ -742,7 +742,7 @@ module Win32
|
||||||
end
|
end
|
||||||
API.SetValue(@hkey, name, type, data, data.length)
|
API.SetValue(@hkey, name, type, data, data.length)
|
||||||
end
|
end
|
||||||
|
|
||||||
def []=(name, rtype, value = nil)
|
def []=(name, rtype, value = nil)
|
||||||
if value
|
if value
|
||||||
write name, rtype, value
|
write name, rtype, value
|
||||||
|
@ -760,19 +760,19 @@ module Win32
|
||||||
end
|
end
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_s(name, value)
|
def write_s(name, value)
|
||||||
write name, REG_SZ, value.to_s
|
write name, REG_SZ, value.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_i(name, value)
|
def write_i(name, value)
|
||||||
write name, REG_DWORD, value.to_i
|
write name, REG_DWORD, value.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def write_bin(name, value)
|
def write_bin(name, value)
|
||||||
write name, REG_BINARY, value.to_s
|
write name, REG_BINARY, value.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# delete
|
# delete
|
||||||
#
|
#
|
||||||
|
@ -780,7 +780,7 @@ module Win32
|
||||||
API.DeleteValue(@hkey, name)
|
API.DeleteValue(@hkey, name)
|
||||||
end
|
end
|
||||||
alias delete delete_value
|
alias delete delete_value
|
||||||
|
|
||||||
def delete_key(name, recursive = false)
|
def delete_key(name, recursive = false)
|
||||||
if recursive
|
if recursive
|
||||||
open(name, KEY_ALL_ACCESS) do |reg|
|
open(name, KEY_ALL_ACCESS) do |reg|
|
||||||
|
@ -802,14 +802,14 @@ module Win32
|
||||||
raise Error.new(5) ## ERROR_ACCESS_DENIED
|
raise Error.new(5) ## ERROR_ACCESS_DENIED
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# flush
|
# flush
|
||||||
#
|
#
|
||||||
def flush
|
def flush
|
||||||
API.FlushKey @hkey
|
API.FlushKey @hkey
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# key information
|
# key information
|
||||||
#
|
#
|
||||||
|
|
|
@ -8,13 +8,13 @@ require 'win32/registry'
|
||||||
module Win32
|
module Win32
|
||||||
module Resolv
|
module Resolv
|
||||||
API = Registry::API
|
API = Registry::API
|
||||||
|
|
||||||
def self.get_hosts_path
|
def self.get_hosts_path
|
||||||
path = get_hosts_dir
|
path = get_hosts_dir
|
||||||
path = File.expand_path('hosts', path)
|
path = File.expand_path('hosts', path)
|
||||||
File.exist?(path) ? path : nil
|
File.exist?(path) ? path : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_resolv_info
|
def self.get_resolv_info
|
||||||
search, nameserver = get_info
|
search, nameserver = get_info
|
||||||
if search.empty?
|
if search.empty?
|
||||||
|
@ -42,7 +42,7 @@ if info.unpack('V5')[4] == 2 # VER_PLATFORM_WIN32_NT
|
||||||
#====================================================================
|
#====================================================================
|
||||||
module_eval <<-'__EOS__', __FILE__, __LINE__+1
|
module_eval <<-'__EOS__', __FILE__, __LINE__+1
|
||||||
TCPIP_NT = 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'
|
TCPIP_NT = 'SYSTEM\CurrentControlSet\Services\Tcpip\Parameters'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
private
|
private
|
||||||
def get_hosts_dir
|
def get_hosts_dir
|
||||||
|
@ -50,7 +50,7 @@ if info.unpack('V5')[4] == 2 # VER_PLATFORM_WIN32_NT
|
||||||
reg.read_s_expand('DataBasePath')
|
reg.read_s_expand('DataBasePath')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_info
|
def get_info
|
||||||
search = nil
|
search = nil
|
||||||
nameserver = []
|
nameserver = []
|
||||||
|
@ -60,7 +60,7 @@ if info.unpack('V5')[4] == 2 # VER_PLATFORM_WIN32_NT
|
||||||
search = slist.split(/,\s*/) unless slist.empty?
|
search = slist.split(/,\s*/) unless slist.empty?
|
||||||
rescue Registry::Error
|
rescue Registry::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
if add_search = search.nil?
|
if add_search = search.nil?
|
||||||
search = []
|
search = []
|
||||||
begin
|
begin
|
||||||
|
@ -76,7 +76,7 @@ if info.unpack('V5')[4] == 2 # VER_PLATFORM_WIN32_NT
|
||||||
rescue Registry::Error
|
rescue Registry::Error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
reg.open('Interfaces') do |reg|
|
reg.open('Interfaces') do |reg|
|
||||||
reg.each_key do |iface,|
|
reg.each_key do |iface,|
|
||||||
reg.open(iface) do |regif|
|
reg.open(iface) do |regif|
|
||||||
|
@ -90,7 +90,7 @@ if info.unpack('V5')[4] == 2 # VER_PLATFORM_WIN32_NT
|
||||||
end
|
end
|
||||||
rescue Registry::Error
|
rescue Registry::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
if add_search
|
if add_search
|
||||||
begin
|
begin
|
||||||
[ 'Domain', 'DhcpDomain' ].each do |key|
|
[ 'Domain', 'DhcpDomain' ].each do |key|
|
||||||
|
@ -120,16 +120,16 @@ else
|
||||||
TCPIP_9X = 'SYSTEM\CurrentControlSet\Services\VxD\MSTCP'
|
TCPIP_9X = 'SYSTEM\CurrentControlSet\Services\VxD\MSTCP'
|
||||||
DHCP_9X = 'SYSTEM\CurrentControlSet\Services\VxD\DHCP'
|
DHCP_9X = 'SYSTEM\CurrentControlSet\Services\VxD\DHCP'
|
||||||
WINDOWS = 'Software\Microsoft\Windows\CurrentVersion'
|
WINDOWS = 'Software\Microsoft\Windows\CurrentVersion'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
# private
|
# private
|
||||||
|
|
||||||
def get_hosts_dir
|
def get_hosts_dir
|
||||||
Registry::HKEY_LOCAL_MACHINE.open(WINDOWS) do |reg|
|
Registry::HKEY_LOCAL_MACHINE.open(WINDOWS) do |reg|
|
||||||
reg.read_s_expand('SystemRoot')
|
reg.read_s_expand('SystemRoot')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_info
|
def get_info
|
||||||
search = []
|
search = []
|
||||||
nameserver = []
|
nameserver = []
|
||||||
|
@ -146,13 +146,13 @@ else
|
||||||
end
|
end
|
||||||
rescue Registry::Error
|
rescue Registry::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
dhcpinfo = get_dhcpinfo
|
dhcpinfo = get_dhcpinfo
|
||||||
search.concat(dhcpinfo[0])
|
search.concat(dhcpinfo[0])
|
||||||
nameserver.concat(dhcpinfo[1])
|
nameserver.concat(dhcpinfo[1])
|
||||||
[ search, nameserver ]
|
[ search, nameserver ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_dhcpinfo
|
def get_dhcpinfo
|
||||||
macaddrs = {}
|
macaddrs = {}
|
||||||
ipaddrs = {}
|
ipaddrs = {}
|
||||||
|
@ -161,7 +161,7 @@ else
|
||||||
ipaddr.each { |ipaddr| ipaddrs[ipaddr] = 1 }
|
ipaddr.each { |ipaddr| ipaddrs[ipaddr] = 1 }
|
||||||
end
|
end
|
||||||
iflist = [ macaddrs, ipaddrs ]
|
iflist = [ macaddrs, ipaddrs ]
|
||||||
|
|
||||||
search = []
|
search = []
|
||||||
nameserver = []
|
nameserver = []
|
||||||
version = -1
|
version = -1
|
||||||
|
@ -170,7 +170,7 @@ else
|
||||||
version = API.unpackdw(reg.read_bin("Version"))
|
version = API.unpackdw(reg.read_bin("Version"))
|
||||||
rescue Registry::Error
|
rescue Registry::Error
|
||||||
end
|
end
|
||||||
|
|
||||||
reg.each_key do |key,|
|
reg.each_key do |key,|
|
||||||
catch(:not_used) do
|
catch(:not_used) do
|
||||||
reg.open(key) do |regdi|
|
reg.open(key) do |regdi|
|
||||||
|
@ -183,7 +183,7 @@ else
|
||||||
end
|
end
|
||||||
[ search, nameserver ]
|
[ search, nameserver ]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_dhcpinfo_95(reg)
|
def get_dhcpinfo_95(reg)
|
||||||
dhcp = reg.read_bin("DhcpInfo")
|
dhcp = reg.read_bin("DhcpInfo")
|
||||||
[
|
[
|
||||||
|
@ -194,7 +194,7 @@ else
|
||||||
reg.read_bin("OptionInfo"),
|
reg.read_bin("OptionInfo"),
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_dhcpinfo_98(reg)
|
def get_dhcpinfo_98(reg)
|
||||||
[
|
[
|
||||||
API.unpackdw(reg.read_bin("DhcpIPAddress")),
|
API.unpackdw(reg.read_bin("DhcpIPAddress")),
|
||||||
|
@ -204,7 +204,7 @@ else
|
||||||
reg.read_bin("OptionInfo"),
|
reg.read_bin("OptionInfo"),
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_dhcpinfo_key(version, reg, iflist)
|
def get_dhcpinfo_key(version, reg, iflist)
|
||||||
info = case version
|
info = case version
|
||||||
when 1
|
when 1
|
||||||
|
@ -225,7 +225,7 @@ else
|
||||||
macaddr and macaddr.size == 6 and
|
macaddr and macaddr.size == 6 and
|
||||||
hwtype == 1 and
|
hwtype == 1 and
|
||||||
iflist[0][macaddr] and iflist[1][ipaddr]
|
iflist[0][macaddr] and iflist[1][ipaddr]
|
||||||
|
|
||||||
size = opt.size
|
size = opt.size
|
||||||
idx = 0
|
idx = 0
|
||||||
while idx <= size
|
while idx <= size
|
||||||
|
@ -249,11 +249,11 @@ else
|
||||||
throw :not_used
|
throw :not_used
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module WsControl
|
module WsControl
|
||||||
WsControl = Win32API.new('wsock32.dll', 'WsControl', 'LLPPPP', 'L')
|
WsControl = Win32API.new('wsock32.dll', 'WsControl', 'LLPPPP', 'L')
|
||||||
WSAGetLastError = Win32API.new('wsock32.dll', 'WSAGetLastError', 'V', 'L')
|
WSAGetLastError = Win32API.new('wsock32.dll', 'WSAGetLastError', 'V', 'L')
|
||||||
|
|
||||||
MAX_TDI_ENTITIES = 512
|
MAX_TDI_ENTITIES = 512
|
||||||
IPPROTO_TCP = 6
|
IPPROTO_TCP = 6
|
||||||
WSCTL_TCP_QUERY_INFORMATION = 0
|
WSCTL_TCP_QUERY_INFORMATION = 0
|
||||||
|
@ -269,7 +269,7 @@ else
|
||||||
IF_MIB = 0x202
|
IF_MIB = 0x202
|
||||||
IF_MIB_STATS_ID = 1
|
IF_MIB_STATS_ID = 1
|
||||||
IP_MIB_ADDRTABLE_ENTRY_ID = 0x102
|
IP_MIB_ADDRTABLE_ENTRY_ID = 0x102
|
||||||
|
|
||||||
def self.wsctl(tei_entity, tei_instance,
|
def self.wsctl(tei_entity, tei_instance,
|
||||||
toi_class, toi_type, toi_id,
|
toi_class, toi_type, toi_id,
|
||||||
buffsize)
|
buffsize)
|
||||||
|
@ -295,7 +295,7 @@ else
|
||||||
[ buff, API.unpackdw(buffsize) ]
|
[ buff, API.unpackdw(buffsize) ]
|
||||||
end
|
end
|
||||||
private_class_method :wsctl
|
private_class_method :wsctl
|
||||||
|
|
||||||
def self.get_iflist
|
def self.get_iflist
|
||||||
# Get TDI Entity List
|
# Get TDI Entity List
|
||||||
entities, size =
|
entities, size =
|
||||||
|
@ -332,7 +332,7 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get IP Addresses
|
# Get IP Addresses
|
||||||
entities.each do |entity, instance|
|
entities.each do |entity, instance|
|
||||||
if entity == CL_NL_ENTITY
|
if entity == CL_NL_ENTITY
|
||||||
|
|
|
@ -17,7 +17,7 @@ module LUSolve
|
||||||
end
|
end
|
||||||
if nrmrow>zero then
|
if nrmrow>zero then
|
||||||
scales <<= one.div(nrmrow,prec)
|
scales <<= one.div(nrmrow,prec)
|
||||||
else
|
else
|
||||||
raise "Singular matrix"
|
raise "Singular matrix"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,10 +30,10 @@
|
||||||
#
|
#
|
||||||
module BigMath
|
module BigMath
|
||||||
|
|
||||||
# Computes the square root of x to the specified number of digits of
|
# Computes the square root of x to the specified number of digits of
|
||||||
# precision.
|
# precision.
|
||||||
#
|
#
|
||||||
# BigDecimal.new('2').sqrt(16).to_s
|
# BigDecimal.new('2').sqrt(16).to_s
|
||||||
# -> "0.14142135623730950488016887242096975E1"
|
# -> "0.14142135623730950488016887242096975E1"
|
||||||
#
|
#
|
||||||
def sqrt(x,prec)
|
def sqrt(x,prec)
|
||||||
|
@ -120,7 +120,7 @@ module BigMath
|
||||||
y
|
y
|
||||||
end
|
end
|
||||||
|
|
||||||
# Computes the value of e (the base of natural logarithms) raised to the
|
# Computes the value of e (the base of natural logarithms) raised to the
|
||||||
# power of x, to the specified number of digits of precision.
|
# power of x, to the specified number of digits of precision.
|
||||||
#
|
#
|
||||||
# If x is infinite or NaN, returns NaN.
|
# If x is infinite or NaN, returns NaN.
|
||||||
|
@ -148,7 +148,7 @@ module BigMath
|
||||||
y
|
y
|
||||||
end
|
end
|
||||||
|
|
||||||
# Computes the natural logarithm of x to the specified number of digits
|
# Computes the natural logarithm of x to the specified number of digits
|
||||||
# of precision.
|
# of precision.
|
||||||
#
|
#
|
||||||
# Returns x if x is infinite or NaN.
|
# Returns x if x is infinite or NaN.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# newton.rb
|
# newton.rb
|
||||||
#
|
#
|
||||||
# Solves the nonlinear algebraic equation system f = 0 by Newton's method.
|
# Solves the nonlinear algebraic equation system f = 0 by Newton's method.
|
||||||
# This program is not dependent on BigDecimal.
|
# This program is not dependent on BigDecimal.
|
||||||
|
@ -28,7 +28,7 @@ require "bigdecimal/jacobian"
|
||||||
module Newton
|
module Newton
|
||||||
include LUSolve
|
include LUSolve
|
||||||
include Jacobian
|
include Jacobian
|
||||||
|
|
||||||
def norm(fv,zero=0.0)
|
def norm(fv,zero=0.0)
|
||||||
s = zero
|
s = zero
|
||||||
n = fv.size
|
n = fv.size
|
||||||
|
|
|
@ -41,7 +41,7 @@ class BigDecimal < Numeric
|
||||||
end
|
end
|
||||||
|
|
||||||
# Converts a BigDecimal to a Rational.
|
# Converts a BigDecimal to a Rational.
|
||||||
def to_r
|
def to_r
|
||||||
sign,digits,base,power = self.split
|
sign,digits,base,power = self.split
|
||||||
numerator = sign*digits.to_i
|
numerator = sign*digits.to_i
|
||||||
denomi_power = power - digits.size # base is always 10
|
denomi_power = power - digits.size # base is always 10
|
||||||
|
|
|
@ -67,10 +67,10 @@ while TRUE
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
#wscrl(i)
|
#wscrl(i)
|
||||||
|
|
||||||
when "p" #when KEY_UP
|
when "p" #when KEY_UP
|
||||||
i = 0
|
i = 0
|
||||||
while i < n
|
while i < n
|
||||||
|
@ -79,8 +79,8 @@ while TRUE
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
#wscrl(-i)
|
#wscrl(-i)
|
||||||
|
|
||||||
when "q"
|
when "q"
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Digest
|
||||||
|
|
||||||
class ::Digest::Class
|
class ::Digest::Class
|
||||||
# creates a digest object and reads a given file, _name_.
|
# creates a digest object and reads a given file, _name_.
|
||||||
#
|
#
|
||||||
# p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
|
# p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
|
||||||
# # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
|
# # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
|
||||||
def self.file(name)
|
def self.file(name)
|
||||||
|
|
|
@ -149,7 +149,7 @@ module DL
|
||||||
mname[0,1] = mname[0,1].downcase
|
mname[0,1] = mname[0,1].downcase
|
||||||
end
|
end
|
||||||
@SYM[mname] = [sym,rdec,enc,dec]
|
@SYM[mname] = [sym,rdec,enc,dec]
|
||||||
|
|
||||||
module_eval [
|
module_eval [
|
||||||
"def #{mname}(*args)",
|
"def #{mname}(*args)",
|
||||||
" sym,rdec,enc,dec = @SYM['#{mname}']",
|
" sym,rdec,enc,dec = @SYM['#{mname}']",
|
||||||
|
|
|
@ -113,7 +113,7 @@ module DL
|
||||||
}
|
}
|
||||||
@size = DL.sizeof(@tys)
|
@size = DL.sizeof(@tys)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_elem(elem)
|
def parse_elem(elem)
|
||||||
elem.strip!
|
elem.strip!
|
||||||
case elem
|
case elem
|
||||||
|
@ -135,7 +135,7 @@ module DL
|
||||||
return [name,ty,num,enc,dec]
|
return [name,ty,num,enc,dec]
|
||||||
end
|
end
|
||||||
end # class Struct
|
end # class Struct
|
||||||
|
|
||||||
class Union < Struct
|
class Union < Struct
|
||||||
def new
|
def new
|
||||||
ptr = DL::malloc(@size)
|
ptr = DL::malloc(@size)
|
||||||
|
|
|
@ -9,7 +9,7 @@ module DL
|
||||||
# ["alias name",
|
# ["alias name",
|
||||||
# "type name", encoding_method, decoding_method, for function prototypes
|
# "type name", encoding_method, decoding_method, for function prototypes
|
||||||
# "type name", encoding_method, decoding_method] for structures (not implemented)
|
# "type name", encoding_method, decoding_method] for structures (not implemented)
|
||||||
|
|
||||||
# for Windows
|
# for Windows
|
||||||
["DWORD", "unsigned long", nil, nil,
|
["DWORD", "unsigned long", nil, nil,
|
||||||
"unsigned long", nil, nil],
|
"unsigned long", nil, nil],
|
||||||
|
@ -49,7 +49,7 @@ module DL
|
||||||
"unsigned int", nil, nil],
|
"unsigned int", nil, nil],
|
||||||
["HWND", "unsigned int", nil, nil,
|
["HWND", "unsigned int", nil, nil,
|
||||||
"unsigned int", nil, nil],
|
"unsigned int", nil, nil],
|
||||||
|
|
||||||
# Others
|
# Others
|
||||||
["uint", "unsigned int", nil, nil,
|
["uint", "unsigned int", nil, nil,
|
||||||
"unsigned int", nil, nil],
|
"unsigned int", nil, nil],
|
||||||
|
|
|
@ -15,7 +15,7 @@ LIBNAME = ARGV[0] || "libsample.so"
|
||||||
class Person
|
class Person
|
||||||
module Core
|
module Core
|
||||||
extend DL::Importable
|
extend DL::Importable
|
||||||
|
|
||||||
dlload LIBNAME
|
dlload LIBNAME
|
||||||
|
|
||||||
# mangled symbol names
|
# mangled symbol names
|
||||||
|
|
|
@ -43,7 +43,7 @@ types = [
|
||||||
"unknown",
|
"unknown",
|
||||||
"no root dir",
|
"no root dir",
|
||||||
"Removable",
|
"Removable",
|
||||||
"Fixed",
|
"Fixed",
|
||||||
"Remote",
|
"Remote",
|
||||||
"CDROM",
|
"CDROM",
|
||||||
"RAM",
|
"RAM",
|
||||||
|
|
|
@ -18,9 +18,9 @@ module Kconv
|
||||||
#
|
#
|
||||||
# Public Constants
|
# Public Constants
|
||||||
#
|
#
|
||||||
|
|
||||||
#Constant of Encoding
|
#Constant of Encoding
|
||||||
|
|
||||||
# Auto-Detect
|
# Auto-Detect
|
||||||
AUTO = NKF::AUTO
|
AUTO = NKF::AUTO
|
||||||
# ISO-2022-JP
|
# ISO-2022-JP
|
||||||
|
@ -47,16 +47,16 @@ module Kconv
|
||||||
#
|
#
|
||||||
# Private Constants
|
# Private Constants
|
||||||
#
|
#
|
||||||
|
|
||||||
# Revision of kconv.rb
|
# Revision of kconv.rb
|
||||||
REVISION = %q$Revision$
|
REVISION = %q$Revision$
|
||||||
|
|
||||||
#Regexp of Encoding
|
#Regexp of Encoding
|
||||||
|
|
||||||
# Regexp of Shift_JIS string (private constant)
|
# Regexp of Shift_JIS string (private constant)
|
||||||
RegexpShiftjis = /\A(?:
|
RegexpShiftjis = /\A(?:
|
||||||
[\x00-\x7f\xa1-\xdf] |
|
[\x00-\x7f\xa1-\xdf] |
|
||||||
[\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc]
|
[\x81-\x9f\xe0-\xfc][\x40-\x7e\x80-\xfc]
|
||||||
)*\z/nx
|
)*\z/nx
|
||||||
|
|
||||||
# Regexp of EUC-JP string (private constant)
|
# Regexp of EUC-JP string (private constant)
|
||||||
|
@ -81,7 +81,7 @@ module Kconv
|
||||||
#
|
#
|
||||||
# Public Methods
|
# Public Methods
|
||||||
#
|
#
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# Kconv.kconv(str, out_code, in_code = Kconv::AUTO)
|
# Kconv.kconv(str, out_code, in_code = Kconv::AUTO)
|
||||||
#
|
#
|
||||||
|
@ -277,11 +277,11 @@ class String
|
||||||
def kconv(out_code, in_code=Kconv::AUTO)
|
def kconv(out_code, in_code=Kconv::AUTO)
|
||||||
Kconv::kconv(self, out_code, in_code)
|
Kconv::kconv(self, out_code, in_code)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# to Encoding
|
# to Encoding
|
||||||
#
|
#
|
||||||
|
|
||||||
# call-seq:
|
# call-seq:
|
||||||
# String#tojis -> string
|
# String#tojis -> string
|
||||||
#
|
#
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
= Version
|
= Version
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
= Notes
|
= Notes
|
||||||
Tested on FreeBSD 5-CURRENT and 4-STABLE
|
Tested on FreeBSD 5-CURRENT and 4-STABLE
|
||||||
- ruby 1.6.8 (2003-01-17) [i386-freebsd5]
|
- ruby 1.6.8 (2003-01-17) [i386-freebsd5]
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
= Version
|
= Version
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
2001/11/06: Contiributed to Ruby/OpenSSL project.
|
2001/11/06: Contiributed to Ruby/OpenSSL project.
|
||||||
|
|
||||||
== class Net::Telnet
|
== class Net::Telnet
|
||||||
|
@ -145,7 +145,7 @@ module Net
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end # preprocess
|
end # preprocess
|
||||||
|
|
||||||
alias waitfor_org waitfor
|
alias waitfor_org waitfor
|
||||||
|
|
||||||
def waitfor(options)
|
def waitfor(options)
|
||||||
|
@ -181,7 +181,7 @@ module Net
|
||||||
begin
|
begin
|
||||||
c = @rest + @sock.sysread(1024 * 1024)
|
c = @rest + @sock.sysread(1024 * 1024)
|
||||||
@dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
|
@dumplog.log_dump('<', c) if @options.has_key?("Dump_log")
|
||||||
if @options["Telnetmode"]
|
if @options["Telnetmode"]
|
||||||
pos = 0
|
pos = 0
|
||||||
catch(:next){
|
catch(:next){
|
||||||
while true
|
while true
|
||||||
|
@ -213,11 +213,11 @@ module Net
|
||||||
end
|
end
|
||||||
@log.print(buf) if @options.has_key?("Output_log")
|
@log.print(buf) if @options.has_key?("Output_log")
|
||||||
line.concat(buf)
|
line.concat(buf)
|
||||||
yield buf if block_given?
|
yield buf if block_given?
|
||||||
rescue EOFError # End of file reached
|
rescue EOFError # End of file reached
|
||||||
if line == ''
|
if line == ''
|
||||||
line = nil
|
line = nil
|
||||||
yield nil if block_given?
|
yield nil if block_given?
|
||||||
end
|
end
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,9 +12,9 @@ require 'expect'
|
||||||
fnames = []
|
fnames = []
|
||||||
PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
|
PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
|
||||||
w_f.sync = true
|
w_f.sync = true
|
||||||
|
|
||||||
$expect_verbose = false
|
$expect_verbose = false
|
||||||
|
|
||||||
if !ENV['USER'].nil?
|
if !ENV['USER'].nil?
|
||||||
username = ENV['USER']
|
username = ENV['USER']
|
||||||
elsif !ENV['LOGNAME'].nil?
|
elsif !ENV['LOGNAME'].nil?
|
||||||
|
@ -22,14 +22,14 @@ PTY.spawn("ftp ftp.ruby-lang.org") do |r_f,w_f,pid|
|
||||||
else
|
else
|
||||||
username = 'guest'
|
username = 'guest'
|
||||||
end
|
end
|
||||||
|
|
||||||
r_f.expect(/^(Name).*: |(word):|> /) do
|
r_f.expect(/^(Name).*: |(word):|> /) do
|
||||||
w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
|
w_f.puts($1 ? "ftp" : $2 ? "#{username}@" : "cd pub/ruby")
|
||||||
end
|
end
|
||||||
r_f.expect("> ") do
|
r_f.expect("> ") do
|
||||||
w_f.print "dir\n"
|
w_f.print "dir\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
r_f.expect(/[^\-]> /) do |output|
|
r_f.expect(/[^\-]> /) do |output|
|
||||||
for x in output[0].split("\n")
|
for x in output[0].split("\n")
|
||||||
if x =~ /(ruby.*?\.tar\.gz)/ then
|
if x =~ /(ruby.*?\.tar\.gz)/ then
|
||||||
|
|
|
@ -18,7 +18,7 @@ PTY.spawn("/bin/csh") do |r_pty,w_pty,pid|
|
||||||
w_pty.flush
|
w_pty.flush
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
while true
|
while true
|
||||||
c = r_pty.sysread(512)
|
c = r_pty.sysread(512)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# by Keiju ISHITSUKA(SHL Japan Inc.)
|
# by Keiju ISHITSUKA(SHL Japan Inc.)
|
||||||
#
|
#
|
||||||
# Documentation by Kevin Jackson and Gavin Sinclair.
|
# Documentation by Kevin Jackson and Gavin Sinclair.
|
||||||
#
|
#
|
||||||
# Performance improvements by Kurt Stephens.
|
# Performance improvements by Kurt Stephens.
|
||||||
#
|
#
|
||||||
# When you <tt>require 'rational'</tt>, all interactions between numbers
|
# When you <tt>require 'rational'</tt>, all interactions between numbers
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
# 1.quo(2) # -> 0.5
|
# 1.quo(2) # -> 0.5
|
||||||
# require 'rational'
|
# require 'rational'
|
||||||
# 1.quo(2) # -> Rational(1,2)
|
# 1.quo(2) # -> Rational(1,2)
|
||||||
#
|
#
|
||||||
# See Rational for full documentation.
|
# See Rational for full documentation.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ require "rational.so"
|
||||||
|
|
||||||
#
|
#
|
||||||
# Creates a Rational number (i.e. a fraction). +a+ and +b+ should be Integers:
|
# Creates a Rational number (i.e. a fraction). +a+ and +b+ should be Integers:
|
||||||
#
|
#
|
||||||
# Rational(1,3) # -> 1/3
|
# Rational(1,3) # -> 1/3
|
||||||
#
|
#
|
||||||
# Note: trying to construct a Rational with floating point or real values
|
# Note: trying to construct a Rational with floating point or real values
|
||||||
|
@ -55,7 +55,7 @@ end
|
||||||
# Examples:
|
# Examples:
|
||||||
# Rational(5,6) # -> 5/6
|
# Rational(5,6) # -> 5/6
|
||||||
# Rational(5) # -> 5/1
|
# Rational(5) # -> 5/1
|
||||||
#
|
#
|
||||||
# Rational numbers are reduced to their lowest terms:
|
# Rational numbers are reduced to their lowest terms:
|
||||||
# Rational(6,10) # -> 3/5
|
# Rational(6,10) # -> 3/5
|
||||||
#
|
#
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TestSyslog < Test::Unit::TestCase
|
||||||
Syslog.close
|
Syslog.close
|
||||||
|
|
||||||
# given parameters
|
# given parameters
|
||||||
Syslog.open("foo", Syslog::LOG_NDELAY | Syslog::LOG_PERROR, Syslog::LOG_DAEMON)
|
Syslog.open("foo", Syslog::LOG_NDELAY | Syslog::LOG_PERROR, Syslog::LOG_DAEMON)
|
||||||
|
|
||||||
assert_equal('foo', Syslog.ident)
|
assert_equal('foo', Syslog.ident)
|
||||||
assert_equal(Syslog::LOG_NDELAY | Syslog::LOG_PERROR, Syslog.options)
|
assert_equal(Syslog::LOG_NDELAY | Syslog::LOG_PERROR, Syslog.options)
|
||||||
|
|
|
@ -20,7 +20,7 @@ end
|
||||||
def create_win32ole_makefile
|
def create_win32ole_makefile
|
||||||
if have_library("ole32") and
|
if have_library("ole32") and
|
||||||
have_library("oleaut32") and
|
have_library("oleaut32") and
|
||||||
have_library("uuid") and
|
have_library("uuid") and
|
||||||
have_library("user32") and
|
have_library("user32") and
|
||||||
have_library("kernel32") and
|
have_library("kernel32") and
|
||||||
have_library("advapi32") and
|
have_library("advapi32") and
|
||||||
|
|
|
@ -20,7 +20,7 @@ end
|
||||||
# Remark!!! CONSTANTS has not tested enoughly!!!
|
# Remark!!! CONSTANTS has not tested enoughly!!!
|
||||||
# CONSTANTS is alpha release.
|
# CONSTANTS is alpha release.
|
||||||
# If there are constants which first letter is not [a-zA-Z],
|
# If there are constants which first letter is not [a-zA-Z],
|
||||||
# like a '_Foo', then maybe you can access the value by
|
# like a '_Foo', then maybe you can access the value by
|
||||||
# using CONSTANTS['_Foo']
|
# using CONSTANTS['_Foo']
|
||||||
#------------------------------------------------------------
|
#------------------------------------------------------------
|
||||||
IE_CONST::CONSTANTS.each do |k, v|
|
IE_CONST::CONSTANTS.each do |k, v|
|
||||||
|
|
|
@ -26,7 +26,7 @@ ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
|
||||||
|
|
||||||
ev.on_event {|*args| default_handler(*args)}
|
ev.on_event {|*args| default_handler(*args)}
|
||||||
ev.on_event("NavigateComplete") {|url| navigate(url)}
|
ev.on_event("NavigateComplete") {|url| navigate(url)}
|
||||||
ev.on_event("Quit") {|*args| stop_msg_loop}
|
ev.on_event("Quit") {|*args| stop_msg_loop}
|
||||||
|
|
||||||
$LOOP = TRUE
|
$LOOP = TRUE
|
||||||
while ($LOOP)
|
while ($LOOP)
|
||||||
|
|
|
@ -7,7 +7,7 @@ require "win32ole"
|
||||||
def listup(items)
|
def listup(items)
|
||||||
# items.each do |i|
|
# items.each do |i|
|
||||||
for i in items
|
for i in items
|
||||||
puts i.name
|
puts i.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class WIN32COMGen
|
||||||
ts = ''
|
ts = ''
|
||||||
typedetails.each do |t|
|
typedetails.each do |t|
|
||||||
case t
|
case t
|
||||||
when 'CARRAY', 'VOID', 'UINT', 'RESULT', 'DECIMAL', 'I8', 'UI8'
|
when 'CARRAY', 'VOID', 'UINT', 'RESULT', 'DECIMAL', 'I8', 'UI8'
|
||||||
# raise "Sorry type\"" + t + "\" not supported"
|
# raise "Sorry type\"" + t + "\" not supported"
|
||||||
ts << "\"??? NOT SUPPORTED TYPE:`#{t}'\""
|
ts << "\"??? NOT SUPPORTED TYPE:`#{t}'\""
|
||||||
when 'USERDEFINED', 'Unknown Type 9'
|
when 'USERDEFINED', 'Unknown Type 9'
|
||||||
|
@ -81,7 +81,7 @@ class WIN32COMGen
|
||||||
generate_argtype(param.ole_type_detail)
|
generate_argtype(param.ole_type_detail)
|
||||||
}.join(", ")
|
}.join(", ")
|
||||||
if proptypes
|
if proptypes
|
||||||
types += ", " if types.size > 0
|
types += ", " if types.size > 0
|
||||||
types += generate_argtype(proptypes)
|
types += generate_argtype(proptypes)
|
||||||
end
|
end
|
||||||
types
|
types
|
||||||
|
@ -98,8 +98,8 @@ class WIN32COMGen
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_method_help(method, type = nil)
|
def generate_method_help(method, type = nil)
|
||||||
str = " # "
|
str = " # "
|
||||||
if type
|
if type
|
||||||
str += type
|
str += type
|
||||||
else
|
else
|
||||||
str += method.return_type
|
str += method.return_type
|
||||||
|
@ -124,7 +124,7 @@ class WIN32COMGen
|
||||||
def generate_method_args_help(method)
|
def generate_method_args_help(method)
|
||||||
args = []
|
args = []
|
||||||
method.params.each_with_index {|param, i|
|
method.params.each_with_index {|param, i|
|
||||||
h = " # #{param.ole_type} arg#{i} --- #{param.name}"
|
h = " # #{param.ole_type} arg#{i} --- #{param.name}"
|
||||||
inout = []
|
inout = []
|
||||||
inout.push "IN" if param.input?
|
inout.push "IN" if param.input?
|
||||||
inout.push "OUT" if param.output?
|
inout.push "OUT" if param.output?
|
||||||
|
@ -167,14 +167,14 @@ class WIN32COMGen
|
||||||
method.visible? &&
|
method.visible? &&
|
||||||
method.size_params > 0
|
method.size_params > 0
|
||||||
}.each do |method|
|
}.each do |method|
|
||||||
types = method.return_type_detail
|
types = method.return_type_detail
|
||||||
io.puts "\n"
|
io.puts "\n"
|
||||||
io.puts generate_method_help(method, types[0])
|
io.puts generate_method_help(method, types[0])
|
||||||
io.puts " def #{method.name}"
|
io.puts " def #{method.name}"
|
||||||
if klass.ole_type == "Class"
|
if klass.ole_type == "Class"
|
||||||
io.print " OLEProperty.new(@dispatch, #{method.dispid}, ["
|
io.print " OLEProperty.new(@dispatch, #{method.dispid}, ["
|
||||||
else
|
else
|
||||||
io.print " OLEProperty.new(self, #{method.dispid}, ["
|
io.print " OLEProperty.new(self, #{method.dispid}, ["
|
||||||
end
|
end
|
||||||
io.print generate_argtypes(method, nil)
|
io.print generate_argtypes(method, nil)
|
||||||
io.print "], ["
|
io.print "], ["
|
||||||
|
@ -321,8 +321,8 @@ STR
|
||||||
|
|
||||||
ole_classes(typelib).select{|klass|
|
ole_classes(typelib).select{|klass|
|
||||||
klass.visible? &&
|
klass.visible? &&
|
||||||
(klass.ole_type == "Class" ||
|
(klass.ole_type == "Class" ||
|
||||||
klass.ole_type == "Interface" ||
|
klass.ole_type == "Interface" ||
|
||||||
klass.ole_type == "Dispatch" ||
|
klass.ole_type == "Dispatch" ||
|
||||||
klass.ole_type == "Enum")
|
klass.ole_type == "Enum")
|
||||||
}.each do |klass|
|
}.each do |klass|
|
||||||
|
@ -330,7 +330,7 @@ STR
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
@ole.quit if @ole
|
@ole.quit if @ole
|
||||||
rescue
|
rescue
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#
|
#
|
||||||
# This file created by olegen.rb as following.
|
# This file created by olegen.rb as following.
|
||||||
# ruby olegen.rb 'Microsoft XML, version 2.0' > xml.rb
|
# ruby olegen.rb 'Microsoft XML, version 2.0' > xml.rb
|
||||||
#
|
#
|
||||||
require 'win32ole'
|
require 'win32ole'
|
||||||
require 'win32ole/property'
|
require 'win32ole/property'
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMImplementation
|
module IXMLDOMImplementation
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -343,7 +343,7 @@ module OLEtagDOMNodeType
|
||||||
NODE_NOTATION = 12
|
NODE_NOTATION = 12
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMNodeList
|
module IXMLDOMNodeList
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -380,7 +380,7 @@ module IXMLDOMNodeList
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMNamedNodeMap
|
module IXMLDOMNamedNodeMap
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -464,7 +464,7 @@ module IXMLDOMNamedNodeMap
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMDocument
|
module IXMLDOMDocument
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -1040,7 +1040,7 @@ module IXMLDOMDocument
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMDocumentType
|
module IXMLDOMDocumentType
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -1368,7 +1368,7 @@ module IXMLDOMDocumentType
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMElement
|
module IXMLDOMElement
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -1752,7 +1752,7 @@ module IXMLDOMElement
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMAttribute
|
module IXMLDOMAttribute
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -2080,7 +2080,7 @@ module IXMLDOMAttribute
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMDocumentFragment
|
module IXMLDOMDocumentFragment
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -2384,7 +2384,7 @@ module IXMLDOMDocumentFragment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMText
|
module IXMLDOMText
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -2771,7 +2771,7 @@ module IXMLDOMText
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMCharacterData
|
module IXMLDOMCharacterData
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -3149,7 +3149,7 @@ module IXMLDOMCharacterData
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMComment
|
module IXMLDOMComment
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -3527,7 +3527,7 @@ module IXMLDOMComment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMCDATASection
|
module IXMLDOMCDATASection
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -3914,7 +3914,7 @@ module IXMLDOMCDATASection
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMProcessingInstruction
|
module IXMLDOMProcessingInstruction
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -4242,7 +4242,7 @@ module IXMLDOMProcessingInstruction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMEntityReference
|
module IXMLDOMEntityReference
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -4608,7 +4608,7 @@ module IXMLDOMParseError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMNotation
|
module IXMLDOMNotation
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
@ -4928,7 +4928,7 @@ module IXMLDOMNotation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
module IXMLDOMEntity
|
module IXMLDOMEntity
|
||||||
include WIN32OLE::VARIANT
|
include WIN32OLE::VARIANT
|
||||||
attr_reader :lastargs
|
attr_reader :lastargs
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# You need RubyUnit and MS Excel and MSI to run this test script
|
# You need RubyUnit and MS Excel and MSI to run this test script
|
||||||
|
|
||||||
require 'rubyunit'
|
require 'rubyunit'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# You need RubyUnit and MS Excel and MSI to run this test script
|
# You need RubyUnit and MS Excel and MSI to run this test script
|
||||||
|
|
||||||
require 'rubyunit'
|
require 'rubyunit'
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class TestOLEPARAM < RUNIT::TestCase
|
||||||
f = methods.find {|m| m.name == 'SaveAs'}
|
f = methods.find {|m| m.name == 'SaveAs'}
|
||||||
assert(f.params[0].input?)
|
assert(f.params[0].input?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_output
|
def test_output
|
||||||
classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
|
classes = WIN32OLE_TYPE.ole_classes(MS_EXCEL_TYPELIB)
|
||||||
methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
|
methods = classes.find {|c| c.name == 'Worksheet'}.ole_methods
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# You need RubyUnit and MS Excel and MSI to run this test script
|
# You need RubyUnit and MS Excel and MSI to run this test script
|
||||||
|
|
||||||
require 'rubyunit'
|
require 'rubyunit'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# You need RubyUnit and MS Excel and MSI to run this test script
|
# You need RubyUnit and MS Excel and MSI to run this test script
|
||||||
|
|
||||||
require 'rubyunit'
|
require 'rubyunit'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# You need RubyUnit and MS Excel and MSI to run this test script
|
# You need RubyUnit and MS Excel and MSI to run this test script
|
||||||
|
|
||||||
require 'rubyunit'
|
require 'rubyunit'
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# You need RubyUnit and MS Excel and MSI to run this test script
|
# You need RubyUnit and MS Excel and MSI to run this test script
|
||||||
|
|
||||||
require 'runit/testcase'
|
require 'runit/testcase'
|
||||||
require 'runit/cui/testrunner'
|
require 'runit/cui/testrunner'
|
||||||
|
@ -289,7 +289,7 @@ class TestWin32OLE_WITH_MSI < RUNIT::TestCase
|
||||||
@record = installer.CreateRecord(2)
|
@record = installer.CreateRecord(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sorry, this test fails.
|
# Sorry, this test fails.
|
||||||
# Win32OLE does not support this style to set property.
|
# Win32OLE does not support this style to set property.
|
||||||
# Use Win32OLE#setproperty or Win32OLE#[]= .
|
# Use Win32OLE#setproperty or Win32OLE#[]= .
|
||||||
# def test_invoke
|
# def test_invoke
|
||||||
|
@ -317,7 +317,7 @@ end
|
||||||
# a subclass of Win32OLE
|
# a subclass of Win32OLE
|
||||||
# override new() and connect()
|
# override new() and connect()
|
||||||
class MyExcel<WIN32OLE
|
class MyExcel<WIN32OLE
|
||||||
def MyExcel.new
|
def MyExcel.new
|
||||||
super "Excel.Application"
|
super "Excel.Application"
|
||||||
end
|
end
|
||||||
def MyExcel.connect
|
def MyExcel.connect
|
||||||
|
@ -330,7 +330,7 @@ class TestMyExcel < TestWin32OLE
|
||||||
# because we overrided new() and connect()
|
# because we overrided new() and connect()
|
||||||
# we need to change the test.
|
# we need to change the test.
|
||||||
# also, because the class will be different
|
# also, because the class will be different
|
||||||
#
|
#
|
||||||
def setup
|
def setup
|
||||||
@excel = MyExcel.new
|
@excel = MyExcel.new
|
||||||
@excel.visible = true
|
@excel.visible = true
|
||||||
|
@ -344,7 +344,7 @@ class TestMyExcel < TestWin32OLE
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
# const_load didn't like to be called twice,
|
# const_load didn't like to be called twice,
|
||||||
# and I don't know how to undefine something in Ruby yet
|
# and I don't know how to undefine something in Ruby yet
|
||||||
# so, hide the test.
|
# so, hide the test.
|
||||||
#
|
#
|
||||||
private :test_s_const_load
|
private :test_s_const_load
|
||||||
|
|
|
@ -9,7 +9,7 @@ require "test/unit"
|
||||||
|
|
||||||
if defined?(WIN32OLE)
|
if defined?(WIN32OLE)
|
||||||
class TestWIN32OLE_FOR_PROPERTYPUTREF < Test::Unit::TestCase
|
class TestWIN32OLE_FOR_PROPERTYPUTREF < Test::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@obj = WIN32OLE.new('Scripting.Dictionary')
|
@obj = WIN32OLE.new('Scripting.Dictionary')
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,8 +35,8 @@ if defined?(WIN32OLE_EVENT)
|
||||||
ev.on_event {|*args| default_handler(*args)}
|
ev.on_event {|*args| default_handler(*args)}
|
||||||
@ie.navigate("file:///#{@f}")
|
@ie.navigate("file:///#{@f}")
|
||||||
while @ie.busy
|
while @ie.busy
|
||||||
WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents')
|
||||||
GC.start
|
GC.start
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
end
|
end
|
||||||
assert_match(/BeforeNavigate/, @event)
|
assert_match(/BeforeNavigate/, @event)
|
||||||
|
|
|
@ -9,7 +9,7 @@ require "test/unit"
|
||||||
|
|
||||||
if defined?(WIN32OLE)
|
if defined?(WIN32OLE)
|
||||||
class TestWIN32OLE_WITH_WORD < Test::Unit::TestCase
|
class TestWIN32OLE_WITH_WORD < Test::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
begin
|
begin
|
||||||
@obj = WIN32OLE.new('Word.Application')
|
@obj = WIN32OLE.new('Word.Application')
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
# With English:
|
# With English:
|
||||||
#
|
#
|
||||||
# require "English"
|
# require "English"
|
||||||
#
|
#
|
||||||
# $OUTPUT_FIELD_SEPARATOR = ' -- '
|
# $OUTPUT_FIELD_SEPARATOR = ' -- '
|
||||||
# "waterbuffalo" =~ /buff/
|
# "waterbuffalo" =~ /buff/
|
||||||
# print $LOADED_FEATURES, $POSTMATCH, $PID, "\n"
|
# print $LOADED_FEATURES, $POSTMATCH, $PID, "\n"
|
||||||
|
@ -83,7 +83,7 @@ alias $DEFAULT_OUTPUT $>
|
||||||
# of the contents of all the files
|
# of the contents of all the files
|
||||||
# given as command-line arguments, or <tt>$stdin</tt>
|
# given as command-line arguments, or <tt>$stdin</tt>
|
||||||
# (in the case where there are no
|
# (in the case where there are no
|
||||||
# arguments). <tt>$<</tt> supports methods similar to a
|
# arguments). <tt>$<</tt> supports methods similar to a
|
||||||
# +File+ object:
|
# +File+ object:
|
||||||
# +inmode+, +close+,
|
# +inmode+, +close+,
|
||||||
# <tt>closed?</tt>, +each+,
|
# <tt>closed?</tt>, +each+,
|
||||||
|
@ -91,7 +91,7 @@ alias $DEFAULT_OUTPUT $>
|
||||||
# +eof+, <tt>eof?</tt>, +file+,
|
# +eof+, <tt>eof?</tt>, +file+,
|
||||||
# +filename+, +fileno+,
|
# +filename+, +fileno+,
|
||||||
# +getc+, +gets+, +lineno+,
|
# +getc+, +gets+, +lineno+,
|
||||||
# <tt>lineno=</tt>, +path+,
|
# <tt>lineno=</tt>, +path+,
|
||||||
# +pos+, <tt>pos=</tt>,
|
# +pos+, <tt>pos=</tt>,
|
||||||
# +read+, +readchar+,
|
# +read+, +readchar+,
|
||||||
# +readline+, +readlines+,
|
# +readline+, +readlines+,
|
||||||
|
@ -139,12 +139,12 @@ alias $ARGV $*
|
||||||
alias $MATCH $&
|
alias $MATCH $&
|
||||||
|
|
||||||
# The string preceding the match in the last
|
# The string preceding the match in the last
|
||||||
# successful pattern match. This variable is local to
|
# successful pattern match. This variable is local to
|
||||||
# the current scope. Read only. Thread local.
|
# the current scope. Read only. Thread local.
|
||||||
alias $PREMATCH $`
|
alias $PREMATCH $`
|
||||||
|
|
||||||
# The string following the match in the last
|
# The string following the match in the last
|
||||||
# successful pattern match. This variable is local to
|
# successful pattern match. This variable is local to
|
||||||
# the current scope. Read only. Thread local.
|
# the current scope. Read only. Thread local.
|
||||||
alias $POSTMATCH $'
|
alias $POSTMATCH $'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#
|
#
|
||||||
# = base64.rb: methods for base64-encoding and -decoding strings
|
# = base64.rb: methods for base64-encoding and -decoding strings
|
||||||
#
|
#
|
||||||
# Author:: Yukihiro Matsumoto
|
# Author:: Yukihiro Matsumoto
|
||||||
# Documentation:: Dave Thomas and Gavin Sinclair
|
# Documentation:: Dave Thomas and Gavin Sinclair
|
||||||
#
|
#
|
||||||
# Until Ruby 1.8.1, these methods were defined at the top-level. Now
|
# Until Ruby 1.8.1, these methods were defined at the top-level. Now
|
||||||
|
@ -16,7 +16,7 @@ require "kconv"
|
||||||
|
|
||||||
# The Base64 module provides for the encoding (#encode64) and decoding
|
# The Base64 module provides for the encoding (#encode64) and decoding
|
||||||
# (#decode64) of binary data using a Base64 representation.
|
# (#decode64) of binary data using a Base64 representation.
|
||||||
#
|
#
|
||||||
# The following particular features are also provided:
|
# The following particular features are also provided:
|
||||||
# - encode into lines of a given length (#b64encode)
|
# - encode into lines of a given length (#b64encode)
|
||||||
# - decode the special format specified in RFC2047 for the
|
# - decode the special format specified in RFC2047 for the
|
||||||
|
@ -24,12 +24,12 @@ require "kconv"
|
||||||
#
|
#
|
||||||
# == Example
|
# == Example
|
||||||
#
|
#
|
||||||
# A simple encoding and decoding.
|
# A simple encoding and decoding.
|
||||||
#
|
#
|
||||||
# require "base64"
|
# require "base64"
|
||||||
#
|
#
|
||||||
# enc = Base64.encode64('Send reinforcements')
|
# enc = Base64.encode64('Send reinforcements')
|
||||||
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
# # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n"
|
||||||
# plain = Base64.decode64(enc)
|
# plain = Base64.decode64(enc)
|
||||||
# # -> "Send reinforcements"
|
# # -> "Send reinforcements"
|
||||||
#
|
#
|
||||||
|
@ -78,7 +78,7 @@ module Base64
|
||||||
decode64($1)
|
decode64($1)
|
||||||
}
|
}
|
||||||
str = Kconv::toeuc(str)
|
str = Kconv::toeuc(str)
|
||||||
str.gsub!(/\n/, ' ')
|
str.gsub!(/\n/, ' ')
|
||||||
str.gsub!(/\0/, '')
|
str.gsub!(/\0/, '')
|
||||||
str
|
str
|
||||||
end
|
end
|
||||||
|
@ -135,7 +135,7 @@ module Base64
|
||||||
# +len+ (default 60) characters.
|
# +len+ (default 60) characters.
|
||||||
#
|
#
|
||||||
# require 'base64'
|
# require 'base64'
|
||||||
# data = "Now is the time for all good coders\nto learn Ruby"
|
# data = "Now is the time for all good coders\nto learn Ruby"
|
||||||
# Base64.b64encode(data)
|
# Base64.b64encode(data)
|
||||||
#
|
#
|
||||||
# <i>Generates:</i>
|
# <i>Generates:</i>
|
||||||
|
@ -147,7 +147,7 @@ module Base64
|
||||||
encode64(bin).scan(/.{1,#{len}}/) do
|
encode64(bin).scan(/.{1,#{len}}/) do
|
||||||
print $&, "\n"
|
print $&, "\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
module Deprecated # :nodoc:
|
module Deprecated # :nodoc:
|
||||||
|
|
164
lib/benchmark.rb
164
lib/benchmark.rb
|
@ -1,13 +1,13 @@
|
||||||
=begin
|
=begin
|
||||||
#
|
#
|
||||||
# benchmark.rb - a performance benchmarking library
|
# benchmark.rb - a performance benchmarking library
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
#
|
#
|
||||||
# Created by Gotoken (gotoken@notwork.org).
|
# Created by Gotoken (gotoken@notwork.org).
|
||||||
#
|
#
|
||||||
# Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
|
# Documentation by Gotoken (original RD), Lyle Johnson (RDoc conversion), and
|
||||||
# Gavin Sinclair (editing).
|
# Gavin Sinclair (editing).
|
||||||
#
|
#
|
||||||
=end
|
=end
|
||||||
|
|
||||||
|
@ -26,15 +26,15 @@
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
#
|
#
|
||||||
# puts Benchmark.measure { "a"*1_000_000 }
|
# puts Benchmark.measure { "a"*1_000_000 }
|
||||||
#
|
#
|
||||||
# On my machine (FreeBSD 3.2 on P5, 100MHz) this generates:
|
# On my machine (FreeBSD 3.2 on P5, 100MHz) this generates:
|
||||||
#
|
#
|
||||||
# 1.166667 0.050000 1.216667 ( 0.571355)
|
# 1.166667 0.050000 1.216667 ( 0.571355)
|
||||||
#
|
#
|
||||||
# This report shows the user CPU time, system CPU time, the sum of
|
# 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
|
# the user and system CPU times, and the elapsed real time. The unit
|
||||||
# of time is seconds.
|
# of time is seconds.
|
||||||
#
|
#
|
||||||
# * Do some experiments sequentially using the #bm method:
|
# * Do some experiments sequentially using the #bm method:
|
||||||
#
|
#
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
# x.report { n.times do ; a = "1"; end }
|
# x.report { n.times do ; a = "1"; end }
|
||||||
# x.report { 1.upto(n) do ; a = "1"; end }
|
# x.report { 1.upto(n) do ; a = "1"; end }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# The result:
|
# The result:
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
|
@ -63,14 +63,14 @@
|
||||||
# x.report("times:") { n.times do ; a = "1"; end }
|
# x.report("times:") { n.times do ; a = "1"; end }
|
||||||
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# The result:
|
# The result:
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
# for: 1.050000 0.000000 1.050000 ( 0.503462)
|
# for: 1.050000 0.000000 1.050000 ( 0.503462)
|
||||||
# times: 1.533333 0.016667 1.550000 ( 0.735473)
|
# times: 1.533333 0.016667 1.550000 ( 0.735473)
|
||||||
# upto: 1.500000 0.016667 1.516667 ( 0.711239)
|
# upto: 1.500000 0.016667 1.516667 ( 0.711239)
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# * The times for some benchmarks depend on the order in which items
|
# * The times for some benchmarks depend on the order in which items
|
||||||
# are run. These differences are due to the cost of memory
|
# are run. These differences are due to the cost of memory
|
||||||
|
@ -79,21 +79,21 @@
|
||||||
# sort an array of floats:
|
# sort an array of floats:
|
||||||
#
|
#
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
#
|
#
|
||||||
# array = (1..1000000).map { rand }
|
# array = (1..1000000).map { rand }
|
||||||
#
|
#
|
||||||
# Benchmark.bmbm do |x|
|
# Benchmark.bmbm do |x|
|
||||||
# x.report("sort!") { array.dup.sort! }
|
# x.report("sort!") { array.dup.sort! }
|
||||||
# x.report("sort") { array.dup.sort }
|
# x.report("sort") { array.dup.sort }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# The result:
|
# The result:
|
||||||
#
|
#
|
||||||
# Rehearsal -----------------------------------------
|
# Rehearsal -----------------------------------------
|
||||||
# sort! 11.928000 0.010000 11.938000 ( 12.756000)
|
# sort! 11.928000 0.010000 11.938000 ( 12.756000)
|
||||||
# sort 13.048000 0.020000 13.068000 ( 13.857000)
|
# sort 13.048000 0.020000 13.068000 ( 13.857000)
|
||||||
# ------------------------------- total: 25.006000sec
|
# ------------------------------- total: 25.006000sec
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
# sort! 12.959000 0.010000 12.969000 ( 13.793000)
|
# sort! 12.959000 0.010000 12.969000 ( 13.793000)
|
||||||
# sort 12.007000 0.000000 12.007000 ( 12.791000)
|
# sort 12.007000 0.000000 12.007000 ( 12.791000)
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
# using the #benchmark method:
|
# using the #benchmark method:
|
||||||
#
|
#
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
# include Benchmark # we need the CAPTION and FMTSTR constants
|
# include Benchmark # we need the CAPTION and FMTSTR constants
|
||||||
#
|
#
|
||||||
# n = 50000
|
# n = 50000
|
||||||
# Benchmark.benchmark(" "*7 + CAPTION, 7, FMTSTR, ">total:", ">avg:") do |x|
|
# Benchmark.benchmark(" "*7 + CAPTION, 7, FMTSTR, ">total:", ">avg:") do |x|
|
||||||
|
@ -112,9 +112,9 @@
|
||||||
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||||
# [tf+tt+tu, (tf+tt+tu)/3]
|
# [tf+tt+tu, (tf+tt+tu)/3]
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# The result:
|
# The result:
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
# for: 1.016667 0.016667 1.033333 ( 0.485749)
|
# for: 1.016667 0.016667 1.033333 ( 0.485749)
|
||||||
# times: 1.450000 0.016667 1.466667 ( 0.681367)
|
# times: 1.450000 0.016667 1.466667 ( 0.681367)
|
||||||
|
@ -145,10 +145,10 @@ module Benchmark
|
||||||
# suitable for nearly all benchmarking requirements. See the examples in
|
# suitable for nearly all benchmarking requirements. See the examples in
|
||||||
# Benchmark, and the #bm and #bmbm methods.
|
# Benchmark, and the #bm and #bmbm methods.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
# include Benchmark # we need the CAPTION and FMTSTR constants
|
# include Benchmark # we need the CAPTION and FMTSTR constants
|
||||||
#
|
#
|
||||||
# n = 50000
|
# n = 50000
|
||||||
# Benchmark.benchmark(" "*7 + CAPTION, 7, FMTSTR, ">total:", ">avg:") do |x|
|
# Benchmark.benchmark(" "*7 + CAPTION, 7, FMTSTR, ">total:", ">avg:") do |x|
|
||||||
|
@ -157,16 +157,16 @@ module Benchmark
|
||||||
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
# tu = x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||||
# [tf+tt+tu, (tf+tt+tu)/3]
|
# [tf+tt+tu, (tf+tt+tu)/3]
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# <i>Generates:</i>
|
# <i>Generates:</i>
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
# for: 1.016667 0.016667 1.033333 ( 0.485749)
|
# for: 1.016667 0.016667 1.033333 ( 0.485749)
|
||||||
# times: 1.450000 0.016667 1.466667 ( 0.681367)
|
# times: 1.450000 0.016667 1.466667 ( 0.681367)
|
||||||
# upto: 1.533333 0.000000 1.533333 ( 0.722166)
|
# upto: 1.533333 0.000000 1.533333 ( 0.722166)
|
||||||
# >total: 4.000000 0.033333 4.033333 ( 1.889282)
|
# >total: 4.000000 0.033333 4.033333 ( 1.889282)
|
||||||
# >avg: 1.333333 0.011111 1.344444 ( 0.629761)
|
# >avg: 1.333333 0.011111 1.344444 ( 0.629761)
|
||||||
#
|
#
|
||||||
|
|
||||||
def benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) # :yield: report
|
def benchmark(caption = "", label_width = nil, fmtstr = nil, *labels) # :yield: report
|
||||||
sync = STDOUT.sync
|
sync = STDOUT.sync
|
||||||
|
@ -177,7 +177,7 @@ module Benchmark
|
||||||
print caption
|
print caption
|
||||||
results = yield(Report.new(label_width, fmtstr))
|
results = yield(Report.new(label_width, fmtstr))
|
||||||
Array === results and results.grep(Tms).each {|t|
|
Array === results and results.grep(Tms).each {|t|
|
||||||
print((labels.shift || t.label || "").ljust(label_width),
|
print((labels.shift || t.label || "").ljust(label_width),
|
||||||
t.format(fmtstr))
|
t.format(fmtstr))
|
||||||
}
|
}
|
||||||
STDOUT.sync = sync
|
STDOUT.sync = sync
|
||||||
|
@ -186,7 +186,7 @@ module Benchmark
|
||||||
|
|
||||||
# A simple interface to the #benchmark method, #bm is generates sequential reports
|
# A simple interface to the #benchmark method, #bm is generates sequential reports
|
||||||
# with labels. The parameters have the same meaning as for #benchmark.
|
# with labels. The parameters have the same meaning as for #benchmark.
|
||||||
#
|
#
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
#
|
#
|
||||||
# n = 50000
|
# n = 50000
|
||||||
|
@ -195,9 +195,9 @@ module Benchmark
|
||||||
# x.report("times:") { n.times do ; a = "1"; end }
|
# x.report("times:") { n.times do ; a = "1"; end }
|
||||||
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
# x.report("upto:") { 1.upto(n) do ; a = "1"; end }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# <i>Generates:</i>
|
# <i>Generates:</i>
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
# for: 1.050000 0.000000 1.050000 ( 0.503462)
|
# for: 1.050000 0.000000 1.050000 ( 0.503462)
|
||||||
# times: 1.533333 0.016667 1.550000 ( 0.735473)
|
# times: 1.533333 0.016667 1.550000 ( 0.735473)
|
||||||
|
@ -224,21 +224,21 @@ module Benchmark
|
||||||
# calculate the required label width.
|
# calculate the required label width.
|
||||||
#
|
#
|
||||||
# require 'benchmark'
|
# require 'benchmark'
|
||||||
#
|
#
|
||||||
# array = (1..1000000).map { rand }
|
# array = (1..1000000).map { rand }
|
||||||
#
|
#
|
||||||
# Benchmark.bmbm do |x|
|
# Benchmark.bmbm do |x|
|
||||||
# x.report("sort!") { array.dup.sort! }
|
# x.report("sort!") { array.dup.sort! }
|
||||||
# x.report("sort") { array.dup.sort }
|
# x.report("sort") { array.dup.sort }
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# <i>Generates:</i>
|
# <i>Generates:</i>
|
||||||
#
|
#
|
||||||
# Rehearsal -----------------------------------------
|
# Rehearsal -----------------------------------------
|
||||||
# sort! 11.928000 0.010000 11.938000 ( 12.756000)
|
# sort! 11.928000 0.010000 11.938000 ( 12.756000)
|
||||||
# sort 13.048000 0.020000 13.068000 ( 13.857000)
|
# sort 13.048000 0.020000 13.068000 ( 13.857000)
|
||||||
# ------------------------------- total: 25.006000sec
|
# ------------------------------- total: 25.006000sec
|
||||||
#
|
#
|
||||||
# user system total real
|
# user system total real
|
||||||
# sort! 12.959000 0.010000 12.969000 ( 13.793000)
|
# sort! 12.959000 0.010000 12.969000 ( 13.793000)
|
||||||
# sort 12.007000 0.000000 12.007000 ( 12.791000)
|
# sort 12.007000 0.000000 12.007000 ( 12.791000)
|
||||||
|
@ -267,7 +267,7 @@ module Benchmark
|
||||||
ets = sum.format("total: %tsec")
|
ets = sum.format("total: %tsec")
|
||||||
printf("%s %s\n\n",
|
printf("%s %s\n\n",
|
||||||
"-"*(width+CAPTION.length-ets.length-1), ets)
|
"-"*(width+CAPTION.length-ets.length-1), ets)
|
||||||
|
|
||||||
# take
|
# take
|
||||||
print ' '*width, CAPTION
|
print ' '*width, CAPTION
|
||||||
list = []
|
list = []
|
||||||
|
@ -285,7 +285,7 @@ module Benchmark
|
||||||
ary
|
ary
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns the time used to execute the given block as a
|
# Returns the time used to execute the given block as a
|
||||||
# Benchmark::Tms object.
|
# Benchmark::Tms object.
|
||||||
#
|
#
|
||||||
|
@ -293,10 +293,10 @@ module Benchmark
|
||||||
t0, r0 = Benchmark.times, Time.now
|
t0, r0 = Benchmark.times, Time.now
|
||||||
yield
|
yield
|
||||||
t1, r1 = Benchmark.times, Time.now
|
t1, r1 = Benchmark.times, Time.now
|
||||||
Benchmark::Tms.new(t1.utime - t0.utime,
|
Benchmark::Tms.new(t1.utime - t0.utime,
|
||||||
t1.stime - t0.stime,
|
t1.stime - t0.stime,
|
||||||
t1.cutime - t0.cutime,
|
t1.cutime - t0.cutime,
|
||||||
t1.cstime - t0.cstime,
|
t1.cstime - t0.cstime,
|
||||||
r1.to_f - r0.to_f,
|
r1.to_f - r0.to_f,
|
||||||
label)
|
label)
|
||||||
end
|
end
|
||||||
|
@ -323,8 +323,8 @@ module Benchmark
|
||||||
# Usually, one doesn't call this method directly, as new
|
# Usually, one doesn't call this method directly, as new
|
||||||
# Job objects are created by the #bmbm method.
|
# Job objects are created by the #bmbm method.
|
||||||
# _width_ is a initial value for the label offset used in formatting;
|
# _width_ is a initial value for the label offset used in formatting;
|
||||||
# the #bmbm method passes its _width_ argument to this constructor.
|
# the #bmbm method passes its _width_ argument to this constructor.
|
||||||
#
|
#
|
||||||
def initialize(width)
|
def initialize(width)
|
||||||
@width = width
|
@width = width
|
||||||
@list = []
|
@list = []
|
||||||
|
@ -343,11 +343,11 @@ module Benchmark
|
||||||
end
|
end
|
||||||
|
|
||||||
alias report item
|
alias report item
|
||||||
|
|
||||||
# An array of 2-element arrays, consisting of label and block pairs.
|
# An array of 2-element arrays, consisting of label and block pairs.
|
||||||
attr_reader :list
|
attr_reader :list
|
||||||
|
|
||||||
# Length of the widest label in the #list, plus one.
|
# Length of the widest label in the #list, plus one.
|
||||||
attr_reader :width
|
attr_reader :width
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -363,10 +363,10 @@ module Benchmark
|
||||||
#
|
#
|
||||||
# Returns an initialized Report instance.
|
# Returns an initialized Report instance.
|
||||||
# Usually, one doesn't call this method directly, as new
|
# Usually, one doesn't call this method directly, as new
|
||||||
# Report objects are created by the #benchmark and #bm methods.
|
# Report objects are created by the #benchmark and #bm methods.
|
||||||
# _width_ and _fmtstr_ are the label offset and
|
# _width_ and _fmtstr_ are the label offset and
|
||||||
# format string used by Tms#format.
|
# format string used by Tms#format.
|
||||||
#
|
#
|
||||||
def initialize(width = 0, fmtstr = nil)
|
def initialize(width = 0, fmtstr = nil)
|
||||||
@width, @fmtstr = width, fmtstr
|
@width, @fmtstr = width, fmtstr
|
||||||
end
|
end
|
||||||
|
@ -398,50 +398,50 @@ module Benchmark
|
||||||
|
|
||||||
# User CPU time
|
# User CPU time
|
||||||
attr_reader :utime
|
attr_reader :utime
|
||||||
|
|
||||||
# System CPU time
|
# System CPU time
|
||||||
attr_reader :stime
|
attr_reader :stime
|
||||||
|
|
||||||
# User CPU time of children
|
# User CPU time of children
|
||||||
attr_reader :cutime
|
attr_reader :cutime
|
||||||
|
|
||||||
# System CPU time of children
|
# System CPU time of children
|
||||||
attr_reader :cstime
|
attr_reader :cstime
|
||||||
|
|
||||||
# Elapsed real time
|
# Elapsed real time
|
||||||
attr_reader :real
|
attr_reader :real
|
||||||
|
|
||||||
# Total time, that is _utime_ + _stime_ + _cutime_ + _cstime_
|
# Total time, that is _utime_ + _stime_ + _cutime_ + _cstime_
|
||||||
attr_reader :total
|
attr_reader :total
|
||||||
|
|
||||||
# Label
|
# Label
|
||||||
attr_reader :label
|
attr_reader :label
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns an initialized Tms object which has
|
# Returns an initialized Tms object which has
|
||||||
# _u_ as the user CPU time, _s_ as the system CPU time,
|
# _u_ as the user CPU time, _s_ as the system CPU time,
|
||||||
# _cu_ as the children's user CPU time, _cs_ as the children's
|
# _cu_ as the children's user CPU time, _cs_ as the children's
|
||||||
# system CPU time, _real_ as the elapsed real time and _l_
|
# system CPU time, _real_ as the elapsed real time and _l_
|
||||||
# as the label.
|
# as the label.
|
||||||
#
|
#
|
||||||
def initialize(u = 0.0, s = 0.0, cu = 0.0, cs = 0.0, real = 0.0, l = nil)
|
def initialize(u = 0.0, s = 0.0, cu = 0.0, cs = 0.0, real = 0.0, l = nil)
|
||||||
@utime, @stime, @cutime, @cstime, @real, @label = u, s, cu, cs, real, l
|
@utime, @stime, @cutime, @cstime, @real, @label = u, s, cu, cs, real, l
|
||||||
@total = @utime + @stime + @cutime + @cstime
|
@total = @utime + @stime + @cutime + @cstime
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a new Tms object whose times are the sum of the times for this
|
# 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_).
|
# Tms object, plus the time required to execute the code block (_blk_).
|
||||||
#
|
#
|
||||||
def add(&blk) # :yield:
|
def add(&blk) # :yield:
|
||||||
self + Benchmark::measure(&blk)
|
self + Benchmark::measure(&blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# An in-place version of #add.
|
# An in-place version of #add.
|
||||||
#
|
#
|
||||||
def add!
|
def add!
|
||||||
t = Benchmark::measure(&blk)
|
t = Benchmark::measure(&blk)
|
||||||
@utime = utime + t.utime
|
@utime = utime + t.utime
|
||||||
@stime = stime + t.stime
|
@stime = stime + t.stime
|
||||||
@cutime = cutime + t.cutime
|
@cutime = cutime + t.cutime
|
||||||
|
@ -450,32 +450,32 @@ module Benchmark
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a new Tms object obtained by memberwise summation
|
# Returns a new Tms object obtained by memberwise summation
|
||||||
# of the individual times for this Tms object with those of the other
|
# of the individual times for this Tms object with those of the other
|
||||||
# Tms object.
|
# Tms object.
|
||||||
# This method and #/() are useful for taking statistics.
|
# This method and #/() are useful for taking statistics.
|
||||||
#
|
#
|
||||||
def +(other); memberwise(:+, other) end
|
def +(other); memberwise(:+, other) end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a new Tms object obtained by memberwise subtraction
|
# Returns a new Tms object obtained by memberwise subtraction
|
||||||
# of the individual times for the other Tms object from those of this
|
# of the individual times for the other Tms object from those of this
|
||||||
# Tms object.
|
# Tms object.
|
||||||
#
|
#
|
||||||
def -(other); memberwise(:-, other) end
|
def -(other); memberwise(:-, other) end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a new Tms object obtained by memberwise multiplication
|
# Returns a new Tms object obtained by memberwise multiplication
|
||||||
# of the individual times for this Tms object by _x_.
|
# of the individual times for this Tms object by _x_.
|
||||||
#
|
#
|
||||||
def *(x); memberwise(:*, x) end
|
def *(x); memberwise(:*, x) end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a new Tms object obtained by memberwise division
|
# Returns a new Tms object obtained by memberwise division
|
||||||
# of the individual times for this Tms object by _x_.
|
# of the individual times for this Tms object by _x_.
|
||||||
# This method and #+() are useful for taking statistics.
|
# This method and #+() are useful for taking statistics.
|
||||||
#
|
#
|
||||||
def /(x); memberwise(:/, x) end
|
def /(x); memberwise(:/, x) end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -486,15 +486,15 @@ module Benchmark
|
||||||
#
|
#
|
||||||
# <tt>%u</tt>:: Replaced by the user CPU time, as reported by Tms#utime.
|
# <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>%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>%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>%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>%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>%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")
|
# <tt>%n</tt>:: Replaced by the label string, as reported by Tms#label (Mnemonic: n of "*n*ame")
|
||||||
#
|
#
|
||||||
# If _fmtstr_ is not given, FMTSTR is used as default value, detailing the
|
# If _fmtstr_ is not given, FMTSTR is used as default value, detailing the
|
||||||
# user, system and real elapsed time.
|
# user, system and real elapsed time.
|
||||||
#
|
#
|
||||||
def format(arg0 = nil, *args)
|
def format(arg0 = nil, *args)
|
||||||
fmtstr = (arg0 || FMTSTR).dup
|
fmtstr = (arg0 || FMTSTR).dup
|
||||||
fmtstr.gsub!(/(%[-+\.\d]*)n/){"#{$1}s" % label}
|
fmtstr.gsub!(/(%[-+\.\d]*)n/){"#{$1}s" % label}
|
||||||
|
@ -507,19 +507,19 @@ module Benchmark
|
||||||
arg0 ? Kernel::format(fmtstr, *args) : fmtstr
|
arg0 ? Kernel::format(fmtstr, *args) : fmtstr
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Same as #format.
|
# Same as #format.
|
||||||
#
|
#
|
||||||
def to_s
|
def to_s
|
||||||
format
|
format
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a new 6-element array, consisting of the
|
# Returns a new 6-element array, consisting of the
|
||||||
# label, user CPU time, system CPU time, children's
|
# label, user CPU time, system CPU time, children's
|
||||||
# user CPU time, children's system CPU time and elapsed
|
# user CPU time, children's system CPU time and elapsed
|
||||||
# real time.
|
# real time.
|
||||||
#
|
#
|
||||||
def to_a
|
def to_a
|
||||||
[@label, @utime, @stime, @cutime, @cstime, @real]
|
[@label, @utime, @stime, @cutime, @cstime, @real]
|
||||||
end
|
end
|
||||||
|
@ -548,7 +548,7 @@ module Benchmark
|
||||||
# The default caption string (heading above the output times).
|
# The default caption string (heading above the output times).
|
||||||
CAPTION = Benchmark::Tms::CAPTION
|
CAPTION = Benchmark::Tms::CAPTION
|
||||||
|
|
||||||
# The default format string used to display times. See also Benchmark::Tms#format.
|
# The default format string used to display times. See also Benchmark::Tms#format.
|
||||||
FMTSTR = Benchmark::Tms::FMTSTR
|
FMTSTR = Benchmark::Tms::FMTSTR
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
248
lib/cgi.rb
248
lib/cgi.rb
|
@ -1,14 +1,14 @@
|
||||||
#
|
#
|
||||||
# cgi.rb - cgi support library
|
# cgi.rb - cgi support library
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
# Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||||
#
|
#
|
||||||
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
# Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||||
#
|
#
|
||||||
# Author: Wakou Aoyama <wakou@ruby-lang.org>
|
# Author: Wakou Aoyama <wakou@ruby-lang.org>
|
||||||
#
|
#
|
||||||
# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
|
# Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
|
||||||
#
|
#
|
||||||
# == Overview
|
# == Overview
|
||||||
#
|
#
|
||||||
# The Common Gateway Interface (CGI) is a simple protocol
|
# The Common Gateway Interface (CGI) is a simple protocol
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
# parameters of the request passed in either in the
|
# parameters of the request passed in either in the
|
||||||
# environment (GET) or via $stdin (POST), and everything
|
# environment (GET) or via $stdin (POST), and everything
|
||||||
# it prints to $stdout is returned to the client.
|
# it prints to $stdout is returned to the client.
|
||||||
#
|
#
|
||||||
# This file holds the +CGI+ class. This class provides
|
# This file holds the +CGI+ class. This class provides
|
||||||
# functionality for retrieving HTTP request parameters,
|
# functionality for retrieving HTTP request parameters,
|
||||||
# managing cookies, and generating HTML output. See the
|
# managing cookies, and generating HTML output. See the
|
||||||
|
@ -77,18 +77,18 @@ require 'English'
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# For each of these variables, there is a corresponding attribute with the
|
# For each of these variables, there is a corresponding attribute with the
|
||||||
# same name, except all lower case and without a preceding HTTP_.
|
# same name, except all lower case and without a preceding HTTP_.
|
||||||
# +content_length+ and +server_port+ are integers; the rest are strings.
|
# +content_length+ and +server_port+ are integers; the rest are strings.
|
||||||
#
|
#
|
||||||
# === Parameters
|
# === Parameters
|
||||||
#
|
#
|
||||||
# The method #params() returns a hash of all parameters in the request as
|
# 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
|
# 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
|
# 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
|
# to values, but only returns a single value (as a String) for each
|
||||||
# parameter name.
|
# parameter name.
|
||||||
#
|
#
|
||||||
# For instance, suppose the request contains the parameter
|
# For instance, suppose the request contains the parameter
|
||||||
# "favourite_colours" with the multiple values "blue" and "green". The
|
# "favourite_colours" with the multiple values "blue" and "green". The
|
||||||
# following behaviour would occur:
|
# following behaviour would occur:
|
||||||
#
|
#
|
||||||
|
@ -107,7 +107,7 @@ require 'English'
|
||||||
#
|
#
|
||||||
# === Multipart requests
|
# === Multipart requests
|
||||||
#
|
#
|
||||||
# If a request's method is POST and its content type is multipart/form-data,
|
# 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
|
# 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
|
# 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
|
# attribute of the file input field, as usual. However, the value is not
|
||||||
|
@ -138,7 +138,7 @@ require 'English'
|
||||||
#
|
#
|
||||||
# Each HTML element has a corresponding method for generating that
|
# Each HTML element has a corresponding method for generating that
|
||||||
# element as a String. The name of this method is the same as 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
|
# 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
|
# 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
|
# to a String. The HTML generation module knows which elements are
|
||||||
# always empty, and silently drops any passed-in body. It also knows
|
# always empty, and silently drops any passed-in body. It also knows
|
||||||
|
@ -152,57 +152,57 @@ require 'English'
|
||||||
# as arguments, rather than via a hash.
|
# as arguments, rather than via a hash.
|
||||||
#
|
#
|
||||||
# == Examples of use
|
# == Examples of use
|
||||||
#
|
#
|
||||||
# === Get form values
|
# === Get form values
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new
|
# cgi = CGI.new
|
||||||
# value = cgi['field_name'] # <== value string for 'field_name'
|
# value = cgi['field_name'] # <== value string for 'field_name'
|
||||||
# # if not 'field_name' included, then return "".
|
# # if not 'field_name' included, then return "".
|
||||||
# fields = cgi.keys # <== array of field names
|
# fields = cgi.keys # <== array of field names
|
||||||
#
|
#
|
||||||
# # returns true if form has 'field_name'
|
# # returns true if form has 'field_name'
|
||||||
# cgi.has_key?('field_name')
|
# cgi.has_key?('field_name')
|
||||||
# cgi.has_key?('field_name')
|
# cgi.has_key?('field_name')
|
||||||
# cgi.include?('field_name')
|
# cgi.include?('field_name')
|
||||||
#
|
#
|
||||||
# CAUTION! cgi['field_name'] returned an Array with the old
|
# CAUTION! cgi['field_name'] returned an Array with the old
|
||||||
# cgi.rb(included in ruby 1.6)
|
# cgi.rb(included in ruby 1.6)
|
||||||
#
|
#
|
||||||
# === Get form values as hash
|
# === Get form values as hash
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new
|
# cgi = CGI.new
|
||||||
# params = cgi.params
|
# params = cgi.params
|
||||||
#
|
#
|
||||||
# cgi.params is a hash.
|
# cgi.params is a hash.
|
||||||
#
|
#
|
||||||
# cgi.params['new_field_name'] = ["value"] # add new param
|
# cgi.params['new_field_name'] = ["value"] # add new param
|
||||||
# cgi.params['field_name'] = ["new_value"] # change value
|
# cgi.params['field_name'] = ["new_value"] # change value
|
||||||
# cgi.params.delete('field_name') # delete param
|
# cgi.params.delete('field_name') # delete param
|
||||||
# cgi.params.clear # delete all params
|
# cgi.params.clear # delete all params
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# === Save form values to file
|
# === Save form values to file
|
||||||
#
|
#
|
||||||
# require "pstore"
|
# require "pstore"
|
||||||
# db = PStore.new("query.db")
|
# db = PStore.new("query.db")
|
||||||
# db.transaction do
|
# db.transaction do
|
||||||
# db["params"] = cgi.params
|
# db["params"] = cgi.params
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# === Restore form values from file
|
# === Restore form values from file
|
||||||
#
|
#
|
||||||
# require "pstore"
|
# require "pstore"
|
||||||
# db = PStore.new("query.db")
|
# db = PStore.new("query.db")
|
||||||
# db.transaction do
|
# db.transaction do
|
||||||
# cgi.params = db["params"]
|
# cgi.params = db["params"]
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# === Get multipart form values
|
# === Get multipart form values
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new
|
# cgi = CGI.new
|
||||||
# value = cgi['field_name'] # <== value string for 'field_name'
|
# value = cgi['field_name'] # <== value string for 'field_name'
|
||||||
|
@ -210,37 +210,37 @@ require 'English'
|
||||||
# value.local_path # <== path to local file of value
|
# value.local_path # <== path to local file of value
|
||||||
# value.original_filename # <== original filename of value
|
# value.original_filename # <== original filename of value
|
||||||
# value.content_type # <== content_type of value
|
# value.content_type # <== content_type of value
|
||||||
#
|
#
|
||||||
# and value has StringIO or Tempfile class methods.
|
# and value has StringIO or Tempfile class methods.
|
||||||
#
|
#
|
||||||
# === Get cookie values
|
# === Get cookie values
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new
|
# cgi = CGI.new
|
||||||
# values = cgi.cookies['name'] # <== array of 'name'
|
# values = cgi.cookies['name'] # <== array of 'name'
|
||||||
# # if not 'name' included, then return [].
|
# # if not 'name' included, then return [].
|
||||||
# names = cgi.cookies.keys # <== array of cookie names
|
# names = cgi.cookies.keys # <== array of cookie names
|
||||||
#
|
#
|
||||||
# and cgi.cookies is a hash.
|
# and cgi.cookies is a hash.
|
||||||
#
|
#
|
||||||
# === Get cookie objects
|
# === Get cookie objects
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new
|
# cgi = CGI.new
|
||||||
# for name, cookie in cgi.cookies
|
# for name, cookie in cgi.cookies
|
||||||
# cookie.expires = Time.now + 30
|
# cookie.expires = Time.now + 30
|
||||||
# end
|
# end
|
||||||
# cgi.out("cookie" => cgi.cookies) {"string"}
|
# cgi.out("cookie" => cgi.cookies) {"string"}
|
||||||
#
|
#
|
||||||
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
|
# cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new
|
# cgi = CGI.new
|
||||||
# cgi.cookies['name'].expires = Time.now + 30
|
# cgi.cookies['name'].expires = Time.now + 30
|
||||||
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
|
# cgi.out("cookie" => cgi.cookies['name']) {"string"}
|
||||||
#
|
#
|
||||||
# === Print http header and html string to $DEFAULT_OUTPUT ($>)
|
# === Print http header and html string to $DEFAULT_OUTPUT ($>)
|
||||||
#
|
#
|
||||||
# require "cgi"
|
# require "cgi"
|
||||||
# cgi = CGI.new("html3") # add HTML generation methods
|
# cgi = CGI.new("html3") # add HTML generation methods
|
||||||
# cgi.out() do
|
# cgi.out() do
|
||||||
|
@ -264,7 +264,7 @@ require 'English'
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # add HTML generation methods
|
# # add HTML generation methods
|
||||||
# CGI.new("html3") # html3.2
|
# CGI.new("html3") # html3.2
|
||||||
# CGI.new("html4") # html4.01 (Strict)
|
# CGI.new("html4") # html4.01 (Strict)
|
||||||
|
@ -286,7 +286,7 @@ class CGI
|
||||||
|
|
||||||
REVISION = '$Id$' #:nodoc:
|
REVISION = '$Id$' #:nodoc:
|
||||||
|
|
||||||
NEEDS_BINMODE = true if /WIN/ni.match(RUBY_PLATFORM)
|
NEEDS_BINMODE = true if /WIN/ni.match(RUBY_PLATFORM)
|
||||||
|
|
||||||
# Path separators in different environments.
|
# Path separators in different environments.
|
||||||
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
|
PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
|
||||||
|
@ -321,7 +321,7 @@ class CGI
|
||||||
|
|
||||||
# :startdoc:
|
# :startdoc:
|
||||||
|
|
||||||
def env_table
|
def env_table
|
||||||
ENV
|
ENV
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ class CGI
|
||||||
# print CGI::unescapeElement(
|
# print CGI::unescapeElement(
|
||||||
# CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
# CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
||||||
# # "<BR><A HREF="url"></A>"
|
# # "<BR><A HREF="url"></A>"
|
||||||
#
|
#
|
||||||
# print CGI::unescapeElement(
|
# print CGI::unescapeElement(
|
||||||
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
# CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
||||||
# # "<BR><A HREF="url"></A>"
|
# # "<BR><A HREF="url"></A>"
|
||||||
|
@ -475,7 +475,7 @@ class CGI
|
||||||
# status:: the HTTP status code, returned as the Status header. See the
|
# status:: the HTTP status code, returned as the Status header. See the
|
||||||
# list of available status codes below.
|
# list of available status codes below.
|
||||||
# server:: the server software, returned as the Server header.
|
# server:: the server software, returned as the Server header.
|
||||||
# connection:: the connection type, returned as the Connection header (for
|
# connection:: the connection type, returned as the Connection header (for
|
||||||
# instance, "close".
|
# instance, "close".
|
||||||
# length:: the length of the content that will be sent, returned as the
|
# length:: the length of the content that will be sent, returned as the
|
||||||
# Content-Length header.
|
# Content-Length header.
|
||||||
|
@ -485,19 +485,19 @@ class CGI
|
||||||
# object, returned as the Expires header.
|
# object, returned as the Expires header.
|
||||||
# cookie:: a cookie or cookies, returned as one or more Set-Cookie headers.
|
# 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
|
# 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
|
# object; an Array of literal cookie strings or Cookie objects; or a
|
||||||
# hash all of whose values are literal cookie strings or Cookie objects.
|
# hash all of whose values are literal cookie strings or Cookie objects.
|
||||||
# These cookies are in addition to the cookies held in the
|
# These cookies are in addition to the cookies held in the
|
||||||
# @output_cookies field.
|
# @output_cookies field.
|
||||||
#
|
#
|
||||||
# Other header lines can also be set; they are appended as key: value.
|
# Other header lines can also be set; they are appended as key: value.
|
||||||
#
|
#
|
||||||
# header
|
# header
|
||||||
# # Content-Type: text/html
|
# # Content-Type: text/html
|
||||||
#
|
#
|
||||||
# header("text/plain")
|
# header("text/plain")
|
||||||
# # Content-Type: text/plain
|
# # Content-Type: text/plain
|
||||||
#
|
#
|
||||||
# header("nph" => true,
|
# header("nph" => true,
|
||||||
# "status" => "OK", # == "200 OK"
|
# "status" => "OK", # == "200 OK"
|
||||||
# # "status" => "200 GOOD",
|
# # "status" => "200 GOOD",
|
||||||
|
@ -512,9 +512,9 @@ class CGI
|
||||||
# "cookie" => [cookie1, cookie2],
|
# "cookie" => [cookie1, cookie2],
|
||||||
# "my_header1" => "my_value"
|
# "my_header1" => "my_value"
|
||||||
# "my_header2" => "my_value")
|
# "my_header2" => "my_value")
|
||||||
#
|
#
|
||||||
# The status codes are:
|
# The status codes are:
|
||||||
#
|
#
|
||||||
# "OK" --> "200 OK"
|
# "OK" --> "200 OK"
|
||||||
# "PARTIAL_CONTENT" --> "206 Partial Content"
|
# "PARTIAL_CONTENT" --> "206 Partial Content"
|
||||||
# "MULTIPLE_CHOICES" --> "300 Multiple Choices"
|
# "MULTIPLE_CHOICES" --> "300 Multiple Choices"
|
||||||
|
@ -533,8 +533,8 @@ class CGI
|
||||||
# "NOT_IMPLEMENTED" --> "501 Method Not Implemented"
|
# "NOT_IMPLEMENTED" --> "501 Method Not Implemented"
|
||||||
# "BAD_GATEWAY" --> "502 Bad Gateway"
|
# "BAD_GATEWAY" --> "502 Bad Gateway"
|
||||||
# "VARIANT_ALSO_VARIES" --> "506 Variant Also Negotiates"
|
# "VARIANT_ALSO_VARIES" --> "506 Variant Also Negotiates"
|
||||||
#
|
#
|
||||||
# This method does not perform charset conversion.
|
# This method does not perform charset conversion.
|
||||||
#
|
#
|
||||||
def header(options = "text/html")
|
def header(options = "text/html")
|
||||||
|
|
||||||
|
@ -670,13 +670,13 @@ class CGI
|
||||||
# # Content-Length: 6
|
# # Content-Length: 6
|
||||||
# #
|
# #
|
||||||
# # string
|
# # string
|
||||||
#
|
#
|
||||||
# cgi.out("text/plain") { "string" }
|
# cgi.out("text/plain") { "string" }
|
||||||
# # Content-Type: text/plain
|
# # Content-Type: text/plain
|
||||||
# # Content-Length: 6
|
# # Content-Length: 6
|
||||||
# #
|
# #
|
||||||
# # string
|
# # string
|
||||||
#
|
#
|
||||||
# cgi.out("nph" => true,
|
# cgi.out("nph" => true,
|
||||||
# "status" => "OK", # == "200 OK"
|
# "status" => "OK", # == "200 OK"
|
||||||
# "server" => ENV['SERVER_SOFTWARE'],
|
# "server" => ENV['SERVER_SOFTWARE'],
|
||||||
|
@ -689,16 +689,16 @@ class CGI
|
||||||
# "cookie" => [cookie1, cookie2],
|
# "cookie" => [cookie1, cookie2],
|
||||||
# "my_header1" => "my_value",
|
# "my_header1" => "my_value",
|
||||||
# "my_header2" => "my_value") { "string" }
|
# "my_header2" => "my_value") { "string" }
|
||||||
#
|
#
|
||||||
# Content-Length is automatically calculated from the size of
|
# Content-Length is automatically calculated from the size of
|
||||||
# the String returned by the content block.
|
# the String returned by the content block.
|
||||||
#
|
#
|
||||||
# If ENV['REQUEST_METHOD'] == "HEAD", then only the header
|
# If ENV['REQUEST_METHOD'] == "HEAD", then only the header
|
||||||
# is outputted (the content block is still required, but it
|
# is outputted (the content block is still required, but it
|
||||||
# is ignored).
|
# is ignored).
|
||||||
#
|
#
|
||||||
# If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then
|
# 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
|
# the content is converted to this charset, and the language is set
|
||||||
# to "ja".
|
# to "ja".
|
||||||
def out(options = "text/html") # :yield:
|
def out(options = "text/html") # :yield:
|
||||||
|
|
||||||
|
@ -755,16 +755,16 @@ class CGI
|
||||||
# 'expires' => Time.now, # optional
|
# 'expires' => Time.now, # optional
|
||||||
# 'secure' => true # optional
|
# 'secure' => true # optional
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
# cgi.out("cookie" => [cookie1, cookie2]) { "string" }
|
# cgi.out("cookie" => [cookie1, cookie2]) { "string" }
|
||||||
#
|
#
|
||||||
# name = cookie1.name
|
# name = cookie1.name
|
||||||
# values = cookie1.value
|
# values = cookie1.value
|
||||||
# path = cookie1.path
|
# path = cookie1.path
|
||||||
# domain = cookie1.domain
|
# domain = cookie1.domain
|
||||||
# expires = cookie1.expires
|
# expires = cookie1.expires
|
||||||
# secure = cookie1.secure
|
# secure = cookie1.secure
|
||||||
#
|
#
|
||||||
# cookie1.name = 'name'
|
# cookie1.name = 'name'
|
||||||
# cookie1.value = ['value1', 'value2', ...]
|
# cookie1.value = ['value1', 'value2', ...]
|
||||||
# cookie1.path = 'path'
|
# cookie1.path = 'path'
|
||||||
|
@ -787,7 +787,7 @@ class CGI
|
||||||
# domain:: the domain for which this cookie applies.
|
# domain:: the domain for which this cookie applies.
|
||||||
# expires:: the time at which this cookie expires, as a +Time+ object.
|
# expires:: the time at which this cookie expires, as a +Time+ object.
|
||||||
# secure:: whether this cookie is a secure cookie or not (default to
|
# secure:: whether this cookie is a secure cookie or not (default to
|
||||||
# false). Secure cookies are only transmitted to HTTPS
|
# false). Secure cookies are only transmitted to HTTPS
|
||||||
# servers.
|
# servers.
|
||||||
#
|
#
|
||||||
# These keywords correspond to attributes of the cookie object.
|
# These keywords correspond to attributes of the cookie object.
|
||||||
|
@ -914,7 +914,7 @@ class CGI
|
||||||
|
|
||||||
# Mixin module. It provides the follow functionality groups:
|
# Mixin module. It provides the follow functionality groups:
|
||||||
#
|
#
|
||||||
# 1. Access to CGI environment variables as methods. See
|
# 1. Access to CGI environment variables as methods. See
|
||||||
# documentation to the CGI class for a list of these variables.
|
# documentation to the CGI class for a list of these variables.
|
||||||
#
|
#
|
||||||
# 2. Access to cookies, including the cookies attribute.
|
# 2. Access to cookies, including the cookies attribute.
|
||||||
|
@ -1050,7 +1050,7 @@ class CGI
|
||||||
(not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
|
(not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
|
||||||
filename = CGI::unescape(filename)
|
filename = CGI::unescape(filename)
|
||||||
end
|
end
|
||||||
|
|
||||||
/Content-Type: ([^\s]*)/ni.match(head)
|
/Content-Type: ([^\s]*)/ni.match(head)
|
||||||
content_type = ($1 or "")
|
content_type = ($1 or "")
|
||||||
|
|
||||||
|
@ -1169,7 +1169,7 @@ class CGI
|
||||||
|
|
||||||
# Get the value for the parameter with a given key.
|
# Get the value for the parameter with a given key.
|
||||||
#
|
#
|
||||||
# If the parameter has multiple values, only the first will be
|
# If the parameter has multiple values, only the first will be
|
||||||
# retrieved; use #params() to get the array of values.
|
# retrieved; use #params() to get the array of values.
|
||||||
def [](key)
|
def [](key)
|
||||||
params = @params[key]
|
params = @params[key]
|
||||||
|
@ -1216,7 +1216,7 @@ class CGI
|
||||||
# # <BODY>
|
# # <BODY>
|
||||||
# # </BODY>
|
# # </BODY>
|
||||||
# # </HTML>
|
# # </HTML>
|
||||||
#
|
#
|
||||||
# print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
|
# print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
|
||||||
# # <HTML>
|
# # <HTML>
|
||||||
# # <BODY>
|
# # <BODY>
|
||||||
|
@ -1301,7 +1301,7 @@ class CGI
|
||||||
# Modules Http3, Http4, etc., contain more basic HTML-generation methods
|
# Modules Http3, Http4, etc., contain more basic HTML-generation methods
|
||||||
# (:title, :center, etc.).
|
# (:title, :center, etc.).
|
||||||
#
|
#
|
||||||
# See class CGI for a detailed example.
|
# See class CGI for a detailed example.
|
||||||
#
|
#
|
||||||
module HtmlExtension
|
module HtmlExtension
|
||||||
|
|
||||||
|
@ -1334,7 +1334,7 @@ class CGI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generate a Document Base URI element as a String.
|
# Generate a Document Base URI element as a String.
|
||||||
#
|
#
|
||||||
# +href+ can either by a string, giving the base URL for the HREF
|
# +href+ can either by a string, giving the base URL for the HREF
|
||||||
# attribute, or it can be a has of the element's attributes.
|
# attribute, or it can be a has of the element's attributes.
|
||||||
|
@ -1414,10 +1414,10 @@ class CGI
|
||||||
#
|
#
|
||||||
# checkbox("name")
|
# checkbox("name")
|
||||||
# # = checkbox("NAME" => "name")
|
# # = checkbox("NAME" => "name")
|
||||||
#
|
#
|
||||||
# checkbox("name", "value")
|
# checkbox("name", "value")
|
||||||
# # = checkbox("NAME" => "name", "VALUE" => "value")
|
# # = checkbox("NAME" => "name", "VALUE" => "value")
|
||||||
#
|
#
|
||||||
# checkbox("name", "value", true)
|
# checkbox("name", "value", true)
|
||||||
# # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
|
# # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
|
||||||
def checkbox(name = "", value = nil, checked = nil)
|
def checkbox(name = "", value = nil, checked = nil)
|
||||||
|
@ -1455,23 +1455,23 @@ class CGI
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
|
||||||
#
|
#
|
||||||
# checkbox_group("name", ["foo"], ["bar", true], "baz")
|
# checkbox_group("name", ["foo"], ["bar", true], "baz")
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
|
||||||
# # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
|
# # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
|
||||||
#
|
#
|
||||||
# checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
|
# checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
|
||||||
# # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
|
# # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
|
||||||
# # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
|
# # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
|
||||||
#
|
#
|
||||||
# checkbox_group("NAME" => "name",
|
# checkbox_group("NAME" => "name",
|
||||||
# "VALUES" => ["foo", "bar", "baz"])
|
# "VALUES" => ["foo", "bar", "baz"])
|
||||||
#
|
#
|
||||||
# checkbox_group("NAME" => "name",
|
# checkbox_group("NAME" => "name",
|
||||||
# "VALUES" => [["foo"], ["bar", true], "baz"])
|
# "VALUES" => [["foo"], ["bar", true], "baz"])
|
||||||
#
|
#
|
||||||
# checkbox_group("NAME" => "name",
|
# checkbox_group("NAME" => "name",
|
||||||
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
|
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
|
||||||
def checkbox_group(name = "", *values)
|
def checkbox_group(name = "", *values)
|
||||||
|
@ -1507,13 +1507,13 @@ class CGI
|
||||||
#
|
#
|
||||||
# file_field("name")
|
# file_field("name")
|
||||||
# # <INPUT TYPE="file" NAME="name" SIZE="20">
|
# # <INPUT TYPE="file" NAME="name" SIZE="20">
|
||||||
#
|
#
|
||||||
# file_field("name", 40)
|
# file_field("name", 40)
|
||||||
# # <INPUT TYPE="file" NAME="name" SIZE="40">
|
# # <INPUT TYPE="file" NAME="name" SIZE="40">
|
||||||
#
|
#
|
||||||
# file_field("name", 40, 100)
|
# file_field("name", 40, 100)
|
||||||
# # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
|
# # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
|
||||||
#
|
#
|
||||||
# file_field("NAME" => "name", "SIZE" => 40)
|
# file_field("NAME" => "name", "SIZE" => 40)
|
||||||
# # <INPUT TYPE="file" NAME="name" SIZE="40">
|
# # <INPUT TYPE="file" NAME="name" SIZE="40">
|
||||||
def file_field(name = "", size = 20, maxlength = nil)
|
def file_field(name = "", size = 20, maxlength = nil)
|
||||||
|
@ -1533,7 +1533,7 @@ class CGI
|
||||||
#
|
#
|
||||||
# +method+ should be either "get" or "post", and defaults to the latter.
|
# +method+ should be either "get" or "post", and defaults to the latter.
|
||||||
# +action+ defaults to the current CGI script name. +enctype+
|
# +action+ defaults to the current CGI script name. +enctype+
|
||||||
# defaults to "application/x-www-form-urlencoded".
|
# defaults to "application/x-www-form-urlencoded".
|
||||||
#
|
#
|
||||||
# Alternatively, the attributes can be specified as a hash.
|
# Alternatively, the attributes can be specified as a hash.
|
||||||
#
|
#
|
||||||
|
@ -1541,19 +1541,19 @@ class CGI
|
||||||
#
|
#
|
||||||
# form{ "string" }
|
# form{ "string" }
|
||||||
# # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
|
# # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
|
||||||
#
|
#
|
||||||
# form("get") { "string" }
|
# form("get") { "string" }
|
||||||
# # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
|
# # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
|
||||||
#
|
#
|
||||||
# form("get", "url") { "string" }
|
# form("get", "url") { "string" }
|
||||||
# # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
|
# # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
|
||||||
#
|
#
|
||||||
# form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
|
# form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
|
||||||
# # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
|
# # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
|
||||||
def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
|
def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
|
||||||
attributes = if method.kind_of?(String)
|
attributes = if method.kind_of?(String)
|
||||||
{ "METHOD" => method, "ACTION" => action,
|
{ "METHOD" => method, "ACTION" => action,
|
||||||
"ENCTYPE" => enctype }
|
"ENCTYPE" => enctype }
|
||||||
else
|
else
|
||||||
unless method.has_key?("METHOD")
|
unless method.has_key?("METHOD")
|
||||||
method["METHOD"] = "post"
|
method["METHOD"] = "post"
|
||||||
|
@ -1585,10 +1585,10 @@ class CGI
|
||||||
#
|
#
|
||||||
# hidden("name")
|
# hidden("name")
|
||||||
# # <INPUT TYPE="hidden" NAME="name">
|
# # <INPUT TYPE="hidden" NAME="name">
|
||||||
#
|
#
|
||||||
# hidden("name", "value")
|
# hidden("name", "value")
|
||||||
# # <INPUT TYPE="hidden" NAME="name" VALUE="value">
|
# # <INPUT TYPE="hidden" NAME="name" VALUE="value">
|
||||||
#
|
#
|
||||||
# hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
|
# hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
|
||||||
# # <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
|
# # <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
|
||||||
def hidden(name = "", value = nil)
|
def hidden(name = "", value = nil)
|
||||||
|
@ -1611,36 +1611,36 @@ class CGI
|
||||||
# should include the entire text of this tag, including angle brackets.
|
# should include the entire text of this tag, including angle brackets.
|
||||||
#
|
#
|
||||||
# The body of the html element is supplied as a block.
|
# The body of the html element is supplied as a block.
|
||||||
#
|
#
|
||||||
# html{ "string" }
|
# html{ "string" }
|
||||||
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
|
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
|
||||||
#
|
#
|
||||||
# html("LANG" => "ja") { "string" }
|
# html("LANG" => "ja") { "string" }
|
||||||
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
|
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
|
||||||
#
|
#
|
||||||
# html("DOCTYPE" => false) { "string" }
|
# html("DOCTYPE" => false) { "string" }
|
||||||
# # <HTML>string</HTML>
|
# # <HTML>string</HTML>
|
||||||
#
|
#
|
||||||
# html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
|
# html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
|
||||||
# # <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
|
# # <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
|
||||||
#
|
#
|
||||||
# html("PRETTY" => " ") { "<BODY></BODY>" }
|
# html("PRETTY" => " ") { "<BODY></BODY>" }
|
||||||
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||||
# # <HTML>
|
# # <HTML>
|
||||||
# # <BODY>
|
# # <BODY>
|
||||||
# # </BODY>
|
# # </BODY>
|
||||||
# # </HTML>
|
# # </HTML>
|
||||||
#
|
#
|
||||||
# html("PRETTY" => "\t") { "<BODY></BODY>" }
|
# html("PRETTY" => "\t") { "<BODY></BODY>" }
|
||||||
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
# # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||||
# # <HTML>
|
# # <HTML>
|
||||||
# # <BODY>
|
# # <BODY>
|
||||||
# # </BODY>
|
# # </BODY>
|
||||||
# # </HTML>
|
# # </HTML>
|
||||||
#
|
#
|
||||||
# html("PRETTY") { "<BODY></BODY>" }
|
# html("PRETTY") { "<BODY></BODY>" }
|
||||||
# # = html("PRETTY" => " ") { "<BODY></BODY>" }
|
# # = html("PRETTY" => " ") { "<BODY></BODY>" }
|
||||||
#
|
#
|
||||||
# html(if $VERBOSE then "PRETTY" end) { "HTML string" }
|
# html(if $VERBOSE then "PRETTY" end) { "HTML string" }
|
||||||
#
|
#
|
||||||
def html(attributes = {}) # :yield:
|
def html(attributes = {}) # :yield:
|
||||||
|
@ -1679,17 +1679,17 @@ class CGI
|
||||||
|
|
||||||
# Generate an Image Button Input element as a string.
|
# Generate an Image Button Input element as a string.
|
||||||
#
|
#
|
||||||
# +src+ is the URL of the image to use for the button. +name+
|
# +src+ is the URL of the image to use for the button. +name+
|
||||||
# is the input name. +alt+ is the alternative text for the image.
|
# is the input name. +alt+ is the alternative text for the image.
|
||||||
#
|
#
|
||||||
# Alternatively, the attributes can be specified as a hash.
|
# Alternatively, the attributes can be specified as a hash.
|
||||||
#
|
#
|
||||||
# image_button("url")
|
# image_button("url")
|
||||||
# # <INPUT TYPE="image" SRC="url">
|
# # <INPUT TYPE="image" SRC="url">
|
||||||
#
|
#
|
||||||
# image_button("url", "name", "string")
|
# image_button("url", "name", "string")
|
||||||
# # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
|
# # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
|
||||||
#
|
#
|
||||||
# image_button("SRC" => "url", "ATL" => "string")
|
# image_button("SRC" => "url", "ATL" => "string")
|
||||||
# # <INPUT TYPE="image" SRC="url" ALT="string">
|
# # <INPUT TYPE="image" SRC="url" ALT="string">
|
||||||
def image_button(src = "", name = nil, alt = nil)
|
def image_button(src = "", name = nil, alt = nil)
|
||||||
|
@ -1715,7 +1715,7 @@ class CGI
|
||||||
#
|
#
|
||||||
# img("src", "alt", 100, 50)
|
# img("src", "alt", 100, 50)
|
||||||
# # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
|
# # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
|
||||||
#
|
#
|
||||||
# img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
|
# img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
|
||||||
# # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
|
# # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
|
||||||
def img(src = "", alt = "", width = nil, height = nil)
|
def img(src = "", alt = "", width = nil, height = nil)
|
||||||
|
@ -1741,15 +1741,15 @@ class CGI
|
||||||
#
|
#
|
||||||
# multipart_form{ "string" }
|
# multipart_form{ "string" }
|
||||||
# # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
|
# # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
|
||||||
#
|
#
|
||||||
# multipart_form("url") { "string" }
|
# multipart_form("url") { "string" }
|
||||||
# # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
|
# # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
|
||||||
def multipart_form(action = nil, enctype = "multipart/form-data")
|
def multipart_form(action = nil, enctype = "multipart/form-data")
|
||||||
attributes = if action == nil
|
attributes = if action == nil
|
||||||
{ "METHOD" => "post", "ENCTYPE" => enctype }
|
{ "METHOD" => "post", "ENCTYPE" => enctype }
|
||||||
elsif action.kind_of?(String)
|
elsif action.kind_of?(String)
|
||||||
{ "METHOD" => "post", "ACTION" => action,
|
{ "METHOD" => "post", "ACTION" => action,
|
||||||
"ENCTYPE" => enctype }
|
"ENCTYPE" => enctype }
|
||||||
else
|
else
|
||||||
unless action.has_key?("METHOD")
|
unless action.has_key?("METHOD")
|
||||||
action["METHOD"] = "post"
|
action["METHOD"] = "post"
|
||||||
|
@ -1777,13 +1777,13 @@ class CGI
|
||||||
#
|
#
|
||||||
# password_field("name")
|
# password_field("name")
|
||||||
# # <INPUT TYPE="password" NAME="name" SIZE="40">
|
# # <INPUT TYPE="password" NAME="name" SIZE="40">
|
||||||
#
|
#
|
||||||
# password_field("name", "value")
|
# password_field("name", "value")
|
||||||
# # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
|
# # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
|
||||||
#
|
#
|
||||||
# password_field("password", "value", 80, 200)
|
# password_field("password", "value", 80, 200)
|
||||||
# # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
|
# # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
|
||||||
#
|
#
|
||||||
# password_field("NAME" => "name", "VALUE" => "value")
|
# password_field("NAME" => "name", "VALUE" => "value")
|
||||||
# # <INPUT TYPE="password" NAME="name" VALUE="value">
|
# # <INPUT TYPE="password" NAME="name" VALUE="value">
|
||||||
def password_field(name = "", value = nil, size = 40, maxlength = nil)
|
def password_field(name = "", value = nil, size = 40, maxlength = nil)
|
||||||
|
@ -1819,21 +1819,21 @@ class CGI
|
||||||
# # <OPTION VALUE="bar">bar</OPTION>
|
# # <OPTION VALUE="bar">bar</OPTION>
|
||||||
# # <OPTION VALUE="baz">baz</OPTION>
|
# # <OPTION VALUE="baz">baz</OPTION>
|
||||||
# # </SELECT>
|
# # </SELECT>
|
||||||
#
|
#
|
||||||
# popup_menu("name", ["foo"], ["bar", true], "baz")
|
# popup_menu("name", ["foo"], ["bar", true], "baz")
|
||||||
# # <SELECT NAME="name">
|
# # <SELECT NAME="name">
|
||||||
# # <OPTION VALUE="foo">foo</OPTION>
|
# # <OPTION VALUE="foo">foo</OPTION>
|
||||||
# # <OPTION VALUE="bar" SELECTED>bar</OPTION>
|
# # <OPTION VALUE="bar" SELECTED>bar</OPTION>
|
||||||
# # <OPTION VALUE="baz">baz</OPTION>
|
# # <OPTION VALUE="baz">baz</OPTION>
|
||||||
# # </SELECT>
|
# # </SELECT>
|
||||||
#
|
#
|
||||||
# popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
|
# popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
|
||||||
# # <SELECT NAME="name">
|
# # <SELECT NAME="name">
|
||||||
# # <OPTION VALUE="1">Foo</OPTION>
|
# # <OPTION VALUE="1">Foo</OPTION>
|
||||||
# # <OPTION SELECTED VALUE="2">Bar</OPTION>
|
# # <OPTION SELECTED VALUE="2">Bar</OPTION>
|
||||||
# # <OPTION VALUE="Baz">Baz</OPTION>
|
# # <OPTION VALUE="Baz">Baz</OPTION>
|
||||||
# # </SELECT>
|
# # </SELECT>
|
||||||
#
|
#
|
||||||
# popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
|
# popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
|
||||||
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
|
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
|
||||||
# # <SELECT NAME="name" MULTIPLE SIZE="2">
|
# # <SELECT NAME="name" MULTIPLE SIZE="2">
|
||||||
|
@ -1884,10 +1884,10 @@ class CGI
|
||||||
#
|
#
|
||||||
# radio_button("name", "value")
|
# radio_button("name", "value")
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="value">
|
# # <INPUT TYPE="radio" NAME="name" VALUE="value">
|
||||||
#
|
#
|
||||||
# radio_button("name", "value", true)
|
# radio_button("name", "value", true)
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
|
# # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
|
||||||
#
|
#
|
||||||
# radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
|
# radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
|
# # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
|
||||||
def radio_button(name = "", value = nil, checked = nil)
|
def radio_button(name = "", value = nil, checked = nil)
|
||||||
|
@ -1905,28 +1905,28 @@ class CGI
|
||||||
#
|
#
|
||||||
# This works the same as #checkbox_group(). However, it is not valid
|
# This works the same as #checkbox_group(). However, it is not valid
|
||||||
# to have more than one radiobutton in a group checked.
|
# to have more than one radiobutton in a group checked.
|
||||||
#
|
#
|
||||||
# radio_group("name", "foo", "bar", "baz")
|
# radio_group("name", "foo", "bar", "baz")
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
|
# # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
|
# # <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
|
# # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
|
||||||
#
|
#
|
||||||
# radio_group("name", ["foo"], ["bar", true], "baz")
|
# radio_group("name", ["foo"], ["bar", true], "baz")
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
|
# # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
|
||||||
# # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
|
# # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
|
# # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
|
||||||
#
|
#
|
||||||
# radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
|
# radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
|
# # <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
|
||||||
# # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
|
# # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
|
||||||
# # <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
|
# # <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
|
||||||
#
|
#
|
||||||
# radio_group("NAME" => "name",
|
# radio_group("NAME" => "name",
|
||||||
# "VALUES" => ["foo", "bar", "baz"])
|
# "VALUES" => ["foo", "bar", "baz"])
|
||||||
#
|
#
|
||||||
# radio_group("NAME" => "name",
|
# radio_group("NAME" => "name",
|
||||||
# "VALUES" => [["foo"], ["bar", true], "baz"])
|
# "VALUES" => [["foo"], ["bar", true], "baz"])
|
||||||
#
|
#
|
||||||
# radio_group("NAME" => "name",
|
# radio_group("NAME" => "name",
|
||||||
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
|
# "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
|
||||||
def radio_group(name = "", *values)
|
def radio_group(name = "", *values)
|
||||||
|
@ -1958,10 +1958,10 @@ class CGI
|
||||||
#
|
#
|
||||||
# reset
|
# reset
|
||||||
# # <INPUT TYPE="reset">
|
# # <INPUT TYPE="reset">
|
||||||
#
|
#
|
||||||
# reset("reset")
|
# reset("reset")
|
||||||
# # <INPUT TYPE="reset" VALUE="reset">
|
# # <INPUT TYPE="reset" VALUE="reset">
|
||||||
#
|
#
|
||||||
# reset("VALUE" => "reset", "ID" => "foo")
|
# reset("VALUE" => "reset", "ID" => "foo")
|
||||||
# # <INPUT TYPE="reset" VALUE="reset" ID="foo">
|
# # <INPUT TYPE="reset" VALUE="reset" ID="foo">
|
||||||
def reset(value = nil, name = nil)
|
def reset(value = nil, name = nil)
|
||||||
|
@ -1985,13 +1985,13 @@ class CGI
|
||||||
#
|
#
|
||||||
# submit
|
# submit
|
||||||
# # <INPUT TYPE="submit">
|
# # <INPUT TYPE="submit">
|
||||||
#
|
#
|
||||||
# submit("ok")
|
# submit("ok")
|
||||||
# # <INPUT TYPE="submit" VALUE="ok">
|
# # <INPUT TYPE="submit" VALUE="ok">
|
||||||
#
|
#
|
||||||
# submit("ok", "button1")
|
# submit("ok", "button1")
|
||||||
# # <INPUT TYPE="submit" VALUE="ok" NAME="button1">
|
# # <INPUT TYPE="submit" VALUE="ok" NAME="button1">
|
||||||
#
|
#
|
||||||
# submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
|
# submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
|
||||||
# # <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
|
# # <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
|
||||||
def submit(value = nil, name = nil)
|
def submit(value = nil, name = nil)
|
||||||
|
@ -2014,16 +2014,16 @@ class CGI
|
||||||
#
|
#
|
||||||
# text_field("name")
|
# text_field("name")
|
||||||
# # <INPUT TYPE="text" NAME="name" SIZE="40">
|
# # <INPUT TYPE="text" NAME="name" SIZE="40">
|
||||||
#
|
#
|
||||||
# text_field("name", "value")
|
# text_field("name", "value")
|
||||||
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
|
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
|
||||||
#
|
#
|
||||||
# text_field("name", "value", 80)
|
# text_field("name", "value", 80)
|
||||||
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
|
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
|
||||||
#
|
#
|
||||||
# text_field("name", "value", 80, 200)
|
# text_field("name", "value", 80, 200)
|
||||||
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
|
# # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
|
||||||
#
|
#
|
||||||
# text_field("NAME" => "name", "VALUE" => "value")
|
# text_field("NAME" => "name", "VALUE" => "value")
|
||||||
# # <INPUT TYPE="text" NAME="name" VALUE="value">
|
# # <INPUT TYPE="text" NAME="name" VALUE="value">
|
||||||
def text_field(name = "", value = nil, size = 40, maxlength = nil)
|
def text_field(name = "", value = nil, size = 40, maxlength = nil)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#
|
#
|
||||||
# This file provides the +CGI::Session+ class, which provides session
|
# This file provides the +CGI::Session+ class, which provides session
|
||||||
# support for CGI scripts. A session is a sequence of HTTP requests
|
# support for CGI scripts. A session is a sequence of HTTP requests
|
||||||
# and responses linked together and associated with a single client.
|
# and responses linked together and associated with a single client.
|
||||||
# Information associated with the session is stored
|
# Information associated with the session is stored
|
||||||
# on the server between requests. A session id is passed between client
|
# on the server between requests. A session id is passed between client
|
||||||
# and server with every request and response, transparently
|
# and server with every request and response, transparently
|
||||||
|
@ -28,7 +28,7 @@ require 'tmpdir'
|
||||||
|
|
||||||
class CGI
|
class CGI
|
||||||
|
|
||||||
# Class representing an HTTP session. See documentation for the file
|
# Class representing an HTTP session. See documentation for the file
|
||||||
# cgi/session.rb for an introduction to HTTP sessions.
|
# cgi/session.rb for an introduction to HTTP sessions.
|
||||||
#
|
#
|
||||||
# == Lifecycle
|
# == Lifecycle
|
||||||
|
@ -47,7 +47,7 @@ class CGI
|
||||||
# == Setting and retrieving session data.
|
# == Setting and retrieving session data.
|
||||||
#
|
#
|
||||||
# The Session class associates data with a session as key-value pairs.
|
# The Session class associates data with a session as key-value pairs.
|
||||||
# This data can be set and retrieved by indexing the Session instance
|
# This data can be set and retrieved by indexing the Session instance
|
||||||
# using '[]', much the same as hashes (although other hash methods
|
# using '[]', much the same as hashes (although other hash methods
|
||||||
# are not supported).
|
# are not supported).
|
||||||
#
|
#
|
||||||
|
@ -60,21 +60,21 @@ class CGI
|
||||||
#
|
#
|
||||||
# == Storing session state
|
# == Storing session state
|
||||||
#
|
#
|
||||||
# The caller can specify what form of storage to use for the session's
|
# 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
|
# data with the +database_manager+ option to CGI::Session::new. The
|
||||||
# following storage classes are provided as part of the standard library:
|
# following storage classes are provided as part of the standard library:
|
||||||
#
|
#
|
||||||
# CGI::Session::FileStore:: stores data as plain text in a flat file. Only
|
# CGI::Session::FileStore:: stores data as plain text in a flat file. Only
|
||||||
# works with String data. This is the default
|
# works with String data. This is the default
|
||||||
# storage type.
|
# storage type.
|
||||||
# CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
|
# CGI::Session::MemoryStore:: stores data in an in-memory hash. The data
|
||||||
# only persists for as long as the current ruby
|
# only persists for as long as the current ruby
|
||||||
# interpreter instance does.
|
# interpreter instance does.
|
||||||
# CGI::Session::PStore:: stores data in Marshalled format. Provided by
|
# CGI::Session::PStore:: stores data in Marshalled format. Provided by
|
||||||
# cgi/session/pstore.rb. Supports data of any type,
|
# cgi/session/pstore.rb. Supports data of any type,
|
||||||
# and provides file-locking and transaction support.
|
# and provides file-locking and transaction support.
|
||||||
#
|
#
|
||||||
# Custom storage types can also be created by defining a class with
|
# Custom storage types can also be created by defining a class with
|
||||||
# the following methods:
|
# the following methods:
|
||||||
#
|
#
|
||||||
# new(session, options)
|
# new(session, options)
|
||||||
|
@ -99,14 +99,14 @@ class CGI
|
||||||
# The simplest way to do this is via cookies. The CGI::Session class
|
# The simplest way to do this is via cookies. The CGI::Session class
|
||||||
# provides transparent support for session id communication via cookies
|
# provides transparent support for session id communication via cookies
|
||||||
# if the client has cookies enabled.
|
# if the client has cookies enabled.
|
||||||
#
|
#
|
||||||
# If the client has cookies disabled, the session id must be included
|
# 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
|
# 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
|
# CGI::Session class in conjunction with the CGI class will transparently
|
||||||
# add the session id as a hidden input field to all forms generated
|
# 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
|
# using the CGI#form() HTML generation method. No built-in support is
|
||||||
# provided for other mechanisms, such as URL re-writing. The caller is
|
# provided for other mechanisms, such as URL re-writing. The caller is
|
||||||
# responsible for extracting the session id from the session_id
|
# responsible for extracting the session id from the session_id
|
||||||
# attribute and manually encoding it in URLs and adding it as a hidden
|
# attribute and manually encoding it in URLs and adding it as a hidden
|
||||||
# input to HTML forms created by other mechanisms. Also, session expiry
|
# input to HTML forms created by other mechanisms. Also, session expiry
|
||||||
# is not automatically handled.
|
# is not automatically handled.
|
||||||
|
@ -124,10 +124,10 @@ class CGI
|
||||||
# session = CGI::Session.new(cgi,
|
# session = CGI::Session.new(cgi,
|
||||||
# 'database_manager' => CGI::Session::PStore, # use PStore
|
# 'database_manager' => CGI::Session::PStore, # use PStore
|
||||||
# 'session_key' => '_rb_sess_id', # custom session key
|
# 'session_key' => '_rb_sess_id', # custom session key
|
||||||
# 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
|
# 'session_expires' => Time.now + 30 * 60, # 30 minute timeout
|
||||||
# 'prefix' => 'pstore_sid_') # PStore option
|
# 'prefix' => 'pstore_sid_') # PStore option
|
||||||
# if cgi.has_key?('user_name') and cgi['user_name'] != ''
|
# if cgi.has_key?('user_name') and cgi['user_name'] != ''
|
||||||
# # coerce to String: cgi[] returns the
|
# # coerce to String: cgi[] returns the
|
||||||
# # string-like CGI::QueryExtension::Value
|
# # string-like CGI::QueryExtension::Value
|
||||||
# session['user_name'] = cgi['user_name'].to_s
|
# session['user_name'] = cgi['user_name'].to_s
|
||||||
# elsif !session['user_name']
|
# elsif !session['user_name']
|
||||||
|
@ -143,11 +143,11 @@ class CGI
|
||||||
# cgi = CGI.new("html4")
|
# cgi = CGI.new("html4")
|
||||||
#
|
#
|
||||||
# # We make sure to delete an old session if one exists,
|
# # We make sure to delete an old session if one exists,
|
||||||
# # not just to free resources, but to prevent the session
|
# # not just to free resources, but to prevent the session
|
||||||
# # from being maliciously hijacked later on.
|
# # from being maliciously hijacked later on.
|
||||||
# begin
|
# begin
|
||||||
# session = CGI::Session.new(cgi, 'new_session' => false)
|
# session = CGI::Session.new(cgi, 'new_session' => false)
|
||||||
# session.delete
|
# session.delete
|
||||||
# rescue ArgumentError # if no old session
|
# rescue ArgumentError # if no old session
|
||||||
# end
|
# end
|
||||||
# session = CGI::Session.new(cgi, 'new_session' => true)
|
# session = CGI::Session.new(cgi, 'new_session' => true)
|
||||||
|
@ -172,7 +172,7 @@ class CGI
|
||||||
# The session id is an MD5 hash based upon the time,
|
# The session id is an MD5 hash based upon the time,
|
||||||
# a random number, and a constant string. This routine
|
# a random number, and a constant string. This routine
|
||||||
# is used internally for automatically generated
|
# is used internally for automatically generated
|
||||||
# session ids.
|
# session ids.
|
||||||
def create_new_id
|
def create_new_id
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
begin
|
begin
|
||||||
|
@ -205,7 +205,7 @@ class CGI
|
||||||
# it is retrieved from the +session_key+ parameter
|
# it is retrieved from the +session_key+ parameter
|
||||||
# of the request, or automatically generated for
|
# of the request, or automatically generated for
|
||||||
# a new session.
|
# a new session.
|
||||||
# new_session:: if true, force creation of a new session. If not set,
|
# new_session:: if true, force creation of a new session. If not set,
|
||||||
# a new session is only created if none currently
|
# a new session is only created if none currently
|
||||||
# exists. If false, a new session is never created,
|
# exists. If false, a new session is never created,
|
||||||
# and if none currently exists and the +session_id+
|
# and if none currently exists and the +session_id+
|
||||||
|
@ -220,7 +220,7 @@ class CGI
|
||||||
# The following options are also recognised, but only apply if the
|
# The following options are also recognised, but only apply if the
|
||||||
# session id is stored in a cookie.
|
# session id is stored in a cookie.
|
||||||
#
|
#
|
||||||
# session_expires:: the time the current session expires, as a
|
# session_expires:: the time the current session expires, as a
|
||||||
# +Time+ object. If not set, the session will terminate
|
# +Time+ object. If not set, the session will terminate
|
||||||
# when the user's browser is closed.
|
# when the user's browser is closed.
|
||||||
# session_domain:: the hostname domain for which this session is valid.
|
# session_domain:: the hostname domain for which this session is valid.
|
||||||
|
@ -232,10 +232,10 @@ class CGI
|
||||||
# +option+ is also passed on to the session storage class initializer; see
|
# +option+ is also passed on to the session storage class initializer; see
|
||||||
# the documentation for each session storage class for the options
|
# the documentation for each session storage class for the options
|
||||||
# they support.
|
# they support.
|
||||||
#
|
#
|
||||||
# The retrieved or created session is automatically added to +request+
|
# The retrieved or created session is automatically added to +request+
|
||||||
# as a cookie, and also to its +output_hidden+ table, which is used
|
# as a cookie, and also to its +output_hidden+ table, which is used
|
||||||
# to add hidden input elements to forms.
|
# to add hidden input elements to forms.
|
||||||
#
|
#
|
||||||
# *WARNING* the +output_hidden+
|
# *WARNING* the +output_hidden+
|
||||||
# fields are surrounded by a <fieldset> tag in HTML 4 generation, which
|
# fields are surrounded by a <fieldset> tag in HTML 4 generation, which
|
||||||
|
@ -322,11 +322,11 @@ class CGI
|
||||||
|
|
||||||
# Store session data on the server. For some session storage types,
|
# Store session data on the server. For some session storage types,
|
||||||
# this is a no-op.
|
# this is a no-op.
|
||||||
def update
|
def update
|
||||||
@dbman.update
|
@dbman.update
|
||||||
end
|
end
|
||||||
|
|
||||||
# Store session data on the server and close the session storage.
|
# Store session data on the server and close the session storage.
|
||||||
# For some session storage types, this is a no-op.
|
# For some session storage types, this is a no-op.
|
||||||
def close
|
def close
|
||||||
@dbman.close
|
@dbman.close
|
||||||
|
@ -358,7 +358,7 @@ class CGI
|
||||||
# created. The session id must only contain alphanumeric
|
# created. The session id must only contain alphanumeric
|
||||||
# characters; automatically generated session ids observe
|
# characters; automatically generated session ids observe
|
||||||
# this requirement.
|
# this requirement.
|
||||||
#
|
#
|
||||||
# +option+ is a hash of options for the initializer. The
|
# +option+ is a hash of options for the initializer. The
|
||||||
# following options are recognised:
|
# following options are recognised:
|
||||||
#
|
#
|
||||||
|
@ -450,7 +450,7 @@ class CGI
|
||||||
# In-memory session storage class.
|
# In-memory session storage class.
|
||||||
#
|
#
|
||||||
# Implements session storage as a global in-memory hash. Session
|
# Implements session storage as a global in-memory hash. Session
|
||||||
# data will only persist for as long as the ruby interpreter
|
# data will only persist for as long as the ruby interpreter
|
||||||
# instance does.
|
# instance does.
|
||||||
class MemoryStore
|
class MemoryStore
|
||||||
GLOBAL_HASH_TABLE = {} #:nodoc:
|
GLOBAL_HASH_TABLE = {} #:nodoc:
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# cgi/session/pstore.rb - persistent storage of marshalled session data
|
# cgi/session/pstore.rb - persistent storage of marshalled session data
|
||||||
#
|
#
|
||||||
# Documentation: William Webber (william@williamwebber.com)
|
# Documentation: William Webber (william@williamwebber.com)
|
||||||
#
|
#
|
||||||
# == Overview
|
# == Overview
|
||||||
#
|
#
|
||||||
# This file provides the CGI::Session::PStore class, which builds
|
# This file provides the CGI::Session::PStore class, which builds
|
||||||
|
@ -29,7 +29,7 @@ class CGI
|
||||||
# created. The session id must only contain alphanumeric
|
# created. The session id must only contain alphanumeric
|
||||||
# characters; automatically generated session ids observe
|
# characters; automatically generated session ids observe
|
||||||
# this requirement.
|
# this requirement.
|
||||||
#
|
#
|
||||||
# +option+ is a hash of options for the initializer. The
|
# +option+ is a hash of options for the initializer. The
|
||||||
# following options are recognised:
|
# following options are recognised:
|
||||||
#
|
#
|
||||||
|
@ -77,7 +77,7 @@ class CGI
|
||||||
end
|
end
|
||||||
|
|
||||||
# Save session state to the session's PStore file.
|
# Save session state to the session's PStore file.
|
||||||
def update
|
def update
|
||||||
@p.transaction do
|
@p.transaction do
|
||||||
@p['hash'] = @hash
|
@p['hash'] = @hash
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# complex.rb -
|
# complex.rb -
|
||||||
# $Release Version: 0.5 $
|
# $Release Version: 0.5 $
|
||||||
# $Revision: 1.3 $
|
# $Revision: 1.3 $
|
||||||
# $Date: 1998/07/08 10:05:28 $
|
# $Date: 1998/07/08 10:05:28 $
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
# Complex numbers can be created in the following manner:
|
# Complex numbers can be created in the following manner:
|
||||||
# - <tt>Complex(a, b)</tt>
|
# - <tt>Complex(a, b)</tt>
|
||||||
# - <tt>Complex.polar(radius, theta)</tt>
|
# - <tt>Complex.polar(radius, theta)</tt>
|
||||||
#
|
#
|
||||||
# Additionally, note the following:
|
# Additionally, note the following:
|
||||||
# - <tt>Complex::I</tt> (the mathematical constant <i>i</i>)
|
# - <tt>Complex::I</tt> (the mathematical constant <i>i</i>)
|
||||||
# - <tt>Numeric#im</tt> (e.g. <tt>5.im -> 0+5i</tt>)
|
# - <tt>Numeric#im</tt> (e.g. <tt>5.im -> 0+5i</tt>)
|
||||||
|
@ -38,14 +38,14 @@ class Numeric
|
||||||
def im
|
def im
|
||||||
Complex(0, self)
|
Complex(0, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# The real part of a complex number, i.e. <i>self</i>.
|
# The real part of a complex number, i.e. <i>self</i>.
|
||||||
#
|
#
|
||||||
def real
|
def real
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# The imaginary part of a complex number, i.e. 0.
|
# The imaginary part of a complex number, i.e. 0.
|
||||||
#
|
#
|
||||||
|
@ -53,7 +53,7 @@ class Numeric
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
alias imag image
|
alias imag image
|
||||||
|
|
||||||
#
|
#
|
||||||
# See Complex#arg.
|
# See Complex#arg.
|
||||||
#
|
#
|
||||||
|
@ -61,14 +61,14 @@ class Numeric
|
||||||
Math.atan2!(0, self)
|
Math.atan2!(0, self)
|
||||||
end
|
end
|
||||||
alias angle arg
|
alias angle arg
|
||||||
|
|
||||||
#
|
#
|
||||||
# See Complex#polar.
|
# See Complex#polar.
|
||||||
#
|
#
|
||||||
def polar
|
def polar
|
||||||
return abs, arg
|
return abs, arg
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# See Complex#conjugate (short answer: returns <i>self</i>).
|
# See Complex#conjugate (short answer: returns <i>self</i>).
|
||||||
#
|
#
|
||||||
|
@ -145,7 +145,7 @@ class Complex < Numeric
|
||||||
x + y
|
x + y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Subtraction with real or complex number.
|
# Subtraction with real or complex number.
|
||||||
#
|
#
|
||||||
|
@ -161,7 +161,7 @@ class Complex < Numeric
|
||||||
x - y
|
x - y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Multiplication with real or complex number.
|
# Multiplication with real or complex number.
|
||||||
#
|
#
|
||||||
|
@ -177,7 +177,7 @@ class Complex < Numeric
|
||||||
x * y
|
x * y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Division by real or complex number.
|
# Division by real or complex number.
|
||||||
#
|
#
|
||||||
|
@ -191,7 +191,7 @@ class Complex < Numeric
|
||||||
x/y
|
x/y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def quo(other)
|
def quo(other)
|
||||||
Complex(@real.quo(1), @image.quo(1)) / other
|
Complex(@real.quo(1), @image.quo(1)) / other
|
||||||
end
|
end
|
||||||
|
@ -240,7 +240,7 @@ class Complex < Numeric
|
||||||
x**y
|
x**y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Remainder after division by a real or complex number.
|
# Remainder after division by a real or complex number.
|
||||||
#
|
#
|
||||||
|
@ -254,7 +254,7 @@ class Complex < Numeric
|
||||||
x % y
|
x % y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#--
|
#--
|
||||||
# def divmod(other)
|
# def divmod(other)
|
||||||
# if other.kind_of?(Complex)
|
# if other.kind_of?(Complex)
|
||||||
|
@ -269,7 +269,7 @@ class Complex < Numeric
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#++
|
#++
|
||||||
|
|
||||||
#
|
#
|
||||||
# Absolute value (aka modulus): distance from the zero point on the complex
|
# Absolute value (aka modulus): distance from the zero point on the complex
|
||||||
# plane.
|
# plane.
|
||||||
|
@ -277,14 +277,14 @@ class Complex < Numeric
|
||||||
def abs
|
def abs
|
||||||
Math.hypot(@real, @image)
|
Math.hypot(@real, @image)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Square of the absolute value.
|
# Square of the absolute value.
|
||||||
#
|
#
|
||||||
def abs2
|
def abs2
|
||||||
@real*@real + @image*@image
|
@real*@real + @image*@image
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Argument (angle from (1,0) on the complex plane).
|
# Argument (angle from (1,0) on the complex plane).
|
||||||
#
|
#
|
||||||
|
@ -292,14 +292,14 @@ class Complex < Numeric
|
||||||
Math.atan2!(@image, @real)
|
Math.atan2!(@image, @real)
|
||||||
end
|
end
|
||||||
alias angle arg
|
alias angle arg
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns the absolute value _and_ the argument.
|
# Returns the absolute value _and_ the argument.
|
||||||
#
|
#
|
||||||
def polar
|
def polar
|
||||||
return abs, arg
|
return abs, arg
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Complex conjugate (<tt>z + z.conjugate = 2 * z.real</tt>).
|
# Complex conjugate (<tt>z + z.conjugate = 2 * z.real</tt>).
|
||||||
#
|
#
|
||||||
|
@ -307,14 +307,14 @@ class Complex < Numeric
|
||||||
Complex(@real, -@image)
|
Complex(@real, -@image)
|
||||||
end
|
end
|
||||||
alias conj conjugate
|
alias conj conjugate
|
||||||
|
|
||||||
#
|
#
|
||||||
# Compares the absolute values of the two numbers.
|
# Compares the absolute values of the two numbers.
|
||||||
#
|
#
|
||||||
def <=> (other)
|
def <=> (other)
|
||||||
self.abs <=> other.abs
|
self.abs <=> other.abs
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Test for numerical equality (<tt>a == a + 0<i>i</i></tt>).
|
# Test for numerical equality (<tt>a == a + 0<i>i</i></tt>).
|
||||||
#
|
#
|
||||||
|
@ -345,7 +345,7 @@ class Complex < Numeric
|
||||||
def denominator
|
def denominator
|
||||||
@real.denominator.lcm(@image.denominator)
|
@real.denominator.lcm(@image.denominator)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# FIXME
|
# FIXME
|
||||||
#
|
#
|
||||||
|
@ -354,7 +354,7 @@ class Complex < Numeric
|
||||||
Complex(@real.numerator*(cd/@real.denominator),
|
Complex(@real.numerator*(cd/@real.denominator),
|
||||||
@image.numerator*(cd/@image.denominator))
|
@image.numerator*(cd/@image.denominator))
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Standard string representation of the complex number.
|
# Standard string representation of the complex number.
|
||||||
#
|
#
|
||||||
|
@ -381,14 +381,14 @@ class Complex < Numeric
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns a hash code for the complex number.
|
# Returns a hash code for the complex number.
|
||||||
#
|
#
|
||||||
def hash
|
def hash
|
||||||
@real.hash ^ @image.hash
|
@real.hash ^ @image.hash
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns "<tt>Complex(<i>real</i>, <i>image</i>)</tt>".
|
# Returns "<tt>Complex(<i>real</i>, <i>image</i>)</tt>".
|
||||||
#
|
#
|
||||||
|
@ -396,19 +396,19 @@ class Complex < Numeric
|
||||||
sprintf("Complex(%s, %s)", @real.inspect, @image.inspect)
|
sprintf("Complex(%s, %s)", @real.inspect, @image.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# +I+ is the imaginary number. It exists at point (0,1) on the complex plane.
|
# +I+ is the imaginary number. It exists at point (0,1) on the complex plane.
|
||||||
#
|
#
|
||||||
I = Complex(0,1)
|
I = Complex(0,1)
|
||||||
|
|
||||||
# The real part of a complex number.
|
# The real part of a complex number.
|
||||||
attr :real
|
attr :real
|
||||||
|
|
||||||
# The imaginary part of a complex number.
|
# The imaginary part of a complex number.
|
||||||
attr :image
|
attr :image
|
||||||
alias imag image
|
alias imag image
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Integer
|
class Integer
|
||||||
|
@ -457,7 +457,7 @@ module Math
|
||||||
alias atan2! atan2
|
alias atan2! atan2
|
||||||
alias acosh! acosh
|
alias acosh! acosh
|
||||||
alias asinh! asinh
|
alias asinh! asinh
|
||||||
alias atanh! atanh
|
alias atanh! atanh
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def sqrt(z)
|
def sqrt(z)
|
||||||
|
@ -477,7 +477,7 @@ module Math
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def exp(z)
|
def exp(z)
|
||||||
if Complex.generic?(z)
|
if Complex.generic?(z)
|
||||||
|
@ -486,7 +486,7 @@ module Math
|
||||||
Complex(exp!(z.real) * cos!(z.image), exp!(z.real) * sin!(z.image))
|
Complex(exp!(z.real) * cos!(z.image), exp!(z.real) * sin!(z.image))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def cos(z)
|
def cos(z)
|
||||||
if Complex.generic?(z)
|
if Complex.generic?(z)
|
||||||
|
@ -496,7 +496,7 @@ module Math
|
||||||
-sin!(z.real)*sinh!(z.image))
|
-sin!(z.real)*sinh!(z.image))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def sin(z)
|
def sin(z)
|
||||||
if Complex.generic?(z)
|
if Complex.generic?(z)
|
||||||
|
@ -506,7 +506,7 @@ module Math
|
||||||
cos!(z.real)*sinh!(z.image))
|
cos!(z.real)*sinh!(z.image))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def tan(z)
|
def tan(z)
|
||||||
if Complex.generic?(z)
|
if Complex.generic?(z)
|
||||||
|
@ -539,7 +539,7 @@ module Math
|
||||||
sinh(z)/cosh(z)
|
sinh(z)/cosh(z)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def log(z)
|
def log(z)
|
||||||
if Complex.generic?(z) and z >= 0
|
if Complex.generic?(z) and z >= 0
|
||||||
|
@ -549,7 +549,7 @@ module Math
|
||||||
Complex(log!(r.abs), theta)
|
Complex(log!(r.abs), theta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Redefined to handle a Complex argument.
|
# Redefined to handle a Complex argument.
|
||||||
def log10(z)
|
def log10(z)
|
||||||
if Complex.generic?(z)
|
if Complex.generic?(z)
|
||||||
|
@ -649,7 +649,7 @@ module Math
|
||||||
module_function :asinh
|
module_function :asinh
|
||||||
module_function :atanh!
|
module_function :atanh!
|
||||||
module_function :atanh
|
module_function :atanh
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Documentation comments:
|
# Documentation comments:
|
||||||
|
|
50
lib/csv.rb
50
lib/csv.rb
|
@ -1,13 +1,13 @@
|
||||||
# CSV -- module for generating/parsing CSV data.
|
# CSV -- module for generating/parsing CSV data.
|
||||||
# Copyright (C) 2000-2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>.
|
# Copyright (C) 2000-2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>.
|
||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
|
||||||
# redistribute it and/or modify it under the same terms of Ruby's license;
|
# redistribute it and/or modify it under the same terms of Ruby's license;
|
||||||
# either the dual license version in 2003, or any later version.
|
# either the dual license version in 2003, or any later version.
|
||||||
|
|
||||||
|
|
||||||
class CSV
|
class CSV
|
||||||
class IllegalFormatError < RuntimeError; end
|
class IllegalFormatError < RuntimeError; end
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class CSV
|
||||||
def CSV.read(path, length = nil, offset = nil)
|
def CSV.read(path, length = nil, offset = nil)
|
||||||
CSV.parse(IO.read(path, length, offset))
|
CSV.parse(IO.read(path, length, offset))
|
||||||
end
|
end
|
||||||
|
|
||||||
def CSV.readlines(path, rs = nil)
|
def CSV.readlines(path, rs = nil)
|
||||||
reader = open_reader(path, 'r', ',', rs)
|
reader = open_reader(path, 'r', ',', rs)
|
||||||
begin
|
begin
|
||||||
|
@ -181,7 +181,7 @@ class CSV
|
||||||
end
|
end
|
||||||
result_str
|
result_str
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse a line from string. Consider using CSV.parse_line instead.
|
# Parse a line from string. Consider using CSV.parse_line instead.
|
||||||
# To parse lines in CSV string, see EXAMPLE below.
|
# To parse lines in CSV string, see EXAMPLE below.
|
||||||
#
|
#
|
||||||
|
@ -239,7 +239,7 @@ class CSV
|
||||||
end
|
end
|
||||||
return parsed_cells, idx
|
return parsed_cells, idx
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert a line from cells data to string. Consider using CSV.generate_line
|
# Convert a line from cells data to string. Consider using CSV.generate_line
|
||||||
# instead. To generate multi-row CSV string, see EXAMPLE below.
|
# instead. To generate multi-row CSV string, see EXAMPLE below.
|
||||||
#
|
#
|
||||||
|
@ -299,7 +299,7 @@ class CSV
|
||||||
end
|
end
|
||||||
parsed_cells
|
parsed_cells
|
||||||
end
|
end
|
||||||
|
|
||||||
# Private class methods.
|
# Private class methods.
|
||||||
class << self
|
class << self
|
||||||
private
|
private
|
||||||
|
@ -334,7 +334,7 @@ class CSV
|
||||||
end
|
end
|
||||||
nil
|
nil
|
||||||
else
|
else
|
||||||
writer = CSV::Writer.create(file, fs, rs)
|
writer = CSV::Writer.create(file, fs, rs)
|
||||||
writer.close_on_terminate
|
writer.close_on_terminate
|
||||||
writer
|
writer
|
||||||
end
|
end
|
||||||
|
@ -480,7 +480,7 @@ class CSV
|
||||||
last_idx = idx
|
last_idx = idx
|
||||||
return :DT_EOS, idx, cell
|
return :DT_EOS, idx, cell
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_body(cell, out_dev, fs, rs)
|
def generate_body(cell, out_dev, fs, rs)
|
||||||
if cell.nil?
|
if cell.nil?
|
||||||
# empty
|
# empty
|
||||||
|
@ -498,7 +498,7 @@ class CSV
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_separator(type, out_dev, fs, rs)
|
def generate_separator(type, out_dev, fs, rs)
|
||||||
case type
|
case type
|
||||||
when :DT_COLSEP
|
when :DT_COLSEP
|
||||||
|
@ -586,7 +586,7 @@ class CSV
|
||||||
# Define if needed.
|
# Define if needed.
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
class StringReader < Reader
|
class StringReader < Reader
|
||||||
def initialize(string, fs = ',', rs = nil)
|
def initialize(string, fs = ',', rs = nil)
|
||||||
|
@ -800,7 +800,7 @@ private
|
||||||
# returns char at idx if n == nil.
|
# returns char at idx if n == nil.
|
||||||
# returns a partial string, from idx to (idx + n) if n != nil. at EOF,
|
# returns a partial string, from idx to (idx + n) if n != nil. at EOF,
|
||||||
# the string size could not equal to arg n.
|
# the string size could not equal to arg n.
|
||||||
def [](idx, n = nil)
|
def [](idx, n = nil)
|
||||||
if idx < 0
|
if idx < 0
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
@ -846,7 +846,7 @@ private
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias get []
|
alias get []
|
||||||
|
|
||||||
# drop a string from the stream.
|
# drop a string from the stream.
|
||||||
# returns dropped size. at EOF, dropped size might not equals to arg n.
|
# returns dropped size. at EOF, dropped size might not equals to arg n.
|
||||||
# Once you drop the head of the stream, access to the dropped part via []
|
# Once you drop the head of the stream, access to the dropped part via []
|
||||||
|
@ -878,11 +878,11 @@ private
|
||||||
end
|
end
|
||||||
size_dropped
|
size_dropped
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_eos?
|
def is_eos?
|
||||||
return idx_is_eos?(0)
|
return idx_is_eos?(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
# WARN: Do not instantiate this class directly. Define your own class
|
# WARN: Do not instantiate this class directly. Define your own class
|
||||||
# which derives this class and define 'read' instance method.
|
# which derives this class and define 'read' instance method.
|
||||||
def initialize
|
def initialize
|
||||||
|
@ -893,13 +893,13 @@ private
|
||||||
add_buf
|
add_buf
|
||||||
@cur_buf = @buf_tail_idx
|
@cur_buf = @buf_tail_idx
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def terminate
|
def terminate
|
||||||
while (rel_buf); end
|
while (rel_buf); end
|
||||||
end
|
end
|
||||||
|
|
||||||
# protected method 'read' must be defined in derived classes.
|
# protected method 'read' must be defined in derived classes.
|
||||||
# CAUTION: Returning a string which size is not equal to 'size' means
|
# CAUTION: Returning a string which size is not equal to 'size' means
|
||||||
# EnfOfStream. When it is not at EOS, you must block the callee, try to
|
# EnfOfStream. When it is not at EOS, you must block the callee, try to
|
||||||
|
@ -907,9 +907,9 @@ private
|
||||||
def read(size) # raise EOFError
|
def read(size) # raise EOFError
|
||||||
raise NotImplementedError.new('Method read must be defined in a derived class.')
|
raise NotImplementedError.new('Method read must be defined in a derived class.')
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def buf_size(idx)
|
def buf_size(idx)
|
||||||
@buf_list[idx].size
|
@buf_list[idx].size
|
||||||
end
|
end
|
||||||
|
@ -937,7 +937,7 @@ private
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rel_buf
|
def rel_buf
|
||||||
if (@cur_buf < 0)
|
if (@cur_buf < 0)
|
||||||
return false
|
return false
|
||||||
|
@ -951,11 +951,11 @@ private
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def idx_is_eos?(idx)
|
def idx_is_eos?(idx)
|
||||||
(@is_eos and ((@cur_buf < 0) or (@cur_buf == @buf_tail_idx)))
|
(@is_eos and ((@cur_buf < 0) or (@cur_buf == @buf_tail_idx)))
|
||||||
end
|
end
|
||||||
|
|
||||||
BufSize = 1024 * 8
|
BufSize = 1024 * 8
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -974,7 +974,7 @@ private
|
||||||
@s = s
|
@s = s
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
terminate
|
terminate
|
||||||
end
|
end
|
||||||
|
@ -984,7 +984,7 @@ private
|
||||||
def read(size)
|
def read(size)
|
||||||
@s.read(size)
|
@s.read(size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def terminate
|
def terminate
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
|
|
@ -256,7 +256,7 @@ class Context
|
||||||
def debug_command(file, line, id, binding)
|
def debug_command(file, line, id, binding)
|
||||||
MUTEX.lock
|
MUTEX.lock
|
||||||
unless defined?($debugger_restart) and $debugger_restart
|
unless defined?($debugger_restart) and $debugger_restart
|
||||||
callcc{|c| $debugger_restart = c}
|
callcc{|c| $debugger_restart = c}
|
||||||
end
|
end
|
||||||
set_last_thread(Thread.current)
|
set_last_thread(Thread.current)
|
||||||
frame_pos = 0
|
frame_pos = 0
|
||||||
|
@ -335,7 +335,7 @@ class Context
|
||||||
stdout.print "Breakpoints:\n"
|
stdout.print "Breakpoints:\n"
|
||||||
for b in break_points
|
for b in break_points
|
||||||
if b[0] and b[1] == 0
|
if b[0] and b[1] == 0
|
||||||
stdout.printf " %d %s:%s\n", n, b[2], b[3]
|
stdout.printf " %d %s:%s\n", n, b[2], b[3]
|
||||||
end
|
end
|
||||||
n += 1
|
n += 1
|
||||||
end
|
end
|
||||||
|
@ -751,7 +751,7 @@ EOHELP
|
||||||
when 'end'
|
when 'end'
|
||||||
@frames.shift
|
@frames.shift
|
||||||
|
|
||||||
when 'raise'
|
when 'raise'
|
||||||
excn_handle(file, line, id, binding)
|
excn_handle(file, line, id, binding)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -921,7 +921,7 @@ class << DEBUGGER__
|
||||||
@stdout.print "Already stopped.\n"
|
@stdout.print "Already stopped.\n"
|
||||||
else
|
else
|
||||||
thread_list(@thread_list[th])
|
thread_list(@thread_list[th])
|
||||||
context(th).suspend
|
context(th).suspend
|
||||||
end
|
end
|
||||||
|
|
||||||
when /^resume\s+(\d+)/
|
when /^resume\s+(\d+)/
|
||||||
|
|
|
@ -37,16 +37,16 @@
|
||||||
# def initialize
|
# def initialize
|
||||||
# @source = SimpleDelegator.new([])
|
# @source = SimpleDelegator.new([])
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def stats( records )
|
# def stats( records )
|
||||||
# @source.__setobj__(records)
|
# @source.__setobj__(records)
|
||||||
#
|
#
|
||||||
# "Elements: #{@source.size}\n" +
|
# "Elements: #{@source.size}\n" +
|
||||||
# " Non-Nil: #{@source.compact.size}\n" +
|
# " Non-Nil: #{@source.compact.size}\n" +
|
||||||
# " Unique: #{@source.uniq.size}\n"
|
# " Unique: #{@source.uniq.size}\n"
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# s = Stats.new
|
# s = Stats.new
|
||||||
# puts s.stats(%w{James Edward Gray II})
|
# puts s.stats(%w{James Edward Gray II})
|
||||||
# puts
|
# puts
|
||||||
|
@ -57,7 +57,7 @@
|
||||||
# Elements: 4
|
# Elements: 4
|
||||||
# Non-Nil: 4
|
# Non-Nil: 4
|
||||||
# Unique: 4
|
# Unique: 4
|
||||||
#
|
#
|
||||||
# Elements: 8
|
# Elements: 8
|
||||||
# Non-Nil: 7
|
# Non-Nil: 7
|
||||||
# Unique: 6
|
# Unique: 6
|
||||||
|
@ -72,19 +72,19 @@
|
||||||
#
|
#
|
||||||
# class Tempfile < DelegateClass(File)
|
# class Tempfile < DelegateClass(File)
|
||||||
# # constant and class member data initialization...
|
# # constant and class member data initialization...
|
||||||
#
|
#
|
||||||
# def initialize(basename, tmpdir=Dir::tmpdir)
|
# def initialize(basename, tmpdir=Dir::tmpdir)
|
||||||
# # build up file path/name in var tmpname...
|
# # build up file path/name in var tmpname...
|
||||||
#
|
#
|
||||||
# @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
|
# @tmpfile = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL, 0600)
|
||||||
#
|
#
|
||||||
# # ...
|
# # ...
|
||||||
#
|
#
|
||||||
# super(@tmpfile)
|
# super(@tmpfile)
|
||||||
#
|
#
|
||||||
# # below this point, all methods of File are supported...
|
# # below this point, all methods of File are supported...
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
|
@ -97,15 +97,15 @@
|
||||||
# super # pass obj to Delegator constructor, required
|
# super # pass obj to Delegator constructor, required
|
||||||
# @_sd_obj = obj # store obj for future use
|
# @_sd_obj = obj # store obj for future use
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def __getobj__
|
# def __getobj__
|
||||||
# @_sd_obj # return object we are delegating to, required
|
# @_sd_obj # return object we are delegating to, required
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def __setobj__(obj)
|
# def __setobj__(obj)
|
||||||
# @_sd_obj = obj # change delegation object, a feature we're providing
|
# @_sd_obj = obj # change delegation object, a feature we're providing
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
@ -159,10 +159,10 @@ class Delegator
|
||||||
target.__send__(m, *args, &block)
|
target.__send__(m, *args, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Checks for a method provided by this the delegate object by fowarding the
|
# Checks for a method provided by this the delegate object by fowarding the
|
||||||
# call through \_\_getobj\_\_.
|
# call through \_\_getobj\_\_.
|
||||||
#
|
#
|
||||||
def respond_to?(m, include_private = false)
|
def respond_to?(m, include_private = false)
|
||||||
return true if super
|
return true if super
|
||||||
return self.__getobj__.respond_to?(m, include_private)
|
return self.__getobj__.respond_to?(m, include_private)
|
||||||
|
|
178
lib/drb/drb.rb
178
lib/drb/drb.rb
|
@ -18,7 +18,7 @@
|
||||||
#
|
#
|
||||||
# The Ruby standard library contains the core classes of the dRuby package.
|
# The Ruby standard library contains the core classes of the dRuby package.
|
||||||
# However, the full package also includes access control lists and the
|
# However, the full package also includes access control lists and the
|
||||||
# Rinda tuple-space distributed task management system, as well as a
|
# Rinda tuple-space distributed task management system, as well as a
|
||||||
# large number of samples. The full dRuby package can be downloaded from
|
# large number of samples. The full dRuby package can be downloaded from
|
||||||
# the dRuby home page (see *References*).
|
# the dRuby home page (see *References*).
|
||||||
#
|
#
|
||||||
|
@ -121,7 +121,7 @@ require 'drb/eq'
|
||||||
# are forwarded to the local object, as described in the discussion of
|
# are forwarded to the local object, as described in the discussion of
|
||||||
# DRbObjects. This has semantics similar to the normal Ruby
|
# DRbObjects. This has semantics similar to the normal Ruby
|
||||||
# pass-by-reference.
|
# pass-by-reference.
|
||||||
#
|
#
|
||||||
# The easiest way to signal that we want an otherwise marshallable
|
# The easiest way to signal that we want an otherwise marshallable
|
||||||
# object to be passed or returned as a DRbObject reference, rather
|
# object to be passed or returned as a DRbObject reference, rather
|
||||||
# than marshalled and sent as a copy, is to include the
|
# than marshalled and sent as a copy, is to include the
|
||||||
|
@ -135,7 +135,7 @@ require 'drb/eq'
|
||||||
# passed back to the remote execution context to be collected, before
|
# passed back to the remote execution context to be collected, before
|
||||||
# the collected values are finally returned to the local context as
|
# the collected values are finally returned to the local context as
|
||||||
# the return value of the method invocation.
|
# the return value of the method invocation.
|
||||||
#
|
#
|
||||||
# == Examples of usage
|
# == Examples of usage
|
||||||
#
|
#
|
||||||
# For more dRuby samples, see the +samples+ directory in the full
|
# For more dRuby samples, see the +samples+ directory in the full
|
||||||
|
@ -148,33 +148,33 @@ require 'drb/eq'
|
||||||
# starting the server code first.
|
# starting the server code first.
|
||||||
#
|
#
|
||||||
# ==== Server code
|
# ==== Server code
|
||||||
#
|
#
|
||||||
# require 'drb/drb'
|
# require 'drb/drb'
|
||||||
#
|
#
|
||||||
# # The URI for the server to connect to
|
# # The URI for the server to connect to
|
||||||
# URI="druby://localhost:8787"
|
# URI="druby://localhost:8787"
|
||||||
#
|
#
|
||||||
# class TimeServer
|
# class TimeServer
|
||||||
#
|
#
|
||||||
# def get_current_time
|
# def get_current_time
|
||||||
# return Time.now
|
# return Time.now
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # The object that handles requests on the server
|
# # The object that handles requests on the server
|
||||||
# FRONT_OBJECT=TimeServer.new
|
# FRONT_OBJECT=TimeServer.new
|
||||||
#
|
#
|
||||||
# $SAFE = 1 # disable eval() and friends
|
# $SAFE = 1 # disable eval() and friends
|
||||||
#
|
#
|
||||||
# DRb.start_service(URI, FRONT_OBJECT)
|
# DRb.start_service(URI, FRONT_OBJECT)
|
||||||
# # Wait for the drb server thread to finish before exiting.
|
# # Wait for the drb server thread to finish before exiting.
|
||||||
# DRb.thread.join
|
# DRb.thread.join
|
||||||
#
|
#
|
||||||
# ==== Client code
|
# ==== Client code
|
||||||
#
|
#
|
||||||
# require 'drb/drb'
|
# require 'drb/drb'
|
||||||
#
|
#
|
||||||
# # The URI to connect to
|
# # The URI to connect to
|
||||||
# SERVER_URI="druby://localhost:8787"
|
# SERVER_URI="druby://localhost:8787"
|
||||||
#
|
#
|
||||||
|
@ -184,43 +184,43 @@ require 'drb/eq'
|
||||||
# # as soon as we pass a non-marshallable object as an argument
|
# # as soon as we pass a non-marshallable object as an argument
|
||||||
# # to a dRuby call.
|
# # to a dRuby call.
|
||||||
# DRb.start_service
|
# DRb.start_service
|
||||||
#
|
#
|
||||||
# timeserver = DRbObject.new_with_uri(SERVER_URI)
|
# timeserver = DRbObject.new_with_uri(SERVER_URI)
|
||||||
# puts timeserver.get_current_time
|
# puts timeserver.get_current_time
|
||||||
#
|
#
|
||||||
# === Remote objects under dRuby
|
# === Remote objects under dRuby
|
||||||
#
|
#
|
||||||
# This example illustrates returning a reference to an object
|
# This example illustrates returning a reference to an object
|
||||||
# from a dRuby call. The Logger instances live in the server
|
# from a dRuby call. The Logger instances live in the server
|
||||||
# process. References to them are returned to the client process,
|
# process. References to them are returned to the client process,
|
||||||
# where methods can be invoked upon them. These methods are
|
# where methods can be invoked upon them. These methods are
|
||||||
# executed in the server process.
|
# executed in the server process.
|
||||||
#
|
#
|
||||||
# ==== Server code
|
# ==== Server code
|
||||||
#
|
#
|
||||||
# require 'drb/drb'
|
# require 'drb/drb'
|
||||||
#
|
#
|
||||||
# URI="druby://localhost:8787"
|
# URI="druby://localhost:8787"
|
||||||
#
|
#
|
||||||
# class Logger
|
# class Logger
|
||||||
#
|
#
|
||||||
# # Make dRuby send Logger instances as dRuby references,
|
# # Make dRuby send Logger instances as dRuby references,
|
||||||
# # not copies.
|
# # not copies.
|
||||||
# include DRb::DRbUndumped
|
# include DRb::DRbUndumped
|
||||||
#
|
#
|
||||||
# def initialize(n, fname)
|
# def initialize(n, fname)
|
||||||
# @name = n
|
# @name = n
|
||||||
# @filename = fname
|
# @filename = fname
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def log(message)
|
# def log(message)
|
||||||
# File.open(@filename, "a") do |f|
|
# File.open(@filename, "a") do |f|
|
||||||
# f.puts("#{Time.now}: #{@name}: #{message}")
|
# f.puts("#{Time.now}: #{@name}: #{message}")
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # We have a central object for creating and retrieving loggers.
|
# # We have a central object for creating and retrieving loggers.
|
||||||
# # This retains a local reference to all loggers created. This
|
# # This retains a local reference to all loggers created. This
|
||||||
# # is so an existing logger can be looked up by name, but also
|
# # is so an existing logger can be looked up by name, but also
|
||||||
|
@ -228,12 +228,12 @@ require 'drb/eq'
|
||||||
# # reference to an object is not sufficient to prevent it being
|
# # reference to an object is not sufficient to prevent it being
|
||||||
# # garbage collected!
|
# # garbage collected!
|
||||||
# class LoggerFactory
|
# class LoggerFactory
|
||||||
#
|
#
|
||||||
# def initialize(bdir)
|
# def initialize(bdir)
|
||||||
# @basedir = bdir
|
# @basedir = bdir
|
||||||
# @loggers = {}
|
# @loggers = {}
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def get_logger(name)
|
# def get_logger(name)
|
||||||
# if !@loggers.has_key? name
|
# if !@loggers.has_key? name
|
||||||
# # make the filename safe, then declare it to be so
|
# # make the filename safe, then declare it to be so
|
||||||
|
@ -242,34 +242,34 @@ require 'drb/eq'
|
||||||
# end
|
# end
|
||||||
# return @loggers[name]
|
# return @loggers[name]
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# FRONT_OBJECT=LoggerFactory.new("/tmp/dlog")
|
# FRONT_OBJECT=LoggerFactory.new("/tmp/dlog")
|
||||||
#
|
#
|
||||||
# $SAFE = 1 # disable eval() and friends
|
# $SAFE = 1 # disable eval() and friends
|
||||||
#
|
#
|
||||||
# DRb.start_service(URI, FRONT_OBJECT)
|
# DRb.start_service(URI, FRONT_OBJECT)
|
||||||
# DRb.thread.join
|
# DRb.thread.join
|
||||||
#
|
#
|
||||||
# ==== Client code
|
# ==== Client code
|
||||||
#
|
#
|
||||||
# require 'drb/drb'
|
# require 'drb/drb'
|
||||||
#
|
#
|
||||||
# SERVER_URI="druby://localhost:8787"
|
# SERVER_URI="druby://localhost:8787"
|
||||||
#
|
#
|
||||||
# DRb.start_service
|
# DRb.start_service
|
||||||
#
|
#
|
||||||
# log_service=DRbObject.new_with_uri(SERVER_URI)
|
# log_service=DRbObject.new_with_uri(SERVER_URI)
|
||||||
#
|
#
|
||||||
# ["loga", "logb", "logc"].each do |logname|
|
# ["loga", "logb", "logc"].each do |logname|
|
||||||
#
|
#
|
||||||
# logger=log_service.get_logger(logname)
|
# logger=log_service.get_logger(logname)
|
||||||
#
|
#
|
||||||
# logger.log("Hello, world!")
|
# logger.log("Hello, world!")
|
||||||
# logger.log("Goodbye, world!")
|
# logger.log("Goodbye, world!")
|
||||||
# logger.log("=== EOT ===")
|
# logger.log("=== EOT ===")
|
||||||
#
|
#
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# == Security
|
# == Security
|
||||||
|
@ -288,9 +288,9 @@ require 'drb/eq'
|
||||||
# ro.instance_eval("`rm -rf *`")
|
# ro.instance_eval("`rm -rf *`")
|
||||||
#
|
#
|
||||||
# The dangers posed by instance_eval and friends are such that a
|
# The dangers posed by instance_eval and friends are such that a
|
||||||
# DRbServer should generally be run with $SAFE set to at least
|
# DRbServer should generally be run with $SAFE set to at least
|
||||||
# level 1. This will disable eval() and related calls on strings
|
# level 1. This will disable eval() and related calls on strings
|
||||||
# passed across the wire. The sample usage code given above follows
|
# passed across the wire. The sample usage code given above follows
|
||||||
# this practice.
|
# this practice.
|
||||||
#
|
#
|
||||||
# A DRbServer can be configured with an access control list to
|
# A DRbServer can be configured with an access control list to
|
||||||
|
@ -360,7 +360,7 @@ module DRb
|
||||||
#
|
#
|
||||||
# This, the default implementation, uses an object's local ObjectSpace
|
# This, the default implementation, uses an object's local ObjectSpace
|
||||||
# __id__ as its id. This means that an object's identification over
|
# __id__ as its id. This means that an object's identification over
|
||||||
# drb remains valid only while that object instance remains alive
|
# drb remains valid only while that object instance remains alive
|
||||||
# within the server runtime.
|
# within the server runtime.
|
||||||
#
|
#
|
||||||
# For alternative mechanisms, see DRb::TimerIdConv in rdb/timeridconv.rb
|
# For alternative mechanisms, see DRb::TimerIdConv in rdb/timeridconv.rb
|
||||||
|
@ -374,7 +374,7 @@ module DRb
|
||||||
def to_obj(ref)
|
def to_obj(ref)
|
||||||
ObjectSpace._id2ref(ref)
|
ObjectSpace._id2ref(ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert an object into a reference id.
|
# Convert an object into a reference id.
|
||||||
#
|
#
|
||||||
# This implementation returns the object's __id__ in the local
|
# This implementation returns the object's __id__ in the local
|
||||||
|
@ -390,7 +390,7 @@ module DRb
|
||||||
# called over drb, then the object remains in the server space
|
# called over drb, then the object remains in the server space
|
||||||
# and a reference to the object is returned, rather than the
|
# and a reference to the object is returned, rather than the
|
||||||
# object being marshalled and moved into the client space.
|
# object being marshalled and moved into the client space.
|
||||||
module DRbUndumped
|
module DRbUndumped
|
||||||
def _dump(dummy) # :nodoc:
|
def _dump(dummy) # :nodoc:
|
||||||
raise TypeError, 'can\'t dump'
|
raise TypeError, 'can\'t dump'
|
||||||
end
|
end
|
||||||
|
@ -424,7 +424,7 @@ module DRb
|
||||||
def self._load(s) # :nodoc:
|
def self._load(s) # :nodoc:
|
||||||
Marshal::load(s)
|
Marshal::load(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def _dump(lv) # :nodoc:
|
def _dump(lv) # :nodoc:
|
||||||
Marshal::dump(@unknown)
|
Marshal::dump(@unknown)
|
||||||
end
|
end
|
||||||
|
@ -456,11 +456,11 @@ module DRb
|
||||||
# +name+ attribute. The marshalled object is held in the +buf+
|
# +name+ attribute. The marshalled object is held in the +buf+
|
||||||
# attribute.
|
# attribute.
|
||||||
class DRbUnknown
|
class DRbUnknown
|
||||||
|
|
||||||
# Create a new DRbUnknown object.
|
# Create a new DRbUnknown object.
|
||||||
#
|
#
|
||||||
# +buf+ is a string containing a marshalled object that could not
|
# +buf+ is a string containing a marshalled object that could not
|
||||||
# be unmarshalled. +err+ is the error message that was raised
|
# be unmarshalled. +err+ is the error message that was raised
|
||||||
# when the unmarshalling failed. It is used to determine the
|
# when the unmarshalling failed. It is used to determine the
|
||||||
# name of the unmarshalled object.
|
# name of the unmarshalled object.
|
||||||
def initialize(err, buf)
|
def initialize(err, buf)
|
||||||
|
@ -499,7 +499,7 @@ module DRb
|
||||||
# Attempt to load the wrapped marshalled object again.
|
# Attempt to load the wrapped marshalled object again.
|
||||||
#
|
#
|
||||||
# If the class of the object is now known locally, the object
|
# If the class of the object is now known locally, the object
|
||||||
# will be unmarshalled and returned. Otherwise, a new
|
# will be unmarshalled and returned. Otherwise, a new
|
||||||
# but identical DRbUnknown object will be returned.
|
# but identical DRbUnknown object will be returned.
|
||||||
def reload
|
def reload
|
||||||
self.class._load(@buf)
|
self.class._load(@buf)
|
||||||
|
@ -513,7 +513,7 @@ module DRb
|
||||||
|
|
||||||
class DRbArray
|
class DRbArray
|
||||||
def initialize(ary)
|
def initialize(ary)
|
||||||
@ary = ary.collect { |obj|
|
@ary = ary.collect { |obj|
|
||||||
if obj.kind_of? DRbUndumped
|
if obj.kind_of? DRbUndumped
|
||||||
DRbObject.new(obj)
|
DRbObject.new(obj)
|
||||||
else
|
else
|
||||||
|
@ -607,7 +607,7 @@ module DRb
|
||||||
rescue
|
rescue
|
||||||
raise(DRbConnError, $!.message, $!.backtrace)
|
raise(DRbConnError, $!.message, $!.backtrace)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recv_request(stream) # :nodoc:
|
def recv_request(stream) # :nodoc:
|
||||||
ref = load(stream)
|
ref = load(stream)
|
||||||
ro = DRb.to_obj(ref)
|
ro = DRb.to_obj(ref)
|
||||||
|
@ -656,10 +656,10 @@ module DRb
|
||||||
# using configuration +config+. Return a
|
# using configuration +config+. Return a
|
||||||
# protocol instance for this listener.
|
# protocol instance for this listener.
|
||||||
# [uri_option(uri, config)] Take a URI, possibly containing an option
|
# [uri_option(uri, config)] Take a URI, possibly containing an option
|
||||||
# component (e.g. a trailing '?param=val'),
|
# component (e.g. a trailing '?param=val'),
|
||||||
# and return a [uri, option] tuple.
|
# and return a [uri, option] tuple.
|
||||||
#
|
#
|
||||||
# All of these methods should raise a DRbBadScheme error if the URI
|
# All of these methods should raise a DRbBadScheme error if the URI
|
||||||
# does not identify the protocol they support (e.g. "druby:" for
|
# does not identify the protocol they support (e.g. "druby:" for
|
||||||
# the standard Ruby protocol). This is how the DRbProtocol module,
|
# the standard Ruby protocol). This is how the DRbProtocol module,
|
||||||
# given a URI, determines which protocol implementation serves that
|
# given a URI, determines which protocol implementation serves that
|
||||||
|
@ -675,14 +675,14 @@ module DRb
|
||||||
#
|
#
|
||||||
# The protocol instance returned by #open must have the following methods:
|
# The protocol instance returned by #open must have the following methods:
|
||||||
#
|
#
|
||||||
# [send_request (ref, msg_id, arg, b)]
|
# [send_request (ref, msg_id, arg, b)]
|
||||||
# Send a request to +ref+ with the given message id and arguments.
|
# Send a request to +ref+ with the given message id and arguments.
|
||||||
# This is most easily implemented by calling DRbMessage.send_request,
|
# This is most easily implemented by calling DRbMessage.send_request,
|
||||||
# providing a stream that sits on top of the current protocol.
|
# providing a stream that sits on top of the current protocol.
|
||||||
# [recv_reply]
|
# [recv_reply]
|
||||||
# Receive a reply from the server and return it as a [success-boolean,
|
# Receive a reply from the server and return it as a [success-boolean,
|
||||||
# reply-value] pair. This is most easily implemented by calling
|
# reply-value] pair. This is most easily implemented by calling
|
||||||
# DRb.recv_reply, providing a stream that sits on top of the
|
# DRb.recv_reply, providing a stream that sits on top of the
|
||||||
# current protocol.
|
# current protocol.
|
||||||
# [alive?]
|
# [alive?]
|
||||||
# Is this connection still alive?
|
# Is this connection still alive?
|
||||||
|
@ -725,7 +725,7 @@ module DRb
|
||||||
# URI by raising a DRbBadScheme error. If no protocol recognises the
|
# URI by raising a DRbBadScheme error. If no protocol recognises the
|
||||||
# URI, then a DRbBadURI error is raised. If a protocol accepts the
|
# URI, then a DRbBadURI error is raised. If a protocol accepts the
|
||||||
# URI, but an error occurs in opening it, a DRbConnError is raised.
|
# URI, but an error occurs in opening it, a DRbConnError is raised.
|
||||||
def open(uri, config, first=true)
|
def open(uri, config, first=true)
|
||||||
@protocol.each do |prot|
|
@protocol.each do |prot|
|
||||||
begin
|
begin
|
||||||
return prot.open(uri, config)
|
return prot.open(uri, config)
|
||||||
|
@ -744,14 +744,14 @@ module DRb
|
||||||
end
|
end
|
||||||
module_function :open
|
module_function :open
|
||||||
|
|
||||||
# Open a server listening for connections at +uri+ with
|
# Open a server listening for connections at +uri+ with
|
||||||
# configuration +config+.
|
# configuration +config+.
|
||||||
#
|
#
|
||||||
# The DRbProtocol module asks each registered protocol in turn to
|
# The DRbProtocol module asks each registered protocol in turn to
|
||||||
# try to open a server at the URI. Each protocol signals that it does
|
# try to open a server at the URI. Each protocol signals that it does
|
||||||
# not handle that URI by raising a DRbBadScheme error. If no protocol
|
# not handle that URI by raising a DRbBadScheme error. If no protocol
|
||||||
# recognises the URI, then a DRbBadURI error is raised. If a protocol
|
# recognises the URI, then a DRbBadURI error is raised. If a protocol
|
||||||
# accepts the URI, but an error occurs in opening it, the underlying
|
# accepts the URI, but an error occurs in opening it, the underlying
|
||||||
# error is passed on to the caller.
|
# error is passed on to the caller.
|
||||||
def open_server(uri, config, first=true)
|
def open_server(uri, config, first=true)
|
||||||
@protocol.each do |prot|
|
@protocol.each do |prot|
|
||||||
|
@ -773,7 +773,7 @@ module DRb
|
||||||
# The DRbProtocol module asks each registered protocol in turn to
|
# The DRbProtocol module asks each registered protocol in turn to
|
||||||
# try to parse the URI. Each protocol signals that it does not handle that
|
# try to parse the URI. Each protocol signals that it does not handle that
|
||||||
# URI by raising a DRbBadScheme error. If no protocol recognises the
|
# URI by raising a DRbBadScheme error. If no protocol recognises the
|
||||||
# URI, then a DRbBadURI error is raised.
|
# URI, then a DRbBadURI error is raised.
|
||||||
def uri_option(uri, config, first=true)
|
def uri_option(uri, config, first=true)
|
||||||
@protocol.each do |prot|
|
@protocol.each do |prot|
|
||||||
begin
|
begin
|
||||||
|
@ -837,9 +837,9 @@ module DRb
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.open_server_inaddr_any(host, port)
|
def self.open_server_inaddr_any(host, port)
|
||||||
infos = Socket::getaddrinfo(host, nil,
|
infos = Socket::getaddrinfo(host, nil,
|
||||||
Socket::AF_UNSPEC,
|
Socket::AF_UNSPEC,
|
||||||
Socket::SOCK_STREAM,
|
Socket::SOCK_STREAM,
|
||||||
0,
|
0,
|
||||||
Socket::AI_PASSIVE)
|
Socket::AI_PASSIVE)
|
||||||
families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
|
families = Hash[*infos.collect { |af, *_| af }.uniq.zip([]).flatten]
|
||||||
|
@ -848,7 +848,7 @@ module DRb
|
||||||
return TCPServer.open(port)
|
return TCPServer.open(port)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Open a server listening for connections at +uri+ using
|
# Open a server listening for connections at +uri+ using
|
||||||
# configuration +config+.
|
# configuration +config+.
|
||||||
def self.open_server(uri, config)
|
def self.open_server(uri, config)
|
||||||
uri = 'druby://:0' unless uri
|
uri = 'druby://:0' unless uri
|
||||||
|
@ -894,7 +894,7 @@ module DRb
|
||||||
def peeraddr
|
def peeraddr
|
||||||
@socket.peeraddr
|
@socket.peeraddr
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the socket.
|
# Get the socket.
|
||||||
def stream; @socket; end
|
def stream; @socket; end
|
||||||
|
|
||||||
|
@ -902,7 +902,7 @@ module DRb
|
||||||
def send_request(ref, msg_id, arg, b)
|
def send_request(ref, msg_id, arg, b)
|
||||||
@msg.send_request(stream, ref, msg_id, arg, b)
|
@msg.send_request(stream, ref, msg_id, arg, b)
|
||||||
end
|
end
|
||||||
|
|
||||||
# On the server side, receive a request from the client.
|
# On the server side, receive a request from the client.
|
||||||
def recv_request
|
def recv_request
|
||||||
@msg.recv_request(stream)
|
@msg.recv_request(stream)
|
||||||
|
@ -932,14 +932,14 @@ module DRb
|
||||||
@socket = nil
|
@socket = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# On the server side, for an instance returned by #open_server,
|
# On the server side, for an instance returned by #open_server,
|
||||||
# accept a client connection and return a new instance to handle
|
# accept a client connection and return a new instance to handle
|
||||||
# the server's side of this client-server session.
|
# the server's side of this client-server session.
|
||||||
def accept
|
def accept
|
||||||
while true
|
while true
|
||||||
s = @socket.accept
|
s = @socket.accept
|
||||||
break if (@acl ? @acl.allow_socket?(s) : true)
|
break if (@acl ? @acl.allow_socket?(s) : true)
|
||||||
s.close
|
s.close
|
||||||
end
|
end
|
||||||
if @config[:tcp_original_host].to_s.size == 0
|
if @config[:tcp_original_host].to_s.size == 0
|
||||||
|
@ -976,16 +976,16 @@ module DRb
|
||||||
end
|
end
|
||||||
attr :option
|
attr :option
|
||||||
def to_s; @option; end
|
def to_s; @option; end
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
return false unless DRbURIOption === other
|
return false unless DRbURIOption === other
|
||||||
@option == other.option
|
@option == other.option
|
||||||
end
|
end
|
||||||
|
|
||||||
def hash
|
def hash
|
||||||
@option.hash
|
@option.hash
|
||||||
end
|
end
|
||||||
|
|
||||||
alias eql? ==
|
alias eql? ==
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1002,7 +1002,7 @@ module DRb
|
||||||
# created to act as a stub for the remote referenced object.
|
# created to act as a stub for the remote referenced object.
|
||||||
def self._load(s)
|
def self._load(s)
|
||||||
uri, ref = Marshal.load(s)
|
uri, ref = Marshal.load(s)
|
||||||
|
|
||||||
if DRb.here?(uri)
|
if DRb.here?(uri)
|
||||||
obj = DRb.to_obj(ref)
|
obj = DRb.to_obj(ref)
|
||||||
if ((! obj.tainted?) && Thread.current[:drb_untaint])
|
if ((! obj.tainted?) && Thread.current[:drb_untaint])
|
||||||
|
@ -1052,7 +1052,7 @@ module DRb
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the URI of the remote object.
|
# Get the URI of the remote object.
|
||||||
def __drburi
|
def __drburi
|
||||||
@uri
|
@uri
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1080,7 +1080,7 @@ module DRb
|
||||||
if DRb.here?(@uri)
|
if DRb.here?(@uri)
|
||||||
obj = DRb.to_obj(@ref)
|
obj = DRb.to_obj(@ref)
|
||||||
DRb.current_server.check_insecure_method(obj, msg_id)
|
DRb.current_server.check_insecure_method(obj, msg_id)
|
||||||
return obj.__send__(msg_id, *a, &b)
|
return obj.__send__(msg_id, *a, &b)
|
||||||
end
|
end
|
||||||
|
|
||||||
succ, result = self.class.with_friend(@uri) do
|
succ, result = self.class.with_friend(@uri) do
|
||||||
|
@ -1103,7 +1103,7 @@ module DRb
|
||||||
def self.with_friend(uri)
|
def self.with_friend(uri)
|
||||||
friend = DRb.fetch_server(uri)
|
friend = DRb.fetch_server(uri)
|
||||||
return yield() unless friend
|
return yield() unless friend
|
||||||
|
|
||||||
save = Thread.current['DRb']
|
save = Thread.current['DRb']
|
||||||
Thread.current['DRb'] = { 'server' => friend }
|
Thread.current['DRb'] = { 'server' => friend }
|
||||||
return yield
|
return yield
|
||||||
|
@ -1115,7 +1115,7 @@ module DRb
|
||||||
prefix = "(#{uri}) "
|
prefix = "(#{uri}) "
|
||||||
bt = []
|
bt = []
|
||||||
result.backtrace.each do |x|
|
result.backtrace.each do |x|
|
||||||
break if /`__send__'$/ =~ x
|
break if /`__send__'$/ =~ x
|
||||||
if /^\(druby:\/\// =~ x
|
if /^\(druby:\/\// =~ x
|
||||||
bt.push(x)
|
bt.push(x)
|
||||||
else
|
else
|
||||||
|
@ -1266,14 +1266,14 @@ module DRb
|
||||||
def self.verbose=(on)
|
def self.verbose=(on)
|
||||||
@@verbose = on
|
@@verbose = on
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get the default value of the :verbose option.
|
# Get the default value of the :verbose option.
|
||||||
def self.verbose
|
def self.verbose
|
||||||
@@verbose
|
@@verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.make_config(hash={}) # :nodoc:
|
def self.make_config(hash={}) # :nodoc:
|
||||||
default_config = {
|
default_config = {
|
||||||
:idconv => @@idconv,
|
:idconv => @@idconv,
|
||||||
:verbose => @@verbose,
|
:verbose => @@verbose,
|
||||||
:tcp_acl => @@acl,
|
:tcp_acl => @@acl,
|
||||||
|
@ -1363,7 +1363,7 @@ module DRb
|
||||||
attr_reader :thread
|
attr_reader :thread
|
||||||
|
|
||||||
# The front object of the DRbServer.
|
# The front object of the DRbServer.
|
||||||
#
|
#
|
||||||
# This object receives remote method calls made on the server's
|
# This object receives remote method calls made on the server's
|
||||||
# URI alone, with an object id.
|
# URI alone, with an object id.
|
||||||
attr_reader :front
|
attr_reader :front
|
||||||
|
@ -1456,7 +1456,7 @@ module DRb
|
||||||
def any_to_s(obj)
|
def any_to_s(obj)
|
||||||
obj.to_s + ":#{obj.class}"
|
obj.to_s + ":#{obj.class}"
|
||||||
rescue
|
rescue
|
||||||
sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
|
sprintf("#<%s:0x%lx>", obj.class, obj.__id__)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check that a method is callable via dRuby.
|
# Check that a method is callable via dRuby.
|
||||||
|
@ -1464,14 +1464,14 @@ module DRb
|
||||||
# +obj+ is the object we want to invoke the method on. +msg_id+ is the
|
# +obj+ is the object we want to invoke the method on. +msg_id+ is the
|
||||||
# method name, as a Symbol.
|
# method name, as a Symbol.
|
||||||
#
|
#
|
||||||
# If the method is an insecure method (see #insecure_method?) a
|
# If the method is an insecure method (see #insecure_method?) a
|
||||||
# SecurityError is thrown. If the method is private or undefined,
|
# SecurityError is thrown. If the method is private or undefined,
|
||||||
# a NameError is thrown.
|
# a NameError is thrown.
|
||||||
def check_insecure_method(obj, msg_id)
|
def check_insecure_method(obj, msg_id)
|
||||||
return true if Proc === obj && msg_id == :__drb_yield
|
return true if Proc === obj && msg_id == :__drb_yield
|
||||||
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
|
raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class
|
||||||
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
|
raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id)
|
||||||
|
|
||||||
if obj.private_methods.include?(msg_id.to_s)
|
if obj.private_methods.include?(msg_id.to_s)
|
||||||
desc = any_to_s(obj)
|
desc = any_to_s(obj)
|
||||||
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
|
raise NoMethodError, "private method `#{msg_id}' called for #{desc}"
|
||||||
|
@ -1483,7 +1483,7 @@ module DRb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
public :check_insecure_method
|
public :check_insecure_method
|
||||||
|
|
||||||
class InvokeMethod # :nodoc:
|
class InvokeMethod # :nodoc:
|
||||||
def initialize(drb_server, client)
|
def initialize(drb_server, client)
|
||||||
@drb_server = drb_server
|
@drb_server = drb_server
|
||||||
|
@ -1505,7 +1505,7 @@ module DRb
|
||||||
perform_with_block
|
perform_with_block
|
||||||
}.value
|
}.value
|
||||||
else
|
else
|
||||||
@result = Thread.new {
|
@result = Thread.new {
|
||||||
Thread.current['DRb'] = info
|
Thread.current['DRb'] = info
|
||||||
$SAFE = @safe_level
|
$SAFE = @safe_level
|
||||||
perform_without_block
|
perform_without_block
|
||||||
|
@ -1520,7 +1520,7 @@ module DRb
|
||||||
end
|
end
|
||||||
@succ = true
|
@succ = true
|
||||||
if @msg_id == :to_ary && @result.class == Array
|
if @msg_id == :to_ary && @result.class == Array
|
||||||
@result = DRbArray.new(@result)
|
@result = DRbArray.new(@result)
|
||||||
end
|
end
|
||||||
return @succ, @result
|
return @succ, @result
|
||||||
rescue StandardError, ScriptError, Interrupt
|
rescue StandardError, ScriptError, Interrupt
|
||||||
|
@ -1536,7 +1536,7 @@ module DRb
|
||||||
@argv = argv
|
@argv = argv
|
||||||
@block = block
|
@block = block
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_insecure_method
|
def check_insecure_method
|
||||||
@drb_server.check_insecure_method(@obj, @msg_id)
|
@drb_server.check_insecure_method(@obj, @msg_id)
|
||||||
end
|
end
|
||||||
|
@ -1545,7 +1545,7 @@ module DRb
|
||||||
init_with_client
|
init_with_client
|
||||||
check_insecure_method
|
check_insecure_method
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_without_block
|
def perform_without_block
|
||||||
if Proc === @obj && @msg_id == :__drb_yield
|
if Proc === @obj && @msg_id == :__drb_yield
|
||||||
if @argv.size == 1
|
if @argv.size == 1
|
||||||
|
@ -1633,7 +1633,7 @@ module DRb
|
||||||
|
|
||||||
# The primary local dRuby server.
|
# The primary local dRuby server.
|
||||||
#
|
#
|
||||||
# This is the server created by the #start_service call.
|
# This is the server created by the #start_service call.
|
||||||
attr_accessor :primary_server
|
attr_accessor :primary_server
|
||||||
module_function :primary_server=, :primary_server
|
module_function :primary_server=, :primary_server
|
||||||
|
|
||||||
|
@ -1648,8 +1648,8 @@ module DRb
|
||||||
# If the above rule fails to find a server, a DRbServerNotFound
|
# If the above rule fails to find a server, a DRbServerNotFound
|
||||||
# error is raised.
|
# error is raised.
|
||||||
def current_server
|
def current_server
|
||||||
drb = Thread.current['DRb']
|
drb = Thread.current['DRb']
|
||||||
server = (drb && drb['server']) ? drb['server'] : @primary_server
|
server = (drb && drb['server']) ? drb['server'] : @primary_server
|
||||||
raise DRbServerNotFound unless server
|
raise DRbServerNotFound unless server
|
||||||
return server
|
return server
|
||||||
end
|
end
|
||||||
|
@ -1695,7 +1695,7 @@ module DRb
|
||||||
DRbServer.make_config
|
DRbServer.make_config
|
||||||
end
|
end
|
||||||
module_function :config
|
module_function :config
|
||||||
|
|
||||||
# Get the front object of the current server.
|
# Get the front object of the current server.
|
||||||
#
|
#
|
||||||
# This raises a DRbServerNotFound error if there is no current server.
|
# This raises a DRbServerNotFound error if there is no current server.
|
||||||
|
@ -1766,7 +1766,7 @@ module DRb
|
||||||
@server.delete(server.uri)
|
@server.delete(server.uri)
|
||||||
end
|
end
|
||||||
module_function :remove_server
|
module_function :remove_server
|
||||||
|
|
||||||
def fetch_server(uri)
|
def fetch_server(uri)
|
||||||
@server[uri]
|
@server[uri]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
external service
|
external service
|
||||||
Copyright (c) 2000,2002 Masatoshi SEKI
|
Copyright (c) 2000,2002 Masatoshi SEKI
|
||||||
=end
|
=end
|
||||||
|
|
||||||
require 'drb/drb'
|
require 'drb/drb'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
=begin
|
=begin
|
||||||
external service manager
|
external service manager
|
||||||
Copyright (c) 2000 Masatoshi SEKI
|
Copyright (c) 2000 Masatoshi SEKI
|
||||||
=end
|
=end
|
||||||
|
|
||||||
require 'drb/drb'
|
require 'drb/drb'
|
||||||
|
@ -21,7 +21,7 @@ module DRb
|
||||||
def self.command=(cmd)
|
def self.command=(cmd)
|
||||||
@@command = cmd
|
@@command = cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super()
|
super()
|
||||||
@cond = new_cond
|
@cond = new_cond
|
||||||
|
@ -51,7 +51,7 @@ module DRb
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def unregist(name)
|
def unregist(name)
|
||||||
synchronize do
|
synchronize do
|
||||||
@servers.delete(name)
|
@servers.delete(name)
|
||||||
|
|
|
@ -9,7 +9,7 @@ module DRb
|
||||||
end
|
end
|
||||||
block_value = @block.call(*x)
|
block_value = @block.call(*x)
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_with_block
|
def perform_with_block
|
||||||
@obj.__send__(@msg_id, *@argv) do |*x|
|
@obj.__send__(@msg_id, *@argv) do |*x|
|
||||||
jump_error = nil
|
jump_error = nil
|
||||||
|
|
|
@ -15,7 +15,7 @@ module DRb
|
||||||
:SSLClientCA => nil,
|
:SSLClientCA => nil,
|
||||||
:SSLCACertificatePath => nil,
|
:SSLCACertificatePath => nil,
|
||||||
:SSLCACertificateFile => nil,
|
:SSLCACertificateFile => nil,
|
||||||
:SSLVerifyMode => ::OpenSSL::SSL::VERIFY_NONE,
|
:SSLVerifyMode => ::OpenSSL::SSL::VERIFY_NONE,
|
||||||
:SSLVerifyDepth => nil,
|
:SSLVerifyDepth => nil,
|
||||||
:SSLVerifyCallback => nil, # custom verification
|
:SSLVerifyCallback => nil, # custom verification
|
||||||
:SSLCertificateStore => nil,
|
:SSLCertificateStore => nil,
|
||||||
|
@ -31,7 +31,7 @@ module DRb
|
||||||
@ssl_ctx = nil
|
@ssl_ctx = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def [](key);
|
def [](key);
|
||||||
@config[key] || DEFAULT[key]
|
@config[key] || DEFAULT[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ module DRb
|
||||||
ssl.connect
|
ssl.connect
|
||||||
ssl
|
ssl
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept(tcp)
|
def accept(tcp)
|
||||||
ssl = OpenSSL::SSL::SSLSocket.new(tcp, @ssl_ctx)
|
ssl = OpenSSL::SSL::SSLSocket.new(tcp, @ssl_ctx)
|
||||||
ssl.sync = true
|
ssl.sync = true
|
||||||
ssl.accept
|
ssl.accept
|
||||||
ssl
|
ssl
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_certificate
|
def setup_certificate
|
||||||
if @cert && @pkey
|
if @cert && @pkey
|
||||||
return
|
return
|
||||||
|
@ -77,7 +77,7 @@ module DRb
|
||||||
cert.not_before = Time.now
|
cert.not_before = Time.now
|
||||||
cert.not_after = Time.now + (365*24*60*60)
|
cert.not_after = Time.now + (365*24*60*60)
|
||||||
cert.public_key = rsa.public_key
|
cert.public_key = rsa.public_key
|
||||||
|
|
||||||
ef = OpenSSL::X509::ExtensionFactory.new(nil,cert)
|
ef = OpenSSL::X509::ExtensionFactory.new(nil,cert)
|
||||||
cert.extensions = [
|
cert.extensions = [
|
||||||
ef.create_extension("basicConstraints","CA:FALSE"),
|
ef.create_extension("basicConstraints","CA:FALSE"),
|
||||||
|
@ -89,7 +89,7 @@ module DRb
|
||||||
cert.add_extension(ef.create_extension("nsComment", comment))
|
cert.add_extension(ef.create_extension("nsComment", comment))
|
||||||
end
|
end
|
||||||
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
|
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
|
||||||
|
|
||||||
@cert = cert
|
@cert = cert
|
||||||
@pkey = rsa
|
@pkey = rsa
|
||||||
end
|
end
|
||||||
|
@ -143,7 +143,7 @@ module DRb
|
||||||
end
|
end
|
||||||
port = soc.addr[1] if port == 0
|
port = soc.addr[1] if port == 0
|
||||||
@uri = "drbssl://#{host}:#{port}"
|
@uri = "drbssl://#{host}:#{port}"
|
||||||
|
|
||||||
ssl_conf = SSLConfig.new(config)
|
ssl_conf = SSLConfig.new(config)
|
||||||
ssl_conf.setup_certificate
|
ssl_conf.setup_certificate
|
||||||
ssl_conf.setup_ssl_context
|
ssl_conf.setup_ssl_context
|
||||||
|
@ -159,7 +159,7 @@ module DRb
|
||||||
@ssl = is_established ? soc : nil
|
@ssl = is_established ? soc : nil
|
||||||
super(uri, soc.to_io, config)
|
super(uri, soc.to_io, config)
|
||||||
end
|
end
|
||||||
|
|
||||||
def stream; @ssl; end
|
def stream; @ssl; end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
|
@ -169,12 +169,12 @@ module DRb
|
||||||
end
|
end
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept
|
def accept
|
||||||
begin
|
begin
|
||||||
while true
|
while true
|
||||||
soc = @socket.accept
|
soc = @socket.accept
|
||||||
break if (@acl ? @acl.allow_socket?(soc) : true)
|
break if (@acl ? @acl.allow_socket?(soc) : true)
|
||||||
soc.close
|
soc.close
|
||||||
end
|
end
|
||||||
ssl = @config.accept(soc)
|
ssl = @config.accept(soc)
|
||||||
|
@ -185,6 +185,6 @@ module DRb
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DRbProtocol.add_protocol(DRbSSLSocket)
|
DRbProtocol.add_protocol(DRbSSLSocket)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ module DRb
|
||||||
end
|
end
|
||||||
|
|
||||||
def add(obj)
|
def add(obj)
|
||||||
synchronize do
|
synchronize do
|
||||||
key = obj.__id__
|
key = obj.__id__
|
||||||
@curr[key] = obj
|
@curr[key] = obj
|
||||||
return key
|
return key
|
||||||
|
@ -27,7 +27,7 @@ module DRb
|
||||||
end
|
end
|
||||||
|
|
||||||
def fetch(key, dv=@sentinel)
|
def fetch(key, dv=@sentinel)
|
||||||
synchronize do
|
synchronize do
|
||||||
obj = peek(key)
|
obj = peek(key)
|
||||||
if obj == @sentinel
|
if obj == @sentinel
|
||||||
return dv unless dv == @sentinel
|
return dv unless dv == @sentinel
|
||||||
|
@ -39,7 +39,7 @@ module DRb
|
||||||
end
|
end
|
||||||
|
|
||||||
def include?(key)
|
def include?(key)
|
||||||
synchronize do
|
synchronize do
|
||||||
obj = peek(key)
|
obj = peek(key)
|
||||||
return false if obj == @sentinel
|
return false if obj == @sentinel
|
||||||
true
|
true
|
||||||
|
@ -47,7 +47,7 @@ module DRb
|
||||||
end
|
end
|
||||||
|
|
||||||
def peek(key)
|
def peek(key)
|
||||||
synchronize do
|
synchronize do
|
||||||
return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
|
return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ module DRb
|
||||||
|
|
||||||
class DRbUNIXSocket < DRbTCPSocket
|
class DRbUNIXSocket < DRbTCPSocket
|
||||||
def self.parse_uri(uri)
|
def self.parse_uri(uri)
|
||||||
if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
|
if /^drbunix:(.*?)(\?(.*))?$/ =~ uri
|
||||||
filename = $1
|
filename = $1
|
||||||
option = $3
|
option = $3
|
||||||
[filename, option]
|
[filename, option]
|
||||||
|
@ -59,7 +59,7 @@ module DRb
|
||||||
@server_mode = server_mode
|
@server_mode = server_mode
|
||||||
@acl = nil
|
@acl = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# import from tempfile.rb
|
# import from tempfile.rb
|
||||||
Max_try = 10
|
Max_try = 10
|
||||||
private
|
private
|
||||||
|
|
|
@ -59,7 +59,7 @@ module Exception2MessageMapper
|
||||||
super
|
super
|
||||||
cl.bind(self) unless cl == E2MM
|
cl.bind(self) unless cl == E2MM
|
||||||
end
|
end
|
||||||
|
|
||||||
# backward compatibility
|
# backward compatibility
|
||||||
def E2MM.extend_to(b)
|
def E2MM.extend_to(b)
|
||||||
c = eval("self", b)
|
c = eval("self", b)
|
||||||
|
@ -91,7 +91,7 @@ module Exception2MessageMapper
|
||||||
# backward compatibility
|
# backward compatibility
|
||||||
alias fail! fail
|
alias fail! fail
|
||||||
def fail(err = nil, *rest)
|
def fail(err = nil, *rest)
|
||||||
begin
|
begin
|
||||||
E2MM.Fail(self, err, *rest)
|
E2MM.Fail(self, err, *rest)
|
||||||
rescue E2MM::ErrNotRegisteredException
|
rescue E2MM::ErrNotRegisteredException
|
||||||
super
|
super
|
||||||
|
@ -101,7 +101,7 @@ module Exception2MessageMapper
|
||||||
public :fail
|
public :fail
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# def_e2message(c, m)
|
# def_e2message(c, m)
|
||||||
# c: exception
|
# c: exception
|
||||||
# m: message_form
|
# m: message_form
|
||||||
|
@ -110,7 +110,7 @@ module Exception2MessageMapper
|
||||||
def def_e2message(c, m)
|
def def_e2message(c, m)
|
||||||
E2MM.def_e2message(self, c, m)
|
E2MM.def_e2message(self, c, m)
|
||||||
end
|
end
|
||||||
|
|
||||||
# def_exception(n, m, s)
|
# def_exception(n, m, s)
|
||||||
# n: exception_name
|
# n: exception_name
|
||||||
# m: message_form
|
# m: message_form
|
||||||
|
@ -137,7 +137,7 @@ module Exception2MessageMapper
|
||||||
E2MM.instance_eval{@MessageMap[[k, c]] = m}
|
E2MM.instance_eval{@MessageMap[[k, c]] = m}
|
||||||
c
|
c
|
||||||
end
|
end
|
||||||
|
|
||||||
# E2MM.def_exception(k, n, m, s)
|
# E2MM.def_exception(k, n, m, s)
|
||||||
# k: class to define exception under.
|
# k: class to define exception under.
|
||||||
# n: exception_name
|
# n: exception_name
|
||||||
|
@ -187,8 +187,8 @@ module Exception2MessageMapper
|
||||||
alias message e2mm_message
|
alias message e2mm_message
|
||||||
end
|
end
|
||||||
|
|
||||||
E2MM.def_exception(E2MM,
|
E2MM.def_exception(E2MM,
|
||||||
:ErrNotRegisteredException,
|
:ErrNotRegisteredException,
|
||||||
"not registerd exception(%s)")
|
"not registerd exception(%s)")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
128
lib/erb.rb
128
lib/erb.rb
|
@ -20,7 +20,7 @@
|
||||||
# purposes of generating document information details and/or flow control.
|
# purposes of generating document information details and/or flow control.
|
||||||
#
|
#
|
||||||
# A very simple example is this:
|
# A very simple example is this:
|
||||||
#
|
#
|
||||||
# require 'erb'
|
# require 'erb'
|
||||||
#
|
#
|
||||||
# x = 42
|
# x = 42
|
||||||
|
@ -68,39 +68,39 @@
|
||||||
# <tt>%q{...}</tt> to avoid trouble with the backslash.
|
# <tt>%q{...}</tt> to avoid trouble with the backslash.
|
||||||
#
|
#
|
||||||
# require "erb"
|
# require "erb"
|
||||||
#
|
#
|
||||||
# # Create template.
|
# # Create template.
|
||||||
# template = %q{
|
# template = %q{
|
||||||
# From: James Edward Gray II <james@grayproductions.net>
|
# From: James Edward Gray II <james@grayproductions.net>
|
||||||
# To: <%= to %>
|
# To: <%= to %>
|
||||||
# Subject: Addressing Needs
|
# Subject: Addressing Needs
|
||||||
#
|
#
|
||||||
# <%= to[/\w+/] %>:
|
# <%= to[/\w+/] %>:
|
||||||
#
|
#
|
||||||
# Just wanted to send a quick note assuring that your needs are being
|
# Just wanted to send a quick note assuring that your needs are being
|
||||||
# addressed.
|
# addressed.
|
||||||
#
|
#
|
||||||
# I want you to know that my team will keep working on the issues,
|
# I want you to know that my team will keep working on the issues,
|
||||||
# especially:
|
# especially:
|
||||||
#
|
#
|
||||||
# <%# ignore numerous minor requests -- focus on priorities %>
|
# <%# ignore numerous minor requests -- focus on priorities %>
|
||||||
# % priorities.each do |priority|
|
# % priorities.each do |priority|
|
||||||
# * <%= priority %>
|
# * <%= priority %>
|
||||||
# % end
|
# % end
|
||||||
#
|
#
|
||||||
# Thanks for your patience.
|
# Thanks for your patience.
|
||||||
#
|
#
|
||||||
# James Edward Gray II
|
# James Edward Gray II
|
||||||
# }.gsub(/^ /, '')
|
# }.gsub(/^ /, '')
|
||||||
#
|
#
|
||||||
# message = ERB.new(template, 0, "%<>")
|
# message = ERB.new(template, 0, "%<>")
|
||||||
#
|
#
|
||||||
# # Set up template data.
|
# # Set up template data.
|
||||||
# to = "Community Spokesman <spokesman@ruby_community.org>"
|
# to = "Community Spokesman <spokesman@ruby_community.org>"
|
||||||
# priorities = [ "Run Ruby Quiz",
|
# priorities = [ "Run Ruby Quiz",
|
||||||
# "Document Modules",
|
# "Document Modules",
|
||||||
# "Answer Questions on Ruby Talk" ]
|
# "Answer Questions on Ruby Talk" ]
|
||||||
#
|
#
|
||||||
# # Produce result.
|
# # Produce result.
|
||||||
# email = message.result
|
# email = message.result
|
||||||
# puts email
|
# puts email
|
||||||
|
@ -110,19 +110,19 @@
|
||||||
# From: James Edward Gray II <james@grayproductions.net>
|
# From: James Edward Gray II <james@grayproductions.net>
|
||||||
# To: Community Spokesman <spokesman@ruby_community.org>
|
# To: Community Spokesman <spokesman@ruby_community.org>
|
||||||
# Subject: Addressing Needs
|
# Subject: Addressing Needs
|
||||||
#
|
#
|
||||||
# Community:
|
# Community:
|
||||||
#
|
#
|
||||||
# Just wanted to send a quick note assuring that your needs are being addressed.
|
# Just wanted to send a quick note assuring that your needs are being addressed.
|
||||||
#
|
#
|
||||||
# I want you to know that my team will keep working on the issues, especially:
|
# I want you to know that my team will keep working on the issues, especially:
|
||||||
#
|
#
|
||||||
# * Run Ruby Quiz
|
# * Run Ruby Quiz
|
||||||
# * Document Modules
|
# * Document Modules
|
||||||
# * Answer Questions on Ruby Talk
|
# * Answer Questions on Ruby Talk
|
||||||
#
|
#
|
||||||
# Thanks for your patience.
|
# Thanks for your patience.
|
||||||
#
|
#
|
||||||
# James Edward Gray II
|
# James Edward Gray II
|
||||||
#
|
#
|
||||||
# === Ruby in HTML
|
# === Ruby in HTML
|
||||||
|
@ -132,7 +132,7 @@
|
||||||
# variables in the Product object can be resolved.
|
# variables in the Product object can be resolved.
|
||||||
#
|
#
|
||||||
# require "erb"
|
# require "erb"
|
||||||
#
|
#
|
||||||
# # Build template data class.
|
# # Build template data class.
|
||||||
# class Product
|
# class Product
|
||||||
# def initialize( code, name, desc, cost )
|
# def initialize( code, name, desc, cost )
|
||||||
|
@ -140,37 +140,37 @@
|
||||||
# @name = name
|
# @name = name
|
||||||
# @desc = desc
|
# @desc = desc
|
||||||
# @cost = cost
|
# @cost = cost
|
||||||
#
|
#
|
||||||
# @features = [ ]
|
# @features = [ ]
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def add_feature( feature )
|
# def add_feature( feature )
|
||||||
# @features << feature
|
# @features << feature
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # Support templating of member data.
|
# # Support templating of member data.
|
||||||
# def get_binding
|
# def get_binding
|
||||||
# binding
|
# binding
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # Create template.
|
# # Create template.
|
||||||
# template = %{
|
# template = %{
|
||||||
# <html>
|
# <html>
|
||||||
# <head><title>Ruby Toys -- <%= @name %></title></head>
|
# <head><title>Ruby Toys -- <%= @name %></title></head>
|
||||||
# <body>
|
# <body>
|
||||||
#
|
#
|
||||||
# <h1><%= @name %> (<%= @code %>)</h1>
|
# <h1><%= @name %> (<%= @code %>)</h1>
|
||||||
# <p><%= @desc %></p>
|
# <p><%= @desc %></p>
|
||||||
#
|
#
|
||||||
# <ul>
|
# <ul>
|
||||||
# <% @features.each do |f| %>
|
# <% @features.each do |f| %>
|
||||||
# <li><b><%= f %></b></li>
|
# <li><b><%= f %></b></li>
|
||||||
# <% end %>
|
# <% end %>
|
||||||
# </ul>
|
# </ul>
|
||||||
#
|
#
|
||||||
# <p>
|
# <p>
|
||||||
# <% if @cost < 10 %>
|
# <% if @cost < 10 %>
|
||||||
# <b>Only <%= @cost %>!!!</b>
|
# <b>Only <%= @cost %>!!!</b>
|
||||||
|
@ -178,13 +178,13 @@
|
||||||
# Call for a price, today!
|
# Call for a price, today!
|
||||||
# <% end %>
|
# <% end %>
|
||||||
# </p>
|
# </p>
|
||||||
#
|
#
|
||||||
# </body>
|
# </body>
|
||||||
# </html>
|
# </html>
|
||||||
# }.gsub(/^ /, '')
|
# }.gsub(/^ /, '')
|
||||||
#
|
#
|
||||||
# rhtml = ERB.new(template)
|
# rhtml = ERB.new(template)
|
||||||
#
|
#
|
||||||
# # Set up template data.
|
# # Set up template data.
|
||||||
# toy = Product.new( "TZ-1002",
|
# toy = Product.new( "TZ-1002",
|
||||||
# "Rubysapien",
|
# "Rubysapien",
|
||||||
|
@ -195,7 +195,7 @@
|
||||||
# toy.add_feature("Karate-Chop Action!!!")
|
# toy.add_feature("Karate-Chop Action!!!")
|
||||||
# toy.add_feature("Matz signature on left leg.")
|
# toy.add_feature("Matz signature on left leg.")
|
||||||
# toy.add_feature("Gem studded eyes... Rubies, of course!")
|
# toy.add_feature("Gem studded eyes... Rubies, of course!")
|
||||||
#
|
#
|
||||||
# # Produce result.
|
# # Produce result.
|
||||||
# rhtml.run(toy.get_binding)
|
# rhtml.run(toy.get_binding)
|
||||||
#
|
#
|
||||||
|
@ -204,10 +204,10 @@
|
||||||
# <html>
|
# <html>
|
||||||
# <head><title>Ruby Toys -- Rubysapien</title></head>
|
# <head><title>Ruby Toys -- Rubysapien</title></head>
|
||||||
# <body>
|
# <body>
|
||||||
#
|
#
|
||||||
# <h1>Rubysapien (TZ-1002)</h1>
|
# <h1>Rubysapien (TZ-1002)</h1>
|
||||||
# <p>Geek's Best Friend! Responds to Ruby commands...</p>
|
# <p>Geek's Best Friend! Responds to Ruby commands...</p>
|
||||||
#
|
#
|
||||||
# <ul>
|
# <ul>
|
||||||
# <li><b>Listens for verbal commands in the Ruby language!</b></li>
|
# <li><b>Listens for verbal commands in the Ruby language!</b></li>
|
||||||
# <li><b>Ignores Perl, Java, and all C variants.</b></li>
|
# <li><b>Ignores Perl, Java, and all C variants.</b></li>
|
||||||
|
@ -215,15 +215,15 @@
|
||||||
# <li><b>Matz signature on left leg.</b></li>
|
# <li><b>Matz signature on left leg.</b></li>
|
||||||
# <li><b>Gem studded eyes... Rubies, of course!</b></li>
|
# <li><b>Gem studded eyes... Rubies, of course!</b></li>
|
||||||
# </ul>
|
# </ul>
|
||||||
#
|
#
|
||||||
# <p>
|
# <p>
|
||||||
# Call for a price, today!
|
# Call for a price, today!
|
||||||
# </p>
|
# </p>
|
||||||
#
|
#
|
||||||
# </body>
|
# </body>
|
||||||
# </html>
|
# </html>
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# == Notes
|
# == Notes
|
||||||
#
|
#
|
||||||
# There are a variety of templating solutions available in various Ruby projects:
|
# There are a variety of templating solutions available in various Ruby projects:
|
||||||
|
@ -300,7 +300,7 @@ class ERB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
attr_accessor :stag
|
attr_accessor :stag
|
||||||
|
|
||||||
def scan(&block)
|
def scan(&block)
|
||||||
@stag = nil
|
@stag = nil
|
||||||
if @percent
|
if @percent
|
||||||
|
@ -407,7 +407,7 @@ class ERB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Scanner.regist_scanner(SimpleScanner, nil, false)
|
Scanner.regist_scanner(SimpleScanner, nil, false)
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -466,13 +466,13 @@ class ERB
|
||||||
def push(cmd)
|
def push(cmd)
|
||||||
@line << cmd
|
@line << cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
def cr
|
def cr
|
||||||
@script << (@line.join('; '))
|
@script << (@line.join('; '))
|
||||||
@line = []
|
@line = []
|
||||||
@script << "\n"
|
@script << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
return unless @line
|
return unless @line
|
||||||
@compiler.post_cmd.each do |x|
|
@compiler.post_cmd.each do |x|
|
||||||
|
@ -498,7 +498,7 @@ class ERB
|
||||||
content = ''
|
content = ''
|
||||||
scanner = make_scanner(s)
|
scanner = make_scanner(s)
|
||||||
scanner.scan do |token|
|
scanner.scan do |token|
|
||||||
next if token.nil?
|
next if token.nil?
|
||||||
next if token == ''
|
next if token == ''
|
||||||
if scanner.stag.nil?
|
if scanner.stag.nil?
|
||||||
case token
|
case token
|
||||||
|
@ -598,19 +598,19 @@ end
|
||||||
class ERB
|
class ERB
|
||||||
#
|
#
|
||||||
# Constructs a new ERB object with the template specified in _str_.
|
# Constructs a new ERB object with the template specified in _str_.
|
||||||
#
|
#
|
||||||
# An ERB object works by building a chunk of Ruby code that will output
|
# An ERB object works by building a chunk of Ruby code that will output
|
||||||
# the completed template when run. If _safe_level_ is set to a non-nil value,
|
# the completed template when run. If _safe_level_ is set to a non-nil value,
|
||||||
# ERB code will be run in a separate thread with <b>$SAFE</b> set to the
|
# ERB code will be run in a separate thread with <b>$SAFE</b> set to the
|
||||||
# provided level.
|
# provided level.
|
||||||
#
|
#
|
||||||
# If _trim_mode_ is passed a String containing one or more of the following
|
# If _trim_mode_ is passed a String containing one or more of the following
|
||||||
# modifiers, ERB will adjust its code generation as listed:
|
# modifiers, ERB will adjust its code generation as listed:
|
||||||
#
|
#
|
||||||
# % enables Ruby code processing for lines beginning with %
|
# % enables Ruby code processing for lines beginning with %
|
||||||
# <> omit newline for lines starting with <% and ending in %>
|
# <> omit newline for lines starting with <% and ending in %>
|
||||||
# > omit newline for lines ending in %>
|
# > omit newline for lines ending in %>
|
||||||
#
|
#
|
||||||
# _eoutvar_ can be used to set the name of the variable ERB will build up
|
# _eoutvar_ can be used to set the name of the variable ERB will build up
|
||||||
# its output in. This is useful when you need to run multiple ERB
|
# its output in. This is useful when you need to run multiple ERB
|
||||||
# templates through the same binding and/or when you want to control where
|
# templates through the same binding and/or when you want to control where
|
||||||
|
@ -619,20 +619,20 @@ class ERB
|
||||||
# === Example
|
# === Example
|
||||||
#
|
#
|
||||||
# require "erb"
|
# require "erb"
|
||||||
#
|
#
|
||||||
# # build data class
|
# # build data class
|
||||||
# class Listings
|
# class Listings
|
||||||
# PRODUCT = { :name => "Chicken Fried Steak",
|
# PRODUCT = { :name => "Chicken Fried Steak",
|
||||||
# :desc => "A well messages pattie, breaded and fried.",
|
# :desc => "A well messages pattie, breaded and fried.",
|
||||||
# :cost => 9.95 }
|
# :cost => 9.95 }
|
||||||
#
|
#
|
||||||
# attr_reader :product, :price
|
# attr_reader :product, :price
|
||||||
#
|
#
|
||||||
# def initialize( product = "", price = "" )
|
# def initialize( product = "", price = "" )
|
||||||
# @product = product
|
# @product = product
|
||||||
# @price = price
|
# @price = price
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# def build
|
# def build
|
||||||
# b = binding
|
# b = binding
|
||||||
# # create and run templates, filling member data variables
|
# # create and run templates, filling member data variables
|
||||||
|
@ -646,21 +646,21 @@ class ERB
|
||||||
# END_PRICE
|
# END_PRICE
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # setup template data
|
# # setup template data
|
||||||
# listings = Listings.new
|
# listings = Listings.new
|
||||||
# listings.build
|
# listings.build
|
||||||
#
|
#
|
||||||
# puts listings.product + "\n" + listings.price
|
# puts listings.product + "\n" + listings.price
|
||||||
#
|
#
|
||||||
# _Generates_
|
# _Generates_
|
||||||
#
|
#
|
||||||
# Chicken Fried Steak
|
# Chicken Fried Steak
|
||||||
# A well messages pattie, breaded and fried.
|
# A well messages pattie, breaded and fried.
|
||||||
#
|
#
|
||||||
# Chicken Fried Steak -- 9.95
|
# Chicken Fried Steak -- 9.95
|
||||||
# A well messages pattie, breaded and fried.
|
# A well messages pattie, breaded and fried.
|
||||||
#
|
#
|
||||||
def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
|
def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
|
||||||
@safe_level = safe_level
|
@safe_level = safe_level
|
||||||
compiler = ERB::Compiler.new(trim_mode)
|
compiler = ERB::Compiler.new(trim_mode)
|
||||||
|
@ -687,7 +687,7 @@ class ERB
|
||||||
|
|
||||||
cmd = []
|
cmd = []
|
||||||
cmd.push "#{eoutvar} = ''"
|
cmd.push "#{eoutvar} = ''"
|
||||||
|
|
||||||
compiler.pre_cmd = cmd
|
compiler.pre_cmd = cmd
|
||||||
|
|
||||||
cmd = []
|
cmd = []
|
||||||
|
@ -705,13 +705,13 @@ class ERB
|
||||||
# Executes the generated ERB code to produce a completed template, returning
|
# Executes the generated ERB code to produce a completed template, returning
|
||||||
# the results of that code. (See ERB#new for details on how this process can
|
# the results of that code. (See ERB#new for details on how this process can
|
||||||
# be affected by _safe_level_.)
|
# be affected by _safe_level_.)
|
||||||
#
|
#
|
||||||
# _b_ accepts a Binding or Proc object which is used to set the context of
|
# _b_ accepts a Binding or Proc object which is used to set the context of
|
||||||
# code evaluation.
|
# code evaluation.
|
||||||
#
|
#
|
||||||
def result(b=TOPLEVEL_BINDING)
|
def result(b=TOPLEVEL_BINDING)
|
||||||
if @safe_level
|
if @safe_level
|
||||||
proc {
|
proc {
|
||||||
$SAFE = @safe_level
|
$SAFE = @safe_level
|
||||||
eval(@src, b, (@filename || '(erb)'), 1)
|
eval(@src, b, (@filename || '(erb)'), 1)
|
||||||
}.call
|
}.call
|
||||||
|
@ -775,14 +775,14 @@ class ERB
|
||||||
public
|
public
|
||||||
#
|
#
|
||||||
# A utility method for escaping HTML tag characters in _s_.
|
# A utility method for escaping HTML tag characters in _s_.
|
||||||
#
|
#
|
||||||
# require "erb"
|
# require "erb"
|
||||||
# include ERB::Util
|
# include ERB::Util
|
||||||
#
|
#
|
||||||
# puts html_escape("is a > 0 & a < 10?")
|
# puts html_escape("is a > 0 & a < 10?")
|
||||||
#
|
#
|
||||||
# _Generates_
|
# _Generates_
|
||||||
#
|
#
|
||||||
# is a > 0 & a < 10?
|
# is a > 0 & a < 10?
|
||||||
#
|
#
|
||||||
def html_escape(s)
|
def html_escape(s)
|
||||||
|
@ -791,17 +791,17 @@ class ERB
|
||||||
alias h html_escape
|
alias h html_escape
|
||||||
module_function :h
|
module_function :h
|
||||||
module_function :html_escape
|
module_function :html_escape
|
||||||
|
|
||||||
#
|
#
|
||||||
# A utility method for encoding the String _s_ as a URL.
|
# A utility method for encoding the String _s_ as a URL.
|
||||||
#
|
#
|
||||||
# require "erb"
|
# require "erb"
|
||||||
# include ERB::Util
|
# include ERB::Util
|
||||||
#
|
#
|
||||||
# puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
|
# puts url_encode("Programming Ruby: The Pragmatic Programmer's Guide")
|
||||||
#
|
#
|
||||||
# _Generates_
|
# _Generates_
|
||||||
#
|
#
|
||||||
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
|
# Programming%20Ruby%3A%20%20The%20Pragmatic%20Programmer%27s%20Guide
|
||||||
#
|
#
|
||||||
def url_encode(s)
|
def url_encode(s)
|
||||||
|
|
172
lib/fileutils.rb
172
lib/fileutils.rb
|
@ -1,17 +1,17 @@
|
||||||
#
|
#
|
||||||
# = fileutils.rb
|
# = fileutils.rb
|
||||||
#
|
#
|
||||||
# Copyright (c) 2000-2006 Minero Aoki
|
# Copyright (c) 2000-2006 Minero Aoki
|
||||||
#
|
#
|
||||||
# This program is free software.
|
# This program is free software.
|
||||||
# You can distribute/modify this program under the same terms of ruby.
|
# You can distribute/modify this program under the same terms of ruby.
|
||||||
#
|
#
|
||||||
# == module FileUtils
|
# == module FileUtils
|
||||||
#
|
#
|
||||||
# Namespace for several file utility methods for copying, moving, removing, etc.
|
# Namespace for several file utility methods for copying, moving, removing, etc.
|
||||||
#
|
#
|
||||||
# === Module Functions
|
# === Module Functions
|
||||||
#
|
#
|
||||||
# cd(dir, options)
|
# cd(dir, options)
|
||||||
# cd(dir, options) {|dir| .... }
|
# cd(dir, options) {|dir| .... }
|
||||||
# pwd()
|
# pwd()
|
||||||
|
@ -64,23 +64,23 @@
|
||||||
# uptodate?(file, cmp_list)
|
# uptodate?(file, cmp_list)
|
||||||
#
|
#
|
||||||
# == module FileUtils::Verbose
|
# == module FileUtils::Verbose
|
||||||
#
|
#
|
||||||
# This module has all methods of FileUtils module, but it outputs messages
|
# This module has all methods of FileUtils module, but it outputs messages
|
||||||
# before acting. This equates to passing the <tt>:verbose</tt> flag to methods
|
# before acting. This equates to passing the <tt>:verbose</tt> flag to methods
|
||||||
# in FileUtils.
|
# in FileUtils.
|
||||||
#
|
#
|
||||||
# == module FileUtils::NoWrite
|
# == module FileUtils::NoWrite
|
||||||
#
|
#
|
||||||
# This module has all methods of FileUtils module, but never changes
|
# This module has all methods of FileUtils module, but never changes
|
||||||
# files/directories. This equates to passing the <tt>:noop</tt> flag to methods
|
# files/directories. This equates to passing the <tt>:noop</tt> flag to methods
|
||||||
# in FileUtils.
|
# in FileUtils.
|
||||||
#
|
#
|
||||||
# == module FileUtils::DryRun
|
# == module FileUtils::DryRun
|
||||||
#
|
#
|
||||||
# This module has all methods of FileUtils module, but never changes
|
# This module has all methods of FileUtils module, but never changes
|
||||||
# files/directories. This equates to passing the <tt>:noop</tt> and
|
# files/directories. This equates to passing the <tt>:noop</tt> and
|
||||||
# <tt>:verbose</tt> flags to methods in FileUtils.
|
# <tt>:verbose</tt> flags to methods in FileUtils.
|
||||||
#
|
#
|
||||||
|
|
||||||
module FileUtils
|
module FileUtils
|
||||||
|
|
||||||
|
@ -107,14 +107,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: verbose
|
# Options: verbose
|
||||||
#
|
#
|
||||||
# Changes the current directory to the directory +dir+.
|
# Changes the current directory to the directory +dir+.
|
||||||
#
|
#
|
||||||
# If this method is called with block, resumes to the old
|
# If this method is called with block, resumes to the old
|
||||||
# working directory after the block execution finished.
|
# working directory after the block execution finished.
|
||||||
#
|
#
|
||||||
# FileUtils.cd('/', :verbose => true) # chdir and report it
|
# FileUtils.cd('/', :verbose => true) # chdir and report it
|
||||||
#
|
#
|
||||||
def cd(dir, options = {}, &block) # :yield: dir
|
def cd(dir, options = {}, &block) # :yield: dir
|
||||||
fu_check_options options, OPT_TABLE['cd']
|
fu_check_options options, OPT_TABLE['cd']
|
||||||
fu_output_message "cd #{dir}" if options[:verbose]
|
fu_output_message "cd #{dir}" if options[:verbose]
|
||||||
|
@ -131,13 +131,13 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: (none)
|
# Options: (none)
|
||||||
#
|
#
|
||||||
# Returns true if +newer+ is newer than all +old_list+.
|
# Returns true if +newer+ is newer than all +old_list+.
|
||||||
# Non-existent files are older than any file.
|
# Non-existent files are older than any file.
|
||||||
#
|
#
|
||||||
# FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
|
# FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
|
||||||
# system 'make hello.o'
|
# system 'make hello.o'
|
||||||
#
|
#
|
||||||
def uptodate?(new, old_list, options = nil)
|
def uptodate?(new, old_list, options = nil)
|
||||||
raise ArgumentError, 'uptodate? does not accept any option' if options
|
raise ArgumentError, 'uptodate? does not accept any option' if options
|
||||||
|
|
||||||
|
@ -154,14 +154,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: mode noop verbose
|
# Options: mode noop verbose
|
||||||
#
|
#
|
||||||
# Creates one or more directories.
|
# Creates one or more directories.
|
||||||
#
|
#
|
||||||
# FileUtils.mkdir 'test'
|
# FileUtils.mkdir 'test'
|
||||||
# FileUtils.mkdir %w( tmp data )
|
# FileUtils.mkdir %w( tmp data )
|
||||||
# FileUtils.mkdir 'notexist', :noop => true # Does not really create.
|
# FileUtils.mkdir 'notexist', :noop => true # Does not really create.
|
||||||
# FileUtils.mkdir 'tmp', :mode => 0700
|
# FileUtils.mkdir 'tmp', :mode => 0700
|
||||||
#
|
#
|
||||||
def mkdir(list, options = {})
|
def mkdir(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['mkdir']
|
fu_check_options options, OPT_TABLE['mkdir']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -178,12 +178,12 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: mode noop verbose
|
# Options: mode noop verbose
|
||||||
#
|
#
|
||||||
# Creates a directory and all its parent directories.
|
# Creates a directory and all its parent directories.
|
||||||
# For example,
|
# For example,
|
||||||
#
|
#
|
||||||
# FileUtils.mkdir_p '/usr/local/lib/ruby'
|
# FileUtils.mkdir_p '/usr/local/lib/ruby'
|
||||||
#
|
#
|
||||||
# causes to make following directories, if it does not exist.
|
# causes to make following directories, if it does not exist.
|
||||||
# * /usr
|
# * /usr
|
||||||
# * /usr/local
|
# * /usr/local
|
||||||
|
@ -191,7 +191,7 @@ module FileUtils
|
||||||
# * /usr/local/lib/ruby
|
# * /usr/local/lib/ruby
|
||||||
#
|
#
|
||||||
# You can pass several directories at a time in a list.
|
# You can pass several directories at a time in a list.
|
||||||
#
|
#
|
||||||
def mkdir_p(list, options = {})
|
def mkdir_p(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['mkdir_p']
|
fu_check_options options, OPT_TABLE['mkdir_p']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -247,14 +247,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop, verbose
|
# Options: noop, verbose
|
||||||
#
|
#
|
||||||
# Removes one or more directories.
|
# Removes one or more directories.
|
||||||
#
|
#
|
||||||
# FileUtils.rmdir 'somedir'
|
# FileUtils.rmdir 'somedir'
|
||||||
# FileUtils.rmdir %w(somedir anydir otherdir)
|
# FileUtils.rmdir %w(somedir anydir otherdir)
|
||||||
# # Does not really remove directory; outputs message.
|
# # Does not really remove directory; outputs message.
|
||||||
# FileUtils.rmdir 'somedir', :verbose => true, :noop => true
|
# FileUtils.rmdir 'somedir', :verbose => true, :noop => true
|
||||||
#
|
#
|
||||||
def rmdir(list, options = {})
|
def rmdir(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['rmdir']
|
fu_check_options options, OPT_TABLE['rmdir']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -277,19 +277,19 @@ module FileUtils
|
||||||
# If +new+ already exists and it is a directory, creates a link +new/old+.
|
# If +new+ already exists and it is a directory, creates a link +new/old+.
|
||||||
# If +new+ already exists and it is not a directory, raises Errno::EEXIST.
|
# If +new+ already exists and it is not a directory, raises Errno::EEXIST.
|
||||||
# But if :force option is set, overwrite +new+.
|
# But if :force option is set, overwrite +new+.
|
||||||
#
|
#
|
||||||
# FileUtils.ln 'gcc', 'cc', :verbose => true
|
# FileUtils.ln 'gcc', 'cc', :verbose => true
|
||||||
# FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
|
# FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
|
||||||
#
|
#
|
||||||
# <b><tt>ln(list, destdir, options = {})</tt></b>
|
# <b><tt>ln(list, destdir, options = {})</tt></b>
|
||||||
#
|
#
|
||||||
# Creates several hard links in a directory, with each one pointing to the
|
# Creates several hard links in a directory, with each one pointing to the
|
||||||
# item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
|
# item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
|
||||||
#
|
#
|
||||||
# include FileUtils
|
# include FileUtils
|
||||||
# cd '/sbin'
|
# cd '/sbin'
|
||||||
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
|
# FileUtils.ln %w(cp mv mkdir), '/bin' # Now /sbin/cp and /bin/cp are linked.
|
||||||
#
|
#
|
||||||
def ln(src, dest, options = {})
|
def ln(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['ln']
|
fu_check_options options, OPT_TABLE['ln']
|
||||||
fu_output_message "ln#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "ln#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
|
@ -311,24 +311,24 @@ module FileUtils
|
||||||
# Options: force noop verbose
|
# Options: force noop verbose
|
||||||
#
|
#
|
||||||
# <b><tt>ln_s(old, new, options = {})</tt></b>
|
# <b><tt>ln_s(old, new, options = {})</tt></b>
|
||||||
#
|
#
|
||||||
# Creates a symbolic link +new+ which points to +old+. If +new+ already
|
# Creates a symbolic link +new+ which points to +old+. If +new+ already
|
||||||
# exists and it is a directory, creates a symbolic link +new/old+. If +new+
|
# exists and it is a directory, creates a symbolic link +new/old+. If +new+
|
||||||
# already exists and it is not a directory, raises Errno::EEXIST. But if
|
# already exists and it is not a directory, raises Errno::EEXIST. But if
|
||||||
# :force option is set, overwrite +new+.
|
# :force option is set, overwrite +new+.
|
||||||
#
|
#
|
||||||
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
|
# FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
|
||||||
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', :force => true
|
# FileUtils.ln_s 'verylongsourcefilename.c', 'c', :force => true
|
||||||
#
|
#
|
||||||
# <b><tt>ln_s(list, destdir, options = {})</tt></b>
|
# <b><tt>ln_s(list, destdir, options = {})</tt></b>
|
||||||
#
|
#
|
||||||
# Creates several symbolic links in a directory, with each one pointing to the
|
# Creates several symbolic links in a directory, with each one pointing to the
|
||||||
# item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
|
# item in +list+. If +destdir+ is not a directory, raises Errno::ENOTDIR.
|
||||||
#
|
#
|
||||||
# If +destdir+ is not a directory, raises Errno::ENOTDIR.
|
# If +destdir+ is not a directory, raises Errno::ENOTDIR.
|
||||||
#
|
#
|
||||||
# FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
|
# FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
|
||||||
#
|
#
|
||||||
def ln_s(src, dest, options = {})
|
def ln_s(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['ln_s']
|
fu_check_options options, OPT_TABLE['ln_s']
|
||||||
fu_output_message "ln -s#{options[:force] ? 'f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "ln -s#{options[:force] ? 'f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
|
@ -348,10 +348,10 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
#
|
#
|
||||||
# Same as
|
# Same as
|
||||||
# #ln_s(src, dest, :force)
|
# #ln_s(src, dest, :force)
|
||||||
#
|
#
|
||||||
def ln_sf(src, dest, options = {})
|
def ln_sf(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['ln_sf']
|
fu_check_options options, OPT_TABLE['ln_sf']
|
||||||
options = options.dup
|
options = options.dup
|
||||||
|
@ -374,7 +374,7 @@ module FileUtils
|
||||||
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
|
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
|
||||||
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true
|
# FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true
|
||||||
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
|
# FileUtils.cp 'symlink', 'dest' # copy content, "dest" is not a symlink
|
||||||
#
|
#
|
||||||
def cp(src, dest, options = {})
|
def cp(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['cp']
|
fu_check_options options, OPT_TABLE['cp']
|
||||||
fu_output_message "cp#{options[:preserve] ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "cp#{options[:preserve] ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
|
@ -393,17 +393,17 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: preserve noop verbose dereference_root remove_destination
|
# Options: preserve noop verbose dereference_root remove_destination
|
||||||
#
|
#
|
||||||
# Copies +src+ to +dest+. If +src+ is a directory, this method copies
|
# Copies +src+ to +dest+. If +src+ is a directory, this method copies
|
||||||
# all its contents recursively. If +dest+ is a directory, copies
|
# all its contents recursively. If +dest+ is a directory, copies
|
||||||
# +src+ to +dest/src+.
|
# +src+ to +dest/src+.
|
||||||
#
|
#
|
||||||
# +src+ can be a list of files.
|
# +src+ can be a list of files.
|
||||||
#
|
#
|
||||||
# # Installing ruby library "mylib" under the site_ruby
|
# # Installing ruby library "mylib" under the site_ruby
|
||||||
# FileUtils.rm_r site_ruby + '/mylib', :force
|
# FileUtils.rm_r site_ruby + '/mylib', :force
|
||||||
# FileUtils.cp_r 'lib/', site_ruby + '/mylib'
|
# FileUtils.cp_r 'lib/', site_ruby + '/mylib'
|
||||||
#
|
#
|
||||||
# # Examples of copying several files to target directory.
|
# # Examples of copying several files to target directory.
|
||||||
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
|
# FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
|
||||||
# FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
|
# FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop => true, :verbose => true
|
||||||
|
@ -413,7 +413,7 @@ module FileUtils
|
||||||
# # use following code.
|
# # use following code.
|
||||||
# FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes src/dest,
|
# FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes src/dest,
|
||||||
# # but this doesn't.
|
# # but this doesn't.
|
||||||
#
|
#
|
||||||
def cp_r(src, dest, options = {})
|
def cp_r(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['cp_r']
|
fu_check_options options, OPT_TABLE['cp_r']
|
||||||
fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "cp -r#{options[:preserve] ? 'p' : ''}#{options[:remove_destination] ? ' --remove-destination' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
|
@ -477,17 +477,17 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: force noop verbose
|
# Options: force noop verbose
|
||||||
#
|
#
|
||||||
# Moves file(s) +src+ to +dest+. If +file+ and +dest+ exist on the different
|
# Moves file(s) +src+ to +dest+. If +file+ and +dest+ exist on the different
|
||||||
# disk partition, the copied file is created on the +dest+ and the original
|
# disk partition, the copied file is created on the +dest+ and the original
|
||||||
# file removed from +src+.
|
# file removed from +src+.
|
||||||
#
|
#
|
||||||
# FileUtils.mv 'badname.rb', 'goodname.rb'
|
# FileUtils.mv 'badname.rb', 'goodname.rb'
|
||||||
# FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', :force => true # no error
|
# FileUtils.mv 'stuff.rb', '/notexist/lib/ruby', :force => true # no error
|
||||||
#
|
#
|
||||||
# FileUtils.mv %w(junk.txt dust.txt), '/home/aamine/.trash/'
|
# FileUtils.mv %w(junk.txt dust.txt), '/home/aamine/.trash/'
|
||||||
# FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
|
# FileUtils.mv Dir.glob('test*.rb'), 'test', :noop => true, :verbose => true
|
||||||
#
|
#
|
||||||
def mv(src, dest, options = {})
|
def mv(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['mv']
|
fu_check_options options, OPT_TABLE['mv']
|
||||||
fu_output_message "mv#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "mv#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
|
@ -532,14 +532,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: force noop verbose
|
# Options: force noop verbose
|
||||||
#
|
#
|
||||||
# Remove file(s) specified in +list+. This method cannot remove directories.
|
# Remove file(s) specified in +list+. This method cannot remove directories.
|
||||||
# All StandardErrors are ignored when the :force option is set.
|
# All StandardErrors are ignored when the :force option is set.
|
||||||
#
|
#
|
||||||
# FileUtils.rm %w( junk.txt dust.txt )
|
# FileUtils.rm %w( junk.txt dust.txt )
|
||||||
# FileUtils.rm Dir.glob('*.so')
|
# FileUtils.rm Dir.glob('*.so')
|
||||||
# FileUtils.rm 'NotExistFile', :force => true # never raises exception
|
# FileUtils.rm 'NotExistFile', :force => true # never raises exception
|
||||||
#
|
#
|
||||||
def rm(list, options = {})
|
def rm(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['rm']
|
fu_check_options options, OPT_TABLE['rm']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -560,7 +560,7 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
#
|
#
|
||||||
# Equivalent to
|
# Equivalent to
|
||||||
#
|
#
|
||||||
# #rm(list, :force => true)
|
# #rm(list, :force => true)
|
||||||
|
@ -581,11 +581,11 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: force noop verbose secure
|
# Options: force noop verbose secure
|
||||||
#
|
#
|
||||||
# remove files +list+[0] +list+[1]... If +list+[n] is a directory,
|
# remove files +list+[0] +list+[1]... If +list+[n] is a directory,
|
||||||
# removes its all contents recursively. This method ignores
|
# removes its all contents recursively. This method ignores
|
||||||
# StandardError when :force option is set.
|
# StandardError when :force option is set.
|
||||||
#
|
#
|
||||||
# FileUtils.rm_r Dir.glob('/tmp/*')
|
# FileUtils.rm_r Dir.glob('/tmp/*')
|
||||||
# FileUtils.rm_r '/', :force => true # :-)
|
# FileUtils.rm_r '/', :force => true # :-)
|
||||||
#
|
#
|
||||||
|
@ -599,7 +599,7 @@ module FileUtils
|
||||||
#
|
#
|
||||||
# NOTE: This method calls #remove_entry_secure if :secure option is set.
|
# NOTE: This method calls #remove_entry_secure if :secure option is set.
|
||||||
# See also #remove_entry_secure.
|
# See also #remove_entry_secure.
|
||||||
#
|
#
|
||||||
def rm_r(list, options = {})
|
def rm_r(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['rm_r']
|
fu_check_options options, OPT_TABLE['rm_r']
|
||||||
# options[:secure] = true unless options.key?(:secure)
|
# options[:secure] = true unless options.key?(:secure)
|
||||||
|
@ -620,14 +620,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose secure
|
# Options: noop verbose secure
|
||||||
#
|
#
|
||||||
# Equivalent to
|
# Equivalent to
|
||||||
#
|
#
|
||||||
# #rm_r(list, :force => true)
|
# #rm_r(list, :force => true)
|
||||||
#
|
#
|
||||||
# WARNING: This method causes local vulnerability.
|
# WARNING: This method causes local vulnerability.
|
||||||
# Read the documentation of #rm_r first.
|
# Read the documentation of #rm_r first.
|
||||||
#
|
#
|
||||||
def rm_rf(list, options = {})
|
def rm_rf(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['rm_rf']
|
fu_check_options options, OPT_TABLE['rm_rf']
|
||||||
options = options.dup
|
options = options.dup
|
||||||
|
@ -786,7 +786,7 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Returns true if the contents of a file A and a file B are identical.
|
# Returns true if the contents of a file A and a file B are identical.
|
||||||
#
|
#
|
||||||
# FileUtils.compare_file('somefile', 'somefile') #=> true
|
# FileUtils.compare_file('somefile', 'somefile') #=> true
|
||||||
# FileUtils.compare_file('/bin/cp', '/bin/mv') #=> maybe false
|
# FileUtils.compare_file('/bin/cp', '/bin/mv') #=> maybe false
|
||||||
#
|
#
|
||||||
|
@ -826,14 +826,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: mode preserve noop verbose
|
# Options: mode preserve noop verbose
|
||||||
#
|
#
|
||||||
# If +src+ is not same as +dest+, copies it and changes the permission
|
# If +src+ is not same as +dest+, copies it and changes the permission
|
||||||
# mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
|
# mode to +mode+. If +dest+ is a directory, destination is +dest+/+src+.
|
||||||
# This method removes destination before copy.
|
# This method removes destination before copy.
|
||||||
#
|
#
|
||||||
# FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
|
# FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
|
||||||
# FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
|
# FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
|
||||||
#
|
#
|
||||||
def install(src, dest, options = {})
|
def install(src, dest, options = {})
|
||||||
fu_check_options options, OPT_TABLE['install']
|
fu_check_options options, OPT_TABLE['install']
|
||||||
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
|
||||||
|
@ -854,14 +854,14 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
#
|
#
|
||||||
# Changes permission bits on the named files (in +list+) to the bit pattern
|
# Changes permission bits on the named files (in +list+) to the bit pattern
|
||||||
# represented by +mode+.
|
# represented by +mode+.
|
||||||
#
|
#
|
||||||
# FileUtils.chmod 0755, 'somecommand'
|
# FileUtils.chmod 0755, 'somecommand'
|
||||||
# FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
|
# FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
|
||||||
# FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
|
# FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
|
||||||
#
|
#
|
||||||
def chmod(mode, list, options = {})
|
def chmod(mode, list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['chmod']
|
fu_check_options options, OPT_TABLE['chmod']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -877,12 +877,12 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose force
|
# Options: noop verbose force
|
||||||
#
|
#
|
||||||
# Changes permission bits on the named files (in +list+)
|
# Changes permission bits on the named files (in +list+)
|
||||||
# to the bit pattern represented by +mode+.
|
# to the bit pattern represented by +mode+.
|
||||||
#
|
#
|
||||||
# FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
|
# FileUtils.chmod_R 0700, "/tmp/app.#{$$}"
|
||||||
#
|
#
|
||||||
def chmod_R(mode, list, options = {})
|
def chmod_R(mode, list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['chmod_R']
|
fu_check_options options, OPT_TABLE['chmod_R']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -906,16 +906,16 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
#
|
#
|
||||||
# Changes owner and group on the named files (in +list+)
|
# Changes owner and group on the named files (in +list+)
|
||||||
# to the user +user+ and the group +group+. +user+ and +group+
|
# to the user +user+ and the group +group+. +user+ and +group+
|
||||||
# may be an ID (Integer/String) or a name (String).
|
# may be an ID (Integer/String) or a name (String).
|
||||||
# If +user+ or +group+ is nil, this method does not change
|
# If +user+ or +group+ is nil, this method does not change
|
||||||
# the attribute.
|
# the attribute.
|
||||||
#
|
#
|
||||||
# FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby'
|
# FileUtils.chown 'root', 'staff', '/usr/local/bin/ruby'
|
||||||
# FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true
|
# FileUtils.chown nil, 'bin', Dir.glob('/usr/bin/*'), :verbose => true
|
||||||
#
|
#
|
||||||
def chown(user, group, list, options = {})
|
def chown(user, group, list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['chown']
|
fu_check_options options, OPT_TABLE['chown']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -935,16 +935,16 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose force
|
# Options: noop verbose force
|
||||||
#
|
#
|
||||||
# Changes owner and group on the named files (in +list+)
|
# Changes owner and group on the named files (in +list+)
|
||||||
# to the user +user+ and the group +group+ recursively.
|
# to the user +user+ and the group +group+ recursively.
|
||||||
# +user+ and +group+ may be an ID (Integer/String) or
|
# +user+ and +group+ may be an ID (Integer/String) or
|
||||||
# a name (String). If +user+ or +group+ is nil, this
|
# a name (String). If +user+ or +group+ is nil, this
|
||||||
# method does not change the attribute.
|
# method does not change the attribute.
|
||||||
#
|
#
|
||||||
# FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
|
# FileUtils.chown_R 'www', 'www', '/var/www/htdocs'
|
||||||
# FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true
|
# FileUtils.chown_R 'cvs', 'cvs', '/var/cvs', :verbose => true
|
||||||
#
|
#
|
||||||
def chown_R(user, group, list, options = {})
|
def chown_R(user, group, list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['chown_R']
|
fu_check_options options, OPT_TABLE['chown_R']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -1015,13 +1015,13 @@ module FileUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Options: noop verbose
|
# Options: noop verbose
|
||||||
#
|
#
|
||||||
# Updates modification time (mtime) and access time (atime) of file(s) in
|
# Updates modification time (mtime) and access time (atime) of file(s) in
|
||||||
# +list+. Files are created if they don't exist.
|
# +list+. Files are created if they don't exist.
|
||||||
#
|
#
|
||||||
# FileUtils.touch 'timestamp'
|
# FileUtils.touch 'timestamp'
|
||||||
# FileUtils.touch Dir.glob('*.c'); system 'make'
|
# FileUtils.touch Dir.glob('*.c'); system 'make'
|
||||||
#
|
#
|
||||||
def touch(list, options = {})
|
def touch(list, options = {})
|
||||||
fu_check_options options, OPT_TABLE['touch']
|
fu_check_options options, OPT_TABLE['touch']
|
||||||
list = fu_list(list)
|
list = fu_list(list)
|
||||||
|
@ -1520,11 +1520,11 @@ module FileUtils
|
||||||
METHODS = singleton_methods() - %w( private_module_function
|
METHODS = singleton_methods() - %w( private_module_function
|
||||||
commands options have_option? options_of collect_method )
|
commands options have_option? options_of collect_method )
|
||||||
|
|
||||||
#
|
#
|
||||||
# This module has all methods of FileUtils module, but it outputs messages
|
# This module has all methods of FileUtils module, but it outputs messages
|
||||||
# before acting. This equates to passing the <tt>:verbose</tt> flag to
|
# before acting. This equates to passing the <tt>:verbose</tt> flag to
|
||||||
# methods in FileUtils.
|
# methods in FileUtils.
|
||||||
#
|
#
|
||||||
module Verbose
|
module Verbose
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@fileutils_output = $stderr
|
@fileutils_output = $stderr
|
||||||
|
@ -1545,11 +1545,11 @@ module FileUtils
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# This module has all methods of FileUtils module, but never changes
|
# This module has all methods of FileUtils module, but never changes
|
||||||
# files/directories. This equates to passing the <tt>:noop</tt> flag
|
# files/directories. This equates to passing the <tt>:noop</tt> flag
|
||||||
# to methods in FileUtils.
|
# to methods in FileUtils.
|
||||||
#
|
#
|
||||||
module NoWrite
|
module NoWrite
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@fileutils_output = $stderr
|
@fileutils_output = $stderr
|
||||||
|
@ -1570,12 +1570,12 @@ module FileUtils
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# This module has all methods of FileUtils module, but never changes
|
# This module has all methods of FileUtils module, but never changes
|
||||||
# files/directories, with printing message before acting.
|
# files/directories, with printing message before acting.
|
||||||
# This equates to passing the <tt>:noop</tt> and <tt>:verbose</tt> flag
|
# This equates to passing the <tt>:noop</tt> and <tt>:verbose</tt> flag
|
||||||
# to methods in FileUtils.
|
# to methods in FileUtils.
|
||||||
#
|
#
|
||||||
module DryRun
|
module DryRun
|
||||||
include FileUtils
|
include FileUtils
|
||||||
@fileutils_output = $stderr
|
@fileutils_output = $stderr
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#--
|
#--
|
||||||
# finalizer.rb -
|
# finalizer.rb -
|
||||||
# $Release Version: 0.3$
|
# $Release Version: 0.3$
|
||||||
# $Revision: 1.4 $
|
# $Revision: 1.4 $
|
||||||
# $Date: 1998/02/27 05:34:33 $
|
# $Date: 1998/02/27 05:34:33 $
|
||||||
|
|
|
@ -33,28 +33,28 @@
|
||||||
#
|
#
|
||||||
# class Queue
|
# class Queue
|
||||||
# extend Forwardable
|
# extend Forwardable
|
||||||
#
|
#
|
||||||
# def initialize
|
# def initialize
|
||||||
# @q = [ ] # prepare delegate object
|
# @q = [ ] # prepare delegate object
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# # setup preferred interface, enq() and deq()...
|
# # setup preferred interface, enq() and deq()...
|
||||||
# def_delegator :@q, :push, :enq
|
# def_delegator :@q, :push, :enq
|
||||||
# def_delegator :@q, :shift, :deq
|
# def_delegator :@q, :shift, :deq
|
||||||
#
|
#
|
||||||
# # support some general Array methods that fit Queues well
|
# # support some general Array methods that fit Queues well
|
||||||
# def_delegators :@q, :clear, :first, :push, :shift, :size
|
# def_delegators :@q, :clear, :first, :push, :shift, :size
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# q = Queue.new
|
# q = Queue.new
|
||||||
# q.enq 1, 2, 3, 4, 5
|
# q.enq 1, 2, 3, 4, 5
|
||||||
# q.push 6
|
# q.push 6
|
||||||
#
|
#
|
||||||
# q.shift # => 1
|
# q.shift # => 1
|
||||||
# while q.size > 0
|
# while q.size > 0
|
||||||
# puts q.deq
|
# puts q.deq
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# q.enq "Ruby", "Perl", "Python"
|
# q.enq "Ruby", "Perl", "Python"
|
||||||
# puts q.first
|
# puts q.first
|
||||||
# q.clear
|
# q.clear
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#
|
#
|
||||||
# = ftools.rb: Extra tools for the File class
|
# = ftools.rb: Extra tools for the File class
|
||||||
#
|
#
|
||||||
# Author:: WATANABE, Hirofumi
|
# Author:: WATANABE, Hirofumi
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
# creating a directory path. See the File class for details.
|
# creating a directory path. See the File class for details.
|
||||||
#
|
#
|
||||||
# FileUtils contains all or nearly all the same functionality and more, and
|
# FileUtils contains all or nearly all the same functionality and more, and
|
||||||
# is a recommended option over ftools
|
# is a recommended option over ftools
|
||||||
#
|
#
|
||||||
# When you
|
# When you
|
||||||
#
|
#
|
||||||
|
@ -39,7 +39,7 @@ class << File
|
||||||
# If +to+ is a valid directory, +from+ will be appended to +to+, adding
|
# If +to+ is a valid directory, +from+ will be appended to +to+, adding
|
||||||
# and escaping backslashes as necessary. Otherwise, +to+ will be returned.
|
# and escaping backslashes as necessary. Otherwise, +to+ will be returned.
|
||||||
# Useful for appending +from+ to +to+ only if the filename was not specified
|
# Useful for appending +from+ to +to+ only if the filename was not specified
|
||||||
# in +to+.
|
# in +to+.
|
||||||
#
|
#
|
||||||
def catname(from, to)
|
def catname(from, to)
|
||||||
if directory? to
|
if directory? to
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
# while g.next?
|
# while g.next?
|
||||||
# puts g.next
|
# puts g.next
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class Generator
|
class Generator
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ class Enumerator
|
||||||
return g.next unless g.end?
|
return g.next unless g.end?
|
||||||
|
|
||||||
g.rewind
|
g.rewind
|
||||||
raise StopIteration, 'iteration reached at end'
|
raise StopIteration, 'iteration reached at end'
|
||||||
end
|
end
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
# found at http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/
|
# found at http://www.sra.co.jp/people/m-kasahr/ruby/getoptlong/
|
||||||
|
|
||||||
# The GetoptLong class allows you to parse command line options similarly to
|
# The GetoptLong class allows you to parse command line options similarly to
|
||||||
# the GNU getopt_long() C library call. Note, however, that GetoptLong is a
|
# the GNU getopt_long() C library call. Note, however, that GetoptLong is a
|
||||||
# pure Ruby implementation.
|
# pure Ruby implementation.
|
||||||
#
|
#
|
||||||
# GetoptLong allows for POSIX-style options like <tt>--file</tt> as well
|
# GetoptLong allows for POSIX-style options like <tt>--file</tt> as well
|
||||||
# as single letter options like <tt>-f</tt>
|
# as single letter options like <tt>-f</tt>
|
||||||
#
|
#
|
||||||
# The empty option <tt>--</tt> (two minus symbols) is used to end option
|
# The empty option <tt>--</tt> (two minus symbols) is used to end option
|
||||||
|
@ -42,16 +42,16 @@
|
||||||
# # greet user by name, if name not supplied default is John
|
# # greet user by name, if name not supplied default is John
|
||||||
# #
|
# #
|
||||||
# # DIR: The directory in which to issue the greeting.
|
# # DIR: The directory in which to issue the greeting.
|
||||||
#
|
#
|
||||||
# require 'getoptlong'
|
# require 'getoptlong'
|
||||||
# require 'rdoc/usage'
|
# require 'rdoc/usage'
|
||||||
#
|
#
|
||||||
# opts = GetoptLong.new(
|
# opts = GetoptLong.new(
|
||||||
# [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
# [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
|
||||||
# [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ],
|
# [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ],
|
||||||
# [ '--name', GetoptLong::OPTIONAL_ARGUMENT ]
|
# [ '--name', GetoptLong::OPTIONAL_ARGUMENT ]
|
||||||
# )
|
# )
|
||||||
#
|
#
|
||||||
# dir = nil
|
# dir = nil
|
||||||
# name = nil
|
# name = nil
|
||||||
# repetitions = 1
|
# repetitions = 1
|
||||||
|
@ -69,14 +69,14 @@
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# if ARGV.length != 1
|
# if ARGV.length != 1
|
||||||
# puts "Missing dir argument (try --help)"
|
# puts "Missing dir argument (try --help)"
|
||||||
# exit 0
|
# exit 0
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# dir = ARGV.shift
|
# dir = ARGV.shift
|
||||||
#
|
#
|
||||||
# Dir.chdir(dir)
|
# Dir.chdir(dir)
|
||||||
# for i in (1..repetitions)
|
# for i in (1..repetitions)
|
||||||
# print "Hello"
|
# print "Hello"
|
||||||
|
@ -120,7 +120,7 @@ class GetoptLong
|
||||||
# Set up option processing.
|
# Set up option processing.
|
||||||
#
|
#
|
||||||
# The options to support are passed to new() as an array of arrays.
|
# The options to support are passed to new() as an array of arrays.
|
||||||
# Each sub-array contains any number of String option names which carry
|
# Each sub-array contains any number of String option names which carry
|
||||||
# the same meaning, and one of the following flags:
|
# the same meaning, and one of the following flags:
|
||||||
#
|
#
|
||||||
# GetoptLong::NO_ARGUMENT :: Option does not take an argument.
|
# GetoptLong::NO_ARGUMENT :: Option does not take an argument.
|
||||||
|
@ -200,23 +200,23 @@ class GetoptLong
|
||||||
# the processing of options as follows:
|
# the processing of options as follows:
|
||||||
#
|
#
|
||||||
# <b>REQUIRE_ORDER</b> :
|
# <b>REQUIRE_ORDER</b> :
|
||||||
#
|
#
|
||||||
# Options are required to occur before non-options.
|
# Options are required to occur before non-options.
|
||||||
#
|
#
|
||||||
# Processing of options ends as soon as a word is encountered that has not
|
# Processing of options ends as soon as a word is encountered that has not
|
||||||
# been preceded by an appropriate option flag.
|
# been preceded by an appropriate option flag.
|
||||||
#
|
#
|
||||||
# For example, if -a and -b are options which do not take arguments,
|
# For example, if -a and -b are options which do not take arguments,
|
||||||
# parsing command line arguments of '-a one -b two' would result in
|
# parsing command line arguments of '-a one -b two' would result in
|
||||||
# 'one', '-b', 'two' being left in ARGV, and only ('-a', '') being
|
# 'one', '-b', 'two' being left in ARGV, and only ('-a', '') being
|
||||||
# processed as an option/arg pair.
|
# processed as an option/arg pair.
|
||||||
#
|
#
|
||||||
# This is the default ordering, if the environment variable
|
# This is the default ordering, if the environment variable
|
||||||
# POSIXLY_CORRECT is set. (This is for compatibility with GNU getopt_long.)
|
# POSIXLY_CORRECT is set. (This is for compatibility with GNU getopt_long.)
|
||||||
#
|
#
|
||||||
# <b>PERMUTE</b> :
|
# <b>PERMUTE</b> :
|
||||||
#
|
#
|
||||||
# Options can occur anywhere in the command line parsed. This is the
|
# Options can occur anywhere in the command line parsed. This is the
|
||||||
# default behavior.
|
# default behavior.
|
||||||
#
|
#
|
||||||
# Every sequence of words which can be interpreted as an option (with or
|
# Every sequence of words which can be interpreted as an option (with or
|
||||||
|
@ -233,7 +233,7 @@ class GetoptLong
|
||||||
#
|
#
|
||||||
# <b>RETURN_IN_ORDER</b> :
|
# <b>RETURN_IN_ORDER</b> :
|
||||||
#
|
#
|
||||||
# All words on the command line are processed as options. Words not
|
# All words on the command line are processed as options. Words not
|
||||||
# preceded by a short or long option flag are passed as arguments
|
# preceded by a short or long option flag are passed as arguments
|
||||||
# with an option of '' (empty string).
|
# with an option of '' (empty string).
|
||||||
#
|
#
|
||||||
|
@ -279,7 +279,7 @@ class GetoptLong
|
||||||
# The method is failed if option processing has already started.
|
# The method is failed if option processing has already started.
|
||||||
#
|
#
|
||||||
if @status != STATUS_YET
|
if @status != STATUS_YET
|
||||||
raise RuntimeError,
|
raise RuntimeError,
|
||||||
"invoke set_options, but option processing has already started"
|
"invoke set_options, but option processing has already started"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -331,7 +331,7 @@ class GetoptLong
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Register the option (`i') to the `@canonical_names' and
|
# Register the option (`i') to the `@canonical_names' and
|
||||||
# `@canonical_names' Hashes.
|
# `@canonical_names' Hashes.
|
||||||
#
|
#
|
||||||
if canonical_name == nil
|
if canonical_name == nil
|
||||||
|
@ -463,7 +463,7 @@ class GetoptLong
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
argument = ARGV.shift
|
argument = ARGV.shift
|
||||||
elsif @ordering == REQUIRE_ORDER
|
elsif @ordering == REQUIRE_ORDER
|
||||||
if (ARGV[0] !~ /^-./)
|
if (ARGV[0] !~ /^-./)
|
||||||
terminate
|
terminate
|
||||||
return nil
|
return nil
|
||||||
|
@ -600,7 +600,7 @@ class GetoptLong
|
||||||
#
|
#
|
||||||
# The block is called repeatedly with two arguments:
|
# The block is called repeatedly with two arguments:
|
||||||
# The first is the option name.
|
# The first is the option name.
|
||||||
# The second is the argument which followed it (if any).
|
# The second is the argument which followed it (if any).
|
||||||
# Example: ('--opt', 'value')
|
# Example: ('--opt', 'value')
|
||||||
#
|
#
|
||||||
# The option name is always converted to the first (preferred)
|
# The option name is always converted to the first (preferred)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# getopts.rb -
|
# getopts.rb -
|
||||||
# $Release Version: $
|
# $Release Version: $
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
|
|
@ -13,7 +13,7 @@ require "thread"
|
||||||
|
|
||||||
#
|
#
|
||||||
# GServer implements a generic server, featuring thread pool management,
|
# GServer implements a generic server, featuring thread pool management,
|
||||||
# simple logging, and multi-server management. See HttpServer in
|
# simple logging, and multi-server management. See HttpServer in
|
||||||
# <tt>xmlrpc/httpserver.rb</tt> in the Ruby standard library for an example of
|
# <tt>xmlrpc/httpserver.rb</tt> in the Ruby standard library for an example of
|
||||||
# GServer in action.
|
# GServer in action.
|
||||||
#
|
#
|
||||||
|
@ -34,7 +34,7 @@ require "thread"
|
||||||
#
|
#
|
||||||
# #
|
# #
|
||||||
# # A server that returns the time in seconds since 1970.
|
# # A server that returns the time in seconds since 1970.
|
||||||
# #
|
# #
|
||||||
# class TimeServer < GServer
|
# class TimeServer < GServer
|
||||||
# def initialize(port=10001, *args)
|
# def initialize(port=10001, *args)
|
||||||
# super(port, *args)
|
# super(port, *args)
|
||||||
|
@ -47,17 +47,17 @@ require "thread"
|
||||||
# # Run the server with logging enabled (it's a separate thread).
|
# # Run the server with logging enabled (it's a separate thread).
|
||||||
# server = TimeServer.new
|
# server = TimeServer.new
|
||||||
# server.audit = true # Turn logging on.
|
# server.audit = true # Turn logging on.
|
||||||
# server.start
|
# server.start
|
||||||
#
|
#
|
||||||
# # *** Now point your browser to http://localhost:10001 to see it working ***
|
# # *** Now point your browser to http://localhost:10001 to see it working ***
|
||||||
#
|
#
|
||||||
# # See if it's still running.
|
# # See if it's still running.
|
||||||
# GServer.in_service?(10001) # -> true
|
# GServer.in_service?(10001) # -> true
|
||||||
# server.stopped? # -> false
|
# server.stopped? # -> false
|
||||||
#
|
#
|
||||||
# # Shut the server down gracefully.
|
# # Shut the server down gracefully.
|
||||||
# server.shutdown
|
# server.shutdown
|
||||||
#
|
#
|
||||||
# # Alternatively, stop it immediately.
|
# # Alternatively, stop it immediately.
|
||||||
# GServer.stop(10001)
|
# GServer.stop(10001)
|
||||||
# # or, of course, "server.stop".
|
# # or, of course, "server.stop".
|
||||||
|
|
|
@ -66,19 +66,19 @@ end
|
||||||
# == Example
|
# == Example
|
||||||
#
|
#
|
||||||
# require 'ipaddr'
|
# require 'ipaddr'
|
||||||
#
|
#
|
||||||
# ipaddr1 = IPAddr.new "3ffe:505:2::1"
|
# ipaddr1 = IPAddr.new "3ffe:505:2::1"
|
||||||
#
|
#
|
||||||
# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
|
# p ipaddr1 #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0001/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
|
||||||
#
|
#
|
||||||
# p ipaddr1.to_s #=> "3ffe:505:2::1"
|
# p ipaddr1.to_s #=> "3ffe:505:2::1"
|
||||||
#
|
#
|
||||||
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
|
# ipaddr2 = ipaddr1.mask(48) #=> #<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>
|
||||||
#
|
#
|
||||||
# p ipaddr2.to_s #=> "3ffe:505:2::"
|
# p ipaddr2.to_s #=> "3ffe:505:2::"
|
||||||
#
|
#
|
||||||
# ipaddr3 = IPAddr.new "192.168.2.0/24"
|
# ipaddr3 = IPAddr.new "192.168.2.0/24"
|
||||||
#
|
#
|
||||||
# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
|
# p ipaddr3 #=> #<IPAddr: IPv4:192.168.2.0/255.255.255.0>
|
||||||
|
|
||||||
class IPAddr
|
class IPAddr
|
||||||
|
@ -425,7 +425,7 @@ class IPAddr
|
||||||
# Creates a new ipaddr object either from a human readable IP
|
# Creates a new ipaddr object either from a human readable IP
|
||||||
# address representation in string, or from a packed in_addr value
|
# address representation in string, or from a packed in_addr value
|
||||||
# followed by an address family.
|
# followed by an address family.
|
||||||
#
|
#
|
||||||
# In the former case, the following are the valid formats that will
|
# In the former case, the following are the valid formats that will
|
||||||
# be recognized: "address", "address/prefixlen" and "address/mask",
|
# be recognized: "address", "address/prefixlen" and "address/mask",
|
||||||
# where IPv6 address may be enclosed in square brackets (`[' and
|
# where IPv6 address may be enclosed in square brackets (`[' and
|
||||||
|
@ -433,7 +433,7 @@ class IPAddr
|
||||||
# IP address. Although the address family is determined
|
# IP address. Although the address family is determined
|
||||||
# automatically from a specified string, you can specify one
|
# automatically from a specified string, you can specify one
|
||||||
# explicitly by the optional second argument.
|
# explicitly by the optional second argument.
|
||||||
#
|
#
|
||||||
# Otherwise an IP address is generated from a packed in_addr value
|
# Otherwise an IP address is generated from a packed in_addr value
|
||||||
# and an address family.
|
# and an address family.
|
||||||
#
|
#
|
||||||
|
|
14
lib/irb.rb
14
lib/irb.rb
|
@ -93,7 +93,7 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# irb interpriter main routine
|
# irb interpriter main routine
|
||||||
#
|
#
|
||||||
class Irb
|
class Irb
|
||||||
def initialize(workspace = nil, input_method = nil, output_method = nil)
|
def initialize(workspace = nil, input_method = nil, output_method = nil)
|
||||||
|
@ -134,7 +134,7 @@ module IRB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@scanner.set_input(@context.io) do
|
@scanner.set_input(@context.io) do
|
||||||
signal_status(:IN_INPUT) do
|
signal_status(:IN_INPUT) do
|
||||||
if l = @context.io.gets
|
if l = @context.io.gets
|
||||||
|
@ -166,11 +166,11 @@ module IRB
|
||||||
if exc
|
if exc
|
||||||
print exc.class, ": ", exc, "\n"
|
print exc.class, ": ", exc, "\n"
|
||||||
if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/
|
if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/
|
||||||
irb_bug = true
|
irb_bug = true
|
||||||
else
|
else
|
||||||
irb_bug = false
|
irb_bug = false
|
||||||
end
|
end
|
||||||
|
|
||||||
messages = []
|
messages = []
|
||||||
lasts = []
|
lasts = []
|
||||||
levels = 0
|
levels = 0
|
||||||
|
@ -182,7 +182,7 @@ module IRB
|
||||||
else
|
else
|
||||||
lasts.push "\tfrom "+m
|
lasts.push "\tfrom "+m
|
||||||
if lasts.size > @context.back_trace_limit
|
if lasts.size > @context.back_trace_limit
|
||||||
lasts.shift
|
lasts.shift
|
||||||
levels += 1
|
levels += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -287,13 +287,13 @@ module IRB
|
||||||
when "l"
|
when "l"
|
||||||
ltype
|
ltype
|
||||||
when "i"
|
when "i"
|
||||||
if $1
|
if $1
|
||||||
format("%" + $1 + "d", indent)
|
format("%" + $1 + "d", indent)
|
||||||
else
|
else
|
||||||
indent.to_s
|
indent.to_s
|
||||||
end
|
end
|
||||||
when "n"
|
when "n"
|
||||||
if $1
|
if $1
|
||||||
format("%" + $1 + "d", line_no)
|
format("%" + $1 + "d", line_no)
|
||||||
else
|
else
|
||||||
line_no.to_s
|
line_no.to_s
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# change-ws.rb -
|
# change-ws.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "irb/cmd/nop.rb"
|
require "irb/cmd/nop.rb"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# fork.rb -
|
# fork.rb -
|
||||||
# $Release Version: 0.9.5 $
|
# $Release Version: 0.9.5 $
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
@RCS_ID='-$Id$-'
|
@RCS_ID='-$Id$-'
|
||||||
|
@ -18,7 +18,7 @@ module IRB
|
||||||
class Fork<Nop
|
class Fork<Nop
|
||||||
def execute(&block)
|
def execute(&block)
|
||||||
pid = send ExtendCommand.irb_original_method_name("fork")
|
pid = send ExtendCommand.irb_original_method_name("fork")
|
||||||
unless pid
|
unless pid
|
||||||
class<<self
|
class<<self
|
||||||
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
|
alias_method :exit, ExtendCommand.irb_original_method_name('exit')
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'rdoc/ri/ri_driver'
|
require 'rdoc/ri/ri_driver'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# load.rb -
|
# load.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "irb/cmd/nop.rb"
|
require "irb/cmd/nop.rb"
|
||||||
|
@ -26,7 +26,7 @@ module IRB
|
||||||
|
|
||||||
class Require<Nop
|
class Require<Nop
|
||||||
include IrbLoader
|
include IrbLoader
|
||||||
|
|
||||||
def execute(file_name)
|
def execute(file_name)
|
||||||
# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
|
# return ruby_require(file_name) unless IRB.conf[:USE_LOADER]
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ module IRB
|
||||||
when /\.(so|o|sl)$/
|
when /\.(so|o|sl)$/
|
||||||
return ruby_require(file_name)
|
return ruby_require(file_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
irb_load(f = file_name + ".rb")
|
irb_load(f = file_name + ".rb")
|
||||||
$".push f
|
$".push f
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# nop.rb -
|
# nop.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,12 +7,12 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
module IRB
|
module IRB
|
||||||
module ExtendCommand
|
module ExtendCommand
|
||||||
class Nop
|
class Nop
|
||||||
|
|
||||||
@RCS_ID='-$Id$-'
|
@RCS_ID='-$Id$-'
|
||||||
|
|
||||||
def self.execute(conf, *opts)
|
def self.execute(conf, *opts)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# change-ws.rb -
|
# change-ws.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "irb/cmd/nop.rb"
|
require "irb/cmd/nop.rb"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/local/bin/ruby
|
#!/usr/local/bin/ruby
|
||||||
#
|
#
|
||||||
# multi.rb -
|
# multi.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "irb/cmd/nop.rb"
|
require "irb/cmd/nop.rb"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/completor.rb -
|
# irb/completor.rb -
|
||||||
# $Release Version: 0.9$
|
# $Release Version: 0.9$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -16,16 +16,16 @@ module IRB
|
||||||
|
|
||||||
ReservedWords = [
|
ReservedWords = [
|
||||||
"BEGIN", "END",
|
"BEGIN", "END",
|
||||||
"alias", "and",
|
"alias", "and",
|
||||||
"begin", "break",
|
"begin", "break",
|
||||||
"case", "class",
|
"case", "class",
|
||||||
"def", "defined", "do",
|
"def", "defined", "do",
|
||||||
"else", "elsif", "end", "ensure",
|
"else", "elsif", "end", "ensure",
|
||||||
"false", "for",
|
"false", "for",
|
||||||
"if", "in",
|
"if", "in",
|
||||||
"module",
|
"module",
|
||||||
"next", "nil", "not",
|
"next", "nil", "not",
|
||||||
"or",
|
"or",
|
||||||
"redo", "rescue", "retry", "return",
|
"redo", "rescue", "retry", "return",
|
||||||
"self", "super",
|
"self", "super",
|
||||||
"then", "true",
|
"then", "true",
|
||||||
|
@ -33,10 +33,10 @@ module IRB
|
||||||
"when", "while",
|
"when", "while",
|
||||||
"yield",
|
"yield",
|
||||||
]
|
]
|
||||||
|
|
||||||
CompletionProc = proc { |input|
|
CompletionProc = proc { |input|
|
||||||
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
||||||
|
|
||||||
# puts "input: #{input}"
|
# puts "input: #{input}"
|
||||||
|
|
||||||
case input
|
case input
|
||||||
|
@ -63,7 +63,7 @@ module IRB
|
||||||
|
|
||||||
candidates = Proc.instance_methods(true) | Hash.instance_methods(true)
|
candidates = Proc.instance_methods(true) | Hash.instance_methods(true)
|
||||||
select_message(receiver, message, candidates)
|
select_message(receiver, message, candidates)
|
||||||
|
|
||||||
when /^(:[^:.]*)$/
|
when /^(:[^:.]*)$/
|
||||||
# Symbol
|
# Symbol
|
||||||
if Symbol.respond_to?(:all_symbols)
|
if Symbol.respond_to?(:all_symbols)
|
||||||
|
@ -135,7 +135,7 @@ module IRB
|
||||||
gv = eval("global_variables", bind)
|
gv = eval("global_variables", bind)
|
||||||
lv = eval("local_variables", bind)
|
lv = eval("local_variables", bind)
|
||||||
cv = eval("self.class.constants", bind)
|
cv = eval("self.class.constants", bind)
|
||||||
|
|
||||||
if (gv | lv | cv).include?(receiver)
|
if (gv | lv | cv).include?(receiver)
|
||||||
# foo.func and foo is local var.
|
# foo.func and foo is local var.
|
||||||
candidates = eval("#{receiver}.methods", bind)
|
candidates = eval("#{receiver}.methods", bind)
|
||||||
|
@ -155,7 +155,7 @@ module IRB
|
||||||
rescue Exception
|
rescue Exception
|
||||||
name = ""
|
name = ""
|
||||||
end
|
end
|
||||||
next if name != "IRB::Context" and
|
next if name != "IRB::Context" and
|
||||||
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
||||||
candidates.concat m.instance_methods(false)
|
candidates.concat m.instance_methods(false)
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ module IRB
|
||||||
|
|
||||||
else
|
else
|
||||||
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind)
|
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind)
|
||||||
|
|
||||||
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
require "irb/workspace"
|
require "irb/workspace"
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ module IRB
|
||||||
@ignore_eof = IRB.conf[:IGNORE_EOF]
|
@ignore_eof = IRB.conf[:IGNORE_EOF]
|
||||||
|
|
||||||
@back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
|
@back_trace_limit = IRB.conf[:BACK_TRACE_LIMIT]
|
||||||
|
|
||||||
self.prompt_mode = IRB.conf[:PROMPT_MODE]
|
self.prompt_mode = IRB.conf[:PROMPT_MODE]
|
||||||
|
|
||||||
if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
|
if IRB.conf[:SINGLE_IRB] or !defined?(JobManager)
|
||||||
|
@ -91,7 +91,7 @@ module IRB
|
||||||
@output_method = StdioOutputMethod.new
|
@output_method = StdioOutputMethod.new
|
||||||
end
|
end
|
||||||
|
|
||||||
@verbose = IRB.conf[:VERBOSE]
|
@verbose = IRB.conf[:VERBOSE]
|
||||||
@echo = IRB.conf[:ECHO]
|
@echo = IRB.conf[:ECHO]
|
||||||
if @echo.nil?
|
if @echo.nil?
|
||||||
@echo = true
|
@echo = true
|
||||||
|
@ -107,7 +107,7 @@ module IRB
|
||||||
attr_accessor :workspace
|
attr_accessor :workspace
|
||||||
attr_reader :thread
|
attr_reader :thread
|
||||||
attr_accessor :io
|
attr_accessor :io
|
||||||
|
|
||||||
attr_accessor :irb
|
attr_accessor :irb
|
||||||
attr_accessor :ap_name
|
attr_accessor :ap_name
|
||||||
attr_accessor :rc
|
attr_accessor :rc
|
||||||
|
@ -142,7 +142,7 @@ module IRB
|
||||||
|
|
||||||
def verbose?
|
def verbose?
|
||||||
if @verbose.nil?
|
if @verbose.nil?
|
||||||
if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
|
if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
|
||||||
false
|
false
|
||||||
elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
|
elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
|
||||||
true
|
true
|
||||||
|
@ -180,7 +180,7 @@ module IRB
|
||||||
@auto_indent_mode = IRB.conf[:AUTO_INDENT]
|
@auto_indent_mode = IRB.conf[:AUTO_INDENT]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect?
|
def inspect?
|
||||||
@inspect_mode.nil? or @inspect_mode
|
@inspect_mode.nil? or @inspect_mode
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/ext/cb.rb -
|
# irb/ext/cb.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
|
@ -23,12 +23,12 @@ module IRB
|
||||||
|
|
||||||
def change_workspace(*_main)
|
def change_workspace(*_main)
|
||||||
if _main.empty?
|
if _main.empty?
|
||||||
@workspace = home_workspace
|
@workspace = home_workspace
|
||||||
return main
|
return main
|
||||||
end
|
end
|
||||||
|
|
||||||
@workspace = WorkSpace.new(_main[0])
|
@workspace = WorkSpace.new(_main[0])
|
||||||
|
|
||||||
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
if !(class<<main;ancestors;end).include?(ExtendCommandBundle)
|
||||||
main.extend ExtendCommandBundle
|
main.extend ExtendCommandBundle
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# history.rb -
|
# history.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
|
@ -57,7 +57,7 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
def size(size)
|
def size(size)
|
||||||
if size != 0 && size < @size
|
if size != 0 && size < @size
|
||||||
@contents = @contents[@size - size .. @size]
|
@contents = @contents[@size - size .. @size]
|
||||||
end
|
end
|
||||||
@size = size
|
@size = size
|
||||||
|
@ -79,7 +79,7 @@ module IRB
|
||||||
@contents.push [no, val]
|
@contents.push [no, val]
|
||||||
@contents.shift if @size != 0 && @contents.size > @size
|
@contents.shift if @size != 0 && @contents.size > @size
|
||||||
end
|
end
|
||||||
|
|
||||||
alias real_inspect inspect
|
alias real_inspect inspect
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# loader.rb -
|
# loader.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ module IRB
|
||||||
irb.suspend_name(path, File.basename(path)) do
|
irb.suspend_name(path, File.basename(path)) do
|
||||||
irb.suspend_input_method(FileInputMethod.new(path)) do
|
irb.suspend_input_method(FileInputMethod.new(path)) do
|
||||||
|back_io|
|
|back_io|
|
||||||
irb.signal_status(:IN_LOAD) do
|
irb.signal_status(:IN_LOAD) do
|
||||||
if back_io.kind_of?(FileInputMethod)
|
if back_io.kind_of?(FileInputMethod)
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
else
|
else
|
||||||
|
@ -62,7 +62,7 @@ module IRB
|
||||||
|
|
||||||
def load_file(path, priv = nil)
|
def load_file(path, priv = nil)
|
||||||
irb.suspend_name(path, File.basename(path)) do
|
irb.suspend_name(path, File.basename(path)) do
|
||||||
|
|
||||||
if priv
|
if priv
|
||||||
ws = WorkSpace.new(Module.new)
|
ws = WorkSpace.new(Module.new)
|
||||||
else
|
else
|
||||||
|
@ -71,7 +71,7 @@ module IRB
|
||||||
irb.suspend_workspace(ws) do
|
irb.suspend_workspace(ws) do
|
||||||
irb.suspend_input_method(FileInputMethod.new(path)) do
|
irb.suspend_input_method(FileInputMethod.new(path)) do
|
||||||
|back_io|
|
|back_io|
|
||||||
irb.signal_status(:IN_LOAD) do
|
irb.signal_status(:IN_LOAD) do
|
||||||
# p irb.conf
|
# p irb.conf
|
||||||
if back_io.kind_of?(FileInputMethod)
|
if back_io.kind_of?(FileInputMethod)
|
||||||
irb.eval_input
|
irb.eval_input
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# math-mode.rb -
|
# math-mode.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
require "mathn"
|
require "mathn"
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
IRB.fail CantShiftToMultiIrbMode unless defined?(Thread)
|
IRB.fail CantShiftToMultiIrbMode unless defined?(Thread)
|
||||||
require "thread"
|
require "thread"
|
||||||
|
@ -67,7 +67,7 @@ module IRB
|
||||||
IRB.fail IrbAlreadyDead unless th.alive?
|
IRB.fail IrbAlreadyDead unless th.alive?
|
||||||
th.exit
|
th.exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(key)
|
def search(key)
|
||||||
job = case key
|
job = case key
|
||||||
|
@ -124,8 +124,8 @@ module IRB
|
||||||
t_status = "exited"
|
t_status = "exited"
|
||||||
end
|
end
|
||||||
ary.push format("#%d->%s on %s (%s: %s)",
|
ary.push format("#%d->%s on %s (%s: %s)",
|
||||||
i,
|
i,
|
||||||
irb.context.irb_name,
|
irb.context.irb_name,
|
||||||
irb.context.main,
|
irb.context.main,
|
||||||
th,
|
th,
|
||||||
t_status)
|
t_status)
|
||||||
|
@ -144,14 +144,14 @@ module IRB
|
||||||
IRB.JobManager.irb(Thread.current).context
|
IRB.JobManager.irb(Thread.current).context
|
||||||
end
|
end
|
||||||
|
|
||||||
# invoke multi-irb
|
# invoke multi-irb
|
||||||
def IRB.irb(file = nil, *main)
|
def IRB.irb(file = nil, *main)
|
||||||
workspace = WorkSpace.new(*main)
|
workspace = WorkSpace.new(*main)
|
||||||
parent_thread = Thread.current
|
parent_thread = Thread.current
|
||||||
Thread.start do
|
Thread.start do
|
||||||
begin
|
begin
|
||||||
irb = Irb.new(workspace, file)
|
irb = Irb.new(workspace, file)
|
||||||
rescue
|
rescue
|
||||||
print "Subirb can't start with context(self): ", workspace.main.inspect, "\n"
|
print "Subirb can't start with context(self): ", workspace.main.inspect, "\n"
|
||||||
print "return to main irb\n"
|
print "return to main irb\n"
|
||||||
Thread.pass
|
Thread.pass
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/local/bin/ruby
|
#!/usr/local/bin/ruby
|
||||||
#
|
#
|
||||||
# save-history.rb -
|
# save-history.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -8,7 +8,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "readline"
|
require "readline"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/lib/tracer.rb -
|
# irb/lib/tracer.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
require "tracer"
|
require "tracer"
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ module IRB
|
||||||
alias __evaluate__ evaluate
|
alias __evaluate__ evaluate
|
||||||
def evaluate(context, statements, file = nil, line = nil)
|
def evaluate(context, statements, file = nil, line = nil)
|
||||||
if context.use_tracer? && file != nil && line != nil
|
if context.use_tracer? && file != nil && line != nil
|
||||||
Tracer.on
|
Tracer.on
|
||||||
begin
|
begin
|
||||||
__evaluate__(context, statements, file, line)
|
__evaluate__(context, statements, file, line)
|
||||||
ensure
|
ensure
|
||||||
|
@ -58,4 +58,4 @@ module IRB
|
||||||
|
|
||||||
IRB.initialize_tracer
|
IRB.initialize_tracer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# use-loader.rb -
|
# use-loader.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "irb/cmd/load"
|
require "irb/cmd/load"
|
||||||
|
@ -31,7 +31,7 @@ module IRB
|
||||||
class Context
|
class Context
|
||||||
|
|
||||||
IRB.conf[:USE_LOADER] = false
|
IRB.conf[:USE_LOADER] = false
|
||||||
|
|
||||||
def use_loader
|
def use_loader
|
||||||
IRB.conf[:USE_LOADER]
|
IRB.conf[:USE_LOADER]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# push-ws.rb -
|
# push-ws.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/extend-command.rb - irb extend command
|
# irb/extend-command.rb - irb extend command
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
module IRB
|
module IRB
|
||||||
#
|
#
|
||||||
|
@ -90,15 +90,15 @@ module IRB
|
||||||
|
|
||||||
[:irb_load, :Load, "irb/cmd/load"],
|
[:irb_load, :Load, "irb/cmd/load"],
|
||||||
[:irb_require, :Require, "irb/cmd/load"],
|
[:irb_require, :Require, "irb/cmd/load"],
|
||||||
[:irb_source, :Source, "irb/cmd/load",
|
[:irb_source, :Source, "irb/cmd/load",
|
||||||
[:source, NO_OVERRIDE]],
|
[:source, NO_OVERRIDE]],
|
||||||
|
|
||||||
[:irb, :IrbCommand, "irb/cmd/subirb"],
|
[:irb, :IrbCommand, "irb/cmd/subirb"],
|
||||||
[:irb_jobs, :Jobs, "irb/cmd/subirb",
|
[:irb_jobs, :Jobs, "irb/cmd/subirb",
|
||||||
[:jobs, NO_OVERRIDE]],
|
[:jobs, NO_OVERRIDE]],
|
||||||
[:irb_fg, :Foreground, "irb/cmd/subirb",
|
[:irb_fg, :Foreground, "irb/cmd/subirb",
|
||||||
[:fg, NO_OVERRIDE]],
|
[:fg, NO_OVERRIDE]],
|
||||||
[:irb_kill, :Kill, "irb/cmd/subirb",
|
[:irb_kill, :Kill, "irb/cmd/subirb",
|
||||||
[:kill, OVERRIDE_PRIVATE_ONLY]],
|
[:kill, OVERRIDE_PRIVATE_ONLY]],
|
||||||
|
|
||||||
[:irb_help, :Help, "irb/cmd/help",
|
[:irb_help, :Help, "irb/cmd/help",
|
||||||
|
@ -162,9 +162,9 @@ module IRB
|
||||||
(override == NO_OVERRIDE) && !respond_to?(to, true)
|
(override == NO_OVERRIDE) && !respond_to?(to, true)
|
||||||
target = self
|
target = self
|
||||||
(class<<self;self;end).instance_eval{
|
(class<<self;self;end).instance_eval{
|
||||||
if target.respond_to?(to, true) &&
|
if target.respond_to?(to, true) &&
|
||||||
!target.respond_to?(EXCB.irb_original_method_name(to), true)
|
!target.respond_to?(EXCB.irb_original_method_name(to), true)
|
||||||
alias_method(EXCB.irb_original_method_name(to), to)
|
alias_method(EXCB.irb_original_method_name(to), to)
|
||||||
end
|
end
|
||||||
alias_method to, from
|
alias_method to, from
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# frame.rb -
|
# frame.rb -
|
||||||
# $Release Version: 0.9$
|
# $Release Version: 0.9$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
|
@ -23,7 +23,7 @@ module IRB
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
space_line = false
|
space_line = false
|
||||||
|
|
||||||
l.sub!(/#.*$/, "")
|
l.sub!(/#.*$/, "")
|
||||||
next if /^\s*$/ =~ l
|
next if /^\s*$/ =~ l
|
||||||
lc.puts l
|
lc.puts l
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
|
@ -21,7 +21,7 @@ module IRB
|
||||||
IRB.load_modules
|
IRB.load_modules
|
||||||
|
|
||||||
unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
|
unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
|
||||||
IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
|
IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -113,9 +113,9 @@ module IRB
|
||||||
|
|
||||||
# @CONF[:LC_MESSAGES] = "en"
|
# @CONF[:LC_MESSAGES] = "en"
|
||||||
@CONF[:LC_MESSAGES] = Locale.new
|
@CONF[:LC_MESSAGES] = Locale.new
|
||||||
|
|
||||||
@CONF[:AT_EXIT] = []
|
@CONF[:AT_EXIT] = []
|
||||||
|
|
||||||
@CONF[:DEBUG_LEVEL] = 1
|
@CONF[:DEBUG_LEVEL] = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ module IRB
|
||||||
yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
|
yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
|
||||||
end
|
end
|
||||||
if home = ENV["HOME"]
|
if home = ENV["HOME"]
|
||||||
yield proc{|rc| home+"/.irb#{rc}"}
|
yield proc{|rc| home+"/.irb#{rc}"}
|
||||||
end
|
end
|
||||||
home = Dir.pwd
|
home = Dir.pwd
|
||||||
yield proc{|rc| home+"/.irb#{rc}"}
|
yield proc{|rc| home+"/.irb#{rc}"}
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
module IRB
|
module IRB
|
||||||
#
|
#
|
||||||
# InputMethod
|
# InputMethod
|
||||||
# StdioInputMethod
|
# StdioInputMethod
|
||||||
# FileInputMethod
|
# FileInputMethod
|
||||||
|
@ -26,7 +26,7 @@ module IRB
|
||||||
attr_reader :file_name
|
attr_reader :file_name
|
||||||
|
|
||||||
attr_accessor :prompt
|
attr_accessor :prompt
|
||||||
|
|
||||||
def gets
|
def gets
|
||||||
IRB.fail NotImplementedError, "gets"
|
IRB.fail NotImplementedError, "gets"
|
||||||
end
|
end
|
||||||
|
@ -36,7 +36,7 @@ module IRB
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class StdioInputMethod < InputMethod
|
class StdioInputMethod < InputMethod
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
@ -61,7 +61,7 @@ module IRB
|
||||||
@line[line_no]
|
@line[line_no]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class FileInputMethod < InputMethod
|
class FileInputMethod < InputMethod
|
||||||
def initialize(file)
|
def initialize(file)
|
||||||
super
|
super
|
||||||
|
@ -84,7 +84,7 @@ module IRB
|
||||||
begin
|
begin
|
||||||
require "readline"
|
require "readline"
|
||||||
class ReadlineInputMethod < InputMethod
|
class ReadlineInputMethod < InputMethod
|
||||||
include Readline
|
include Readline
|
||||||
def initialize
|
def initialize
|
||||||
super
|
super
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/lc/error.rb -
|
# irb/lc/error.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/lc/ja/error.rb -
|
# irb/lc/ja/error.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
autoload :Kconv, "kconv"
|
autoload :Kconv, "kconv"
|
||||||
|
@ -20,7 +20,7 @@ module IRB
|
||||||
LOCALE_DIR = "/lc/"
|
LOCALE_DIR = "/lc/"
|
||||||
|
|
||||||
def initialize(locale = nil)
|
def initialize(locale = nil)
|
||||||
@lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
|
@lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C"
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :lang
|
attr_reader :lang
|
||||||
|
@ -101,7 +101,7 @@ module IRB
|
||||||
end
|
end
|
||||||
|
|
||||||
alias toplevel_load load
|
alias toplevel_load load
|
||||||
|
|
||||||
def load(file, priv=nil)
|
def load(file, priv=nil)
|
||||||
dir = File.dirname(file)
|
dir = File.dirname(file)
|
||||||
dir = "" if dir == "."
|
dir = "" if dir == "."
|
||||||
|
@ -115,7 +115,7 @@ module IRB
|
||||||
lc_path = search_file(dir, base)
|
lc_path = search_file(dir, base)
|
||||||
return real_load(lc_path, priv) if lc_path
|
return real_load(lc_path, priv) if lc_path
|
||||||
end
|
end
|
||||||
|
|
||||||
for path in $:
|
for path in $:
|
||||||
lc_path = search_file(path + "/" + dir, base)
|
lc_path = search_file(path + "/" + dir, base)
|
||||||
return real_load(lc_path, priv) if lc_path
|
return real_load(lc_path, priv) if lc_path
|
||||||
|
@ -124,7 +124,7 @@ module IRB
|
||||||
@lang = back if back
|
@lang = back if back
|
||||||
end
|
end
|
||||||
raise LoadError, "No such file to load -- #{file}"
|
raise LoadError, "No such file to load -- #{file}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def real_load(path, priv)
|
def real_load(path, priv)
|
||||||
src = self.String(File.read(path))
|
src = self.String(File.read(path))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# notifier.rb - output methods used by irb
|
# notifier.rb - output methods used by irb
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
@ -16,16 +16,16 @@ require "irb/output-method"
|
||||||
module IRB
|
module IRB
|
||||||
module Notifier
|
module Notifier
|
||||||
extend Exception2MessageMapper
|
extend Exception2MessageMapper
|
||||||
def_exception :ErrUndefinedNotifier,
|
def_exception :ErrUndefinedNotifier,
|
||||||
"undefined notifier level: %d is specified"
|
"undefined notifier level: %d is specified"
|
||||||
def_exception :ErrUnrecognizedLevel,
|
def_exception :ErrUnrecognizedLevel,
|
||||||
"unrecognized notifier level: %s is specified"
|
"unrecognized notifier level: %s is specified"
|
||||||
|
|
||||||
def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
|
def def_notifier(prefix = "", output_method = StdioOutputMethod.new)
|
||||||
CompositeNotifier.new(prefix, output_method)
|
CompositeNotifier.new(prefix, output_method)
|
||||||
end
|
end
|
||||||
module_function :def_notifier
|
module_function :def_notifier
|
||||||
|
|
||||||
class AbstractNotifier
|
class AbstractNotifier
|
||||||
def initialize(prefix, base_notifier)
|
def initialize(prefix, base_notifier)
|
||||||
@prefix = prefix
|
@prefix = prefix
|
||||||
|
@ -113,7 +113,7 @@ module IRB
|
||||||
|
|
||||||
def initialize(base, level, prefix)
|
def initialize(base, level, prefix)
|
||||||
super(prefix, base)
|
super(prefix, base)
|
||||||
|
|
||||||
@level = level
|
@level = level
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ module IRB
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
@level <=> other.level
|
@level <=> other.level
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify?
|
def notify?
|
||||||
@base_notifier.level >= self
|
@base_notifier.level >= self
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# output-method.rb - output methods used by irb
|
# output-method.rb - output methods used by irb
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
@ -40,7 +40,7 @@ module IRB
|
||||||
# <最小フィールド幅> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
|
# <最小フィールド幅> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
|
||||||
# <精度>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
|
# <精度>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
|
||||||
# #<長さ修正文字>(hh|h|l|ll|L|q|j|z|t)
|
# #<長さ修正文字>(hh|h|l|ll|L|q|j|z|t)
|
||||||
# <恃垂饯赖矢机>[diouxXeEfgGcsb%]
|
# <恃垂饯赖矢机>[diouxXeEfgGcsb%]
|
||||||
def parse_printf_format(format, opts)
|
def parse_printf_format(format, opts)
|
||||||
return format, opts if $1.size % 2 == 1
|
return format, opts if $1.size % 2 == 1
|
||||||
end
|
end
|
||||||
|
@ -52,7 +52,7 @@ module IRB
|
||||||
puts [f, p, pp, pos, new_pos, c].join("!")
|
puts [f, p, pp, pos, new_pos, c].join("!")
|
||||||
pos = new_pos if new_pos
|
pos = new_pos if new_pos
|
||||||
if c == "I"
|
if c == "I"
|
||||||
inspects.push pos.to_i
|
inspects.push pos.to_i
|
||||||
(f||"")+(p||"")+(pp||"")+(pos||"")+"s"
|
(f||"")+(p||"")+(pp||"")+(pos||"")+"s"
|
||||||
else
|
else
|
||||||
$&
|
$&
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
@ -21,12 +21,12 @@ class RubyLex
|
||||||
def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
|
def_exception(:AlreadyDefinedToken, "Already defined token(%s)")
|
||||||
def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
|
def_exception(:TkReading2TokenNoKey, "key nothing(key='%s')")
|
||||||
def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
|
def_exception(:TkSymbol2TokenNoKey, "key nothing(key='%s')")
|
||||||
def_exception(:TkReading2TokenDuplicateError,
|
def_exception(:TkReading2TokenDuplicateError,
|
||||||
"key duplicate(token_n='%s', key='%s')")
|
"key duplicate(token_n='%s', key='%s')")
|
||||||
def_exception(:SyntaxError, "%s")
|
def_exception(:SyntaxError, "%s")
|
||||||
|
|
||||||
def_exception(:TerminateLineInput, "Terminate Line Input")
|
def_exception(:TerminateLineInput, "Terminate Line Input")
|
||||||
|
|
||||||
include RubyToken
|
include RubyToken
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -54,7 +54,7 @@ class RubyLex
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
@space_seen = false
|
@space_seen = false
|
||||||
@here_header = false
|
@here_header = false
|
||||||
|
|
||||||
@continue = false
|
@continue = false
|
||||||
@line = ""
|
@line = ""
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class RubyLex
|
||||||
else
|
else
|
||||||
@base_char_no += @readed.size
|
@base_char_no += @readed.size
|
||||||
end
|
end
|
||||||
|
|
||||||
readed = @readed.join("")
|
readed = @readed.join("")
|
||||||
@readed = []
|
@readed = []
|
||||||
readed
|
readed
|
||||||
|
@ -111,7 +111,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
@seek += 1
|
@seek += 1
|
||||||
if c == "\n"
|
if c == "\n"
|
||||||
@line_no += 1
|
@line_no += 1
|
||||||
@char_no = 0
|
@char_no = 0
|
||||||
else
|
else
|
||||||
@char_no += 1
|
@char_no += 1
|
||||||
|
@ -148,10 +148,10 @@ class RubyLex
|
||||||
c2 = @here_readed.pop
|
c2 = @here_readed.pop
|
||||||
end
|
end
|
||||||
c = c2 unless c
|
c = c2 unless c
|
||||||
@rests.unshift c #c =
|
@rests.unshift c #c =
|
||||||
@seek -= 1
|
@seek -= 1
|
||||||
if c == "\n"
|
if c == "\n"
|
||||||
@line_no -= 1
|
@line_no -= 1
|
||||||
if idx = @readed.reverse.index("\n")
|
if idx = @readed.reverse.index("\n")
|
||||||
@char_no = @readed.size - idx
|
@char_no = @readed.size - idx
|
||||||
else
|
else
|
||||||
|
@ -216,14 +216,14 @@ class RubyLex
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
@space_seen = false
|
@space_seen = false
|
||||||
@here_header = false
|
@here_header = false
|
||||||
|
|
||||||
@continue = false
|
@continue = false
|
||||||
prompt
|
prompt
|
||||||
|
|
||||||
@line = ""
|
@line = ""
|
||||||
@exp_line_no = @line_no
|
@exp_line_no = @line_no
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_top_level_statement
|
def each_top_level_statement
|
||||||
initialize_input
|
initialize_input
|
||||||
catch(:TERM_INPUT) do
|
catch(:TERM_INPUT) do
|
||||||
|
@ -297,7 +297,7 @@ class RubyLex
|
||||||
# Tracer.off
|
# Tracer.off
|
||||||
tk
|
tk
|
||||||
end
|
end
|
||||||
|
|
||||||
ENINDENT_CLAUSE = [
|
ENINDENT_CLAUSE = [
|
||||||
"case", "class", "def", "do", "for", "if",
|
"case", "class", "def", "do", "for", "if",
|
||||||
"module", "unless", "until", "while", "begin" #, "when"
|
"module", "unless", "until", "while", "begin" #, "when"
|
||||||
|
@ -314,7 +314,7 @@ class RubyLex
|
||||||
"W" => "]",
|
"W" => "]",
|
||||||
"s" => ":"
|
"s" => ":"
|
||||||
}
|
}
|
||||||
|
|
||||||
PERCENT_PAREN = {
|
PERCENT_PAREN = {
|
||||||
"{" => "}",
|
"{" => "}",
|
||||||
"[" => "]",
|
"[" => "]",
|
||||||
|
@ -354,7 +354,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rule("=begin",
|
@OP.def_rule("=begin",
|
||||||
proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
|
proc{|op, io| @prev_char_no == 0 && peek(0) =~ /\s/}) do
|
||||||
|op, io|
|
|op, io|
|
||||||
@ltype = "="
|
@ltype = "="
|
||||||
until getc == "\n"; end
|
until getc == "\n"; end
|
||||||
|
@ -374,8 +374,8 @@ class RubyLex
|
||||||
else
|
else
|
||||||
@continue = false
|
@continue = false
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
until (@indent_stack.empty? ||
|
until (@indent_stack.empty? ||
|
||||||
[TkLPAREN, TkLBRACK, TkLBRACE,
|
[TkLPAREN, TkLBRACK, TkLBRACE,
|
||||||
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
||||||
@indent_stack.pop
|
@indent_stack.pop
|
||||||
end
|
end
|
||||||
|
@ -385,9 +385,9 @@ class RubyLex
|
||||||
Token(TkNL)
|
Token(TkNL)
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rules("*", "**",
|
@OP.def_rules("*", "**",
|
||||||
"=", "==", "===",
|
"=", "==", "===",
|
||||||
"=~", "<=>",
|
"=~", "<=>",
|
||||||
"<", "<=",
|
"<", "<=",
|
||||||
">", ">=", ">>") do
|
">", ">=", ">>") do
|
||||||
|op, io|
|
|op, io|
|
||||||
|
@ -455,7 +455,7 @@ class RubyLex
|
||||||
@lex_state = EXPR_BEG;
|
@lex_state = EXPR_BEG;
|
||||||
Token(TkQUESTION)
|
Token(TkQUESTION)
|
||||||
else
|
else
|
||||||
if (ch == '\\')
|
if (ch == '\\')
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
|
@ -469,8 +469,8 @@ class RubyLex
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token(op)
|
Token(op)
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rules("+=", "-=", "*=", "**=",
|
@OP.def_rules("+=", "-=", "*=", "**=",
|
||||||
"&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
|
"&=", "|=", "^=", "<<=", ">>=", "||=", "&&=") do
|
||||||
|op, io|
|
|op, io|
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
|
@ -529,7 +529,7 @@ class RubyLex
|
||||||
|
|
||||||
lex_int2
|
lex_int2
|
||||||
end
|
end
|
||||||
|
|
||||||
def lex_int2
|
def lex_int2
|
||||||
@OP.def_rules("]", "}", ")") do
|
@OP.def_rules("]", "}", ")") do
|
||||||
|op, io|
|
|op, io|
|
||||||
|
@ -572,7 +572,7 @@ class RubyLex
|
||||||
Token(TkOPASGN, "/") #/)
|
Token(TkOPASGN, "/") #/)
|
||||||
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
elsif @lex_state == EXPR_ARG and @space_seen and peek(0) !~ /\s/
|
||||||
identify_string(op)
|
identify_string(op)
|
||||||
else
|
else
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token("/") #/)
|
Token("/") #/)
|
||||||
end
|
end
|
||||||
|
@ -588,7 +588,7 @@ class RubyLex
|
||||||
# @lex_state = EXPR_BEG
|
# @lex_state = EXPR_BEG
|
||||||
# Token(OP_ASGN, :^)
|
# Token(OP_ASGN, :^)
|
||||||
# end
|
# end
|
||||||
|
|
||||||
@OP.def_rules(",") do
|
@OP.def_rules(",") do
|
||||||
|op, io|
|
|op, io|
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
|
@ -598,8 +598,8 @@ class RubyLex
|
||||||
@OP.def_rules(";") do
|
@OP.def_rules(";") do
|
||||||
|op, io|
|
|op, io|
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
until (@indent_stack.empty? ||
|
until (@indent_stack.empty? ||
|
||||||
[TkLPAREN, TkLBRACK, TkLBRACE,
|
[TkLPAREN, TkLBRACK, TkLBRACE,
|
||||||
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
TkfLPAREN, TkfLBRACK, TkfLBRACE].include?(@indent_stack.last))
|
||||||
@indent_stack.pop
|
@indent_stack.pop
|
||||||
end
|
end
|
||||||
|
@ -617,7 +617,7 @@ class RubyLex
|
||||||
@lex_state = EXPR_BEG
|
@lex_state = EXPR_BEG
|
||||||
Token("~")
|
Token("~")
|
||||||
end
|
end
|
||||||
|
|
||||||
@OP.def_rule("(") do
|
@OP.def_rule("(") do
|
||||||
|op, io|
|
|op, io|
|
||||||
@indent += 1
|
@indent += 1
|
||||||
|
@ -718,7 +718,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
|
# @OP.def_rule("def", proc{|op, io| /\s/ =~ io.peek(0)}) do
|
||||||
# |op, io|
|
# |op, io|
|
||||||
# @indent += 1
|
# @indent += 1
|
||||||
# @lex_state = EXPR_FNAME
|
# @lex_state = EXPR_FNAME
|
||||||
|
@ -739,13 +739,13 @@ class RubyLex
|
||||||
printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
|
printf "MATCH: end %s: %s\n", op, io.inspect if RubyLex.debug?
|
||||||
t
|
t
|
||||||
end
|
end
|
||||||
|
|
||||||
p @OP if RubyLex.debug?
|
p @OP if RubyLex.debug?
|
||||||
end
|
end
|
||||||
|
|
||||||
def identify_gvar
|
def identify_gvar
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
|
|
||||||
case ch = getc
|
case ch = getc
|
||||||
when /[~_*$?!@\/\\;,=:<>".]/ #"
|
when /[~_*$?!@\/\\;,=:<>".]/ #"
|
||||||
Token(TkGVAR, "$" + ch)
|
Token(TkGVAR, "$" + ch)
|
||||||
|
@ -761,12 +761,12 @@ class RubyLex
|
||||||
ungetc
|
ungetc
|
||||||
ungetc
|
ungetc
|
||||||
identify_identifier
|
identify_identifier
|
||||||
else
|
else
|
||||||
ungetc
|
ungetc
|
||||||
Token("$")
|
Token("$")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def identify_identifier
|
def identify_identifier
|
||||||
token = ""
|
token = ""
|
||||||
if peek(0) =~ /[$@]/
|
if peek(0) =~ /[$@]/
|
||||||
|
@ -781,7 +781,7 @@ class RubyLex
|
||||||
token.concat ch
|
token.concat ch
|
||||||
end
|
end
|
||||||
ungetc
|
ungetc
|
||||||
|
|
||||||
if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
|
if (ch == "!" || ch == "?") && token[0,1] =~ /\w/ && peek(0) != "="
|
||||||
token.concat getc
|
token.concat getc
|
||||||
end
|
end
|
||||||
|
@ -799,7 +799,7 @@ class RubyLex
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
return Token(TkIVAR, token)
|
return Token(TkIVAR, token)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @lex_state != EXPR_DOT
|
if @lex_state != EXPR_DOT
|
||||||
print token, "\n" if RubyLex.debug?
|
print token, "\n" if RubyLex.debug?
|
||||||
|
|
||||||
|
@ -927,7 +927,7 @@ class RubyLex
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
Token(Ltype2Token[lt])
|
Token(Ltype2Token[lt])
|
||||||
end
|
end
|
||||||
|
|
||||||
def identify_quotation
|
def identify_quotation
|
||||||
ch = getc
|
ch = getc
|
||||||
if lt = PERCENT_LTYPE[ch]
|
if lt = PERCENT_LTYPE[ch]
|
||||||
|
@ -968,10 +968,10 @@ class RubyLex
|
||||||
match = /[0-7_]/
|
match = /[0-7_]/
|
||||||
when /[89]/
|
when /[89]/
|
||||||
RubyLex.fail SyntaxError, "Illegal octal digit"
|
RubyLex.fail SyntaxError, "Illegal octal digit"
|
||||||
else
|
else
|
||||||
return Token(TkINTEGER)
|
return Token(TkINTEGER)
|
||||||
end
|
end
|
||||||
|
|
||||||
len0 = true
|
len0 = true
|
||||||
non_digit = false
|
non_digit = false
|
||||||
while ch = getc
|
while ch = getc
|
||||||
|
@ -999,7 +999,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
return Token(TkINTEGER)
|
return Token(TkINTEGER)
|
||||||
end
|
end
|
||||||
|
|
||||||
type = TkINTEGER
|
type = TkINTEGER
|
||||||
allow_point = true
|
allow_point = true
|
||||||
allow_e = true
|
allow_e = true
|
||||||
|
@ -1042,7 +1042,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
Token(type)
|
Token(type)
|
||||||
end
|
end
|
||||||
|
|
||||||
def identify_string(ltype, quoted = ltype)
|
def identify_string(ltype, quoted = ltype)
|
||||||
@ltype = ltype
|
@ltype = ltype
|
||||||
@quoted = quoted
|
@quoted = quoted
|
||||||
|
@ -1063,7 +1063,7 @@ class RubyLex
|
||||||
elsif ch == '\\' #'
|
elsif ch == '\\' #'
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
if PERCENT_PAREN.values.include?(@quoted)
|
if PERCENT_PAREN.values.include?(@quoted)
|
||||||
if PERCENT_PAREN[ch] == @quoted
|
if PERCENT_PAREN[ch] == @quoted
|
||||||
nest += 1
|
nest += 1
|
||||||
elsif ch == @quoted
|
elsif ch == @quoted
|
||||||
|
@ -1087,7 +1087,7 @@ class RubyLex
|
||||||
@lex_state = EXPR_END
|
@lex_state = EXPR_END
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def identify_comment
|
def identify_comment
|
||||||
@ltype = "#"
|
@ltype = "#"
|
||||||
|
|
||||||
|
@ -1103,7 +1103,7 @@ class RubyLex
|
||||||
end
|
end
|
||||||
return Token(TkCOMMENT)
|
return Token(TkCOMMENT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_escape
|
def read_escape
|
||||||
case ch = getc
|
case ch = getc
|
||||||
when "\n", "\r", "\f"
|
when "\n", "\r", "\f"
|
||||||
|
@ -1120,7 +1120,7 @@ class RubyLex
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
when "x"
|
when "x"
|
||||||
2.times do
|
2.times do
|
||||||
case ch = getc
|
case ch = getc
|
||||||
|
@ -1149,7 +1149,7 @@ class RubyLex
|
||||||
read_escape
|
read_escape
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
# other characters
|
# other characters
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/ruby-token.rb - ruby tokens
|
# irb/ruby-token.rb - ruby tokens
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
module RubyToken
|
module RubyToken
|
||||||
EXPR_BEG = :EXPR_BEG
|
EXPR_BEG = :EXPR_BEG
|
||||||
|
@ -22,7 +22,7 @@ module RubyToken
|
||||||
if !defined?(Symbol)
|
if !defined?(Symbol)
|
||||||
Symbol = Integer
|
Symbol = Integer
|
||||||
end
|
end
|
||||||
|
|
||||||
class Token
|
class Token
|
||||||
def initialize(seek, line_no, char_no)
|
def initialize(seek, line_no, char_no)
|
||||||
@seek = seek
|
@seek = seek
|
||||||
|
@ -87,7 +87,7 @@ module RubyToken
|
||||||
if (tk = TkReading2Token[token]).nil?
|
if (tk = TkReading2Token[token]).nil?
|
||||||
IRB.fail TkReading2TokenNoKey, token
|
IRB.fail TkReading2TokenNoKey, token
|
||||||
end
|
end
|
||||||
tk = Token(tk[0], value)
|
tk = Token(tk[0], value)
|
||||||
if tk.kind_of?(TkOp)
|
if tk.kind_of?(TkOp)
|
||||||
tk.name = token
|
tk.name = token
|
||||||
end
|
end
|
||||||
|
@ -96,8 +96,8 @@ module RubyToken
|
||||||
if (tk = TkSymbol2Token[token]).nil?
|
if (tk = TkSymbol2Token[token]).nil?
|
||||||
IRB.fail TkSymbol2TokenNoKey, token
|
IRB.fail TkSymbol2TokenNoKey, token
|
||||||
end
|
end
|
||||||
return Token(tk[0], value)
|
return Token(tk[0], value)
|
||||||
else
|
else
|
||||||
if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
|
if (token.ancestors & [TkId, TkVal, TkOPASGN, TkUnknownChar]).empty?
|
||||||
token.new(@prev_seek, @prev_line_no, @prev_char_no)
|
token.new(@prev_seek, @prev_line_no, @prev_char_no)
|
||||||
else
|
else
|
||||||
|
@ -197,7 +197,7 @@ module RubyToken
|
||||||
[:TkASSOC, TkOp, "=>"],
|
[:TkASSOC, TkOp, "=>"],
|
||||||
[:TkQUESTION, TkOp, "?"], #?
|
[:TkQUESTION, TkOp, "?"], #?
|
||||||
[:TkCOLON, TkOp, ":"], #:
|
[:TkCOLON, TkOp, ":"], #:
|
||||||
|
|
||||||
[:TkfLPAREN], # func( #
|
[:TkfLPAREN], # func( #
|
||||||
[:TkfLBRACK], # func[ #
|
[:TkfLBRACK], # func[ #
|
||||||
[:TkfLBRACE], # func{ #
|
[:TkfLBRACE], # func{ #
|
||||||
|
@ -253,7 +253,7 @@ module RubyToken
|
||||||
IRB.fail AlreadyDefinedToken, token_n
|
IRB.fail AlreadyDefinedToken, token_n
|
||||||
end
|
end
|
||||||
token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
|
token_c = eval("class #{token_n} < #{super_token}; end; #{token_n}")
|
||||||
|
|
||||||
if reading
|
if reading
|
||||||
if TkReading2Token[reading]
|
if TkReading2Token[reading]
|
||||||
IRB.fail TkReading2TokenDuplicateError, token_n, reading
|
IRB.fail TkReading2TokenDuplicateError, token_n, reading
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "e2mmap"
|
require "e2mmap"
|
||||||
|
@ -25,20 +25,20 @@ module IRB
|
||||||
D_WARN = DOUT::def_notifier(1, "Warn: ")
|
D_WARN = DOUT::def_notifier(1, "Warn: ")
|
||||||
D_DEBUG = DOUT::def_notifier(2, "Debug: ")
|
D_DEBUG = DOUT::def_notifier(2, "Debug: ")
|
||||||
D_DETAIL = DOUT::def_notifier(4, "Detail: ")
|
D_DETAIL = DOUT::def_notifier(4, "Detail: ")
|
||||||
|
|
||||||
DOUT.level = Notifier::D_NOMSG
|
DOUT.level = Notifier::D_NOMSG
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@head = Node.new("")
|
@head = Node.new("")
|
||||||
end
|
end
|
||||||
|
|
||||||
def def_rule(token, preproc = nil, postproc = nil, &block)
|
def def_rule(token, preproc = nil, postproc = nil, &block)
|
||||||
D_DETAIL.pp token
|
D_DETAIL.pp token
|
||||||
|
|
||||||
postproc = block if block_given?
|
postproc = block if block_given?
|
||||||
node = create(token, preproc, postproc)
|
node = create(token, preproc, postproc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def def_rules(*tokens, &block)
|
def def_rules(*tokens, &block)
|
||||||
if block_given?
|
if block_given?
|
||||||
p = block
|
p = block
|
||||||
|
@ -47,18 +47,18 @@ module IRB
|
||||||
def_rule(token, nil, p)
|
def_rule(token, nil, p)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def preproc(token, proc)
|
def preproc(token, proc)
|
||||||
node = search(token)
|
node = search(token)
|
||||||
node.preproc=proc
|
node.preproc=proc
|
||||||
end
|
end
|
||||||
|
|
||||||
#$BMW%A%'%C%/(B?
|
#$BMW%A%'%C%/(B?
|
||||||
def postproc(token)
|
def postproc(token)
|
||||||
node = search(token, proc)
|
node = search(token, proc)
|
||||||
node.postproc=proc
|
node.postproc=proc
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(token)
|
def search(token)
|
||||||
@head.search(token.split(//))
|
@head.search(token.split(//))
|
||||||
end
|
end
|
||||||
|
@ -66,7 +66,7 @@ module IRB
|
||||||
def create(token, preproc = nil, postproc = nil)
|
def create(token, preproc = nil, postproc = nil)
|
||||||
@head.create_subnode(token.split(//), preproc, postproc)
|
@head.create_subnode(token.split(//), preproc, postproc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(token)
|
def match(token)
|
||||||
case token
|
case token
|
||||||
when Array
|
when Array
|
||||||
|
@ -79,14 +79,14 @@ module IRB
|
||||||
D_DETAIL.exec_if{D_DEATIL.printf "match end: %s:%s\n", ret, token.inspect}
|
D_DETAIL.exec_if{D_DEATIL.printf "match end: %s:%s\n", ret, token.inspect}
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
format("<SLex: @head = %s>", @head.inspect)
|
format("<SLex: @head = %s>", @head.inspect)
|
||||||
end
|
end
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# class Node -
|
# class Node -
|
||||||
#
|
#
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
class Node
|
class Node
|
||||||
|
@ -100,7 +100,7 @@ module IRB
|
||||||
|
|
||||||
attr_accessor :preproc
|
attr_accessor :preproc
|
||||||
attr_accessor :postproc
|
attr_accessor :postproc
|
||||||
|
|
||||||
def search(chrs, opt = nil)
|
def search(chrs, opt = nil)
|
||||||
return self if chrs.empty?
|
return self if chrs.empty?
|
||||||
ch = chrs.shift
|
ch = chrs.shift
|
||||||
|
@ -115,7 +115,7 @@ module IRB
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_subnode(chrs, preproc = nil, postproc = nil)
|
def create_subnode(chrs, preproc = nil, postproc = nil)
|
||||||
if chrs.empty?
|
if chrs.empty?
|
||||||
if @postproc
|
if @postproc
|
||||||
|
@ -128,7 +128,7 @@ module IRB
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
ch = chrs.shift
|
ch = chrs.shift
|
||||||
if node = @Tree[ch]
|
if node = @Tree[ch]
|
||||||
if chrs.empty?
|
if chrs.empty?
|
||||||
|
@ -162,7 +162,7 @@ module IRB
|
||||||
# chrs: String
|
# chrs: String
|
||||||
# character array
|
# character array
|
||||||
# io must have getc()/ungetc(); and ungetc() must be
|
# io must have getc()/ungetc(); and ungetc() must be
|
||||||
# able to be called arbitrary number of times.
|
# able to be called arbitrary number of times.
|
||||||
#
|
#
|
||||||
def match(chrs, op = "")
|
def match(chrs, op = "")
|
||||||
D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
|
D_DETAIL.print "match>: ", chrs, "op:", op, "\n"
|
||||||
|
@ -257,14 +257,14 @@ if $0 == __FILE__
|
||||||
print "1: ", tr.inspect, "\n"
|
print "1: ", tr.inspect, "\n"
|
||||||
tr.def_rule("==") {print "==\n"}
|
tr.def_rule("==") {print "==\n"}
|
||||||
print "2: ", tr.inspect, "\n"
|
print "2: ", tr.inspect, "\n"
|
||||||
|
|
||||||
print "case 1:\n"
|
print "case 1:\n"
|
||||||
print tr.match("="), "\n"
|
print tr.match("="), "\n"
|
||||||
print "case 2:\n"
|
print "case 2:\n"
|
||||||
print tr.match("=="), "\n"
|
print tr.match("=="), "\n"
|
||||||
print "case 3:\n"
|
print "case 3:\n"
|
||||||
print tr.match("=>"), "\n"
|
print tr.match("=>"), "\n"
|
||||||
|
|
||||||
when "2"
|
when "2"
|
||||||
tr = SLex.new
|
tr = SLex.new
|
||||||
print "0: ", tr.inspect, "\n"
|
print "0: ", tr.inspect, "\n"
|
||||||
|
@ -272,7 +272,7 @@ if $0 == __FILE__
|
||||||
print "1: ", tr.inspect, "\n"
|
print "1: ", tr.inspect, "\n"
|
||||||
tr.def_rule("==", proc{false}) {print "==\n"}
|
tr.def_rule("==", proc{false}) {print "==\n"}
|
||||||
print "2: ", tr.inspect, "\n"
|
print "2: ", tr.inspect, "\n"
|
||||||
|
|
||||||
print "case 1:\n"
|
print "case 1:\n"
|
||||||
print tr.match("="), "\n"
|
print tr.match("="), "\n"
|
||||||
print "case 2:\n"
|
print "case 2:\n"
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
module IRB
|
module IRB
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/workspace-binding.rb -
|
# irb/workspace-binding.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
module IRB
|
module IRB
|
||||||
class WorkSpace
|
class WorkSpace
|
||||||
|
@ -22,7 +22,7 @@ module IRB
|
||||||
case IRB.conf[:CONTEXT_MODE]
|
case IRB.conf[:CONTEXT_MODE]
|
||||||
when 0 # binding in proc on TOPLEVEL_BINDING
|
when 0 # binding in proc on TOPLEVEL_BINDING
|
||||||
@binding = eval("proc{binding}.call",
|
@binding = eval("proc{binding}.call",
|
||||||
TOPLEVEL_BINDING,
|
TOPLEVEL_BINDING,
|
||||||
__FILE__,
|
__FILE__,
|
||||||
__LINE__)
|
__LINE__)
|
||||||
when 1 # binding in loaded file
|
when 1 # binding in loaded file
|
||||||
|
@ -38,7 +38,7 @@ EOF
|
||||||
when 2 # binding in loaded file(thread use)
|
when 2 # binding in loaded file(thread use)
|
||||||
unless defined? BINDING_QUEUE
|
unless defined? BINDING_QUEUE
|
||||||
require "thread"
|
require "thread"
|
||||||
|
|
||||||
IRB.const_set("BINDING_QUEUE", SizedQueue.new(1))
|
IRB.const_set("BINDING_QUEUE", SizedQueue.new(1))
|
||||||
Thread.abort_on_exception = true
|
Thread.abort_on_exception = true
|
||||||
Thread.start do
|
Thread.start do
|
||||||
|
@ -50,7 +50,7 @@ EOF
|
||||||
|
|
||||||
when 3 # binging in function on TOPLEVEL_BINDING(default)
|
when 3 # binging in function on TOPLEVEL_BINDING(default)
|
||||||
@binding = eval("def irb_binding; binding; end; irb_binding",
|
@binding = eval("def irb_binding; binding; end; irb_binding",
|
||||||
TOPLEVEL_BINDING,
|
TOPLEVEL_BINDING,
|
||||||
__FILE__,
|
__FILE__,
|
||||||
__LINE__ - 3)
|
__LINE__ - 3)
|
||||||
end
|
end
|
||||||
|
@ -64,7 +64,7 @@ EOF
|
||||||
when Module
|
when Module
|
||||||
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
@binding = eval("IRB.conf[:__MAIN__].module_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
@binding = eval("IRB.conf[:__MAIN__].instance_eval('binding', __FILE__, __LINE__)", @binding, __FILE__, __LINE__)
|
||||||
rescue TypeError
|
rescue TypeError
|
||||||
IRB.fail CantChangeBinding, @main.inspect
|
IRB.fail CantChangeBinding, @main.inspect
|
||||||
|
@ -80,7 +80,7 @@ EOF
|
||||||
def evaluate(context, statements, file = __FILE__, line = __LINE__)
|
def evaluate(context, statements, file = __FILE__, line = __LINE__)
|
||||||
eval(statements, @binding, file, line)
|
eval(statements, @binding, file, line)
|
||||||
end
|
end
|
||||||
|
|
||||||
# error message manipulator
|
# error message manipulator
|
||||||
def filter_backtrace(bt)
|
def filter_backtrace(bt)
|
||||||
case IRB.conf[:CONTEXT_MODE]
|
case IRB.conf[:CONTEXT_MODE]
|
||||||
|
@ -96,7 +96,7 @@ EOF
|
||||||
return nil if bt =~ /irb\/.*\.rb/
|
return nil if bt =~ /irb\/.*\.rb/
|
||||||
when 3
|
when 3
|
||||||
return nil if bt =~ /irb\/.*\.rb/
|
return nil if bt =~ /irb\/.*\.rb/
|
||||||
bt.sub!(/:\s*in `irb_binding'/){""}
|
bt.sub!(/:\s*in `irb_binding'/){""}
|
||||||
end
|
end
|
||||||
bt
|
bt
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# irb/ws-for-case-2.rb -
|
# irb/ws-for-case-2.rb -
|
||||||
# $Release Version: 0.9.5$
|
# $Release Version: 0.9.5$
|
||||||
# $Revision$
|
# $Revision$
|
||||||
# $Date$
|
# $Date$
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
while true
|
while true
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
require "irb"
|
require "irb"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# The Mail class represents an internet mail message (as per RFC822, RFC2822)
|
# The Mail class represents an internet mail message (as per RFC822, RFC2822)
|
||||||
# with headers and a body.
|
# with headers and a body.
|
||||||
class Mail
|
class Mail
|
||||||
|
|
||||||
# Create a new Mail where +f+ is either a stream which responds to gets(),
|
# Create a new Mail where +f+ is either a stream which responds to gets(),
|
||||||
|
@ -31,7 +31,7 @@ class Mail
|
||||||
@header[attr] += "\n" + line
|
@header[attr] += "\n" + line
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless line
|
return unless line
|
||||||
|
|
||||||
while line = f.gets()
|
while line = f.gets()
|
||||||
|
@ -53,7 +53,7 @@ class Mail
|
||||||
return @body
|
return @body
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return the header corresponding to +field+.
|
# Return the header corresponding to +field+.
|
||||||
#
|
#
|
||||||
# Matching is case-insensitive.
|
# Matching is case-insensitive.
|
||||||
def [](field)
|
def [](field)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue