#--
-# $Id: app.rb 30 2005-04-23 15:25:21Z tilman $
-#
# Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
#
# Permission is hereby granted, free of charge, to any person obtaining
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
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")
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
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 ""
tf_in.flush
Tempfile.open("redact_col#{col.id}.amx") do |tf_out|
- incl = `edje-config --datadir`.strip
+ incl = `pkg-config edje --variable=datadir`.strip
c = "embryo_cc " +
"-i #{incl}/include " +
"-o #{tf_out.path} #{tf_in.path}"
- unless system(c)
+ system(c)
+ unless (0..1).include?($?.exitstatus)
raise("Cannot compile Embryo code")
end
def dump_fonts(ef)
EDJE.font_dir.each do |entry|
- ef.write("fonts/#{entry.filename}",
+ ef.write("fonts/#{entry.alias}",
File.read(entry.filename))
end
end