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 (
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
;
41 return (CHAR8
*) NULL
;
48 IN EFI_HII_PROTOCOL
*This
,
49 IN CHAR16
*StringToTest
,
50 IN OUT UINT32
*FirstMissing
,
51 OUT UINT32
*GlyphBufferSize
56 Test if all of the characters in a string have corresponding font characters.
71 GetTagGuidByFwHiiHandle (
72 IN CONST HII_THUNK_PRIVATE_DATA
*Private
,
73 IN FRAMEWORK_EFI_HII_HANDLE FwHiiHandle
,
78 HII_THUNK_CONTEXT
*ThunkContext
;
80 ASSERT (TagGuid
!= NULL
);
82 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
83 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
85 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
87 if (FwHiiHandle
== ThunkContext
->FwHiiHandle
) {
88 CopyGuid (TagGuid
, &ThunkContext
->TagGuid
);
92 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
103 IN EFI_HII_PROTOCOL
*This
,
105 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
106 IN OUT STRING_REF
*Reference
,
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
125 HII_THUNK_PRIVATE_DATA
*Private
;
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 CHAR16 LanguageCopy
[ISO_639_2_ENTRY_SIZE
+ 1];
134 CHAR8
*Rfc3066AsciiLanguage
;
136 LastStringId
= (EFI_STRING_ID
) 0;
137 StringId
= (EFI_STRING_ID
) 0;
139 Rfc3066AsciiLanguage
= NULL
;
141 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
143 Status
= GetTagGuidByFwHiiHandle (Private
, Handle
, &TagGuid
);
144 ASSERT_EFI_ERROR (Status
);
146 if (Language
!= NULL
) {
147 ZeroMem (AsciiLanguage
, sizeof (AsciiLanguage
));;
148 ZeroMem (LanguageCopy
, sizeof (LanguageCopy
));
149 CopyMem (LanguageCopy
, Language
, ISO_639_2_ENTRY_SIZE
* sizeof (CHAR16
));
150 UnicodeStrToAsciiStr (LanguageCopy
, AsciiLanguage
);
151 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (AsciiLanguage
);
152 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
155 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
156 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
157 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
159 if (CompareGuid (&TagGuid
, &ThunkContext
->TagGuid
)) {
161 if (*Reference
== 0) {
163 // Create a new string token.
165 if (Rfc3066AsciiLanguage
== NULL
) {
167 // For all languages in the package list.
169 Status
= HiiLibNewString (ThunkContext
->UefiHiiHandle
, &StringId
, NewString
);
172 // For specified language.
174 Status
= mHiiStringProtocol
->NewString (
176 ThunkContext
->UefiHiiHandle
,
178 Rfc3066AsciiLanguage
,
186 // Update the existing string token.
188 if (Rfc3066AsciiLanguage
== NULL
) {
190 // For all languages in the package list.
192 Status
= HiiLibSetString (ThunkContext
->UefiHiiHandle
, *Reference
, NewString
);
195 // For specified language.
197 Status
= mHiiStringProtocol
->SetString (
199 ThunkContext
->UefiHiiHandle
,
201 Rfc3066AsciiLanguage
,
207 if (EFI_ERROR (Status
)) {
209 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
211 return EFI_INVALID_PARAMETER
;
214 if (*Reference
== 0) {
216 // When creating new string token, make sure all created token is the same
217 // for all string packages registered using FW HII interface.
219 if (LastStringId
== (EFI_STRING_ID
) 0) {
220 LastStringId
= StringId
;
222 if (LastStringId
!= StringId
) {
224 return EFI_INVALID_PARAMETER
;
230 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
234 if (*Reference
== 0) {
235 *Reference
= StringId
;
237 Status
= EFI_SUCCESS
;
239 DEBUG((EFI_D_ERROR
, "Thunk HiiNewString fails to find the String Packages to update\n"));
241 // BUGBUG: Remove ths ASSERT when development is done.
244 Status
= EFI_NOT_FOUND
;
248 // For UNI file, some String may not be defined for a language. This has been true for a lot of platform code.
249 // For this case, EFI_NOT_FOUND will be returned. To allow the old code to be run without porting, we don't assert
250 // on EFI_NOT_FOUND. The missing Strings will be shown if user select a differnt languages other than the default
251 // English language for the platform.
253 ASSERT_EFI_ERROR (EFI_ERROR (Status
) && Status
!= EFI_NOT_FOUND
);
261 IN EFI_HII_PROTOCOL
*This
,
262 IN FRAMEWORK_EFI_HII_HANDLE Handle
268 This function removes any new strings that were added after the initial string export for this handle.
282 IN EFI_HII_PROTOCOL
*This
,
283 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
286 IN CHAR16
*LanguageString
,
287 IN OUT UINTN
*BufferLengthTemp
,
288 OUT EFI_STRING StringBuffer
294 This function extracts a string from a package already registered with the EFI HII database.
297 This - A pointer to the EFI_HII_PROTOCOL instance.
298 Handle - The HII handle on which the string resides.
299 Token - The string token assigned to the string.
300 Raw - If TRUE, the string is returned unedited in the internal storage format described
301 above. If false, the string returned is edited by replacing <cr> with <space>
302 and by removing special characters such as the <wide> prefix.
303 LanguageString - Pointer to a NULL-terminated string containing a single ISO 639-2 language
304 identifier, indicating the language to print. If the LanguageString is empty (starts
305 with a NULL), the default system language will be used to determine the language.
306 BufferLength - Length of the StringBuffer. If the status reports that the buffer width is too
307 small, this parameter is filled with the length of the buffer needed.
308 StringBuffer - The buffer designed to receive the characters in the string. Type EFI_STRING is
312 EFI_INVALID_PARAMETER - If input parameter is invalid.
313 EFI_BUFFER_TOO_SMALL - If the *BufferLength is too small.
314 EFI_SUCCESS - Operation is successful.
318 CHAR8
*Iso639AsciiLanguage
;
319 HII_THUNK_PRIVATE_DATA
*Private
;
320 CHAR8
*Rfc3066AsciiLanguage
;
321 EFI_HII_HANDLE UefiHiiHandle
;
324 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
326 Iso639AsciiLanguage
= NULL
;
327 Rfc3066AsciiLanguage
= NULL
;
329 if (LanguageString
!= NULL
) {
330 Iso639AsciiLanguage
= AllocateZeroPool (StrLen (LanguageString
) + 1);
331 if (Iso639AsciiLanguage
== NULL
) {
332 return EFI_OUT_OF_RESOURCES
;
334 UnicodeStrToAsciiStr (LanguageString
, Iso639AsciiLanguage
);
337 // Caller of Framework HII Interface uses the Language Identification String defined
338 // in Iso639. So map it to the Language Identifier defined in RFC3066.
340 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (Iso639AsciiLanguage
);
343 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
344 // Iso639ToRfc3066Map.
346 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
350 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
351 if (UefiHiiHandle
== NULL
) {
352 Status
= EFI_NOT_FOUND
;
356 if (Rfc3066AsciiLanguage
== NULL
) {
357 Status
= HiiLibGetString (UefiHiiHandle
, Token
, StringBuffer
, BufferLengthTemp
);
359 Status
= mHiiStringProtocol
->GetString (
361 Rfc3066AsciiLanguage
,
371 SafeFreePool (Iso639AsciiLanguage
);
379 IN EFI_HII_PROTOCOL
*This
,
380 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
382 IN OUT UINT16
*Index
,
384 IN CHAR16
*LanguageString
,
385 IN OUT UINT16
*BufferLength
,
386 OUT EFI_STRING StringBuffer
392 This function allows a program to extract a part of a string of not more than a given width.
393 With repeated calls, this allows a calling program to extract "lines" of text that fit inside
394 columns. The effort of measuring the fit of strings inside columns is localized to this call.
403 return EFI_UNSUPPORTED
;