generate_param: generate struct entries if we don't generate access functions.
[nivanova/samba-autobuild/.git] / script / generate_param.py
index 4e04b3a45bfabfbae61063bd8265216f5559a56e..7315d868a4f7b6d22fd89ace4bbb4e8beec9953b 100644 (file)
@@ -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="<FUNCTIONS|S3PROTO|LIBPROTO|PARAMDEFS|S3PARAM|S3TABLE>",
-                 choices=["FUNCTIONS", "S3PROTO", "LIBPROTO", "PARAMDEFS", "S3PARAM", "S3TABLE"], default="FUNCTIONS")
+parser.add_option("--mode", type="choice", metavar="<FUNCTIONS|S3PROTO|LIBPROTO|PARAMDEFS>",
+                 choices=["FUNCTIONS", "S3PROTO", "LIBPROTO", "PARAMDEFS"], default="FUNCTIONS")
 parser.add_option("--scope", metavar="<GLOBAL|LOCAL>",
                   choices = ["GLOBAL", "LOCAL"], default="GLOBAL")
 
@@ -69,8 +69,9 @@ def iterate_all(path):
         synonym = parameter.attrib.get("synonym")
         removed = parameter.attrib.get("removed")
         generated = parameter.attrib.get("generated_function")
-        if synonym == "1" or removed == "1" or generated == "0":
+        if removed == "1":
             continue
+
         constant = parameter.attrib.get("constant")
         parm = parameter.attrib.get("parm")
         if name is None or param_type is None or context is None:
@@ -82,7 +83,9 @@ def iterate_all(path):
                'context': context,
                'function': func,
                'constant': (constant == '1'),
-               'parm': (parm == '1')}
+               'parm': (parm == '1'),
+               'synonym' : synonym,
+               'generated' : generated }
 
 # map doc attributes to a section of the generated function
 context_dict = {"G": "_GLOBAL", "S": "_LOCAL"}
@@ -98,6 +101,11 @@ def generate_functions(path_in, path_out):
             # filter out parameteric options
             if ':' in parameter['name']:
                 continue
+            if parameter['synonym'] == "1":
+                continue
+            if parameter['generated'] == "0":
+                continue
+
             output_string = "FN"
             temp = context_dict.get(parameter['context'])
             if temp is None: 
@@ -129,6 +137,10 @@ def make_s3_param_proto(path_in, path_out):
             # filter out parameteric options
             if ':' in parameter['name']:
                 continue
+            if parameter['synonym'] == "1":
+                continue
+            if parameter['generated'] == "0":
+                continue
 
             output_string = ""
             if parameter['constant']:
@@ -175,9 +187,13 @@ def make_lib_proto(path_in, path_out):
             # filter out parameteric options
             if ':' in parameter['name']:
                 continue
+            if parameter['synonym'] == "1":
+                continue
+            if parameter['generated'] == "0":
+                continue
 
             output_string = ""
-            if parameter['constant'] or parameter['type'] == 'string':
+            if parameter['constant']:
                 output_string += 'const '
             param_type = mapping.get(parameter['type'])
             if param_type is None:
@@ -186,12 +202,20 @@ def make_lib_proto(path_in, path_out):
 
             output_string += "lpcfg_%s" % parameter['function']
 
-            if parameter['context'] == 'G':
-                output_string += '(struct loadparm_context *);\n'
-            elif parameter['context'] == 'S':
-                output_string += '(struct loadparm_service *, struct loadparm_service *);\n'
+            if parameter['type'] == 'string' and not parameter['constant']:
+                if parameter['context'] == 'G':
+                    output_string += '(struct loadparm_context *, TALLOC_CTX *ctx);\n'
+                elif parameter['context'] == 'S':
+                    output_string += '(struct loadparm_service *, struct loadparm_service *, TALLOC_CTX *ctx);\n'
+                else:
+                    raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
             else:
-                raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
+                if parameter['context'] == 'G':
+                    output_string += '(struct loadparm_context *);\n'
+                elif parameter['context'] == 'S':
+                    output_string += '(struct loadparm_service *, struct loadparm_service *);\n'
+                else:
+                    raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
 
             
             file_out.write(output_string)
@@ -230,6 +254,8 @@ def make_param_defs(path_in, path_out, scope):
             # filter out parameteric options
             if ':' in parameter['name']:
                 continue
