1 # Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
2 # This program and the accompanying materials
3 # are licensed and made available under the terms and conditions of the BSD License
4 # which accompanies this distribution. The full text of the license may be found at
5 # http://opensource.org/licenses/bsd-license.php
7 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
8 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 #This file is used to collect all defined strings in multiple uni files
19 import Common
.EdkLogger
as EdkLogger
20 from Common
.BuildToolError
import *
21 from Common
.String
import GetLineNo
22 from Common
.Misc
import PathClass
27 UNICODE_WIDE_CHAR
= u
'\\wide'
28 UNICODE_NARROW_CHAR
= u
'\\narrow'
29 UNICODE_NON_BREAKING_CHAR
= u
'\\nbr'
30 UNICODE_UNICODE_CR
= '\r'
31 UNICODE_UNICODE_LF
= '\n'
33 NARROW_CHAR
= u
'\uFFF0'
35 NON_BREAKING_CHAR
= u
'\uFFF2'
41 DOBULE_QUOTED_SPLASH
= u
'\\"'
42 SIGLE_QUOTED_SPLASH
= u
"\\'"
43 TAB_BACK_SLASH
= u
"\\/"
45 gIncludePattern
= re
.compile("^#include +[\"<]+([^\"< >]+)[>\"]+$", re
.MULTILINE | re
.UNICODE
)
47 ## Convert a python unicode string to a normal string
49 # Convert a python unicode string to a normal string
50 # UniToStr(u'I am a string') is 'I am a string'
52 # @param Uni: The python unicode string
54 # @retval: The formatted normal string
57 return repr(Uni
)[2:-1]
59 ## Convert a unicode string to a Hex list
61 # Convert a unicode string to a Hex list
62 # UniToHexList('ABC') is ['0x41', '0x00', '0x42', '0x00', '0x43', '0x00']
64 # @param Uni: The python unicode string
66 # @retval List: The formatted hex list
68 def UniToHexList(Uni
):
71 Temp
= '%04X' % ord(Item
)
72 List
.append('0x' + Temp
[2:4])
73 List
.append('0x' + Temp
[0:2])
76 LangConvTable
= {'eng':'en', 'fra':'fr', \
77 'aar':'aa', 'abk':'ab', 'ave':'ae', 'afr':'af', 'aka':'ak', 'amh':'am', \
78 'arg':'an', 'ara':'ar', 'asm':'as', 'ava':'av', 'aym':'ay', 'aze':'az', \
79 'bak':'ba', 'bel':'be', 'bul':'bg', 'bih':'bh', 'bis':'bi', 'bam':'bm', \
80 'ben':'bn', 'bod':'bo', 'bre':'br', 'bos':'bs', 'cat':'ca', 'che':'ce', \
81 'cha':'ch', 'cos':'co', 'cre':'cr', 'ces':'cs', 'chu':'cu', 'chv':'cv', \
82 'cym':'cy', 'dan':'da', 'deu':'de', 'div':'dv', 'dzo':'dz', 'ewe':'ee', \
83 'ell':'el', 'epo':'eo', 'spa':'es', 'est':'et', 'eus':'eu', 'fas':'fa', \
84 'ful':'ff', 'fin':'fi', 'fij':'fj', 'fao':'fo', 'fry':'fy', 'gle':'ga', \
85 'gla':'gd', 'glg':'gl', 'grn':'gn', 'guj':'gu', 'glv':'gv', 'hau':'ha', \
86 'heb':'he', 'hin':'hi', 'hmo':'ho', 'hrv':'hr', 'hat':'ht', 'hun':'hu', \
87 'hye':'hy', 'her':'hz', 'ina':'ia', 'ind':'id', 'ile':'ie', 'ibo':'ig', \
88 'iii':'ii', 'ipk':'ik', 'ido':'io', 'isl':'is', 'ita':'it', 'iku':'iu', \
89 'jpn':'ja', 'jav':'jv', 'kat':'ka', 'kon':'kg', 'kik':'ki', 'kua':'kj', \
90 'kaz':'kk', 'kal':'kl', 'khm':'km', 'kan':'kn', 'kor':'ko', 'kau':'kr', \
91 'kas':'ks', 'kur':'ku', 'kom':'kv', 'cor':'kw', 'kir':'ky', 'lat':'la', \
92 'ltz':'lb', 'lug':'lg', 'lim':'li', 'lin':'ln', 'lao':'lo', 'lit':'lt', \
93 'lub':'lu', 'lav':'lv', 'mlg':'mg', 'mah':'mh', 'mri':'mi', 'mkd':'mk', \
94 'mal':'ml', 'mon':'mn', 'mar':'mr', 'msa':'ms', 'mlt':'mt', 'mya':'my', \
95 'nau':'na', 'nob':'nb', 'nde':'nd', 'nep':'ne', 'ndo':'ng', 'nld':'nl', \
96 'nno':'nn', 'nor':'no', 'nbl':'nr', 'nav':'nv', 'nya':'ny', 'oci':'oc', \
97 'oji':'oj', 'orm':'om', 'ori':'or', 'oss':'os', 'pan':'pa', 'pli':'pi', \
98 'pol':'pl', 'pus':'ps', 'por':'pt', 'que':'qu', 'roh':'rm', 'run':'rn', \
99 'ron':'ro', 'rus':'ru', 'kin':'rw', 'san':'sa', 'srd':'sc', 'snd':'sd', \
100 'sme':'se', 'sag':'sg', 'sin':'si', 'slk':'sk', 'slv':'sl', 'smo':'sm', \
101 'sna':'sn', 'som':'so', 'sqi':'sq', 'srp':'sr', 'ssw':'ss', 'sot':'st', \
102 'sun':'su', 'swe':'sv', 'swa':'sw', 'tam':'ta', 'tel':'te', 'tgk':'tg', \
103 'tha':'th', 'tir':'ti', 'tuk':'tk', 'tgl':'tl', 'tsn':'tn', 'ton':'to', \
104 'tur':'tr', 'tso':'ts', 'tat':'tt', 'twi':'tw', 'tah':'ty', 'uig':'ug', \
105 'ukr':'uk', 'urd':'ur', 'uzb':'uz', 'ven':'ve', 'vie':'vi', 'vol':'vo', \
106 'wln':'wa', 'wol':'wo', 'xho':'xh', 'yid':'yi', 'yor':'yo', 'zha':'za', \
107 'zho':'zh', 'zul':'zu'}
111 # Check the language code read from .UNI file and convert ISO 639-2 codes to RFC 4646 codes if appropriate
112 # ISO 639-2 language codes supported in compatiblity mode
113 # RFC 4646 language codes supported in native mode
115 # @param LangName: Language codes read from .UNI file
117 # @retval LangName: Valid lanugage code in RFC 4646 format or None
119 def GetLanguageCode(LangName
, IsCompatibleMode
, File
):
122 length
= len(LangName
)
124 if length
== 3 and LangName
.isalpha():
125 TempLangName
= LangConvTable
.get(LangName
.lower())
126 if TempLangName
!= None:
130 EdkLogger
.error("Unicode File Parser", FORMAT_INVALID
, "Invalid ISO 639-2 language code : %s" % LangName
, File
)
132 if (LangName
[0] == 'X' or LangName
[0] == 'x') and LangName
[1] == '-':
135 if LangName
.isalpha():
138 if LangName
.isalpha() and LangConvTable
.get(LangName
.lower()) == None:
141 if LangName
[0:2].isalpha() and LangName
[2] == '-':
144 if LangName
[0:2].isalpha() and LangName
[2] == '-':
146 if LangName
[0:3].isalpha() and LangConvTable
.get(LangName
.lower()) == None and LangName
[3] == '-':
149 EdkLogger
.error("Unicode File Parser", FORMAT_INVALID
, "Invalid RFC 4646 language code : %s" % LangName
, File
)
151 ## StringDefClassObject
153 # A structure for language definition
155 class StringDefClassObject(object):
156 def __init__(self
, Name
= None, Value
= None, Referenced
= False, Token
= None, UseOtherLangDef
= ''):
158 self
.StringNameByteList
= []
159 self
.StringValue
= ''
160 self
.StringValueByteList
= ''
162 self
.Referenced
= Referenced
163 self
.UseOtherLangDef
= UseOtherLangDef
167 self
.StringName
= Name
168 self
.StringNameByteList
= UniToHexList(Name
)
170 self
.StringValue
= Value
+ u
'\x00' # Add a NULL at string tail
171 self
.StringValueByteList
= UniToHexList(self
.StringValue
)
172 self
.Length
= len(self
.StringValueByteList
)
177 return repr(self
.StringName
) + ' ' + \
178 repr(self
.Token
) + ' ' + \
179 repr(self
.Referenced
) + ' ' + \
180 repr(self
.StringValue
) + ' ' + \
181 repr(self
.UseOtherLangDef
)
183 def UpdateValue(self
, Value
= None):
185 self
.StringValue
= Value
+ u
'\x00' # Add a NULL at string tail
186 self
.StringValueByteList
= UniToHexList(self
.StringValue
)
187 self
.Length
= len(self
.StringValueByteList
)
189 ## UniFileClassObject
191 # A structure for .uni file definition
193 class UniFileClassObject(object):
194 def __init__(self
, FileList
= [], IsCompatibleMode
= False, IncludePathList
= []):
195 self
.FileList
= FileList
197 self
.LanguageDef
= [] #[ [u'LanguageIdentifier', u'PrintableName'], ... ]
198 self
.OrderedStringList
= {} #{ u'LanguageIdentifier' : [StringDefClassObject] }
199 self
.OrderedStringDict
= {} #{ u'LanguageIdentifier' : {StringName:(IndexInList)} }
200 self
.OrderedStringListByToken
= {} #{ u'LanguageIdentifier' : {Token: StringDefClassObject} }
201 self
.IsCompatibleMode
= IsCompatibleMode
202 self
.IncludePathList
= IncludePathList
203 if len(self
.FileList
) > 0:
204 self
.LoadUniFiles(FileList
)
207 # Get Language definition
209 def GetLangDef(self
, File
, Line
):
210 Lang
= distutils
.util
.split_quoted((Line
.split(u
"//")[0]))
213 FileIn
= codecs
.open(File
.Path
, mode
='rb', encoding
='utf-16').read()
214 except UnicodeError, X
:
215 EdkLogger
.error("build", FILE_READ_FAILURE
, "File read failure: %s" % str(X
), ExtraData
=File
);
217 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=File
);
218 LineNo
= GetLineNo(FileIn
, Line
, False)
219 EdkLogger
.error("Unicode File Parser", PARSER_ERROR
, "Wrong language definition",
220 ExtraData
="""%s\n\t*Correct format is like '#langdef en-US "English"'""" % Line
, File
= File
, Line
= LineNo
)
222 LangName
= GetLanguageCode(Lang
[1], self
.IsCompatibleMode
, self
.File
)
223 LangPrintName
= Lang
[2]
226 for Item
in self
.LanguageDef
:
227 if Item
[0] == LangName
:
232 self
.LanguageDef
.append([LangName
, LangPrintName
])
235 # Add language string
237 self
.AddStringToList(u
'$LANGUAGE_NAME', LangName
, LangName
, 0, True, Index
=0)
238 self
.AddStringToList(u
'$PRINTABLE_LANGUAGE_NAME', LangName
, LangPrintName
, 1, True, Index
=1)
242 # The found STRING tokens will be added into new language string list
243 # so that the unique STRING identifier is reserved for all languages in the package list.
245 FirstLangName
= self
.LanguageDef
[0][0]
246 if LangName
!= FirstLangName
:
247 for Index
in range (2, len (self
.OrderedStringList
[FirstLangName
])):
248 Item
= self
.OrderedStringList
[FirstLangName
][Index
]
249 if Item
.UseOtherLangDef
!= '':
250 OtherLang
= Item
.UseOtherLangDef
252 OtherLang
= FirstLangName
253 self
.OrderedStringList
[LangName
].append (StringDefClassObject(Item
.StringName
, '', Item
.Referenced
, Item
.Token
, OtherLang
))
254 self
.OrderedStringDict
[LangName
][Item
.StringName
] = len(self
.OrderedStringList
[LangName
]) - 1
258 # Get String name and value
260 def GetStringObject(self
, Item
):
264 Name
= Item
.split()[1]
265 # Check the string name is the upper character
267 MatchString
= re
.match('[A-Z0-9_]+', Name
, re
.UNICODE
)
268 if MatchString
== None or MatchString
.end(0) != len(Name
):
269 EdkLogger
.error('Unicode File Parser', FORMAT_INVALID
, 'The string token name %s defined in UNI file %s contains the invalid lower case character.' %(Name
, self
.File
))
270 LanguageList
= Item
.split(u
'#language ')
271 for IndexI
in range(len(LanguageList
)):
275 Language
= LanguageList
[IndexI
].split()[0]
276 Value
= LanguageList
[IndexI
][LanguageList
[IndexI
].find(u
'\"') + len(u
'\"') : LanguageList
[IndexI
].rfind(u
'\"')] #.replace(u'\r\n', u'')
277 Language
= GetLanguageCode(Language
, self
.IsCompatibleMode
, self
.File
)
278 self
.AddStringToList(Name
, Language
, Value
)
281 # Get include file list and load them
283 def GetIncludeFile(self
, Item
, Dir
):
284 FileName
= Item
[Item
.find(u
'#include ') + len(u
'#include ') :Item
.find(u
' ', len(u
'#include '))][1:-1]
285 self
.LoadUniFile(FileName
)
288 # Pre-process before parse .uni file
290 def PreProcess(self
, File
):
291 if not os
.path
.exists(File
.Path
) or not os
.path
.isfile(File
.Path
):
292 EdkLogger
.error("Unicode File Parser", FILE_NOT_FOUND
, ExtraData
=File
.Path
)
295 FileIn
= codecs
.open(File
.Path
, mode
='rb', encoding
='utf-16').readlines()
296 except UnicodeError, X
:
297 EdkLogger
.error("build", FILE_READ_FAILURE
, "File read failure: %s" % str(X
), ExtraData
=File
.Path
);
299 EdkLogger
.error("build", FILE_OPEN_FAILURE
, ExtraData
=File
.Path
);
303 # Use unique identifier
308 Line
= FileIn
[LineCount
]
312 # Ignore comment line and empty line
314 if Line
== u
'' or Line
.startswith(u
'//'):
318 # Process comment embeded in string define lines
320 FindFlag
= Line
.find(u
'//')
322 Line
= Line
.replace(Line
[FindFlag
:], u
' ')
323 if FileIn
[LineCount
].strip().startswith('#language'):
324 Line
= Line
+ FileIn
[LineCount
]
325 FileIn
[LineCount
-1] = Line
326 FileIn
[LineCount
] = os
.linesep
328 for Index
in xrange (LineCount
+ 1, len (FileIn
) - 1):
329 if (Index
== len(FileIn
) -1):
330 FileIn
[Index
] = os
.linesep
332 FileIn
[Index
] = FileIn
[Index
+ 1]
335 Line
= Line
.replace(u
'/langdef', u
'#langdef')
336 Line
= Line
.replace(u
'/string', u
'#string')
337 Line
= Line
.replace(u
'/language', u
'#language')
338 Line
= Line
.replace(u
'/include', u
'#include')
340 Line
= Line
.replace(u
'\\\\', u
'\u0006')
341 Line
= Line
.replace(UNICODE_WIDE_CHAR
, WIDE_CHAR
)
342 Line
= Line
.replace(UNICODE_NARROW_CHAR
, NARROW_CHAR
)
343 Line
= Line
.replace(UNICODE_NON_BREAKING_CHAR
, NON_BREAKING_CHAR
)
345 Line
= Line
.replace(u
'\\r\\n', CR
+ LF
)
346 Line
= Line
.replace(u
'\\n', CR
+ LF
)
347 Line
= Line
.replace(u
'\\r', CR
)
348 Line
= Line
.replace(u
'\\t', u
'\t')
349 Line
= Line
.replace(u
'''\"''', u
'''"''')
350 Line
= Line
.replace(u
'\t', u
' ')
351 Line
= Line
.replace(u
'\u0006', u
'\\')
352 Line
= Line
.replace(DOBULE_QUOTED_SPLASH
, u
'"')
353 Line
= Line
.replace(SIGLE_QUOTED_SPLASH
, u
"'")
354 Line
= Line
.replace(TAB_BACK_SLASH
, u
"/")
356 # if Line.find(u'\\x'):
357 # hex = Line[Line.find(u'\\x') + 2 : Line.find(u'\\x') + 6]
358 # hex = "u'\\u" + hex + "'"
360 IncList
= gIncludePattern
.findall(Line
)
361 if len(IncList
) == 1:
362 for Dir
in [File
.Dir
] + self
.IncludePathList
:
363 IncFile
= PathClass(str(IncList
[0]), Dir
)
364 if os
.path
.isfile(IncFile
.Path
):
365 Lines
.extend(self
.PreProcess(IncFile
))
368 EdkLogger
.error("Unicode File Parser", FILE_NOT_FOUND
, Message
="Cannot find include file", ExtraData
=str(IncList
[0]))
378 def LoadUniFile(self
, File
= None):
380 EdkLogger
.error("Unicode File Parser", PARSER_ERROR
, 'No unicode file is given')
383 # Process special char in file
385 Lines
= self
.PreProcess(File
)
388 # Get Unicode Information
390 for IndexI
in range(len(Lines
)):
392 if (IndexI
+ 1) < len(Lines
):
393 SecondLine
= Lines
[IndexI
+ 1]
394 if (IndexI
+ 2) < len(Lines
):
395 ThirdLine
= Lines
[IndexI
+ 2]
398 # Get Language def information
400 if Line
.find(u
'#langdef ') >= 0:
401 self
.GetLangDef(File
, Line
)
408 # Get string def information format 1 as below
410 # #string MY_STRING_1
412 # My first English string line 1
413 # My first English string line 2
414 # #string MY_STRING_1
416 # Mi segunda secuencia 1
417 # Mi segunda secuencia 2
419 if Line
.find(u
'#string ') >= 0 and Line
.find(u
'#language ') < 0 and \
420 SecondLine
.find(u
'#string ') < 0 and SecondLine
.find(u
'#language ') >= 0 and \
421 ThirdLine
.find(u
'#string ') < 0 and ThirdLine
.find(u
'#language ') < 0:
422 Name
= Line
[Line
.find(u
'#string ') + len(u
'#string ') : ].strip(' ')
423 Language
= SecondLine
[SecondLine
.find(u
'#language ') + len(u
'#language ') : ].strip(' ')
424 for IndexJ
in range(IndexI
+ 2, len(Lines
)):
425 if Lines
[IndexJ
].find(u
'#string ') < 0 and Lines
[IndexJ
].find(u
'#language ') < 0:
426 Value
= Value
+ Lines
[IndexJ
]
430 # Value = Value.replace(u'\r\n', u'')
431 Language
= GetLanguageCode(Language
, self
.IsCompatibleMode
, self
.File
)
432 # Check the string name is the upper character
433 if not self
.IsCompatibleMode
and Name
!= '':
434 MatchString
= re
.match('[A-Z0-9_]+', Name
, re
.UNICODE
)
435 if MatchString
== None or MatchString
.end(0) != len(Name
):
436 EdkLogger
.error('Unicode File Parser', FORMAT_INVALID
, 'The string token name %s defined in UNI file %s contains the invalid lower case character.' %(Name
, self
.File
))
437 self
.AddStringToList(Name
, Language
, Value
)
441 # Get string def information format 2 as below
443 # #string MY_STRING_1 #language eng "My first English string line 1"
444 # "My first English string line 2"
445 # #language spa "Mi segunda secuencia 1"
446 # "Mi segunda secuencia 2"
447 # #string MY_STRING_2 #language eng "My first English string line 1"
448 # "My first English string line 2"
449 # #string MY_STRING_2 #language spa "Mi segunda secuencia 1"
450 # "Mi segunda secuencia 2"
452 if Line
.find(u
'#string ') >= 0 and Line
.find(u
'#language ') >= 0:
454 for IndexJ
in range(IndexI
+ 1, len(Lines
)):
455 if Lines
[IndexJ
].find(u
'#string ') >= 0 and Lines
[IndexJ
].find(u
'#language ') >= 0:
458 elif Lines
[IndexJ
].find(u
'#string ') < 0 and Lines
[IndexJ
].find(u
'#language ') >= 0:
459 StringItem
= StringItem
+ Lines
[IndexJ
]
460 elif Lines
[IndexJ
].count(u
'\"') >= 2:
461 StringItem
= StringItem
[ : StringItem
.rfind(u
'\"')] + Lines
[IndexJ
][Lines
[IndexJ
].find(u
'\"') + len(u
'\"') : ]
462 self
.GetStringObject(StringItem
)
466 # Load multiple .uni files
468 def LoadUniFiles(self
, FileList
):
469 if len(FileList
) > 0:
470 for File
in FileList
:
471 self
.LoadUniFile(File
)
474 # Add a string to list
476 def AddStringToList(self
, Name
, Language
, Value
, Token
= None, Referenced
= False, UseOtherLangDef
= '', Index
= -1):
477 for LangNameItem
in self
.LanguageDef
:
478 if Language
== LangNameItem
[0]:
481 EdkLogger
.error('Unicode File Parser', FORMAT_NOT_SUPPORTED
, "The language '%s' for %s is not defined in Unicode file %s." \
482 % (Language
, Name
, self
.File
))
484 if Language
not in self
.OrderedStringList
:
485 self
.OrderedStringList
[Language
] = []
486 self
.OrderedStringDict
[Language
] = {}
489 if Name
in self
.OrderedStringDict
[Language
]:
492 ItemIndexInList
= self
.OrderedStringDict
[Language
][Name
]
493 Item
= self
.OrderedStringList
[Language
][ItemIndexInList
]
494 Item
.UpdateValue(Value
)
495 Item
.UseOtherLangDef
= ''
498 Token
= len(self
.OrderedStringList
[Language
])
500 self
.OrderedStringList
[Language
].append(StringDefClassObject(Name
, Value
, Referenced
, Token
, UseOtherLangDef
))
501 self
.OrderedStringDict
[Language
][Name
] = Token
502 for LangName
in self
.LanguageDef
:
504 # New STRING token will be added into all language string lists.
505 # so that the unique STRING identifier is reserved for all languages in the package list.
507 if LangName
[0] != Language
:
508 if UseOtherLangDef
!= '':
509 OtherLangDef
= UseOtherLangDef
511 OtherLangDef
= Language
512 self
.OrderedStringList
[LangName
[0]].append(StringDefClassObject(Name
, '', Referenced
, Token
, OtherLangDef
))
513 self
.OrderedStringDict
[LangName
[0]][Name
] = len(self
.OrderedStringList
[LangName
[0]]) - 1
515 self
.OrderedStringList
[Language
].insert(Index
, StringDefClassObject(Name
, Value
, Referenced
, Token
, UseOtherLangDef
))
516 self
.OrderedStringDict
[Language
][Name
] = Index
519 # Set the string as referenced
521 def SetStringReferenced(self
, Name
):
523 # String stoken are added in the same order in all language string lists.
524 # So, only update the status of string stoken in first language string list.
526 Lang
= self
.LanguageDef
[0][0]
527 if Name
in self
.OrderedStringDict
[Lang
]:
528 ItemIndexInList
= self
.OrderedStringDict
[Lang
][Name
]
529 Item
= self
.OrderedStringList
[Lang
][ItemIndexInList
]
530 Item
.Referenced
= True
533 # Search the string in language definition by Name
535 def FindStringValue(self
, Name
, Lang
):
536 if Name
in self
.OrderedStringDict
[Lang
]:
537 ItemIndexInList
= self
.OrderedStringDict
[Lang
][Name
]
538 return self
.OrderedStringList
[Lang
][ItemIndexInList
]
543 # Search the string in language definition by Token
545 def FindByToken(self
, Token
, Lang
):
546 for Item
in self
.OrderedStringList
[Lang
]:
547 if Item
.Token
== Token
:
553 # Re-order strings and re-generate tokens
557 # Retoken all language strings according to the status of string stoken in the first language string.
559 FirstLangName
= self
.LanguageDef
[0][0]
561 # Convert the OrderedStringList to be OrderedStringListByToken in order to faciliate future search by token
562 for LangNameItem
in self
.LanguageDef
:
563 self
.OrderedStringListByToken
[LangNameItem
[0]] = {}
566 # Use small token for all referred string stoken.
569 for Index
in range (0, len (self
.OrderedStringList
[FirstLangName
])):
570 FirstLangItem
= self
.OrderedStringList
[FirstLangName
][Index
]
571 if FirstLangItem
.Referenced
== True:
572 for LangNameItem
in self
.LanguageDef
:
573 LangName
= LangNameItem
[0]
574 OtherLangItem
= self
.OrderedStringList
[LangName
][Index
]
575 OtherLangItem
.Referenced
= True
576 OtherLangItem
.Token
= RefToken
577 self
.OrderedStringListByToken
[LangName
][OtherLangItem
.Token
] = OtherLangItem
578 RefToken
= RefToken
+ 1
581 # Use big token for all unreferred string stoken.
584 for Index
in range (0, len (self
.OrderedStringList
[FirstLangName
])):
585 FirstLangItem
= self
.OrderedStringList
[FirstLangName
][Index
]
586 if FirstLangItem
.Referenced
== False:
587 for LangNameItem
in self
.LanguageDef
:
588 LangName
= LangNameItem
[0]
589 OtherLangItem
= self
.OrderedStringList
[LangName
][Index
]
590 OtherLangItem
.Token
= RefToken
+ UnRefToken
591 self
.OrderedStringListByToken
[LangName
][OtherLangItem
.Token
] = OtherLangItem
592 UnRefToken
= UnRefToken
+ 1
595 # Show the instance itself
598 print self
.LanguageDef
599 #print self.OrderedStringList
600 for Item
in self
.OrderedStringList
:
602 for Member
in self
.OrderedStringList
[Item
]:
605 # This acts like the main() function for the script, unless it is 'import'ed into another
607 if __name__
== '__main__':
608 EdkLogger
.Initialize()
609 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
610 a
= UniFileClassObject([PathClass("C:\\Edk\\Strings.uni"), PathClass("C:\\Edk\\Strings2.uni")])