docs-xml: remove explicit "constant"
[bbaumbach/samba-autobuild/.git] / script / generate_param.py
index b610f6fb5e8275cca68f0712492152d009423bd3..c29a29df57e7a96585c3db3e3df284076a40e936 100644 (file)
 #  License along with this library; if not, see <http://www.gnu.org/licenses/>.
 #
 
-import errno
 import os
-import re
-import subprocess
 import xml.etree.ElementTree as ET
-import sys
 import optparse
 
 # parse command line arguments
@@ -38,7 +34,7 @@ parser.add_option("-o", "--output", dest="output",
 parser.add_option("--mode", type="choice", metavar="<FUNCTIONS|S3PROTO|LIBPROTO|PARAMDEFS|PARAMTABLE>",
                   choices=["FUNCTIONS", "S3PROTO", "LIBPROTO", "PARAMDEFS", "PARAMTABLE"], default="FUNCTIONS")
 parser.add_option("--scope", metavar="<GLOBAL|LOCAL>",
-                  choices = ["GLOBAL", "LOCAL"], default="GLOBAL")
+                  choices=["GLOBAL", "LOCAL"], default="GLOBAL")
 
 (options, args) = parser.parse_args()
 
@@ -47,8 +43,9 @@ if options.filename is None:
 if options.output is None:
     parser.error("No output file specified")
 
+
 def iterate_all(path):