+            if parameter['synonym'] == "1":
+                continue
 
             if (scope == "GLOBAL" and parameter['context'] != "G" or
                 scope == "LOCAL" and parameter['context'] != "S"):
@@ -250,90 +276,6 @@ def make_param_defs(path_in, path_out, scope):
     finally:
         file_out.close()
 
-def make_s3_param(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 loadparm_s3_helpers\n")
-        file_out.write("{\n")
-        file_out.write("\tconst char * (*get_parametric)(struct loadparm_service *, const char *type, const char *option);\n")
-        file_out.write("\tstruct parm_struct * (*get_parm_struct)(const char *param_name);\n")
-        file_out.write("\tvoid * (*get_parm_ptr)(struct loadparm_service *service, struct parm_struct *parm);\n")
-        file_out.write("\tstruct loadparm_service * (*get_service)(const char *service_name);\n")
-        file_out.write("\tstruct loadparm_service * (*get_default_loadparm_service)(void);\n")
-        file_out.write("\tstruct loadparm_service * (*get_servicebynum)(int snum);\n")
-        file_out.write("\tint (*get_numservices)(void);\n")
-        file_out.write("\tbool (*load)(const char *filename);\n")
-        file_out.write("\tbool (*set_cmdline)(const char *pszParmName, const char *pszParmValue);\n")
-        file_out.write("\tvoid (*dump)(FILE *f, bool show_defaults, int maxtoprint);\n")
-        file_out.write("\tconst char * (*dnsdomain)(void);\n")
-        for parameter in iterate_all(path_in):
-            # filter out parameteric options
-            if ':' in parameter['name']:
-                continue
-            if parameter['context'] != 'G':
-                continue
-            # STRING isn't handle yet properly
-            if parameter['type'] == 'string' and not parameter['constant']:
-                continue
-            output_string = "\t"
-            if parameter['constant'] or parameter['type'] == 'string':
-                output_string += 'const '
-            param_type = mapping.get(parameter['type'])
-            if param_type is None:
-               raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
-            output_string += param_type
-
-            output_string += " (*%s)(void);\n" % parameter['function']
-            file_out.write(output_string)
-
-        file_out.write("};\n")
-        file_out.write("\n#endif /* %s */\n\n" % header)
-    finally:
-        file_out.close()
-
-def make_s3_param_ctx_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')
-        file_out.write("static const struct loadparm_s3_helpers s3_fns =\n")
-        file_out.write("{\n")
-        file_out.write("\t.get_parametric = lp_parm_const_string_service,\n")
-        file_out.write("\t.get_parm_struct = lp_get_parameter,\n")
-        file_out.write("\t.get_parm_ptr = lp_parm_ptr,\n")
-        file_out.write("\t.get_service = lp_service_for_s4_ctx,\n")
-        file_out.write("\t.get_servicebynum = lp_servicebynum_for_s4_ctx,\n")
-        file_out.write("\t.get_default_loadparm_service = lp_default_loadparm_service,\n")
-        file_out.write("\t.get_numservices = lp_numservices,\n")
-        file_out.write("\t.load = lp_load_for_s4_ctx,\n")
-        file_out.write("\t.set_cmdline = lp_set_cmdline,\n")
-        file_out.write("\t.dump = lp_dump,\n")
-        file_out.write("\t.dnsdomain = lp_dnsdomain,\n")
-        header = get_header(path_out)
-        for parameter in iterate_all(path_in):
-            # filter out parameteric options
-            if ':' in parameter['name']:
-                continue
-            if parameter['context'] != 'G':
-                continue
-            # STRING isn't handle yet properly
-            if parameter['type'] == 'string' and not parameter['constant']:
-                continue
-            output_string = "\t.%s" % parameter['function']
-            output_string += " = lp_%s,\n" % parameter['function']
-            file_out.write(output_string)
-
-        file_out.write("};")
-    finally:
-        file_out.close()
-
-
-
 if options.mode == 'FUNCTIONS':
     generate_functions(options.filename, options.output)
 elif options.mode == 'S3PROTO':
@@ -342,7 +284,3 @@ 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 == 'S3PARAM':
-    make_s3_param(options.filename, options.output)
-elif options.mode == 'S3TABLE':
-    make_s3_param_ctx_table(options.filename, options.output)