2 This file implements the protocol functions related to string package.
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
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.
16 #include "HiiDatabase.h"
23 ISO639TORFC3066MAP Iso639ToRfc3066Map
[] = {
29 ConvertIso639ToRfc3066 (
34 CHAR8 AsciiLanguage
[ISO_639_2_ENTRY_SIZE
+ 1];
36 AsciiStrnCpy (AsciiLanguage
, Iso638Lang
, sizeof (AsciiLanguage
));
37 for (Index
= 0; Index
< ISO_639_2_ENTRY_SIZE
+ 1; Index
++) {
38 if (AsciiLanguage
[Index
] == 0) {
40 } else if (AsciiLanguage
[Index
] >= 'A' && AsciiLanguage
[Index
] <= 'Z') {
41 AsciiLanguage
[Index
] = AsciiLanguage
[Index
] - 'A' + 'a';
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
;
51 return (CHAR8
*) NULL
;
58 IN EFI_HII_PROTOCOL
*This
,
59 IN CHAR16
*StringToTest
,
60 IN OUT UINT32
*FirstMissing
,
61 OUT UINT32
*GlyphBufferSize
66 Test if all of the characters in a string have corresponding font characters.
81 GetTagGuidByFwHiiHandle (
82 IN CONST HII_THUNK_PRIVATE_DATA
*Private
,
83 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle
,
88 HII_THUNK_CONTEXT
*ThunkContext
;
90 ASSERT (TagGuid
!= NULL
);
92 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
93 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
95 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
97 if (FwHiiHandle
== ThunkContext
->FwHiiHandle
) {
98 CopyGuid (TagGuid
, &ThunkContext
->TagGuid
);
102 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
105 return EFI_NOT_FOUND
;
113 IN EFI_HII_PROTOCOL
*This
,
115 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
116 IN OUT STRING_REF
*Reference
,
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
135 HII_THUNK_PRIVATE_DATA
*Private
;
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];
144 CHAR8
*Rfc3066AsciiLanguage
;
146 LastStringId
= (EFI_STRING_ID
) 0;
147 StringId
= (EFI_STRING_ID
) 0;
149 Rfc3066AsciiLanguage
= NULL
;
151 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
153 Status
= GetTagGuidByFwHiiHandle (Private
, Handle
, &TagGuid
);
154 ASSERT_EFI_ERROR (Status
);
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
);
165 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
166 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
167 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
169 if (CompareGuid (&TagGuid
, &ThunkContext
->TagGuid
)) {
171 if (*Reference
== 0) {
173 // Create a new string token.
175 if (Rfc3066AsciiLanguage
== NULL
) {
177 // For all languages in the package list.
179 Status
= HiiLibNewString (ThunkContext
->UefiHiiHandle
, &StringId
, NewString
);
182 // For specified language.
184 Status
= mHiiStringProtocol
->NewString (
186 ThunkContext
->UefiHiiHandle
,
188 Rfc3066AsciiLanguage
,
196 // Update the existing string token.
198 if (Rfc3066AsciiLanguage
== NULL
) {
200 // For all languages in the package list.
202 Status
= HiiLibSetString (ThunkContext
->UefiHiiHandle
, *Reference
, NewString
);
205 // For specified language.
207 Status
= mHiiStringProtocol
->SetString (
209 ThunkContext
->UefiHiiHandle
,
211 Rfc3066AsciiLanguage
,
217 if (EFI_ERROR (Status
)) {
219 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
221 return EFI_INVALID_PARAMETER
;
224 if (*Reference
== 0) {
226 // When creating new string token, make sure all created token is the same
227 // for all string packages registered using FW HII interface.
229 if (LastStringId
== (EFI_STRING_ID
) 0) {
230 LastStringId
= StringId
;
232 if (LastStringId
!= StringId
) {
234 return EFI_INVALID_PARAMETER
;
240 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
244 if (*Reference
== 0) {
245 *Reference
= StringId
;
247 Status
= EFI_SUCCESS
;
249 DEBUG((EFI_D_ERROR
, "Thunk HiiNewString fails to find the String Packages to update\n"));
251 // BUGBUG: Remove ths ASSERT when development is done.
254 Status
= EFI_NOT_FOUND
;
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.
263 ASSERT_EFI_ERROR (EFI_ERROR (Status
) && Status
!= EFI_NOT_FOUND
);
271 IN EFI_HII_PROTOCOL
*This
,
272 IN FRAMEWORK_EFI_HII_HANDLE Handle
278 This function removes any new strings that were added after the initial string export for this handle.
292 IN EFI_HII_PROTOCOL
*This
,
293 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
296 IN CHAR16
*LanguageString
,
297 IN OUT UINTN
*BufferLengthTemp
,
298 OUT EFI_STRING StringBuffer
304 This function extracts a string from a package already registered with the EFI HII database.
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
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.
328 CHAR8
*Iso639AsciiLanguage
;
329 HII_THUNK_PRIVATE_DATA
*Private
;
330 CHAR8
*Rfc3066AsciiLanguage
;
331 EFI_HII_HANDLE UefiHiiHandle
;
334 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
336 Iso639AsciiLanguage
= NULL
;
337 Rfc3066AsciiLanguage
= NULL
;
339 if (LanguageString
!= NULL
) {
340 Iso639AsciiLanguage
= AllocateZeroPool (StrLen (LanguageString
) + 1);
341 if (Iso639AsciiLanguage
== NULL
) {
342 return EFI_OUT_OF_RESOURCES
;
344 UnicodeStrToAsciiStr (LanguageString
, Iso639AsciiLanguage
);
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.
350 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (Iso639AsciiLanguage
);
353 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
354 // Iso639ToRfc3066Map.
356 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
360 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
361 if (UefiHiiHandle
== NULL
) {
362 Status
= EFI_NOT_FOUND
;
366 if (Rfc3066AsciiLanguage
== NULL
) {
367 Status
= HiiLibGetString (UefiHiiHandle
, Token
, StringBuffer
, BufferLengthTemp
);
369 Status
= mHiiStringProtocol
->GetString (
371 Rfc3066AsciiLanguage
,
381 SafeFreePool (Iso639AsciiLanguage
);
389 IN EFI_HII_PROTOCOL
*This
,
390 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
392 IN OUT UINT16
*Index
,
394 IN CHAR16
*LanguageString
,
395 IN OUT UINT16
*BufferLength
,
396 OUT EFI_STRING StringBuffer
402 This function allows a program to extract a part of a string of not more than a given width.
403 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
404 columns. The effort of measuring the fit of strings inside columns is localized to this call.
413 return EFI_UNSUPPORTED
;