diff options
Diffstat (limited to 'tools/genruby.rb')
-rwxr-xr-x | tools/genruby.rb | 598 |
1 files changed, 402 insertions, 196 deletions
diff --git a/tools/genruby.rb b/tools/genruby.rb index 2eae0e7..f6980fb 100755 --- a/tools/genruby.rb +++ b/tools/genruby.rb @@ -1,146 +1,38 @@ #! /usr/bin/env ruby # -*- coding: UTF-8 -*- # -path = File.dirname __FILE__ -lib_path = File.join path, '..', 'lib', 'efl', 'native' -# -# header, module name, fct prefix, lib -libraries = [ - # HEADER MODUE NAME FCT PREFIX LIB OUTPUT REQUIRES - [ 'eina_types.h', 'Eina', 'eina', 'eina', 'eina_types.rb' ], - [ 'eina_main.h', 'Eina', 'eina', 'eina', 'eina.rb' ], - [ 'eina_xattr.h', 'EinaXattr', 'eina_xattr', 'eina', 'eina_xattr.rb' ], - [ 'eina_log.h', 'EinaLog', 'eina_log', 'eina', 'eina_log.rb' ], - [ 'eina_list.h', 'EinaList', 'eina_list', 'eina', 'eina_list.rb' ], - [ 'eina_hash.h', 'EinaHash', 'eina_hash', 'eina', 'eina_hash.rb' ], - [ 'Eet.h', 'Eet', 'eet', 'eet', 'eet.rb', [ 'efl/native/eina_xattr' ] ], - [ 'Evas.h', 'Evas', 'evas', 'evas', 'evas.rb' ], -# [ 'Evas_GL.h', 'EvasGl', 'evas_gl', 'evas', 'evas/evas_gl.rb' ], - [ 'Edje.h', 'Edje', 'edje', 'edje', 'edje.rb' ], - [ 'Ecore.h', 'Ecore', 'ecore', 'ecore', 'ecore.rb' ], -# [ 'Ecore_Con.h', 'EcoreCon', 'ecore_con', 'ecore', 'ecore/ecore_con.rb' ], - [ 'Ecore_Input.h', 'EcoreInput', 'ecore_event', 'ecore_input', 'ecore_input.rb' ], - [ 'Ecore_Getopt.h', 'EcoreGetopt', 'ecore_getopt', 'ecore', 'ecore_getopt.rb' ], - [ 'Ecore_Evas.h', 'EcoreEvas', 'ecore_evas', 'ecore_evas', 'ecore_evas.rb' ], -# [ 'Ecore_Fb.h', 'EcoreFb', 'ecore', 'ecore', 'ecore/ecore_fb.rb' ], -# [ 'Ecore_File.h', 'EcoreFile', 'ecore', 'ecore', 'ecore/ecore_file.rb' ], - [ 'EMap.h', 'EMap', 'emap', 'emap', 'emap.rb' ], - [ 'Elementary.h', 'Elm', 'elm', 'libelementary-ver-pre-svn-09.so.0', 'elementary.rb' ], -] # INDENT=' '*8 +WRAP_LEN=150 # -REQUIRES=['efl/ffi'] -# -HEADER =<<-EOF -#! /usr/bin/env ruby -# -*- coding: UTF-8 -*- -# -REQUIRES -# -module Efl - # - module MNAME - # - FCT_PREFIX = 'MY_FCT_PREFIX_' - # - def self.method_missing m, *args, &block - sym, args_s = ModuleHelper.find_function m, FCT_PREFIX - self.module_eval "def self.\#{m} *args, █ r=Efl::Native.\#{sym}(\#{args_s}); yield r if block_given?; r; end" - self.send m, *args, &block - end - # - end - # - module Native -EOF -FOOTER =<<-EOF - end -end -# -# EOF -EOF -# -TYPES = { - 'int' => ':int', - 'char' => ':char', - 'void' => ':void', - 'long' => ':long', - 'short' => ':short', - 'float' => ':float', - 'pid_t' => ':ulong', - 'time_t' => ':ulong', - 'size_t' => ':ulong', - 'ssize_t' => ':long', - 'double' => ':double', - 'long int' => ':long', - 'long long' => ':long_long', - 'unsigned int' => ':uint', - 'unsigned char' => ':uchar', - 'unsigned short' => ':ushort', - 'unsigned long long' => ':ulong_long', - 'int *' => ':int_p', - 'void *' => ':void_p', - 'short *' => ':short_p', - 'float *' => ':float_p', - 'size_t *' => ':ulong_p', - 'ssize_t *' => ':long_p', - 'double *' => ':double_p', - 'unsigned int *' => ':uint_p', - 'unsigned char *' => ':uchar_p', - 'unsigned short *' => ':ushort_p', - 'char *' => ':string', # FIXME ?!?! - 'char **' => ':string_array', # FIXME ?!?! - 'char ***' => ':string_array_p', # FIXME ?!?! - 'fd_set *' => ':pointer', - 'FILE *' => ':pointer', - 'va_list' => ':pointer', # FIXME ?!?! - 'struct tm *' => ':pointer', - 'struct timeval *' => ':pointer', - 'struct sockaddr *' => ':pointer', - # Efl BASE TYPES - 'Eina_Bool' => ':eina_bool', - 'Eina_Bool *' => ':eina_bool_p', - 'Eina_Inlist *' => ':pointer', - 'Eina_Iterator' => ':eina_iterator', - 'Eina_Iterator *' => ':eina_iterator_p', - 'Eina_Accessor' => ':eina_accessor', - 'Eina_Accessor *' => ':eina_accessor_p', - 'Evas_GL_API *' => ':evas_gl_api_p', -} -# -TYPES_USAGE = {} -# -def set_type t, v, cb=false - return 'bool' if t =~/Eina_Bool/ - v = v.downcase.sub(/(const|struct|enum|union) /,' ').strip - if not TYPES[t].nil? - puts "type already exists >#{t}< #{v}" - exit 1 - end - r = TYPES[v] - v = r[1..-1] if not r.nil? - TYPES[t]=':'+v - if cb - TYPES[t+' *']=':'+v +def set_type t, sym + return ETYPES['Eina_Bool'] if t=='Eina_Bool' + if ETYPES[t].nil? +# v = ( ETYPES[sym].nil? ? ( TYPES[sym].nil? ? ':'+sym.downcase : TYPES[sym] ) : ETYPES[sym] ) + v = ( TYPES[sym].nil? ? ':'+sym.downcase : TYPES[sym] ) + ETYPES[t] = v + printf "\033[0;35m%40s\033[0m => \033[0;36m%s\033[0m\n",t,v + return v else - TYPES[t+' *']=':'+v+'_p' - TYPES[t+' **']=':'+v+'_pp' - TYPES[t+' ***']=':'+v+'_ppp' + printf "\033[0;31mERROR type #{t} => #{sym} alredy exists!\033[0m\n" + exit 1 end - v end # def get_type t k = t.gsub(/(const|enum|union)/, '').strip - k.sub!(/\*/,' *') if k=~/\w+\*/ r = TYPES[k] - if r.nil? - puts "unknown type >#{k}< #{t}" + return r unless r.nil? + r = ETYPES[k] + return r unless r.nil? + if not k=~ /\*/ + printf "\033[0;31munknown type >#{k}< #{t}\033[0m\n" exit 1 end - TYPES_USAGE[k]||=true - r + k = k.gsub(/[ \*]*/, '').strip + r = ETYPES[k] + return ':'+k.downcase if r==':pointer' + ':pointer' end # def get_type_from_arg arg, l @@ -152,39 +44,66 @@ def get_type_from_arg arg, l end k = arg.gsub(/const/,'').gsub(/\s{2,}/,' ').strip if k=~/(.*?)(\w+)$/ - return get_type $1 + return get_type $1.strip end # try with unchanged argument string t = get_type k if t.nil? - puts "wrong arg >#{k}< #{arg} (#{l})" + printf "\033[0;31mwrong arg >#{k}< #{arg} (#{l})\033[0m\n" exit 1 end t end # def wrap_text txt, indent - txt.gsub( /(.{1,#{170}})(?: +|$\n?)|(.{1,#{170}})/,"\\1\\2\n#{indent}").sub(/\n\s+$/,'') + txt.gsub( /(.{1,#{150}})(?: +|$\n?)|(.{1,#{150}})/,"\\1\\2\n#{indent}").sub(/\n\s+$/,'') end # def gen_enums path, indent r = [] open(path+'-enums','r').readlines.each do |l| l.strip! - if not l=~/(typedef enum(?: \w+)?) \{([-A-Z0-9_=, ]+)\} (\w+);/ + if not l=~/((?:typedef )?enum(?: \w+)?) \{(.*)\} (\w+)/ + printf "\033[0;31mFIXME : #{l}\n#{indent}# FIXME\033[0m\n" r << indent+"# #{l}\n#{indent}# FIXME" next end - typedef = $1 - values = $2 - typename = $3 - v = set_type typename, typename - args = values.split(',').collect { |cst| ':'+cst.strip.downcase }.join(', ').gsub(/=/,',').gsub(/ ,/,',') + typedef = $1.strip + values = $2.strip + typename = $3.strip + tsym = set_type typename, typename + 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] + elsif v.nil? + h[s]=i + i+=1 + elsif v=~/\|/ + els = v.gsub(/[\(\)]/,'').split(/\|/) + v = els.inject('') { |s,e| s+="#{h[e]}|" }[0..-2] + h[s]=v + i=eval(v).to_i+1 + else + h[s]=v + i=eval(v).to_i+1 + end + end + args = syms.inject(''){|r,s| r+=":#{s.strip.downcase}, #{h[s]}, " }.sub(/, $/,'') + end r << indent+"# #{typedef} {...} #{typename};" - r << wrap_text( indent+"enum :#{v}, [ #{args} ]", indent+' '*4 ) - r << [ typename+' *', indent+"typedef :pointer, :#{v}_p" ] - r << [ typename+' **', indent+"typedef :pointer, :#{v}_pp" ] - r << [ typename+' ***', indent+"typedef :pointer, :#{v}_ppp" ] + r << wrap_text( indent+"enum #{tsym}, [ #{args} ]", indent+' '*4 ) end r end @@ -193,23 +112,22 @@ def gen_typedefs path, indent r = [] open(path+'-types','r').readlines.each do |l| l.strip! - if l=~/typedef (struct|enum|union) _\w+ (\w+);/ - t = $2 - v = 'pointer' - set_type t, t + if l=~/typedef (struct|union) _?\w+ (\w+);/ + t = $2.strip + sym = 'pointer' + elsif l=~/typedef enum/ + # nothing todo + next elsif l =~/typedef\s+((?:\w+\**\s)+)(\w+);/ - t = $2 - v = $1 - v = set_type t, v + t = $2.strip + sym = $1.strip else r << indent+"# #{l}\n#{indent}# FIXME" next end + tsym = set_type t, sym r << indent+"# #{l}" - r << indent+"typedef :#{v}, :#{t.downcase}" - r << [ t+' *', indent+"typedef :pointer, :#{t.downcase}_p" ] - r << [ t+' **', indent+"typedef :pointer, :#{t.downcase}_pp" ] - r << [ t+' ***', indent+"typedef :pointer, :#{t.downcase}_ppp" ] + r << indent+"typedef #{tsym}, :#{t.downcase}" end r end @@ -219,17 +137,18 @@ def gen_callbacks path, indent open(path+'-callbacks','r').readlines.each do |l| l.strip! if not l=~/^\s*typedef\s+(.*)((?:\(\*?\w+\)| \*?\w+))\s*\((.*)\);/ + printf "\033[0;31m# #{l}\n#{indent}# FIXME\033[0m\n" r << indent+"# #{l}\n#{indent}# FIXME" next end - ret = $1 + ret = $1.strip name = $2.strip args = $3.split(',').collect { |arg| get_type_from_arg arg, l }.join ', ' - k = name.sub(/\(/,'').sub(/\)/,'').sub(/\*/,'') - t = name.downcase.sub(/\(/,'').sub(/\)/,'').sub(/\*/,'') - t = set_type k, t, true + t = name.sub(/\(/,'').sub(/\)/,'').sub(/\*/,'') + sym = ( t.downcase=~/_cb$/ ? t : t+'_cb' ) + tsym = set_type t, sym r << indent+"# #{l}" - r << wrap_text(indent+"callback :#{t}, [ #{args} ], #{get_type ret}", indent+' '*4 ) + r << wrap_text(indent+"callback #{tsym}, [ #{args} ], #{get_type ret}", indent+' '*4 ) end r end @@ -239,11 +158,12 @@ def gen_variables path, indent open(path+'-variables','r').readlines.each do |l| l.strip! if not l=~ /EAPI\s+extern\s+(\w+\s+\*?)(\w+)/ + printf "\033[0;31m# #{l}\n#{indent}# FIXME\033[0m\n" r << indent+"# #{l}\n#{indent}# FIXME" next end - var = $2 - t = $1 + var = $2.strip + t = $1.strip r << indent+"# #{l}" r << wrap_text(indent+"attach_variable :#{var}, #{get_type t}", indent+' '*4) end @@ -255,12 +175,13 @@ def gen_functions path, indent r << indent+"fcts = [" open(path+'-functions','r').readlines.each do |l| l.strip! - if not l=~ /EAPI ([a-zA-Z0-9_\* ]+?)(\w+) ?\(([a-zA-Z0-9_ \*,\.]+)\)( *[A-Z]{2,})?/ + if not l=~ /EAPI ([a-zA-Z0-9_\* ]+?)(\w+) ?\(([a-zA-Z0-9_ \*,\.]*)\)( *[A-Z]{2,})?/ + printf "\033[0;31m# #{l}\n#{indent}# FIXME\033[0m\n" r << indent+"# #{l}\n#{indent}# FIXME" next end - ret = $1 - func = $2.downcase + ret = $1.strip + func = $2.strip.downcase args = $3.split(',').collect { |arg| get_type_from_arg arg, l }.join ', ' r << indent+"# #{l}" r << wrap_text(indent+"[ :#{func}, [ #{args} ], #{get_type ret} ],", indent+' '*4) @@ -269,47 +190,332 @@ def gen_functions path, indent r end # +NATIVE='efl/native' +# +HEADER =<<-EOF +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require '#{NATIVE}'REQUIRES +# +module Efl + # + module MNAME + # + FCT_PREFIX = 'MY_FCT_PREFIX_' unless const_defined? :FCT_PREFIX + # + def self.method_missing meth, *args, &block + sym = Efl::MethodResolver.resolve self, meth, FCT_PREFIX + self.send sym, *args, &block + end + # + end + # + module Native +EOF +# +FOOTER =<<-EOF + end +end +# +# EOF +EOF +# +TYPES = { + 'int' => ':int', + 'char' => ':char', + 'void' => ':void', + 'long' => ':long', + 'short' => ':short', + 'float' => ':float', + 'pid_t' => ':ulong', + 'time_t' => ':ulong', + 'size_t' => ':ulong', + 'ssize_t' => ':long', + 'uintptr_t' => ':pointer', + 'double' => ':double', + 'long int' => ':long', + 'long long' => ':long_long', + 'unsigned int' => ':uint', + 'unsigned char' => ':uchar', + 'unsigned short' => ':ushort', + 'unsigned long long' => ':ulong_long', + 'char *' => ':string', # FIXME ?!?! + 'fd_set *' => ':pointer', + 'FILE *' => ':pointer', + 'va_list' => ':pointer', # FIXME ?!?! + 'struct tm *' => ':pointer', + 'struct timeval *' => ':pointer', + 'struct sockaddr *' => ':pointer', +} +ETYPES = { + 'Eina_Bool' => ':bool' +} +# Evas.h +EVAS_LAYER_MIN=-32768 +EVAS_LAYER_MAX=32767 +# +path = File.dirname __FILE__ +lib_path = File.join path, '..', 'lib', 'efl', 'native' +# +libs = [] +libs << { + :lib=>'eina', :header=>'eina_types.h', + :modname=>'Eina', :prefix=>'eina', :outfile=>'eina_types.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'eina', :header=>'eina_main.h', + :modname=>'Eina', :prefix=>'eina', :outfile=>'eina.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'eina', :header=>'eina_xattr.h', + :modname=>'EinaXattr', :prefix=>'eina_xattr', :outfile=>'eina_xattr.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'eina', :header=>'eina_log.h', + :modname=>'EinaLog', :prefix=>'eina_log', :outfile=>'eina_log.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'eina', :header=>'eina_list.h', + :modname=>'EinaList', :prefix=>'eina_list', :outfile=>'eina_list.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'eina', :header=>'eina_hash.h', + :modname=>'EinaHash', :prefix=>'eina_hash', :outfile=>'eina_hash.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'eet', :header=>'Eet.h', + :modname=>'Eet', :prefix=>'eet', :outfile=>'eet.rb', + :requires=>["#{NATIVE}/eina_xattr","#{NATIVE}/eina_list"], :constants=>[] +} +libs << { + :lib=>'evas', :header=>'Evas.h', + :modname=>'Evas', :prefix=>'evas', :outfile=>'evas.rb', + :requires=>["#{NATIVE}/eina_list"], :constants=>['EVAS_LAYER_MIN','EVAS_LAYER_MAX'] +} +libs << { + :lib=>'edje', :header=>'Edje.h', + :modname=>'Edje', :prefix=>'edje', :outfile=>'edje.rb', + :requires=>["#{NATIVE}/evas"], :constants=>[] +} +libs << { + :lib=>'ecore', :header=>'Ecore.h', + :modname=>'Ecore', :prefix=>'ecore', :outfile=>'ecore.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'ecore_input', :header=>'Ecore_Input.h', + :modname=>'EcoreInput', :prefix=>'ecore_event', :outfile=>'ecore_input.rb', + :requires=>[], :constants=>[] +} +libs << { + :lib=>'ecore', :header=>'Ecore_Getopt.h', + :modname=>'EcoreGetopt', :prefix=>'ecore_getopt', :outfile=>'ecore_getopt.rb', + :requires=>["#{NATIVE}/eina_list"], :constants=>[] +} +libs << { + :lib=>'ecore_evas', :header=>'Ecore_Evas.h', + :modname=>'EcoreEvas', :prefix=>'ecore_evas', :outfile=>'ecore_evas.rb', + :requires=>["#{NATIVE}/ecore_getopt","#{NATIVE}/evas"], :constants=>[] +} +libs << { + :lib=>'emap', :header=>'EMap.h', + :modname=>'Emap', :prefix=>'emap', :outfile=>'emap.rb', + :requires=>["#{NATIVE}/eina_list"], :constants=>[] +} +ELM_LIB='elementary-ver-pre-svn-09.so.0' +libs << { + :lib=>ELM_LIB,:header=>'Elementary.h', + :modname=>'Elm', :prefix=>'elm', :outfile=>'elementary.rb', + :requires=>["#{NATIVE}/elm/elm_general","#{NATIVE}/elm/elm_tooltip"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_general.h', + :modname=>'Elm', :prefix=>'elm', :outfile=>'elm/elm_general.rb', + :requires=>["#{NATIVE}/evas","#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_tooltip.h', + :modname=>'ElmTooltip', :prefix=>'elm', :outfile=>'elm/elm_tooltip.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_object_item.h', + :modname=>'ElmObjectItem', :prefix=>'elm_object_item', :outfile=>'elm/elm_object_item.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_icon.h', + :modname=>'ElmIcon', :prefix=>'elm_icon', :outfile=>'elm/elm_icon.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_scroller.h', + :modname=>'ElmScroller', :prefix=>'elm_scroller', :outfile=>'elm/elm_scroller.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_entry.h', + :modname=>'ElmEntry', :prefix=>'elm_entry', :outfile=>'elm/elm_entry.rb', + :requires=>["#{NATIVE}/edje","#{NATIVE}/elementary","#{NATIVE}/elm/elm_icon","#{NATIVE}/elm/elm_scroller"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_list.h', + :modname=>'ElmList', :prefix=>'elm_list', :outfile=>'elm/elm_list.rb', + :requires=>["#{NATIVE}/elementary","#{NATIVE}/elm/elm_scroller"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_win.h', + :modname=>'ElmWin', :prefix=>'elm_win', :outfile=>'elm/elm_win.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_bg.h', + :modname=>'ElmBg', :prefix=>'elm_bg', :outfile=>'elm/elm_bg.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_label.h', + :modname=>'ElmLabel', :prefix=>'elm_label', :outfile=>'elm/elm_label.rb', + :requires=>["#{NATIVE}/elementary","#{NATIVE}/elm/elm_entry"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_object.h', + :modname=>'ElmObject', :prefix=>'elm_object', :outfile=>'elm/elm_object.rb', + :requires=>["#{NATIVE}/edje","#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_box.h', + :modname=>'ElmBox', :prefix=>'elm_box', :outfile=>'elm/elm_box.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_button.h', + :modname=>'ElmButton', :prefix=>'elm_button', :outfile=>'elm/elm_button.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_frame.h', + :modname=>'ElmFrame', :prefix=>'elm_frame', :outfile=>'elm/elm_frame.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_panel.h', + :modname=>'ElmPanel', :prefix=>'elm_panel', :outfile=>'elm/elm_panel.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_image.h', + :modname=>'ElmImage', :prefix=>'elm_image', :outfile=>'elm/elm_image.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_grid.h', + :modname=>'ElmGrid', :prefix=>'elm_grid', :outfile=>'elm/elm_grid.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_menu.h', + :modname=>'ElmMenu', :prefix=>'elm_menu', :outfile=>'elm/elm_menu.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_check.h', + :modname=>'ElmCheck', :prefix=>'elm_check', :outfile=>'elm/elm_check.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_clock.h', + :modname=>'ElmClock', :prefix=>'elm_clock', :outfile=>'elm/elm_clock.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_calendar.h', + :modname=>'ElmCalendar', :prefix=>'elm_calendar', :outfile=>'elm/elm_calendar.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_bubble.h', + :modname=>'ElmBubble', :prefix=>'elm_bubble', :outfile=>'elm/elm_bubble.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_layout.h', + :modname=>'ElmLayout', :prefix=>'elm_layout', :outfile=>'elm/elm_layout.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_cursor.h', + :modname=>'ElmCursor', :prefix=>'elm_cursor', :outfile=>'elm/elm_cursor.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +libs << { + :lib=>ELM_LIB,:header=>'elm_notify.h', + :modname=>'ElmNotify', :prefix=>'elm_notify', :outfile=>'elm/elm_notify.rb', + :requires=>["#{NATIVE}/elementary"], :constants=>[] +} +# Dir.mkdir lib_path unless (File.exists? lib_path) # -libraries.collect do |header,module_name,fct_prefix,lib, output, requires| - base = File.join path, 'api', header - output = File.join lib_path, output - Dir.mkdir File.dirname(output) unless File.exists? File.dirname(output) - printf "%-60s", "parse #{base}-*" - r = [lib, output, module_name, fct_prefix, requires ] - print "enums, " - r << gen_enums(base, INDENT) - print "typedefs, " - r << gen_typedefs(base, INDENT) - print "callbacks, " - r << gen_callbacks(base, INDENT) - print "variables, " - r << gen_variables(base, INDENT) - puts "functions." - r << gen_functions(base, INDENT) - r -end.each do |lib, output, module_name, fct_prefix, requires, enums, typedefs, callbacks, variables, functions| - printf "%-60s", "generate #{output}" - open(output,'w:utf-8') do |f| - requires||=[] - reqs = REQUIRES.concat(requires).collect{|r| "require '#{r}'" }.join ("\n") - f << HEADER.gsub(/MNAME/,module_name).sub(/MY_FCT_PREFIX/,fct_prefix).sub(/REQUIRES/,reqs) - f << "#{INDENT}#\n#{INDENT}ffi_lib '#{lib}'" - f << "\n#{INDENT}#\n#{INDENT}# ENUMS" +libs.each do |lib| + base = File.join path, 'api', lib[:header] + printf "\033[1;33mparse \033[0;32m%s-*\033[0;0m\n",base + printf " \033[0;33menums...\033[0;0m\n" + lib[:enums]=gen_enums(base, INDENT) + printf " \033[0;33mtypedefs...\033[0;0m\n" + lib[:typedefs]=gen_typedefs(base, INDENT) + printf " \033[0;33mcallbacks...\033[0;0m\n" + lib[:callbacks]=gen_callbacks(base, INDENT) + printf " \033[0;33mvariables...\033[0;0m\n" + lib[:variables]=gen_variables(base, INDENT) + printf " \033[0;33mfunctions...\033[0;0m\n" + lib[:functions]=gen_functions(base, INDENT) + printf "\033[1;33mdone\033[0;0m\n" +end +libs.each do |lib| + printf "\033[1;33mgenerate\033[0;0m %-50s\033[0;0m",lib[:outpath] + outpath = File.join lib_path, lib[:outfile] + outdir = File.dirname outpath + Dir.mkdir outdir unless File.exists? outdir + open(File.join(outpath),'w:utf-8') do |f| + reqs = ( lib[:requires].nil? ? '' : lib[:requires].inject('') {|s,e| s+="\nrequire '#{e}'"}) + f << HEADER.gsub(/MNAME/,lib[:modname]).sub(/MY_FCT_PREFIX/,lib[:prefix]).sub(/REQUIRES/,reqs) + f << "#{INDENT}#\n#{INDENT}ffi_lib '#{lib[:lib]}'" + if not lib[:constants].empty? + f << "\n#{INDENT}#\n#{INDENT}# CONSTANTS" + f << "\n"+lib[:constants].collect { |cst| INDENT+cst+"="+eval(cst).to_s}.compact.join("\n") + end print "enums, " - f << "\n"+enums.collect { |t| ( t.is_a?(Array) ? ( TYPES_USAGE[t[0]] ? t[1] : nil ) : t ) }.compact.join("\n") unless enums.empty? - f << "\n#{INDENT}#\n#{INDENT}# TYPEDEFS" + if not lib[:enums].empty? + f << "\n#{INDENT}#\n#{INDENT}# ENUMS" + f << "\n"+lib[:enums].collect { |t| ( t.is_a?(Array) ? t[1] : t ) }.compact.join("\n") + end print "typedefs, " - f << "\n"+typedefs.collect { |t| ( t.is_a?(Array) ? ( TYPES_USAGE[t[0]] ? t[1] : nil ) : t ) }.compact.join("\n") unless typedefs.empty? - f << "\n#{INDENT}#\n#{INDENT}# CALLBACKS" + if not lib[:typedefs].empty? + f << "\n#{INDENT}#\n#{INDENT}# TYPEDEFS" + f << "\n"+lib[:typedefs].collect { |t| ( t.is_a?(Array) ? t[1] : t ) }.compact.join("\n") + end print "callbacks, " - f << "\n"+callbacks.join("\n") unless callbacks.empty? - f << "\n#{INDENT}#\n#{INDENT}# VARIABLES" + if not lib[:callbacks].empty? + f << "\n#{INDENT}#\n#{INDENT}# CALLBACKS" + f << "\n"+lib[:callbacks].join("\n") + end print "variables, " - f << "\n"+variables.join("\n") unless variables.empty? - f << "\n#{INDENT}#\n#{INDENT}# FUNCTIONS" + if not lib[:variables].empty? + f << "\n#{INDENT}#\n#{INDENT}# VARIABLES" + f << "\n"+lib[:variables].join("\n") + end puts "functions." - f << "\n"+functions.join("\n") unless functions.empty? + if not lib[:functions].empty? + f << "\n#{INDENT}#\n#{INDENT}# FUNCTIONS" + f << "\n"+lib[:functions].join("\n") + end f << "\n#{INDENT}#\n#{INDENT}attach_fcts fcts\n#{INDENT}#\n" f << FOOTER end |