]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/HiiDatabaseDxe/String.c
Update build.exe after StrGather python script was changed.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / String.c
CommitLineData
93e3992d 1/** @file\r
e90b081a 2Implementation for EFI_HII_STRING_PROTOCOL.\r
3\r
93e3992d 4\r
5Copyright (c) 2007, Intel Corporation\r
6All rights reserved. This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
93e3992d 14**/\r
15\r
16\r
17#include "HiiDatabase.h"\r
18\r
19CHAR16 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
e90b081a 32 This is a internal function.\r
33\r
34\r
93e3992d 35 @param Private Hii database private structure.\r
36 @param StringPackage HII string package instance.\r
813acf3a 37 @param FontId Font identifer, which must be unique within the string package.\r
93e3992d 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
93e3992d 50BOOLEAN\r
51ReferFontInfoLocally (\r
52 IN HII_DATABASE_PRIVATE_DATA *Private,\r
53 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
813acf3a 54 IN UINT8 FontId,\r
93e3992d 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
93e3992d 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
813acf3a 88 LocalFont->FontId = FontId;\r
93e3992d 89 LocalFont->GlobalEntry = &GlobalFontInfo->Entry;\r
90 InsertTailList (&StringPackage->FontInfoList, &LocalFont->Entry);\r
91\r
93e3992d 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
e90b081a 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
93e3992d 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
93e3992d 114EFI_STATUS\r
115ConvertToUnicodeText (\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
96ff65a1 127 if (*BufferSize < StringSize || StringDest == NULL) {\r
93e3992d 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
e90b081a 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
93e3992d 149 @param StringSrc Points to current null-terminated string.\r
93e3992d 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
93e3992d 158EFI_STATUS\r
159GetUnicodeStringTextOrSize (\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
93e3992d 166 UINT8 *StringPtr;\r
167\r
168 ASSERT (StringSrc != NULL && BufferSize != NULL);\r
169\r
93e3992d 170 StringSize = sizeof (CHAR16);\r
171 StringPtr = StringSrc;\r
aa2e1536 172 while (ReadUnaligned16 ((UINT16 *) StringPtr) != 0) {\r
93e3992d 173 StringSize += sizeof (CHAR16);\r
174 StringPtr += sizeof (CHAR16);\r
175 }\r
176\r
813acf3a 177 if (*BufferSize < StringSize) {\r
178 *BufferSize = StringSize;\r
179 return EFI_BUFFER_TOO_SMALL;\r
180 }\r
93e3992d 181 if (StringDest != NULL) {\r
93e3992d 182 CopyMem (StringDest, StringSrc, StringSize);\r
93e3992d 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
e90b081a 193 This is a internal function.\r
194\r
93e3992d 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
93e3992d 205EFI_STATUS\r
206GetStringFontInfo (\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.\r
239 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_END).\r
240\r
241 @param Private Hii database private structure.\r
242 @param StringPackage Hii string package instance.\r
ac644614 243 @param StringId The string's id, which is unique within\r
93e3992d 244 PackageList.\r
245 @param BlockType Output the block type of found string block.\r
246 @param StringBlockAddr Output the block address of found string block.\r
247 @param StringTextOffset Offset, relative to the found block address, of\r
248 the string text information.\r
249 @param LastStringId Output the last string id when StringId = 0.\r
250\r
251 @retval EFI_SUCCESS The string text and font is retrieved\r
252 successfully.\r
253 @retval EFI_NOT_FOUND The specified text or font info can not be found\r
254 out.\r
255 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the\r
256 task.\r
257\r
258**/\r
259EFI_STATUS\r
260FindStringBlock (\r
261 IN HII_DATABASE_PRIVATE_DATA *Private,\r
262 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
263 IN EFI_STRING_ID StringId,\r
264 OUT UINT8 *BlockType, OPTIONAL\r
265 OUT UINT8 **StringBlockAddr, OPTIONAL\r
266 OUT UINTN *StringTextOffset, OPTIONAL\r
267 OUT EFI_STRING_ID *LastStringId OPTIONAL\r
268 )\r
269{\r
270 UINT8 *BlockHdr;\r
271 EFI_STRING_ID CurrentStringId;\r
272 UINTN BlockSize;\r
273 UINTN Index;\r
274 UINT8 *StringTextPtr;\r
275 UINTN Offset;\r
276 HII_FONT_INFO *LocalFont;\r
277 EFI_FONT_INFO *FontInfo;\r
278 HII_GLOBAL_FONT_INFO *GlobalFont;\r
279 UINTN FontInfoSize;\r
280 UINT16 StringCount;\r
281 UINT16 SkipCount;\r
282 EFI_HII_FONT_STYLE FontStyle;\r
283 UINT16 FontSize;\r
284 UINT8 Length8;\r
285 EFI_HII_SIBT_EXT2_BLOCK Ext2;\r
813acf3a 286 UINT8 FontId;\r
93e3992d 287 UINT32 Length32;\r
288 UINTN StringSize;\r
289 CHAR16 Zero;\r
290\r
291 ASSERT (StringPackage != NULL);\r
292 ASSERT (StringPackage->Signature == HII_STRING_PACKAGE_SIGNATURE);\r
293\r
294 CurrentStringId = 1;\r
295\r
296 if (StringId != (EFI_STRING_ID) (-1) && StringId != 0) {\r
297 ASSERT (BlockType != NULL && StringBlockAddr != NULL && StringTextOffset != NULL);\r
298 } else {\r
299 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r
300 }\r
301\r
302 ZeroMem (&Zero, sizeof (CHAR16));\r
303\r
304 //\r
305 // Parse the string blocks to get the string text and font.\r
306 //\r
307 BlockHdr = StringPackage->StringBlock;\r
308 BlockSize = 0;\r
309 Offset = 0;\r
310 while (*BlockHdr != EFI_HII_SIBT_END) {\r
311 switch (*BlockHdr) {\r
312 case EFI_HII_SIBT_STRING_SCSU:\r
313 Offset = sizeof (EFI_HII_STRING_BLOCK);\r
314 StringTextPtr = BlockHdr + Offset;\r
315 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);\r
316 CurrentStringId++;\r
317 break;\r
318\r
319 case EFI_HII_SIBT_STRING_SCSU_FONT:\r
320 Offset = sizeof (EFI_HII_SIBT_STRING_SCSU_FONT_BLOCK) - sizeof (UINT8);\r
321 StringTextPtr = BlockHdr + Offset;\r
322 BlockSize += Offset + AsciiStrSize ((CHAR8 *) StringTextPtr);\r
323 CurrentStringId++;\r
324 break;\r
325\r
326 case EFI_HII_SIBT_STRINGS_SCSU:\r
327 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));\r
328 StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_BLOCK) - sizeof (UINT8);\r
329 BlockSize += StringTextPtr - BlockHdr;\r
330\r
331 for (Index = 0; Index < StringCount; Index++) {\r
332 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);\r
333 if (CurrentStringId == StringId) {\r
334 *BlockType = *BlockHdr;\r
335 *StringBlockAddr = BlockHdr;\r
336 *StringTextOffset = StringTextPtr - BlockHdr;\r
337 return EFI_SUCCESS;\r
338 }\r
339 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);\r
340 CurrentStringId++;\r
341 }\r
342 break;\r
343\r
344 case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
345 CopyMem (\r
346 &StringCount,\r
347 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r
348 sizeof (UINT16)\r
349 );\r
350 StringTextPtr = BlockHdr + sizeof (EFI_HII_SIBT_STRINGS_SCSU_FONT_BLOCK) - sizeof (UINT8);\r
351 BlockSize += StringTextPtr - BlockHdr;\r
352\r
353 for (Index = 0; Index < StringCount; Index++) {\r
354 BlockSize += AsciiStrSize ((CHAR8 *) StringTextPtr);\r
355 if (CurrentStringId == StringId) {\r
356 *BlockType = *BlockHdr;\r
357 *StringBlockAddr = BlockHdr;\r
358 *StringTextOffset = StringTextPtr - BlockHdr;\r
359 return EFI_SUCCESS;\r
360 }\r
361 StringTextPtr = StringTextPtr + AsciiStrSize ((CHAR8 *) StringTextPtr);\r
362 CurrentStringId++;\r
363 }\r
364 break;\r
365\r
366 case EFI_HII_SIBT_STRING_UCS2:\r
367 Offset = sizeof (EFI_HII_STRING_BLOCK);\r
368 StringTextPtr = BlockHdr + Offset;\r
369 //\r
370 // Use StringSize to store the size of the specified string, including the NULL\r
371 // terminator.\r
372 //\r
373 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r
374 BlockSize += Offset + StringSize;\r
375 CurrentStringId++;\r
376 break;\r
377\r
378 case EFI_HII_SIBT_STRING_UCS2_FONT:\r
379 Offset = sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r
380 StringTextPtr = BlockHdr + Offset;\r
381 //\r
382 // Use StrSize 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_STRINGS_UCS2:\r
391 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_BLOCK) - sizeof (CHAR16);\r
392 StringTextPtr = BlockHdr + Offset;\r
393 BlockSize += Offset;\r
394 CopyMem (&StringCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));\r
395 for (Index = 0; Index < StringCount; Index++) {\r
396 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r
397 BlockSize += StringSize;\r
398 if (CurrentStringId == StringId) {\r
399 *BlockType = *BlockHdr;\r
400 *StringBlockAddr = BlockHdr;\r
401 *StringTextOffset = StringTextPtr - BlockHdr;\r
402 return EFI_SUCCESS;\r
403 }\r
404 StringTextPtr = StringTextPtr + StringSize;\r
405 CurrentStringId++;\r
406 }\r
407 break;\r
408\r
409 case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
410 Offset = sizeof (EFI_HII_SIBT_STRINGS_UCS2_FONT_BLOCK) - sizeof (CHAR16);\r
411 StringTextPtr = BlockHdr + Offset;\r
412 BlockSize += Offset;\r
413 CopyMem (\r
414 &StringCount,\r
415 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r
416 sizeof (UINT16)\r
417 );\r
418 for (Index = 0; Index < StringCount; Index++) {\r
419 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r
420 BlockSize += StringSize;\r
421 if (CurrentStringId == StringId) {\r
422 *BlockType = *BlockHdr;\r
423 *StringBlockAddr = BlockHdr;\r
424 *StringTextOffset = StringTextPtr - BlockHdr;\r
425 return EFI_SUCCESS;\r
426 }\r
427 StringTextPtr = StringTextPtr + StringSize;\r
428 CurrentStringId++;\r
429 }\r
430 break;\r
431\r
432 case EFI_HII_SIBT_DUPLICATE:\r
433 if (CurrentStringId == StringId) {\r
434 //\r
435 // Incoming StringId is an id of a duplicate string block.\r
436 // Update the StringId to be the previous string block.\r
437 // Go back to the header of string block to search.\r
438 //\r
439 CopyMem (\r
440 &StringId,\r
441 BlockHdr + sizeof (EFI_HII_STRING_BLOCK),\r
442 sizeof (EFI_STRING_ID)\r
443 );\r
444 ASSERT (StringId != CurrentStringId);\r
445 CurrentStringId = 1;\r
446 BlockSize = 0;\r
447 } else {\r
448 BlockSize += sizeof (EFI_HII_SIBT_DUPLICATE_BLOCK);\r
449 CurrentStringId++;\r
450 }\r
451 break;\r
452\r
453 case EFI_HII_SIBT_SKIP1:\r
454 SkipCount = (UINT16) (*(BlockHdr + sizeof (EFI_HII_STRING_BLOCK)));\r
455 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);\r
456 BlockSize += sizeof (EFI_HII_SIBT_SKIP1_BLOCK);\r
457 break;\r
458\r
459 case EFI_HII_SIBT_SKIP2:\r
460 CopyMem (&SkipCount, BlockHdr + sizeof (EFI_HII_STRING_BLOCK), sizeof (UINT16));\r
461 CurrentStringId = (UINT16) (CurrentStringId + SkipCount);\r
462 BlockSize += sizeof (EFI_HII_SIBT_SKIP2_BLOCK);\r
463 break;\r
464\r
465 case EFI_HII_SIBT_EXT1:\r
466 CopyMem (\r
467 &Length8,\r
468 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r
469 sizeof (UINT8)\r
470 );\r
471 BlockSize += Length8;\r
472 break;\r
473\r
474 case EFI_HII_SIBT_EXT2:\r
475 CopyMem (&Ext2, BlockHdr, sizeof (EFI_HII_SIBT_EXT2_BLOCK));\r
476 if (Ext2.BlockType2 == EFI_HII_SIBT_FONT && StringId == (EFI_STRING_ID) (-1)) {\r
477 //\r
478 // Find the relationship between global font info and the font info of\r
479 // this EFI_HII_SIBT_FONT block then backup its information in local package.\r
480 //\r
813acf3a 481 BlockHdr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r
482 CopyMem (&FontId, BlockHdr, sizeof (UINT8));\r
483 BlockHdr += sizeof (UINT8);\r
93e3992d 484 CopyMem (&FontSize, BlockHdr, sizeof (UINT16));\r
485 BlockHdr += sizeof (UINT16);\r
486 CopyMem (&FontStyle, BlockHdr, sizeof (EFI_HII_FONT_STYLE));\r
487 BlockHdr += sizeof (EFI_HII_FONT_STYLE);\r
488 GetUnicodeStringTextOrSize (NULL, BlockHdr, &StringSize);\r
489\r
490 FontInfoSize = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + StringSize;\r
491 FontInfo = (EFI_FONT_INFO *) AllocateZeroPool (FontInfoSize);\r
492 if (FontInfo == NULL) {\r
493 return EFI_OUT_OF_RESOURCES;\r
494 }\r
495 FontInfo->FontStyle = FontStyle;\r
496 FontInfo->FontSize = FontSize;\r
497 CopyMem (FontInfo->FontName, BlockHdr, StringSize);\r
498\r
813acf3a 499 //\r
500 // If find the corresponding global font info, save the relationship.\r
501 // Otherwise ignore this EFI_HII_SIBT_FONT block.\r
502 //\r
93e3992d 503 if (IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont)) {\r
813acf3a 504 ReferFontInfoLocally (Private, StringPackage, FontId, TRUE, GlobalFont, &LocalFont);\r
93e3992d 505 }\r
506\r
507 //\r
813acf3a 508 // Since string package tool set FontId initially to 0 and increases it\r
509 // progressively by one, StringPackage->FondId always represents an unique\r
510 // and available FontId.\r
511 // \r
512 StringPackage->FontId++;\r
513\r
676df92c 514 FreePool (FontInfo);\r
93e3992d 515 }\r
516\r
517 BlockSize += Ext2.Length;\r
518\r
519 break;\r
520\r
521 case EFI_HII_SIBT_EXT4:\r
522 CopyMem (\r
523 &Length32,\r
524 BlockHdr + sizeof (EFI_HII_STRING_BLOCK) + sizeof (UINT8),\r
525 sizeof (UINT32)\r
526 );\r
527\r
528 BlockSize += Length32;\r
529 break;\r
530\r
531 default:\r
532 break;\r
533 }\r
534\r
535 if (StringId > 0) {\r
536 if (StringId == CurrentStringId - 1) {\r
537 *BlockType = *BlockHdr;\r
538 *StringBlockAddr = BlockHdr;\r
539 *StringTextOffset = Offset;\r
540 return EFI_SUCCESS;\r
541 }\r
542\r
543 if (StringId < CurrentStringId - 1) {\r
544 return EFI_NOT_FOUND;\r
545 }\r
546 }\r
547 BlockHdr = StringPackage->StringBlock + BlockSize;\r
548\r
549 }\r
550\r
551 if (StringId == (EFI_STRING_ID) (-1)) {\r
552 return EFI_SUCCESS;\r
553 }\r
554\r
555 if (StringId == 0 && LastStringId != NULL) {\r
556 *LastStringId = CurrentStringId;\r
557 return EFI_SUCCESS;\r
558 }\r
559\r
560 return EFI_NOT_FOUND;\r
561}\r
562\r
563\r
564/**\r
565 Parse all string blocks to get a string specified by StringId.\r
566\r
e90b081a 567 This is a internal function.\r
568\r
93e3992d 569 @param Private Hii database private structure.\r
570 @param StringPackage Hii string package instance.\r
ac644614 571 @param StringId The string's id, which is unique within\r
93e3992d 572 PackageList.\r
573 @param String Points to retrieved null-terminated string.\r
574 @param StringSize On entry, points to the size of the buffer pointed\r
575 to by String, in bytes. On return, points to the\r
576 length of the string, in bytes.\r
577 @param StringFontInfo If not NULL, allocate a buffer to record the\r
578 output font info. It's caller's responsibility to\r
579 free this buffer.\r
580\r
581 @retval EFI_SUCCESS The string text and font is retrieved\r
582 successfully.\r
583 @retval EFI_NOT_FOUND The specified text or font info can not be found\r
584 out.\r
585 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to\r
586 hold the string.\r
587\r
588**/\r
93e3992d 589EFI_STATUS\r
590GetStringWorker (\r
591 IN HII_DATABASE_PRIVATE_DATA *Private,\r
592 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
593 IN EFI_STRING_ID StringId,\r
594 OUT EFI_STRING String,\r
595 IN OUT UINTN *StringSize,\r
596 OUT EFI_FONT_INFO **StringFontInfo OPTIONAL\r
597 )\r
598{\r
599 UINT8 *StringTextPtr;\r
600 UINT8 BlockType;\r
601 UINT8 *StringBlockAddr;\r
602 UINTN StringTextOffset;\r
603 EFI_STATUS Status;\r
604 UINT8 FontId;\r
605\r
606 ASSERT (StringPackage != NULL && StringSize != NULL);\r
607 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r
608\r
609 //\r
610 // Find the specified string block\r
611 //\r
612 Status = FindStringBlock (\r
613 Private,\r
614 StringPackage,\r
615 StringId,\r
616 &BlockType,\r
617 &StringBlockAddr,\r
618 &StringTextOffset,\r
619 NULL\r
620 );\r
621 if (EFI_ERROR (Status)) {\r
622 return Status;\r
623 }\r
624\r
625 //\r
626 // Get the string text.\r
627 //\r
628 StringTextPtr = StringBlockAddr + StringTextOffset;\r
629 switch (BlockType) {\r
630 case EFI_HII_SIBT_STRING_SCSU:\r
631 case EFI_HII_SIBT_STRING_SCSU_FONT:\r
632 case EFI_HII_SIBT_STRINGS_SCSU:\r
633 case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
634 Status = ConvertToUnicodeText (String, (CHAR8 *) StringTextPtr, StringSize);\r
635 break;\r
636 case EFI_HII_SIBT_STRING_UCS2:\r
637 case EFI_HII_SIBT_STRING_UCS2_FONT:\r
638 case EFI_HII_SIBT_STRINGS_UCS2:\r
639 case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
640 Status = GetUnicodeStringTextOrSize (String, StringTextPtr, StringSize);\r
641 break;\r
642 default:\r
643 return EFI_NOT_FOUND;\r
644 }\r
645 if (EFI_ERROR (Status)) {\r
646 return Status;\r
647 }\r
648\r
649 //\r
813acf3a 650 // Get the string font. The FontId 0 is the default font for those string blocks which \r
651 // do not specify a font identifier. If default font is not specified, return NULL.\r
93e3992d 652 //\r
653 if (StringFontInfo != NULL) {\r
654 switch (BlockType) {\r
655 case EFI_HII_SIBT_STRING_SCSU_FONT:\r
656 case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
657 case EFI_HII_SIBT_STRING_UCS2_FONT:\r
658 case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
659 FontId = *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK));\r
93e3992d 660 break;\r
661 default:\r
813acf3a 662 FontId = 0;\r
663 }\r
664 Status = GetStringFontInfo (StringPackage, FontId, StringFontInfo);\r
665 if (Status == EFI_NOT_FOUND) {\r
666 *StringFontInfo = NULL;\r
93e3992d 667 }\r
668 }\r
669\r
670 return EFI_SUCCESS;\r
671}\r
672\r
673\r
674/**\r
675 Parse all string blocks to set a String specified by StringId.\r
676\r
e90b081a 677 This is a internal function.\r
678\r
93e3992d 679 @param Private HII database driver private structure.\r
680 @param StringPackage HII string package instance.\r
ac644614 681 @param StringId The string's id, which is unique within\r
93e3992d 682 PackageList.\r
683 @param String Points to the new null-terminated string.\r
684 @param StringFontInfo Points to the input font info.\r
685\r
686 @retval EFI_SUCCESS The string was updated successfully.\r
687 @retval EFI_NOT_FOUND The string specified by StringId is not in the\r
688 database.\r
689 @retval EFI_INVALID_PARAMETER The String or Language was NULL.\r
690 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in\r
691 current database.\r
692 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the\r
693 task.\r
694\r
695**/\r
93e3992d 696EFI_STATUS\r
697SetStringWorker (\r
698 IN HII_DATABASE_PRIVATE_DATA *Private,\r
699 IN OUT HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
700 IN EFI_STRING_ID StringId,\r
701 IN EFI_STRING String,\r
702 IN EFI_FONT_INFO *StringFontInfo OPTIONAL\r
703 )\r
704{\r
705 UINT8 *StringTextPtr;\r
706 UINT8 BlockType;\r
707 UINT8 *StringBlockAddr;\r
708 UINTN StringTextOffset;\r
709 EFI_STATUS Status;\r
710 UINT8 *Block;\r
711 UINT8 *BlockPtr;\r
712 UINTN BlockSize;\r
713 UINTN OldBlockSize;\r
714 HII_FONT_INFO *LocalFont;\r
715 HII_GLOBAL_FONT_INFO *GlobalFont;\r
716 BOOLEAN Referred;\r
717 EFI_HII_SIBT_EXT2_BLOCK Ext2;\r
718 UINTN StringSize;\r
719 UINTN TmpSize;\r
720\r
721\r
722 ASSERT (Private != NULL && StringPackage != NULL && String != NULL);\r
723 ASSERT (Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);\r
724 //\r
725 // Find the specified string block\r
726 //\r
727 Status = FindStringBlock (\r
728 Private,\r
729 StringPackage,\r
730 StringId,\r
731 &BlockType,\r
732 &StringBlockAddr,\r
733 &StringTextOffset,\r
734 NULL\r
735 );\r
736 if (EFI_ERROR (Status)) {\r
737 return Status;\r
738 }\r
739\r
740 LocalFont = NULL;\r
741 GlobalFont = NULL;\r
742 Referred = FALSE;\r
743\r
744 //\r
813acf3a 745 // The input StringFontInfo should exist in current database if specified.\r
93e3992d 746 //\r
747 if (StringFontInfo != NULL) {\r
93e3992d 748 if (!IsFontInfoExisted (Private, StringFontInfo, NULL, NULL, &GlobalFont)) {\r
749 return EFI_INVALID_PARAMETER;\r
750 } else {\r
813acf3a 751 Referred = ReferFontInfoLocally (\r
752 Private, \r
753 StringPackage, \r
754 StringPackage->FontId, \r
755 FALSE, \r
756 GlobalFont, \r
757 &LocalFont\r
758 );\r
759 if (!Referred) {\r
760 StringPackage->FontId++;\r
761 }\r
93e3992d 762 }\r
93e3992d 763 //\r
813acf3a 764 // Update the FontId of the specified string block to input font info.\r
93e3992d 765 //\r
766 switch (BlockType) {\r
813acf3a 767 case EFI_HII_SIBT_STRING_SCSU_FONT: \r
93e3992d 768 case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
769 case EFI_HII_SIBT_STRING_UCS2_FONT:\r
770 case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
771 *(StringBlockAddr + sizeof (EFI_HII_STRING_BLOCK)) = LocalFont->FontId;\r
772 break;\r
773 default:\r
813acf3a 774 //\r
775 // When modify the font info of these blocks, the block type should be updated\r
776 // to contain font info thus the whole structure should be revised.\r
777 // It is recommended to use tool to modify the block type not in the code.\r
778 // \r
779 return EFI_UNSUPPORTED;\r
93e3992d 780 }\r
93e3992d 781 }\r
782\r
783 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r
784\r
785 //\r
813acf3a 786 // Set the string text and font.\r
93e3992d 787 //\r
788 StringTextPtr = StringBlockAddr + StringTextOffset;\r
789 switch (BlockType) {\r
790 case EFI_HII_SIBT_STRING_SCSU:\r
791 case EFI_HII_SIBT_STRING_SCSU_FONT:\r
792 case EFI_HII_SIBT_STRINGS_SCSU:\r
793 case EFI_HII_SIBT_STRINGS_SCSU_FONT:\r
794 BlockSize = OldBlockSize + StrLen (String);\r
795 BlockSize -= AsciiStrLen ((CHAR8 *) StringTextPtr);\r
796 Block = AllocateZeroPool (BlockSize);\r
797 if (Block == NULL) {\r
798 return EFI_OUT_OF_RESOURCES;\r
799 }\r
800\r
801 CopyMem (Block, StringPackage->StringBlock, StringTextPtr - StringPackage->StringBlock);\r
802 BlockPtr = Block + (StringTextPtr - StringPackage->StringBlock);\r
803\r
804 while (*String != 0) {\r
805 *BlockPtr++ = (CHAR8) *String++;\r
806 }\r
807 *BlockPtr++ = 0;\r
808\r
809 \r
810 TmpSize = OldBlockSize - (StringTextPtr - StringPackage->StringBlock) - AsciiStrSize ((CHAR8 *) StringTextPtr);\r
811 CopyMem (\r
812 BlockPtr,\r
813 StringTextPtr + AsciiStrSize ((CHAR8 *)StringTextPtr),\r
814 TmpSize\r
815 );\r
816\r
676df92c 817 FreePool (StringPackage->StringBlock);\r
93e3992d 818 StringPackage->StringBlock = Block;\r
819 StringPackage->StringPkgHdr->Header.Length += (UINT32) (BlockSize - OldBlockSize);\r
820 break;\r
821\r
822 case EFI_HII_SIBT_STRING_UCS2:\r
823 case EFI_HII_SIBT_STRING_UCS2_FONT:\r
824 case EFI_HII_SIBT_STRINGS_UCS2:\r
825 case EFI_HII_SIBT_STRINGS_UCS2_FONT:\r
826 //\r
827 // Use StrSize to store the size of the specified string, including the NULL\r
828 // terminator.\r
829 //\r
830 GetUnicodeStringTextOrSize (NULL, StringTextPtr, &StringSize);\r
831\r
832 BlockSize = OldBlockSize + StrSize (String) - StringSize;\r
833 Block = AllocateZeroPool (BlockSize);\r
834 if (Block == NULL) {\r
835 return EFI_OUT_OF_RESOURCES;\r
836 }\r
837\r
838 CopyMem (Block, StringPackage->StringBlock, StringTextPtr - StringPackage->StringBlock);\r
839 BlockPtr = Block + (StringTextPtr - StringPackage->StringBlock);\r
840\r
841 CopyMem (BlockPtr, String, StrSize (String));\r
842 BlockPtr += StrSize (String);\r
843\r
844 CopyMem (\r
845 BlockPtr,\r
846 StringTextPtr + StringSize,\r
847 OldBlockSize - (StringTextPtr - StringPackage->StringBlock) - StringSize\r
848 );\r
849\r
676df92c 850 FreePool (StringPackage->StringBlock);\r
93e3992d 851 StringPackage->StringBlock = Block;\r
852 StringPackage->StringPkgHdr->Header.Length += (UINT32) (BlockSize - OldBlockSize);\r
853 break;\r
854\r
855 default:\r
856 return EFI_NOT_FOUND;\r
857 }\r
858\r
859 //\r
860 // Insert a new EFI_HII_SIBT_FONT_BLOCK to the header of string block, if incoming\r
861 // StringFontInfo does not exist in current string package.\r
862 //\r
863 // This new block does not impact on the value of StringId.\r
864 //\r
865 //\r
866 if (StringFontInfo == NULL || Referred) {\r
867 return EFI_SUCCESS;\r
868 }\r
869\r
870 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r
871 BlockSize = OldBlockSize + sizeof (EFI_HII_SIBT_FONT_BLOCK) - sizeof (CHAR16) +\r
872 StrSize (GlobalFont->FontInfo->FontName);\r
873\r
874 Block = AllocateZeroPool (BlockSize);\r
875 if (Block == NULL) {\r
876 return EFI_OUT_OF_RESOURCES;\r
877 }\r
878\r
879 BlockPtr = Block;\r
880 Ext2.Header.BlockType = EFI_HII_SIBT_EXT2;\r
881 Ext2.BlockType2 = EFI_HII_SIBT_FONT;\r
882 Ext2.Length = (UINT16) (BlockSize - OldBlockSize);\r
883 CopyMem (BlockPtr, &Ext2, sizeof (EFI_HII_SIBT_EXT2_BLOCK));\r
884 BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r
885\r
886 *BlockPtr = LocalFont->FontId;\r
887 BlockPtr += sizeof (UINT8);\r
888 CopyMem (BlockPtr, &GlobalFont->FontInfo->FontSize, sizeof (UINT16));\r
889 BlockPtr += sizeof (UINT16);\r
890 CopyMem (BlockPtr, &GlobalFont->FontInfo->FontStyle, sizeof (UINT32));\r
891 BlockPtr += sizeof (UINT32);\r
892 CopyMem (\r
893 BlockPtr,\r
894 GlobalFont->FontInfo->FontName,\r
895 StrSize (GlobalFont->FontInfo->FontName)\r
896 );\r
897 BlockPtr += StrSize (GlobalFont->FontInfo->FontName);\r
898\r
899 CopyMem (BlockPtr, StringPackage->StringBlock, OldBlockSize);\r
900\r
676df92c 901 FreePool (StringPackage->StringBlock);\r
93e3992d 902 StringPackage->StringBlock = Block;\r
903 StringPackage->StringPkgHdr->Header.Length += Ext2.Length;\r
904\r
905 return EFI_SUCCESS;\r
906\r
907}\r
908\r
909\r
910/**\r
911 This function adds the string String to the group of strings owned by PackageList, with the\r
912 specified font information StringFontInfo and returns a new string id.\r
913\r
914 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r
915 @param PackageList Handle of the package list where this string will\r
916 be added.\r
917 @param StringId On return, contains the new strings id, which is\r
918 unique within PackageList.\r
919 @param Language Points to the language for the new string.\r
920 @param LanguageName Points to the printable language name to associate\r
921 with the passed in Language field.If LanguageName\r
922 is not NULL and the string package header's\r
923 LanguageName associated with a given Language is\r
924 not zero, the LanguageName being passed in will\r
925 be ignored.\r
926 @param String Points to the new null-terminated string.\r
ac644614 927 @param StringFontInfo Points to the new string's font information or\r
93e3992d 928 NULL if the string should have the default system\r
929 font, size and style.\r
930\r
931 @retval EFI_SUCCESS The new string was added successfully.\r
932 @retval EFI_NOT_FOUND The specified PackageList could not be found in\r
933 database.\r
934 @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources.\r
935 @retval EFI_INVALID_PARAMETER String is NULL or StringId is NULL or Language is\r
936 NULL.\r
937 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in\r
938 current database.\r
939\r
940**/\r
941EFI_STATUS\r
942EFIAPI\r
943HiiNewString (\r
944 IN CONST EFI_HII_STRING_PROTOCOL *This,\r
945 IN EFI_HII_HANDLE PackageList,\r
946 OUT EFI_STRING_ID *StringId,\r
947 IN CONST CHAR8 *Language,\r
948 IN CONST CHAR16 *LanguageName, OPTIONAL\r
949 IN CONST EFI_STRING String,\r
950 IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL\r
951 )\r
952{\r
953 EFI_STATUS Status;\r
954 LIST_ENTRY *Link;\r
955 BOOLEAN Matched;\r
956 HII_DATABASE_PRIVATE_DATA *Private;\r
957 HII_DATABASE_RECORD *DatabaseRecord;\r
958 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
959 HII_STRING_PACKAGE_INSTANCE *StringPackage;\r
960 UINT32 HeaderSize;\r
961 UINT32 BlockSize;\r
962 UINT32 OldBlockSize;\r
963 UINT8 *StringBlock;\r
964 UINT8 *BlockPtr;\r
965 UINT32 Ucs2BlockSize;\r
966 UINT32 FontBlockSize;\r
967 UINT32 Ucs2FontBlockSize;\r
968 EFI_HII_SIBT_EXT2_BLOCK Ext2;\r
969 HII_FONT_INFO *LocalFont;\r
970 HII_GLOBAL_FONT_INFO *GlobalFont;\r
844390f7 971 CHAR8 *MatchedLanguage;\r
93e3992d 972\r
973 if (This == NULL || String == NULL || StringId == NULL || Language == NULL || PackageList == NULL) {\r
974 return EFI_INVALID_PARAMETER;\r
975 }\r
976\r
977 if (!IsHiiHandleValid (PackageList)) {\r
978 return EFI_NOT_FOUND;\r
979 }\r
980\r
981 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
982 GlobalFont = NULL;\r
983\r
984 //\r
985 // If StringFontInfo specify a paritcular font, it should exist in current database.\r
986 //\r
987 if (StringFontInfo != NULL) {\r
988 if (!IsFontInfoExisted (Private, (EFI_FONT_INFO *) StringFontInfo, NULL, NULL, &GlobalFont)) {\r
989 return EFI_INVALID_PARAMETER;\r
990 }\r
991 }\r
992\r
993 //\r
994 // Get the matching package list.\r
995 //\r
996 PackageListNode = NULL;\r
997 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r
998 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
999 if (DatabaseRecord->Handle == PackageList) {\r
1000 PackageListNode = DatabaseRecord->PackageList;\r
1001 break;\r
1002 }\r
1003 }\r
1004 if (PackageListNode == NULL) {\r
1005 return EFI_NOT_FOUND;\r
1006 }\r
1007\r
1008 //\r
1009 // Try to get the matching string package. Create a new string package when failed.\r
1010 //\r
1011 StringPackage = NULL;\r
1012 Matched = FALSE;\r
1013 for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r
1014 Link != &PackageListNode->StringPkgHdr;\r
1015 Link = Link->ForwardLink\r
1016 ) {\r
1017 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
844390f7 1018 MatchedLanguage = GetBestLanguage (StringPackage->StringPkgHdr->Language, FALSE, (CHAR8 *) Language, NULL);\r
1019 if (MatchedLanguage != NULL) {\r
1020 FreePool (MatchedLanguage);\r
93e3992d 1021 Matched = TRUE;\r
1022 break;\r
1023 }\r
1024 }\r
1025\r
1026 if (!Matched) {\r
1027 //\r
1028 // LanguageName is required to create a new string package.\r
1029 //\r
1030 if (LanguageName == NULL) {\r
1031 return EFI_INVALID_PARAMETER;\r
1032 }\r
1033\r
1034 StringPackage = AllocateZeroPool (sizeof (HII_STRING_PACKAGE_INSTANCE));\r
1035 if (StringPackage == NULL) {\r
1036 return EFI_OUT_OF_RESOURCES;\r
1037 }\r
1038\r
1039 StringPackage->Signature = HII_STRING_PACKAGE_SIGNATURE;\r
1040 StringPackage->FontId = 0;\r
1041 InitializeListHead (&StringPackage->FontInfoList);\r
1042\r
1043 //\r
1044 // Fill in the string package header\r
1045 //\r
1046 HeaderSize = (UINT32) (AsciiStrSize ((CHAR8 *) Language) - 1 + sizeof (EFI_HII_STRING_PACKAGE_HDR));\r
1047 StringPackage->StringPkgHdr = AllocateZeroPool (HeaderSize);\r
1048 if (StringPackage->StringPkgHdr == NULL) {\r
676df92c 1049 FreePool (StringPackage);\r
93e3992d 1050 return EFI_OUT_OF_RESOURCES;\r
1051 }\r
1052 StringPackage->StringPkgHdr->Header.Type = EFI_HII_PACKAGE_STRINGS;\r
1053 StringPackage->StringPkgHdr->HdrSize = HeaderSize;\r
1054 StringPackage->StringPkgHdr->StringInfoOffset = HeaderSize;\r
1055 CopyMem (StringPackage->StringPkgHdr->LanguageWindow, mLanguageWindow, 16 * sizeof (CHAR16));;\r
1056 StringPackage->StringPkgHdr->LanguageName = 1;\r
1057 AsciiStrCpy (StringPackage->StringPkgHdr->Language, (CHAR8 *) Language);\r
1058\r
1059 //\r
1060 // Calculate the length of the string blocks, including string block to record\r
1061 // printable language full name and EFI_HII_SIBT_END_BLOCK.\r
1062 //\r
1063 Ucs2BlockSize = (UINT32) (StrSize ((CHAR16 *) LanguageName) +\r
1064 sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK) - sizeof (CHAR16));\r
1065\r
1066 BlockSize = Ucs2BlockSize + sizeof (EFI_HII_SIBT_END_BLOCK);\r
1067 StringPackage->StringBlock = (UINT8 *) AllocateZeroPool (BlockSize);\r
1068 if (StringPackage->StringBlock == NULL) {\r
676df92c 1069 FreePool (StringPackage->StringPkgHdr);\r
1070 FreePool (StringPackage);\r
93e3992d 1071 return EFI_OUT_OF_RESOURCES;\r
1072 }\r
1073\r
1074 //\r
1075 // Insert the string block of printable language full name\r
1076 //\r
1077 BlockPtr = StringPackage->StringBlock;\r
1078 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r
1079 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r
1080 CopyMem (BlockPtr, (EFI_STRING) LanguageName, StrSize ((EFI_STRING) LanguageName));\r
1081 BlockPtr += StrSize ((EFI_STRING) LanguageName);\r
1082\r
1083 //\r
1084 // Insert the end block\r
1085 //\r
1086 *BlockPtr = EFI_HII_SIBT_END;\r
1087\r
1088 //\r
1089 // Append this string package node to string package array in this package list.\r
1090 //\r
1091 StringPackage->StringPkgHdr->Header.Length = HeaderSize + BlockSize;\r
1092 PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length;\r
1093 InsertTailList (&PackageListNode->StringPkgHdr, &StringPackage->StringEntry);\r
1094\r
1095 }\r
1096\r
1097 //\r
1098 // Create a string block and corresponding font block if exists, then append them\r
1099 // to the end of the string package.\r
1100 //\r
1101 Status = FindStringBlock (\r
1102 Private,\r
1103 StringPackage,\r
1104 0,\r
1105 NULL,\r
1106 NULL,\r
1107 NULL,\r
1108 StringId\r
1109 );\r
1110 if (EFI_ERROR (Status)) {\r
1111 return Status;\r
1112 }\r
1113\r
1114 OldBlockSize = StringPackage->StringPkgHdr->Header.Length - StringPackage->StringPkgHdr->HdrSize;\r
1115\r
1116 if (StringFontInfo == NULL) {\r
1117 //\r
1118 // Create a EFI_HII_SIBT_STRING_UCS2_BLOCK since font info is not specified.\r
1119 //\r
1120\r
1121 Ucs2BlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_BLOCK)\r
1122 - sizeof (CHAR16));\r
1123\r
1124 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2BlockSize);\r
1125 if (StringBlock == NULL) {\r
1126 return EFI_OUT_OF_RESOURCES;\r
1127 }\r
1128 //\r
1129 // Copy original string blocks, except the EFI_HII_SIBT_END.\r
1130 //\r
1131 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r
1132 //\r
1133 // Create a EFI_HII_SIBT_STRING_UCS2 block\r
1134 //\r
1135 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r
1136 *BlockPtr = EFI_HII_SIBT_STRING_UCS2;\r
1137 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r
1138 CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));\r
1139 BlockPtr += StrSize ((EFI_STRING) String);\r
1140\r
1141 //\r
1142 // Append a EFI_HII_SIBT_END block to the end.\r
1143 //\r
1144 *BlockPtr = EFI_HII_SIBT_END;\r
676df92c 1145 FreePool (StringPackage->StringBlock);\r
93e3992d 1146 StringPackage->StringBlock = StringBlock;\r
1147 StringPackage->StringPkgHdr->Header.Length += Ucs2BlockSize;\r
1148 PackageListNode->PackageListHdr.PackageLength += Ucs2BlockSize;\r
1149\r
1150 } else {\r
1151 //\r
1152 // StringFontInfo is specified here. If there is a EFI_HII_SIBT_FONT_BLOCK\r
1153 // which refers to this font info, create a EFI_HII_SIBT_STRING_UCS2_FONT block\r
1154 // only. Otherwise create a EFI_HII_SIBT_FONT block with a EFI_HII_SIBT_STRING\r
1155 // _UCS2_FONT block.\r
1156 //\r
1157 Ucs2FontBlockSize = (UINT32) (StrSize (String) + sizeof (EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK) -\r
1158 sizeof (CHAR16));\r
813acf3a 1159 if (ReferFontInfoLocally (Private, StringPackage, StringPackage->FontId, FALSE, GlobalFont, &LocalFont)) {\r
93e3992d 1160 //\r
1161 // Create a EFI_HII_SIBT_STRING_UCS2_FONT block only.\r
1162 //\r
1163 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + Ucs2FontBlockSize);\r
1164 if (StringBlock == NULL) {\r
1165 return EFI_OUT_OF_RESOURCES;\r
1166 }\r
1167 //\r
1168 // Copy original string blocks, except the EFI_HII_SIBT_END.\r
1169 //\r
1170 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r
1171 //\r
1172 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r
1173 //\r
1174 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r
1175 *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r
1176 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r
1177 *BlockPtr = LocalFont->FontId;\r
1178 BlockPtr += sizeof (UINT8);\r
1179 CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));\r
1180 BlockPtr += StrSize ((EFI_STRING) String);\r
1181\r
1182 //\r
1183 // Append a EFI_HII_SIBT_END block to the end.\r
1184 //\r
1185 *BlockPtr = EFI_HII_SIBT_END;\r
676df92c 1186 FreePool (StringPackage->StringBlock);\r
93e3992d 1187 StringPackage->StringBlock = StringBlock;\r
1188 StringPackage->StringPkgHdr->Header.Length += Ucs2FontBlockSize;\r
1189 PackageListNode->PackageListHdr.PackageLength += Ucs2FontBlockSize;\r
1190\r
1191 } else {\r
1192 //\r
1193 // EFI_HII_SIBT_FONT_BLOCK does not exist in current string package, so\r
1194 // create a EFI_HII_SIBT_FONT block to record the font info, then generate\r
1195 // a EFI_HII_SIBT_STRING_UCS2_FONT block to record the incoming string.\r
1196 //\r
1197 FontBlockSize = (UINT32) (StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName) +\r
1198 sizeof (EFI_HII_SIBT_FONT_BLOCK) - sizeof (CHAR16));\r
1199 StringBlock = (UINT8 *) AllocateZeroPool (OldBlockSize + FontBlockSize + Ucs2FontBlockSize);\r
1200 if (StringBlock == NULL) {\r
1201 return EFI_OUT_OF_RESOURCES;\r
1202 }\r
1203 //\r
1204 // Copy original string blocks, except the EFI_HII_SIBT_END.\r
1205 //\r
1206 CopyMem (StringBlock, StringPackage->StringBlock, OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK));\r
1207\r
1208 //\r
1209 // Create a EFI_HII_SIBT_FONT block firstly and then backup its info in string\r
1210 // package instance for future reference.\r
1211 //\r
1212 BlockPtr = StringBlock + OldBlockSize - sizeof (EFI_HII_SIBT_END_BLOCK);\r
1213\r
1214 Ext2.Header.BlockType = EFI_HII_SIBT_EXT2;\r
1215 Ext2.BlockType2 = EFI_HII_SIBT_FONT;\r
1216 Ext2.Length = (UINT16) FontBlockSize;\r
1217 CopyMem (BlockPtr, &Ext2, sizeof (EFI_HII_SIBT_EXT2_BLOCK));\r
1218 BlockPtr += sizeof (EFI_HII_SIBT_EXT2_BLOCK);\r
1219\r
1220 *BlockPtr = LocalFont->FontId;\r
1221 BlockPtr += sizeof (UINT8);\r
1222 CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontSize, sizeof (UINT16));\r
1223 BlockPtr += sizeof (UINT16);\r
1224 CopyMem (BlockPtr, &((EFI_FONT_INFO *) StringFontInfo)->FontStyle, sizeof (EFI_HII_FONT_STYLE));\r
1225 BlockPtr += sizeof (EFI_HII_FONT_STYLE);\r
1226 CopyMem (\r
1227 BlockPtr,\r
1228 &((EFI_FONT_INFO *) StringFontInfo)->FontName,\r
1229 StrSize (((EFI_FONT_INFO *) StringFontInfo)->FontName)\r
1230 );\r
1231\r
1232 //\r
1233 // Create a EFI_HII_SIBT_STRING_UCS2_FONT_BLOCK\r
1234 //\r
1235 *BlockPtr = EFI_HII_SIBT_STRING_UCS2_FONT;\r
1236 BlockPtr += sizeof (EFI_HII_STRING_BLOCK);\r
1237 *BlockPtr = LocalFont->FontId;\r
1238 BlockPtr += sizeof (UINT8);\r
1239 CopyMem (BlockPtr, (EFI_STRING) String, StrSize ((EFI_STRING) String));\r
1240 BlockPtr += StrSize ((EFI_STRING) String);\r
1241\r
1242 //\r
1243 // Append a EFI_HII_SIBT_END block to the end.\r
1244 //\r
1245 *BlockPtr = EFI_HII_SIBT_END;\r
676df92c 1246 FreePool (StringPackage->StringBlock);\r
93e3992d 1247 StringPackage->StringBlock = StringBlock;\r
1248 StringPackage->StringPkgHdr->Header.Length += FontBlockSize + Ucs2FontBlockSize;\r
1249 PackageListNode->PackageListHdr.PackageLength += FontBlockSize + Ucs2FontBlockSize;\r
813acf3a 1250\r
1251 //\r
1252 // Increase the FontId to make it unique since we already add \r
1253 // a EFI_HII_SIBT_FONT block to this string package.\r
1254 //\r
1255 StringPackage->FontId++;\r
93e3992d 1256 }\r
1257 }\r
1258\r
8d00a0f1 1259 //\r
1260 // Trigger any registered notification function\r
1261 //\r
1262 if (!Matched) { \r
1263 return InvokeRegisteredFunction (\r
1264 Private,\r
1265 EFI_HII_DATABASE_NOTIFY_NEW_PACK,\r
1266 (VOID *) StringPackage,\r
1267 EFI_HII_PACKAGE_STRINGS,\r
1268 PackageList\r
1269 );\r
1270 }\r
1271\r
93e3992d 1272 return EFI_SUCCESS;\r
1273}\r
1274\r
1275\r
1276/**\r
1277 This function retrieves the string specified by StringId which is associated\r
1278 with the specified PackageList in the language Language and copies it into\r
1279 the buffer specified by String.\r
1280\r
1281 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r
1282 @param Language Points to the language for the retrieved string.\r
1283 @param PackageList The package list in the HII database to search for\r
1284 the specified string.\r
1285 @param StringId The string's id, which is unique within\r
1286 PackageList.\r
1287 @param String Points to the new null-terminated string.\r
1288 @param StringSize On entry, points to the size of the buffer pointed\r
1289 to by String, in bytes. On return, points to the\r
1290 length of the string, in bytes.\r
ac644614 1291 @param StringFontInfo If not NULL, points to the string's font\r
93e3992d 1292 information. It's caller's responsibility to free\r
1293 this buffer.\r
1294\r
1295 @retval EFI_SUCCESS The string was returned successfully.\r
1296 @retval EFI_NOT_FOUND The string specified by StringId is not available.\r
1297 @retval EFI_NOT_FOUND The string specified by StringId is available but\r
813acf3a 1298 not in the specified language.\r
1299 The specified PackageList is not in the database.\r
1300 @retval EFI_INVALID_LANGUAGE - The string specified by StringId is available but\r
93e3992d 1301 @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringSize is too small to\r
1302 hold the string.\r
1303 @retval EFI_INVALID_PARAMETER The String or Language or StringSize was NULL.\r
1304 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the\r
1305 request.\r
1306\r
1307**/\r
1308EFI_STATUS\r
1309EFIAPI\r
1310HiiGetString (\r
1311 IN CONST EFI_HII_STRING_PROTOCOL *This,\r
1312 IN CONST CHAR8 *Language,\r
1313 IN EFI_HII_HANDLE PackageList,\r
1314 IN EFI_STRING_ID StringId,\r
1315 OUT EFI_STRING String,\r
1316 IN OUT UINTN *StringSize,\r
1317 OUT EFI_FONT_INFO **StringFontInfo OPTIONAL\r
1318 )\r
1319{\r
1320 EFI_STATUS Status;\r
1321 LIST_ENTRY *Link;\r
1322 HII_DATABASE_PRIVATE_DATA *Private;\r
1323 HII_DATABASE_RECORD *DatabaseRecord;\r
1324 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
1325 HII_STRING_PACKAGE_INSTANCE *StringPackage;\r
844390f7 1326 CHAR8 *MatchedLanguage;\r
93e3992d 1327\r
1328 if (This == NULL || Language == NULL || StringId < 1 || StringSize == NULL || PackageList == NULL) {\r
1329 return EFI_INVALID_PARAMETER;\r
1330 }\r
1331\r
1332 if (String == NULL && *StringSize != 0) {\r
1333 return EFI_INVALID_PARAMETER;\r
1334 }\r
1335\r
1336 if (!IsHiiHandleValid (PackageList)) {\r
1337 return EFI_NOT_FOUND;\r
1338 }\r
1339\r
1340 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
1341 PackageListNode = NULL;\r
1342\r
1343 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r
1344 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
1345 if (DatabaseRecord->Handle == PackageList) {\r
1346 PackageListNode = DatabaseRecord->PackageList;\r
1347 break;\r
1348 }\r
1349 }\r
1350\r
1351 if (PackageListNode != NULL) {\r
813acf3a 1352 //\r
1353 // First search: to match the StringId in the specified language.\r
1354 //\r
93e3992d 1355 for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r
1356 Link != &PackageListNode->StringPkgHdr;\r
1357 Link = Link->ForwardLink\r
1358 ) {\r
813acf3a 1359 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
844390f7 1360 MatchedLanguage = GetBestLanguage (StringPackage->StringPkgHdr->Language, FALSE, (CHAR8 *) Language, NULL);\r
1361 if (MatchedLanguage != NULL) {\r
1362 FreePool (MatchedLanguage);\r
813acf3a 1363 Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);\r
1364 if (Status != EFI_NOT_FOUND) {\r
1365 return Status;\r
1366 }\r
93e3992d 1367 }\r
1368 }\r
813acf3a 1369 //\r
1370 // Second search: to match the StringId in other available languages if exist.\r
1371 //\r
1372 for (Link = PackageListNode->StringPkgHdr.ForwardLink; \r
1373 Link != &PackageListNode->StringPkgHdr;\r
1374 Link = Link->ForwardLink\r
1375 ) {\r
1376 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE); \r
1377 Status = GetStringWorker (Private, StringPackage, StringId, String, StringSize, StringFontInfo);\r
1378 if (!EFI_ERROR (Status)) {\r
1379 return EFI_INVALID_LANGUAGE;\r
1380 }\r
1381 } \r
93e3992d 1382 }\r
1383\r
1384 return EFI_NOT_FOUND;\r
1385}\r
1386\r
1387\r
1388\r
1389/**\r
1390 This function updates the string specified by StringId in the specified PackageList to the text\r
1391 specified by String and, optionally, the font information specified by StringFontInfo.\r
1392\r
1393 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r
1394 @param PackageList The package list containing the strings.\r
ac644614 1395 @param StringId The string's id, which is unique within\r
93e3992d 1396 PackageList.\r
1397 @param Language Points to the language for the updated string.\r
1398 @param String Points to the new null-terminated string.\r
ac644614 1399 @param StringFontInfo Points to the string's font information or NULL if\r
93e3992d 1400 the string font information is not changed.\r
1401\r
1402 @retval EFI_SUCCESS The string was updated successfully.\r
1403 @retval EFI_NOT_FOUND The string specified by StringId is not in the\r
1404 database.\r
1405 @retval EFI_INVALID_PARAMETER The String or Language was NULL.\r
1406 @retval EFI_INVALID_PARAMETER The specified StringFontInfo does not exist in\r
1407 current database.\r
1408 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the\r
1409 task.\r
1410\r
1411**/\r
1412EFI_STATUS\r
1413EFIAPI\r
1414HiiSetString (\r
1415 IN CONST EFI_HII_STRING_PROTOCOL *This,\r
1416 IN EFI_HII_HANDLE PackageList,\r
1417 IN EFI_STRING_ID StringId,\r
1418 IN CONST CHAR8 *Language,\r
1419 IN CONST EFI_STRING String,\r
1420 IN CONST EFI_FONT_INFO *StringFontInfo OPTIONAL\r
1421 )\r
1422{\r
1423 EFI_STATUS Status;\r
1424 LIST_ENTRY *Link;\r
1425 HII_DATABASE_PRIVATE_DATA *Private;\r
1426 HII_DATABASE_RECORD *DatabaseRecord;\r
1427 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
1428 HII_STRING_PACKAGE_INSTANCE *StringPackage;\r
1429 UINT32 OldPackageLen;\r
844390f7 1430 CHAR8 *MatchedLanguage;\r
93e3992d 1431\r
1432 if (This == NULL || Language == NULL || StringId < 1 || String == NULL || PackageList == NULL) {\r
1433 return EFI_INVALID_PARAMETER;\r
1434 }\r
1435\r
1436 if (!IsHiiHandleValid (PackageList)) {\r
1437 return EFI_NOT_FOUND;\r
1438 }\r
1439\r
1440 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
1441 PackageListNode = NULL;\r
1442\r
1443 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r
1444 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
1445 if (DatabaseRecord->Handle == PackageList) {\r
1446 PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);\r
1447 }\r
1448 }\r
1449\r
1450 if (PackageListNode != NULL) {\r
1451 for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r
1452 Link != &PackageListNode->StringPkgHdr;\r
1453 Link = Link->ForwardLink\r
1454 ) {\r
1455 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
844390f7 1456 MatchedLanguage = GetBestLanguage (StringPackage->StringPkgHdr->Language, FALSE, (CHAR8 *) Language, NULL);\r
1457 if (MatchedLanguage != NULL) {\r
1458 FreePool (MatchedLanguage);\r
93e3992d 1459 OldPackageLen = StringPackage->StringPkgHdr->Header.Length;\r
1460 Status = SetStringWorker (\r
1461 Private,\r
1462 StringPackage,\r
1463 StringId,\r
1464 (EFI_STRING) String,\r
1465 (EFI_FONT_INFO *) StringFontInfo\r
1466 );\r
1467 if (EFI_ERROR (Status)) {\r
1468 return Status;\r
1469 }\r
1470 PackageListNode->PackageListHdr.PackageLength += StringPackage->StringPkgHdr->Header.Length - OldPackageLen;\r
1471 return EFI_SUCCESS;\r
1472 }\r
1473 }\r
1474 }\r
1475\r
1476 return EFI_NOT_FOUND;\r
1477}\r
1478\r
1479\r
1480\r
1481/**\r
1482 This function returns the list of supported languages, in the format specified\r
1483 in Appendix M of UEFI 2.1 spec.\r
1484\r
1485 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r
1486 @param PackageList The package list to examine.\r
1487 @param Languages Points to the buffer to hold the returned string.\r
1488 @param LanguagesSize On entry, points to the size of the buffer pointed\r
1489 to by Languages, in bytes. On return, points to\r
1490 the length of Languages, in bytes.\r
1491\r
1492 @retval EFI_SUCCESS The languages were returned successfully.\r
1493 @retval EFI_INVALID_PARAMETER The Languages or LanguagesSize was NULL.\r
1494 @retval EFI_BUFFER_TOO_SMALL The LanguagesSize is too small to hold the list of\r
1495 supported languages. LanguageSize is updated to\r
1496 contain the required size.\r
1497 @retval EFI_NOT_FOUND Could not find string package in specified\r
1498 packagelist.\r
1499\r
1500**/\r
1501EFI_STATUS\r
1502EFIAPI\r
1503HiiGetLanguages (\r
1504 IN CONST EFI_HII_STRING_PROTOCOL *This,\r
1505 IN EFI_HII_HANDLE PackageList,\r
1506 IN OUT CHAR8 *Languages,\r
1507 IN OUT UINTN *LanguagesSize\r
1508 )\r
1509{\r
1510 LIST_ENTRY *Link;\r
1511 HII_DATABASE_PRIVATE_DATA *Private;\r
1512 HII_DATABASE_RECORD *DatabaseRecord;\r
1513 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
1514 HII_STRING_PACKAGE_INSTANCE *StringPackage;\r
1515 UINTN ResultSize;\r
1516\r
1517 if (This == NULL || Languages == NULL || LanguagesSize == NULL || PackageList == NULL) {\r
1518 return EFI_INVALID_PARAMETER;\r
1519 }\r
1520 if (!IsHiiHandleValid (PackageList)) {\r
1521 return EFI_NOT_FOUND;\r
1522 }\r
1523\r
1524 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
1525\r
1526 PackageListNode = NULL;\r
1527 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r
1528 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
1529 if (DatabaseRecord->Handle == PackageList) {\r
1530 PackageListNode = DatabaseRecord->PackageList;\r
1531 break;\r
1532 }\r
1533 }\r
1534 if (PackageListNode == NULL) {\r
1535 return EFI_NOT_FOUND;\r
1536 }\r
1537\r
1538 //\r
1539 // Search the languages in the specified packagelist.\r
1540 //\r
1541 ResultSize = 0;\r
1542 for (Link = PackageListNode->StringPkgHdr.ForwardLink;\r
1543 Link != &PackageListNode->StringPkgHdr;\r
1544 Link = Link->ForwardLink\r
1545 ) {\r
1546 StringPackage = CR (Link, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
1547 ResultSize += AsciiStrSize (StringPackage->StringPkgHdr->Language);\r
2fef9e5f 1548 if (ResultSize <= *LanguagesSize) {\r
93e3992d 1549 AsciiStrCpy (Languages, StringPackage->StringPkgHdr->Language);\r
1550 Languages += AsciiStrSize (StringPackage->StringPkgHdr->Language);\r
1551 *(Languages - 1) = L';';\r
1552 }\r
1553 }\r
1554 if (ResultSize == 0) {\r
1555 return EFI_NOT_FOUND;\r
1556 }\r
1557\r
1558 if (*LanguagesSize < ResultSize) {\r
1559 *LanguagesSize = ResultSize;\r
1560 return EFI_BUFFER_TOO_SMALL;\r
1561 }\r
1562\r
1563 *(Languages - 1) = 0;\r
1564 return EFI_SUCCESS;\r
1565}\r
1566\r
1567\r
1568/**\r
1569 Each string package has associated with it a single primary language and zero\r
1570 or more secondary languages. This routine returns the secondary languages\r
1571 associated with a package list.\r
1572\r
1573 @param This A pointer to the EFI_HII_STRING_PROTOCOL instance.\r
1574 @param PackageList The package list to examine.\r
1575 @param FirstLanguage Points to the primary language.\r
1576 @param SecondaryLanguages Points to the buffer to hold the returned list of\r
1577 secondary languages for the specified\r
1578 FirstLanguage. If there are no secondary\r
1579 languages, the function returns successfully, but\r
1580 this is set to NULL.\r
e90b081a 1581 @param SecondaryLanguagesSize On entry, points to the size of the buffer pointed\r
1582 to by SecondaryLanguages, in bytes. On return,\r
1583 points to the length of SecondaryLanguages in bytes.\r
93e3992d 1584\r
1585 @retval EFI_SUCCESS Secondary languages were correctly returned.\r
e90b081a 1586 @retval EFI_INVALID_PARAMETER FirstLanguage or SecondaryLanguages or\r
1587 SecondaryLanguagesSize was NULL.\r
1588 @retval EFI_BUFFER_TOO_SMALL The buffer specified by SecondaryLanguagesSize is\r
93e3992d 1589 too small to hold the returned information.\r
1590 SecondLanguageSize is updated to hold the size of\r
1591 the buffer required.\r
813acf3a 1592 @retval EFI_INVALID_LANGUAGE The language specified by FirstLanguage is not\r
1593 present in the specified package list.\r
1594 @retval EFI_NOT_FOUND The specified PackageList is not in the Database. \r
93e3992d 1595\r
1596**/\r
1597EFI_STATUS\r
1598EFIAPI\r
1599HiiGetSecondaryLanguages (\r
1600 IN CONST EFI_HII_STRING_PROTOCOL *This,\r
1601 IN EFI_HII_HANDLE PackageList,\r
1602 IN CONST CHAR8 *FirstLanguage,\r
e90b081a 1603 IN OUT CHAR8 *SecondaryLanguages,\r
1604 IN OUT UINTN *SecondaryLanguagesSize\r
93e3992d 1605 )\r
1606{\r
1607 LIST_ENTRY *Link;\r
1608 LIST_ENTRY *Link1;\r
1609 HII_DATABASE_PRIVATE_DATA *Private;\r
1610 HII_DATABASE_RECORD *DatabaseRecord;\r
1611 HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageListNode;\r
1612 HII_STRING_PACKAGE_INSTANCE *StringPackage;\r
1613 CHAR8 *Languages;\r
1614 UINTN ResultSize;\r
844390f7 1615 CHAR8 *MatchedLanguage;\r
93e3992d 1616\r
1617 if (This == NULL || PackageList == NULL || FirstLanguage == NULL) {\r
1618 return EFI_INVALID_PARAMETER;\r
1619 }\r
e90b081a 1620 if (SecondaryLanguages == NULL || SecondaryLanguagesSize == NULL) {\r
93e3992d 1621 return EFI_INVALID_PARAMETER;\r
1622 }\r
1623 if (!IsHiiHandleValid (PackageList)) {\r
1624 return EFI_NOT_FOUND;\r
1625 }\r
1626\r
1627 Private = HII_STRING_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
93e3992d 1628\r
813acf3a 1629 PackageListNode = NULL; \r
93e3992d 1630 for (Link = Private->DatabaseList.ForwardLink; Link != &Private->DatabaseList; Link = Link->ForwardLink) {\r
1631 DatabaseRecord = CR (Link, HII_DATABASE_RECORD, DatabaseEntry, HII_DATABASE_RECORD_SIGNATURE);\r
1632 if (DatabaseRecord->Handle == PackageList) {\r
1633 PackageListNode = (HII_DATABASE_PACKAGE_LIST_INSTANCE *) (DatabaseRecord->PackageList);\r
813acf3a 1634 break;\r
1635 }\r
1636 }\r
1637 if (PackageListNode == NULL) {\r
1638 return EFI_NOT_FOUND;\r
1639 }\r
1640 \r
1641 Languages = NULL;\r
1642 ResultSize = 0;\r
1643 for (Link1 = PackageListNode->StringPkgHdr.ForwardLink;\r
1644 Link1 != &PackageListNode->StringPkgHdr;\r
1645 Link1 = Link1->ForwardLink\r
1646 ) {\r
1647 StringPackage = CR (Link1, HII_STRING_PACKAGE_INSTANCE, StringEntry, HII_STRING_PACKAGE_SIGNATURE);\r
844390f7 1648 MatchedLanguage = GetBestLanguage (StringPackage->StringPkgHdr->Language, FALSE, (CHAR8 *) FirstLanguage, NULL);\r
1649 if (MatchedLanguage != NULL) {\r
1650 FreePool (MatchedLanguage);\r
813acf3a 1651 Languages = StringPackage->StringPkgHdr->Language;\r
1652 //\r
1653 // Language is a series of ';' terminated strings, first one is primary\r
1654 // language and following with other secondary languages or NULL if no\r
1655 // secondary languages any more.\r
1656 //\r
1657 Languages = AsciiStrStr (Languages, ";");\r
1658 if (Languages == NULL) {\r
1659 break;\r
1660 }\r
1661 Languages++;\r
93e3992d 1662\r
813acf3a 1663 ResultSize = AsciiStrSize (Languages);\r
e90b081a 1664 if (ResultSize <= *SecondaryLanguagesSize) {\r
1665 AsciiStrCpy (SecondaryLanguages, Languages);\r
813acf3a 1666 } else {\r
e90b081a 1667 *SecondaryLanguagesSize = ResultSize;\r
813acf3a 1668 return EFI_BUFFER_TOO_SMALL;\r
93e3992d 1669 }\r
813acf3a 1670\r
1671 return EFI_SUCCESS;\r
93e3992d 1672 }\r
1673 }\r
1674\r
813acf3a 1675 return EFI_INVALID_LANGUAGE;\r
93e3992d 1676}\r
1677\r