Skip to content

Instantly share code, notes, and snippets.

@vaiorabbit
Last active December 21, 2015 15:49
Show Gist options
  • Select an option

  • Save vaiorabbit/6329231 to your computer and use it in GitHub Desktop.

Select an option

Save vaiorabbit/6329231 to your computer and use it in GitHub Desktop.
gl.xml (*) から enum を抽出して Ruby 向けに整形&出力するテスト (*) https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml
# (Execution example)
# $ ruby generate_enum.rb > glenum.rb [RETURN]
# $ head glenum.rb [RETURN]
# module OpenGL
# GL_DEPTH_BUFFER_BIT = 0x00000100
# GL_STENCIL_BUFFER_BIT = 0x00000400
# GL_COLOR_BUFFER_BIT = 0x00004000
# GL_FALSE = 0
# GL_TRUE = 1
# GL_POINTS = 0x0000
# GL_LINES = 0x0001
# GL_LINE_LOOP = 0x0002
# GL_LINE_STRIP = 0x0003module OpenGL
# $
require 'nokogiri'
doc = Nokogiri::XML(open("./gl.xml"))
# Collect all enum
gl_all_enum_map = {}
doc.xpath('registry/enums/enum').each do |enum_tag|
# check alias
alias_attr = enum_tag['alias']
next if alias_attr != nil
gl_all_enum_map[enum_tag['name']] = enum_tag['value']
end
# Extract standard enum
gl_std_enum_map = {}
doc.xpath('registry/feature').each do |feature_tag|
if "gl" == feature_tag['api']
# OpenGL Standard enums
feature_tag.xpath('require/enum').each do |tag|
gl_std_enum_map[tag['name']] = gl_all_enum_map[tag['name']]
end
end
end
# Output
if __FILE__ == $0
puts "module OpenGL"
gl_std_enum_map.each do |enum|
print " #{enum[0]} = #{enum[1]}\n"
end
puts "end"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment