]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Strings.c
clean up for IPF ICC tool chain.
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Strings.c
1 /**@file
2 This file implements the protocol functions related to string package.
3
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "HiiDatabase.h"
17
18 typedef struct {
19 CHAR8 *Iso639;
20 CHAR8 *Rfc3066;
21 } ISO639TORFC3066MAP;
22
23 ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {
24 {"eng", "en-US"},
25 {"fra", "fr-FR"},
26 };
27
28 CHAR8 *
29 ConvertIso639ToRfc3066 (
30 CHAR8 *Iso638Lang
31 )
32 {
33 UINTN Index;
34 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];
35
36 AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));
37 for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {
38 if (AsciiLanguage [Index] == 0) {
39 break;
40 } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {
41 AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');
42 }
43 }
44
45 for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {
46 if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {
47 return Iso639ToRfc3066Map[Index].Rfc3066;
48 }
49 }
50
51 return (CHAR8 *) NULL;
52 }
53
54
55 EFI_STATUS
56 EFIAPI
57 HiiTestString (
58 IN EFI_HII_PROTOCOL *This,
59 IN CHAR16 *StringToTest,
60 IN OUT UINT32 *FirstMissing,
61 OUT UINT32 *GlyphBufferSize
62 )
63 /*++
64
65 Routine Description:
66 Test if all of the characters in a string have corresponding font characters.
67
68 Arguments:
69
70 Returns:
71
72 --*/
73 {
74 ASSERT (FALSE);
75 return EFI_SUCCESS;
76 }
77
78
79
80 EFI_STATUS
81 GetTagGuidByFwHiiHandle (
82 IN CONST HII_THUNK_PRIVATE_DATA *Private,
83 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle,
84 OUT EFI_GUID *TagGuid
85 )
86 {
87 LIST_ENTRY *Link;
88 HII_THUNK_CONTEXT *ThunkContext;
89
90 ASSERT (TagGuid != NULL);
91
92 Link = GetFirstNode (&Private->ThunkContextListHead);
93 while (!IsNull (&Private->ThunkContextListHead, Link)) {
94
95 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
96
97 if (FwHiiHandle == ThunkContext->FwHiiHandle) {
98 CopyGuid (TagGuid, &ThunkContext->TagGuid);
99 return EFI_SUCCESS;
100 }
101
102 Link = GetNextNode (&Private->ThunkContextListHead, Link);
103 }
104
105 return EFI_NOT_FOUND;
106 }
107
108
109
110 EFI_STATUS
111 EFIAPI
112 HiiNewString (
113 IN EFI_HII_PROTOCOL *This,
114 IN CHAR16 *Language,
115 IN FRAMEWORK_EFI_HII_HANDLE Handle,
116 IN OUT STRING_REF *Reference,
117 IN CHAR16 *NewString
118 )
119 /*++
120
121 Routine Description:
122 This function allows a new String to be added to an already existing String Package.
123 We will make a buffer the size of the package + StrSize of the new string. We will
124 copy the string package that first gets changed and the following language packages until
125 we encounter the NULL string package. All this time we will ensure that the offsets have
126 been adjusted.
127
128 Arguments:
129
130 Returns:
131
132 --*/
133 {
134 EFI_STATUS Status;
135 HII_THUNK_PRIVATE_DATA *Private;
136 EFI_GUID TagGuid;
137 LIST_ENTRY *Link;
138 HII_THUNK_CONTEXT *ThunkContext;
139 EFI_STRING_ID StringId;
140 EFI_STRING_ID LastStringId;
141 CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];
142 CHAR16 LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];
143 BOOLEAN Found;
144 CHAR8 *Rfc3066AsciiLanguage;
145
146 LastStringId = (EFI_STRING_ID) 0;
147 StringId = (EFI_STRING_ID) 0;
148 Found = FALSE;
149 Rfc3066AsciiLanguage = NULL;
150
151 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
152
153 Status = GetTagGuidByFwHiiHandle (Private, Handle, &TagGuid);
154 ASSERT_EFI_ERROR (Status);
155
156 if (Language != NULL) {
157 ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;
158 ZeroMem (LanguageCopy, sizeof (LanguageCopy));
159 CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));
160 UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);
161 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);
162 ASSERT (Rfc3066AsciiLanguage != NULL);
163 }
164
165 Link = GetFirstNode (&Private->ThunkContextListHead);
166 while (!IsNull (&Private->ThunkContextListHead, Link)) {
167 ThunkContext = HII_THUNK_CONTEXT_FROM_LINK (Link);
168
169 if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {
170 Found = TRUE;
171 if (*Reference == 0) {
172 //
173 // Create a new string token.
174 //
175 if (Rfc3066AsciiLanguage == NULL) {
176 //
177 // For all languages in the package list.
178 //
179 Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &StringId, NewString);
180 } else {
181 //
182 // For specified language.
183 //
184 Status = mHiiStringProtocol->NewString (
185 mHiiStringProtocol,
186 ThunkContext->UefiHiiHandle,
187 &StringId,
188 Rfc3066AsciiLanguage,
189 NULL,
190 NewString,
191 NULL
192 );
193 }
194 } else {
195 //
196 // Update the existing string token.
197 //
198 if (Rfc3066AsciiLanguage == NULL) {
199 //
200 // For all languages in the package list.
201 //
202 Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *Reference, NewString);
203 } else {
204 //
205 // For specified language.
206 //
207 Status = mHiiStringProtocol->SetString (
208 mHiiStringProtocol,
209 ThunkContext->UefiHiiHandle,
210 *Reference,
211 Rfc3066AsciiLanguage,
212 NewString,
213 NULL
214 );
215 }
216 }
217 if (EFI_ERROR (Status)) {
218 //
219 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
220 //
221 return EFI_INVALID_PARAMETER;
222 }
223
224 if (*Reference == 0) {
225 //
226 // When creating new string token, make sure all created token is the same
227 // for all string packages registered using FW HII interface.
228 //
229 if (LastStringId == (EFI_STRING_ID) 0) {
230 LastStringId = StringId;
231 } else {
232 if (LastStringId != StringId) {
233 ASSERT(FALSE);
234 return EFI_INVALID_PARAMETER;
235 }
236 }
237 }
238 }
239
240 Link = GetNextNode (&Private->ThunkContextListHead, Link);
241 }
242
243 if (Found) {
244 if (*Reference == 0) {
245 *Reference = StringId;
246 }
247 Status = EFI_SUCCESS;
248 } else {
249 DEBUG((EFI_D_ERROR, "Thunk HiiNewString fails to find the String Packages to update\n"));
250 //
251 // BUGBUG: Remove ths ASSERT when development is done.
252 //
253 ASSERT (FALSE);
254 Status = EFI_NOT_FOUND;
255 }
256
257 //
258 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.
259 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert
260 // on EFI_NOT_FOUND. The missing Strings will be shown if user select a differnt languages other than the default
261 // English language for the platform.
262 //
263 ASSERT_EFI_ERROR (EFI_ERROR (Status) && Status != EFI_NOT_FOUND);
264
265 return Status;
266 }
267
268 EFI_STATUS
269 EFIAPI
270 HiiResetStrings (
271 IN EFI_HII_PROTOCOL *This,
272 IN FRAMEWORK_EFI_HII_HANDLE Handle
273 )
274 /*++
275
276 Routine Description:
277
278 This function removes any new strings that were added after the initial string export for this handle.
279
280 Arguments:
281
282 Returns:
283
284 --*/
285 {
286 return EFI_SUCCESS;
287 }
288
289 EFI_STATUS
290 EFIAPI
291 HiiGetString (
292 IN EFI_HII_PROTOCOL *This,
293 IN FRAMEWORK_EFI_HII_HANDLE Handle,
294 IN STRING_REF Token,
295 IN BOOLEAN Raw,
296 IN CHAR16 *LanguageString,
297 IN OUT UINTN *BufferLengthTemp,
298 OUT EFI_STRING StringBuffer
299 )
300 /*++
301
302 Routine Description:
303
304 This function extracts a string from a package already registered with the EFI HII database.
305
306 Arguments:
307 This - A pointer to the EFI_HII_PROTOCOL instance.
308 Handle - The HII handle on which the string resides.
309 Token - The string token assigned to the string.
310 Raw - If TRUE, the string is returned unedited in the internal storage format described
311 above. If false, the string returned is edited by replacing <cr> with <space>
312 and by removing special characters such as the <wide> prefix.
313 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language
314 identifier, indicating the language to print. If the LanguageString is empty (starts
315 with a NULL), the default system language will be used to determine the language.
316 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too
317 small, this parameter is filled with the length of the buffer needed.
318 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is
319 defined in String.
320
321 Returns:
322 EFI_INVALID_PARAMETER - If input parameter is invalid.
323 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.
324 EFI_SUCCESS - Operation is successful.
325
326 --*/
327 {
328 CHAR8 *Iso639AsciiLanguage;
329 HII_THUNK_PRIVATE_DATA *Private;
330 CHAR8 *Rfc3066AsciiLanguage;
331 EFI_HII_HANDLE UefiHiiHandle;
332 EFI_STATUS Status;
333
334 Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);
335
336 Iso639AsciiLanguage = NULL;
337 Rfc3066AsciiLanguage = NULL;
338
339 if (LanguageString != NULL) {
340 Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);
341 if (Iso639AsciiLanguage == NULL) {
342 return EFI_OUT_OF_RESOURCES;
343 }
344 UnicodeStrToAsciiStr (LanguageString, Iso639AsciiLanguage);
345
346 //
347 // Caller of Framework HII Interface uses the Language Identification String defined
348 // in Iso639. So map it to the Language Identifier defined in RFC3066.
349 //
350 Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);
351
352 //
353 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
354 // Iso639ToRfc3066Map.
355 //
356 ASSERT (Rfc3066AsciiLanguage != NULL);
357
358 }
359
360 UefiHiiHandle = FwHiiHandleToUefiHiiHandle (Private, Handle);
361 if (UefiHiiHandle == NULL) {
362 Status = EFI_NOT_FOUND;
363 goto Done;
364 }
365
366 if (Rfc3066AsciiLanguage == NULL) {
367 Status = HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);
368 } else {
369 Status = mHiiStringProtocol->GetString (
370 mHiiStringProtocol,
371 Rfc3066AsciiLanguage,
372 UefiHiiHandle,
373 Token,
374 StringBuffer,
375 BufferLengthTemp,
376 NULL
377 );
378 }
379
380 Done:
381 if (Iso639AsciiLanguage != NULL) {
382 FreePool (Iso639AsciiLanguage);
383 }
384
385 return Status;
386 }
387
388 EFI_STATUS
389 EFIAPI
390 HiiGetLine (
391 IN EFI_HII_PROTOCOL *This,
392 IN FRAMEWORK_EFI_HII_HANDLE Handle,
393 IN STRING_REF Token,
394 IN OUT UINT16 *Index,
395 IN UINT16 LineWidth,
396 IN CHAR16 *LanguageString,
397 IN OUT UINT16 *BufferLength,
398 OUT EFI_STRING StringBuffer
399 )
400 /*++
401
402 Routine Description:
403
404 This function allows a program to extract a part of a string of not more than a given width.
405 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
406 columns. The effort of measuring the fit of strings inside columns is localized to this call.
407
408 Arguments:
409
410 Returns:
411
412 --*/
413 {
414 ASSERT (FALSE);
415 return EFI_UNSUPPORTED;
416 }
417
418