Skip to content

Instantly share code, notes, and snippets.

@kainjow
Created February 12, 2017 03:21
Show Gist options
  • Save kainjow/f06ed0f9edcb484b539f1662bcb1ec8f to your computer and use it in GitHub Desktop.
Save kainjow/f06ed0f9edcb484b539f1662bcb1ec8f to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
current_filename = nil
current_file = nil
# http://anthonylewis.com/2011/02/09/to-hex-and-back-with-ruby/
def hex_to_bin(s)
s.scan(/../).map { |x| x.hex }.pack('c*')
end
File.readlines(File.dirname(__FILE__) + '/GLResources.cpp').each do |line|
next if line.strip!.empty?
next if line.match(/^#include/) ||
line.match(/^const char/) ||
line.match(/^};$/) ||
line.match(/^unsigned int/)
match = line.match(/^unsigned char GL::(.*?)\[\] = {$/)
if match
current_filename = match[1].gsub('_', '.')
current_file.close if current_file
current_file = File.open(File.dirname(__FILE__) + '/resources/' + current_filename, 'w')
next
end
match = line.match(/^0x[a-f0-9]{2,}/)
if match
values = line.gsub(' ', '').gsub('0x', '').split(',').each do |hex|
current_file.write(hex_to_bin(hex))
end
next
end
abort "Unknown line: #{line}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment