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