Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby18/lib64/ruby/1.8
File: irb.rb
#
[0] Fix | Delete
# irb.rb - irb main module
[1] Fix | Delete
# $Release Version: 0.9.5 $
[2] Fix | Delete
# $Revision: 24483 $
[3] Fix | Delete
# $Date: 2009-08-09 17:44:15 +0900 (Sun, 09 Aug 2009) $
[4] Fix | Delete
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
[5] Fix | Delete
#
[6] Fix | Delete
# --
[7] Fix | Delete
#
[8] Fix | Delete
#
[9] Fix | Delete
#
[10] Fix | Delete
require "e2mmap"
[11] Fix | Delete
[12] Fix | Delete
require "irb/init"
[13] Fix | Delete
require "irb/context"
[14] Fix | Delete
require "irb/extend-command"
[15] Fix | Delete
#require "irb/workspace"
[16] Fix | Delete
[17] Fix | Delete
require "irb/ruby-lex"
[18] Fix | Delete
require "irb/input-method"
[19] Fix | Delete
require "irb/locale"
[20] Fix | Delete
[21] Fix | Delete
STDOUT.sync = true
[22] Fix | Delete
[23] Fix | Delete
module IRB
[24] Fix | Delete
@RCS_ID='-$Id: irb.rb 24483 2009-08-09 08:44:15Z shyouhei $-'
[25] Fix | Delete
[26] Fix | Delete
class Abort < Exception;end
[27] Fix | Delete
[28] Fix | Delete
#
[29] Fix | Delete
@CONF = {}
[30] Fix | Delete
[31] Fix | Delete
def IRB.conf
[32] Fix | Delete
@CONF
[33] Fix | Delete
end
[34] Fix | Delete
[35] Fix | Delete
# IRB version method
[36] Fix | Delete
def IRB.version
[37] Fix | Delete
if v = @CONF[:VERSION] then return v end
[38] Fix | Delete
[39] Fix | Delete
require "irb/version"
[40] Fix | Delete
rv = @RELEASE_VERSION.sub(/\.0/, "")
[41] Fix | Delete
@CONF[:VERSION] = format("irb %s(%s)", rv, @LAST_UPDATE_DATE)
[42] Fix | Delete
end
[43] Fix | Delete
[44] Fix | Delete
def IRB.CurrentContext
[45] Fix | Delete
IRB.conf[:MAIN_CONTEXT]
[46] Fix | Delete
end
[47] Fix | Delete
[48] Fix | Delete
# initialize IRB and start TOP_LEVEL irb
[49] Fix | Delete
def IRB.start(ap_path = nil)
[50] Fix | Delete
$0 = File::basename(ap_path, ".rb") if ap_path
[51] Fix | Delete
[52] Fix | Delete
IRB.setup(ap_path)
[53] Fix | Delete
[54] Fix | Delete
if @CONF[:SCRIPT]
[55] Fix | Delete
irb = Irb.new(nil, @CONF[:SCRIPT])
[56] Fix | Delete
else
[57] Fix | Delete
irb = Irb.new
[58] Fix | Delete
end
[59] Fix | Delete
[60] Fix | Delete
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
[61] Fix | Delete
@CONF[:MAIN_CONTEXT] = irb.context
[62] Fix | Delete
[63] Fix | Delete
trap("SIGINT") do
[64] Fix | Delete
irb.signal_handle
[65] Fix | Delete
end
[66] Fix | Delete
[67] Fix | Delete
begin
[68] Fix | Delete
catch(:IRB_EXIT) do
[69] Fix | Delete
irb.eval_input
[70] Fix | Delete
end
[71] Fix | Delete
ensure
[72] Fix | Delete
irb_at_exit
[73] Fix | Delete
end
[74] Fix | Delete
# print "\n"
[75] Fix | Delete
end
[76] Fix | Delete
[77] Fix | Delete
def IRB.irb_at_exit
[78] Fix | Delete
@CONF[:AT_EXIT].each{|hook| hook.call}
[79] Fix | Delete
end
[80] Fix | Delete
[81] Fix | Delete
def IRB.irb_exit(irb, ret)
[82] Fix | Delete
throw :IRB_EXIT, ret
[83] Fix | Delete
end
[84] Fix | Delete
[85] Fix | Delete
def IRB.irb_abort(irb, exception = Abort)
[86] Fix | Delete
if defined? Thread
[87] Fix | Delete
irb.context.thread.raise exception, "abort then interrupt!!"
[88] Fix | Delete
else
[89] Fix | Delete
raise exception, "abort then interrupt!!"
[90] Fix | Delete
end
[91] Fix | Delete
end
[92] Fix | Delete
[93] Fix | Delete
#
[94] Fix | Delete
# irb interpriter main routine
[95] Fix | Delete
#
[96] Fix | Delete
class Irb
[97] Fix | Delete
def initialize(workspace = nil, input_method = nil, output_method = nil)
[98] Fix | Delete
@context = Context.new(self, workspace, input_method, output_method)
[99] Fix | Delete
@context.main.extend ExtendCommandBundle
[100] Fix | Delete
@signal_status = :IN_IRB
[101] Fix | Delete
[102] Fix | Delete
@scanner = RubyLex.new
[103] Fix | Delete
@scanner.exception_on_syntax_error = false
[104] Fix | Delete
end
[105] Fix | Delete
attr_reader :context
[106] Fix | Delete
attr_accessor :scanner
[107] Fix | Delete
[108] Fix | Delete
def eval_input
[109] Fix | Delete
@scanner.set_prompt do
[110] Fix | Delete
|ltype, indent, continue, line_no|
[111] Fix | Delete
if ltype
[112] Fix | Delete
f = @context.prompt_s
[113] Fix | Delete
elsif continue
[114] Fix | Delete
f = @context.prompt_c
[115] Fix | Delete
elsif indent > 0
[116] Fix | Delete
f = @context.prompt_n
[117] Fix | Delete
else @context.prompt_i
[118] Fix | Delete
f = @context.prompt_i
[119] Fix | Delete
end
[120] Fix | Delete
f = "" unless f
[121] Fix | Delete
if @context.prompting?
[122] Fix | Delete
@context.io.prompt = p = prompt(f, ltype, indent, line_no)
[123] Fix | Delete
else
[124] Fix | Delete
@context.io.prompt = p = ""
[125] Fix | Delete
end
[126] Fix | Delete
if @context.auto_indent_mode
[127] Fix | Delete
unless ltype
[128] Fix | Delete
ind = prompt(@context.prompt_i, ltype, indent, line_no)[/.*\z/].size +
[129] Fix | Delete
indent * 2 - p.size
[130] Fix | Delete
ind += 2 if continue
[131] Fix | Delete
@context.io.prompt = p + " " * ind if ind > 0
[132] Fix | Delete
end
[133] Fix | Delete
end
[134] Fix | Delete
end
[135] Fix | Delete
[136] Fix | Delete
@scanner.set_input(@context.io) do
[137] Fix | Delete
signal_status(:IN_INPUT) do
[138] Fix | Delete
if l = @context.io.gets
[139] Fix | Delete
print l if @context.verbose?
[140] Fix | Delete
else
[141] Fix | Delete
if @context.ignore_eof? and @context.io.readable_atfer_eof?
[142] Fix | Delete
l = "\n"
[143] Fix | Delete
if @context.verbose?
[144] Fix | Delete
printf "Use \"exit\" to leave %s\n", @context.ap_name
[145] Fix | Delete
end
[146] Fix | Delete
end
[147] Fix | Delete
end
[148] Fix | Delete
l
[149] Fix | Delete
end
[150] Fix | Delete
end
[151] Fix | Delete
[152] Fix | Delete
@scanner.each_top_level_statement do |line, line_no|
[153] Fix | Delete
signal_status(:IN_EVAL) do
[154] Fix | Delete
begin
[155] Fix | Delete
line.untaint
[156] Fix | Delete
@context.evaluate(line, line_no)
[157] Fix | Delete
output_value if @context.echo?
[158] Fix | Delete
exc = nil
[159] Fix | Delete
rescue Interrupt => exc
[160] Fix | Delete
rescue SystemExit, SignalException
[161] Fix | Delete
raise
[162] Fix | Delete
rescue Exception => exc
[163] Fix | Delete
end
[164] Fix | Delete
if exc
[165] Fix | Delete
print exc.class, ": ", exc, "\n"
[166] Fix | Delete
if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/
[167] Fix | Delete
irb_bug = true
[168] Fix | Delete
else
[169] Fix | Delete
irb_bug = false
[170] Fix | Delete
end
[171] Fix | Delete
[172] Fix | Delete
messages = []
[173] Fix | Delete
lasts = []
[174] Fix | Delete
levels = 0
[175] Fix | Delete
for m in exc.backtrace
[176] Fix | Delete
m = @context.workspace.filter_backtrace(m) unless irb_bug
[177] Fix | Delete
if m
[178] Fix | Delete
if messages.size < @context.back_trace_limit
[179] Fix | Delete
messages.push "\tfrom "+m
[180] Fix | Delete
else
[181] Fix | Delete
lasts.push "\tfrom "+m
[182] Fix | Delete
if lasts.size > @context.back_trace_limit
[183] Fix | Delete
lasts.shift
[184] Fix | Delete
levels += 1
[185] Fix | Delete
end
[186] Fix | Delete
end
[187] Fix | Delete
end
[188] Fix | Delete
end
[189] Fix | Delete
print messages.join("\n"), "\n"
[190] Fix | Delete
unless lasts.empty?
[191] Fix | Delete
printf "... %d levels...\n", levels if levels > 0
[192] Fix | Delete
print lasts.join("\n")
[193] Fix | Delete
end
[194] Fix | Delete
print "Maybe IRB bug!!\n" if irb_bug
[195] Fix | Delete
end
[196] Fix | Delete
if $SAFE > 2
[197] Fix | Delete
abort "Error: irb does not work for $SAFE level higher than 2"
[198] Fix | Delete
end
[199] Fix | Delete
end
[200] Fix | Delete
end
[201] Fix | Delete
end
[202] Fix | Delete
[203] Fix | Delete
def suspend_name(path = nil, name = nil)
[204] Fix | Delete
@context.irb_path, back_path = path, @context.irb_path if path
[205] Fix | Delete
@context.irb_name, back_name = name, @context.irb_name if name
[206] Fix | Delete
begin
[207] Fix | Delete
yield back_path, back_name
[208] Fix | Delete
ensure
[209] Fix | Delete
@context.irb_path = back_path if path
[210] Fix | Delete
@context.irb_name = back_name if name
[211] Fix | Delete
end
[212] Fix | Delete
end
[213] Fix | Delete
[214] Fix | Delete
def suspend_workspace(workspace)
[215] Fix | Delete
@context.workspace, back_workspace = workspace, @context.workspace
[216] Fix | Delete
begin
[217] Fix | Delete
yield back_workspace
[218] Fix | Delete
ensure
[219] Fix | Delete
@context.workspace = back_workspace
[220] Fix | Delete
end
[221] Fix | Delete
end
[222] Fix | Delete
[223] Fix | Delete
def suspend_input_method(input_method)
[224] Fix | Delete
back_io = @context.io
[225] Fix | Delete
@context.instance_eval{@io = input_method}
[226] Fix | Delete
begin
[227] Fix | Delete
yield back_io
[228] Fix | Delete
ensure
[229] Fix | Delete
@context.instance_eval{@io = back_io}
[230] Fix | Delete
end
[231] Fix | Delete
end
[232] Fix | Delete
[233] Fix | Delete
def suspend_context(context)
[234] Fix | Delete
@context, back_context = context, @context
[235] Fix | Delete
begin
[236] Fix | Delete
yield back_context
[237] Fix | Delete
ensure
[238] Fix | Delete
@context = back_context
[239] Fix | Delete
end
[240] Fix | Delete
end
[241] Fix | Delete
[242] Fix | Delete
def signal_handle
[243] Fix | Delete
unless @context.ignore_sigint?
[244] Fix | Delete
print "\nabort!!\n" if @context.verbose?
[245] Fix | Delete
exit
[246] Fix | Delete
end
[247] Fix | Delete
[248] Fix | Delete
case @signal_status
[249] Fix | Delete
when :IN_INPUT
[250] Fix | Delete
print "^C\n"
[251] Fix | Delete
raise RubyLex::TerminateLineInput
[252] Fix | Delete
when :IN_EVAL
[253] Fix | Delete
IRB.irb_abort(self)
[254] Fix | Delete
when :IN_LOAD
[255] Fix | Delete
IRB.irb_abort(self, LoadAbort)
[256] Fix | Delete
when :IN_IRB
[257] Fix | Delete
# ignore
[258] Fix | Delete
else
[259] Fix | Delete
# ignore other cases as well
[260] Fix | Delete
end
[261] Fix | Delete
end
[262] Fix | Delete
[263] Fix | Delete
def signal_status(status)
[264] Fix | Delete
return yield if @signal_status == :IN_LOAD
[265] Fix | Delete
[266] Fix | Delete
signal_status_back = @signal_status
[267] Fix | Delete
@signal_status = status
[268] Fix | Delete
begin
[269] Fix | Delete
yield
[270] Fix | Delete
ensure
[271] Fix | Delete
@signal_status = signal_status_back
[272] Fix | Delete
end
[273] Fix | Delete
end
[274] Fix | Delete
[275] Fix | Delete
def prompt(prompt, ltype, indent, line_no)
[276] Fix | Delete
p = prompt.dup
[277] Fix | Delete
p.gsub!(/%([0-9]+)?([a-zA-Z])/) do
[278] Fix | Delete
case $2
[279] Fix | Delete
when "N"
[280] Fix | Delete
@context.irb_name
[281] Fix | Delete
when "m"
[282] Fix | Delete
@context.main.to_s
[283] Fix | Delete
when "M"
[284] Fix | Delete
@context.main.inspect
[285] Fix | Delete
when "l"
[286] Fix | Delete
ltype
[287] Fix | Delete
when "i"
[288] Fix | Delete
if $1
[289] Fix | Delete
format("%" + $1 + "d", indent)
[290] Fix | Delete
else
[291] Fix | Delete
indent.to_s
[292] Fix | Delete
end
[293] Fix | Delete
when "n"
[294] Fix | Delete
if $1
[295] Fix | Delete
format("%" + $1 + "d", line_no)
[296] Fix | Delete
else
[297] Fix | Delete
line_no.to_s
[298] Fix | Delete
end
[299] Fix | Delete
when "%"
[300] Fix | Delete
"%"
[301] Fix | Delete
end
[302] Fix | Delete
end
[303] Fix | Delete
p
[304] Fix | Delete
end
[305] Fix | Delete
[306] Fix | Delete
def output_value
[307] Fix | Delete
if @context.inspect?
[308] Fix | Delete
printf @context.return_format, @context.last_value.inspect
[309] Fix | Delete
else
[310] Fix | Delete
printf @context.return_format, @context.last_value
[311] Fix | Delete
end
[312] Fix | Delete
end
[313] Fix | Delete
[314] Fix | Delete
def inspect
[315] Fix | Delete
ary = []
[316] Fix | Delete
for iv in instance_variables
[317] Fix | Delete
case iv
[318] Fix | Delete
when "@signal_status"
[319] Fix | Delete
ary.push format("%s=:%s", iv, @signal_status.id2name)
[320] Fix | Delete
when "@context"
[321] Fix | Delete
ary.push format("%s=%s", iv, eval(iv).__to_s__)
[322] Fix | Delete
else
[323] Fix | Delete
ary.push format("%s=%s", iv, eval(iv))
[324] Fix | Delete
end
[325] Fix | Delete
end
[326] Fix | Delete
format("#<%s: %s>", self.class, ary.join(", "))
[327] Fix | Delete
end
[328] Fix | Delete
end
[329] Fix | Delete
[330] Fix | Delete
# Singleton method
[331] Fix | Delete
def @CONF.inspect
[332] Fix | Delete
IRB.version unless self[:VERSION]
[333] Fix | Delete
[334] Fix | Delete
array = []
[335] Fix | Delete
for k, v in sort{|a1, a2| a1[0].id2name <=> a2[0].id2name}
[336] Fix | Delete
case k
[337] Fix | Delete
when :MAIN_CONTEXT, :__TMP__EHV__
[338] Fix | Delete
array.push format("CONF[:%s]=...myself...", k.id2name)
[339] Fix | Delete
when :PROMPT
[340] Fix | Delete
s = v.collect{
[341] Fix | Delete
|kk, vv|
[342] Fix | Delete
ss = vv.collect{|kkk, vvv| ":#{kkk.id2name}=>#{vvv.inspect}"}
[343] Fix | Delete
format(":%s=>{%s}", kk.id2name, ss.join(", "))
[344] Fix | Delete
}
[345] Fix | Delete
array.push format("CONF[:%s]={%s}", k.id2name, s.join(", "))
[346] Fix | Delete
else
[347] Fix | Delete
array.push format("CONF[:%s]=%s", k.id2name, v.inspect)
[348] Fix | Delete
end
[349] Fix | Delete
end
[350] Fix | Delete
array.join("\n")
[351] Fix | Delete
end
[352] Fix | Delete
end
[353] Fix | Delete
[354] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function