]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/AutoGen/StrGather.py
BaseTools: Use absolute import in AutoGen
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / StrGather.py
1 ## @file
2 # This file is used to parse a strings file and create or add to a string database
3 # file.
4 #
5 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 ##
15 # Import Modules
16 #
17 from __future__ import absolute_import
18 import re
19 import Common.EdkLogger as EdkLogger
20 from Common.BuildToolError import *
21 from .UniClassObject import *
22 from io import BytesIO
23 from struct import pack, unpack
24 from Common.LongFilePathSupport import OpenLongFilePath as open
25
26 ##
27 # Static definitions
28 #
29 EFI_HII_SIBT_END = '0x00'
30 EFI_HII_SIBT_STRING_SCSU = '0x10'
31 EFI_HII_SIBT_STRING_SCSU_FONT = '0x11'
32 EFI_HII_SIBT_STRINGS_SCSU = '0x12'
33 EFI_HII_SIBT_STRINGS_SCSU_FONT = '0x13'
34 EFI_HII_SIBT_STRING_UCS2 = '0x14'
35 EFI_HII_SIBT_STRING_UCS2_FONT = '0x15'
36 EFI_HII_SIBT_STRINGS_UCS2 = '0x16'
37 EFI_HII_SIBT_STRINGS_UCS2_FONT = '0x17'
38 EFI_HII_SIBT_DUPLICATE = '0x20'
39 EFI_HII_SIBT_SKIP2 = '0x21'
40 EFI_HII_SIBT_SKIP1 = '0x22'
41 EFI_HII_SIBT_EXT1 = '0x30'
42 EFI_HII_SIBT_EXT2 = '0x31'
43 EFI_HII_SIBT_EXT4 = '0x32'
44 EFI_HII_SIBT_FONT = '0x40'
45
46 EFI_HII_PACKAGE_STRINGS = '0x04'
47 EFI_HII_PACKAGE_FORM = '0x02'
48
49 StringPackageType = EFI_HII_PACKAGE_STRINGS
50 StringPackageForm = EFI_HII_PACKAGE_FORM
51 StringBlockType = EFI_HII_SIBT_STRING_UCS2
52 StringSkipType = EFI_HII_SIBT_SKIP2
53
54 HexHeader = '0x'
55
56 COMMENT = '// '
57 DEFINE_STR = '#define'
58 COMMENT_DEFINE_STR = COMMENT + DEFINE_STR
59 NOT_REFERENCED = 'not referenced'
60 COMMENT_NOT_REFERENCED = ' ' + COMMENT + NOT_REFERENCED
61 CHAR_ARRAY_DEFIN = 'unsigned char'
62 COMMON_FILE_NAME = 'Strings'
63 STRING_TOKEN = re.compile('STRING_TOKEN *\(([A-Z0-9_]+) *\)', re.MULTILINE | re.UNICODE)
64
65 EFI_HII_ARRAY_SIZE_LENGTH = 4
66 EFI_HII_PACKAGE_HEADER_LENGTH = 4
67 EFI_HII_HDR_SIZE_LENGTH = 4
68 EFI_HII_STRING_OFFSET_LENGTH = 4
69 EFI_STRING_ID = 1
70 EFI_STRING_ID_LENGTH = 2
71 EFI_HII_LANGUAGE_WINDOW = 0
72 EFI_HII_LANGUAGE_WINDOW_LENGTH = 2
73 EFI_HII_LANGUAGE_WINDOW_NUMBER = 16
74 EFI_HII_STRING_PACKAGE_HDR_LENGTH = EFI_HII_PACKAGE_HEADER_LENGTH + EFI_HII_HDR_SIZE_LENGTH + EFI_HII_STRING_OFFSET_LENGTH + EFI_HII_LANGUAGE_WINDOW_LENGTH * EFI_HII_LANGUAGE_WINDOW_NUMBER + EFI_STRING_ID_LENGTH
75
76 H_C_FILE_HEADER = ['//', \
77 '// DO NOT EDIT -- auto-generated file', \
78 '//', \
79 '// This file is generated by the StrGather utility', \
80 '//']
81 LANGUAGE_NAME_STRING_NAME = '$LANGUAGE_NAME'
82 PRINTABLE_LANGUAGE_NAME_STRING_NAME = '$PRINTABLE_LANGUAGE_NAME'
83
84 ## Convert a dec number to a hex string
85 #
86 # Convert a dec number to a formatted hex string in length digit
87 # The digit is set to default 8
88 # The hex string starts with "0x"
89 # DecToHexStr(1000) is '0x000003E8'
90 # DecToHexStr(1000, 6) is '0x0003E8'
91 #
92 # @param Dec: The number in dec format
93 # @param Digit: The needed digit of hex string
94 #
95 # @retval: The formatted hex string
96 #
97 def DecToHexStr(Dec, Digit = 8):
98 return '0x{0:0{1}X}'.format(Dec, Digit)
99
100 ## Convert a dec number to a hex list
101 #
102 # Convert a dec number to a formatted hex list in size digit
103 # The digit is set to default 8
104 # DecToHexList(1000) is ['0xE8', '0x03', '0x00', '0x00']
105 # DecToHexList(1000, 6) is ['0xE8', '0x03', '0x00']
106 #
107 # @param Dec: The number in dec format
108 # @param Digit: The needed digit of hex list
109 #
110 # @retval: A list for formatted hex string
111 #
112 def DecToHexList(Dec, Digit = 8):
113 Hex = '{0:0{1}X}'.format(Dec, Digit)
114 return ["0x" + Hex[Bit:Bit + 2] for Bit in range(Digit - 2, -1, -2)]
115
116 ## Convert a acsii string to a hex list
117 #
118 # Convert a acsii string to a formatted hex list
119 # AscToHexList('en-US') is ['0x65', '0x6E', '0x2D', '0x55', '0x53']
120 #
121 # @param Ascii: The acsii string
122 #
123 # @retval: A list for formatted hex string
124 #
125 def AscToHexList(Ascii):
126 return ['0x{0:02X}'.format(ord(Item)) for Item in Ascii]
127
128 ## Create content of .h file
129 #
130 # Create content of .h file
131 #
132 # @param BaseName: The basename of strings
133 # @param UniObjectClass A UniObjectClass instance
134 # @param IsCompatibleMode Compatible mode
135 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
136 #
137 # @retval Str: A string of .h file content
138 #
139 def CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):
140 Str = ''
141 ValueStartPtr = 60
142 Line = COMMENT_DEFINE_STR + ' ' + LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(0, 4) + COMMENT_NOT_REFERENCED
143 Str = WriteLine(Str, Line)
144 Line = COMMENT_DEFINE_STR + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' * (ValueStartPtr - len(DEFINE_STR + PRINTABLE_LANGUAGE_NAME_STRING_NAME)) + DecToHexStr(1, 4) + COMMENT_NOT_REFERENCED
145 Str = WriteLine(Str, Line)
146 UnusedStr = ''
147
148 #Group the referred/Unused STRING token together.
149 for Index in range(2, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]])):
150 StringItem = UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[0][0]][Index]
151 Name = StringItem.StringName
152 Token = StringItem.Token
153 Referenced = StringItem.Referenced
154 if Name is not None:
155 Line = ''
156 if Referenced == True:
157 if (ValueStartPtr - len(DEFINE_STR + Name)) <= 0:
158 Line = DEFINE_STR + ' ' + Name + ' ' + DecToHexStr(Token, 4)
159 else:
160 Line = DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4)
161 Str = WriteLine(Str, Line)
162 else:
163 if (ValueStartPtr - len(DEFINE_STR + Name)) <= 0:
164 Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED
165 else:
166 Line = COMMENT_DEFINE_STR + ' ' + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(Token, 4) + COMMENT_NOT_REFERENCED
167 UnusedStr = WriteLine(UnusedStr, Line)
168
169 Str = ''.join([Str, UnusedStr])
170
171 Str = WriteLine(Str, '')
172 if IsCompatibleMode or UniGenCFlag:
173 Str = WriteLine(Str, 'extern unsigned char ' + BaseName + 'Strings[];')
174 return Str
175
176 ## Create a complete .h file
177 #
178 # Create a complet .h file with file header and file content
179 #
180 # @param BaseName: The basename of strings
181 # @param UniObjectClass A UniObjectClass instance
182 # @param IsCompatibleMode Compatible mode
183 # @param UniGenCFlag UniString is generated into AutoGen C file when it is set to True
184 #
185 # @retval Str: A string of complete .h file
186 #
187 def CreateHFile(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag):
188 HFile = WriteLine('', CreateHFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniGenCFlag))
189
190 return HFile
191
192 ## Create a buffer to store all items in an array
193 #
194 # @param BinBuffer Buffer to contain Binary data.
195 # @param Array: The array need to be formatted
196 #
197 def CreateBinBuffer(BinBuffer, Array):
198 for Item in Array:
199 BinBuffer.write(pack("B", int(Item, 16)))
200
201 ## Create a formatted string all items in an array
202 #
203 # Use ',' to join each item in an array, and break an new line when reaching the width (default is 16)
204 #
205 # @param Array: The array need to be formatted
206 # @param Width: The line length, the default value is set to 16
207 #
208 # @retval ArrayItem: A string for all formatted array items
209 #
210 def CreateArrayItem(Array, Width = 16):
211 MaxLength = Width
212 Index = 0
213 Line = ' '
214 ArrayItem = ''
215
216 for Item in Array:
217 if Index < MaxLength:
218 Line = Line + Item + ', '
219 Index = Index + 1
220 else:
221 ArrayItem = WriteLine(ArrayItem, Line)
222 Line = ' ' + Item + ', '
223 Index = 1
224 ArrayItem = Write(ArrayItem, Line.rstrip())
225
226 return ArrayItem
227
228 ## CreateCFileStringValue
229 #
230 # Create a line with string value
231 #
232 # @param Value: Value of the string
233 #
234 # @retval Str: A formatted string with string value
235 #
236
237 def CreateCFileStringValue(Value):
238 Value = [StringBlockType] + Value
239 Str = WriteLine('', CreateArrayItem(Value))
240
241 return Str
242
243 ## GetFilteredLanguage
244 #
245 # apply get best language rules to the UNI language code list
246 #
247 # @param UniLanguageList: language code definition list in *.UNI file
248 # @param LanguageFilterList: language code filter list of RFC4646 format in DSC file
249 #
250 # @retval UniLanguageListFiltered: the filtered language code
251 #
252 def GetFilteredLanguage(UniLanguageList, LanguageFilterList):
253 UniLanguageListFiltered = []
254 # if filter list is empty, then consider there is no filter
255 if LanguageFilterList == []:
256 UniLanguageListFiltered = UniLanguageList
257 return UniLanguageListFiltered
258 for Language in LanguageFilterList:
259 # first check for exact match
260 if Language in UniLanguageList:
261 if Language not in UniLanguageListFiltered:
262 UniLanguageListFiltered.append(Language)
263 # find the first one with the same/equivalent primary tag
264 else:
265 if Language.find('-') != -1:
266 PrimaryTag = Language[0:Language.find('-')].lower()
267 else:
268 PrimaryTag = Language
269
270 if len(PrimaryTag) == 3:
271 PrimaryTag = LangConvTable.get(PrimaryTag)
272
273 for UniLanguage in UniLanguageList:
274 if UniLanguage.find('-') != -1:
275 UniLanguagePrimaryTag = UniLanguage[0:UniLanguage.find('-')].lower()
276 else:
277 UniLanguagePrimaryTag = UniLanguage
278
279 if len(UniLanguagePrimaryTag) == 3:
280 UniLanguagePrimaryTag = LangConvTable.get(UniLanguagePrimaryTag)
281
282 if PrimaryTag == UniLanguagePrimaryTag:
283 if UniLanguage not in UniLanguageListFiltered:
284 UniLanguageListFiltered.append(UniLanguage)
285 break
286 else:
287 # Here is rule 3 for "get best language"
288 # If tag is not listed in the Unicode file, the default ("en") tag should be used for that language
289 # for better processing, find the one that best suit for it.
290 DefaultTag = 'en'
291 if DefaultTag not in UniLanguageListFiltered:
292 # check whether language code with primary code equivalent with DefaultTag already in the list, if so, use that
293 for UniLanguage in UniLanguageList:
294 if UniLanguage.startswith('en-') or UniLanguage.startswith('eng-'):
295 if UniLanguage not in UniLanguageListFiltered:
296 UniLanguageListFiltered.append(UniLanguage)
297 break
298 else:
299 UniLanguageListFiltered.append(DefaultTag)
300 return UniLanguageListFiltered
301
302
303 ## Create content of .c file
304 #
305 # Create content of .c file
306 #
307 # @param BaseName: The basename of strings
308 # @param UniObjectClass A UniObjectClass instance
309 # @param IsCompatibleMode Compatible mode
310 # @param UniBinBuffer UniBinBuffer to contain UniBinary data.
311 # @param FilterInfo Platform language filter information
312 #
313 # @retval Str: A string of .c file content
314 #
315 def CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, UniBinBuffer, FilterInfo):
316 #
317 # Init array length
318 #
319 TotalLength = EFI_HII_ARRAY_SIZE_LENGTH
320 Str = ''
321 Offset = 0
322
323 EDK2Module = FilterInfo[0]
324 if EDK2Module:
325 LanguageFilterList = FilterInfo[1]
326 else:
327 # EDK module is using ISO639-2 format filter, convert to the RFC4646 format
328 LanguageFilterList = [LangConvTable.get(F.lower()) for F in FilterInfo[1]]
329
330 UniLanguageList = []
331 for IndexI in range(len(UniObjectClass.LanguageDef)):
332 UniLanguageList += [UniObjectClass.LanguageDef[IndexI][0]]
333
334 UniLanguageListFiltered = GetFilteredLanguage(UniLanguageList, LanguageFilterList)
335
336
337 #
338 # Create lines for each language's strings
339 #
340 for IndexI in range(len(UniObjectClass.LanguageDef)):
341 Language = UniObjectClass.LanguageDef[IndexI][0]
342 if Language not in UniLanguageListFiltered:
343 continue
344
345 StringBuffer = BytesIO()
346 StrStringValue = ''
347 ArrayLength = 0
348 NumberOfUseOtherLangDef = 0
349 Index = 0
350 for IndexJ in range(1, len(UniObjectClass.OrderedStringList[UniObjectClass.LanguageDef[IndexI][0]])):
351 Item = UniObjectClass.OrderedStringListByToken[Language][IndexJ]
352
353 Name = Item.StringName
354 Value = Item.StringValueByteList
355 Referenced = Item.Referenced
356 Token = Item.Token
357 UseOtherLangDef = Item.UseOtherLangDef
358
359 if UseOtherLangDef != '' and Referenced:
360 NumberOfUseOtherLangDef = NumberOfUseOtherLangDef + 1
361 Index = Index + 1
362 else:
363 if NumberOfUseOtherLangDef > 0:
364 StrStringValue = WriteLine(StrStringValue, CreateArrayItem([StringSkipType] + DecToHexList(NumberOfUseOtherLangDef, 4)))
365 CreateBinBuffer (StringBuffer, ([StringSkipType] + DecToHexList(NumberOfUseOtherLangDef, 4)))
366 NumberOfUseOtherLangDef = 0
367 ArrayLength = ArrayLength + 3
368 if Referenced and Item.Token > 0:
369 Index = Index + 1
370 StrStringValue = WriteLine(StrStringValue, "// %s: %s:%s" % (DecToHexStr(Index, 4), Name, DecToHexStr(Token, 4)))
371 StrStringValue = Write(StrStringValue, CreateCFileStringValue(Value))
372 CreateBinBuffer (StringBuffer, [StringBlockType] + Value)
373 ArrayLength = ArrayLength + Item.Length + 1 # 1 is for the length of string type
374
375 #
376 # EFI_HII_PACKAGE_HEADER
377 #
378 Offset = EFI_HII_STRING_PACKAGE_HDR_LENGTH + len(Language) + 1
379 ArrayLength = Offset + ArrayLength + 1
380
381 #
382 # Create PACKAGE HEADER
383 #
384 Str = WriteLine(Str, '// PACKAGE HEADER\n')
385 TotalLength = TotalLength + ArrayLength
386
387 List = DecToHexList(ArrayLength, 6) + \
388 [StringPackageType] + \
389 DecToHexList(Offset) + \
390 DecToHexList(Offset) + \
391 DecToHexList(EFI_HII_LANGUAGE_WINDOW, EFI_HII_LANGUAGE_WINDOW_LENGTH * 2) * EFI_HII_LANGUAGE_WINDOW_NUMBER + \
392 DecToHexList(EFI_STRING_ID, 4) + \
393 AscToHexList(Language) + \
394 DecToHexList(0, 2)
395 Str = WriteLine(Str, CreateArrayItem(List, 16) + '\n')
396
397 #
398 # Create PACKAGE DATA
399 #
400 Str = WriteLine(Str, '// PACKAGE DATA\n')
401 Str = Write(Str, StrStringValue)
402
403 #
404 # Add an EFI_HII_SIBT_END at last
405 #
406 Str = WriteLine(Str, ' ' + EFI_HII_SIBT_END + ",")
407
408 #
409 # Create binary UNI string
410 #
411 if UniBinBuffer:
412 CreateBinBuffer (UniBinBuffer, List)
413 UniBinBuffer.write (StringBuffer.getvalue())
414 UniBinBuffer.write (pack("B", int(EFI_HII_SIBT_END, 16)))
415 StringBuffer.close()
416
417 #
418 # Create line for string variable name
419 # "unsigned char $(BaseName)Strings[] = {"
420 #
421 AllStr = WriteLine('', CHAR_ARRAY_DEFIN + ' ' + BaseName + COMMON_FILE_NAME + '[] = {\n')
422
423 if IsCompatibleMode:
424 #
425 # Create FRAMEWORK_EFI_HII_PACK_HEADER in compatible mode
426 #
427 AllStr = WriteLine(AllStr, '// FRAMEWORK PACKAGE HEADER Length')
428 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength + 2)) + '\n')
429 AllStr = WriteLine(AllStr, '// FRAMEWORK PACKAGE HEADER Type')
430 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(2, 4)) + '\n')
431 else:
432 #
433 # Create whole array length in UEFI mode
434 #
435 AllStr = WriteLine(AllStr, '// STRGATHER_OUTPUT_HEADER')
436 AllStr = WriteLine(AllStr, CreateArrayItem(DecToHexList(TotalLength)) + '\n')
437
438 #
439 # Join package data
440 #
441 AllStr = Write(AllStr, Str)
442
443 return AllStr
444
445 ## Create end of .c file
446 #
447 # Create end of .c file
448 #
449 # @retval Str: A string of .h file end
450 #
451 def CreateCFileEnd():
452 Str = Write('', '};')
453 return Str
454
455 ## Create a .c file
456 #
457 # Create a complete .c file
458 #
459 # @param BaseName: The basename of strings
460 # @param UniObjectClass A UniObjectClass instance
461 # @param IsCompatibleMode Compatible Mode
462 # @param FilterInfo Platform language filter information
463 #
464 # @retval CFile: A string of complete .c file
465 #
466 def CreateCFile(BaseName, UniObjectClass, IsCompatibleMode, FilterInfo):
467 CFile = ''
468 CFile = WriteLine(CFile, CreateCFileContent(BaseName, UniObjectClass, IsCompatibleMode, None, FilterInfo))
469 CFile = WriteLine(CFile, CreateCFileEnd())
470 return CFile
471
472 ## GetFileList
473 #
474 # Get a list for all files
475 #
476 # @param IncludeList: A list of all path to be searched
477 # @param SkipList: A list of all types of file could be skipped
478 #
479 # @retval FileList: A list of all files found
480 #
481 def GetFileList(SourceFileList, IncludeList, SkipList):
482 if IncludeList is None:
483 EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, "Include path for unicode file is not defined")
484
485 FileList = []
486 if SkipList is None:
487 SkipList = []
488
489 for File in SourceFileList:
490 for Dir in IncludeList:
491 if not os.path.exists(Dir):
492 continue
493 File = os.path.join(Dir, File.Path)
494 #
495 # Ignore Dir
496 #
497 if os.path.isfile(File) != True:
498 continue
499 #
500 # Ignore file listed in skip list
501 #
502 IsSkip = False
503 for Skip in SkipList:
504 if os.path.splitext(File)[1].upper() == Skip.upper():
505 EdkLogger.verbose("Skipped %s for string token uses search" % File)
506 IsSkip = True
507 break
508
509 if not IsSkip:
510 FileList.append(File)
511
512 break
513
514 return FileList
515
516 ## SearchString
517 #
518 # Search whether all string defined in UniObjectClass are referenced
519 # All string used should be set to Referenced
520 #
521 # @param UniObjectClass: Input UniObjectClass
522 # @param FileList: Search path list
523 # @param IsCompatibleMode Compatible Mode
524 #
525 # @retval UniObjectClass: UniObjectClass after searched
526 #
527 def SearchString(UniObjectClass, FileList, IsCompatibleMode):
528 if FileList == []:
529 return UniObjectClass
530
531 for File in FileList:
532 if os.path.isfile(File):
533 Lines = open(File, 'r')
534 for Line in Lines:
535 for StrName in STRING_TOKEN.findall(Line):
536 EdkLogger.debug(EdkLogger.DEBUG_5, "Found string identifier: " + StrName)
537 UniObjectClass.SetStringReferenced(StrName)
538
539 UniObjectClass.ReToken()
540
541 return UniObjectClass
542
543 ## GetStringFiles
544 #
545 # This function is used for UEFI2.1 spec
546 #
547 #
548 def GetStringFiles(UniFilList, SourceFileList, IncludeList, IncludePathList, SkipList, BaseName, IsCompatibleMode = False, ShellMode = False, UniGenCFlag = True, UniGenBinBuffer = None, FilterInfo = [True, []]):
549 if len(UniFilList) > 0:
550 if ShellMode:
551 #
552 # support ISO 639-2 codes in .UNI files of EDK Shell
553 #
554 Uni = UniFileClassObject(sorted (UniFilList), True, IncludePathList)
555 else:
556 Uni = UniFileClassObject(sorted (UniFilList), IsCompatibleMode, IncludePathList)
557 else:
558 EdkLogger.error("UnicodeStringGather", AUTOGEN_ERROR, 'No unicode files given')
559
560 FileList = GetFileList(SourceFileList, IncludeList, SkipList)
561
562 Uni = SearchString(Uni, sorted (FileList), IsCompatibleMode)
563
564 HFile = CreateHFile(BaseName, Uni, IsCompatibleMode, UniGenCFlag)
565 CFile = None
566 if IsCompatibleMode or UniGenCFlag:
567 CFile = CreateCFile(BaseName, Uni, IsCompatibleMode, FilterInfo)
568 if UniGenBinBuffer:
569 CreateCFileContent(BaseName, Uni, IsCompatibleMode, UniGenBinBuffer, FilterInfo)
570
571 return HFile, CFile
572
573 #
574 # Write an item
575 #
576 def Write(Target, Item):
577 return ''.join([Target, Item])
578
579 #
580 # Write an item with a break line
581 #
582 def WriteLine(Target, Item):
583 return ''.join([Target, Item, '\n'])
584
585 # This acts like the main() function for the script, unless it is 'import'ed into another
586 # script.
587 if __name__ == '__main__':
588 EdkLogger.info('start')
589
590 UniFileList = [
591 r'C:\\Edk\\Strings2.uni',
592 r'C:\\Edk\\Strings.uni'
593 ]
594
595 SrcFileList = []
596 for Root, Dirs, Files in os.walk('C:\\Edk'):
597 for File in Files:
598 SrcFileList.append(File)
599
600 IncludeList = [
601 r'C:\\Edk'
602 ]
603
604 SkipList = ['.inf', '.uni']
605 BaseName = 'DriverSample'
606 (h, c) = GetStringFiles(UniFileList, SrcFileList, IncludeList, SkipList, BaseName, True)
607 hfile = open('unistring.h', 'w')
608 cfile = open('unistring.c', 'w')
609 hfile.write(h)
610 cfile.write(c)
611
612 EdkLogger.info('end')