X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FAutoGen%2FStrGather.py;h=60840041ba22ce2fc290808efc0ace05e615b6b0;hp=3df493834c48cd5cb225e04f4e263839840e8940;hb=47fea6afd74af76c7e2a2b03d319b7ac035ac26a;hpb=6780eef1f9ed0af24795708c3be7adafd7113691 diff --git a/BaseTools/Source/Python/AutoGen/StrGather.py b/BaseTools/Source/Python/AutoGen/StrGather.py index 3df493834c..60840041ba 100644 --- a/BaseTools/Source/Python/AutoGen/StrGather.py +++ b/BaseTools/Source/Python/AutoGen/StrGather.py @@ -1,4 +1,8 @@ -# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.
+## @file +# This file is used to parse a strings file and create or add to a string database +# file. +# +# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
# This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License # which accompanies this distribution. The full text of the license may be found at @@ -7,10 +11,6 @@ # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -# -#This file is used to parse a strings file and create or add to a string database file. -# - ## # Import Modules # @@ -20,6 +20,7 @@ from Common.BuildToolError import * from UniClassObject import * from StringIO import StringIO from struct import pack +from Common.LongFilePathSupport import OpenLongFilePath as open ## # Static definitions @@ -62,7 +63,7 @@ OFFSET = 'offset' STRING = 'string' TO = 'to' STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE) -COMPATIBLE_STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Za-z0-9_]+) *\)', re.MULTILINE | re.UNICODE) +COMPATIBLE_STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE) EFI_HII_ARRAY_SIZE_LENGTH = 4 EFI_HII_PACKAGE_HEADER_LENGTH = 4 @@ -112,7 +113,7 @@ def DecToHexStr(Dec, Digit = 8): # @retval: A list for formatted hex string # def DecToHexList(Dec, Digit = 8): - Hex = eval("'%0" + str(Digit) + "X' % int(Dec)" ) + Hex = eval("'%0" + str(Digit) + "X' % int(Dec)") List = [] for Bit in range(Digit - 2, -1, -2): List.append(HexHeader + Hex[Bit:Bit + 2]) @@ -168,8 +169,9 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag): Str = WriteLine(Str, Line) Line = COMMENT_DEFINE_STR + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + PRINTABLE_LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(1, 4) + COMMENT_NOT_REFERENCED Str = WriteLine(Str, Line) + UnusedStr = '' - #Group the referred STRING token together. + #Group the referred/Unused STRING token together. for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])): StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index] Name = StringItem.StringName @@ -183,21 +185,14 @@ def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag): else: Line = DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) Str = WriteLine(Str, Line) - - #Group the unused STRING token together. - for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])): - StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index] - Name = StringItem.StringName - Token = StringItem.Token - Referenced = StringItem.Referenced - if Name != None: - Line = '' - if Referenced == False: + else: if (ValueStartPtr - len(DEFINE_STR + Name)) <= 0: Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED else: Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED - Str = WriteLine(Str, Line) + UnusedStr = WriteLine(UnusedStr, Line) + + Str = ''.join([Str, UnusedStr]) Str = WriteLine(Str, '') if IsCompatibleMode or UniGenCFlag: @@ -240,7 +235,7 @@ def CreateCFileHeader(): # def CreateBinBuffer(BinBuffer, Array): for Item in Array: - BinBuffer.write(pack("B", int(Item,16))) + BinBuffer.write(pack("B", int(Item, 16))) ## Create a formatted string all items in an array # @@ -263,7 +258,7 @@ def CreateArrayItem(Array, Width = 16): Index = Index + 1 else: ArrayItem = WriteLine(ArrayItem, Line) - Line = ' ' + Item + ', ' + Line = ' ' + Item + ', ' Index = 1 ArrayItem = Write(ArrayItem, Line.rstrip()) @@ -325,7 +320,7 @@ def GetFilteredLanguage(UniLanguageList, LanguageFilterList): if PrimaryTag == UniLanguagePrimaryTag: if UniLanguage not in UniLanguageListFiltered: - UniLanguageListFiltered += [UniLanguage] + UniLanguageListFiltered += [UniLanguage] break else: # Here is rule 3 for "get best language" @@ -373,7 +368,7 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, UniLanguageList = [] for IndexI in range(len(UniObjectClass.LanguageDef)): - UniLanguageList += [UniObjectClass.LanguageDef[IndexI][0]] + UniLanguageList += [UniObjectClass.LanguageDef[IndexI][0]] UniLanguageListFiltered = GetFilteredLanguage(UniLanguageList, LanguageFilterList) @@ -383,7 +378,6 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, # for IndexI in range(len(UniObjectClass.LanguageDef)): Language = UniObjectClass.LanguageDef[IndexI][0] - LangPrintName = UniObjectClass.LanguageDef[IndexI][1] if Language not in UniLanguageListFiltered: continue @@ -393,12 +387,12 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, NumberOfUseOtherLangDef = 0 Index = 0 for IndexJ in range(1, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[IndexI][0]])): - Item = UniObjectClass.FindByToken(IndexJ, Language) + Item = UniObjectClass.OrderedStringListByToken[Language][IndexJ] + Name = Item.StringName Value = Item.StringValueByteList Referenced = Item.Referenced Token = Item.Token - Length = Item.Length UseOtherLangDef = Item.UseOtherLangDef if UseOtherLangDef != '' and Referenced: @@ -456,14 +450,14 @@ def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, if UniBinBuffer: CreateBinBuffer (UniBinBuffer, List) UniBinBuffer.write (StringBuffer.getvalue()) - UniBinBuffer.write (pack("B", int(EFI_HII_SIBT_END,16))) + UniBinBuffer.write (pack("B", int(EFI_HII_SIBT_END, 16))) StringBuffer.close() # # Create line for string variable name # "unsigned char $(BaseName)Strings[] = {" # - AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + BaseName + COMMON_FILE_NAME + '[] = {\n' ) + AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + BaseName + COMMON_FILE_NAME + '[] = {\n') if IsCompatibleMode: # @@ -595,10 +589,7 @@ def SearchString(UniObjectClass, FileList, IsCompatibleMode): # This function is used for UEFI2.1 spec # # -def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None, FilterInfo = [True, []]): - Status = True - ErrorMessage = '' - +def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None, FilterInfo = [True, []]): if len(UniFilList) > 0: if ShellMode: # @@ -627,13 +618,13 @@ def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, Ski # Write an item # def Write(Target, Item): - return Target + Item + return ''.join([Target, Item]) # # Write an item with a break line # def WriteLine(Target, Item): - return Target + Item + '\n' + return ''.join([Target, Item, '\n']) # This acts like the main() function for the script, unless it is 'import'ed into another # script.