From 5deeba69d4dd72412a6e2e7969b3199bb26b207c Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 18 Jun 2015 07:37:24 +0200 Subject: [PATCH] generate_param: add a means to generate param_table_gen.c from the docs This is triggered by the new argument PARAMTABLE. Signed-off-by: Michael Adam Reviewed-by: Jeremy Allison --- script/generate_param.py | 107 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/script/generate_param.py b/script/generate_param.py index b71d3aac35d..611bafa9c5e 100644 --- a/script/generate_param.py +++ b/script/generate_param.py @@ -35,8 +35,8 @@ parser.add_option("-f", "--file", dest="filename", help="input file", metavar="FILE") parser.add_option("-o", "--output", dest="output", help='output file', metavar="FILE") -parser.add_option("--mode", type="choice", metavar="", - choices=["FUNCTIONS", "S3PROTO", "LIBPROTO", "PARAMDEFS"], default="FUNCTIONS") +parser.add_option("--mode", type="choice", metavar="", + choices=["FUNCTIONS", "S3PROTO", "LIBPROTO", "PARAMDEFS", "PARAMTABLE"], default="FUNCTIONS") parser.add_option("--scope", metavar="", choices = ["GLOBAL", "LOCAL"], default="GLOBAL") @@ -69,6 +69,11 @@ def iterate_all(path): synonym = parameter.attrib.get("synonym") removed = parameter.attrib.get("removed") generated = parameter.attrib.get("generated_function") + handler = parameter.attrib.get("handler") + enumlist = parameter.attrib.get("enumlist") + deprecated = parameter.attrib.get("deprecated") + synonyms = parameter.findall('synonym') + if removed == "1": continue @@ -78,6 +83,10 @@ def iterate_all(path): raise Exception("Error parsing parameter: " + name) if func is None: func = name.replace(" ", "_").lower() + if enumlist is None: + enumlist = "NULL" + if handler is None: + handler = "NULL" yield {'name': name, 'type': param_type, 'context': context, @@ -85,7 +94,11 @@ def iterate_all(path): 'constant': (constant == '1'), 'parm': (parm == '1'), 'synonym' : synonym, - 'generated' : generated } + 'generated' : generated, + 'enumlist' : enumlist, + 'handler' : handler, + 'deprecated' : deprecated, + 'synonyms' : synonyms } # map doc attributes to a section of the generated function context_dict = {"G": "_GLOBAL", "S": "_LOCAL"} @@ -296,6 +309,92 @@ def make_param_defs(path_in, path_out, scope): finally: file_out.close() +type_dict = { + "boolean" : "P_BOOL", + "boolean-rev" : "P_BOOLREV", + "boolean-auto" : "P_ENUM", + "list" : "P_LIST", + "string" : "P_STRING", + "integer" : "P_INTEGER", + "enum" : "P_ENUM", + "char" : "P_CHAR", + "cmdlist" : "P_CMDLIST", + "bytes" : "P_BYTES", + "octal" : "P_OCTAL", + "ustring" : "P_USTRING", + } + +def make_param_table(path_in, path_out): + file_out = open(path_out, 'w') + try: + file_out.write('/* This file was automatically generated by generate_param.py. DO NOT EDIT */\n\n') + header = get_header(path_out) + file_out.write("#ifndef %s\n" % header) + file_out.write("#define %s\n\n" % header) + + file_out.write("struct parm_struct parm_table[] = {\n") + + for parameter in iterate_all(path_in): + # filter out parameteric options + if ':' in parameter['name']: + continue + if parameter['context'] == 'G': + p_class = "P_GLOBAL" + else: + p_class = "P_LOCAL" + + p_type = type_dict.get(parameter['type']) + + if parameter['context'] == 'G': + temp = "GLOBAL" + else: + temp = "LOCAL" + offset = "%s_VAR(%s)" % (temp, parameter['function']) + + enumlist = parameter['enumlist'] + handler = parameter['handler'] + synonym = parameter['synonym'] + deprecated = parameter['deprecated'] + flags_list = [] + if synonym == "1": + flags_list.append("FLAG_SYNONYM") + if deprecated == "1": + flags_list.append("FLAG_DEPRECATED") + flags = "|".join(flags_list) + synonyms = parameter['synonyms'] + + file_out.write("\t{\n") + file_out.write("\t\t.label\t\t= \"%s\",\n" % parameter['name']) + file_out.write("\t\t.type\t\t= %s,\n" % p_type) + file_out.write("\t\t.p_class\t= %s,\n" % p_class) + file_out.write("\t\t.offset\t\t= %s,\n" % offset) + file_out.write("\t\t.special\t= %s,\n" % handler) + file_out.write("\t\t.enum_list\t= %s,\n" % enumlist) + if flags != "": + file_out.write("\t\t.flags\t\t= %s,\n" % flags) + file_out.write("\t},\n") + + if synonyms is not None: + # for synonyms, we only list the synonym flag: + flags = "FLAG_SYNONYM" + for syn in synonyms: + file_out.write("\t{\n") + file_out.write("\t\t.label\t\t= \"%s\",\n" % syn.text) + file_out.write("\t\t.type\t\t= %s,\n" % p_type) + file_out.write("\t\t.p_class\t= %s,\n" % p_class) + file_out.write("\t\t.offset\t\t= %s,\n" % offset) + file_out.write("\t\t.special\t= %s,\n" % handler) + file_out.write("\t\t.enum_list\t= %s,\n" % enumlist) + if flags != "": + file_out.write("\t\t.flags\t\t= %s,\n" % flags) + file_out.write("\t},\n") + + file_out.write("\n\t{NULL, P_BOOL, P_NONE, 0, NULL, NULL, 0}\n"); + file_out.write("};\n") + file_out.write("\n#endif /* %s */\n\n" % header) + finally: + file_out.close() + if options.mode == 'FUNCTIONS': generate_functions(options.filename, options.output) elif options.mode == 'S3PROTO': @@ -304,3 +403,5 @@ elif options.mode == 'LIBPROTO': make_lib_proto(options.filename, options.output) elif options.mode == 'PARAMDEFS': make_param_defs(options.filename, options.output, options.scope) +elif options.mode == 'PARAMTABLE': + make_param_table(options.filename, options.output) -- 2.11.4.GIT