Class: InitCreator
- Inherits:
-
Object
- Object
- InitCreator
- Defined in:
- ext/gtk2/extconf.rb
Instance Method Summary collapse
- #<<(target) ⇒ Object
-
#initialize(output) ⇒ InitCreator
constructor
A new instance of InitCreator.
- #print(*args) ⇒ Object
- #print_data(array, type, defs, extern = false) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(output) ⇒ InitCreator
Returns a new instance of InitCreator.
106 107 108 109 |
# File 'ext/gtk2/extconf.rb', line 106 def initialize(output) @output = output @targets = [] end |
Instance Method Details
#<<(target) ⇒ Object
111 112 113 |
# File 'ext/gtk2/extconf.rb', line 111 def <<(target) @targets << target end |
#print(*args) ⇒ Object
185 186 187 |
# File 'ext/gtk2/extconf.rb', line 185 def print(*args) @output.print(*args) end |
#print_data(array, type, defs, extern = false) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'ext/gtk2/extconf.rb', line 161 def print_data(array, type, defs, extern = false) if array[type] dependencies = { "Init_gtk_gdk_gc()" => ["Init_gtk_gdk_draw()"], } extern_def = "extern void" if extern print "##{defs} #{type}\n" if defs sorted_array = array[type].dup dependencies.each do |key, values| next unless sorted_array.include?(key) sorted_array.delete(key) value_indexes = values.collect do |value| sorted_array.index(value) end max_value_index = value_indexes.compact.max sorted_array[max_value_index + 1, 0] = key end sorted_array.each do |val| print "#{extern_def} #{val};\n" end print "#endif\n" if defs end end |
#run ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'ext/gtk2/extconf.rb', line 115 def run inits = Hash.new except_targets = ["Init_gtk2()", "Init_gtk_gdk()", "Init_gtk_gtk()"] @targets.each do |target| target.each_line do |line| if /^(Init_.*\((?:void)?\))(.*)/ =~ line init = $1 unless except_targets.include?(init) flag = $2 if flag.size > 0 if flag =~ /\/\*\s*(\w*)\s*\*\// inits[$1] = Array.new unless inits[$1] inits[$1] << init end else inits[""] = Array.new unless inits[""] inits[""] << init end end end end end inits[""] = inits[""].sort_by do |value| if value == "Init_gtk_gdk_draw()" inits[""].size * 2 elsif value == "Init_gtk_gdk_gc()" -inits[""].size else inits[""].index(value) end end print_data(inits, "", nil, true) print_data(inits, "GTK_DISABLE_DEPRECATED", "ifndef", true) print_data(inits, "GTK_ENABLE_BROKEN", "ifdef", true) print "void Init_gtk_inits(void)\n" print "{\n" print_data(inits, "", nil) print_data(inits, "GTK_DISABLE_DEPRECATED", "ifndef") print_data(inits, "GTK_ENABLE_BROKEN", "ifdef") print "}\n" end |