# 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
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()
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
"""
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)
'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"}
"ustring" : "_STRING",
}
+
def generate_functions(path_in, path_out):
f = open(path_out, 'w')
try:
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 *',
'ustring' : 'char *',
}
+
def make_s3_param_proto(path_in, path_out):
file_out = open(path_out, 'w')
try:
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'])
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'
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'])
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'
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:
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")
finally:
file_out.close()
+
type_dict = {
"boolean" : "P_BOOL",
"boolean-rev" : "P_BOOLREV",
"ustring" : "P_USTRING",
}
+
def make_param_table(path_in, path_out):
file_out = open(path_out, 'w')
try:
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':