Improved
This commit is contained in:
parent
f990ddc22d
commit
731a6a4aa8
|
@ -1,8 +1,9 @@
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
|
require 'getoptlong'
|
||||||
|
|
||||||
def print_body(defs)
|
def print_body(defs, prefix)
|
||||||
includes = ['<glib-object.h>']
|
includes = ['<glib-object.h>']
|
||||||
content = "GList *\ngm_mcp_classes_initialize() {\n\tGList *result = NULL;\n\n"
|
content = prefix + "GList *\ngm_mcp_classes_initialize() {\n" + prefix + "\tGList *result = NULL;\n\n"
|
||||||
|
|
||||||
defs.each do |line|
|
defs.each do |line|
|
||||||
ucase = line.gsub(/[A-Z]+[a-z]+/) do |s|
|
ucase = line.gsub(/[A-Z]+[a-z]+/) do |s|
|
||||||
|
@ -13,25 +14,61 @@ def print_body(defs)
|
||||||
mcase = ucase.downcase.gsub('_', '-')
|
mcase = ucase.downcase.gsub('_', '-')
|
||||||
|
|
||||||
includes << '"gm-mcp-' + mcase + '.h"'
|
includes << '"gm-mcp-' + mcase + '.h"'
|
||||||
content += "\tresult = g_list_append(result, \n\t\t\tg_type_class_ref(GM_TYPE_MCP_" + ucase + "));\n"
|
content += prefix + "\tresult = g_list_append(result, \n" + prefix + "\t\t\tg_type_class_ref(GM_TYPE_MCP_" + ucase + "));\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
includes.each {|inc| $stdout.write('#include ' + inc + "\n")}
|
includes.each {|inc| $stdout.write(prefix + '#include ' + inc + "\n")}
|
||||||
$stdout.write("\n" + content + "\n\treturn result;\n}\n")
|
$stdout.write("\n" + content + "\n" + prefix + "\treturn result;\n" + prefix + "}\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_header(defs)
|
def print_header(defs, prefix)
|
||||||
$stdout.write("GList *gm_mcp_classes_initialize();\n")
|
$stdout.write(prefix + "GList *gm_mcp_classes_initialize();\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def print_files(defs, prefix)
|
||||||
|
out = ''
|
||||||
|
defs.each do |line|
|
||||||
|
lcase = line.gsub(/[A-Z]+[a-z]*/) do |s|
|
||||||
|
s.downcase + '-'
|
||||||
|
end
|
||||||
|
|
||||||
|
lcase.chop!
|
||||||
|
out += prefix + "gm-mcp-" + lcase + ".c gm-mcp-" + lcase + ".h \\\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
$stdout.write(out[0..-3])
|
||||||
|
end
|
||||||
|
|
||||||
|
opts = GetoptLong.new(
|
||||||
|
["--body", "-b", GetoptLong::NO_ARGUMENT],
|
||||||
|
["--header", "-h", GetoptLong::NO_ARGUMENT],
|
||||||
|
["--files", "-f", GetoptLong::NO_ARGUMENT],
|
||||||
|
["--prefix", "-p", GetoptLong::REQUIRED_ARGUMENT],
|
||||||
|
["--defs", "-d", GetoptLong::REQUIRED_ARGUMENT]
|
||||||
|
)
|
||||||
|
|
||||||
|
options = {}
|
||||||
|
opts.each do |arg,value|
|
||||||
|
options[arg] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
if !options['--defs']
|
||||||
|
print "Specify a definition file with --defs!\n"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
prefix = (options['--prefix'] or '')
|
||||||
|
|
||||||
begin
|
begin
|
||||||
defs = File.readlines(ARGV[0])
|
defs = File.readlines(options['--defs'])
|
||||||
defs.collect! {|elem| elem.chomp}
|
defs.collect! {|elem| elem.chomp}
|
||||||
|
|
||||||
if (ARGV[1] == "header")
|
if (options['--header'])
|
||||||
print_header(defs)
|
print_header(defs, prefix)
|
||||||
elsif (ARGV[1] == "body")
|
elsif (options['--body'])
|
||||||
print_body(defs)
|
print_body(defs, prefix)
|
||||||
|
elsif (options['--files'])
|
||||||
|
print_files(defs, prefix)
|
||||||
end
|
end
|
||||||
rescue StandardError => boom
|
rescue StandardError => boom
|
||||||
p boom
|
p boom
|
||||||
|
|
Reference in New Issue