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