+++ /dev/null
-/*++\r
-\r
-Copyright (c) 2006, Intel Corporation \r
-All rights reserved. This program and the accompanying materials \r
-are licensed and made available under the terms and conditions of the BSD License \r
-which accompanies this distribution. The full text of the license may be found at \r
-http://opensource.org/licenses/bsd-license.php \r
- \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
-\r
-Module Name:\r
-\r
- string.c\r
-\r
-Abstract:\r
-\r
- String support\r
-\r
-Revision History\r
-\r
---*/\r
-\r
-#include "Bds.h"\r
-#include "String.h"\r
-#include "Language.h"\r
-\r
-extern UINT8 EdkGenericPlatformBdsLibStrings[];\r
-\r
-EFI_GUID gBdsStringPackGuid = { 0x7bac95d3, 0xddf, 0x42f3, {0x9e, 0x24, 0x7c, 0x64, 0x49, 0x40, 0x37, 0x9a} };\r
-\r
-EFI_HII_HANDLE gStringPackHandle;\r
-EFI_HII_PROTOCOL *Hii;\r
-\r
-EFI_STATUS\r
-InitializeStringSupport (\r
- VOID\r
- )\r
-/*++\r
-\r
-Routine Description:\r
- \r
- Initialize HII global accessor for string support\r
-\r
-Arguments:\r
- None\r
-\r
-Returns:\r
- String from ID.\r
-\r
---*/\r
-{\r
- EFI_STATUS Status;\r
- EFI_HII_PACKAGES *PackageList;\r
- //\r
- // There should only ever be one HII protocol\r
- //\r
- Status = gBS->LocateProtocol (\r
- &gEfiHiiProtocolGuid,\r
- NULL,\r
- (VOID**)&Hii\r
- );\r
- if (!EFI_ERROR (Status)) {\r
- PackageList = PreparePackages (1, &gBdsStringPackGuid, EdkGenericPlatformBdsLibStrings);\r
- Status = Hii->NewPack (Hii, PackageList, &gStringPackHandle);\r
- gBS->FreePool (PackageList);\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-CHAR16 *\r
-GetStringById (\r
- IN STRING_REF Id\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Get string by string id from HII Interface\r
-\r
-Arguments:\r
-\r
- Id - String ID.\r
- \r
-Returns:\r
-\r
- CHAR16 * - String from ID.\r
- NULL - If error occurs.\r
-\r
---*/\r
-{\r
- CHAR16 *String;\r
- UINTN StringLength;\r
- EFI_STATUS Status;\r
-\r
- //\r
- // Set default string size assumption at no more than 256 bytes\r
- //\r
- StringLength = 0x100;\r
-\r
- String = AllocateZeroPool (StringLength);\r
- if (String == NULL) {\r
- //\r
- // If this happens, we are oh-so-dead, but return a NULL in any case.\r
- //\r
- return NULL;\r
- }\r
- //\r
- // Get the current string for the current Language\r
- //\r
- Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);\r
- if (EFI_ERROR (Status)) {\r
- if (Status == EFI_BUFFER_TOO_SMALL) {\r
- //\r
- // Free the old pool\r
- //\r
- gBS->FreePool (String);\r
-\r
- //\r
- // Allocate new pool with correct value\r
- //\r
- String = AllocatePool (StringLength);\r
- ASSERT (String != NULL);\r
-\r
- Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);\r
- if (!EFI_ERROR (Status)) {\r
- return String;\r
- }\r
- }\r
-\r
- return NULL;\r
- }\r
-\r
- return String;\r
-}\r