bin/dsktool.rb in dsktool-0.1.4 vs bin/dsktool.rb in dsktool-0.1.5
- old
+ new
@@ -9,11 +9,12 @@
#
# dsktool.rb [switches] <filename.dsk>
# -c | --catalog display catalog
# -e | --extract FILENAME extract file by name (either to stdout,
# or file specified by --output)
-# -h | --help display this message
+# -h | --help display this message
+# -d | --dump FILENAME hex dump
# -l | --list FILENAME monitor style listing (disassembles 65C02 opcodes)
# -o | --output FILENAME specify name to save extracted file as
# -r | --raw don't convert basic files to ASCII
# -x | --explode extract all files
# -v | --version show version number
@@ -27,77 +28,55 @@
# dsktool.rb -l FID DOS3MASTR.dsk
# dsktool.rb --list fid -o fid.lst DOS3MASTR.dsk
# dsktool.rb --extract "COLOR DEMOSOFT" DOS3MASTR.dsk
# dsktool.rb -e HELLO -o HELLO.bas DOS3MASTR.dsk
# dsktool.rb -x DOS3MASTR.dsk.gz
+# dsktool.rb -x DOS3MASTR.dsk.gz -o /tmp/DOS3MASTR/
# dsktool.rb -c http://jamtronix.com/dsks/apshai.dsk.gz
-DSKTOOL_VERSION="0.1.4"
+DSKTOOL_VERSION="0.1.5"
+#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 'optparse'
-require 'rdoc/usage'
+require 'rdoc_patch' #RDoc::usage patched to work under gem executables
-#due to a bug in rdoc, RDoc.usage won't work correctly when run from a gem executable
-# see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211297
-# Display usage from the given file
-def RDoc.usage_from_file(input_file, *args)
- comment = File.open(input_file) do |file|
- RDoc.find_comment(file)
- end
- comment = comment.gsub(/^\s*#/, '')
-
- markup = SM::SimpleMarkup.new
- flow_convertor = SM::ToFlow.new
-
- flow = markup.convert(comment, flow_convertor)
-
- format = "plain"
-
- unless args.empty?
- flow = extract_sections(flow, args)
- end
-
- options = RI::Options.instance
- if args = ENV["RI"]
- options.parse(args.split)
- end
- formatter = options.formatter.new(options, "")
- formatter.display_flow(flow)
- exit
-end
-
-
catalog=false
explode=false
-raw_mode=false
output_filename=nil
extract_filename=nil
-list_filename=nil
+extract_mode=:default
explode_directory=nil
opts=OptionParser.new
opts.on("-h","--help") {RDoc::usage_from_file(__FILE__)}
opts.on("-v","--version") do
- puts "dsktool.rb "+DSKTOOL_VERSION
+ puts File.basename($0)+" "+DSKTOOL_VERSION
exit
end
-opts.on("-r","--raw") {raw_mode=true}
+opts.on("-r","--raw") {extract_mode=:raw}
opts.on("-c","--catalog") {catalog=true}
opts.on("-x","--explode") {explode=true}
-opts.on("-l","--list FILENAME",String) {|val| list_filename=val.upcase}
+opts.on("-l","--list FILENAME",String) do |val|
+ extract_filename=val.upcase
+ extract_mode=:list
+end
+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}
filename=opts.parse(ARGV)[0] rescue RDoc::usage_from_file(__FILE__,'Usage')
RDoc::usage_from_file(__FILE__,'Usage') if (filename.nil?)
-#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 'DSK'
dsk=DSK.read(filename)
output_file= case
- when (output_filename.nil?) then STDOUT
+ when (output_filename.nil?) || (explode) then STDOUT
else File.open(output_filename,"wb")
end
if(catalog) then
if (dsk.is_dos33?) then
@@ -106,11 +85,11 @@
puts "#{filename} is not in DOS 3.3 format"
end
end
if(explode) then
- output_dir=File.basename(filename,".*")
+ output_dir=output_filename.nil??File.basename(filename,".*"):output_filename
if !(File.exists?(output_dir)) then
Dir.mkdir(output_dir)
end
dsk.files.each_value do |f|
@@ -127,27 +106,21 @@
if (!extract_filename.nil?) then
file=dsk.files[extract_filename]
if file.nil? then
puts "'#{extract_filename}' not found in #{filename}"
- else
- if (raw_mode) then
- output_file<<file.contents
- else
- output_file<<file
- end
- end
-end
-
-if (!list_filename.nil?) then
- file=dsk.files[list_filename]
- if file.nil? then
- puts "'#{list_filename}' not found in #{filename}"
- else
- if file.instance_of?(BinaryFile)
- output_file<<file.disassembly
- else
- puts "'#{list_filename}' is not a binary file"
+ else
+ output_file<< case extract_mode
+ when :raw then file.contents
+ when :hex then file.hex_dump
+ when :list then
+ if file.instance_of?(BinaryFile)
+ file.disassembly
+ else
+ puts "'#{extract_filename}' is not a binary file"
+ exit
+ end
+ else file.to_s
end
end
end
# == Author