From d63f2942c1aaf419de4809d0e6d841d7d253fd62 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 3 Dec 2024 10:26:30 -0800 Subject: [PATCH] extensions.py: pass output by reference Instead of using a global for it. --- src/extensions.py | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/extensions.py b/src/extensions.py index 095f54e..4fe2360 100755 --- a/src/extensions.py +++ b/src/extensions.py @@ -81,6 +81,34 @@ def parseFile(filename): assert xproto == None xproto = mod +def format_strings(name, table, output): + if table is None: + output.write("\t.num_%s = 0,\n" % name) + output.write("\t.strings_%s = NULL,\n" % name) + else: + if len(table) == 256: + # This must be xproto and the value isn't used, so instead use + # something that fits into uint8_t. + output.write("\t.num_%s = 0,\n" % (name)) + else: + output.write("\t.num_%s = %d,\n" % (name, len(table))) + output.write("\t.strings_%s = \"%s\\0\",\n" % (name, "\\0".join(table))) + +def emit_module(module, output): + t = "" + prefix = "extension_" + if module.is_ext: + t = "static " + else: + prefix = "" + output.write("%sconst struct static_extension_info_t %s%s_info = { // %s\n" % (t, prefix, module.name, module.xname)) + format_strings("minor", module.requests_table, output) + format_strings("events", module.events_table, output) + format_strings("xge_events", module.xge_events_table, output) + format_strings("errors", module.errors_table, output) + output.write("\t.name = \"%s\",\n" % module.name) + output.write("};\n\n") + # Parse the xml file output_file = sys.argv[1] for input_file in sys.argv[2:]: @@ -94,37 +122,9 @@ output.write("#include \"errors.h\"\n") output.write("#include \n") output.write("\n") -def format_strings(name, table): - if table is None: - output.write("\t.num_%s = 0,\n" % name) - output.write("\t.strings_%s = NULL,\n" % name) - else: - if len(table) == 256: - # This must be xproto and the value isn't used, so instead use - # something that fits into uint8_t. - output.write("\t.num_%s = 0,\n" % (name)) - else: - output.write("\t.num_%s = %d,\n" % (name, len(table))) - output.write("\t.strings_%s = \"%s\\0\",\n" % (name, "\\0".join(table))) - -def emit_module(module): - t = "" - prefix = "extension_" - if module.is_ext: - t = "static " - else: - prefix = "" - output.write("%sconst struct static_extension_info_t %s%s_info = { // %s\n" % (t, prefix, module.name, module.xname)) - format_strings("minor", module.requests_table) - format_strings("events", module.events_table) - format_strings("xge_events", module.xge_events_table) - format_strings("errors", module.errors_table) - output.write("\t.name = \"%s\",\n" % module.name) - output.write("};\n\n") - for module in modules: - emit_module(module) -emit_module(xproto) + emit_module(module, output) +emit_module(xproto, output) output.write("int register_extensions(xcb_errors_context_t *ctx, xcb_connection_t *conn)\n"); output.write("{\n");