bin/ripxplore.rb in ripxplore-0.4.0 vs bin/ripxplore.rb in ripxplore-0.5.0

- old
+ new

@@ -31,118 +31,126 @@ # files with extension .gz will be read & written using gzip # input files can be URLs # -#make sure the relevant folder with our libraries is in the require path -lib_path=File.expand_path(File.dirname(__FILE__)+"//..//lib") -$:.unshift(lib_path) unless $:.include?(lib_path) -require 'rubygems' -require 'optparse' -require 'rdoc_patch' #RDoc::usage patched to work under gem executables - +#pull in the RipXplore lib - we need to give the specific path to it since otherwise on case insensitive OSes (e.g. windows) this file +#will get pulled in instead require File.expand_path(File.dirname(__FILE__)+"//..//lib")+'//RipXplore' -catalog=false -diskdump=false -show_trace=false -output_filename=nil -extract_filename=nil -debug_logging=false -extract_mode=:default -opts=OptionParser.new -opts.on("-h","--help") {RDoc::usage_from_file(__FILE__)} -opts.on("-v","--version") do - puts File.basename($0)+" "+RipXplore::VERSION - exit -end -opts.on("-r","--raw") {extract_mode=:raw} -opts.on("-c","--catalog") {catalog=true} -opts.on("-D","--diskdump") {diskdump=true} -opts.on("-l","--list FILENAME",String) do |val| - extract_filename=val.upcase - extract_mode=:list -end +#only do this next bit if this file was specifically executed, if not then it was probably loaded by a 'require RipXplore' on a +#case insenstive OS +if __FILE__ == $0 then -opts.on("-S","--showtrace") {show_trace=true} + #make sure the relevant folder with our libraries is in the require path + lib_path=File.expand_path(File.dirname(__FILE__)+"//..//lib") + $:.unshift(lib_path) unless $:.include?(lib_path) + require 'rubygems' + require 'optparse' + require 'rdoc_patch' #RDoc::usage patched to work under gem executables -opts.on("-d","--dump FILENAME",String) do |val| - extract_filename=val.upcase - extract_mode=:hex -end -opts.on("-e","--extract FILENAME",String) {|val| extract_filename=val.upcase} -opts.on("-o","--output FILENAME",String) {|val| output_filename=val} -opts.on("-t","--filetype FILETYPE",String) {|val| add_file_options[:filetype]=val} -opts.on("-V","--verbose") {debug_logging=true} -filename=opts.parse(ARGV)[0] rescue RDoc::usage_from_file(__FILE__,'Usage') -RDoc::usage_from_file(__FILE__,'Usage') if (filename.nil?) - - - -RipXploreLog.debug_logging if debug_logging -begin #to wrap a rescue clause - - begin - fsimage=RipXplore.best_fit_from_filename(filename) - rescue - #if we run dsktool.rb in a batch or shell file iterating over a bunch of dsk files, we may not know what file - #has the error - STDERR << "error while parsing #{filename}\n" - raise + catalog=false + diskdump=false + show_trace=false + output_filename=nil + extract_filename=nil + debug_logging=false + extract_mode=:default + opts=OptionParser.new + opts.on("-h","--help") {RDoc::usage_from_file(__FILE__)} + opts.on("-v","--version") do + puts File.basename($0)+" "+RipXplore::VERSION + exit end - - output_file= case - when (output_filename.nil?) then STDOUT - else File.open(output_filename,"wb") + opts.on("-r","--raw") {extract_mode=:raw} + opts.on("-c","--catalog") {catalog=true} + opts.on("-D","--diskdump") {diskdump=true} + opts.on("-l","--list FILENAME",String) do |val| + extract_filename=val.upcase + extract_mode=:list end - if (diskdump) then - puts fsimage.to_hex_dump + opts.on("-S","--showtrace") {show_trace=true} + + opts.on("-d","--dump FILENAME",String) do |val| + extract_filename=val.upcase + extract_mode=:hex end + opts.on("-e","--extract FILENAME",String) {|val| extract_filename=val.upcase} + opts.on("-o","--output FILENAME",String) {|val| output_filename=val} + opts.on("-t","--filetype FILETYPE",String) {|val| add_file_options[:filetype]=val} + opts.on("-V","--verbose") {debug_logging=true} - if(catalog) then + filename=opts.parse(ARGV)[0] rescue RDoc::usage_from_file(__FILE__,'Usage') + RDoc::usage_from_file(__FILE__,'Usage') if (filename.nil?) - [:host_system,:image_format,:file_system].each do |att| - if (fsimage.respond_to?(att)) then - puts "#{att.to_s}:\t#{fsimage.send(att)}" - end + + + RipXploreLog.debug_logging if debug_logging + begin #to wrap a rescue clause + + begin + fsimage=RipXplore.best_fit_from_filename(filename) + rescue + #if we run dsktool.rb in a batch or shell file iterating over a bunch of dsk files, we may not know what file + #has the error + STDERR << "error while parsing #{filename}\n" + raise end - puts fsimage.catalog - end + output_file= case + when (output_filename.nil?) then STDOUT + else File.open(output_filename,"wb") + end - if (!extract_filename.nil?) then - file=fsimage.files[extract_filename] - if file.nil? then - puts "'#{extract_filename}' not found in #{filename}" - else - output_file<< case extract_mode - when :raw then file.contents - when :hex then file.to_hex_dump - when :ascii then file.to_ascii - when :list then - if file.respond_to?(:to_listing) - file.to_listing - elsif file.respond_to?(:to_disassembly) - file.to_disassembly - else - puts "'#{extract_filename}' can't be listed" - exit - end - else - if file.respond_to?(:to_text) - file.to_text - else - file.contents - end + if (diskdump) then + puts fsimage.to_hex_dump + end + + if(catalog) then + + [:host_system,:image_format,:file_system].each do |att| + if (fsimage.respond_to?(att)) then + puts "#{att.to_s}:\t#{fsimage.send(att)}" + end end + puts fsimage.catalog end + + + if (!extract_filename.nil?) then + file=fsimage.files[extract_filename] + if file.nil? then + puts "'#{extract_filename}' not found in #{filename}" + else + output_file<< case extract_mode + when :raw then file.contents + when :hex then file.to_hex_dump + when :ascii then file.to_ascii + when :list then + if file.respond_to?(:to_listing) + file.to_listing + elsif file.respond_to?(:to_disassembly) + file.to_disassembly + else + puts "'#{extract_filename}' can't be listed" + exit + end + else + if file.respond_to?(:to_text) + file.to_text + else + file.contents + end + end + end + end + rescue + puts $! + raise if show_trace end -rescue - puts $! - raise if show_trace -end +end #if run from command line # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008 Jonno Downes (jonno@jamtronix.com)