]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/UPT/Library/UniClassObject.py
BaseTools: UPT: remove unused variable and inaccessible code.
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Library / UniClassObject.py
index 563b82c6889c8b9b2d1b5d1b3ced43eda02c487c..0014a7561ba88b1b02b735ecc04ba2b334571f0c 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Collect all defined strings in multiple uni files.\r
 #\r
 ## @file\r
 # Collect all defined strings in multiple uni files.\r
 #\r
-# Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
 #\r
 # This program and the accompanying materials are licensed and made available \r
 # under the terms and conditions of the BSD License which accompanies this \r
@@ -27,6 +27,7 @@ from Library.String import GetLineNo
 from Library.Misc import PathClass\r
 from Library.Misc import GetCharIndexOutStr\r
 from Library import DataType as DT\r
 from Library.Misc import PathClass\r
 from Library.Misc import GetCharIndexOutStr\r
 from Library import DataType as DT\r
+from Library.ParserValidate import CheckUTF16FileHeader\r
 \r
 ##\r
 # Static definitions\r
 \r
 ##\r
 # Static definitions\r
@@ -46,8 +47,6 @@ NULL = u'\u0000'
 TAB = u'\t'\r
 BACK_SPLASH = u'\\'\r
 \r
 TAB = u'\t'\r
 BACK_SPLASH = u'\\'\r
 \r
-gINCLUDE_PATTERN = re.compile("^!include[\s]+([\S]+)[\s]*$", re.MULTILINE | re.UNICODE)\r
-\r
 gLANG_CONV_TABLE = {'eng':'en', 'fra':'fr', \\r
                  'aar':'aa', 'abk':'ab', 'ave':'ae', 'afr':'af', 'aka':'ak', 'amh':'am', \\r
                  'arg':'an', 'ara':'ar', 'asm':'as', 'ava':'av', 'aym':'ay', 'aze':'az', \\r
 gLANG_CONV_TABLE = {'eng':'en', 'fra':'fr', \\r
                  'aar':'aa', 'abk':'ab', 'ave':'ae', 'afr':'af', 'aka':'ak', 'amh':'am', \\r
                  'arg':'an', 'ara':'ar', 'asm':'as', 'ava':'av', 'aym':'ay', 'aze':'az', \\r
@@ -136,6 +135,8 @@ def ConvertSpecialUnicodes(Uni):
 # @retval LangName:  Valid lanugage code in RFC 1766 format or None\r
 #\r
 def GetLanguageCode1766(LangName, File=None):\r
 # @retval LangName:  Valid lanugage code in RFC 1766 format or None\r
 #\r
 def GetLanguageCode1766(LangName, File=None):\r
+    return LangName\r
+\r
     length = len(LangName)\r
     if length == 2:\r
         if LangName.isalpha():\r
     length = len(LangName)\r
     if length == 2:\r
         if LangName.isalpha():\r
@@ -325,9 +326,11 @@ class UniFileClassObject(object):
         Lang = distutils.util.split_quoted((Line.split(u"//")[0]))\r
         if len(Lang) != 3:\r
             try:\r
         Lang = distutils.util.split_quoted((Line.split(u"//")[0]))\r
         if len(Lang) != 3:\r
             try:\r
-                FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').read()\r
+                FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').readlines()\r
+            except UnicodeError, Xstr:\r
+                FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()\r
             except UnicodeError, Xstr:\r
             except UnicodeError, Xstr:\r
-                FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').read()\r
+                FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines()\r
             except:\r
                 EdkLogger.Error("Unicode File Parser", \r
                                 ToolError.FILE_OPEN_FAILURE, \r
             except:\r
                 EdkLogger.Error("Unicode File Parser", \r
                                 ToolError.FILE_OPEN_FAILURE, \r
@@ -424,7 +427,16 @@ class UniFileClassObject(object):
                              ToolError.FILE_NOT_FOUND,\r
                              ExtraData=File.Path)\r
 \r
                              ToolError.FILE_NOT_FOUND,\r
                              ExtraData=File.Path)\r
 \r
+        #\r
+        # Check file header of the Uni file\r
+        #\r
+#         if not CheckUTF16FileHeader(File.Path):\r
+#             EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+#                             ExtraData='The file %s is either invalid UTF-16LE or it is missing the BOM.' % File.Path)\r
+\r
         try:\r
         try:\r
+            FileIn = codecs.open(File.Path, mode='rb', encoding='utf_8').readlines()\r
+        except UnicodeError, Xstr:\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines()\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
             FileIn = codecs.open(File.Path, mode='rb', encoding='utf_16_le').readlines()\r
@@ -529,21 +541,15 @@ class UniFileClassObject(object):
             Line = Line.replace(u'\t', u' ')\r
             Line = Line.replace(u'\u0006', u'\\')\r
 \r
             Line = Line.replace(u'\t', u' ')\r
             Line = Line.replace(u'\u0006', u'\\')\r
 \r
-            IncList = gINCLUDE_PATTERN.findall(Line)\r
-            if len(IncList) == 1:\r
-                for Dir in [File.Dir] + self.IncludePathList:\r
-                    IncFile = PathClass(str(IncList[0]), Dir)\r
-                    self.IncFileList.append(IncFile)\r
-                    if os.path.isfile(IncFile.Path):\r
-                        Lines.extend(self.PreProcess(IncFile, True))\r
-                        break\r
-                else:\r
-                    EdkLogger.Error("Unicode File Parser", \r
-                                    ToolError.FILE_NOT_FOUND, \r
-                                    Message="Cannot find include file", \r
-                                    ExtraData=str(IncList[0]))\r
-                continue\r
-            \r
+            #\r
+            # Check if single line has correct '"'\r
+            #\r
+            if Line.startswith(u'#string') and Line.find(u'#language') > -1 and Line.find('"') > Line.find(u'#language'):\r
+                if not Line.endswith('"'):\r
+                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                    ExtraData='''The line %s misses '"' at the end of it in file %s'''\r
+                                                 % (LineCount, File.Path))\r
+\r
             #\r
             # Between Name entry and Language entry can not contain line feed\r
             #\r
             #\r
             # Between Name entry and Language entry can not contain line feed\r
             #\r
@@ -564,16 +570,18 @@ class UniFileClassObject(object):
             #\r
             if Line.startswith(u'"'):\r
                 if StringEntryExistsFlag == 2:\r
             #\r
             if Line.startswith(u'"'):\r
                 if StringEntryExistsFlag == 2:\r
-                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, \r
+                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
                                     Message=ST.ERR_UNIPARSE_LINEFEED_UP_EXIST % Line, ExtraData=File.Path)\r
                                     Message=ST.ERR_UNIPARSE_LINEFEED_UP_EXIST % Line, ExtraData=File.Path)\r
