Class: InitCreator

Inherits:
Object
  • Object
show all
Defined in:
ext/gtk2/extconf.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ InitCreator

Returns a new instance of InitCreator.



100
101
102
103
# File 'ext/gtk2/extconf.rb', line 100

def initialize(output)
  @output = output
  @targets = []
end

Instance Method Details

#<<(target) ⇒ Object



105
106
107
# File 'ext/gtk2/extconf.rb', line 105

def <<(target)
  @targets << target
end


170
171
172
# File 'ext/gtk2/extconf.rb', line 170

def print(*args)
  @output.print(*args)
end


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'ext/gtk2/extconf.rb', line 145

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|
      key_index = sorted_array.index(key)
      values.each do |value|
        value_index = sorted_array.index(value)
        next if value_index.nil?
        sorted_array.delete(value)
        sorted_array[key_index - 1, 0] = value
        key_index = sorted_array.index(key)
      end
    end
    sorted_array.each do |val|
      print "#{extern_def}   #{val};\n"
    end
    print "#endif\n" if defs
  end
end

#runObject



109
110
111
112
113
114
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
# File 'ext/gtk2/extconf.rb', line 109

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_.*\(\))(.*)/ =~ 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

  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()\n"
  print "{\n"
  print_data(inits, "", nil)
  print_data(inits, "GTK_DISABLE_DEPRECATED", "ifndef")
  print_data(inits, "GTK_ENABLE_BROKEN", "ifdef")
  print "}\n"
end