Top Level Namespace

Defined Under Namespace

Modules: EmacsLisp, EmacsLispString, Enumerable, FilenameString, GeneratedMessage, GrepInit, IfTest, KanjiConverter, LangHelp, LocalVariables, Math, MkArray, StripTags, Test, URLConv, Untar, W3MUtils Classes: AbstractIndex, AbstractLink, Array, AssertFile, ConfigScript, Dir, File, FileContents, GenericContents, Grep, HTML, HTMLIndex, IO, Info, LuaHelp, Manpage, Matrix, MkLangHelp, MylibCommand, Numeric, Object, PHPManual, PerlDoc, PerlFunc, PodSections, Proc, PythonLib, RunConfig, ScriptBug, String, StructWithType, Suite, Tempfile, TestLangHelp, Time, URIContents, UnTable, Vector, ViewLink, W3MExtractLinks, W3MGrep, W3MLink

Constant Summary collapse

@@__system_to_string_count__ =
0

Instance Method Summary collapse

Instance Method Details

#_getopts_sub(argv, single_opts, *long_opts) ⇒ Object

getopts



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/langhelp/langhelp-sub.rb', line 190

def _getopts_sub(argv, single_opts, *long_opts)
  require 'optparse'
  opt = OptionParser.new

  (single_opts || "").split(//).each do |single_opt|
    opt.on("-#{single_opt}"){ eval "$OPT_#{single_opt}=true" }
  end

  long_opts.each do |long_opt|
    have_arg_p = (long_opt[-1,1] == ':')
    long_opt.chomp!(':')
    block = lambda{|x| eval "$OPT_#{long_opt}=x"}
    if have_arg_p
      if long_opt.length == 1   # -x arg
        opt.on("-#{long_opt} [ARG]",&block)
      else                    # --long arg
        opt.on("--#{long_opt}=[ARG]",&block)
      end
    else                        # --long
      opt.on("--#{long_opt}"){ eval "$OPT_#{long_opt}=true"}
    end
  end

  opt.parse! argv
end

#bug!(message = 'must not happen') ⇒ Object

Raises ScriptBug exception.

Raises:



772
773
774
# File 'lib/langhelp/langhelp-sub.rb', line 772

def bug!( message = 'must not happen' )
  raise ScriptBug, "\n[SCRIPT BUG] " + message
end

#getopts(single_opts, *long_opts) ⇒ Object

getopts compatibility layer using optparse.rb



217
218
219
# File 'lib/langhelp/langhelp-sub.rb', line 217

def getopts(single_opts, *long_opts)
  _getopts_sub ARGV, single_opts, *long_opts
end

#notify_exitObject

notify_exit



590
591
592
593
594
595
# File 'lib/langhelp/langhelp-sub.rb', line 590

def notify_exit
  # Notify when the program is exited.
  at_exit do
    bell_message "#$0 exited."
  end
end

#show_usage(msg = nil) ⇒ Object

show_usage Prints the script’s first comment block.



843
844
845
846
847
848
849
850
851
852
853
# File 'lib/langhelp/langhelp-sub.rb', line 843

def show_usage(msg=nil)
  name = caller[-1].sub(/:\d+$/, '')
  $stderr.puts "\nError: #{msg}" if msg
  $stderr.puts
  File.open(name) do |f|
    while line = f.readline and line.sub!(/^# ?/, '')
      $stderr.puts line
    end
  end
  exit 1
end

#system_safe(*x) ⇒ Object

system_safe mswin32 ruby’s ‘system’ workaround.



876
877
878
879
880
881
# File 'lib/langhelp/langhelp-sub.rb', line 876

def system_safe(*x)
  begin
    system *x
  rescue
  end
end

#system_to_string(*args) ⇒ Object



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/langhelp/langhelp-sub.rb', line 538

def system_to_string(*args)
  begin
    tmpf = File.join(Dir.tmpdir, "#{$$}-#{@@__system_to_string_count__}")
    @@__system_to_string_count__ += 1
    ret = nil
    open(tmpf,"w") do |f|
      IO.redirect(f) {
        system *args
      }
    end
    File.read(tmpf)
  ensure
    FileUtils.rm_f tmpf
  end
end

#vrequire(f) ⇒ Object

vrequire verbose require



55
56
57
58
59
# File 'lib/langhelp/langhelp-sub.rb', line 55

def vrequire(f)
  puts "loading " + f + "..."
  require f
  puts "loading " + f + "...done" 
end

#vsystem(cmd) ⇒ Object

vsystem verbose system



63
64
65
66
# File 'lib/langhelp/langhelp-sub.rb', line 63

def vsystem(cmd)
  puts cmd
  system cmd
end

#with_temp_dir(dir = Dir.tmpdir+"/tmp_#{$$}") ⇒ Object

Makes a temporary directory and executes a block and cleans the directory.



468
469
470
471
472
473
474
475
476
477
# File 'lib/langhelp/langhelp-sub.rb', line 468

def with_temp_dir(dir=Dir.tmpdir+"/tmp_#{$$}")
  require 'fileutils'
  begin
    dir = Pathname.new(dir).expand_path
    dir.mkdir
    Dir.chdir(dir) { yield(dir) }
  ensure
    FileUtils.rm_rf(dir)
  end
end