2008-02-02 14:11:49 +01:00
|
|
|
/** @file
|
|
|
|
Language related HII Library implementation.
|
|
|
|
|
2008-08-18 14:11:37 +02:00
|
|
|
Copyright (c) 2006 - 2008, Intel Corporation<BR>
|
2008-02-02 14:11:49 +01:00
|
|
|
All rights reserved. This program and the accompanying materials
|
|
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
#include "InternalHiiLib.h"
|
|
|
|
|
2008-07-14 07:29:49 +02:00
|
|
|
/**
|
|
|
|
Get next language from language code list (with separator ';').
|
|
|
|
|
|
|
|
If LangCode is NULL, then ASSERT.
|
|
|
|
If Lang is NULL, then ASSERT.
|
|
|
|
|
|
|
|
@param LangCode On input: point to first language in the list. On
|
|
|
|
output: point to next language in the list, or
|
|
|
|
NULL if no more language in the list.
|
|
|
|
@param Lang The first language in the list.
|
|
|
|
|
|
|
|
**/
|
2008-02-02 14:11:49 +01:00
|
|
|
VOID
|
|
|
|
EFIAPI
|
|
|
|
HiiLibGetNextLanguage (
|
|
|
|
IN OUT CHAR8 **LangCode,
|
|
|
|
OUT CHAR8 *Lang
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Index;
|
|
|
|
CHAR8 *StringPtr;
|
|
|
|
|
|
|
|
ASSERT (LangCode != NULL);
|
2008-08-12 09:20:10 +02:00
|
|
|
ASSERT (*LangCode != NULL);
|
2008-02-02 14:11:49 +01:00
|
|
|
ASSERT (Lang != NULL);
|
|
|
|
|
|
|
|
Index = 0;
|
|
|
|
StringPtr = *LangCode;
|
|
|
|
while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {
|
|
|
|
Index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyMem (Lang, StringPtr, Index);
|
|
|
|
Lang[Index] = 0;
|
|
|
|
|
|
|
|
if (StringPtr[Index] == ';') {
|
|
|
|
Index++;
|
|
|
|
}
|
|
|
|
*LangCode = StringPtr + Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-14 07:29:49 +02:00
|
|
|
/**
|
|
|
|
This function returns the list of supported languages, in the format specified
|
|
|
|
in UEFI specification Appendix M.
|
|
|
|
|
|
|
|
If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
|
|
|
|
|
|
|
|
@param HiiHandle The HII package list handle.
|
|
|
|
|
|
|
|
@retval !NULL The supported languages.
|
|
|
|
@retval NULL If Supported Languages can not be retrived.
|
|
|
|
|
|
|
|
**/
|
2008-02-02 14:11:49 +01:00
|
|
|
CHAR8 *
|
|
|
|
EFIAPI
|
|
|
|
HiiLibGetSupportedLanguages (
|
|
|
|
IN EFI_HII_HANDLE HiiHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BufferSize;
|
|
|
|
CHAR8 *LanguageString;
|
|
|
|
|
|
|
|
ASSERT (IsHiiHandleRegistered (HiiHandle));
|
|
|
|
//
|
|
|
|
// Collect current supported Languages for given HII handle
|
2008-08-18 14:11:37 +02:00
|
|
|
// First try allocate 4K buffer to store the current supported languages.
|
2008-02-02 14:11:49 +01:00
|
|
|
//
|
|
|
|
BufferSize = 0x1000;
|
2008-04-14 08:29:03 +02:00
|
|
|
LanguageString = AllocateZeroPool (BufferSize);
|
|
|
|
if (LanguageString == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-23 11:38:38 +02:00
|
|
|
|
2008-02-02 14:11:49 +01:00
|
|
|
Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);
|
|
|
|
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2008-07-16 03:22:51 +02:00
|
|
|
FreePool (LanguageString);
|
2008-04-14 08:29:03 +02:00
|
|
|
LanguageString = AllocateZeroPool (BufferSize);
|
|
|
|
if (LanguageString == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-02-02 14:11:49 +01:00
|
|
|
Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
LanguageString = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LanguageString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-14 07:29:49 +02:00
|
|
|
/**
|
|
|
|
This function returns the number of supported languages on HiiHandle.
|
|
|
|
|
|
|
|
If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
|
|
|
|
If not enough resource to complete the operation, then ASSERT.
|
|
|
|
|
|
|
|
@param HiiHandle The HII package list handle.
|
|
|
|
|
|
|
|
@return The number of supported languages.
|
|
|
|
|
|
|
|
**/
|
2008-02-02 14:11:49 +01:00
|
|
|
UINT16
|
|
|
|
EFIAPI
|
|
|
|
HiiLibGetSupportedLanguageNumber (
|
|
|
|
IN EFI_HII_HANDLE HiiHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
CHAR8 *Languages;
|
|
|
|
CHAR8 *LanguageString;
|
|
|
|
UINT16 LangNumber;
|
|
|
|
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
|
|
|
|
|
|
|
|
Languages = HiiLibGetSupportedLanguages (HiiHandle);
|
|
|
|
if (Languages == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LangNumber = 0;
|
|
|
|
LanguageString = Languages;
|
|
|
|
while (*LanguageString != 0) {
|
|
|
|
HiiLibGetNextLanguage (&LanguageString, Lang);
|
|
|
|
LangNumber++;
|
|
|
|
}
|
2008-07-16 03:22:51 +02:00
|
|
|
FreePool (Languages);
|
2008-02-02 14:11:49 +01:00
|
|
|
|
|
|
|
return LangNumber;
|
|
|
|
}
|
2008-04-14 08:29:03 +02:00
|
|
|
|
2008-07-14 07:29:49 +02:00
|
|
|
/**
|
|
|
|
This function returns the list of supported 2nd languages, in the format specified
|
|
|
|
in UEFI specification Appendix M.
|
|
|
|
|
|
|
|
If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
|
|
|
|
If not enough resource to complete the operation, then ASSERT.
|
|
|
|
|
|
|
|
@param HiiHandle The HII package list handle.
|
|
|
|
@param FirstLanguage Pointer to language name buffer.
|
|
|
|
|
|
|
|
@return The supported languages.
|
|
|
|
|
|
|
|
**/
|
2008-04-14 08:29:03 +02:00
|
|
|
CHAR8 *
|
|
|
|
EFIAPI
|
|
|
|
HiiLibGetSupportedSecondaryLanguages (
|
|
|
|
IN EFI_HII_HANDLE HiiHandle,
|
|
|
|
IN CONST CHAR8 *FirstLanguage
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN BufferSize;
|
|
|
|
CHAR8 *LanguageString;
|
|
|
|
|
|
|
|
ASSERT (HiiHandle != NULL);
|
|
|
|
ASSERT (IsHiiHandleRegistered (HiiHandle));
|
|
|
|
//
|
|
|
|
// Collect current supported 2nd Languages for given HII handle
|
2008-08-18 14:11:37 +02:00
|
|
|
// First try allocate 4K buffer to store the current supported 2nd languages.
|
2008-04-14 08:29:03 +02:00
|
|
|
//
|
|
|
|
BufferSize = 0x1000;
|
|
|
|
LanguageString = AllocateZeroPool (BufferSize);
|
|
|
|
if (LanguageString == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-23 11:38:38 +02:00
|
|
|
|
2008-04-14 08:29:03 +02:00
|
|
|
Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
|
|
|
|
|
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
2008-07-16 03:22:51 +02:00
|
|
|
FreePool (LanguageString);
|
2008-04-14 08:29:03 +02:00
|
|
|
LanguageString = AllocateZeroPool (BufferSize);
|
|
|
|
if (LanguageString == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
LanguageString = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return LanguageString;
|
|
|
|
}
|
|
|
|
|
|
|
|
|