X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=lib%2Fredact%2Fapp.rb;h=5a229100b1a3b9f8d22919851c1dcf5c9fdbb37b;hb=dc00882e6139ccbee72bad4f96cabe950ba0c338;hp=b706acc4abed2d3b804b84a79e5afd500c540d6a;hpb=46be2501a5b9c1b0e2a5d243beb59d96aeb0f870;p=redact.git diff --git a/lib/redact/app.rb b/lib/redact/app.rb index b706acc..5a22910 100644 --- a/lib/redact/app.rb +++ b/lib/redact/app.rb @@ -1,5 +1,5 @@ #-- -# $Id: app.rb 4 2005-03-26 19:26:56Z tilman $ +# $Id: app.rb 57 2005-06-14 15:11:35Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # @@ -32,20 +32,30 @@ require "optparse" SCRIPT_LINES__ = {} +class OpenStruct + def clear + @table = {} + end +end + module Redact + OPTIONS = OpenStruct.new + class App + attr_reader :options + def initialize(args) @filename = nil - @options = OpenStruct.new + OPTIONS.clear @option_parser = parse_args(args) - @options.input = args.first - if @options.input.nil? + OPTIONS.input = args.first + if OPTIONS.input.nil? puts @option_parser.help exit end - @options.output ||= @options.input.sub(/.[^.]+$/, ".edj") + OPTIONS.output ||= OPTIONS.input.sub(/.[^.]+$/, ".edj") end def run @@ -53,12 +63,12 @@ module Redact SCRIPT_LINES__.clear begin - load @options.input + load OPTIONS.input rescue LoadError - raise("Cannot load '#{@options.input}'") + raise("Cannot load '#{OPTIONS.input}'") end - @filename = Pathname.new(@options.input).cleanpath.to_s + @filename = Pathname.new(OPTIONS.input).cleanpath.to_s if EDJE.collections.empty? raise("No collections found") @@ -66,15 +76,20 @@ module Redact amx = compile_embryo - Eet::File.open(@options.output, "w") do |ef| - dump_amx(amx, ef) - - dump_header(ef) - dump_collections(ef) - dump_fonts(ef) - dump_images(ef) - dump_source(ef) - dump_fontmap(ef) + begin + Eet::File.open(OPTIONS.output, "w") do |ef| + dump_amx(amx, ef) + + dump_header(ef) + dump_collections(ef) + dump_fonts(ef) + dump_images(ef) + dump_source(ef) + dump_fontmap(ef) + end + rescue Exception + File.rm_f(OPTIONS.output) + raise end end @@ -88,17 +103,17 @@ module Redact o.on("-o", "--output OUTPUT_FILE", "Write Edje to OUTPUT_FILE") do |file| - @options.output = file + OPTIONS.output = file end o.on("--image_dir IMAGE_DIR", "Add IMAGE_DIR to the image lookup path") do |dir| - @options.image_dir = dir + OPTIONS.image_dir = dir end o.on("--font_dir FONT_DIR", "Add FONT_DIR to the font lookup path") do |dir| - @options.font_dir = dir + OPTIONS.font_dir = dir end o.separator "" @@ -110,11 +125,7 @@ module Redact end o.on_tail("--version", "Show version") do - puts <