diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-23 16:11:11 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-01-23 16:11:11 +0100 |
commit | a6b423787b9d9df618d89468e2573b4d598f011e (patch) | |
tree | 2ccc594c7eb0374fd17bccc0cd0afc5d3baf11b1 /tools | |
parent | 7d22f5782e018c9245828c11c8316315434ce23f (diff) | |
download | ffi-efl-a6b423787b9d9df618d89468e2573b4d598f011e.zip ffi-efl-a6b423787b9d9df618d89468e2573b4d598f011e.tar.gz |
tools/genruby: take care of enum backward references
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/genruby.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tools/genruby.rb b/tools/genruby.rb index 5508981..baca539 100755 --- a/tools/genruby.rb +++ b/tools/genruby.rb @@ -151,7 +151,28 @@ def gen_enums path, indent values = $2.strip typename = $3.strip tsym = set_type typename, typename - args = values.split(',').collect { |cst| ':'+cst.strip.downcase }.join(', ').gsub(/=/,',').gsub(/ ,/,',') + syms, vals = [], [] + values.split(',').each do |define| + s,v = define.gsub(/ /,'').split(/=/) + syms << s + vals << v + end + if vals.count(nil) == vals.length + args = syms.collect{ |sym| ':'+sym.strip.downcase }.join(', ') + else + i=0 + h={} + syms.zip(vals) do |s,v| + sym=':'+s.downcase + if h.has_key? v + h[s]=h[v] + else + h[s]=i + i+=1 + end + end + args = syms.inject(''){|r,s| r+=":#{s.strip.downcase}, #{h[s]}, " } + end r << indent+"# #{typedef} {...} #{typename};" r << wrap_text( indent+"enum #{tsym}, [ #{args} ]", indent+' '*4 ) end |