]> 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 c57bfdf57d9fcf4f95bc4c45505c3dcc31bdfcef..0014a7561ba88b1b02b735ecc04ba2b334571f0c 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Collect all defined strings in multiple uni files.\r
 #\r
-# Copyright (c) 2014 - 2015, 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
@@ -47,8 +47,6 @@ NULL = u'\u0000'
 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
@@ -328,9 +326,11 @@ class UniFileClassObject(object):
         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
-                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
@@ -430,11 +430,13 @@ class UniFileClassObject(object):
         #\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
+        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
+            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
@@ -539,22 +541,15 @@ class UniFileClassObject(object):
             Line = Line.replace(u'\t', u' ')\r
             Line = Line.replace(u'\u0006', u'\\')\r
 \r
-            # IncList = gINCLUDE_PATTERN.findall(Line)\r
-            IncList = []\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
@@ -575,9 +570,9 @@ class UniFileClassObject(object):
             #\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
-                     \r
+\r
                 StringEntryExistsFlag = 1\r
                 if not Line.endswith('"'):\r
                     EdkLogger.Error("Unicode File Parser", ToolError.FORMAT_INVALID,\r
@@ -585,7 +580,7 @@ class UniFileClassObject(object):
                                               % (LineCount, File.Path))\r
             elif Line.startswith(u'#language'):\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_UNI_MISS_STRING_ENTRY % Line, ExtraData=File.Path)\r
                 StringEntryExistsFlag = 0\r
             else:\r
@@ -1046,6 +1041,8 @@ class UniFileClassObject(object):
                              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