]> git.proxmox.com Git - mirror_edk2.git/blame - Nt32Pkg/PlatformBdsDxe/Generic/String.c
Cleanups in PlatformBds.c. BDS will get rewritten, but his makes it easier to look...
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / String.c
CommitLineData
bc11b829 1/*++\r
2\r
3Copyright (c) 2006 - 2007, 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//\r
25// Include common header file for this module.\r
26//\r
27#include "CommonHeader.h"\r
28\r
29#include "Bds.h"\r
06335580 30#include "BdsString.h"\r
bc11b829 31#include "Language.h"\r
32\r
bc11b829 33EFI_STATUS\r
34InitializeStringSupport (\r
35 VOID\r
36 )\r
37/*++\r
38\r
39Routine Description:\r
d1477e4d 40 reset\r
bc11b829 41 Initialize HII global accessor for string support\r
42\r
43Arguments:\r
44 None\r
45\r
46Returns:\r
47 String from ID.\r
48\r
49--*/\r
50{\r
51 EFI_STATUS Status;\r
52 EFI_HII_PACKAGES *PackageList;\r
53 //\r
54 // There should only ever be one HII protocol\r
55 //\r
56 Status = gBS->LocateProtocol (\r
57 &gEfiHiiProtocolGuid,\r
58 NULL,\r
d1477e4d 59 &gHii\r
bc11b829 60 );\r
61 if (!EFI_ERROR (Status)) {\r
d1477e4d
A
62 PackageList = PreparePackages (1, &gEfiCallerIdGuid, PlatformBdsStrings);\r
63 Status = gHii->NewPack (gHii, PackageList, &gStringPackHandle);\r
bc11b829 64 FreePool (PackageList);\r
65 }\r
66\r
67 return Status;\r
68}\r
69\r
70CHAR16 *\r
71GetStringById (\r
72 IN STRING_REF Id\r
73 )\r
74/*++\r
75\r
76Routine Description:\r
77\r
78 Get string by string id from HII Interface\r
79\r
80Arguments:\r
81\r
82 Id - String ID.\r
83\r
84Returns:\r
85\r
86 CHAR16 * - String from ID.\r
87 NULL - If error occurs.\r
88\r
89--*/\r
90{\r
91 CHAR16 *String;\r
92 UINTN StringLength;\r
93 EFI_STATUS Status;\r
94\r
95 //\r
96 // Set default string size assumption at no more than 256 bytes\r
97 //\r
98 StringLength = 0x100;\r
99\r
100 String = AllocateZeroPool (StringLength);\r
101 if (String == NULL) {\r
102 //\r
103 // If this happens, we are oh-so-dead, but return a NULL in any case.\r
104 //\r
105 return NULL;\r
106 }\r
107 //\r
108 // Get the current string for the current Language\r
109 //\r
d1477e4d 110 Status = gHii->GetString (gHii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);\r
bc11b829 111 if (EFI_ERROR (Status)) {\r
112 if (Status == EFI_BUFFER_TOO_SMALL) {\r
113 //\r
114 // Free the old pool\r
115 //\r
116 FreePool (String);\r
117\r
118 //\r
119 // Allocate new pool with correct value\r
120 //\r
121 String = AllocatePool (StringLength);\r
122 ASSERT (String != NULL);\r
123\r
d1477e4d 124 Status = gHii->GetString (gHii, gStringPackHandle, Id, FALSE, NULL, &StringLength, String);\r
bc11b829 125 if (!EFI_ERROR (Status)) {\r
126 return String;\r
127 }\r
128 }\r
129\r
130 return NULL;\r
131 }\r
132\r
133 return String;\r
134}\r