]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Implementation for EFI_HII_STRING_PROTOCOL.\r | |
3 | \r | |
4 | \r | |
5 | Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | \r | |
17 | #include "HiiDatabase.h"\r | |
18 | \r | |
19 | CHAR16 mLanguageWindow[16] = {\r | |
20 | 0x0000, 0x0080, 0x0100, 0x0300,\r | |
21 | 0x2000, 0x2080, 0x2100, 0x3000,\r | |
22 | 0x0080, 0x00C0, 0x0400, 0x0600,\r | |
23 | 0x0900, 0x3040, 0x30A0, 0xFF00\r | |
24 | };\r | |
25 | \r | |
26 | \r | |
27 | /**\r | |
28 | This function checks whether a global font info is referred by local\r | |
29 | font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create\r | |
30 | a HII_FONT_INFO to refer it locally.\r | |
31 | \r | |
32 | This is a internal function.\r | |
33 | \r | |
34 | \r | |
35 | @param Private Hii database private structure.\r | |
36 | @param StringPackage HII string package instance.\r | |
37 | @param FontId Font identifer, which must be unique within the string package.\r | |
38 | @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to\r | |
39 | the same EFI_FONT_INFO is permitted. Otherwise it\r | |
40 | is not allowed.\r | |
41 | @param GlobalFontInfo Input a global font info which specify a\r | |
42 | EFI_FONT_INFO.\r | |
43 | @param LocalFontInfo Output a local font info which refers to a\r | |
44 | EFI_FONT_INFO.\r | |
45 | \r | |
46 | @retval TRUE Already referred before calling this function.\r | |
47 | @retval FALSE Not referred before calling this function.\r | |
48 | \r | |
49 | **/\r | |
50 | BOOLEAN\r | |
51 | ReferFontInfoLocally (\r | |
52 | IN HII_DATABASE_PRIVATE_DATA *Private,\r | |
53 | IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r | |
54 | IN UINT8 FontId,\r | |
55 | IN BOOLEAN DuplicateEnable,\r | |
56 | IN HII_GLOBAL_FONT_INFO *GlobalFontInfo,\r | |
57 | OUT HII_FONT_INFO **LocalFontInfo\r | |
58 | )\r | |
59 | {\r | |
60 | HII_FONT_INFO *LocalFont;\r | |
61 | LIST_ENTRY *Link;\r | |
62 | \r | |
63 | ASSERT (Private != NULL && StringPackage != NULL && GlobalFontInfo != NULL && LocalFontInfo != NULL);\r | |
64 | \r | |
65 | if (!DuplicateEnable) {\r | |
66 | for (Link = StringPackage->FontInfoList.ForwardLink;\r | |
67 | Link != &StringPackage->FontInfoList;\r | |
68 | Link = Link->ForwardLink\r | |
69 | ) {\r | |
70 | LocalFont = CR (Link, HII_FONT_INFO, Entry, HII_FONT_INFO_SIGNATURE);\r | |
71 | if (LocalFont->GlobalEntry == &GlobalFontInfo->Entry) {\r | |
72 | //\r | |
73 | // Already referred by local font info list, return directly.\r | |
74 | //\r | |
75 | *LocalFontInfo = LocalFont;\r | |
76 | return TRUE;\r | |
77 | }\r | |
78 | }\r | |
79 | }\r | |
80 | // FontId identifies EFI_FONT_INFO in local string package uniquely.\r | |
81 | // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies\r | |
82 | // EFI_FONT_INFO uniquely in whole hii database.\r | |
83 | //\r | |
84 | LocalFont = (HII_FONT_INFO *) AllocateZeroPool (sizeof (HII_FONT_INFO));\r | |
85 | ASSERT (LocalFont != NULL);\r | |
86 | \r | |
87 | LocalFont->Signature = HII_FONT_INFO_SIGNATURE;\r | |
88 | LocalFont->FontId = FontId;\r | |
89 | LocalFont->GlobalEntry = &GlobalFontInfo->Entry;\r | |
90 | InsertTailList (&StringPackage->FontInfoList, &LocalFont->Entry);\r | |
91 | \r | |
92 | *LocalFontInfo = LocalFont;\r | |
93 | return FALSE;\r | |
94 | }\r | |
95 | \r | |
96 | \r | |
97 | /**\r | |
98 | Convert Ascii string text to unicode string test.\r | |
99 | \r | |
100 | This is a internal function.\r | |
101 | \r | |
102 | \r | |
103 | @param StringDest Buffer to store the string text. If it is NULL,\r | |
104 | only the size will be returned.\r | |
105 | @param StringSrc Points to current null-terminated string.\r | |
106 | @param BufferSize Length of the buffer.\r | |
107 | \r | |
108 | @retval EFI_SUCCESS The string text was outputed successfully.\r | |
109 | @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string\r | |
110 | text. BufferSize is updated to the required buffer\r | |
111 | size.\r | |
112 | \r | |
113 | **/\r | |
114 | EFI_STATUS\r | |
115 | ConvertToUnicodeText (\r | |
116 | OUT EFI_STRING StringDest,\r | |
117 | IN CHAR8 *StringSrc,\r | |
118 | IN OUT UINTN *BufferSize\r | |
119 | )\r | |
120 | {\r | |
121 | UINTN StringSize;\r | |
122 | UINTN Index;\r | |
123 | \r | |
124 | ASSERT (StringSrc != NULL && BufferSize != NULL);\r | |
125 | \r | |
126 | StringSize = AsciiStrSize (StringSrc) * 2;\r | |
127 | if (*BufferSize < StringSize || StringDest == NULL) {\r | |
128 | *BufferSize = StringSize;\r | |
129 | return EFI_BUFFER_TOO_SMALL;\r | |
130 | }\r | |
131 | \r | |
132 | for (Index = 0; Index < AsciiStrLen (StringSrc); Index++) {\r | |
133 | StringDest[Index] = (CHAR16) StringSrc[Index];\r | |
134 | }\r | |
135 | \r | |
136 | StringDest[Index] = 0;\r | |
137 | return EFI_SUCCESS;\r | |
138 | }\r | |
139 | \r | |
140 | \r | |
141 | /**\r | |
142 | Calculate the size of StringSrc and output it. If StringDest is not NULL,\r | |
143 | copy string text from src to dest.\r | |
144 | \r | |
145 | This is a internal function.\r | |
146 | \r | |
147 | @param StringDest Buffer to store the string text. If it is NULL,\r | |
148 | only the size will be returned.\r | |
149 | @param StringSrc Points to current null-terminated string.\r | |
150 | @param BufferSize Length of the buffer.\r | |
151 | \r | |
152 | @retval EFI_SUCCESS The string text was outputed successfully.\r | |
153 | @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string\r | |
154 | text. BufferSize is updated to the required buffer\r | |
155 | size.\r | |
156 | \r | |
157 | **/\r | |
158 | EFI_STATUS\r | |
159 | GetUnicodeStringTextOrSize (\r | |
160 | OUT EFI_STRING StringDest, OPTIONAL\r | |
161 | IN UINT8 *StringSrc,\r | |
162 | IN OUT UINTN *BufferSize\r | |
163 | )\r | |
164 | {\r | |
165 | UINTN StringSize;\r | |
166 | UINT8 *StringPtr;\r | |
167 | \r | |
168 | ASSERT (StringSrc != NULL && BufferSize != NULL);\r | |
169 | \r | |
170 | StringSize = sizeof (CHAR16);\r | |
171 | StringPtr = StringSrc;\r | |
172 | while (ReadUnaligned16 ((UINT16 *) StringPtr) != 0) {\r | |
173 | StringSize += sizeof (CHAR16);\r | |
174 | StringPtr += sizeof (CHAR16);\r | |
175 | }\r | |
176 | \r | |
177 | if (*BufferSize < StringSize) {\r | |
178 | *BufferSize = StringSize;\r | |
179 | return EFI_BUFFER_TOO_SMALL;\r | |
180 | }\r | |
181 | if (StringDest != NULL) {\r | |
182 | CopyMem (StringDest, StringSrc, StringSize);\r | |
183 | }\r | |
184 | \r | |
185 | *BufferSize = StringSize;\r | |
186 | return EFI_SUCCESS;\r | |
187 | }\r | |
188 | \r | |
189 | \r | |
190 | /**\r | |
191 | Copy string font info to a buffer.\r | |
192 | \r | |
193 | This is a internal function.\r | |
194 | \r | |
195 | @param StringPackage Hii string package instance.\r | |
196 | @param FontId Font identifier which is unique in a string\r | |
197 | package.\r | |
198 | @param StringFontInfo Buffer to record the output font info. It's\r | |
199 | caller's responsibility to free this buffer.\r | |
200 | \r | |
201 | @retval EFI_SUCCESS The string font is outputed successfully.\r | |
202 | @retval EFI_NOT_FOUND The specified font id does not exist.\r | |
203 | \r | |
204 | **/\r | |
205 | EFI_STATUS\r | |
206 | GetStringFontInfo (\r | |
207 | IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r | |
208 | IN UINT8 FontId,\r | |
209 | OUT EFI_FONT_INFO **StringFontInfo\r | |
210 | )\r | |
211 | {\r | |
212 | LIST_ENTRY *Link;\r | |
213 | HII_FONT_INFO *FontInfo;\r | |
214 | HII_GLOBAL_FONT_INFO *GlobalFont;\r | |
215 | \r | |
216 | ASSERT (StringFontInfo != NULL && StringPackage != NULL);\r | |
217 | \r | |
218 | for (Link = StringPackage->FontInfoList.ForwardLink; Link != &StringPackage->FontInfoList; Link = Link->ForwardLink) {\r | |
219 | FontInfo = CR (Link, HII_FONT_INFO, Entry, HII_FONT_INFO_SIGNATURE);\r | |
220 | if (FontInfo->FontId == FontId) {\r | |
221 | GlobalFont = CR (FontInfo->GlobalEntry, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);\r | |
222 | *StringFontInfo = (EFI_FONT_INFO *) AllocateZeroPool (GlobalFont->FontInfoSize);\r | |
223 | if (*StringFontInfo == NULL) {\r | |
224 | return EFI_OUT_OF_RESOURCES;\r | |
225 | }\r | |
226 | CopyMem (*StringFontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);\r | |
227 | return EFI_SUCCESS;\r | |
228 | }\r | |
229 | }\r | |
230 | \r | |
231 | return EFI_NOT_FOUND;\r | |
232 | }\r | |
233 | \r | |
234 | \r | |
235 | /**\r | |
236 | Parse all string blocks to find a String block specified by StringId.\r | |
237 | If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks\r | |
238 | within this string package and backup its information. If LastStringId is \r | |
239 | specified, the string id of last string block will also be output.\r | |
240 | If StringId = 0, output the string id of last string block (EFI_HII_SIBT_STRING).\r | |
241 | \r | |
242 | @param Private Hii database private structure.\r | |
243 | @param StringPackage Hii string package instance.\r | |
244 | @param StringId The string's id, which is unique within\r | |
245 | PackageList.\r | |
246 | @param BlockType Output the block type of found string block.\r | |
247 | @param StringBlockAddr Output the block address of found string block.\r | |
248 | @param StringTextOffset Offset, relative to the found block address, of\r | |
249 | the string text information.\r | |
250 | @param LastStringId Output the last string id when StringId = 0 or StringId = -1.\r | |
251 | @param StartStringId The first id in the skip block which StringId in the block.\r | |
252 | \r | |
253 | @retval EFI_SUCCESS The string text and font is retrieved\r | |
254 | successfully.\r | |
255 | @retval EFI_NOT_FOUND The specified text or font info can not be found\r | |
256 | out.\r | |
257 | @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the\r | |
258 | task.\r | |
259 | \r | |
260 | **/\r | |
261 | EFI_STATUS\r | |
262 | FindStringBlock (\r | |
263 | IN HII_DATABASE_PRIVATE_DATA *Private,\r | |
264 | IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r | |
265 | IN EFI_STRING_ID StringId,\r | |
266 | OUT UINT8 *BlockType, OPTIONAL\r | |
267 | OUT UINT8 **StringBlockAddr, OPTIONAL\r | |
268 | OUT UINTN *StringTextOffset, OPTIONAL\r | |
269 | OUT EFI_STRING_ID *LastStringId, OPTIONAL\r | |
270 | OUT EFI_STRING_ID *StartStringId OPTIONAL\r | |
271 | )\r | |
272 | {\r | |
273 | UINT8 *BlockHdr;\r | |
274 | EFI_STRING_ID CurrentStringId;\r | |
275 | UINTN BlockSize;\r | |
276 | UINTN Index;\r | |
277 | UINT8 *StringTextPtr;\r | |
278 | UINTN Offset;\r | |
279 | HII_FONT_INFO *LocalFont;\r | |
280 | EFI_FONT_INFO *FontInfo;\r | |
281 | HII_GLOBAL_FONT_INFO *GlobalFont;\r | |
282 | UINTN FontInfoSize;\r | |
283 | UINT16 StringCount;\r | |
284 | UINT16 SkipCount;\r | |
285 | EFI_HII_FONT_STYLE FontStyle;\r | |
286 | UINT16 FontSize;\r | |
287 | UINT8 Length8;\r | |
288 | EFI_HII_SIBT_EXT2_BLOCK Ext2;\r | |
289 | UINT8 FontId;\r | |
290 | UINT32 Length32;\r | |
291 | UINTN StringSize;\r | |
292 | CHAR16 Zero;\r | |
293 | \r | |
294 | ASSERT (StringPackage != NULL);\r | |
295 | ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE);\r | |
296 | \r | |
297 | CurrentStringId = 1;\r | |
298 | \r | |
299 | if (StringId != (EFI_STRING_ID) (-1) && StringId != 0) {\r | |
300 | ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r | |
301 | if (StringId > StringPackage->MaxStringId) {\r | |
302 | return EFI_NOT_FOUND;\r | |
303 | }\r | |
304 | } else {\r | |
305 | ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r | |
306 | if (StringId == 0 && LastStringId != NULL) {\r | |
307 | *LastStringId = StringPackage->MaxStringId;\r | |
308 | return EFI_SUCCESS;\r | |
309 | }\r | |
310 | }\r | |
311 | \r | |
312 | ZeroMem (&Zero, sizeof (CHAR16));\r | |
313 | \r | |
314 | //\r | |
315 | // Parse the string blocks to get the string text and font.\r | |
316 | //\r | |
317 | BlockHdr = StringPackage->StringBlock;\r | |
318 | BlockSize = 0;\r | |
319 | Offset = 0;\r | |
320 | while (*BlockHdr != EFI_HII_SIBT_END) {\r | |
321 | switch (*BlockHdr) {\r | |
322 | case EFI_HII_SIBT_STRING_SCSU:\r | |
323 | Offset = sizeof (EFI_HII_STRING_BLOCK);\r | |
324 | StringTextPtr = BlockHdr + Offset;\r | |
325 | BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
326 | CurrentStringId++;\r | |
327 | break;\r | |
328 | \r | |
329 | case EFI_HII_SIBT_STRING_SCSU_FONT:\r | |
330 | Offset = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);\r | |
331 | StringTextPtr = BlockHdr + Offset;\r | |
332 | BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
333 | CurrentStringId++;\r | |
334 | break;\r | |
335 | \r | |
336 | case EFI_HII_SIBT_STRINGS_SCSU:\r | |
337 | CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));\r | |
338 | StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8);\r | |
339 | BlockSize += StringTextPtr - BlockHdr;\r | |
340 | \r | |
341 | for (Index = 0; Index < StringCount; Index++) {\r | |
342 | BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
343 | if (CurrentStringId == StringId) {\r | |
344 | ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r | |
345 | *BlockType = *BlockHdr;\r | |
346 | *StringBlockAddr = BlockHdr;\r | |
347 | *StringTextOffset = StringTextPtr - BlockHdr;\r | |
348 | return EFI_SUCCESS;\r | |
349 | }\r | |
350 | StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
351 | CurrentStringId++;\r | |
352 | }\r | |
353 | break;\r | |
354 | \r | |
355 | case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r | |
356 | CopyMem (\r | |
357 | &StringCount,\r | |
358 | BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r | |
359 | sizeof (UINT16)\r | |
360 | );\r | |
361 | StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8);\r | |
362 | BlockSize += StringTextPtr - BlockHdr;\r | |
363 | \r | |
364 | for (Index = 0; Index < StringCount; Index++) {\r | |
365 | BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
366 | if (CurrentStringId == StringId) {\r | |
367 | ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r | |
368 | *BlockType = *BlockHdr;\r | |
369 | *StringBlockAddr = BlockHdr;\r | |
370 | *StringTextOffset = StringTextPtr - BlockHdr;\r | |
371 | return EFI_SUCCESS;\r | |
372 | }\r | |
373 | StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
374 | CurrentStringId++;\r | |
375 | }\r | |
376 | break;\r | |
377 | \r | |
378 | case EFI_HII_SIBT_STRING_UCS2:\r | |
379 | Offset = sizeof (EFI_HII_STRING_BLOCK);\r | |
380 | StringTextPtr = BlockHdr + Offset;\r | |
381 | //\r | |
382 | // Use StringSize to store the size of the specified string, including the NULL\r | |
383 | // terminator.\r | |
384 | //\r | |
385 | GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r | |
386 | BlockSize += Offset + StringSize;\r | |
387 | CurrentStringId++;\r | |
388 | break;\r | |
389 | \r | |
390 | case EFI_HII_SIBT_STRING_UCS2_FONT:\r | |
391 | Offset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r | |
392 | StringTextPtr = BlockHdr + Offset;\r | |
393 | //\r | |
394 | // Use StrSize to store the size of the specified string, including the NULL\r | |
395 | // terminator.\r | |
396 | //\r | |
397 | GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r | |
398 | BlockSize += Offset + StringSize;\r | |
399 | CurrentStringId++;\r | |
400 | break;\r | |
401 | \r | |
402 | case EFI_HII_SIBT_STRINGS_UCS2:\r | |
403 | Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);\r | |
404 | StringTextPtr = BlockHdr + Offset;\r | |
405 | BlockSize += Offset;\r | |
406 | CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));\r | |
407 | for (Index = 0; Index < StringCount; Index++) {\r | |
408 | GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r | |
409 | BlockSize += StringSize;\r | |
410 | if (CurrentStringId == StringId) {\r | |
411 | ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r | |
412 | *BlockType = *BlockHdr;\r | |
413 | *StringBlockAddr = BlockHdr;\r | |
414 | *StringTextOffset = StringTextPtr - BlockHdr;\r | |
415 | return EFI_SUCCESS;\r | |
416 | }\r | |
417 | StringTextPtr = StringTextPtr + StringSize;\r | |
418 | CurrentStringId++;\r | |
419 | }\r | |
420 | break;\r | |
421 | \r | |
422 | case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r | |
423 | Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r | |
424 | StringTextPtr = BlockHdr + Offset;\r | |
425 | BlockSize += Offset;\r | |
426 | CopyMem (\r | |
427 | &StringCount,\r | |
428 | BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r | |
429 | sizeof (UINT16)\r | |
430 | );\r | |
431 | for (Index = 0; Index < StringCount; Index++) {\r | |
432 | GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r | |
433 | BlockSize += StringSize;\r | |
434 | if (CurrentStringId == StringId) {\r | |
435 | ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r | |
436 | *BlockType = *BlockHdr;\r | |
437 | *StringBlockAddr = BlockHdr;\r | |
438 | *StringTextOffset = StringTextPtr - BlockHdr;\r | |
439 | return EFI_SUCCESS;\r | |
440 | }\r | |
441 | StringTextPtr = StringTextPtr + StringSize;\r | |
442 | CurrentStringId++;\r | |
443 | }\r | |
444 | break;\r | |
445 | \r | |
446 | case EFI_HII_SIBT_DUPLICATE:\r | |
447 | if (CurrentStringId == StringId) {\r | |
448 | //\r | |
449 | // Incoming StringId is an id of a duplicate string block.\r | |
450 | // Update the StringId to be the previous string block.\r | |
451 | // Go back to the header of string block to search.\r | |
452 | //\r | |
453 | CopyMem (\r | |
454 | &StringId,\r | |
455 | BlockHdr + sizeof (EFI_HII_STRING_BLOCK),\r | |
456 | sizeof (EFI_STRING_ID)\r | |
457 | );\r | |
458 | ASSERT (StringId != CurrentStringId);\r | |
459 | CurrentStringId = 1;\r | |
460 | BlockSize = 0;\r | |
461 | } else {\r | |
462 | BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);\r | |
463 | CurrentStringId++;\r | |
464 | }\r | |
465 | break;\r | |
466 | \r | |
467 | case EFI_HII_SIBT_SKIP1:\r | |
468 | SkipCount = (UINT16) (*(BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));\r | |
469 | CurrentStringId = (UINT16) (CurrentStringId + SkipCount);\r | |
470 | BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK);\r | |
471 | break;\r | |
472 | \r | |
473 | case EFI_HII_SIBT_SKIP2:\r | |
474 | CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));\r | |
475 | CurrentStringId = (UINT16) (CurrentStringId + SkipCount);\r | |
476 | BlockSize += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);\r | |
477 | break;\r | |
478 | \r | |
479 | case EFI_HII_SIBT_EXT1:\r | |
480 | CopyMem (\r | |
481 | &Length8,\r | |
482 | BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r | |
483 | sizeof (UINT8)\r | |
484 | );\r | |
485 | BlockSize += Length8;\r | |
486 | break;\r | |
487 | \r | |
488 | case EFI_HII_SIBT_EXT2:\r | |
489 | CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));\r | |
490 | if (Ext2.BlockType2 == EFI_HII_SIBT_FONT && StringId == (EFI_STRING_ID) (-1)) {\r | |
491 | //\r | |
492 | // Find the relationship between global font info and the font info of\r | |
493 | // this EFI_HII_SIBT_FONT block then backup its information in local package.\r | |
494 | //\r | |
495 | BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r | |
496 | CopyMem (&FontId, BlockHdr, sizeof (UINT8));\r | |
497 | BlockHdr += sizeof (UINT8);\r | |
498 | CopyMem (&FontSize, BlockHdr, sizeof (UINT16));\r | |
499 | BlockHdr += sizeof (UINT16);\r | |
500 | CopyMem (&FontStyle, BlockHdr, sizeof (EFI_HII_FONT_STYLE));\r | |
501 | BlockHdr += sizeof (EFI_HII_FONT_STYLE);\r | |
502 | GetUnicodeStringTextOrSize (NULL, BlockHdr, &StringSize);\r | |
503 | \r | |
504 | FontInfoSize = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + StringSize;\r | |
505 | FontInfo = (EFI_FONT_INFO *) AllocateZeroPool (FontInfoSize);\r | |
506 | if (FontInfo == NULL) {\r | |
507 | return EFI_OUT_OF_RESOURCES;\r | |
508 | }\r | |
509 | FontInfo->FontStyle = FontStyle;\r | |
510 | FontInfo->FontSize = FontSize;\r | |
511 | CopyMem (FontInfo->FontName, BlockHdr, StringSize);\r | |
512 | \r | |
513 | //\r | |
514 | // If find the corresponding global font info, save the relationship.\r | |
515 | // Otherwise ignore this EFI_HII_SIBT_FONT block.\r | |
516 | //\r | |
517 | if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont)) {\r | |
518 | ReferFontInfoLocally (Private, StringPackage, FontId, TRUE, GlobalFont, &LocalFont);\r | |
519 | }\r | |
520 | \r | |
521 | //\r | |
522 | // Since string package tool set FontId initially to 0 and increases it\r | |
523 | // progressively by one, StringPackage->FondId always represents an unique\r | |
524 | // and available FontId.\r | |
525 | // \r | |
526 | StringPackage->FontId++;\r | |
527 | \r | |
528 | FreePool (FontInfo);\r | |
529 | }\r | |
530 | \r | |
531 | BlockSize += Ext2.Length;\r | |
532 | \r | |
533 | break;\r | |
534 | \r | |
535 | case EFI_HII_SIBT_EXT4:\r | |
536 | CopyMem (\r | |
537 | &Length32,\r | |
538 | BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r | |
539 | sizeof (UINT32)\r | |
540 | );\r | |
541 | \r | |
542 | BlockSize += Length32;\r | |
543 | break;\r | |
544 | \r | |
545 | default:\r | |
546 | break;\r | |
547 | }\r | |
548 | \r | |
549 | if (StringId > 0 && StringId != (EFI_STRING_ID)(-1)) {\r | |
550 | ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r | |
551 | *BlockType = *BlockHdr;\r | |
552 | *StringBlockAddr = BlockHdr;\r | |
553 | *StringTextOffset = Offset;\r | |
554 | \r | |
555 | if (StringId == CurrentStringId - 1) {\r | |
556 | //\r | |
557 | // if only one skip item, return EFI_NOT_FOUND.\r | |
558 | //\r | |
559 | if(*BlockType == EFI_HII_SIBT_SKIP2 || *BlockType == EFI_HII_SIBT_SKIP1) {\r | |
560 | return EFI_NOT_FOUND;\r | |
561 | } else {\r | |
562 | return EFI_SUCCESS;\r | |
563 | }\r | |
564 | }\r | |
565 | \r | |
566 | if (StringId < CurrentStringId - 1) {\r | |
567 | return EFI_NOT_FOUND;\r | |
568 | }\r | |
569 | }\r | |
570 | BlockHdr = StringPackage->StringBlock + BlockSize;\r | |
571 | if (StartStringId != NULL) {\r | |
572 | *StartStringId = CurrentStringId;\r | |
573 | }\r | |
574 | }\r | |
575 | \r | |
576 | //\r | |
577 | // Get last string ID\r | |
578 | //\r | |
579 | if (StringId == (EFI_STRING_ID) (-1) && LastStringId != NULL) {\r | |
580 | *LastStringId = (EFI_STRING_ID) (CurrentStringId - 1);\r | |
581 | return EFI_SUCCESS;\r | |
582 | }\r | |
583 | \r | |
584 | return EFI_NOT_FOUND;\r | |
585 | }\r | |
586 | \r | |
587 | \r | |
588 | /**\r | |
589 | Parse all string blocks to get a string specified by StringId.\r | |
590 | \r | |
591 | This is a internal function.\r | |
592 | \r | |
593 | @param Private Hii database private structure.\r | |
594 | @param StringPackage Hii string package instance.\r | |
595 | @param StringId The string's id, which is unique within\r | |
596 | PackageList.\r | |
597 | @param String Points to retrieved null-terminated string.\r | |
598 | @param StringSize On entry, points to the size of the buffer pointed\r | |
599 | to by String, in bytes. On return, points to the\r | |
600 | length of the string, in bytes.\r | |
601 | @param StringFontInfo If not NULL, allocate a buffer to record the\r | |
602 | output font info. It's caller's responsibility to\r | |
603 | free this buffer.\r | |
604 | \r | |
605 | @retval EFI_SUCCESS The string text and font is retrieved\r | |
606 | successfully.\r | |
607 | @retval EFI_NOT_FOUND The specified text or font info can not be found\r | |
608 | out.\r | |
609 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to\r | |
610 | hold the string.\r | |
611 | \r | |
612 | **/\r | |
613 | EFI_STATUS\r | |
614 | GetStringWorker (\r | |
615 | IN HII_DATABASE_PRIVATE_DATA *Private,\r | |
616 | IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r | |
617 | IN EFI_STRING_ID StringId,\r | |
618 | OUT EFI_STRING String,\r | |
619 | IN OUT UINTN *StringSize, OPTIONAL\r | |
620 | OUT EFI_FONT_INFO **StringFontInfo OPTIONAL\r | |
621 | )\r | |
622 | {\r | |
623 | UINT8 *StringTextPtr;\r | |
624 | UINT8 BlockType;\r | |
625 | UINT8 *StringBlockAddr;\r | |
626 | UINTN StringTextOffset;\r | |
627 | EFI_STATUS Status;\r | |
628 | UINT8 FontId;\r | |
629 | \r | |
630 | ASSERT (StringPackage != NULL);\r | |
631 | ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r | |
632 | \r | |
633 | //\r | |
634 | // Find the specified string block\r | |
635 | //\r | |
636 | Status = FindStringBlock (\r | |
637 | Private,\r | |
638 | StringPackage,\r | |
639 | StringId,\r | |
640 | &BlockType,\r | |
641 | &StringBlockAddr,\r | |
642 | &StringTextOffset,\r | |
643 | NULL,\r | |
644 | NULL\r | |
645 | );\r | |
646 | if (EFI_ERROR (Status)) {\r | |
647 | return Status;\r | |
648 | }\r | |
649 | \r | |
650 | if (StringSize == NULL) {\r | |
651 | //\r | |
652 | // String text buffer is not requested\r | |
653 | //\r | |
654 | return EFI_SUCCESS;\r | |
655 | }\r | |
656 | \r | |
657 | //\r | |
658 | // Get the string text.\r | |
659 | //\r | |
660 | StringTextPtr = StringBlockAddr + StringTextOffset;\r | |
661 | switch (BlockType) {\r | |
662 | case EFI_HII_SIBT_STRING_SCSU:\r | |
663 | case EFI_HII_SIBT_STRING_SCSU_FONT:\r | |
664 | case EFI_HII_SIBT_STRINGS_SCSU:\r | |
665 | case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r | |
666 | Status = ConvertToUnicodeText (String, (CHAR8 *) StringTextPtr, StringSize);\r | |
667 | break;\r | |
668 | case EFI_HII_SIBT_STRING_UCS2:\r | |
669 | case EFI_HII_SIBT_STRING_UCS2_FONT:\r | |
670 | case EFI_HII_SIBT_STRINGS_UCS2:\r | |
671 | case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r | |
672 | Status = GetUnicodeStringTextOrSize (String, StringTextPtr, StringSize);\r | |
673 | break;\r | |
674 | default:\r | |
675 | return EFI_NOT_FOUND;\r | |
676 | }\r | |
677 | if (EFI_ERROR (Status)) {\r | |
678 | return Status;\r | |
679 | }\r | |
680 | \r | |
681 | //\r | |
682 | // Get the string font. The FontId 0 is the default font for those string blocks which \r | |
683 | // do not specify a font identifier. If default font is not specified, return NULL.\r | |
684 | //\r | |
685 | if (StringFontInfo != NULL) {\r | |
686 | switch (BlockType) {\r | |
687 | case EFI_HII_SIBT_STRING_SCSU_FONT:\r | |
688 | case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r | |
689 | case EFI_HII_SIBT_STRING_UCS2_FONT:\r | |
690 | case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r | |
691 | FontId = *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK));\r | |
692 | break;\r | |
693 | default:\r | |
694 | FontId = 0;\r | |
695 | }\r | |
696 | Status = GetStringFontInfo (StringPackage, FontId, StringFontInfo);\r | |
697 | if (Status == EFI_NOT_FOUND) {\r | |
698 | *StringFontInfo = NULL;\r | |
699 | }\r | |
700 | }\r | |
701 | \r | |
702 | return EFI_SUCCESS;\r | |
703 | }\r | |
704 | \r | |
705 | /**\r | |
706 | If GetStringBlock find the StringId's string is not saved in the exist string block,\r | |
707 | this function will create the UCS2 string block to save the string; also split the \r | |
708 | skip block into two or one skip block.\r | |
709 | \r | |
710 | This is a internal function.\r | |
711 | \r | |
712 | @param StringPackage Hii string package instance.\r | |
713 | @param StartStringId The first id in the skip block which StringId in the block.\r | |
714 | @param StringId The string's id, which is unique within\r | |
715 | PackageList. \r | |
716 | @param BlockType Output the block type of found string block. \r | |
717 | @param StringBlockAddr Output the block address of found string block. \r | |
718 | @param FontBlock whether this string block has font info.\r | |
719 | \r | |
720 | @retval EFI_SUCCESS The string font is outputed successfully.\r | |
721 | @retval EFI_OUT_OF_RESOURCES NO resource for the memory to save the new string block.\r | |
722 | \r | |
723 | **/\r | |
724 | EFI_STATUS\r | |
725 | InsertLackStringBlock (\r | |
726 | IN OUT HII_STRING_PACKAGE_INSTANCE *StringPackage,\r | |
727 | IN EFI_STRING_ID StartStringId,\r | |
728 | IN EFI_STRING_ID StringId,\r | |
729 | IN OUT UINT8 *BlockType,\r | |
730 | IN OUT UINT8 **StringBlockAddr,\r | |
731 | IN BOOLEAN FontBlock\r | |
732 | )\r | |
733 | {\r | |
734 | UINT8 *BlockPtr;\r | |
735 | UINT8 *StringBlock;\r | |
736 | UINT32 SkipLen; \r | |
737 | UINT32 OldBlockSize;\r | |
738 | UINT32 NewBlockSize;\r | |
739 | UINT32 FrontSkipNum;\r | |
740 | UINT32 NewUCSBlockLen;\r | |
741 | UINT8 *OldStringAddr;\r | |
742 | UINT32 IdCount;\r | |
743 | \r | |
744 | FrontSkipNum = 0;\r | |
745 | SkipLen = 0;\r | |
746 | OldStringAddr = *StringBlockAddr;\r | |
747 | \r | |
748 | ASSERT (*BlockType == EFI_HII_SIBT_SKIP1 || *BlockType == EFI_HII_SIBT_SKIP2);\r | |
749 | //\r | |
750 | // Old skip block size.\r | |
751 | //\r | |
752 | if (*BlockType == EFI_HII_SIBT_SKIP1) {\r | |
753 | SkipLen = sizeof (EFI_HII_SIBT_SKIP1_BLOCK);\r | |
754 | IdCount = *(UINT8*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));\r | |
755 | } else {\r | |
756 | SkipLen = sizeof (EFI_HII_SIBT_SKIP2_BLOCK);\r | |
757 | IdCount = *(UINT16*)(OldStringAddr + sizeof (EFI_HII_STRING_BLOCK));\r | |
758 | } \r | |
759 | \r | |
760 | //\r | |
761 | // New create UCS or UCS2 block size.\r | |
762 | //\r | |
763 | if (FontBlock) {\r | |
764 | NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK);\r | |
765 | } else {\r | |
766 | NewUCSBlockLen = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);\r | |
767 | }\r | |
768 | \r | |
769 | OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r | |
770 | \r | |
771 | if (StartStringId == StringId) {\r | |
772 | //\r | |
773 | // New block + [Skip block]\r | |
774 | //\r | |
775 | if (IdCount > 1) {\r | |
776 | NewBlockSize = OldBlockSize + NewUCSBlockLen;\r | |
777 | } else {\r | |
778 | NewBlockSize = OldBlockSize + NewUCSBlockLen - SkipLen;\r | |
779 | }\r | |
780 | } else if (StartStringId + IdCount - 1 == StringId){\r | |
781 | //\r | |
782 | // Skip block + New block\r | |
783 | //\r | |
784 | NewBlockSize = OldBlockSize + NewUCSBlockLen;\r | |
785 | FrontSkipNum = StringId - StartStringId;\r | |
786 | } else {\r | |
787 | //\r | |
788 | // Skip block + New block + [Skip block]\r | |
789 | //\r | |
790 | NewBlockSize = OldBlockSize + NewUCSBlockLen + SkipLen;\r | |
791 | FrontSkipNum = StringId - StartStringId;\r | |
792 | }\r | |
793 | \r | |
794 | StringBlock = (UINT8 *) AllocateZeroPool (NewBlockSize);\r | |
795 | if (StringBlock == NULL) {\r | |
796 | return EFI_OUT_OF_RESOURCES;\r | |
797 | }\r | |
798 | \r | |
799 | //\r | |
800 | // Copy old block in front of skip block.\r | |
801 | //\r | |
802 | CopyMem (StringBlock, StringPackage->StringBlock, OldStringAddr - StringPackage->StringBlock); \r | |
803 | BlockPtr = StringBlock + (OldStringAddr - StringPackage->StringBlock);\r | |
804 | \r | |
805 | if (FrontSkipNum > 0) {\r | |
806 | *BlockPtr = *BlockType;\r | |
807 | if (*BlockType == EFI_HII_SIBT_SKIP1) {\r | |
808 | *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) FrontSkipNum;\r | |
809 | } else {\r | |
810 | *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) FrontSkipNum;\r | |
811 | }\r | |
812 | BlockPtr += SkipLen;\r | |
813 | }\r | |
814 | \r | |
815 | //\r | |
816 | // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r | |
817 | //\r | |
818 | *StringBlockAddr = BlockPtr;\r | |
819 | if (FontBlock) {\r | |
820 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r | |
821 | } else {\r | |
822 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r | |
823 | }\r | |
824 | BlockPtr += NewUCSBlockLen;\r | |
825 | \r | |
826 | if (IdCount > FrontSkipNum + 1) {\r | |
827 | *BlockPtr = *BlockType;\r | |
828 | if (*BlockType == EFI_HII_SIBT_SKIP1) {\r | |
829 | *(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT8) (IdCount - FrontSkipNum - 1);\r | |
830 | } else {\r | |
831 | *(UINT16 *)(BlockPtr + sizeof (EFI_HII_STRING_BLOCK)) = (UINT16) (IdCount - FrontSkipNum - 1);\r | |
832 | }\r | |
833 | BlockPtr += SkipLen;\r | |
834 | }\r | |
835 | \r | |
836 | //\r | |
837 | // Append a EFI_HII_SIBT_END block to the end.\r | |
838 | //\r | |
839 | CopyMem (BlockPtr, OldStringAddr + SkipLen, OldBlockSize - (OldStringAddr - StringPackage->StringBlock) - SkipLen); \r | |
840 | \r | |
841 | if (FontBlock) {\r | |
842 | *BlockType = EFI_HII_SIBT_STRING_UCS2_FONT;\r | |
843 | } else {\r | |
844 | *BlockType = EFI_HII_SIBT_STRING_UCS2;\r | |
845 | }\r | |
846 | FreePool (StringPackage->StringBlock);\r | |
847 | StringPackage->StringBlock = StringBlock;\r | |
848 | StringPackage->StringPkgHdr->Header.Length += NewBlockSize - OldBlockSize;\r | |
849 | \r | |
850 | return EFI_SUCCESS;\r | |
851 | }\r | |
852 | \r | |
853 | /**\r | |
854 | Parse all string blocks to set a String specified by StringId.\r | |
855 | \r | |
856 | This is a internal function.\r | |
857 | \r | |
858 | @param Private HII database driver private structure.\r | |
859 | @param StringPackage HII string package instance.\r | |
860 | @param StringId The string's id, which is unique within\r | |
861 | PackageList.\r | |
862 | @param String Points to the new null-terminated string.\r | |
863 | @param StringFontInfo Points to the input font info.\r | |
864 | \r | |
865 | @retval EFI_SUCCESS The string was updated successfully.\r | |
866 | @retval EFI_NOT_FOUND The string specified by StringId is not in the\r | |
867 | database.\r | |
868 | @retval EFI_INVALID_PARAMETER The String or Language was NULL.\r | |
869 | @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in\r | |
870 | current database.\r | |
871 | @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the\r | |
872 | task.\r | |
873 | \r | |
874 | **/\r | |
875 | EFI_STATUS\r | |
876 | SetStringWorker (\r | |
877 | IN HII_DATABASE_PRIVATE_DATA *Private,\r | |
878 | IN OUT HII_STRING_PACKAGE_INSTANCE *StringPackage,\r | |
879 | IN EFI_STRING_ID StringId,\r | |
880 | IN EFI_STRING String,\r | |
881 | IN EFI_FONT_INFO *StringFontInfo OPTIONAL\r | |
882 | )\r | |
883 | {\r | |
884 | UINT8 *StringTextPtr;\r | |
885 | UINT8 BlockType;\r | |
886 | UINT8 *StringBlockAddr;\r | |
887 | UINTN StringTextOffset;\r | |
888 | EFI_STATUS Status;\r | |
889 | UINT8 *Block;\r | |
890 | UINT8 *BlockPtr;\r | |
891 | UINTN BlockSize;\r | |
892 | UINTN OldBlockSize;\r | |
893 | HII_FONT_INFO *LocalFont;\r | |
894 | HII_GLOBAL_FONT_INFO *GlobalFont;\r | |
895 | BOOLEAN Referred;\r | |
896 | EFI_HII_SIBT_EXT2_BLOCK Ext2;\r | |
897 | UINTN StringSize;\r | |
898 | UINTN TmpSize;\r | |
899 | EFI_STRING_ID StartStringId;\r | |
900 | \r | |
901 | StartStringId = 0;\r | |
902 | ASSERT (Private != NULL && StringPackage != NULL && String != NULL);\r | |
903 | ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r | |
904 | //\r | |
905 | // Find the specified string block\r | |
906 | //\r | |
907 | Status = FindStringBlock (\r | |
908 | Private,\r | |
909 | StringPackage,\r | |
910 | StringId,\r | |
911 | &BlockType,\r | |
912 | &StringBlockAddr,\r | |
913 | &StringTextOffset,\r | |
914 | NULL,\r | |
915 | &StartStringId\r | |
916 | );\r | |
917 | if (EFI_ERROR (Status) && (BlockType == EFI_HII_SIBT_SKIP1 || BlockType == EFI_HII_SIBT_SKIP2)) {\r | |
918 | Status = InsertLackStringBlock(StringPackage, \r | |
919 | StartStringId, \r | |
920 | StringId, \r | |
921 | &BlockType,\r | |
922 | &StringBlockAddr,\r | |
923 | (BOOLEAN)(StringFontInfo != NULL)\r | |
924 | );\r | |
925 | if (EFI_ERROR (Status)) {\r | |
926 | return Status;\r | |
927 | }\r | |
928 | if (StringFontInfo != NULL) {\r | |
929 | StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r | |
930 | } else {\r | |
931 | StringTextOffset = sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16);\r | |
932 | }\r | |
933 | }\r | |
934 | \r | |
935 | LocalFont = NULL;\r | |
936 | GlobalFont = NULL;\r | |
937 | Referred = FALSE;\r | |
938 | \r | |
939 | //\r | |
940 | // The input StringFontInfo should exist in current database if specified.\r | |
941 | //\r | |
942 | if (StringFontInfo != NULL) {\r | |
943 | if (!IsFontInfoExisted (Private, StringFontInfo, NULL, NULL, &GlobalFont)) {\r | |
944 | return EFI_INVALID_PARAMETER;\r | |
945 | } else {\r | |
946 | Referred = ReferFontInfoLocally (\r | |
947 | Private, \r | |
948 | StringPackage, \r | |
949 | StringPackage->FontId, \r | |
950 | FALSE, \r | |
951 | GlobalFont, \r | |
952 | &LocalFont\r | |
953 | );\r | |
954 | if (!Referred) {\r | |
955 | StringPackage->FontId++;\r | |
956 | }\r | |
957 | }\r | |
958 | //\r | |
959 | // Update the FontId of the specified string block to input font info.\r | |
960 | //\r | |
961 | switch (BlockType) {\r | |
962 | case EFI_HII_SIBT_STRING_SCSU_FONT: \r | |
963 | case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r | |
964 | case EFI_HII_SIBT_STRING_UCS2_FONT:\r | |
965 | case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r | |
966 | *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK)) = LocalFont->FontId;\r | |
967 | break;\r | |
968 | default:\r | |
969 | //\r | |
970 | // When modify the font info of these blocks, the block type should be updated\r | |
971 | // to contain font info thus the whole structure should be revised.\r | |
972 | // It is recommended to use tool to modify the block type not in the code.\r | |
973 | // \r | |
974 | return EFI_UNSUPPORTED;\r | |
975 | }\r | |
976 | }\r | |
977 | \r | |
978 | OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r | |
979 | \r | |
980 | //\r | |
981 | // Set the string text and font.\r | |
982 | //\r | |
983 | StringTextPtr = StringBlockAddr + StringTextOffset;\r | |
984 | switch (BlockType) {\r | |
985 | case EFI_HII_SIBT_STRING_SCSU:\r | |
986 | case EFI_HII_SIBT_STRING_SCSU_FONT:\r | |
987 | case EFI_HII_SIBT_STRINGS_SCSU:\r | |
988 | case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r | |
989 | BlockSize = OldBlockSize + StrLen (String);\r | |
990 | BlockSize -= AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
991 | Block = AllocateZeroPool (BlockSize);\r | |
992 | if (Block == NULL) {\r | |
993 | return EFI_OUT_OF_RESOURCES;\r | |
994 | }\r | |
995 | \r | |
996 | CopyMem (Block, StringPackage->StringBlock, StringTextPtr - StringPackage->StringBlock);\r | |
997 | BlockPtr = Block + (StringTextPtr - StringPackage->StringBlock);\r | |
998 | \r | |
999 | while (*String != 0) {\r | |
1000 | *BlockPtr++ = (CHAR8) *String++;\r | |
1001 | }\r | |
1002 | *BlockPtr++ = 0;\r | |
1003 | \r | |
1004 | \r | |
1005 | TmpSize = OldBlockSize - (StringTextPtr - StringPackage->StringBlock) - AsciiStrSize ((CHAR8 *) StringTextPtr);\r | |
1006 | CopyMem (\r | |
1007 | BlockPtr,\r | |
1008 | StringTextPtr + AsciiStrSize ((CHAR8 *)StringTextPtr),\r | |
1009 | TmpSize\r | |
1010 | );\r | |
1011 | \r | |
1012 | FreePool (StringPackage->StringBlock);\r | |
1013 | StringPackage->StringBlock = Block;\r | |
1014 | StringPackage->StringPkgHdr->Header.Length += (UINT32) (BlockSize - OldBlockSize);\r | |
1015 | break;\r | |
1016 | \r | |
1017 | case EFI_HII_SIBT_STRING_UCS2:\r | |
1018 | case EFI_HII_SIBT_STRING_UCS2_FONT:\r | |
1019 | case EFI_HII_SIBT_STRINGS_UCS2:\r | |
1020 | case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r | |
1021 | //\r | |
1022 | // Use StrSize to store the size of the specified string, including the NULL\r | |
1023 | // terminator.\r | |
1024 | //\r | |
1025 | GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r | |
1026 | \r | |
1027 | BlockSize = OldBlockSize + StrSize (String) - StringSize;\r | |
1028 | Block = AllocateZeroPool (BlockSize);\r | |
1029 | if (Block == NULL) {\r | |
1030 | return EFI_OUT_OF_RESOURCES;\r | |
1031 | }\r | |
1032 | \r | |
1033 | CopyMem (Block, StringPackage->StringBlock, StringTextPtr - StringPackage->StringBlock);\r | |
1034 | BlockPtr = Block + (StringTextPtr - StringPackage->StringBlock);\r | |
1035 | \r | |
1036 | CopyMem (BlockPtr, String, StrSize (String));\r | |
1037 | BlockPtr += StrSize (String);\r | |
1038 | \r | |
1039 | CopyMem (\r | |
1040 | BlockPtr,\r | |
1041 | StringTextPtr + StringSize,\r | |
1042 | OldBlockSize - (StringTextPtr - StringPackage->StringBlock) - StringSize\r | |
1043 | );\r | |
1044 | \r | |
1045 | FreePool (StringPackage->StringBlock);\r | |
1046 | StringPackage->StringBlock = Block;\r | |
1047 | StringPackage->StringPkgHdr->Header.Length += (UINT32) (BlockSize - OldBlockSize);\r | |
1048 | break;\r | |
1049 | \r | |
1050 | default:\r | |
1051 | return EFI_NOT_FOUND;\r | |
1052 | }\r | |
1053 | \r | |
1054 | //\r | |
1055 | // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming\r | |
1056 | // StringFontInfo does not exist in current string package.\r | |
1057 | //\r | |
1058 | // This new block does not impact on the value of StringId.\r | |
1059 | //\r | |
1060 | //\r | |
1061 | if (StringFontInfo == NULL || Referred) {\r | |
1062 | return EFI_SUCCESS;\r | |
1063 | }\r | |
1064 | \r | |
1065 | OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r | |
1066 | BlockSize = OldBlockSize + sizeof (EFI_HII_SIBT_FONT_BLOCK) - sizeof (CHAR16) +\r | |
1067 | StrSize (GlobalFont->FontInfo->FontName);\r | |
1068 | \r | |
1069 | Block = AllocateZeroPool (BlockSize);\r | |
1070 | if (Block == NULL) {\r | |
1071 | return EFI_OUT_OF_RESOURCES;\r | |
1072 | }\r | |
1073 | \r | |
1074 | BlockPtr = Block;\r | |
1075 | Ext2.Header.BlockType = EFI_HII_SIBT_EXT2;\r | |
1076 | Ext2.BlockType2 = EFI_HII_SIBT_FONT;\r | |
1077 | Ext2.Length = (UINT16) (BlockSize - OldBlockSize);\r | |
1078 | CopyMem (BlockPtr, &Ext2, sizeof (EFI_HII_SIBT_EXT2_BLOCK));\r | |
1079 | BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r | |
1080 | \r | |
1081 | *BlockPtr = LocalFont->FontId;\r | |
1082 | BlockPtr += sizeof (UINT8);\r | |
1083 | CopyMem (BlockPtr, &GlobalFont->FontInfo->FontSize, sizeof (UINT16));\r | |
1084 | BlockPtr += sizeof (UINT16);\r | |
1085 | CopyMem (BlockPtr, &GlobalFont->FontInfo->FontStyle, sizeof (UINT32));\r | |
1086 | BlockPtr += sizeof (UINT32);\r | |
1087 | CopyMem (\r | |
1088 | BlockPtr,\r | |
1089 | GlobalFont->FontInfo->FontName,\r | |
1090 | StrSize (GlobalFont->FontInfo->FontName)\r | |
1091 | );\r | |
1092 | BlockPtr += StrSize (GlobalFont->FontInfo->FontName);\r | |
1093 | \r | |
1094 | CopyMem (BlockPtr, StringPackage->StringBlock, OldBlockSize);\r | |
1095 | \r | |
1096 | FreePool (StringPackage->StringBlock);\r | |
1097 | StringPackage->StringBlock = Block;\r | |
1098 | StringPackage->StringPkgHdr->Header.Length += Ext2.Length;\r | |
1099 | \r | |
1100 | return EFI_SUCCESS;\r | |
1101 | \r | |
1102 | }\r | |
1103 | \r | |
1104 | \r | |
1105 | /**\r | |
1106 | This function adds the string String to the group of strings owned by PackageList, with the\r | |
1107 | specified font information StringFontInfo and returns a new string id. \r | |
1108 | The new string identifier is guaranteed to be unique within the package list. \r | |
1109 | That new string identifier is reserved for all languages in the package list. \r | |
1110 | \r | |
1111 | \r | |
1112 | @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r | |
1113 | @param PackageList Handle of the package list where this string will\r | |
1114 | be added.\r | |
1115 | @param StringId On return, contains the new strings id, which is\r | |
1116 | unique within PackageList.\r | |
1117 | @param Language Points to the language for the new string.\r | |
1118 | @param LanguageName Points to the printable language name to associate\r | |
1119 | with the passed in Language field.If LanguageName\r | |
1120 | is not NULL and the string package header's\r | |
1121 | LanguageName associated with a given Language is\r | |
1122 | not zero, the LanguageName being passed in will\r | |
1123 | be ignored.\r | |
1124 | @param String Points to the new null-terminated string.\r | |
1125 | @param StringFontInfo Points to the new string's font information or\r | |
1126 | NULL if the string should have the default system\r | |
1127 | font, size and style.\r | |
1128 | \r | |
1129 | @retval EFI_SUCCESS The new string was added successfully.\r | |
1130 | @retval EFI_NOT_FOUND The specified PackageList could not be found in\r | |
1131 | database.\r | |
1132 | @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.\r | |
1133 | @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is\r | |
1134 | NULL.\r | |
1135 | @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in\r | |
1136 | current database.\r | |
1137 | \r | |
1138 | **/\r | |
1139 | EFI_STATUS\r | |
1140 | EFIAPI\r | |
1141 | HiiNewString (\r | |
1142 | IN CONST EFI_HII_STRING_PROTOCOL *This,\r | |
1143 | IN EFI_HII_HANDLE PackageList,\r | |
1144 | OUT EFI_STRING_ID *StringId,\r | |
1145 | IN CONST CHAR8 *Language,\r | |
1146 | IN CONST CHAR16 *LanguageName, OPTIONAL\r | |
1147 | IN CONST EFI_STRING String,\r | |
1148 | IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL\r | |
1149 | )\r | |
1150 | {\r | |
1151 | EFI_STATUS Status;\r | |
1152 | LIST_ENTRY *Link;\r | |
1153 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1154 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
1155 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1156 | HII_STRING_PACKAGE_INSTANCE *StringPackage;\r | |
1157 | UINT32 HeaderSize;\r | |
1158 | UINT32 BlockSize;\r | |
1159 | UINT32 OldBlockSize;\r | |
1160 | UINT8 *StringBlock;\r | |
1161 | UINT8 *BlockPtr;\r | |
1162 | UINT32 Ucs2BlockSize;\r | |
1163 | UINT32 FontBlockSize;\r | |
1164 | UINT32 Ucs2FontBlockSize;\r | |
1165 | EFI_HII_SIBT_EXT2_BLOCK Ext2;\r | |
1166 | HII_FONT_INFO *LocalFont;\r | |
1167 | HII_GLOBAL_FONT_INFO *GlobalFont;\r | |
1168 | EFI_STRING_ID NewStringId;\r | |
1169 | EFI_STRING_ID NextStringId;\r | |
1170 | EFI_STRING_ID Index;\r | |
1171 | HII_STRING_PACKAGE_INSTANCE *MatchStringPackage;\r | |
1172 | BOOLEAN NewStringPackageCreated;\r | |
1173 | \r | |
1174 | \r | |
1175 | if (This == NULL || String == NULL || StringId == NULL || Language == NULL || PackageList == NULL) {\r | |
1176 | return EFI_INVALID_PARAMETER;\r | |
1177 | }\r | |
1178 | \r | |
1179 | if (!IsHiiHandleValid (PackageList)) {\r | |
1180 | return EFI_NOT_FOUND;\r | |
1181 | }\r | |
1182 | \r | |
1183 | Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1184 | GlobalFont = NULL;\r | |
1185 | \r | |
1186 | //\r | |
1187 | // If StringFontInfo specify a paritcular font, it should exist in current database.\r | |
1188 | //\r | |
1189 | if (StringFontInfo != NULL) {\r | |
1190 | if (!IsFontInfoExisted (Private, (EFI_FONT_INFO *) StringFontInfo, NULL, NULL, &GlobalFont)) {\r | |
1191 | return EFI_INVALID_PARAMETER;\r | |
1192 | }\r | |
1193 | }\r | |
1194 | \r | |
1195 | //\r | |
1196 | // Get the matching package list.\r | |
1197 | //\r | |
1198 | PackageListNode = NULL;\r | |
1199 | for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r | |
1200 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
1201 | if (DatabaseRecord->Handle == PackageList) {\r | |
1202 | PackageListNode = DatabaseRecord->PackageList;\r | |
1203 | break;\r | |
1204 | }\r | |
1205 | }\r | |
1206 | if (PackageListNode == NULL) {\r | |
1207 | return EFI_NOT_FOUND;\r | |
1208 | }\r | |
1209 | \r | |
1210 | Status = EFI_SUCCESS;\r | |
1211 | NewStringPackageCreated = FALSE;\r | |
1212 | NewStringId = 0;\r | |
1213 | NextStringId = 0;\r | |
1214 | StringPackage = NULL;\r | |
1215 | MatchStringPackage = NULL;\r | |
1216 | for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r | |
1217 | Link != &PackageListNode->StringPkgHdr;\r | |
1218 | Link = Link->ForwardLink\r | |
1219 | ) {\r | |
1220 | StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r | |
1221 | //\r | |
1222 | // Create a string block and corresponding font block if exists, then append them\r | |
1223 | // to the end of the string package.\r | |
1224 | //\r | |
1225 | Status = FindStringBlock (\r | |
1226 | Private,\r | |
1227 | StringPackage,\r | |
1228 | 0,\r | |
1229 | NULL,\r | |
1230 | NULL,\r | |
1231 | NULL,\r | |
1232 | &NextStringId,\r | |
1233 | NULL\r | |
1234 | );\r | |
1235 | if (EFI_ERROR (Status)) {\r | |
1236 | goto Done;\r | |
1237 | }\r | |
1238 | //\r | |
1239 | // Make sure that new StringId is same in all String Packages for the different language.\r | |
1240 | //\r | |
1241 | if (NewStringId != 0 && NewStringId != NextStringId) {\r | |
1242 | ASSERT (FALSE);\r | |
1243 | Status = EFI_INVALID_PARAMETER;\r | |
1244 | goto Done;\r | |
1245 | }\r | |
1246 | NewStringId = NextStringId;\r | |
1247 | //\r | |
1248 | // Get the matched string package with language.\r | |
1249 | //\r | |
1250 | if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {\r | |
1251 | MatchStringPackage = StringPackage;\r | |
1252 | } else {\r | |
1253 | OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r | |
1254 | //\r | |
1255 | // Create a blank EFI_HII_SIBT_STRING_UCS2_BLOCK to reserve new string ID.\r | |
1256 | //\r | |
1257 | Ucs2BlockSize = (UINT32) sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);\r | |
1258 | \r | |
1259 | StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2BlockSize);\r | |
1260 | if (StringBlock == NULL) {\r | |
1261 | Status = EFI_OUT_OF_RESOURCES;\r | |
1262 | goto Done;\r | |
1263 | }\r | |
1264 | //\r | |
1265 | // Copy original string blocks, except the EFI_HII_SIBT_END.\r | |
1266 | //\r | |
1267 | CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r | |
1268 | //\r | |
1269 | // Create a blank EFI_HII_SIBT_STRING_UCS2 block\r | |
1270 | //\r | |
1271 | BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r | |
1272 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r | |
1273 | BlockPtr += sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);\r | |
1274 | \r | |
1275 | //\r | |
1276 | // Append a EFI_HII_SIBT_END block to the end.\r | |
1277 | //\r | |
1278 | *BlockPtr = EFI_HII_SIBT_END;\r | |
1279 | FreePool (StringPackage->StringBlock);\r | |
1280 | StringPackage->StringBlock = StringBlock;\r | |
1281 | StringPackage->StringPkgHdr->Header.Length += Ucs2BlockSize;\r | |
1282 | PackageListNode->PackageListHdr.PackageLength += Ucs2BlockSize;\r | |
1283 | }\r | |
1284 | }\r | |
1285 | if (NewStringId == 0) {\r | |
1286 | //\r | |
1287 | // No string package is found.\r | |
1288 | // Create new string package. StringId 1 is reserved for Language Name string.\r | |
1289 | //\r | |
1290 | *StringId = 2;\r | |
1291 | } else {\r | |
1292 | //\r | |
1293 | // Set new StringId\r | |
1294 | //\r | |
1295 | *StringId = (EFI_STRING_ID) (NewStringId + 1);\r | |
1296 | }\r | |
1297 | \r | |
1298 | if (MatchStringPackage != NULL) {\r | |
1299 | StringPackage = MatchStringPackage;\r | |
1300 | } else {\r | |
1301 | //\r | |
1302 | // LanguageName is required to create a new string package.\r | |
1303 | //\r | |
1304 | if (LanguageName == NULL) {\r | |
1305 | Status = EFI_INVALID_PARAMETER;\r | |
1306 | goto Done;\r | |
1307 | }\r | |
1308 | \r | |
1309 | StringPackage = AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE));\r | |
1310 | if (StringPackage == NULL) {\r | |
1311 | Status = EFI_OUT_OF_RESOURCES;\r | |
1312 | goto Done;\r | |
1313 | }\r | |
1314 | \r | |
1315 | StringPackage->Signature = HII_STRING_PACKAGE_SIGNATURE;\r | |
1316 | StringPackage->MaxStringId = *StringId;\r | |
1317 | StringPackage->FontId = 0;\r | |
1318 | InitializeListHead (&StringPackage->FontInfoList);\r | |
1319 | \r | |
1320 | //\r | |
1321 | // Fill in the string package header\r | |
1322 | //\r | |
1323 | HeaderSize = (UINT32) (AsciiStrSize ((CHAR8 *) Language) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR));\r | |
1324 | StringPackage->StringPkgHdr = AllocateZeroPool (HeaderSize);\r | |
1325 | if (StringPackage->StringPkgHdr == NULL) {\r | |
1326 | FreePool (StringPackage);\r | |
1327 | Status = EFI_OUT_OF_RESOURCES;\r | |
1328 | goto Done;\r | |
1329 | }\r | |
1330 | StringPackage->StringPkgHdr->Header.Type = EFI_HII_PACKAGE_STRINGS;\r | |
1331 | StringPackage->StringPkgHdr->HdrSize = HeaderSize;\r | |
1332 | StringPackage->StringPkgHdr->StringInfoOffset = HeaderSize;\r | |
1333 | CopyMem (StringPackage->StringPkgHdr->LanguageWindow, mLanguageWindow, 16 * sizeof (CHAR16));\r | |
1334 | StringPackage->StringPkgHdr->LanguageName = 1;\r | |
1335 | AsciiStrCpy (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language);\r | |
1336 | \r | |
1337 | //\r | |
1338 | // Calculate the length of the string blocks, including string block to record\r | |
1339 | // printable language full name and EFI_HII_SIBT_END_BLOCK.\r | |
1340 | //\r | |
1341 | Ucs2BlockSize = (UINT32) (StrSize ((CHAR16 *) LanguageName) + \r | |
1342 | (*StringId - 1) * sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16));\r | |
1343 | \r | |
1344 | BlockSize = Ucs2BlockSize + sizeof (EFI_HII_SIBT_END_BLOCK);\r | |
1345 | StringPackage->StringBlock = (UINT8 *) AllocateZeroPool (BlockSize);\r | |
1346 | if (StringPackage->StringBlock == NULL) {\r | |
1347 | FreePool (StringPackage->StringPkgHdr);\r | |
1348 | FreePool (StringPackage);\r | |
1349 | Status = EFI_OUT_OF_RESOURCES;\r | |
1350 | goto Done;\r | |
1351 | }\r | |
1352 | \r | |
1353 | //\r | |
1354 | // Insert the string block of printable language full name\r | |
1355 | //\r | |
1356 | BlockPtr = StringPackage->StringBlock;\r | |
1357 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r | |
1358 | BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r | |
1359 | CopyMem (BlockPtr, (EFI_STRING) LanguageName, StrSize ((EFI_STRING) LanguageName));\r | |
1360 | BlockPtr += StrSize ((EFI_STRING) LanguageName);\r | |
1361 | for (Index = 2; Index <= *StringId - 1; Index ++) {\r | |
1362 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r | |
1363 | BlockPtr += sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK);\r | |
1364 | }\r | |
1365 | //\r | |
1366 | // Insert the end block\r | |
1367 | //\r | |
1368 | *BlockPtr = EFI_HII_SIBT_END;\r | |
1369 | \r | |
1370 | //\r | |
1371 | // Append this string package node to string package array in this package list.\r | |
1372 | //\r | |
1373 | StringPackage->StringPkgHdr->Header.Length = HeaderSize + BlockSize;\r | |
1374 | PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length;\r | |
1375 | InsertTailList (&PackageListNode->StringPkgHdr, &StringPackage->StringEntry);\r | |
1376 | NewStringPackageCreated = TRUE;\r | |
1377 | }\r | |
1378 | \r | |
1379 | OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r | |
1380 | \r | |
1381 | if (StringFontInfo == NULL) {\r | |
1382 | //\r | |
1383 | // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.\r | |
1384 | //\r | |
1385 | Ucs2BlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK)\r | |
1386 | - sizeof (CHAR16));\r | |
1387 | \r | |
1388 | StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2BlockSize);\r | |
1389 | if (StringBlock == NULL) {\r | |
1390 | Status = EFI_OUT_OF_RESOURCES;\r | |
1391 | goto Done;\r | |
1392 | }\r | |
1393 | //\r | |
1394 | // Copy original string blocks, except the EFI_HII_SIBT_END.\r | |
1395 | //\r | |
1396 | CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r | |
1397 | //\r | |
1398 | // Create a EFI_HII_SIBT_STRING_UCS2 block\r | |
1399 | //\r | |
1400 | BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r | |
1401 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r | |
1402 | BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r | |
1403 | CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));\r | |
1404 | BlockPtr += StrSize ((EFI_STRING) String);\r | |
1405 | \r | |
1406 | //\r | |
1407 | // Append a EFI_HII_SIBT_END block to the end.\r | |
1408 | //\r | |
1409 | *BlockPtr = EFI_HII_SIBT_END;\r | |
1410 | FreePool (StringPackage->StringBlock);\r | |
1411 | StringPackage->StringBlock = StringBlock;\r | |
1412 | StringPackage->StringPkgHdr->Header.Length += Ucs2BlockSize;\r | |
1413 | PackageListNode->PackageListHdr.PackageLength += Ucs2BlockSize;\r | |
1414 | \r | |
1415 | } else {\r | |
1416 | //\r | |
1417 | // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK\r | |
1418 | // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block\r | |
1419 | // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING\r | |
1420 | // _UCS2_FONT block.\r | |
1421 | //\r | |
1422 | Ucs2FontBlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) -\r | |
1423 | sizeof (CHAR16));\r | |
1424 | if (ReferFontInfoLocally (Private, StringPackage, StringPackage->FontId, FALSE, GlobalFont, &LocalFont)) {\r | |
1425 | //\r | |
1426 | // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.\r | |
1427 | //\r | |
1428 | StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2FontBlockSize);\r | |
1429 | if (StringBlock == NULL) {\r | |
1430 | Status = EFI_OUT_OF_RESOURCES;\r | |
1431 | goto Done;\r | |
1432 | }\r | |
1433 | //\r | |
1434 | // Copy original string blocks, except the EFI_HII_SIBT_END.\r | |
1435 | //\r | |
1436 | CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r | |
1437 | //\r | |
1438 | // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r | |
1439 | //\r | |
1440 | BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r | |
1441 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r | |
1442 | BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r | |
1443 | *BlockPtr = LocalFont->FontId;\r | |
1444 | BlockPtr += sizeof (UINT8);\r | |
1445 | CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));\r | |
1446 | BlockPtr += StrSize ((EFI_STRING) String);\r | |
1447 | \r | |
1448 | //\r | |
1449 | // Append a EFI_HII_SIBT_END block to the end.\r | |
1450 | //\r | |
1451 | *BlockPtr = EFI_HII_SIBT_END;\r | |
1452 | FreePool (StringPackage->StringBlock);\r | |
1453 | StringPackage->StringBlock = StringBlock;\r | |
1454 | StringPackage->StringPkgHdr->Header.Length += Ucs2FontBlockSize;\r | |
1455 | PackageListNode->PackageListHdr.PackageLength += Ucs2FontBlockSize;\r | |
1456 | \r | |
1457 | } else {\r | |
1458 | //\r | |
1459 | // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so\r | |
1460 | // create a EFI_HII_SIBT_FONT block to record the font info, then generate\r | |
1461 | // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.\r | |
1462 | //\r | |
1463 | FontBlockSize = (UINT32) (StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName) +\r | |
1464 | sizeof (EFI_HII_SIBT_FONT_BLOCK) - sizeof (CHAR16));\r | |
1465 | StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + FontBlockSize + Ucs2FontBlockSize);\r | |
1466 | if (StringBlock == NULL) {\r | |
1467 | Status = EFI_OUT_OF_RESOURCES;\r | |
1468 | goto Done;\r | |
1469 | }\r | |
1470 | //\r | |
1471 | // Copy original string blocks, except the EFI_HII_SIBT_END.\r | |
1472 | //\r | |
1473 | CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r | |
1474 | \r | |
1475 | //\r | |
1476 | // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string\r | |
1477 | // package instance for future reference.\r | |
1478 | //\r | |
1479 | BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r | |
1480 | \r | |
1481 | Ext2.Header.BlockType = EFI_HII_SIBT_EXT2;\r | |
1482 | Ext2.BlockType2 = EFI_HII_SIBT_FONT;\r | |
1483 | Ext2.Length = (UINT16) FontBlockSize;\r | |
1484 | CopyMem (BlockPtr, &Ext2, sizeof (EFI_HII_SIBT_EXT2_BLOCK));\r | |
1485 | BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r | |
1486 | \r | |
1487 | *BlockPtr = LocalFont->FontId;\r | |
1488 | BlockPtr += sizeof (UINT8);\r | |
1489 | CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontSize, sizeof (UINT16));\r | |
1490 | BlockPtr += sizeof (UINT16);\r | |
1491 | CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontStyle, sizeof (EFI_HII_FONT_STYLE));\r | |
1492 | BlockPtr += sizeof (EFI_HII_FONT_STYLE);\r | |
1493 | CopyMem (\r | |
1494 | BlockPtr,\r | |
1495 | &((EFI_FONT_INFO *) StringFontInfo)->FontName,\r | |
1496 | StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName)\r | |
1497 | );\r | |
1498 | BlockPtr += StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName);\r | |
1499 | //\r | |
1500 | // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r | |
1501 | //\r | |
1502 | *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r | |
1503 | BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r | |
1504 | *BlockPtr = LocalFont->FontId;\r | |
1505 | BlockPtr += sizeof (UINT8);\r | |
1506 | CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));\r | |
1507 | BlockPtr += StrSize ((EFI_STRING) String);\r | |
1508 | \r | |
1509 | //\r | |
1510 | // Append a EFI_HII_SIBT_END block to the end.\r | |
1511 | //\r | |
1512 | *BlockPtr = EFI_HII_SIBT_END;\r | |
1513 | FreePool (StringPackage->StringBlock);\r | |
1514 | StringPackage->StringBlock = StringBlock;\r | |
1515 | StringPackage->StringPkgHdr->Header.Length += FontBlockSize + Ucs2FontBlockSize;\r | |
1516 | PackageListNode->PackageListHdr.PackageLength += FontBlockSize + Ucs2FontBlockSize;\r | |
1517 | \r | |
1518 | //\r | |
1519 | // Increase the FontId to make it unique since we already add \r | |
1520 | // a EFI_HII_SIBT_FONT block to this string package.\r | |
1521 | //\r | |
1522 | StringPackage->FontId++;\r | |
1523 | }\r | |
1524 | }\r | |
1525 | \r | |
1526 | Done:\r | |
1527 | if (!EFI_ERROR (Status) && NewStringPackageCreated) {\r | |
1528 | //\r | |
1529 | // Trigger any registered notification function for new string package\r | |
1530 | //\r | |
1531 | Status = InvokeRegisteredFunction (\r | |
1532 | Private,\r | |
1533 | EFI_HII_DATABASE_NOTIFY_NEW_PACK,\r | |
1534 | (VOID *) StringPackage,\r | |
1535 | EFI_HII_PACKAGE_STRINGS,\r | |
1536 | PackageList\r | |
1537 | );\r | |
1538 | }\r | |
1539 | \r | |
1540 | if (!EFI_ERROR (Status)) {\r | |
1541 | //\r | |
1542 | // Update MaxString Id to new StringId\r | |
1543 | //\r | |
1544 | for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r | |
1545 | Link != &PackageListNode->StringPkgHdr;\r | |
1546 | Link = Link->ForwardLink\r | |
1547 | ) {\r | |
1548 | StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r | |
1549 | StringPackage->MaxStringId = *StringId;\r | |
1550 | }\r | |
1551 | } else if (NewStringPackageCreated) {\r | |
1552 | //\r | |
1553 | // Free the allocated new string Package when new string can't be added.\r | |
1554 | //\r | |
1555 | RemoveEntryList (&StringPackage->StringEntry);\r | |
1556 | FreePool (StringPackage->StringBlock);\r | |
1557 | FreePool (StringPackage->StringPkgHdr);\r | |
1558 | FreePool (StringPackage);\r | |
1559 | }\r | |
1560 | \r | |
1561 | return Status;\r | |
1562 | }\r | |
1563 | \r | |
1564 | \r | |
1565 | /**\r | |
1566 | This function retrieves the string specified by StringId which is associated\r | |
1567 | with the specified PackageList in the language Language and copies it into\r | |
1568 | the buffer specified by String.\r | |
1569 | \r | |
1570 | @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r | |
1571 | @param Language Points to the language for the retrieved string.\r | |
1572 | @param PackageList The package list in the HII database to search for\r | |
1573 | the specified string.\r | |
1574 | @param StringId The string's id, which is unique within\r | |
1575 | PackageList.\r | |
1576 | @param String Points to the new null-terminated string.\r | |
1577 | @param StringSize On entry, points to the size of the buffer pointed\r | |
1578 | to by String, in bytes. On return, points to the\r | |
1579 | length of the string, in bytes.\r | |
1580 | @param StringFontInfo If not NULL, points to the string's font\r | |
1581 | information. It's caller's responsibility to free\r | |
1582 | this buffer.\r | |
1583 | \r | |
1584 | @retval EFI_SUCCESS The string was returned successfully.\r | |
1585 | @retval EFI_NOT_FOUND The string specified by StringId is not available.\r | |
1586 | @retval EFI_NOT_FOUND The string specified by StringId is available but\r | |
1587 | not in the specified language.\r | |
1588 | The specified PackageList is not in the database.\r | |
1589 | @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but\r | |
1590 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to\r | |
1591 | hold the string.\r | |
1592 | @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL.\r | |
1593 | @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the\r | |
1594 | request.\r | |
1595 | \r | |
1596 | **/\r | |
1597 | EFI_STATUS\r | |
1598 | EFIAPI\r | |
1599 | HiiGetString (\r | |
1600 | IN CONST EFI_HII_STRING_PROTOCOL *This,\r | |
1601 | IN CONST CHAR8 *Language,\r | |
1602 | IN EFI_HII_HANDLE PackageList,\r | |
1603 | IN EFI_STRING_ID StringId,\r | |
1604 | OUT EFI_STRING String,\r | |
1605 | IN OUT UINTN *StringSize,\r | |
1606 | OUT EFI_FONT_INFO **StringFontInfo OPTIONAL\r | |
1607 | )\r | |
1608 | {\r | |
1609 | EFI_STATUS Status;\r | |
1610 | LIST_ENTRY *Link;\r | |
1611 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1612 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
1613 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1614 | HII_STRING_PACKAGE_INSTANCE *StringPackage;\r | |
1615 | \r | |
1616 | if (This == NULL || Language == NULL || StringId < 1 || StringSize == NULL || PackageList == NULL) {\r | |
1617 | return EFI_INVALID_PARAMETER;\r | |
1618 | }\r | |
1619 | \r | |
1620 | if (String == NULL && *StringSize != 0) {\r | |
1621 | return EFI_INVALID_PARAMETER;\r | |
1622 | }\r | |
1623 | \r | |
1624 | if (!IsHiiHandleValid (PackageList)) {\r | |
1625 | return EFI_NOT_FOUND;\r | |
1626 | }\r | |
1627 | \r | |
1628 | Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1629 | PackageListNode = NULL;\r | |
1630 | \r | |
1631 | for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r | |
1632 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
1633 | if (DatabaseRecord->Handle == PackageList) {\r | |
1634 | PackageListNode = DatabaseRecord->PackageList;\r | |
1635 | break;\r | |
1636 | }\r | |
1637 | }\r | |
1638 | \r | |
1639 | if (PackageListNode != NULL) {\r | |
1640 | //\r | |
1641 | // First search: to match the StringId in the specified language.\r | |
1642 | //\r | |
1643 | for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r | |
1644 | Link != &PackageListNode->StringPkgHdr;\r | |
1645 | Link = Link->ForwardLink\r | |
1646 | ) {\r | |
1647 | StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r | |
1648 | if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {\r | |
1649 | Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);\r | |
1650 | if (Status != EFI_NOT_FOUND) {\r | |
1651 | return Status;\r | |
1652 | }\r | |
1653 | }\r | |
1654 | }\r | |
1655 | //\r | |
1656 | // Second search: to match the StringId in other available languages if exist.\r | |
1657 | //\r | |
1658 | for (Link = PackageListNode->StringPkgHdr.ForwardLink; \r | |
1659 | Link != &PackageListNode->StringPkgHdr;\r | |
1660 | Link = Link->ForwardLink\r | |
1661 | ) {\r | |
1662 | StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); \r | |
1663 | Status = GetStringWorker (Private, StringPackage, StringId, NULL, NULL, NULL);\r | |
1664 | if (!EFI_ERROR (Status)) {\r | |
1665 | return EFI_INVALID_LANGUAGE;\r | |
1666 | }\r | |
1667 | } \r | |
1668 | }\r | |
1669 | \r | |
1670 | return EFI_NOT_FOUND;\r | |
1671 | }\r | |
1672 | \r | |
1673 | \r | |
1674 | \r | |
1675 | /**\r | |
1676 | This function updates the string specified by StringId in the specified PackageList to the text\r | |
1677 | specified by String and, optionally, the font information specified by StringFontInfo.\r | |
1678 | \r | |
1679 | @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r | |
1680 | @param PackageList The package list containing the strings.\r | |
1681 | @param StringId The string's id, which is unique within\r | |
1682 | PackageList.\r | |
1683 | @param Language Points to the language for the updated string.\r | |
1684 | @param String Points to the new null-terminated string.\r | |
1685 | @param StringFontInfo Points to the string's font information or NULL if\r | |
1686 | the string font information is not changed.\r | |
1687 | \r | |
1688 | @retval EFI_SUCCESS The string was updated successfully.\r | |
1689 | @retval EFI_NOT_FOUND The string specified by StringId is not in the\r | |
1690 | database.\r | |
1691 | @retval EFI_INVALID_PARAMETER The String or Language was NULL.\r | |
1692 | @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in\r | |
1693 | current database.\r | |
1694 | @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the\r | |
1695 | task.\r | |
1696 | \r | |
1697 | **/\r | |
1698 | EFI_STATUS\r | |
1699 | EFIAPI\r | |
1700 | HiiSetString (\r | |
1701 | IN CONST EFI_HII_STRING_PROTOCOL *This,\r | |
1702 | IN EFI_HII_HANDLE PackageList,\r | |
1703 | IN EFI_STRING_ID StringId,\r | |
1704 | IN CONST CHAR8 *Language,\r | |
1705 | IN CONST EFI_STRING String,\r | |
1706 | IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL\r | |
1707 | )\r | |
1708 | {\r | |
1709 | EFI_STATUS Status;\r | |
1710 | LIST_ENTRY *Link;\r | |
1711 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1712 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
1713 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1714 | HII_STRING_PACKAGE_INSTANCE *StringPackage;\r | |
1715 | UINT32 OldPackageLen;\r | |
1716 | \r | |
1717 | if (This == NULL || Language == NULL || StringId < 1 || String == NULL || PackageList == NULL) {\r | |
1718 | return EFI_INVALID_PARAMETER;\r | |
1719 | }\r | |
1720 | \r | |
1721 | if (!IsHiiHandleValid (PackageList)) {\r | |
1722 | return EFI_NOT_FOUND;\r | |
1723 | }\r | |
1724 | \r | |
1725 | Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1726 | PackageListNode = NULL;\r | |
1727 | \r | |
1728 | for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r | |
1729 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
1730 | if (DatabaseRecord->Handle == PackageList) {\r | |
1731 | PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);\r | |
1732 | }\r | |
1733 | }\r | |
1734 | \r | |
1735 | if (PackageListNode != NULL) {\r | |
1736 | for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r | |
1737 | Link != &PackageListNode->StringPkgHdr;\r | |
1738 | Link = Link->ForwardLink\r | |
1739 | ) {\r | |
1740 | StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r | |
1741 | if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language)) {\r | |
1742 | OldPackageLen = StringPackage->StringPkgHdr->Header.Length;\r | |
1743 | Status = SetStringWorker (\r | |
1744 | Private,\r | |
1745 | StringPackage,\r | |
1746 | StringId,\r | |
1747 | (EFI_STRING) String,\r | |
1748 | (EFI_FONT_INFO *) StringFontInfo\r | |
1749 | );\r | |
1750 | if (EFI_ERROR (Status)) {\r | |
1751 | return Status;\r | |
1752 | }\r | |
1753 | PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length - OldPackageLen;\r | |
1754 | return EFI_SUCCESS;\r | |
1755 | }\r | |
1756 | }\r | |
1757 | }\r | |
1758 | \r | |
1759 | return EFI_NOT_FOUND;\r | |
1760 | }\r | |
1761 | \r | |
1762 | \r | |
1763 | \r | |
1764 | /**\r | |
1765 | This function returns the list of supported languages, in the format specified\r | |
1766 | in Appendix M of UEFI 2.1 spec.\r | |
1767 | \r | |
1768 | @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r | |
1769 | @param PackageList The package list to examine.\r | |
1770 | @param Languages Points to the buffer to hold the returned\r | |
1771 | null-terminated ASCII string.\r | |
1772 | @param LanguagesSize On entry, points to the size of the buffer pointed\r | |
1773 | to by Languages, in bytes. On return, points to\r | |
1774 | the length of Languages, in bytes.\r | |
1775 | \r | |
1776 | @retval EFI_SUCCESS The languages were returned successfully.\r | |
1777 | @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL.\r | |
1778 | @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of\r | |
1779 | supported languages. LanguageSize is updated to\r | |
1780 | contain the required size.\r | |
1781 | @retval EFI_NOT_FOUND Could not find string package in specified\r | |
1782 | packagelist.\r | |
1783 | \r | |
1784 | **/\r | |
1785 | EFI_STATUS\r | |
1786 | EFIAPI\r | |
1787 | HiiGetLanguages (\r | |
1788 | IN CONST EFI_HII_STRING_PROTOCOL *This,\r | |
1789 | IN EFI_HII_HANDLE PackageList,\r | |
1790 | IN OUT CHAR8 *Languages,\r | |
1791 | IN OUT UINTN *LanguagesSize\r | |
1792 | )\r | |
1793 | {\r | |
1794 | LIST_ENTRY *Link;\r | |
1795 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1796 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
1797 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1798 | HII_STRING_PACKAGE_INSTANCE *StringPackage;\r | |
1799 | UINTN ResultSize;\r | |
1800 | \r | |
1801 | if (This == NULL || Languages == NULL || LanguagesSize == NULL || PackageList == NULL) {\r | |
1802 | return EFI_INVALID_PARAMETER;\r | |
1803 | }\r | |
1804 | if (!IsHiiHandleValid (PackageList)) {\r | |
1805 | return EFI_NOT_FOUND;\r | |
1806 | }\r | |
1807 | \r | |
1808 | Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1809 | \r | |
1810 | PackageListNode = NULL;\r | |
1811 | for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r | |
1812 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
1813 | if (DatabaseRecord->Handle == PackageList) {\r | |
1814 | PackageListNode = DatabaseRecord->PackageList;\r | |
1815 | break;\r | |
1816 | }\r | |
1817 | }\r | |
1818 | if (PackageListNode == NULL) {\r | |
1819 | return EFI_NOT_FOUND;\r | |
1820 | }\r | |
1821 | \r | |
1822 | //\r | |
1823 | // Search the languages in the specified packagelist.\r | |
1824 | //\r | |
1825 | ResultSize = 0;\r | |
1826 | for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r | |
1827 | Link != &PackageListNode->StringPkgHdr;\r | |
1828 | Link = Link->ForwardLink\r | |
1829 | ) {\r | |
1830 | StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r | |
1831 | ResultSize += AsciiStrSize (StringPackage->StringPkgHdr->Language);\r | |
1832 | if (ResultSize <= *LanguagesSize) {\r | |
1833 | AsciiStrCpy (Languages, StringPackage->StringPkgHdr->Language);\r | |
1834 | Languages += AsciiStrSize (StringPackage->StringPkgHdr->Language);\r | |
1835 | *(Languages - 1) = L';';\r | |
1836 | }\r | |
1837 | }\r | |
1838 | if (ResultSize == 0) {\r | |
1839 | return EFI_NOT_FOUND;\r | |
1840 | }\r | |
1841 | \r | |
1842 | if (*LanguagesSize < ResultSize) {\r | |
1843 | *LanguagesSize = ResultSize;\r | |
1844 | return EFI_BUFFER_TOO_SMALL;\r | |
1845 | }\r | |
1846 | \r | |
1847 | *(Languages - 1) = 0;\r | |
1848 | return EFI_SUCCESS;\r | |
1849 | }\r | |
1850 | \r | |
1851 | \r | |
1852 | /**\r | |
1853 | Each string package has associated with it a single primary language and zero\r | |
1854 | or more secondary languages. This routine returns the secondary languages\r | |
1855 | associated with a package list.\r | |
1856 | \r | |
1857 | @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r | |
1858 | @param PackageList The package list to examine.\r | |
1859 | @param PrimaryLanguage Points to the null-terminated ASCII string that specifies\r | |
1860 | the primary language. Languages are specified in the\r | |
1861 | format specified in Appendix M of the UEFI 2.0 specification.\r | |
1862 | @param SecondaryLanguages Points to the buffer to hold the returned null-terminated\r | |
1863 | ASCII string that describes the list of\r | |
1864 | secondary languages for the specified\r | |
1865 | PrimaryLanguage. If there are no secondary\r | |
1866 | languages, the function returns successfully, but\r | |
1867 | this is set to NULL.\r | |
1868 | @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed\r | |
1869 | to by SecondaryLanguages, in bytes. On return,\r | |
1870 | points to the length of SecondaryLanguages in bytes.\r | |
1871 | \r | |
1872 | @retval EFI_SUCCESS Secondary languages were correctly returned.\r | |
1873 | @retval EFI_INVALID_PARAMETER PrimaryLanguage or SecondaryLanguages or\r | |
1874 | SecondaryLanguagesSize was NULL.\r | |
1875 | @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is\r | |
1876 | too small to hold the returned information.\r | |
1877 | SecondaryLanguageSize is updated to hold the size of\r | |
1878 | the buffer required.\r | |
1879 | @retval EFI_INVALID_LANGUAGE The language specified by PrimaryLanguage is not\r | |
1880 | present in the specified package list.\r | |
1881 | @retval EFI_NOT_FOUND The specified PackageList is not in the Database. \r | |
1882 | \r | |
1883 | **/\r | |
1884 | EFI_STATUS\r | |
1885 | EFIAPI\r | |
1886 | HiiGetSecondaryLanguages (\r | |
1887 | IN CONST EFI_HII_STRING_PROTOCOL *This,\r | |
1888 | IN EFI_HII_HANDLE PackageList,\r | |
1889 | IN CONST CHAR8 *PrimaryLanguage,\r | |
1890 | IN OUT CHAR8 *SecondaryLanguages,\r | |
1891 | IN OUT UINTN *SecondaryLanguagesSize\r | |
1892 | )\r | |
1893 | {\r | |
1894 | LIST_ENTRY *Link;\r | |
1895 | LIST_ENTRY *Link1;\r | |
1896 | HII_DATABASE_PRIVATE_DATA *Private;\r | |
1897 | HII_DATABASE_RECORD *DatabaseRecord;\r | |
1898 | HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r | |
1899 | HII_STRING_PACKAGE_INSTANCE *StringPackage;\r | |
1900 | CHAR8 *Languages;\r | |
1901 | UINTN ResultSize;\r | |
1902 | \r | |
1903 | if (This == NULL || PackageList == NULL || PrimaryLanguage == NULL) {\r | |
1904 | return EFI_INVALID_PARAMETER;\r | |
1905 | }\r | |
1906 | if (SecondaryLanguages == NULL || SecondaryLanguagesSize == NULL) {\r | |
1907 | return EFI_INVALID_PARAMETER;\r | |
1908 | }\r | |
1909 | if (!IsHiiHandleValid (PackageList)) {\r | |
1910 | return EFI_NOT_FOUND;\r | |
1911 | }\r | |
1912 | \r | |
1913 | Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r | |
1914 | \r | |
1915 | PackageListNode = NULL; \r | |
1916 | for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r | |
1917 | DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r | |
1918 | if (DatabaseRecord->Handle == PackageList) {\r | |
1919 | PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);\r | |
1920 | break;\r | |
1921 | }\r | |
1922 | }\r | |
1923 | if (PackageListNode == NULL) {\r | |
1924 | return EFI_NOT_FOUND;\r | |
1925 | }\r | |
1926 | \r | |
1927 | Languages = NULL;\r | |
1928 | ResultSize = 0;\r | |
1929 | for (Link1 = PackageListNode->StringPkgHdr.ForwardLink;\r | |
1930 | Link1 != &PackageListNode->StringPkgHdr;\r | |
1931 | Link1 = Link1->ForwardLink\r | |
1932 | ) {\r | |
1933 | StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r | |
1934 | if (HiiCompareLanguage (StringPackage->StringPkgHdr->Language, (CHAR8 *) PrimaryLanguage)) {\r | |
1935 | Languages = StringPackage->StringPkgHdr->Language;\r | |
1936 | //\r | |
1937 | // Language is a series of ';' terminated strings, first one is primary\r | |
1938 | // language and following with other secondary languages or NULL if no\r | |
1939 | // secondary languages any more.\r | |
1940 | //\r | |
1941 | Languages = AsciiStrStr (Languages, ";");\r | |
1942 | if (Languages == NULL) {\r | |
1943 | break;\r | |
1944 | }\r | |
1945 | Languages++;\r | |
1946 | \r | |
1947 | ResultSize = AsciiStrSize (Languages);\r | |
1948 | if (ResultSize <= *SecondaryLanguagesSize) {\r | |
1949 | AsciiStrCpy (SecondaryLanguages, Languages);\r | |
1950 | } else {\r | |
1951 | *SecondaryLanguagesSize = ResultSize;\r | |
1952 | return EFI_BUFFER_TOO_SMALL;\r | |
1953 | }\r | |
1954 | \r | |
1955 | return EFI_SUCCESS;\r | |
1956 | }\r | |
1957 | }\r | |
1958 | \r | |
1959 | return EFI_INVALID_LANGUAGE;\r | |
1960 | }\r | |
1961 | \r | |
1962 | /**\r | |
1963 | Converts the ascii character of the string from uppercase to lowercase.\r | |
1964 | This is a internal function.\r | |
1965 | \r | |
1966 | @param ConfigString String to be converted\r | |
1967 | \r | |
1968 | **/\r | |
1969 | VOID\r | |
1970 | EFIAPI\r | |
1971 | AsciiHiiToLower (\r | |
1972 | IN CHAR8 *ConfigString\r | |
1973 | )\r | |
1974 | {\r | |
1975 | CHAR8 *String;\r | |
1976 | \r | |
1977 | ASSERT (ConfigString != NULL);\r | |
1978 | \r | |
1979 | //\r | |
1980 | // Convert all hex digits in range [A-F] in the configuration header to [a-f]\r | |
1981 | //\r | |
1982 | for (String = ConfigString; *String != '\0'; String++) {\r | |
1983 | if ( *String >= 'A' && *String <= 'Z') {\r | |
1984 | *String = (CHAR8) (*String - 'A' + 'a');\r | |
1985 | }\r | |
1986 | }\r | |
1987 | \r | |
1988 | return;\r | |
1989 | }\r | |
1990 | \r | |
1991 | /**\r | |
1992 | Compare whether two names of languages are identical.\r | |
1993 | \r | |
1994 | @param Language1 Name of language 1 from StringPackage\r | |
1995 | @param Language2 Name of language 2 to be compared with language 1.\r | |
1996 | \r | |
1997 | @retval TRUE same\r | |
1998 | @retval FALSE not same\r | |
1999 | \r | |
2000 | **/\r | |
2001 | BOOLEAN\r | |
2002 | HiiCompareLanguage (\r | |
2003 | IN CHAR8 *Language1,\r | |
2004 | IN CHAR8 *Language2\r | |
2005 | )\r | |
2006 | {\r | |
2007 | UINTN Index;\r | |
2008 | UINTN StrLen;\r | |
2009 | CHAR8 *Lan1;\r | |
2010 | CHAR8 *Lan2;\r | |
2011 | \r | |
2012 | //\r | |
2013 | // Convert to lower to compare.\r | |
2014 | //\r | |
2015 | StrLen = AsciiStrSize (Language1);\r | |
2016 | Lan1 = AllocateZeroPool (StrLen);\r | |
2017 | AsciiStrCpy(Lan1, Language1);\r | |
2018 | AsciiHiiToLower (Lan1);\r | |
2019 | \r | |
2020 | StrLen = AsciiStrSize (Language2);\r | |
2021 | Lan2 = AllocateZeroPool (StrLen);\r | |
2022 | AsciiStrCpy(Lan2, Language2);\r | |
2023 | AsciiHiiToLower (Lan2);\r | |
2024 | \r | |
2025 | //\r | |
2026 | // Compare the Primary Language in Language1 to Language2\r | |
2027 | //\r | |
2028 | for (Index = 0; Lan1[Index] != 0 && Lan1[Index] != ';'; Index++) {\r | |
2029 | if (Lan1[Index] != Lan2[Index]) {\r | |
2030 | //\r | |
2031 | // Return FALSE if any characters are different.\r | |
2032 | //\r | |
2033 | return FALSE;\r | |
2034 | }\r | |
2035 | }\r | |
2036 | \r | |
2037 | FreePool (Lan1);\r | |
2038 | FreePool (Lan2);\r | |
2039 | \r | |
2040 | //\r | |
2041 | // Only return TRUE if Language2[Index] is a Null-terminator which means\r | |
2042 | // the Primary Language in Language1 is the same length as Language2. If\r | |
2043 | // Language2[Index] is not a Null-terminator, then Language2 is longer than\r | |
2044 | // the Primary Language in Language1, and FALSE must be returned.\r | |
2045 | //\r | |
2046 | return (BOOLEAN) (Language2[Index] == 0);\r | |
2047 | }\r |