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