CHANGED: - if variable starts with a digit, add a "_" at the beginning
authorChristian Taedcke <Christian.Taedcke@ica-traffic.de>
Fri, 19 Feb 2010 08:18:40 +0100
changeset 639 27c0a025acf3
parent 638 00bc03cb5606
child 640 e9a4e4c308bb
CHANGED: - if variable starts with a digit, add a "_" at the beginning
* * *
FIXED: - if callback array name starts with a digit, prepend "_"
objdictgen/gen_cfile.py
--- a/objdictgen/gen_cfile.py	Fri Sep 10 08:55:42 2010 +0200
+++ b/objdictgen/gen_cfile.py	Fri Feb 19 08:18:40 2010 +0100
@@ -40,6 +40,14 @@
 internal_types = {}
 default_string_size = 10
 
+#Verify that the name does not start with a digit
+def UnDigitName(name):
+    start_with_digit = re.compile(r'^(\d.*)')
+    if start_with_digit.match(name):
+        return start_with_digit.sub(r'_\1', name)
+    return name
+
+
 # Format a string for making a C++ variable
 def FormatName(name):
     wordlist = [word for word in word_model.findall(name) if word != '']
@@ -204,7 +212,7 @@
                 texts["suffixe"] = ""
             texts["value"], texts["comment"] = ComputeValue(typeinfos[2], values)
             if index in variablelist:
-                texts["name"] = FormatName(subentry_infos["name"])
+                texts["name"] = UnDigitName(FormatName(subentry_infos["name"]))
                 strDeclareHeader += "extern %(subIndexType)s %(name)s%(suffixe)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00*/\n"%texts
                 mappedVariableContent += "%(subIndexType)s %(name)s%(suffixe)s = %(value)s;\t\t/* Mapped at index 0x%(index)04X, subindex 0x00 */\n"%texts
             else:
@@ -235,7 +243,7 @@
                     texts["type_suffixe"] = ""
                 texts["length"] = values[0]
                 if index in variablelist:
-                    texts["name"] = FormatName(entry_infos["name"])
+                    texts["name"] = UnDigitName(FormatName(entry_infos["name"]))
                     texts["values_count"] =  str(len(values)-1)
                     strDeclareHeader += "extern %(subIndexType)s%(type_suffixe)s %(name)s[%(values_count)s];\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n"%texts
                     mappedVariableContent += "%(subIndexType)s%(type_suffixe)s %(name)s[] =\t\t/* Mapped at index 0x%(index)04X, subindex 0x01 - 0x%(length)02X */\n  {\n"%texts
@@ -261,7 +269,7 @@
                     strIndex += "                    };\n"
             else:
                 
-                texts["parent"] = FormatName(entry_infos["name"])
+                texts["parent"] = UnDigitName(FormatName(entry_infos["name"]))
                 # Entry type is ARRAY
                 for subIndex, value in enumerate(values):
                     texts["subIndex"] = subIndex
@@ -288,6 +296,7 @@
                 name = FormatName(entry_infos["name"])
             else:
                 name = "%(NodeName)s_Index%(index)04X"%texts
+            name=UnDigitName(name);
             strIndex += "                    ODCallback_t %s_callbacks[] = \n                     {\n"%name
             for subIndex in xrange(len(values)):
                 strIndex += "                       NULL,\n"
@@ -337,7 +346,7 @@
                 save = "|TO_BE_SAVE"
             else:
                 save = ""
-            strIndex += "                       { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,name,sep)
+            strIndex += "                       { %s%s, %s, %s, (void*)&%s }%s\n"%(subentry_infos["access"].upper(),save,typeinfos[2],sizeof,UnDigitName(name),sep)
             pointer_name = pointers_dict.get((index, subIndex), None)
             if pointer_name is not None:
                 pointedVariableContent += "%s* %s = &%s;\n"%(typeinfos[0], pointer_name, name)