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