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];
133 CHAR8
*Rfc3066AsciiLanguage
;
135 LastStringId
= (EFI_STRING_ID
) 0;
136 StringId
= (EFI_STRING_ID
) 0;
138 Rfc3066AsciiLanguage
= NULL
;
140 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
142 Status
= GetTagGuidByFwHiiHandle (Private
, Handle
, &TagGuid
);
143 ASSERT_EFI_ERROR (Status
);
145 if (Language
!= NULL
) {
146 ZeroMem (AsciiLanguage
, sizeof (AsciiLanguage
));;
148 UnicodeStrToAsciiStr (Language
, AsciiLanguage
);
149 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (AsciiLanguage
);
150 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
153 Link
= GetFirstNode (&Private
->ThunkContextListHead
);
154 while (!IsNull (&Private
->ThunkContextListHead
, Link
)) {
155 ThunkContext
= HII_THUNK_CONTEXT_FROM_LINK (Link
);
157 if (CompareGuid (&TagGuid
, &ThunkContext
->TagGuid
)) {
159 if (*Reference
== 0) {
161 // Create a new string token.
163 if (Rfc3066AsciiLanguage
== NULL
) {
165 // For all languages in the package list.
167 Status
= HiiLibNewString (ThunkContext
->UefiHiiHandle
, &StringId
, NewString
);
170 // For specified language.
172 Status
= mHiiStringProtocol
->NewString (
174 ThunkContext
->UefiHiiHandle
,
176 Rfc3066AsciiLanguage
,
184 // Update the existing string token.
186 if (Rfc3066AsciiLanguage
== NULL
) {
188 // For all languages in the package list.
190 Status
= HiiLibSetString (ThunkContext
->UefiHiiHandle
, *Reference
, NewString
);
193 // For specified language.
195 Status
= mHiiStringProtocol
->SetString (
197 ThunkContext
->UefiHiiHandle
,
199 Rfc3066AsciiLanguage
,
205 if (EFI_ERROR (Status
)) {
207 // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.
209 return EFI_INVALID_PARAMETER
;
212 if (*Reference
== 0) {
214 // When creating new string token, make sure all created token is the same
215 // for all string packages registered using FW HII interface.
217 if (LastStringId
== (EFI_STRING_ID
) 0) {
218 LastStringId
= StringId
;
220 if (LastStringId
!= StringId
) {
222 return EFI_INVALID_PARAMETER
;
228 Link
= GetNextNode (&Private
->ThunkContextListHead
, Link
);
232 if (*Reference
== 0) {
233 *Reference
= StringId
;
235 Status
= EFI_SUCCESS
;
237 DEBUG((EFI_D_ERROR
, "Thunk HiiNewString fails to find the String Packages to update\n"));
239 // BUGBUG: Remove ths ASSERT when development is done.
242 Status
= EFI_NOT_FOUND
;
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.
251 ASSERT_EFI_ERROR (EFI_ERROR (Status
) && Status
!= EFI_NOT_FOUND
);
259 IN EFI_HII_PROTOCOL
*This
,
260 IN FRAMEWORK_EFI_HII_HANDLE Handle
266 This function removes any new strings that were added after the initial string export for this handle.
280 IN EFI_HII_PROTOCOL
*This
,
281 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
284 IN CHAR16
*LanguageString
,
285 IN OUT UINTN
*BufferLengthTemp
,
286 OUT EFI_STRING StringBuffer
292 This function extracts a string from a package already registered with the EFI HII database.
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
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.
316 CHAR8
*Iso639AsciiLanguage
;
317 HII_THUNK_PRIVATE_DATA
*Private
;
318 CHAR8
*Rfc3066AsciiLanguage
;
319 EFI_HII_HANDLE UefiHiiHandle
;
322 Private
= HII_THUNK_PRIVATE_DATA_FROM_THIS(This
);
324 Iso639AsciiLanguage
= NULL
;
325 Rfc3066AsciiLanguage
= NULL
;
327 if (LanguageString
!= NULL
) {
328 Iso639AsciiLanguage
= AllocateZeroPool (StrLen (LanguageString
) + 1);
329 if (Iso639AsciiLanguage
== NULL
) {
330 return EFI_OUT_OF_RESOURCES
;
332 UnicodeStrToAsciiStr (LanguageString
, Iso639AsciiLanguage
);
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.
338 Rfc3066AsciiLanguage
= ConvertIso639ToRfc3066 (Iso639AsciiLanguage
);
341 // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to
342 // Iso639ToRfc3066Map.
344 ASSERT (Rfc3066AsciiLanguage
!= NULL
);
348 UefiHiiHandle
= FwHiiHandleToUefiHiiHandle (Private
, Handle
);
349 if (UefiHiiHandle
== NULL
) {
350 Status
= EFI_NOT_FOUND
;
354 if (Rfc3066AsciiLanguage
== NULL
) {
355 Status
= HiiLibGetString (UefiHiiHandle
, Token
, StringBuffer
, BufferLengthTemp
);
357 Status
= mHiiStringProtocol
->GetString (
359 Rfc3066AsciiLanguage
,
369 SafeFreePool (Iso639AsciiLanguage
);
377 IN EFI_HII_PROTOCOL
*This
,
378 IN FRAMEWORK_EFI_HII_HANDLE Handle
,
380 IN OUT UINT16
*Index
,
382 IN CHAR16
*LanguageString
,
383 IN OUT UINT16
*BufferLength
,
384 OUT EFI_STRING StringBuffer
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.
401 return EFI_UNSUPPORTED
;