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"
21 IN EFI_HII_PROTOCOL
*This
,
22 IN CHAR16
*StringToTest
,
23 IN OUT UINT32
*FirstMissing
,
24 OUT UINT32
*GlyphBufferSize
29 Test if all of the characters in a string have corresponding font characters.
42 GetTagGuidByFwHiiHandle (
43 IN CONST HII_THUNK_PRIVATE_DATA
*Private
,
44 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle
,
49 HII_THUNK_CONTEXT
*ThunkContext
;
51 ASSERT (TagGuid
!= NULL
);
53 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
54 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
56 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
58 if (FwHiiHandle
== ThunkContext
->FwHiiHandle
) {
59 CopyGuid (TagGuid
, &ThunkContext
->TagGuid
);
63 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
74 IN EFI_HII_PROTOCOL
*This
,
76 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
77 IN OUT STRING_REF
*Reference
,
83 This function allows a new String to be added to an already existing String Package.
84 We will make a buffer the size of the package + StrSize of the new string. We will
85 copy the string package that first gets changed and the following language packages until
86 we encounter the NULL string package. All this time we will ensure that the offsets have
96 HII_THUNK_PRIVATE_DATA
*Private
;
99 HII_THUNK_CONTEXT
*ThunkContext
;
100 EFI_STRING_ID StringId
;
101 EFI_STRING_ID LastStringId
;
102 CHAR8
*AsciiLanguage
;
106 // BugBug: Conver the language to 3066.
109 LastStringId
= (EFI_STRING_ID
) 0;
110 StringId
= (EFI_STRING_ID
) 0;
112 AsciiLanguage
= NULL
;
114 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
116 Status
= GetTagGuidByFwHiiHandle (Private
, Handle
, &TagGuid
);
117 ASSERT_EFI_ERROR (Status
);
119 if (Language
!= NULL
) {
120 AsciiLanguage
= AllocateZeroPool (StrLen (Language
) + 1);
121 UnicodeStrToAsciiStr (Language
, AsciiLanguage
);
124 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
125 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
126 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
128 if (CompareGuid (&TagGuid
, &ThunkContext
->TagGuid
)) {
130 if (*Reference
== 0) {
132 // Create a new string token.
134 if (AsciiLanguage
== NULL
) {
136 // For all languages in the package list.
138 Status
= HiiLibNewString (ThunkContext
->UefiHiiHandle
, &StringId
, NewString
);
141 // For specified language.
143 Status
= mHiiStringProtocol
->NewString (
145 ThunkContext
->UefiHiiHandle
,
155 // Update the existing string token.
157 if (AsciiLanguage
== NULL
) {
159 // For all languages in the package list.
161 Status
= HiiLibSetString (ThunkContext
->UefiHiiHandle
, *Reference
, NewString
);
164 // For specified language.
166 Status
= mHiiStringProtocol
->SetString (
168 ThunkContext
->UefiHiiHandle
,
176 if (EFI_ERROR (Status
)) {
178 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
180 return EFI_INVALID_PARAMETER
;
183 if (*Reference
== 0) {
185 // When creating new string token, make sure all created token is the same
186 // for all string packages registered using FW HII interface.
188 if (LastStringId
== (EFI_STRING_ID
) 0) {
189 LastStringId
= StringId
;
191 if (LastStringId
!= StringId
) {
193 return EFI_INVALID_PARAMETER
;
199 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
203 if (*Reference
== 0) {
204 *Reference
= StringId
;
206 Status
= EFI_SUCCESS
;
208 DEBUG((EFI_D_ERROR
, "Thunk HiiNewString fails to find the String Packages to update\n"));
210 // BUGBUG: Remove ths ASSERT when development is done.
213 Status
= EFI_NOT_FOUND
;
217 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.
218 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert
219 // on EFI_NOT_FOUND. The missing Strings will be shown if user select a differnt languages other than the default
220 // English language for the platform.
222 ASSERT_EFI_ERROR (EFI_ERROR (Status
) && Status
!= EFI_NOT_FOUND
);
230 IN EFI_HII_PROTOCOL
*This
,
231 IN FRAMEWORK_EFI_HII_HANDLE Handle
237 This function removes any new strings that were added after the initial string export for this handle.
251 } ISO639TORFC3066MAP
;
253 ISO639TORFC3066MAP Iso639ToRfc3066Map
[] = {
259 ConvertIso639ToRfc3066 (
265 for (Index
= 0; Index
< sizeof (Iso639ToRfc3066Map
) / sizeof (Iso639ToRfc3066Map
[0]); Index
++) {
266 if (AsciiStrnCmp (Iso638Lang
, Iso639ToRfc3066Map
[Index
].Iso639
, AsciiStrSize (Iso638Lang
)) == 0) {
267 return Iso639ToRfc3066Map
[Index
].Rfc3066
;
271 return (CHAR8
*) NULL
;
277 IN EFI_HII_PROTOCOL
*This
,
278 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
281 IN CHAR16
*LanguageString
,
282 IN OUT UINTN
*BufferLengthTemp
,
283 OUT EFI_STRING StringBuffer
289 This function extracts a string from a package already registered with the EFI HII database.
292 This - A pointer to the EFI_HII_PROTOCOL instance.
293 Handle - The HII handle on which the string resides.
294 Token - The string token assigned to the string.
295 Raw - If TRUE, the string is returned unedited in the internal storage format described
296 above. If false, the string returned is edited by replacing <cr> with <space>
297 and by removing special characters such as the <wide> prefix.
298 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language
299 identifier, indicating the language to print. If the LanguageString is empty (starts
300 with a NULL), the default system language will be used to determine the language.
301 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too
302 small, this parameter is filled with the length of the buffer needed.
303 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is
307 EFI_INVALID_PARAMETER - If input parameter is invalid.
308 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.
309 EFI_SUCCESS - Operation is successful.
314 HII_THUNK_CONTEXT
*ThunkContext
;
315 CHAR8
*AsciiLanguage
;
316 HII_THUNK_PRIVATE_DATA
*Private
;
317 CHAR8
*Rfc3066AsciiLanguage
;
319 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
321 if (LanguageString
== NULL
) {
322 AsciiLanguage
= NULL
;
324 AsciiLanguage
= AllocateZeroPool (StrLen (LanguageString
) + 1);
325 if (AsciiLanguage
== NULL
) {
326 return EFI_OUT_OF_RESOURCES
;
328 UnicodeStrToAsciiStr (LanguageString
, AsciiLanguage
);
330 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (AsciiLanguage
);
333 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
334 // Iso639ToRfc3066Map.
336 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
338 // Caller of Framework HII Interface uses the Language Identification String defined
339 // in Iso639. So map it to the Language Identifier defined in RFC3066.
341 if (Rfc3066AsciiLanguage
!= NULL
) {
342 FreePool (AsciiLanguage
);
343 AsciiLanguage
= AllocateCopyPool (AsciiStrSize (Rfc3066AsciiLanguage
), Rfc3066AsciiLanguage
);
348 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
350 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
352 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
354 if (Handle
== ThunkContext
->FwHiiHandle
) {
355 if (AsciiLanguage
== NULL
) {
356 return HiiLibGetString (ThunkContext
->UefiHiiHandle
, Token
, StringBuffer
, BufferLengthTemp
);
358 return mHiiStringProtocol
->GetString (
361 ThunkContext
->UefiHiiHandle
,
371 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
374 return EFI_NOT_FOUND
;
380 IN EFI_HII_PROTOCOL
*This
,
381 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
383 IN OUT UINT16
*Index
,
385 IN CHAR16
*LanguageString
,
386 IN OUT UINT16
*BufferLength
,
387 OUT EFI_STRING StringBuffer
393 This function allows a program to extract a part of a string of not more than a given width.
394 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
395 columns. The effort of measuring the fit of strings inside columns is localized to this call.
404 return EFI_UNSUPPORTED
;