100 lines
1.6 KiB
Text
100 lines
1.6 KiB
Text
|
#!/usr/bin/ruby
|
||
|
|
||
|
require 'optparse'
|
||
|
|
||
|
require 'rubygems'
|
||
|
require 'bindata'
|
||
|
|
||
|
require 'xtmfile/xtmheader'
|
||
|
|
||
|
|
||
|
class XtmJoin
|
||
|
class XtmJoinArgumentError < ArgumentError ; end
|
||
|
|
||
|
attr_reader :opts
|
||
|
|
||
|
|
||
|
def initialize args
|
||
|
@args = []
|
||
|
@input_xtm = nil
|
||
|
parse_command_line args
|
||
|
end
|
||
|
|
||
|
def parse_command_line args
|
||
|
@args = args.clone
|
||
|
@opts = OptionParser.new do |opts|
|
||
|
opts.banner = "Usage: #{File.basename $0} [options]\n"
|
||
|
|
||
|
opts.separator ""
|
||
|
opts.separator "Mandatory options"
|
||
|
|
||
|
opts.on("-i", "--input FILE", "Input XTM file") do |r|
|
||
|
@input_xtm = r
|
||
|
end
|
||
|
|
||
|
opts.separator ""
|
||
|
opts.separator "General options:"
|
||
|
|
||
|
opts.on("-h", "--help", "Show this help") do |h|
|
||
|
@help = h
|
||
|
end
|
||
|
opts.on("-v", "--verbose", "Show warnings too") do |v|
|
||
|
@verbose = v
|
||
|
end
|
||
|
opts.separator ""
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def validate!
|
||
|
@opts.parse!
|
||
|
|
||
|
raise XtmJoinArgumentError, "No input XTM file specified!" if @input_xtm.nil?
|
||
|
end
|
||
|
|
||
|
|
||
|
def run
|
||
|
validate!
|
||
|
|
||
|
output_file = nil
|
||
|
# initial file
|
||
|
|
||
|
in_xtm = File.open( @input_xtm, "rb" )
|
||
|
header = XtmHeader::read in_xtm
|
||
|
|
||
|
output_file = header.filename_str
|
||
|
|
||
|
puts "Writing data to %s" % output_file
|
||
|
|
||
|
# FIXME: prevent overwriting
|
||
|
out_xtm = File.open( output_file, "wb" )
|
||
|
|
||
|
while not in_xtm.eof?
|
||
|
buffer = in_xtm.read 1024
|
||
|
out_xtm.write buffer
|
||
|
end
|
||
|
|
||
|
# remaining files
|
||
|
end
|
||
|
|
||
|
def self.main args
|
||
|
xj = nil
|
||
|
begin
|
||
|
xj = XtmJoin.new args
|
||
|
xj.run
|
||
|
exit 0
|
||
|
rescue XtmJoinArgumentError => e
|
||
|
STDERR.puts "%s" % xj.opts
|
||
|
STDERR.puts "error: %s" % e.message
|
||
|
|
||
|
exit 1
|
||
|
rescue SystemExit => e
|
||
|
raise e
|
||
|
rescue Exception => e
|
||
|
STDERR.puts "error: %s" % e.message
|
||
|
exit 1
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
XtmJoin.main ARGV
|