]>
Commit | Line | Data |
---|---|---|
08e4b3cf | 1 | /** @file\r |
2 | HII Library implementation that uses DXE protocols and services.\r | |
3 | \r | |
4 | Copyright (c) 2006 - 2008, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | \r | |
16 | #include "InternalHiiLib.h"\r | |
17 | \r | |
08e4b3cf | 18 | /**\r |
cb7d01c0 | 19 | This function create a new string in String Package or updates an existing \r |
20 | string in a String Package. If StringId is 0, then a new string is added to\r | |
21 | a String Package. If StringId is not zero, then a string in String Package is\r | |
22 | updated. If SupportedLanguages is NULL, then the string is added or updated\r | |
23 | for all the languages that the String Package supports. If SupportedLanguages\r | |
24 | is not NULL, then the string is added or updated for the set of languages \r | |
25 | specified by SupportedLanguages.\r | |
26 | \r | |
27 | If HiiHandle is NULL, then ASSERT().\r | |
28 | If String is NULL, then ASSERT().\r | |
29 | \r | |
30 | @param[in] HiiHandle A handle that was previously registered in the \r | |
31 | HII Database.\r | |
32 | @param[in] StringId If zero, then a new string is created in the \r | |
33 | String Package associated with HiiHandle. If \r | |
34 | non-zero, then the string specified by StringId \r | |
35 | is updated in the String Package associated \r | |
36 | with HiiHandle. \r | |
37 | @param[in] String A pointer to the Null-terminated Unicode string \r | |
38 | to add or update in the String Package associated \r | |
39 | with HiiHandle.\r | |
40 | @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of \r | |
41 | language codes. If this parameter is NULL, then \r | |
42 | String is added or updated in the String Package \r | |
43 | associated with HiiHandle for all the languages \r | |
44 | that the String Package supports. If this \r | |
45 | parameter is not NULL, then then String is added \r | |
46 | or updated in the String Package associated with \r | |
47 | HiiHandle for the set oflanguages specified by \r | |
48 | SupportedLanguages. The format of \r | |
49 | SupportedLanguages must follow the language \r | |
50 | format assumed the HII Database.\r | |
51 | \r | |
52 | @retval 0 The string could not be added or updated in the String Package.\r | |
53 | @retval Other The EFI_STRING_ID of the newly added or updated string.\r | |
08e4b3cf | 54 | \r |
55 | **/\r | |
cb7d01c0 | 56 | EFI_STRING_ID\r |
08e4b3cf | 57 | EFIAPI\r |
cb7d01c0 | 58 | HiiSetString (\r |
59 | IN EFI_HII_HANDLE HiiHandle,\r | |
60 | IN EFI_STRING_ID StringId, OPTIONAL\r | |
61 | IN CONST EFI_STRING String,\r | |
62 | IN CONST CHAR8 *SupportedLanguages OPTIONAL\r | |
08e4b3cf | 63 | )\r |
64 | {\r | |
cb7d01c0 | 65 | EFI_STATUS Status;\r |
66 | CHAR8 *AllocatedLanguages;\r | |
67 | CHAR8 *Supported;\r | |
68 | CHAR8 *Language;\r | |
69 | EFI_STRING_ID NewStringId;\r | |
08e4b3cf | 70 | \r |
cb7d01c0 | 71 | ASSERT (HiiHandle != NULL);\r |
08e4b3cf | 72 | ASSERT (String != NULL);\r |
08e4b3cf | 73 | \r |
cb7d01c0 | 74 | if (SupportedLanguages == NULL) {\r |
75 | //\r | |
76 | // Retrieve the languages that the package specified by HiiHandle supports\r | |
77 | //\r | |
78 | AllocatedLanguages = HiiGetSupportedLanguages (HiiHandle);\r | |
79 | } else {\r | |
80 | //\r | |
81 | // Allocate a copy of the SupportLanguages string that passed in\r | |
82 | //\r | |
f580c1bd | 83 | AllocatedLanguages = AllocateCopyPool (AsciiStrSize (SupportedLanguages), SupportedLanguages);\r |
cb7d01c0 | 84 | }\r |
08e4b3cf | 85 | \r |
ea7cd3ec | 86 | //\r |
cb7d01c0 | 87 | // If there are not enough resources for the supported languages string, then return a StringId of 0\r |
ea7cd3ec | 88 | //\r |
cb7d01c0 | 89 | if (AllocatedLanguages == NULL) {\r |
90 | return (EFI_STRING_ID)(0);\r | |
91 | }\r | |
08e4b3cf | 92 | \r |
cb7d01c0 | 93 | NewStringId = 0;\r |
94 | Status = EFI_INVALID_PARAMETER;\r | |
95 | //\r | |
96 | // Loop through each language that the string supports\r | |
97 | //\r | |
98 | for (Supported = AllocatedLanguages; *Supported != '\0'; ) {\r | |
99 | //\r | |
100 | // Cache a pointer to the beginning of the current language in the list of languages\r | |
101 | //\r | |
102 | Language = Supported;\r | |
08e4b3cf | 103 | \r |
104 | //\r | |
cb7d01c0 | 105 | // Search for the next language seperator and replace it with a Null-terminator\r |
08e4b3cf | 106 | //\r |
cb7d01c0 | 107 | for (; *Supported != 0 && *Supported != ';'; Supported++);\r |
108 | if (*Supported != 0) {\r | |
109 | *(Supported++) = '\0';\r | |
08e4b3cf | 110 | }\r |
08e4b3cf | 111 | \r |
cb7d01c0 | 112 | //\r |
113 | // If StringId is 0, then call NewString(). Otherwise, call SetString()\r | |
114 | //\r | |
115 | if (StringId == (EFI_STRING_ID)(0)) {\r | |
116 | Status = gHiiString->NewString (gHiiString, HiiHandle, &NewStringId, Language, NULL, String, NULL);\r | |
117 | } else {\r | |
118 | Status = gHiiString->SetString (gHiiString, HiiHandle, StringId, Language, String, NULL);\r | |
119 | }\r | |
08e4b3cf | 120 | \r |
121 | //\r | |
cb7d01c0 | 122 | // If there was an error, then break out of the loop and return a StringId of 0\r |
08e4b3cf | 123 | //\r |
08e4b3cf | 124 | if (EFI_ERROR (Status)) {\r |
125 | break;\r | |
126 | }\r | |
127 | }\r | |
128 | \r | |
cb7d01c0 | 129 | //\r |
130 | // Free the buffer of supported languages\r | |
131 | //\r | |
132 | FreePool (AllocatedLanguages);\r | |
133 | \r | |
134 | if (EFI_ERROR (Status)) {\r | |
135 | return (EFI_STRING_ID)(0);\r | |
136 | } else if (StringId == (EFI_STRING_ID)(0)) {\r | |
137 | return NewStringId;\r | |
138 | } else {\r | |
139 | return StringId;\r | |
140 | }\r | |
08e4b3cf | 141 | }\r |
142 | \r | |
143 | \r | |
144 | /**\r | |
cb7d01c0 | 145 | Retrieves a string from a string package names by GUID in a specific language. \r |
146 | If the language is not specified, then a string from a string package in the \r | |
147 | current platform language is retrieved. If the string can not be retrieved \r | |
148 | using the specified language or the current platform language, then the string \r | |
149 | is retrieved from the string package in the first language the string package \r | |
150 | supports. The returned string is allocated using AllocatePool(). The caller \r | |
151 | is responsible for freeing the allocated buffer using FreePool().\r | |
152 | \r | |
153 | If PackageListGuid is NULL, then ASSERT().\r | |
154 | If StringId is 0, then ASSERT.\r | |
155 | \r | |
156 | @param[in] PackageListGuid The GUID of a package list that was previously \r | |
157 | registered in the HII Database.\r | |
158 | @param[in] StringId The identifier of the string to retrieved from the \r | |
159 | string package associated with PackageListGuid.\r | |
160 | @param[in] Language The language of the string to retrieve. If this \r | |
161 | parameter is NULL, then the current platform \r | |
162 | language is used. The format of Language must \r | |
163 | follow the language format assumed the HII Database.\r | |
164 | \r | |
165 | @retval NULL The package list specified by PackageListGuid is not present in the\r | |
166 | HII Database.\r | |
167 | @retval NULL The string specified by StringId is not present in the string package.\r | |
168 | @retval Other The string was returned.\r | |
08e4b3cf | 169 | \r |
170 | **/\r | |
cb7d01c0 | 171 | EFI_STRING\r |
08e4b3cf | 172 | EFIAPI\r |
cb7d01c0 | 173 | HiiGetPackageString (\r |
174 | IN CONST EFI_GUID *PackageListGuid,\r | |
175 | IN EFI_STRING_ID StringId,\r | |
176 | IN CONST CHAR8 *Language OPTIONAL\r | |
08e4b3cf | 177 | )\r |
178 | {\r | |
cb7d01c0 | 179 | EFI_HANDLE *HiiHandleBuffer;\r |
180 | EFI_HANDLE HiiHandle;\r | |
08e4b3cf | 181 | \r |
cb7d01c0 | 182 | ASSERT (PackageListGuid != NULL);\r |
08e4b3cf | 183 | \r |
cb7d01c0 | 184 | HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid);\r |
185 | if (HiiHandleBuffer == NULL) {\r | |
186 | return NULL;\r | |
08e4b3cf | 187 | }\r |
188 | \r | |
cb7d01c0 | 189 | HiiHandle = HiiHandleBuffer[0];\r |
4a1102c9 | 190 | FreePool (HiiHandleBuffer);\r |
191 | \r | |
cb7d01c0 | 192 | return HiiGetString (HiiHandle, StringId, Language);\r |
08e4b3cf | 193 | }\r |
194 | \r | |
195 | /**\r | |
cb7d01c0 | 196 | Retrieves a string from a string package in a specific language. If the language\r |
197 | is not specified, then a string from a string package in the current platform \r | |
198 | language is retrieved. If the string can not be retrieved using the specified \r | |
199 | language or the current platform language, then the string is retrieved from \r | |
200 | the string package in the first language the string package supports. The \r | |
201 | returned string is allocated using AllocatePool(). The caller is responsible \r | |
202 | for freeing the allocated buffer using FreePool().\r | |
203 | \r | |
204 | If HiiHandle is NULL, then ASSERT().\r | |
205 | If StringId is 0, then ASSET.\r | |
206 | \r | |
207 | @param[in] HiiHandle A handle that was previously registered in the HII Database.\r | |
208 | @param[in] StringId The identifier of the string to retrieved from the string \r | |
209 | package associated with HiiHandle.\r | |
210 | @param[in] Language The language of the string to retrieve. If this parameter \r | |
211 | is NULL, then the current platform language is used. The \r | |
212 | format of Language must follow the language format assumed \r | |
213 | the HII Database.\r | |
214 | \r | |
215 | @retval NULL The string specified by StringId is not present in the string package.\r | |
216 | @retval Other The string was returned.\r | |
08e4b3cf | 217 | \r |
218 | **/\r | |
cb7d01c0 | 219 | EFI_STRING\r |
08e4b3cf | 220 | EFIAPI\r |
cb7d01c0 | 221 | HiiGetString (\r |
222 | IN EFI_HII_HANDLE HiiHandle,\r | |
223 | IN EFI_STRING_ID StringId,\r | |
224 | IN CONST CHAR8 *Language OPTIONAL\r | |
08e4b3cf | 225 | )\r |
226 | {\r | |
227 | EFI_STATUS Status;\r | |
cb7d01c0 | 228 | UINTN StringSize;\r |
229 | CHAR16 TempString;\r | |
230 | EFI_STRING String;\r | |
231 | CHAR8 *SupportedLanguages;\r | |
232 | CHAR8 *PlatformLanguage;\r | |
ea7cd3ec | 233 | CHAR8 *BestLanguage;\r |
08e4b3cf | 234 | \r |
cb7d01c0 | 235 | ASSERT (HiiHandle != NULL);\r |
236 | ASSERT (StringId != 0);\r | |
08e4b3cf | 237 | \r |
cb7d01c0 | 238 | //\r |
239 | // Initialize all allocated buffers to NULL\r | |
240 | // \r | |
241 | SupportedLanguages = NULL;\r | |
242 | PlatformLanguage = NULL;\r | |
243 | BestLanguage = NULL;\r | |
244 | String = NULL;\r | |
08e4b3cf | 245 | \r |
cb7d01c0 | 246 | //\r |
247 | // Get the languages that the package specified by HiiHandle supports\r | |
248 | //\r | |
249 | SupportedLanguages = HiiGetSupportedLanguages (HiiHandle);\r | |
250 | if (SupportedLanguages == NULL) {\r | |
251 | goto Error;\r | |
08e4b3cf | 252 | }\r |
253 | \r | |
cb7d01c0 | 254 | //\r |
255 | // Get the current platform language setting\r | |
256 | //\r | |
257 | PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r | |
08e4b3cf | 258 | \r |
cb7d01c0 | 259 | //\r |
260 | // If Languag is NULL, then set it to an empty string, so it will be \r | |
261 | // skipped by GetBestLanguage()\r | |
262 | //\r | |
263 | if (Language == NULL) {\r | |
264 | Language = "";\r | |
265 | }\r | |
08e4b3cf | 266 | \r |
cb7d01c0 | 267 | //\r |
268 | // Get the best matching language from SupportedLanguages\r | |
269 | //\r | |
270 | BestLanguage = GetBestLanguage (\r | |
271 | SupportedLanguages, \r | |
272 | FALSE, // RFC 4646 mode\r | |
273 | Language, // Highest priority \r | |
274 | PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority\r | |
275 | SupportedLanguages, // Lowest priority \r | |
276 | NULL\r | |
277 | );\r | |
278 | if (BestLanguage == NULL) {\r | |
279 | goto Error;\r | |
280 | }\r | |
08e4b3cf | 281 | \r |
cb7d01c0 | 282 | //\r |
283 | // Retrieve the size of the string in the string package for the BestLanguage\r | |
284 | //\r | |
285 | StringSize = 0;\r | |
286 | Status = gHiiString->GetString (\r | |
287 | gHiiString,\r | |
288 | BestLanguage,\r | |
289 | HiiHandle,\r | |
290 | StringId,\r | |
291 | &TempString,\r | |
292 | &StringSize,\r | |
293 | NULL\r | |
294 | );\r | |
295 | //\r | |
296 | // If GetString() returns EFI_SUCCESS for a zero size, \r | |
297 | // then there are no supported languages registered for HiiHandle. If GetString() \r | |
298 | // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present\r | |
299 | // in the HII Database\r | |
300 | //\r | |
301 | if (Status != EFI_BUFFER_TOO_SMALL) {\r | |
302 | goto Error;\r | |
303 | }\r | |
08e4b3cf | 304 | \r |
cb7d01c0 | 305 | //\r |
306 | // Allocate a buffer for the return string\r | |
307 | //\r | |
308 | String = AllocateZeroPool (StringSize);\r | |
309 | if (String == NULL) {\r | |
310 | goto Error;\r | |
311 | }\r | |
08e4b3cf | 312 | \r |
cb7d01c0 | 313 | //\r |
314 | // Retrieve the string from the string package\r | |
315 | //\r | |
316 | Status = gHiiString->GetString (\r | |
317 | gHiiString,\r | |
318 | BestLanguage,\r | |
319 | HiiHandle,\r | |
320 | StringId,\r | |
321 | String,\r | |
322 | &StringSize,\r | |
323 | NULL\r | |
324 | );\r | |
325 | if (EFI_ERROR (Status)) {\r | |
326 | //\r | |
327 | // Free the buffer and return NULL if the supported languages can not be retrieved.\r | |
328 | //\r | |
329 | FreePool (String);\r | |
330 | String = NULL;\r | |
08e4b3cf | 331 | }\r |
332 | \r | |
cb7d01c0 | 333 | Error:\r |
334 | //\r | |
335 | // Free allocated buffers\r | |
336 | //\r | |
337 | if (SupportedLanguages != NULL) {\r | |
338 | FreePool (SupportedLanguages);\r | |
339 | }\r | |
340 | if (PlatformLanguage != NULL) {\r | |
341 | FreePool (PlatformLanguage);\r | |
342 | }\r | |
343 | if (BestLanguage != NULL) {\r | |
344 | FreePool (BestLanguage);\r | |
08e4b3cf | 345 | }\r |
346 | \r | |
cb7d01c0 | 347 | //\r |
348 | // Return the Null-terminated Unicode string\r | |
349 | //\r | |
350 | return String;\r | |
08e4b3cf | 351 | }\r |
352 | \r |