78 internal_types[typename] = typeinfos |
78 internal_types[typename] = typeinfos |
79 else: |
79 else: |
80 raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
80 raise ValueError, """!!! %s isn't a valid type for CanFestival."""%typename |
81 return typeinfos |
81 return typeinfos |
82 |
82 |
|
83 def ComputeValue(type, value): |
|
84 if type == "visible_string": |
|
85 return "\"%s\""%value, "" |
|
86 elif type == "domain": |
|
87 return "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]), "" |
|
88 elif type.startswith("real"): |
|
89 return "%f"%value, "" |
|
90 else: |
|
91 return "0x%X"%value, "\t/* %s */"%str(value) |
|
92 |
83 def WriteFile(filepath, content): |
93 def WriteFile(filepath, content): |
84 cfile = open(filepath,"w") |
94 cfile = open(filepath,"w") |
85 cfile.write(content) |
95 cfile.write(content) |
86 cfile.close() |
96 cfile.close() |
87 |
97 |
176 texts["subIndexType"] = typeinfos[0] |
186 texts["subIndexType"] = typeinfos[0] |
177 if typeinfos[1] is not None: |
187 if typeinfos[1] is not None: |
178 texts["suffixe"] = "[%d]"%typeinfos[1] |
188 texts["suffixe"] = "[%d]"%typeinfos[1] |
179 else: |
189 else: |
180 texts["suffixe"] = "" |
190 texts["suffixe"] = "" |
181 if typeinfos[2] == "visible_string": |
191 texts["value"], texts["comment"] = ComputeValue(typeinfos[2], values) |
182 texts["value"] = "\"%s\""%values |
|
183 texts["comment"] = "" |
|
184 elif typeinfos[2] == "domain": |
|
185 texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) |
|
186 texts["comment"] = "" |
|
187 else: |
|
188 texts["value"] = "0x%X"%values |
|
189 texts["comment"] = "\t/* %s */"%str(values) |
|
190 if index in variablelist: |
192 if index in variablelist: |
191 texts["name"] = FormatName(subentry_infos["name"]) |
193 texts["name"] = FormatName(subentry_infos["name"]) |
192 strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts |
194 strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts |
193 mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts |
195 mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts |
194 else: |
196 else: |
220 texts["name"] = FormatName(entry_infos["name"]) |
222 texts["name"] = FormatName(entry_infos["name"]) |
221 strDeclareHeader += "extern %(subIndexType)s %(name)s[%(length)d]%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n"%texts |
223 strDeclareHeader += "extern %(subIndexType)s %(name)s[%(length)d]%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n"%texts |
222 mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n {\n"%texts |
224 mappedVariableContent += "%(subIndexType)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n {\n"%texts |
223 for subIndex, value in enumerate(values): |
225 for subIndex, value in enumerate(values): |
224 sep = "," |
226 sep = "," |
225 comment = "" |
|
226 if subIndex > 0: |
227 if subIndex > 0: |
227 if subIndex == len(values)-1: |
228 if subIndex == len(values)-1: |
228 sep = "" |
229 sep = "" |
229 if typeinfos[2] == "visible_string": |
230 value, comment = ComputeValue(typeinfos[2], value) |
230 value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value))) |
|
231 elif typeinfos[2] == "domain": |
|
232 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) |
|
233 else: |
|
234 comment = "\t/* %s */"%str(value) |
|
235 value = "0x%X"%value |
|
236 mappedVariableContent += " %s%s%s\n"%(value, sep, comment) |
231 mappedVariableContent += " %s%s%s\n"%(value, sep, comment) |
237 mappedVariableContent += " };\n" |
232 mappedVariableContent += " };\n" |
238 else: |
233 else: |
239 strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n {\n"%texts |
234 strIndex += " %(subIndexType)s %(NodeName)s_obj%(index)04X[] = \n {\n"%texts |
240 for subIndex, value in enumerate(values): |
235 for subIndex, value in enumerate(values): |
241 sep = "," |
236 sep = "," |
242 comment = "" |
|
243 if subIndex > 0: |
237 if subIndex > 0: |
244 if subIndex == len(values)-1: |
238 if subIndex == len(values)-1: |
245 sep = "" |
239 sep = "" |
246 if typeinfos[2] == "visible_string": |
240 value, comment = ComputeValue(typeinfos[2], value) |
247 value = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value))) |
|
248 elif typeinfos[2] == "domain": |
|
249 value = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) |
|
250 else: |
|
251 comment = "\t/* %s */"%str(value) |
|
252 value = "0x%X"%value |
|
253 strIndex += " %s%s%s\n"%(value, sep, comment) |
241 strIndex += " %s%s%s\n"%(value, sep, comment) |
254 strIndex += " };\n" |
242 strIndex += " };\n" |
255 else: |
243 else: |
256 |
244 |
257 texts["parent"] = FormatName(entry_infos["name"]) |
245 texts["parent"] = FormatName(entry_infos["name"]) |
265 texts["subIndexType"] = typeinfos[0] |
253 texts["subIndexType"] = typeinfos[0] |
266 if typeinfos[1] is not None: |
254 if typeinfos[1] is not None: |
267 texts["suffixe"] = "[%d]"%typeinfos[1] |
255 texts["suffixe"] = "[%d]"%typeinfos[1] |
268 else: |
256 else: |
269 texts["suffixe"] = "" |
257 texts["suffixe"] = "" |
270 if typeinfos[2] == "visible_string": |
258 texts["value"], texts["comment"] = ComputeValue(typeinfos[2], value) |
271 texts["value"] = "\"%s%s\""%(value, "\\0" * (default_string_size - len(value))) |
|
272 texts["comment"] = "" |
|
273 elif typeinfos[2] == "domain": |
|
274 texts["value"] = "\"%s\""%''.join(["\\x%2.2x"%ord(char) for char in value]) |
|
275 texts["comment"] = "" |
|
276 else: |
|
277 texts["value"] = "0x%X"%value |
|
278 texts["comment"] = "\t/* %s */"%str(value) |
|
279 texts["name"] = FormatName(subentry_infos["name"]) |
259 texts["name"] = FormatName(subentry_infos["name"]) |
280 if index in variablelist: |
260 if index in variablelist: |
281 strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
261 strDeclareHeader += "extern %(subIndexType)s %(parent)s_%(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
282 mappedVariableContent += "%(subIndexType)s %(parent)s_%(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
262 mappedVariableContent += "%(subIndexType)s %(parent)s_%(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x%(subIndex)02X */\n"%texts |
283 else: |
263 else: |