#-- # $Id: app.rb 57 2005-06-14 15:11:35Z tilman $ # # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de) # # 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. require "redact/redact.rb" require "redact/source.rb" require "ftools" require "tempfile" require "pathname" require "ostruct" 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.clear @option_parser = parse_args(args) OPTIONS.input = args.first if OPTIONS.input.nil? puts @option_parser.help exit end OPTIONS.output ||= OPTIONS.input.sub(/.[^.]+$/, ".edj") end def run EDJE.clear SCRIPT_LINES__.clear begin load OPTIONS.input rescue LoadError raise("Cannot load '#{OPTIONS.input}'") end @filename = Pathname.new(OPTIONS.input).cleanpath.to_s if EDJE.collections.empty? raise("No collections found") end amx = compile_embryo 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 private def parse_args(args) OptionParser.new do |o| o.banner = "Usage: redact [options] INPUT_FILE" o.separator "" o.separator "Specific options:" o.on("-o", "--output OUTPUT_FILE", "Write Edje to OUTPUT_FILE") do |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 end o.on("--font_dir FONT_DIR", "Add FONT_DIR to the font lookup path") do |dir| OPTIONS.font_dir = dir end o.separator "" o.separator "Common options:" o.on_tail("-h", "--help", "Show this message") do puts o exit end o.on_tail("--version", "Show version") do puts "Redact #{Redact::VERSION}" exit end o.parse!(args) end end def compile_embryo ret = {} EDJE.collections.each_value do |col| next unless col.has_embryo? Tempfile.open("redact_col#{col.id}.sma") do |tf_in| tf_in.puts "#include " dump_sma(tf_in, col) tf_in.flush Tempfile.open("redact_col#{col.id}.amx") do |tf_out| incl = `edje-config --datadir`.strip c = "embryo_cc " + "-i #{incl}/include " + "-o #{tf_out.path} #{tf_in.path}" system(c) unless (0..1).include?($?.exitstatus) raise("Cannot compile Embryo code") end ret[col.id] = tf_out.read end end end ret end def dump_sma(tf, col) if col.has_embryo?(false) tf.puts col.script.to_embryo(col) end col.programs.each_value do |p| next unless p.is_a?(ExecScriptProgram) s = p.script.to_embryo(col).gsub(/^(.+)$/, "\t\\1") tf.puts <