#!/bin/env ruby # ripxplore.rb # # == Synopsis # # Manipulate file system images as used by vintage computer emulators # Currently supports # DSK images as used by Apple 2 emulators # JV1 DSK images as used by TRS-80 emulators # D64 images as used by C64 emulators # ATR images as used by 8-bit Atari emulators # == Usage # # ripxplore.rb [switches] # -c | --catalog display catalog # -d | --dump FILENAME hex dump # -D | --diskdump hex dump of entire disk # -e | --extract FILENAME extract file by name (either to stdout, # or file specified by --output) # -h | --help display this message # -l | --list FILENAME BASIC files are listed, binary files are disassembled # -o | --output FILENAME specify name to save extracted file as # -r | --raw don't convert files to ASCII # -S | --showtrace show full stack trace on any error # -V | --verbose verbose mode # -v | --version show version number # -x | --explode extract all files # # Supports 16 sector DSK images and 35-40 track D64 images # 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 require File.expand_path(File.dirname(__FILE__)+"//..//lib")+'//RipXplore' catalog=false explode=false diskdump=false show_trace=false output_filename=nil extract_filename=nil debug_logging=false extract_mode=:default explode_directory=nil 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("-x","--explode") {explode=true} opts.on("-l","--list FILENAME",String) do |val| extract_filename=val.upcase extract_mode=:list end 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} 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 end output_file= case when (output_filename.nil?) || (explode) then STDOUT else File.open(output_filename,"wb") 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(explode) then output_dir=output_filename.nil??File.basename(filename,".*"):output_filename if !(File.exists?(output_dir)) then Dir.mkdir(output_dir) end fsimage.files.each_value do |f| if (extract_mode==:raw) then output_filename=output_dir+"/"+f.filename+".raw" File.open(output_filename,"wb") <