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
2005-11-07 10:15:43 +00:00

40 lines
888 B
Ruby
Executable File

#!/usr/bin/ruby
def print_body(defs)
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| $stdout.write('#include ' + inc + "\n")}
$stdout.write("\n" + content + "\n\treturn result;\n}\n")
end
def print_header(defs)
$stdout.write("GList *gm_mcp_classes_initialize();\n")
end
begin
defs = File.readlines(ARGV[0])
defs.collect! {|elem| elem.chomp}
if (ARGV[1] == "header")
print_header(defs)
elsif (ARGV[1] == "body")
print_body(defs)
end
rescue StandardError => boom
p boom
exit(1)
end