# # dsktool.rb # # == Synopsis # # Manipulate DSK format files (as used by Apple 2 emulators) # # == Usage # # dsktool.rb [switches] # -c | --log display catalog # -e | --extract FILENAME extract file by name (either to stdout, # or file specified by --output) # -h | --help display this message # -l | --list FILENAME monitor style listing (disassembles 65C02 opcodes) # -o | --output FILENAME specify name to save extracted file as # -x | --explode extract all files # -v | --version show version number # # Currently only works with DOS 3.3 format # DSK images can be # # examples: # dsktool.rb -c DOS3MASTR.dsk.gz # dsktool.rb -l FID DOS3MASTR.dsk # dsktool.rb --list fid -o fid.asm 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_VERSION="0.1.3" require 'optparse' require 'rdoc/usage' #due to a bug in rdoc, tghe 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 output_filename=nil extract_filename=nil list_filename=nil 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 exit end 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("-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 else File.open(output_filename,"wb") end if(catalog) then if (dsk.is_dos33?) then dsk.dump_catalog else puts "#{filename} is not in DOS 3.3 format" end end if(explode) then output_dir=File.basename(filename,".*") if !(File.exists?(output_dir)) then Dir.mkdir(output_dir) end dsk.files.each_value do |f| output_filename=output_dir+"/"+f.filename+f.file_extension File.open(output_filename,"wb") <