2 # Copyright (c) 2005 Tilman Sauerbeck (tilman at code-monkey de)
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be
13 # included in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 require "redact/redact.rb"
24 require "redact/source.rb"
40 OPTIONS = OpenStruct.new
48 @option_parser = parse_args(args)
50 OPTIONS.input = args.first
52 puts @option_parser.help
56 OPTIONS.output ||= OPTIONS.input.sub(/.[^.]+$/, ".edj")
66 raise("Cannot load '#{OPTIONS.input}'")
69 @filename = Pathname.new(OPTIONS.input).cleanpath.to_s
71 if EDJE.collections.empty?
72 raise("No collections found")
78 Eet::File.open(OPTIONS.output, "w") do |ef|
89 File.rm_f(OPTIONS.output)
96 OptionParser.new do |o|
97 o.banner = "Usage: redact [options] INPUT_FILE"
100 o.separator "Specific options:"
102 o.on("-o", "--output OUTPUT_FILE",
103 "Write Edje to OUTPUT_FILE") do |file|
104 OPTIONS.output = file
107 o.on("--image_dir IMAGE_DIR",
108 "Add IMAGE_DIR to the image lookup path") do |dir|
109 OPTIONS.image_dir = dir
112 o.on("--font_dir FONT_DIR",
113 "Add FONT_DIR to the font lookup path") do |dir|
114 OPTIONS.font_dir = dir
118 o.separator "Common options:"
120 o.on_tail("-h", "--help", "Show this message") do
125 o.on_tail("--version", "Show version") do
126 puts "Redact #{Redact::VERSION}"
137 EDJE.collections.each_value do |col|
138 next unless col.has_embryo?
140 Tempfile.open("redact_col#{col.id}.sma") do |tf_in|
141 tf_in.puts "#include <edje>"
145 Tempfile.open("redact_col#{col.id}.amx") do |tf_out|
146 incl = `edje-config --datadir`.strip
149 "-i #{incl}/include " +
150 "-o #{tf_out.path} #{tf_in.path}"
152 unless (0..1).include?($?.exitstatus)
153 raise("Cannot compile Embryo code")
156 ret[col.id] = tf_out.read
164 def dump_sma(tf, col)
165 if col.has_embryo?(false)
166 tf.puts col.script.to_embryo(col)
169 col.programs.each_value do |p|
170 next unless p.is_a?(ExecScriptProgram)
172 s = p.script.to_embryo(col).gsub(/^(.+)$/, "\t\\1")
175 public _p#{p.id}(sig[], src[])
183 def dump_amx(amx, ef)
184 amx.each do |id, code|
185 ef.write("scripts/#{id}", code)
190 ef.write("edje_file", EDJE.to_eet)
193 def dump_collections(ef)
194 EDJE.collections.each_value do |col|
195 ef.write("collections/#{col.id}", col.to_eet)
200 EDJE.font_dir.each do |entry|
201 ef.write("fonts/#{entry.alias}",
202 File.read(entry.filename))
207 EDJE.image_dir.each do |entry|
208 ef.write_image("images/#{entry.id}",
209 entry.image.data_for_reading_only,
210 entry.image.width, entry.image.height,
211 entry.image.has_alpha?)
218 SCRIPT_LINES__.each do |file, value|
219 sane = Pathname.new(file).cleanpath.to_s
220 method = (sane == @filename) ? :unshift : :push
221 s.send(method, SourceFile.new(sane, value.join))
223 # include files that are read with File.read, too
224 value.join.grep(/File\.read\(\"(.+)\"\)/) do
225 sane = Pathname.new($1).cleanpath.to_s
226 s << SourceFile.new(sane, File.read(sane))
230 ef.write("edje_sources", s.to_eet)
234 fm = EDJE.font_dir.inject(FontMap.new) do |a, entry|
235 a << FontMapEntry.new(entry)
238 ef.write("edje_source_fontmap", fm.to_eet)