]>
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 | |
06335580 | 30 | #include "BdsString.h"\r |
bc11b829 | 31 | #include "Language.h"\r |
32 | \r | |
bc11b829 | 33 | EFI_STATUS\r |
34 | InitializeStringSupport (\r | |
35 | VOID\r | |
36 | )\r | |
37 | /*++\r | |
38 | \r | |
39 | Routine Description:\r | |
d1477e4d | 40 | reset\r |
bc11b829 | 41 | Initialize HII global accessor for string support\r |
42 | \r | |
43 | Arguments:\r | |
44 | None\r | |
45 | \r | |
46 | Returns:\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 | |
70 | CHAR16 *\r | |
71 | GetStringById (\r | |
72 | IN STRING_REF Id\r | |
73 | )\r | |
74 | /*++\r | |
75 | \r | |
76 | Routine Description:\r | |
77 | \r | |
78 | Get string by string id from HII Interface\r | |
79 | \r | |
80 | Arguments:\r | |
81 | \r | |
82 | Id - String ID.\r | |
83 | \r | |
84 | Returns:\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 |