Last active
December 21, 2015 16:19
-
-
Save vaiorabbit/6332725 to your computer and use it in GitHub Desktop.
gl.xml の型情報(<types>)から typedef 名 → Cの型名 の対応関係を作るスクリプト (*) https://cvs.khronos.org/svn/repos/ogl/trunk/doc/registry/public/api/gl.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # $ ruby extract_type.rb | |
| # GLenum => unsigned int | |
| # GLboolean => unsigned char | |
| # GLbitfield => unsigned int | |
| # GLvoid => void | |
| # GLbyte => signed char | |
| # GLshort => short | |
| # GLint => int | |
| # GLclampx => int | |
| # GLubyte => unsigned char | |
| # GLushort => unsigned short | |
| # GLuint => unsigned int | |
| # ... | |
| require 'nokogiri' | |
| GLTypeMapEntry = Struct.new( :def_name, :ctype_name ) | |
| gl_type_map = [] | |
| doc = Nokogiri::XML(open("./gl.xml")) | |
| doc.xpath('registry/types/type').each do |type_tag| | |
| # Skip stddef/khrplatform/inttypes to process actual GL types | |
| name_attr = type_tag['name'] | |
| next if name_attr == 'stddef' || name_attr == 'khrplatform' || name_attr == 'inttypes' | |
| # Skip ES1/2 types | |
| api_attr = type_tag['api'] | |
| if api_attr != nil | |
| next if api_attr == 'gles1' || api_attr == 'gles2' | |
| end | |
| # Analyze the content of <type>...</type> | |
| content = type_tag.text | |
| name_tag = type_tag.at('name') | |
| if name_tag != nil | |
| # ex.) <type>typedef float <name>GLfloat</name>;</type> | |
| def_name = name_tag.text # ex.) def_name <- GLfloat | |
| ctype_name = content.chomp(def_name + ';').sub('typedef ','') # ex.) ctype_name <- float | |
| else | |
| # The actual type of 'GLhandleARB' should be changed depending on your platform (#ifdef __APPLE__, ...) | |
| def_name = name_attr | |
| ctype_name = "Needs tweaking by hand..." | |
| end | |
| # Store the result into name -> ctype map | |
| map_entry = GLTypeMapEntry.new | |
| map_entry.def_name = def_name | |
| map_entry.ctype_name = ctype_name | |
| gl_type_map << map_entry | |
| end | |
| gl_type_map.each do |t| | |
| print "#{t.def_name} => #{t.ctype_name}\n" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment