git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@223 7335b...
authorhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 28 Jun 2007 06:17:44 +0000 (06:17 +0000)
committerhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 28 Jun 2007 06:17:44 +0000 (06:17 +0000)
Source/Python/StrGather.py
Source/Python/UniClassObject.py

index 408980c..25a6468 100644 (file)
@@ -39,8 +39,8 @@ H_C_FILE_HEADER = ['//', \
 LANGUAGE_NAME_STRING_NAME = '$LANGUAGE_NAME'\r
 PRINTABLE_LANGUAGE_NAME_STRING_NAME = '$PRINTABLE_LANGUAGE_NAME'\r
 \r
-def DecToHexStr(Dec):\r
-    return '0x%04X' % int(Dec)\r
+def DecToHexStr(Dec, Digit):\r
+    return eval("'0x%0" + str(Digit) + "X' % int(Dec)")\r
 \r
 def DecToHexList(Dec):\r
     Hex = "%08X" % int(Dec)\r
@@ -58,15 +58,21 @@ def CreateHFileHeader(BaseName):
 def CreateHFileContent(UniObjectClass):\r
     Str = ''\r
     ValueStartPtr = 60\r
-    for Index in range(len(UniObjectClass.StringList)):\r
-        Name = UniObjectClass.FindStringObjectNameByToken(Index)\r
+    Line = COMMENT_DEFINE_STR + ' ' + LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(0, 4) + COMMENT_NOT_REFERENCED\r
+    Str = WriteLine(Str, Line)\r
+    Line = COMMENT_DEFINE_STR + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + PRINTABLE_LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(1, 4) + COMMENT_NOT_REFERENCED\r
+    Str = WriteLine(Str, Line)\r
+    for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])):\r
+        StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index]\r
+        Name = StringItem.StringName\r
+        Token = StringItem.Token\r
+        Referenced = StringItem.Referenced\r
         if Name != None:\r
-            StringItem = UniObjectClass.StringList[Name]\r
             Line = ''\r
-            if StringItem.Referenced == True:\r
-                Line = DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(StringItem.Token)\r
+            if Referenced == True:\r
+                Line = DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4)\r
             else:\r
-                Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(StringItem.Token) + COMMENT_NOT_REFERENCED\r
+                Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED\r
             Str = WriteLine(Str, Line)\r
     return Str\r
 \r
@@ -83,13 +89,12 @@ def CreateCFileHeader():
     \r
     return Str\r
   \r
-def CreateArrayItem(Value):\r
-    MaxLength = 16\r
+def CreateArrayItem(Value, Width = 16):\r
+    MaxLength = Width\r
     Index = 0\r
     Line = '  '\r
     ArrayItem = ''\r
     \r
-    #Value = Value + UniToHexList(u'\x00')\r
     for Item in Value:\r
         if Index < MaxLength:\r
             Line = Line + Item + ', '\r
@@ -98,60 +103,77 @@ def CreateArrayItem(Value):
             ArrayItem = WriteLine(ArrayItem, Line)\r
             Line = '  ' + Item +  ', '\r
             Index = 1\r
-    ArrayItem = Write(ArrayItem, Line)\r
+    ArrayItem = Write(ArrayItem, Line.rstrip())\r
     \r
     return ArrayItem\r
 \r
-def CreateCFileLanguageHeader(Name, PrintableName, Offset):\r
-    Str = WriteLine('  ', COMMENT + STRING + ' ' + LANGUAGE_NAME_STRING_NAME + ' ' + OFFSET + ' ' + Offset)\r
-    Str = WriteLine(Str, CreateArrayItem(UniToHexList(Name + u'\x00')))\r
-    Str = WriteLine(Str, '  ' + COMMENT + STRING + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' + OFFSET + ' ' + Offset)\r
-    Str = WriteLine(Str, CreateArrayItem(PrintableName + UniToHexList(u'\x00')))\r
-    \r
-    return Str\r
-\r
-def CreateCFileStringDef(Name, Offset, Token):\r
-    Str = Write('  ', CreateArrayItem(DecToHexList(Offset)) + COMMENT + ' offset to string ' + Name + ' (' + DecToHexStr(Token) + ')')\r
+def CreateCFileStringDef(Name, Offset, Token, UseOtherLangDef = ''):\r
+    Comment = ''\r
+    if UseOtherLangDef != '':\r
+        Comment = ' - not defined for this language -- using secondary language ' + UniToStr(UseOtherLangDef) + ' definition'\r
+    Str = Write('', CreateArrayItem(DecToHexList(Offset)) + '  ' + COMMENT + 'offset to string ' + Name + ' (' + DecToHexStr(Token, 4) + ')' + Comment)\r
 \r
     return Str\r
     \r
-def CreateCFileStringValue(Name, Language, Value, Offset):\r
-    Str = WriteLine('  ', COMMENT + STRING + ' ' + Name + ' ' + OFFSET + ' ' + str(Offset))\r
-    Str = WriteLine(Str, CreateArrayItem(Value + UniToHexList(u'\x00')))\r
+def CreateCFileStringValue(Name, Language, Value, Offset):    \r
+    Str = WriteLine('  ', COMMENT + STRING + ' ' + Name + ' ' + OFFSET + ' ' + DecToHexStr(Offset, 8))\r
+    Str = WriteLine(Str, CreateArrayItem(Value))\r
     \r
     return Str\r
 \r
 def CreateCFileContent(BaseName, UniObjectClass):\r
     Str = ''\r
-    StrStringDef = ''\r
-    StrStringValue = ''\r
-    Offset = 428\r
-    Str = WriteLine(Str, CHAR_ARRAY_DEFIN + BaseName + COMMON_FILE_NAME + '[] = {\n' )\r
-    for Language in UniObjectClass.LanguageDef:        \r
+\r
+    Str = WriteLine(Str, CHAR_ARRAY_DEFIN + ' ' + BaseName + '[] = {\n' )\r
+    for IndexI in range(len(UniObjectClass.LanguageDef)):\r
+        Language = UniObjectClass.LanguageDef[IndexI][0]\r
+        LangPrintName = UniObjectClass.LanguageDef[IndexI][1]\r
+        Length = 0\r
+        NameLength = 0\r
+        Count = 0\r
+        for Item in UniObjectClass.OrderedStringList[Language]:\r
+            if Item.Referenced:\r
+                Length = Length + Item.Length\r
+                Count = Count + 1\r
+\r
         Str = WriteLine(Str, '//******************************************************************************')\r
-        Str = WriteLine(Str, COMMENT + 'Start of string definitions for ' + Language + '/' + '')\r
-        Str = Write(Str, CreateCFileLanguageHeader(Language, UniObjectClass.LanguageDef[Language], '0x00001'))\r
-        for Index in range(2, len(UniObjectClass.StringList)):\r
-            Name = UniObjectClass.FindStringObjectNameByToken(Index)\r
-            if Name != None:\r
-                UniString = UniObjectClass.StringList[Name]\r
-                #print Language\r
-                #print Name\r
-                #print UniObjectClass.StringList[Name].StringValue\r
-                if UniString.Referenced:\r
-                    if Language in UniString.StringValue.keys():\r
-                        StrStringDef = WriteLine(StrStringDef, CreateCFileStringDef(Name, Offset, UniString.Token))\r
-                        StrStringValue = Write(StrStringValue, CreateCFileStringValue(Name, Language, UniString.StringValue[Language], Offset))\r
-                        Offset = Offset + len(UniString.StringValue[Language])\r
-    Str = WriteLine(Str, StrStringDef)\r
-    Str = WriteLine(Str, StrStringValue)\r
+        Str = WriteLine(Str, COMMENT + 'Start of string definitions for ' + Language + '/' + LangPrintName)\r
+        \r
+        #\r
+        # EFI_HII_STRING_PACK_HEADER\r
+        #\r
+        Offset = LENGTH_EFI_HII_STRING_PACK_HEADER + LENGTH_STRING_OFFSET * Count\r
+        Length = Offset + Length\r
+        List = DecToHexList(Length) + DecToHexList(2)[0:2] + DecToHexList(Offset) + DecToHexList(Offset + len(UniToHexList(Language)) + 2) + DecToHexList(Count) + DecToHexList(0)\r
+        Str = WriteLine(Str, CreateArrayItem(List, 8))\r
+        \r
+        Str = WriteLine(Str, '  // offset 0x16')\r
+        StrStringDef = ''\r
+        StrStringValue = ''\r
+        for Item in UniObjectClass.OrderedStringList[Language]:\r
+            Name = Item.StringName\r
+            Value = Item.StringValueByteList\r
+            Referenced = Item.Referenced\r
+            Token = Item.Token\r
+            Length = Item.Length\r
+            UseOtherLangDef = Item.UseOtherLangDef\r
+             \r
+            if Referenced:\r
+                StrStringDef = WriteLine(StrStringDef, CreateCFileStringDef(Name, Offset, Token, UseOtherLangDef))\r
+                StrStringValue = Write(StrStringValue, CreateCFileStringValue(Name, Language, Value, Offset))\r
+                Offset = Offset + Length\r
+            else:\r
+                StrStringDef = WriteLine(StrStringDef, '  ' + COMMENT + Name + ' ' + NOT_REFERENCED)\r
+\r
+        Str = WriteLine(Str, StrStringDef)\r
+        Str = WriteLine(Str, StrStringValue)\r
     return Str\r
 \r
 def CreateCFileEnd():\r
     Str = WriteLine('  ', '// strings terminator pack')\r
     Str = WriteLine(Str, '  ' + '0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ')\r
     Str = WriteLine(Str, '  ' + '0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ')\r
-    Str = Write(Str, '  ' + '};')\r
+    Str = Write(Str, '};')\r
     return Str\r
 \r
 def CreateCFile(BaseName, UniObjectClass):\r
@@ -162,7 +184,7 @@ def CreateCFile(BaseName, UniObjectClass):
 \r
 def GetFileList(IncludeList, SkipList):\r
     if IncludeList == None:\r
-        return None\r
+        EdkLogger.error("Include path is not defined")\r
     \r
     FileList = []\r
     if SkipList == None:\r
@@ -203,11 +225,7 @@ def SearchString(UniObjectClass, FileList):
                     UniObjectClass.SetStringReferenced(StrName)\r
      \r
     UniObjectClass.ReToken()\r
-#    for index in range(len(UniObjectClass.StringList)):\r
-#        name = UniObjectClass.FindStringObjectNameByToken(index)\r
-#        if name != None:\r
-#            #print index, str(UniObjectClass.StringList[name])\r
-#            pass\r
+\r
     return UniObjectClass\r
 \r
 def GetStringFiles(UniFilList, IncludeList, SkipList, BaseName):\r
@@ -217,20 +235,16 @@ def GetStringFiles(UniFilList, IncludeList, SkipList, BaseName):
     if len(UniFilList) > 0:\r
         Uni = UniFileClassObject(UniFilList)\r
     else:\r
-        Status = False\r
-        ErrorMessage = 'No Unicode Files Found'\r
+        EdkLogger.error('No Unicode Files Found')\r
     \r
     FileList = GetFileList(IncludeList, SkipList)\r
     \r
     Uni = SearchString(Uni, FileList)\r
     \r
-    if len(Uni.StringList) > 0:\r
-        pass\r
-    \r
     HFile = CreateHFile(BaseName, Uni)\r
     CFile = CreateCFile(BaseName, Uni)\r
 \r
-    return Status, ErrorMessage, HFile, CFile\r
+    return HFile, CFile\r
 \r
 def Write(Target, Item):\r
     return Target + Item\r
@@ -245,8 +259,8 @@ if __name__ == '__main__':
     UniFileList = ['C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample\\inventorystrings.uni', 'C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample\\VfrStrings.uni']\r
     IncludeList = ['C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample']\r
     SkipList = ['.inf', '.uni']\r
-    BaseName = 'DriverSample'\r
-    (s, e, h, c) = GetStringFiles(UniFileList, IncludeList, SkipList, BaseName)\r
+    BaseName = 'DriverSampleStrings'\r
+    (h, c) = GetStringFiles(UniFileList, IncludeList, SkipList, BaseName)\r
     hfile = open('C:\string.h', 'w')\r
     cfile = open('C:\string.c', 'w')\r
     hfile.write(h)\r
index 9fdf99f..6ad01c3 100644 (file)
 #This file is used to collect all defined strings in multiple uni files \r
 #\r
 \r
-import codecs\r
-import binascii\r
-import os\r
+import os, codecs\r
 import EdkLogger\r
 \r
-def StrToUnix(Str):\r
-    return unicode(Str)\r
+UNICODE_WIDE_CHAR = u'\\wide'\r
+UNICODE_NARROW_CHAR = u'\\narrow'\r
+UNICODE_NON_BREAKING_CHAR = u'\\nbr'\r
+UNICODE_UNICODE_CR = '\r'\r
+UNICODE_UNICODE_LF = '\n'\r
 \r
-def HexListToUni(List):\r
-    pass\r
+NARROW_CHAR = u'\uFFF0'\r
+WIDE_CHAR = u'\uFFF1'\r
+NON_BREAKING_CHAR = u'\uFFF2'\r
+CR = u'\u000D'\r
+LF = u'\u000A'\r
+NULL = u'\u0000'\r
+TAB = u'\t'\r
+BACK_SPLASH = u'\\'\r
 \r
 def UniToStr(Uni):\r
     return repr(Uni)[2:-1]\r
@@ -33,31 +40,27 @@ def UniToHexList(Uni):
         List.append('0x' + Temp[0:2])\r
     return List\r
 \r
-class StringDefinitionClassObject(object):\r
-    def __init__(self, Name = None, Language = None, Value = None, Token = None):\r
+class StringDefClassObject(object):\r
+    def __init__(self, Name = None, Value = None, Referenced = False, Token = None, UseOtherLangDef = ''):\r
         self.StringName = ''\r
         self.StringNameByteList = []\r
-        self.StringValue = {}                        #{ u'Language' : u'Value' }\r
-        self.Referenced = False\r
-        self.Offset = ''\r
-        self.Token = ''\r
+        self.StringValue = ''\r
+        self.StringValueByteList = ''\r
+        self.Token = 0\r
+        self.Referenced = Referenced\r
+        self.UseOtherLangDef = UseOtherLangDef\r
+        self.Length = 0\r
         \r
         if Name != None:\r
             self.StringName = Name\r
             self.StringNameByteList = UniToHexList(Name)\r
-        if Value != None and Language != None:\r
-            self.StringValue[Language] = UniToHexList(Value)\r
+        if Value != None:\r
+            self.StringValue = Value + u'\x00'        # Add a NULL at string tail\r
+            self.StringValueByteList = UniToHexList(self.StringValue)\r
+            self.Length = len(self.StringValueByteList)\r
         if Token != None:\r
             self.Token = Token\r
-        \r
-    def Update(self, Name = None, Language = None, Value = None):\r
-        if Name != None:\r
-            self.StringName = Name\r
-            self.StringNameByteList = UniToHexList(Name)\r
-            \r
-        if Value != None and Language != None:\r
-            self.StringValue[Language] = UniToHexList(Value)\r
-        \r
+\r
     def __str__(self):\r
         return repr(self.StringName) + ' ' + \\r
                repr(self.Token) + ' ' + \\r
@@ -68,23 +71,24 @@ class UniFileClassObject(object):
     def __init__(self, FileList = []):\r
         self.FileList = FileList\r
         self.Token = 2\r
-        self.LanguageDef = {}                   #{ u'LanguageIdentifier' : [PrintableName] }\r
-        self.StringList = {}                    #{ 'StringName' : StringDefinitionClassObject }\r
-        self.OrderedStringList = []               #[ StringDefinitionClassObject ] \r
+        self.LanguageDef = []                   #[ [u'LanguageIdentifier', u'PrintableName'], ... ]\r
+        self.OrderedStringList = {}             #{ u'LanguageIdentifier' : [StringDefClassObject]  }\r
         \r
         if len(self.FileList) > 0:\r
             self.LoadUniFiles(FileList)\r
-                \r
+\r
     def GetLangDef(self, Line):\r
         LangName = Line[Line.find(u'#langdef ') + len(u'#langdef ') : Line.find(u' ', len(u'#langdef '))]\r
         LangPrintName = Line[Line.find(u'\"') + len(u'\"') : Line.rfind(u'\"')]\r
-        self.LanguageDef[LangName] = UniToHexList(LangPrintName)\r
+\r
+        if [LangName, LangPrintName] not in self.LanguageDef:\r
+            self.LanguageDef.append([LangName, LangPrintName])\r
         \r
         #\r
-        # Add default string\r
+        # Add language string\r
         #\r
-        self.AddStringToList(u'$LANGUAGE_NAME', LangName, LangName, 0)\r
-        self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', LangPrintName, LangPrintName, 1)  \r
+        self.AddStringToList(u'$LANGUAGE_NAME', LangName, LangName, 0, True)\r
+        self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', LangName, LangPrintName, 1, True)\r
 \r
         return True\r
         \r
@@ -103,22 +107,45 @@ class UniFileClassObject(object):
                 Value = LanguageList[IndexI][LanguageList[IndexI].find(u'\"') + len(u'\"') : LanguageList[IndexI].rfind(u'\"')].replace(u'\r\n', u'')\r
                 self.AddStringToList(Name, Language, Value)\r
     \r
+    def PreProcess(self, FileIn):\r
+        Lines = []\r
+        #\r
+        # Use unique identifier\r
+        #\r
+        for Index in range(len(FileIn)):\r
+            if FileIn[Index].startswith(u'//') or FileIn[Index] == u'\r\n':\r
+                continue\r
+            FileIn[Index] = FileIn[Index].replace(u'/langdef', u'#langdef')\r
+            FileIn[Index] = FileIn[Index].replace(u'/string', u'#string')\r
+            FileIn[Index] = FileIn[Index].replace(u'/language', u'#language')\r
+            \r
+            FileIn[Index] = FileIn[Index].replace(UNICODE_WIDE_CHAR, WIDE_CHAR)\r
+            FileIn[Index] = FileIn[Index].replace(UNICODE_NARROW_CHAR, NARROW_CHAR)\r
+            FileIn[Index] = FileIn[Index].replace(UNICODE_NON_BREAKING_CHAR, NON_BREAKING_CHAR)\r
+            FileIn[Index] = FileIn[Index].replace(u'\\r\\n', CR + LF)\r
+            FileIn[Index] = FileIn[Index].replace(u'\\n', CR + LF)\r
+            FileIn[Index] = FileIn[Index].replace(u'\\r', CR)\r
+            FileIn[Index] = FileIn[Index].replace(u'\\t', u'\t')\r
+            FileIn[Index] = FileIn[Index].replace(u'\\\\', u'\\')\r
+            FileIn[Index] = FileIn[Index].replace(u'''\"''', u'''"''')\r
+            FileIn[Index] = FileIn[Index].replace(u'\t', u' ')\r
+#           if FileIn[Index].find(u'\\x'):\r
+#               hex = FileIn[Index][FileIn[Index].find(u'\\x') + 2 : FileIn[Index].find(u'\\x') + 6]\r
+#               hex = "u'\\u" + hex + "'"\r
+                        \r
+            Lines.append(FileIn[Index])\r
+        \r
+        return Lines\r
+    \r
     def LoadUniFile(self, File = None):\r
         if File != None:\r
             if os.path.exists(File) and os.path.isfile(File):\r
                 FileIn = codecs.open(File, mode='rb', encoding='utf-16').readlines()             \r
-                Lines = []\r
+                \r
                 #\r
-                # Use unique identifier\r
+                # Process special char in file\r
                 #\r
-                for Index in range(len(FileIn)):\r
-                    if FileIn[Index].startswith(u'//') or FileIn[Index] == u'\r\n':\r
-                        continue\r
-                    FileIn[Index] = FileIn[Index].replace(u'/langdef', u'#langdef')\r
-                    FileIn[Index] = FileIn[Index].replace(u'/string', u'#string')\r
-                    FileIn[Index] = FileIn[Index].replace(u'/language', u'#language')\r
-                    FileIn[Index] = FileIn[Index].replace(u'\t', u' ')\r
-                    Lines.append(FileIn[Index])\r
+                Lines = self.PreProcess(FileIn)\r
                 \r
                 #\r
                 # Get Unicode Information\r
@@ -197,62 +224,86 @@ class UniFileClassObject(object):
                             elif Lines[IndexJ].find(u'\"') >= 2:\r
                                 StringItem = StringItem[ : StringItem.rfind(u'\"')] + Lines[IndexJ][Lines[IndexJ].find(u'\"') + len(u'\"') : ]\r
                         self.GetStringObject(StringItem)              \r
-\r
+            else:\r
+                EdkLogger.error(File + ' is not a valid file')\r
+    \r
     def LoadUniFiles(self, FileList = []):\r
         if len(FileList) > 0:\r
             for File in FileList:\r
                 self.LoadUniFile(File)\r
                 \r
-    def AddStringToList(self, Name, Language, Value, Token = None):\r
-        if Name in self.StringList.keys():\r
-            self.StringList[UniToStr(Name)].Update(Name, Language, Value)\r
-        else:\r
-            if Token != None:\r
-                self.StringList[UniToStr(Name)] = StringDefinitionClassObject(Name, Language, Value, Token)\r
-            else:\r
-                self.StringList[UniToStr(Name)] = StringDefinitionClassObject(Name, Language, Value, self.Token)\r
-                self.Token = self.Token + 1\r
-            \r
-    def FindStringObjectNameByToken(self, Token):\r
-        for Item in self.StringList:\r
-            if self.StringList[Item].Token == Token:\r
-                return Item\r
-        return None\r
+    def AddStringToList(self, Name, Language, Value, Token = None, Referenced = False, UseOtherLangDef = ''):\r
+        if Language not in self.OrderedStringList:\r
+            self.OrderedStringList[Language] = []\r
+        \r
+        IsAdded = False\r
+        for Item in self.OrderedStringList[Language]:\r
+            if Name == Item.StringName:\r
+                IsAdded = True\r
+                break\r
+        if not IsAdded:\r
+            Token = len(self.OrderedStringList[Language])\r
+            self.OrderedStringList[Language].append(StringDefClassObject(Name, Value, Referenced, Token, UseOtherLangDef))\r
     \r
     def SetStringReferenced(self, Name):\r
-        if Name in self.StringList.keys():\r
-            self.StringList[Name].Referenced = True\r
-            \r
+        for Lang in self.OrderedStringList:\r
+            for Item in self.OrderedStringList[Lang]:\r
+                if Name == Item.StringName:\r
+                    Item.Referenced = True\r
+                    break\r
     \r
-    def CreateOrderedStringList(self):\r
-        pass\r
+    def FindStringValue(self, Name, Lang):\r
+        for Item in self.OrderedStringList[Lang]:\r
+            if Item.StringName == Name:\r
+                return Item\r
+        \r
+        return None\r
     \r
     def ReToken(self):\r
-        Token = 2\r
-        FalseCount = 1\r
-        Length = len(self.StringList)\r
-        for Index in range(2, Length):\r
-            Name = self.FindStringObjectNameByToken(Index)\r
-            if Name != None:\r
-                if self.StringList[Name].Referenced == True:\r
-                    self.StringList[Name].Token = Token\r
+        #\r
+        # Search each string to find if it is defined for each language\r
+        # Use secondary language value to replace if missing in any one language\r
+        #           \r
+        for IndexI in range(0, len(self.LanguageDef)):\r
+            LangKey = self.LanguageDef[IndexI][0]\r
+            for Item in self.OrderedStringList[LangKey]:\r
+                Name = Item.StringName\r
+                Value = Item.StringValue[0:-1]\r
+                Referenced = Item.Referenced\r
+                for IndexJ in range(0, len(self.LanguageDef)):\r
+                    LangFind = self.LanguageDef[IndexJ][0]\r
+                    if self.FindStringValue(Name, LangFind) == None:\r
+                        Token = len(self.OrderedStringList[LangFind])\r
+                        self.AddStringToList(Name, LangFind, Value, Token, Referenced, LangKey)\r
+        \r
+        #\r
+        # Retoken\r
+        #\r
+        for Lang in self.LanguageDef:\r
+            LangName = Lang[0]\r
+            ReferencedStringList = []\r
+            NotReferencedStringList = []\r
+            Token = 0\r
+            for Item in self.OrderedStringList[LangName]:\r
+                if Item.Referenced == True:\r
+                    Item.Token = Token\r
+                    ReferencedStringList.append(Item)\r
                     Token = Token + 1\r
                 else:\r
-                    self.StringList[Name].Token = Length + FalseCount\r
-                    FalseCount = FalseCount + 1\r
-                \r
-        for Index in range(2, Length + FalseCount):\r
-            Name = self.FindStringObjectNameByToken(Index)\r
-            if Name != None and self.StringList[Name].Referenced == False:\r
-                self.StringList[Name].Token = Token\r
-                Token = Token + 1\r
+                    NotReferencedStringList.append(Item)\r
+            self.OrderedStringList[LangName] = ReferencedStringList\r
+            for Index in range(len(NotReferencedStringList)):\r
+                NotReferencedStringList[Index].Token = Token + Index\r
+                self.OrderedStringList[LangName].append(NotReferencedStringList[Index])\r
             \r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 if __name__ == '__main__':\r
-    a = UniFileClassObject(['C:\\Documents and Settings\\hchen30\\Desktop\\inventorystrings.uni'])\r
-    for i in a.LanguageDef:\r
-        print i, a.LanguageDef[i]\r
-    for i in a.StringList:\r
-        print i, str(a.StringList[i])\r
+    a = UniFileClassObject(['C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample\\inventorystrings.uni', 'C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample\\VfrStrings.uni'])\r
+    print a.LanguageDef\r
+    print a.OrderedStringList\r
+    for i in a.OrderedStringList:\r
+        print i\r
+        for m in a.OrderedStringList[i]:\r
+            print str(m)\r
     
\ No newline at end of file