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