-                     \r
+\r
                 StringEntryExistsFlag = 1\r
                 if not Line.endswith('"'):\r
                 StringEntryExistsFlag = 1\r
                 if not Line.endswith('"'):\r
-                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, ExtraData=File.Path)\r
+                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                    ExtraData='''The line %s misses '"' at the end of it in file %s'''\r
+                                              % (LineCount, File.Path))\r
             elif Line.startswith(u'#language'):\r
                 if StringEntryExistsFlag == 2:\r
             elif Line.startswith(u'#language'):\r
                 if StringEntryExistsFlag == 2:\r
-                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID, \r
-                                    Message=ST.ERR_UNIPARSE_LINEFEED_UP_EXIST % Line, ExtraData=File.Path)\r
+                    EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
+                                    Message=ST.ERR_UNI_MISS_STRING_ENTRY % Line, ExtraData=File.Path)\r
                 StringEntryExistsFlag = 0\r
             else:\r
                 StringEntryExistsFlag = 0\r
                 StringEntryExistsFlag = 0\r
             else:\r
                 StringEntryExistsFlag = 0\r
@@ -1033,6 +1041,8 @@ class UniFileClassObject(object):
                              ToolError.FILE_NOT_FOUND,\r
                              ExtraData=FilaPath)\r
         try:\r
                              ToolError.FILE_NOT_FOUND,\r
                              ExtraData=FilaPath)\r
         try:\r
+            FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_8').readlines()\r
+        except UnicodeError, Xstr:\r
             FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
             FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16_le').readlines()\r
             FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16').readlines()\r
         except UnicodeError:\r
             FileIn = codecs.open(FilaPath, mode='rb', encoding='utf_16_le').readlines()\r