This repository has been archived on 2020-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
gnoemoe/gnoemoe/mcp/mcpinit.rb

35 lines
831 B
Ruby
Executable File

#!/usr/bin/ruby
begin
defs = File.readlines(ARGV[0])
defs.collect! {|elem| elem.chomp}
fout = File.open(ARGV[1] + '.c', 'w')
includes = ['<glib-object.h>']
content = "GList *\ngm_mcp_classes_initialize() {\n\tGList *result = NULL;\n\n"
defs.each do |line|
ucase = line.gsub(/[A-Z]+[a-z]+/) do |s|
s.upcase + '_'
end
ucase.chop!
mcase = ucase.downcase.gsub('_', '-')
includes << '"gm-mcp-' + mcase + '.h"'
content += "\tresult = g_list_append(result, \n\t\t\tg_type_class_ref(GM_TYPE_MCP_" + ucase + "));\n"
end
includes.each {|inc| fout.write('#include ' + inc + "\n")}
fout.write("\n" + content + "\treturn result;\n}\n")
fout.close
fout = File.open(ARGV[1] + '.h', 'w')
fout.write("GList *gm_mcp_classes_initialize();\n")
fout.close
rescue StandardError => boom
p boom
exit(1)
end