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