Change the semantic of the replaceSeparators function
[bertos.git] / wizard / bertos_utils.py
1 #!/usr/bin/env python
2 # encoding: utf-8
3 #
4 # Copyright 2008 Develer S.r.l. (http://www.develer.com/)
5 # All rights reserved.
6 #
7 # $Id$
8 #
9 # Author: Lorenzo Berni <duplo@develer.com>
10 #
11
12 import os
13 import fnmatch
14 import glob
15 import re
16 import shutil
17 # Use custom copytree function
18 import copytree
19 import pickle
20
21 import const
22 from plugins import codelite_project
23 import DefineException
24
25 def isBertosDir(directory):
26    return os.path.exists(directory + "/VERSION")
27
28 def bertosVersion(directory):
29    return open(directory + "/VERSION").readline().strip()
30
31 def createBertosProject(project_info):
32     directory = project_info.info("PROJECT_PATH")
33     sources_dir = project_info.info("SOURCES_PATH")
34     if not os.path.isdir(directory):
35         os.mkdir(directory)
36     f = open(directory + "/project.bertos", "w")
37     f.write(pickle.dumps(project_info))
38     f.close()
39     # Destination source dir
40     srcdir = directory + "/bertos"
41     shutil.rmtree(srcdir, True)
42     copytree.copytree(sources_dir + "/bertos", srcdir, ignore_list=const.IGNORE_LIST)
43     # Destination makefile
44     makefile = directory + "/Makefile"
45     if os.path.exists(makefile):
46         os.remove(makefile)
47     makefile = open("mktemplates/Makefile").read()
48     makefile = makefileGenerator(project_info, makefile)
49     open(directory + "/Makefile", "w").write(makefile)
50     # Destination project dir
51     prjdir = directory + "/" + os.path.basename(directory)
52     shutil.rmtree(prjdir, True)
53     os.mkdir(prjdir)
54     # Destination hw files
55     hwdir = prjdir + "/hw"
56     shutil.rmtree(hwdir, True)
57     os.mkdir(hwdir)
58     # Copy all the hw files
59     for module, information in project_info.info("MODULES").items():
60         for hwfile in information["hw"]:
61             string = open(sources_dir + "/" + hwfile, "r").read()
62             open(hwdir + "/" + os.path.basename(hwfile), "w").write(string)
63     # Destination configurations files
64     cfgdir = prjdir + "/cfg"
65     shutil.rmtree(cfgdir, True)
66     os.mkdir(cfgdir)
67     # Set to 1 the autoenabled for enabled modules
68     for module, information in project_info.info("MODULES").items():
69         if information["enabled"] and "configuration" in information and information["configuration"] != "":
70             configurations = project_info.info("CONFIGURATIONS")
71             configuration = configurations[information["configuration"]]
72             for start, parameter in configuration["paramlist"]:
73                 if "type" in configuration[parameter] and configuration[parameter]["type"] == "autoenabled":
74                     configuration[parameter]["value"] = "1"
75             project_info.setInfo("CONFIGURATIONS", configurations)
76     # Copy all the configuration files
77     for configuration, information in project_info.info("CONFIGURATIONS").items():
78         string = open(sources_dir + "/" + configuration, "r").read()
79         for start, parameter in information["paramlist"]:
80             infos = information[parameter]
81             value = infos["value"]
82             if "unsigned" in infos["informations"] and infos["informations"]["unsigned"]:
83                 value += "U"
84             if "long" in infos["informations"] and infos["informations"]["long"]:
85                 value += "L"
86             string = sub(string, parameter, value)
87         f = open(cfgdir + "/" + os.path.basename(configuration), "w")
88         f.write(string)
89         f.close()
90     # Destinatio mk file
91     makefile = open("mktemplates/template.mk", "r").read()
92     makefile = mkGenerator(project_info, makefile)
93     open(prjdir + "/" + os.path.basename(prjdir) + ".mk", "w").write(makefile)
94     # Destination main.c file
95     main = open("srctemplates/main.c", "r").read()
96     open(prjdir + "/main.c", "w").write(main)
97     # Codelite project files
98     if "codelite" in project_info.info("OUTPUT"):
99         codelite_project.createProject(project_info)
100
101 def mkGenerator(project_info, makefile):
102     """
103     Generates the mk file for the current project.
104     """
105     mk_data = {}
106     mk_data["$pname"] = os.path.basename(project_info.info("PROJECT_PATH"))
107     mk_data["$cpuflag"] = project_info.info("CPU_INFOS")["CPU_FLAG_NAME"]
108     mk_data["$cpuname"] = project_info.info("CPU_INFOS")["CORE_CPU"]
109     mk_data["$cpuclockfreq"] = project_info.info("SELECTED_FREQ")
110     mk_data["$cflags"] = " ".join(project_info.info("CPU_INFOS")["C_FLAGS"])
111     mk_data["$ldflags"] = " ".join(project_info.info("CPU_INFOS")["LD_FLAGS"])
112     mk_data["$cppflags"] = " ".join(project_info.info("CPU_INFOS")["CPP_FLAGS"])
113     mk_data["$cppaflags"] = " ".join(project_info.info("CPU_INFOS")["CPPA_FLAGS"])
114     mk_data["$cxxflags"] = " ".join(project_info.info("CPU_INFOS")["CXX_FLAGS"])
115     mk_data["$asflags"] = " ".join(project_info.info("CPU_INFOS")["AS_FLAGS"])
116     mk_data["$arflags"] = " ".join(project_info.info("CPU_INFOS")["AR_FLAGS"])
117     mk_data["$csrc"], mk_data["$pcsrc"], mk_data["$cppasrc"], mk_data["$cxxsrc"], mk_data["$asrc"], mk_data["$constants"] = csrcGenerator(project_info)
118     mk_data["$prefix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[0])
119     mk_data["$suffix"] = replaceSeparators(project_info.info("TOOLCHAIN")["path"].split("gcc")[1])
120     mk_data["$main"] = os.path.basename(project_info.info("PROJECT_PATH")) + "/main.c"
121     for key in mk_data:
122         while makefile.find(key) != -1:
123             makefile = makefile.replace(key, mk_data[key])
124     return makefile
125
126 def makefileGenerator(project_info, makefile):
127     """
128     Generate the Makefile for the current project.
129     """
130     # TODO write a general function that works for both the mk file and the Makefile
131     while makefile.find("project_name") != -1:
132         makefile = makefile.replace("project_name", os.path.basename(project_info.info("PROJECT_PATH")))
133     return makefile
134
135 def csrcGenerator(project_info):
136     modules = project_info.info("MODULES")
137     files = project_info.info("FILES")
138     if "harvard" in project_info.info("CPU_INFOS")["CPU_TAGS"]:
139         harvard = True
140     else:
141         harvard = False
142     # file to be included in CSRC variable
143     csrc = []
144     # file to be included in PCSRC variable
145     pcsrc = []
146     # files to be included in CPPASRC variable
147     cppasrc = []
148     # files to be included in CXXSRC variable
149     cxxsrc = []
150     # files to be included in ASRC variable
151     asrc = []
152     # constants to be included at the beginning of the makefile
153     constants = {}
154     for module, information in modules.items():
155         module_files = set([])
156         dependency_files = set([])
157         # assembly sources
158         asm_files = set([])
159         hwdir = os.path.basename(project_info.info("PROJECT_PATH")) + "/hw" 
160         if information["enabled"]:
161             if "constants" in information:
162                 constants.update(information["constants"])
163             cfiles, sfiles = findModuleFiles(module, project_info)
164             module_files |= set(cfiles)
165             asm_files |= set(sfiles)
166             for file in information["hw"]:
167                 if file.endswith(".c"):
168                     module_files |= set([hwdir + "/" + os.path.basename(file)])
169             for file_dependency in information["depends"]:
170                 if file_dependency in files:
171                     dependencyCFiles, dependencySFiles = findModuleFiles(file_dependency, project_info)
172                     dependency_files |= set(dependencyCFiles)
173                     asm_files |= set(dependencySFiles)
174             for file in module_files:
175                 if not harvard or information.get("harvard", "both") == "both":
176                     csrc.append(file)
177                 if harvard and "harvard" in information:
178                     pcsrc.append(file)
179             for file in dependency_files:
180                 csrc.append(file)
181             for file in project_info.info("CPU_INFOS")["C_SRC"]:
182                 csrc.append(file)
183             for file in project_info.info("CPU_INFOS")["PC_SRC"]:
184                 pcsrc.append(file)
185             for file in asm_files:
186                 cppasrc.append(file)
187     for file in project_info.info("CPU_INFOS")["CPPA_SRC"]:
188         cppasrc.append(file)
189     for file in project_info.info("CPU_INFOS")["CXX_SRC"]:
190         cxxsrc.append(file)
191     for file in project_info.info("CPU_INFOS")["ASRC"]:
192         asrc.append(file)
193     csrc = " \\\n\t".join(csrc) + " \\"
194     pcsrc = " \\\n\t".join(pcsrc) + " \\"
195     cppasrc = " \\\n\t".join(cppasrc) + " \\"
196     cxxsrc = " \\\n\t".join(cxxsrc) + " \\"
197     asrc = " \\\n\t".join(asrc) + " \\"
198     constants = "\n".join([os.path.basename(project_info.info("PROJECT_PATH")) + "_" + key + " = " + str(value) for key, value in constants.items()])
199     return csrc, pcsrc, cppasrc, cxxsrc, asrc, constants
200
201 def findModuleFiles(module, project_info):
202     # Find the files related to the selected module
203     cfiles = []
204     sfiles = []
205     # .c files related to the module and the cpu architecture
206     for filename, path in findDefinitions(module + ".c", project_info) + \
207             findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".c", project_info):
208         path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
209         path = replaceSeparators(path)
210         cfiles.append(path + "/" + filename)
211     # .s files related to the module and the cpu architecture
212     for filename, path in findDefinitions(module + ".s", project_info) + \
213             findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".s", project_info) + \
214             findDefinitions(module + ".S", project_info) + \
215             findDefinitions(module + "_" + project_info.info("CPU_INFOS")["TOOLCHAIN"] + ".S", project_info):
216         path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
217         path = replaceSeparators(path)
218         sfiles.append(path + "/" + filename)
219     # .c and .s files related to the module and the cpu tags
220     for tag in project_info.info("CPU_INFOS")["CPU_TAGS"]:
221         for filename, path in findDefinitions(module + "_" + tag + ".c", project_info):
222             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
223             if os.sep != "/":
224                 path = replaceSeparators(path)
225             cfiles.append(path + "/" + filename)
226         for filename, path in findDefinitions(module + "_" + tag + ".s", project_info) + \
227                 findDefinitions(module + "_" + tag + ".S", project_info):
228             path = path.replace(project_info.info("SOURCES_PATH") + os.sep, "")
229             path = replaceSeparators(path)
230             sfiles.append(path + "/" + filename)
231     return cfiles, sfiles
232
233 def replaceSeparators(path):
234     """
235     Replace the separators in the given path with unix standard separator.
236     """
237     if os.sep != "/":
238         while path.find(os.sep) != -1:
239             path = path.replace(os.sep, "/")
240     return path
241
242 def getSystemPath():
243     path = os.environ["PATH"]
244     if os.name == "nt":
245         path = path.split(";")
246     else:
247         path = path.split(":")
248     return path
249
250 def findToolchains(path_list):
251     toolchains = []
252     for element in path_list:
253         for toolchain in glob.glob(element+ "/" + const.GCC_NAME):
254             toolchains.append(toolchain)
255     return list(set(toolchains))
256
257 def getToolchainInfo(output):
258     info = {}
259     expr = re.compile("Target: .*")
260     target = expr.findall(output)
261     if len(target) == 1:
262         info["target"] = target[0].split("Target: ")[1]
263     expr = re.compile("gcc version [0-9,.]*")
264     version = expr.findall(output)
265     if len(version) == 1:
266         info["version"] = version[0].split("gcc version ")[1]
267     expr = re.compile("gcc version [0-9,.]* \(.*\)")
268     build = expr.findall(output)
269     if len(build) == 1:
270         build = build[0].split("gcc version ")[1]
271         build = build[build.find("(") + 1 : build.find(")")]
272         info["build"] = build
273     expr = re.compile("Configured with: .*")
274     configured = expr.findall(output)
275     if len(configured) == 1:
276         info["configured"] = configured[0].split("Configured with: ")[1]
277     expr = re.compile("Thread model: .*")
278     thread = expr.findall(output)
279     if len(thread) == 1:
280         info["thread"] = thread[0].split("Thread model: ")[1]
281     return info
282
283 def loadSourceTree(project):
284     fileList = [f for f in os.walk(project.info("SOURCES_PATH"))]
285     project.setInfo("FILE_LIST", fileList)
286
287 def findDefinitions(ftype, project):
288     L = project.info("FILE_LIST")
289     definitions = []
290     for element in L:
291         for filename in element[2]:
292             if fnmatch.fnmatch(filename, ftype):
293                 definitions.append((filename, element[0]))
294     return definitions
295
296 def loadCpuInfos(project):
297     cpuInfos = []
298     for definition in findDefinitions(const.CPU_DEFINITION, project):
299         cpuInfos.append(getInfos(definition))
300     return cpuInfos
301
302 def getTagSet(cpu_info):
303     tag_set = set([])
304     for cpu in cpu_info:
305         tag_set |= set([cpu["CPU_NAME"]])
306         tag_set |= set(cpu["CPU_TAGS"])
307         tag_set |= set([cpu["CORE_CPU"]])
308         tag_set |= set([cpu["TOOLCHAIN"]])
309     return tag_set
310         
311
312 def getInfos(definition):
313     D = {}
314     D.update(const.CPU_DEF)
315     def include(filename, dict = D, directory=definition[1]):
316         execfile(directory + "/" + filename, {}, D)
317     D["include"] = include
318     include(definition[0], D)
319     D["CPU_NAME"] = definition[0].split(".")[0]
320     D["DEFINITION_PATH"] = definition[1] + "/" + definition[0]
321     del D["include"]
322     return D
323
324 def getCommentList(string):
325     comment_list = re.findall(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/", string)
326     comment_list = [re.findall(r"^\s*\* *(.*?)$", comment, re.MULTILINE) for comment in comment_list]
327     return comment_list
328
329 def loadModuleDefinition(first_comment):
330     to_be_parsed = False
331     module_definition = {}
332     for num, line in enumerate(first_comment):
333         index = line.find("$WIZ$")
334         if index != -1:
335             to_be_parsed = True
336             try:
337                 exec line[index + len("$WIZ$ "):] in {}, module_definition
338             except:
339                 raise ParseError(num, line[index:])
340         elif line.find("\\brief") != -1:
341             module_definition["module_description"] = line[line.find("\\brief") + len("\\brief "):]
342     module_dict = {}
343     if "module_name" in module_definition:
344         module_name = module_definition[const.MODULE_DEFINITION["module_name"]]
345         del module_definition[const.MODULE_DEFINITION["module_name"]]
346         module_dict[module_name] = {}
347         if const.MODULE_DEFINITION["module_depends"] in module_definition:
348             depends = module_definition[const.MODULE_DEFINITION["module_depends"]]
349             del module_definition[const.MODULE_DEFINITION["module_depends"]]
350             if type(depends) == str:
351                 depends = (depends,)
352             module_dict[module_name]["depends"] = depends
353         else:
354             module_dict[module_name]["depends"] = ()
355         if const.MODULE_DEFINITION["module_configuration"] in module_definition:
356             module_dict[module_name]["configuration"] = module_definition[const.MODULE_DEFINITION["module_configuration"]]
357             del module_definition[const.MODULE_DEFINITION["module_configuration"]]
358         else:
359             module_dict[module_name]["configuration"] = ""
360         if "module_description" in module_definition:
361             module_dict[module_name]["description"] = module_definition["module_description"]
362             del module_definition["module_description"]
363         if const.MODULE_DEFINITION["module_harvard"] in module_definition:
364             harvard = module_definition[const.MODULE_DEFINITION["module_harvard"]]
365             if harvard == "both" or harvard == "pgm_memory":
366                 module_dict[module_name]["harvard"] = harvard
367             del module_definition[const.MODULE_DEFINITION["module_harvard"]]
368         if const.MODULE_DEFINITION["module_hw"] in module_definition:
369             hw = module_definition[const.MODULE_DEFINITION["module_hw"]]
370             del module_definition[const.MODULE_DEFINITION["module_hw"]]
371             if type(hw) == str:
372                 hw = (hw, )
373             module_dict[module_name]["hw"] = hw
374         else:
375             module_dict[module_name]["hw"] = ()
376         if const.MODULE_DEFINITION["module_supports"] in module_definition:
377             supports = module_definition[const.MODULE_DEFINITION["module_supports"]]
378             del module_definition[const.MODULE_DEFINITION["module_supports"]]
379             module_dict[module_name]["supports"] = supports
380         module_dict[module_name]["constants"] = module_definition
381         module_dict[module_name]["enabled"] = False
382     return to_be_parsed, module_dict
383
384 def isSupported(project, module=None, property_id=None):
385     if not module and property_id:
386         item = project.info("CONFIGURATIONS")[property_id[0]][property_id[1]]["informations"]
387     else:
388         item = project.info("MODULES")[module]
389     tag_dict = project.info("ALL_CPU_TAGS")
390     if "supports" in item:
391         support_string = item["supports"]
392         supported = {}
393         try:
394             exec "supported = " + support_string in tag_dict, supported
395         except:
396             raise SupportedException(support_string)
397         return supported["supported"]
398     else:
399         return True
400
401 def loadDefineLists(comment_list):
402     define_list = {}
403     for comment in comment_list:
404         for num, line in enumerate(comment):
405             index = line.find("$WIZ$")
406             if index != -1:
407                 try:
408                     exec line[index + len("$WIZ$ "):] in {}, define_list
409                 except:
410                     raise ParseError(num, line[index:])
411     for key, value in define_list.items():
412         if type(value) == str:
413             define_list[key] = (value,)
414     return define_list
415
416 def getDescriptionInformations(comment):
417     """
418     Take the doxygen comment and strip the wizard informations, returning the tuple
419     (comment, wizard_information)
420     """
421     brief = ""
422     description = ""
423     information = {}
424     for num, line in enumerate(comment):
425         index = line.find("$WIZ$")
426         if index != -1:
427             if len(brief) == 0:
428                 brief += line[:index].strip()
429             else:
430                 description += " " + line[:index]
431             try:
432                 exec line[index + len("$WIZ$ "):] in {}, information
433             except:
434                 raise ParseError(num, line[index:])
435         else:
436             if len(brief) == 0:
437                 brief += line.strip()
438             else:
439                 description += " " + line
440                 description = description.strip()
441     return brief.strip(), description.strip(), information
442
443 def getDefinitionBlocks(text):
444     """
445     Take a text and return a list of tuple (description, name-value).
446     """
447     block = []
448     block_tmp = re.finditer(r"/\*{2}\s*([^*]*\*(?:[^/*][^*]*\*+)*)/\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE)
449     for match in block_tmp:
450         # Only the first element is needed
451         comment = match.group(1)
452         define = match.group(2)
453         start = match.start()
454         block.append(([re.findall(r"^\s*\* *(.*?)$", line, re.MULTILINE)[0] for line in comment.splitlines()], define, start))
455     for match in re.finditer(r"/{3}\s*([^<].*?)\s*#define\s+((?:[^/]*?/?)+)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
456         comment = match.group(1)
457         define = match.group(2)
458         start = match.start()
459         block.append(([comment], define, start))
460     for match in re.finditer(r"#define\s*(.*?)\s*/{3}<\s*(.+?)\s*?(?:/{2,3}[^<].*?)?$", text, re.MULTILINE):
461         comment = match.group(2)
462         define = match.group(1)
463         start = match.start()
464         block.append(([comment], define, start))
465     return block
466
467 def loadModuleData(project):
468     module_info_dict = {}
469     list_info_dict = {}
470     configuration_info_dict = {}
471     file_dict = {}
472     for filename, path in findDefinitions("*.h", project) + findDefinitions("*.c", project) + findDefinitions("*.s", project) + findDefinitions("*.S", project):
473         comment_list = getCommentList(open(path + "/" + filename, "r").read())
474         if len(comment_list) > 0:
475             module_info = {}
476             configuration_info = {}
477             try:
478                 to_be_parsed, module_dict = loadModuleDefinition(comment_list[0])
479             except ParseError, err:
480                 raise DefineException.ModuleDefineException(path, err.line_number, err.line)
481             for module, information in module_dict.items():
482                 if "depends" not in information:
483                     information["depends"] = ()
484                 information["depends"] += (filename.split(".")[0],)
485                 information["category"] = os.path.basename(path)
486                 if "configuration" in information and len(information["configuration"]):
487                     configuration = module_dict[module]["configuration"]
488                     try:
489                         configuration_info[configuration] = loadConfigurationInfos(project.info("SOURCES_PATH") + "/" + configuration)
490                     except ParseError, err:
491                         raise DefineException.ConfigurationDefineException(project.info("SOURCES_PATH") + "/" + configuration, err.line_number, err.line)
492             module_info_dict.update(module_dict)
493             configuration_info_dict.update(configuration_info)
494             if to_be_parsed:
495                 try:
496                     list_dict = loadDefineLists(comment_list[1:])
497                     list_info_dict.update(list_dict)
498                 except ParseError, err:
499                     raise DefineException.EnumDefineException(path, err.line_number, err.line)
500     for filename, path in findDefinitions("*_" + project.info("CPU_INFOS")["TOOLCHAIN"] + ".h", project):
501         comment_list = getCommentList(open(path + "/" + filename, "r").read())
502         list_info_dict.update(loadDefineLists(comment_list))
503     for tag in project.info("CPU_INFOS")["CPU_TAGS"]:
504         for filename, path in findDefinitions("*_" + tag + ".h", project):
505             comment_list = getCommentList(open(path + "/" + filename, "r").read())
506             list_info_dict.update(loadDefineLists(comment_list))
507     project.setInfo("MODULES", module_info_dict)
508     project.setInfo("LISTS", list_info_dict)
509     project.setInfo("CONFIGURATIONS", configuration_info_dict)
510     project.setInfo("FILES", file_dict)
511
512 def formatParamNameValue(text):
513     """
514     Take the given string and return a tuple with the name of the parameter in the first position
515     and the value in the second.
516     """
517     block = re.findall("\s*([^\s]+)\s*(.+?)\s*$", text, re.MULTILINE)
518     return block[0]
519
520 def loadConfigurationInfos(path):
521     """
522     Return the module configurations found in the given file as a dict with the
523     parameter name as key and a dict containig the fields above as value:
524         "value": the value of the parameter
525         "description": the description of the parameter
526         "informations": a dict containig optional informations:
527             "type": "int" | "boolean" | "enum"
528             "min": the minimum value for integer parameters
529             "max": the maximum value for integer parameters
530             "long": boolean indicating if the num is a long
531             "unsigned": boolean indicating if the num is an unsigned
532             "value_list": the name of the enum for enum parameters
533     """
534     configuration_infos = {}
535     configuration_infos["paramlist"] = []
536     for comment, define, start in getDefinitionBlocks(open(path, "r").read()):
537         name, value = formatParamNameValue(define)
538         brief, description, informations = getDescriptionInformations(comment)
539         configuration_infos["paramlist"].append((start, name))
540         configuration_infos[name] = {}
541         configuration_infos[name]["value"] = value
542         configuration_infos[name]["informations"] = informations
543         if not "type" in configuration_infos[name]["informations"]:
544             configuration_infos[name]["informations"]["type"] = findParameterType(configuration_infos[name])
545         if ("type" in configuration_infos[name]["informations"] and
546                 configuration_infos[name]["informations"]["type"] == "int" and
547                 configuration_infos[name]["value"].find("L") != -1):
548             configuration_infos[name]["informations"]["long"] = True
549             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("L", "")
550         if ("type" in configuration_infos[name]["informations"] and
551                 configuration_infos[name]["informations"]["type"] == "int" and
552                 configuration_infos[name]["value"].find("U") != -1):
553             configuration_infos[name]["informations"]["unsigned"] = True
554             configuration_infos[name]["value"] = configuration_infos[name]["value"].replace("U", "")
555         configuration_infos[name]["description"] = description
556         configuration_infos[name]["brief"] = brief
557     return configuration_infos
558
559 def findParameterType(parameter):
560     if "value_list" in parameter["informations"]:
561         return "enum"
562     if "min" in parameter["informations"] or "max" in parameter["informations"] or re.match(r"^\d+U?L?$", parameter["value"]) != None:
563         return "int"
564
565 def sub(string, parameter, value):
566     """
567     Substitute the given value at the given parameter define in the given string
568     """
569     return re.sub(r"(?P<define>#define\s+" + parameter + r"\s+)([^\s]+)", r"\g<define>" + value, string)
570
571 def isInt(informations):
572     """
573     Return True if the value is a simple int.
574     """
575     if ("long" not in informatios or not informations["long"]) and ("unsigned" not in informations or informations["unsigned"]):
576         return True
577     else:
578         return False
579
580 def isLong(informations):
581     """
582     Return True if the value is a long.
583     """
584     if "long" in informations and informations["long"] and "unsigned" not in informations:
585         return True
586     else:
587         return False
588
589 def isUnsigned(informations):
590     """
591     Return True if the value is an unsigned.
592     """
593     if "unsigned" in informations and informations["unsigned"] and "long" not in informations:
594         return True
595     else:
596         return False
597
598 def isUnsignedLong(informations):
599     """
600     Return True if the value is an unsigned long.
601     """
602     if "unsigned" in informations and "long" in informations and informations["unsigned"] and informations["long"]:
603         return True
604     else:
605         return False
606
607 class ParseError(Exception):
608     def __init__(self, line_number, line):
609         Exception.__init__(self)
610         self.line_number = line_number
611         self.line = line
612
613 class SupportedException(Exception):
614     def __init__(self, support_string):
615         Exception.__init__(self)
616         self.support_string = support_string