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