1 # Unix SMB/CIFS implementation.
2 # Copyright (C) 2014 Catalyst.Net Ltd
4 # Auto generate param_functions.c
6 # ** NOTE! The following LGPL license applies to the ldb
7 # ** library. This does NOT imply that all of Samba is released
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 3 of the License, or (at your option) any later version.
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, see <http://www.gnu.org/licenses/>.
28 import xml.etree.ElementTree as ET
32 # parse command line arguments
33 parser = optparse.OptionParser()
34 parser.add_option("-f", "--file", dest="filename",
35 help="input file", metavar="FILE")
36 parser.add_option("-o", "--output", dest="output",
37 help='output file', metavar="FILE")
38 parser.add_option("--mode", type="choice", metavar="<FUNCTIONS>",
39 choices=["FUNCTIONS"], default="FUNCTIONS")
41 (options, args) = parser.parse_args()
43 if options.filename is None:
44 parser.error("No input file specified")
45 if options.output is None:
46 parser.error("No output file specified")
48 def iterate_all(path):
49 """Iterate and yield all the parameters.
51 :param path: path to parameters xml file
57 raise Exception("Error opening parameters file")
60 # parse the parameters xml file
61 root = ET.fromstring(out)
62 for parameter in root:
63 name = parameter.attrib.get("name")
64 param_type = parameter.attrib.get("type")
65 context = parameter.attrib.get("context")
66 func = parameter.attrib.get("function")
67 synonym = parameter.attrib.get("synonym")
68 removed = parameter.attrib.get("removed")
69 generated = parameter.attrib.get("generated_function")
70 if synonym == "1" or removed == "1" or generated == "0":
72 constant = parameter.attrib.get("constant")
73 parm = parameter.attrib.get("parm")
74 if name is None or param_type is None or context is None:
75 raise Exception("Error parsing parameter: " + name)
77 func = name.replace(" ", "_").lower()
82 'constant': (constant == '1'),
83 'parm': (parm == '1')}
85 # map doc attributes to a section of the generated function
86 context_dict = {"G": "_GLOBAL", "S": "_LOCAL"}
87 param_type_dict = {"boolean": "_BOOL", "list": "_LIST", "string": "_STRING",
88 "integer": "_INTEGER", "enum": "_INTEGER", "char" : "_CHAR",
89 "boolean-auto": "_INTEGER"}
91 f = open(options.output, 'w')
94 for parameter in iterate_all(options.filename):
95 # filter out parameteric options
96 if ':' in parameter['name']:
99 temp = context_dict.get(parameter['context'])
101 raise Exception(parameter['name'] + " has an invalid context " + parameter['context'])
102 output_string += temp
103 if parameter['constant']:
104 output_string += "_CONST"
105 if parameter['parm']:
106 output_string += "_PARM"
107 temp = param_type_dict.get(parameter['type'])
109 raise Exception(parameter['name'] + " has an invalid param type " + parameter['type'])
110 output_string += temp
111 f.write(output_string + "(" + parameter['function'] +", " + parameter['function'] + ')\n')