diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-18 13:09:26 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-18 13:09:26 +0000 |
commit | 5c1bd53c92f888f45f6a843f2ef70f2fcdac077f () | |
tree | 5e59d6e126eff13c9e661aa12f0b33f5db20b6c8 /lib | |
parent | 52d481d8de7ee3e0dfaef7322d540f95223bf41b (diff) |
* lib/irb/init.rb (IRB.opt_parse): (M17N) adds -U and -E as command
line options. [ruby-dev:37161]. Fixes #711. improved long optinos. * lib/irb/init.rb (IRB.set_encoding): new subroutine for IRB.opt_parse * lib/irb/input-method.rb (IRB::StdioInputMethod): (M17N) regards scripts that user types as encoded in the external_encoding. * lib/irb/input-method.rb (IRB::ReadlineInputMethod): ditto. * lib/irb/input-method.rb (IRB::FileInputMethod): (M17N) respects magic comment. * lib/irb/help.rb (IRB.print_usage): (M17N) respects magic comment in the resource file. * lib/irb/lc/help-message: adds -U and -E. * lib/irb/lc/ja/help-message: ditto. re-encoded from ISO-2022-JP into UTF-8. * lib/irb/lc/ja/encoding_aliases.rb: new file. provides Japanese specific character encoding name table for backward compatibility. * lib/irb/lc/ja/error.rb: re-eoncoded from ISO-2022-JP into UTF-8. magic comment. * lib/irb/locale.rb: integrated with Ruby 1.9's M17N support. * lib/irb/magic-file.rb: new file. utility to handle files with magic comment and opens in the correct encoding. * lib/irb/ruby-lex.rb (RubyLex#each_top_level_statement): recovers character encoding for a statement after it lexed so that irb can eval the statement in correct encoding. * lib/irb/src_encoding.rb: new file. utility. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/irb/help.rb | 27 | ||||
-rw-r--r-- | lib/irb/init.rb | 46 | ||||
-rw-r--r-- | lib/irb/input-method.rb | 32 | ||||
-rw-r--r-- | lib/irb/lc/help-message | 4 | ||||
-rw-r--r-- | lib/irb/lc/ja/encoding_aliases.rb | 8 | ||||
-rw-r--r-- | lib/irb/lc/ja/error.rb | 23 | ||||
-rw-r--r-- | lib/irb/lc/ja/help-message | 50 | ||||
-rw-r--r-- | lib/irb/locale.rb | 109 | ||||
-rw-r--r-- | lib/irb/magic-file.rb | 36 | ||||
-rw-r--r-- | lib/irb/ruby-lex.rb | 1 | ||||
-rw-r--r-- | lib/irb/src_encoding.rb | 4 |
11 files changed, 232 insertions, 108 deletions
@@ -9,24 +9,27 @@ # # module IRB def IRB.print_usage lc = IRB.conf[:LC_MESSAGES] path = lc.find("irb/help-message") space_line = false - File.foreach(path) do - |l| - if /^\s*$/ =~ l - lc.puts l unless space_line - space_line = true - next end - space_line = false - - l.sub!(/#.*$/, "") - next if /^\s*$/ =~ l - lc.puts l - end end end @@ -139,6 +139,11 @@ module IRB when /^-I(.+)?/ opt = $1 || ARGV.shift load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt when "--inspect" @CONF[:INSPECT_MODE] = true when "--noinspect" @@ -155,8 +160,9 @@ module IRB @CONF[:VERBOSE] = true when "--noverbose" @CONF[:VERBOSE] = false - when "--prompt-mode", "--prompt" - prompt_mode = ARGV.shift.upcase.tr("-", "_").intern @CONF[:PROMPT_MODE] = prompt_mode when "--noprompt" @CONF[:PROMPT_MODE] = :NULL @@ -166,14 +172,14 @@ module IRB @CONF[:PROMPT_MODE] = :SIMPLE when "--tracer" @CONF[:USE_TRACER] = true - when "--back-trace-limit" - @CONF[:BACK_TRACE_LIMIT] = ARGV.shift.to_i - when "--context-mode" - @CONF[:CONTEXT_MODE] = ARGV.shift.to_i when "--single-irb" @CONF[:SINGLE_IRB] = true - when "--irb_debug" - @CONF[:DEBUG_LEVEL] = ARGV.shift.to_i when "-v", "--version" print IRB.version, "\n" exit 0 @@ -181,6 +187,12 @@ module IRB require "irb/help" IRB.print_usage exit 0 when /^-/ IRB.fail UnrecognizedSwitch, opt else @@ -195,6 +207,7 @@ module IRB end end $LOAD_PATH.unshift(*load_path) end # running config @@ -253,4 +266,21 @@ module IRB end end end @@ -8,6 +8,9 @@ # # # module IRB # # InputMethod @@ -41,15 +44,19 @@ module IRB super @line_no = 0 @line = [] end def gets print @prompt - @line[@line_no += 1] = $stdin.gets end def eof? - $stdin.eof? end def readable_atfer_eof? @@ -59,12 +66,16 @@ module IRB def line(line_no) @line[line_no] end end class FileInputMethod < InputMethod def initialize(file) super - @io = open(file) end attr_reader :file_name @@ -78,6 +89,10 @@ module IRB # print @prompt, l l end end begin @@ -90,11 +105,14 @@ module IRB @line_no = 0 @line = [] @eof = false end def gets - Readline.input = STDIN - Readline.output = STDOUT if l = readline(@prompt, false) HISTORY.push(l) if !l.empty? @line[@line_no += 1] = l + "\n" @@ -115,6 +133,10 @@ module IRB def line(line_no) @line[line_no] end end rescue LoadError end @@ -1,3 +1,4 @@ # # irb/lc/help-message.rb - # $Release Version: 0.9.5$ @@ -14,6 +15,8 @@ Usage: irb.rb [options] [programfile] [arguments] -d Set $DEBUG to true (same as `ruby -d') -r load-module Same as `ruby -r' -I path Specify $LOAD_PATH directory --inspect Use `inspect' for output (default except for bc mode) --noinspect Don't use inspect for output --readline Use Readline extension module @@ -32,3 +35,4 @@ Usage: irb.rb [options] [programfile] [arguments] value is 16. --irb_debug n Set internal debug level to n (not for popular use) -v, --version Print the version of irb @@ -0,0 +1,8 @@ @@ -1,4 +1,4 @@ -# # irb/lc/ja/error.rb - # $Release Version: 0.9.5$ # $Revision$ @@ -13,14 +13,15 @@ require "e2mmap" module IRB # exceptions extend Exception2MessageMapper - def_exception :UnrecognizedSwitch, '$B%9%$%C%A(B(%s)$B$,J,$j$^$;$s(B' - def_exception :NotImplementedError, '`%s\'$B$NDj5A$,I,MW$G$9(B' - def_exception :CantReturnToNormalMode, 'Normal$B%b!<%I$KLa$l$^$;$s(B.' - def_exception :IllegalParameter, '$B%Q%i%a!<%?(B(%s)$B$,4V0c$C$F$$$^$9(B.' - def_exception :IrbAlreadyDead, 'Irb$B$O4{$K;`$s$G$$$^$9(B.' - def_exception :IrbSwitchedToCurrentThread, '$B%+%l%s%H%9%l%C%I$K@Z$jBX$o$j$^$7$?(B.' - def_exception :NoSuchJob, '$B$=$N$h$&$J%8%g%V(B(%s)$B$O$"$j$^$;$s(B.' - def_exception :CantShiftToMultiIrbMode, 'multi-irb mode$B$K0\$l$^$;$s(B.' - def_exception :CantChangeBinding, '$B%P%$%s%G%#%s%0(B(%s)$B$KJQ99$G$-$^$;$s(B.' - def_exception :UndefinedPromptMode, '$B%W%m%s%W%H%b!<%I(B(%s)$B$ODj5A$5$l$F$$$^$;$s(B.' end @@ -1,4 +1,4 @@ -# # irb/lc/ja/help-message.rb - # $Release Version: 0.9.5$ # $Revision$ @@ -9,27 +9,31 @@ # # Usage: irb.rb [options] [programfile] [arguments] - -f ~/.irbrc $B$rFI$_9~$^$J$$(B. - -m bc$B%b!<%I(B($BJ,?t(B, $B9TNs$N7W;;$,$G$-$k(B) - -d $DEBUG $B$r(Btrue$B$K$9$k(B(ruby -d $B$HF1$8(B) - -r load-module ruby -r $B$HF1$8(B. - -I path $LOAD_PATH $B$K(B path $B$rDI2C$9$k(B. - --inspect $B7k2L=PNO$K(Binspect$B$rMQ$$$k(B(bc$B%b!<%I0J30$O%G%U%)%k%H(B). - --noinspect $B7k2L=PNO$K(Binspect$B$rMQ$$$J$$(B. - --readline readline$B%i%$%V%i%j$rMxMQ$9$k(B. - --noreadline readline$B%i%$%V%i%j$rMxMQ$7$J$$(B. --prompt prompt-mode/--prompt-mode prompt-mode - $B%W%m%s%W%H%b!<%I$r@ZBX$($^$9(B. $B8=:_Dj5A$5$l$F$$$k%W(B - $B%m%s%W%H%b!<%I$O(B, default, simple, xmp, inf-ruby$B$,(B - $BMQ0U$5$l$F$$$^$9(B. - --inf-ruby-mode emacs$B$N(Binf-ruby-mode$BMQ$N%W%m%s%W%HI=<($r9T$J$&(B. $BFC(B - $B$K;XDj$,$J$$8B$j(B, readline$B%i%$%V%i%j$O;H$o$J$/$J$k(B. - --simple-prompt $BHs>o$K%7%s%W%k$J%W%m%s%W%H$rMQ$$$k%b!<%I$G$9(B. - --noprompt $B%W%m%s%W%HI=<($r9T$J$o$J$$(B. - --tracer $B%3%^%s%I<B9T;~$K%H%l!<%9$r9T$J$&(B. --back-trace-limit n - $B%P%C%/%H%l!<%9I=<($r%P%C%/%H%l!<%9$NF,$+$i(B n, $B8e$m(B - $B$+$i(Bn$B$@$19T$J$&(B. $B%G%U%)%k%H$O(B16 - --irb_debug n irb$B$N%G%P%C%0%G%P%C%0%l%Y%k$r(Bn$B$K@_Dj$9$k(B($BMxMQ$7$J(B - $B$$J}$,L5Fq$G$7$g$&(B). - -v, --version irb$B$N%P!<%8%g%s$rI=<($9$k(B @@ -8,43 +8,51 @@ # # # - -autoload :Kconv, "kconv" - module IRB class Locale @RCS_ID='-$Id$-' - JPDefaultLocale = "ja" LOCALE_DIR = "/lc/" - def initialize(locale = nil) - @lang = locale || ENV["IRB_LANG"] || ENV["LC_MESSAGES"] || ENV["LC_ALL"] || ENV["LANG"] || "C" - end - - attr_reader :lang - def lc2kconv(lang) - case lang - when "ja_JP.ujis", "ja_JP.euc", "ja_JP.eucJP", "ja_JP.EUC-JP" - Kconv::EUC - when "ja_JP.sjis", "ja_JP.SJIS" - Kconv::SJIS - when /ja_JP.utf-?8/i - Kconv::UTF8 end end - private :lc2kconv def String(mes) mes = super(mes) - case @lang - when /^ja/ - mes = Kconv::kconv(mes, lc2kconv(@lang)) else mes end - mes end def format(*opts) @@ -106,27 +114,20 @@ module IRB dir = "" if dir == "." base = File.basename(file) - if /^ja(_JP)?$/ =~ @lang - back, @lang = @lang, "C" end - begin - if dir[0] == ?/ #/ - lc_path = search_file(dir, base) - return real_load(lc_path, priv) if lc_path - end - - for path in $: - lc_path = search_file(path + "/" + dir, base) - return real_load(lc_path, priv) if lc_path - end - ensure - @lang = back if back end raise LoadError, "No such file to load -- #{file}" end def real_load(path, priv) - src = self.String(File.read(path)) if priv eval("self", TOPLEVEL_BINDING).extend(Module.new {eval(src, nil, path)}) else @@ -152,29 +153,39 @@ module IRB end def search_file(path, file) - if File.exist?(p1 = path + lc_path(file, "C")) - if File.exist?(p2 = path + lc_path(file)) - return p2 - else - end - return p1 - else end nil end private :search_file - def lc_path(file = "", lc = @lang) - case lc - when "C" LOCALE_DIR + file - when /^ja/ - LOCALE_DIR + "ja/" + file else LOCALE_DIR + @lang + "/" + file end end private :lc_path end end @@ -0,0 +1,36 @@ @@ -240,6 +240,7 @@ class RubyLex end end if @line != "\n" yield @line, @exp_line_no end break unless l @@ -0,0 +1,4 @@ |