#!/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 # DSK images as used by Tandy CoCo emulators # DSK images as used by TI 99/4a emulators # JV1 DSK images as used by TRS-80 emulators # D64 images as used by C64 emulators # ATR images as used by Atari 400/800 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 # # files with extension .gz will be read & written using gzip # input files can be URLs # #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' #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 #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 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 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?) 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 (!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 end #if run from command line # == Author # Jonno Downes (jonno@jamtronix.com) # # == Copyright # Copyright (c) 2008 Jonno Downes (jonno@jamtronix.com) # #Permission is hereby granted, free of charge, to any person obtaining #a copy of this software and associated documentation files (the #"Software"), to deal in the Software without restriction, including #without limitation the rights to use, copy, modify, merge, publish, #distribute, sublicense, and/or sell copies of the Software, and to #permit persons to whom the Software is furnished to do so, subject to #the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.