-    """Iterate and yield all the parameters. 
+    """Iterate and yield all the parameters.
 
     :param path: path to parameters xml file
     """
@@ -78,6 +75,7 @@ def iterate_all(path):
             continue
 
         constant = parameter.attrib.get("constant")
+        substitution = parameter.attrib.get("substitution")
         parm = parameter.attrib.get("parm")
         if name is None or param_type is None or context is None:
             raise Exception("Error parsing parameter: " + name)
@@ -92,13 +90,15 @@ def iterate_all(path):
                'context': context,
                'function': func,
                'constant': (constant == '1'),
+               'substitution': (substitution == '1'),
                'parm': (parm == '1'),
                'synonym' : synonym,
                'generated' : generated,
                'enumlist' : enumlist,
                'handler' : handler,
                'deprecated' : deprecated,
-               'synonyms' : synonyms}
+               'synonyms' : synonyms }
+
 
 # map doc attributes to a section of the generated function
 context_dict = {"G": "_GLOBAL", "S": "_LOCAL"}
@@ -116,6 +116,7 @@ param_type_dict = {
                     "ustring"      : "_STRING",
                   }
 
+
 def generate_functions(path_in, path_out):
     f = open(path_out, 'w')
     try:
@@ -131,21 +132,25 @@ def generate_functions(path_in, path_out):
 
             output_string = "FN"
             temp = context_dict.get(parameter['context'])
-            if temp is None: 
+            if temp is None:
                 raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
             output_string += temp
-            if parameter['constant']:
-                output_string += "_CONST"
-            if parameter['parm']: 
+            if parameter['type'] == "string" or parameter['type'] == "ustring":
+                if parameter['substitution']:
+                    output_string += "_SUBSTITUTED"
+                else:
+                    output_string += "_CONST"
+            if parameter['parm']:
                 output_string += "_PARM"
             temp = param_type_dict.get(parameter['type'])
             if temp is None:
                 raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
             output_string += temp
-            f.write(output_string + "(" + parameter['function'] +", " + parameter['function'] + ')\n')
+            f.write(output_string + "(" + parameter['function'] + ", " + parameter['function'] + ')\n')
     finally:
         f.close()
 
+
 mapping = {
             'boolean'      : 'bool ',
             'string'       : 'char *',
@@ -160,6 +165,7 @@ mapping = {
             'ustring'      : 'char *',
           }
 
+
 def make_s3_param_proto(path_in, path_out):
     file_out = open(path_out, 'w')
     try:
@@ -177,8 +183,6 @@ def make_s3_param_proto(path_in, path_out):
                 continue
 
             output_string = ""
-            if parameter['constant']:
-                output_string += 'const '
             param_type = mapping.get(parameter['type'])
             if param_type is None:
                 raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
@@ -191,13 +195,21 @@ def make_s3_param_proto(path_in, path_out):
             else:
                 param = "int"
 
-            if parameter['type'] == 'string' and not parameter['constant']:
-                if parameter['context'] == 'G':
-                    output_string += '(TALLOC_CTX *ctx);\n'
-                elif parameter['context'] == 'S':
-                    output_string += '(TALLOC_CTX *ctx, %s);\n' % param
+            if parameter['type'] == 'string' or parameter['type'] == 'ustring':
+                if parameter['substitution']:
+                    if parameter['context'] == 'G':
+                        output_string += '(TALLOC_CTX *ctx, const struct loadparm_substitution *lp_sub);\n'
+                    elif parameter['context'] == 'S':
+                        output_string += '(TALLOC_CTX *ctx, const struct loadparm_substitution *lp_sub, %s);\n' % param
+                    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 = 'const ' + output_string + '(void);\n'
+                    elif parameter['context'] == 'S':
+                        output_string = 'const ' + output_string + '(%s);\n' % param
+                    else:
+                        raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
             else:
                 if parameter['context'] == 'G':
                     output_string += '(void);\n'
@@ -227,8 +239,6 @@ def make_lib_proto(path_in, path_out):
                 continue
 
             output_string = ""
-            if parameter['constant']:
-                output_string += 'const '
             param_type = mapping.get(parameter['type'])
             if param_type is None:
                 raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
@@ -236,13 +246,21 @@ def make_lib_proto(path_in, path_out):
 
             output_string += "lpcfg_%s" % parameter['function']
 
-            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'
+            if parameter['type'] == 'string' or parameter['type'] == 'ustring':
+                if parameter['substitution']:
+                    if parameter['context'] == 'G':
+                        output_string += '(struct loadparm_context *, const struct loadparm_substitution *lp_sub, 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 context " + parameter['context'])
                 else:
-                    raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
+                    if parameter['context'] == 'G':
+                        output_string = 'const ' + output_string + '(struct loadparm_context *);\n'
+                    elif parameter['context'] == 'S':
+                        output_string = 'const ' + output_string + '(struct loadparm_service *, struct loadparm_service *);\n'
+                    else:
+                        raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
             else:
                 if parameter['context'] == 'G':
                     output_string += '(struct loadparm_context *);\n'
@@ -251,16 +269,17 @@ def make_lib_proto(path_in, path_out):
                 else:
                     raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
 
-
             file_out.write(output_string)
     finally:
         file_out.close()
 
+
 def get_header(path):
     header = os.path.basename(path).upper()
     header = header.replace(".", "_").replace("\\", "_").replace("-", "_")
     return "__%s__" % header
 
+
 def make_param_defs(path_in, path_out, scope):
     file_out = open(path_out, 'w')
     try:
@@ -268,7 +287,7 @@ def make_param_defs(path_in, path_out, scope):
         header = get_header(path_out)
         file_out.write("#ifndef %s\n" % header)
         file_out.write("#define %s\n\n" % header)
-        if scope == "GLOBAL": 
+        if scope == "GLOBAL":
             file_out.write("/**\n")
             file_out.write(" * This structure describes global (ie., server-wide) parameters.\n")
             file_out.write(" */\n")
@@ -309,6 +328,7 @@ def make_param_defs(path_in, path_out, scope):
     finally:
         file_out.close()
 
+
 type_dict = {
               "boolean"      : "P_BOOL",
               "boolean-rev"  : "P_BOOLREV",
@@ -324,6 +344,7 @@ type_dict = {
               "ustring"      : "P_USTRING",
             }
 
+
 def make_param_table(path_in, path_out):
     file_out = open(path_out, 'w')
     try:
@@ -389,12 +410,13 @@ def make_param_table(path_in, path_out):
                         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\t{ .label = NULL }\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':