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