]>
Commit | Line | Data |
---|---|---|
c9093a06 | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation \r | |
4 | All rights reserved. This program and the accompanying materials \r | |
5 | are licensed and made available under the terms and conditions of the BSD License \r | |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | string.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | String support\r | |
19 | \r | |
20 | Revision 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 | |
28 | extern UINT8 BdsStrings[];\r | |
29 | \r | |
997e26f6 | 30 | EFI_GUID gBdsStringPackGuid = { 0x7bac95d3, 0xddf, 0x42f3, {0x9e, 0x24, 0x7c, 0x64, 0x49, 0x40, 0x37, 0x9a} };\r |
c9093a06 | 31 | \r |
32 | EFI_HII_HANDLE gStringPackHandle;\r | |
33 | EFI_HII_PROTOCOL *Hii;\r | |
34 | \r | |
35 | EFI_STATUS\r | |
36 | InitializeStringSupport (\r | |
37 | VOID\r | |
38 | )\r | |
39 | /*++\r | |
40 | \r | |
41 | Routine Description:\r | |
42 | \r | |
43 | Initialize HII global accessor for string support\r | |
44 | \r | |
45 | Arguments:\r | |
46 | None\r | |
47 | \r | |
48 | Returns:\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 | |
72 | CHAR16 *\r | |
73 | GetStringById (\r | |
74 | IN STRING_REF Id\r | |
75 | )\r | |
76 | /*++\r | |
77 | \r | |
78 | Routine Description:\r | |
79 | \r | |
80 | Get string by string id from HII Interface\r | |
81 | \r | |
82 | Arguments:\r | |
83 | \r | |
84 | Id - String ID.\r | |
85 | \r | |
86 | Returns:\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 |