]> git.proxmox.com Git - mirror_edk2.git/blame - EdkUnixPkg/Dxe/PlatformBds/Generic/String.c
newline added at end
[mirror_edk2.git] / EdkUnixPkg / Dxe / PlatformBds / Generic / String.c
CommitLineData
c9093a06 1/*++\r
2\r
3Copyright (c) 2006, Intel Corporation \r
4All rights reserved. This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11\r
12Module Name:\r
13\r
14 string.c\r
15\r
16Abstract:\r
17\r
18 String support\r
19\r
20Revision History\r
21\r
22--*/\r
23\r
24#include "Bds.h"\r
25#include "String.h"\r
26#include "Language.h"\r
27\r
28extern UINT8 BdsStrings[];\r
29\r
997e26f6 30EFI_GUID gBdsStringPackGuid = { 0x7bac95d3, 0xddf, 0x42f3, {0x9e, 0x24, 0x7c, 0x64, 0x49, 0x40, 0x37, 0x9a} };\r
c9093a06 31\r
32EFI_HII_HANDLE gStringPackHandle;\r
33EFI_HII_PROTOCOL *Hii;\r
34\r
35EFI_STATUS\r
36InitializeStringSupport (\r
37 VOID\r
38 )\r
39/*++\r
40\r
41Routine Description:\r
42 \r
43 Initialize HII global accessor for string support\r
44\r
45Arguments:\r
46 None\r
47\r
48Returns:\r
49 String from ID.\r
50\r
51--*/\r
52{\r
53 EFI_STATUS Status;\r
54 EFI_HII_PACKAGES *PackageList;\r
55 //\r
56 // There should only ever be one HII protocol\r
57 //\r
58 Status = gBS->LocateProtocol (\r
59 &gEfiHiiProtocolGuid,\r
60 NULL,\r
997e26f6 61 (VOID**)&Hii\r
c9093a06 62 );\r
63 if (!EFI_ERROR (Status)) {\r
64 PackageList = PreparePackages (1, &gBdsStringPackGuid, BdsStrings);\r
65 Status = Hii->NewPack (Hii, PackageList, &gStringPackHandle);\r
66 gBS->FreePool (PackageList);\r
67 }\r
68\r
69 return Status;\r
70}\r
71\r
72CHAR16 *\r
73GetStringById (\r
74 IN STRING_REF Id\r
75 )\r
76/*++\r
77\r
78Routine Description:\r
79\r
80 Get string by string id from HII Interface\r
81\r
82Arguments:\r
83\r
84 Id - String ID.\r
85 \r
86Returns:\r
87\r
88 CHAR16 * - String from ID.\r
89 NULL - If error occurs.\r
90\r
91--*/\r
92{\r
93 CHAR16 *String;\r
94 UINTN StringLength;\r
95 EFI_STATUS Status;\r
96\r
97 //\r
98 // Set default string size assumption at no more than 256 bytes\r
99 //\r
100 StringLength = 0x100;\r
101\r
102 String = AllocateZeroPool (StringLength);\r
103 if (String == NULL) {\r
104 //\r
105 // If this happens, we are oh-so-dead, but return a NULL in any case.\r
106 //\r
107 return NULL;\r
108 }\r
109 //\r
110 // Get the current string for the current Language\r
111 //\r
112 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);\r
113 if (EFI_ERROR (Status)) {\r
114 if (Status == EFI_BUFFER_TOO_SMALL) {\r
115 //\r
116 // Free the old pool\r
117 //\r
118 gBS->FreePool (String);\r
119\r
120 //\r
121 // Allocate new pool with correct value\r
122 //\r
123 String = AllocatePool (StringLength);\r
124 ASSERT (String != NULL);\r
125\r
126 Status = Hii->GetString (Hii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);\r
127 if (!EFI_ERROR (Status)) {\r
128 return String;\r
129 }\r
130 }\r
131\r
132 return NULL;\r
133 }\r
134\r
135 return String;\r
136}\r