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