2007-12-20 10:16:45 +01:00
|
|
|
/** @file
|
2009-03-24 15:19:12 +01:00
|
|
|
Unicode Collation Support component that hides the trivial difference of Unicode Collation
|
2007-12-20 10:16:45 +01:00
|
|
|
and Unicode collation 2 Protocol.
|
|
|
|
|
2018-06-27 15:06:14 +02:00
|
|
|
Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
|
2010-04-26 03:24:39 +02:00
|
|
|
This program and the accompanying materials are licensed and made available
|
2010-02-08 04:23:03 +01:00
|
|
|
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.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
**/
|
|
|
|
|
2007-12-21 04:27:26 +01:00
|
|
|
#include "Fat.h"
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationInterface = NULL;
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
/**
|
|
|
|
Worker function to initialize Unicode Collation support.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2009-04-08 09:36:44 +02:00
|
|
|
It tries to locate Unicode Collation (2) protocol and matches it with current
|
|
|
|
platform language code.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
@param AgentHandle The handle used to open Unicode Collation (2) protocol.
|
|
|
|
@param ProtocolGuid The pointer to Unicode Collation (2) protocol GUID.
|
|
|
|
@param VariableName The name of the RFC 4646 or ISO 639-2 language variable.
|
|
|
|
@param DefaultLanguage The default language in case the RFC 4646 or ISO 639-2 language is absent.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
@retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
|
|
|
|
@retval Others The Unicode Collation (2) protocol has not been located.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
EFI_STATUS
|
2009-03-24 15:19:12 +01:00
|
|
|
InitializeUnicodeCollationSupportWorker (
|
2007-12-20 10:16:45 +01:00
|
|
|
IN EFI_HANDLE AgentHandle,
|
2009-03-24 15:19:12 +01:00
|
|
|
IN EFI_GUID *ProtocolGuid,
|
|
|
|
IN CONST CHAR16 *VariableName,
|
|
|
|
IN CONST CHAR8 *DefaultLanguage
|
2007-12-20 10:16:45 +01:00
|
|
|
)
|
|
|
|
{
|
2013-05-29 11:01:46 +02:00
|
|
|
EFI_STATUS ReturnStatus;
|
2007-12-20 10:16:45 +01:00
|
|
|
EFI_STATUS Status;
|
2009-03-24 15:19:12 +01:00
|
|
|
UINTN NumHandles;
|
2007-12-20 10:16:45 +01:00
|
|
|
UINTN Index;
|
|
|
|
EFI_HANDLE *Handles;
|
|
|
|
EFI_UNICODE_COLLATION_PROTOCOL *Uci;
|
2009-03-24 15:19:12 +01:00
|
|
|
BOOLEAN Iso639Language;
|
|
|
|
CHAR8 *Language;
|
|
|
|
CHAR8 *BestLanguage;
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
Status = gBS->LocateHandleBuffer (
|
|
|
|
ByProtocol,
|
2009-03-24 15:19:12 +01:00
|
|
|
ProtocolGuid,
|
2007-12-20 10:16:45 +01:00
|
|
|
NULL,
|
2009-03-24 15:19:12 +01:00
|
|
|
&NumHandles,
|
2007-12-20 10:16:45 +01:00
|
|
|
&Handles
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
Iso639Language = (BOOLEAN) (ProtocolGuid == &gEfiUnicodeCollationProtocolGuid);
|
2012-05-31 12:10:29 +02:00
|
|
|
GetEfiGlobalVariable2 (VariableName, (VOID**) &Language, NULL);
|
2009-03-24 15:19:12 +01:00
|
|
|
|
2013-05-29 11:01:46 +02:00
|
|
|
ReturnStatus = EFI_UNSUPPORTED;
|
2009-03-24 15:19:12 +01:00
|
|
|
for (Index = 0; Index < NumHandles; Index++) {
|
2007-12-20 10:16:45 +01:00
|
|
|
//
|
|
|
|
// Open Unicode Collation Protocol
|
|
|
|
//
|
|
|
|
Status = gBS->OpenProtocol (
|
|
|
|
Handles[Index],
|
2009-03-24 15:19:12 +01:00
|
|
|
ProtocolGuid,
|
2007-12-20 10:16:45 +01:00
|
|
|
(VOID **) &Uci,
|
|
|
|
AgentHandle,
|
|
|
|
NULL,
|
|
|
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
|
|
|
);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
//
|
|
|
|
// Find the best matching matching language from the supported languages
|
2018-06-27 15:06:14 +02:00
|
|
|
// of Unicode Collation (2) protocol.
|
2009-03-24 15:19:12 +01:00
|
|
|
//
|
2009-03-25 09:40:00 +01:00
|
|
|
BestLanguage = GetBestLanguage (
|
|
|
|
Uci->SupportedLanguages,
|
|
|
|
Iso639Language,
|
2009-12-15 23:15:22 +01:00
|
|
|
(Language == NULL) ? "" : Language,
|
2009-03-25 09:40:00 +01:00
|
|
|
DefaultLanguage,
|
|
|
|
NULL
|
|
|
|
);
|
2009-03-24 15:19:12 +01:00
|
|
|
if (BestLanguage != NULL) {
|
|
|
|
FreePool (BestLanguage);
|
2007-12-20 10:16:45 +01:00
|
|
|
mUnicodeCollationInterface = Uci;
|
2013-05-29 11:01:46 +02:00
|
|
|
ReturnStatus = EFI_SUCCESS;
|
2007-12-20 10:16:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
if (Language != NULL) {
|
|
|
|
FreePool (Language);
|
|
|
|
}
|
|
|
|
|
2007-12-20 10:16:45 +01:00
|
|
|
FreePool (Handles);
|
|
|
|
|
2013-05-29 11:01:46 +02:00
|
|
|
return ReturnStatus;
|
2007-12-20 10:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initialize Unicode Collation support.
|
|
|
|
|
2009-04-08 09:36:44 +02:00
|
|
|
It tries to locate Unicode Collation 2 protocol and matches it with current
|
2008-10-10 04:33:21 +02:00
|
|
|
platform language code. If for any reason the first attempt fails, it then tries to
|
|
|
|
use Unicode Collation Protocol.
|
|
|
|
|
2007-12-20 10:16:45 +01:00
|
|
|
@param AgentHandle The handle used to open Unicode Collation (2) protocol.
|
|
|
|
|
|
|
|
@retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
|
|
|
|
@retval Others The Unicode Collation (2) protocol has not been located.
|
|
|
|
|
|
|
|
**/
|
|
|
|
EFI_STATUS
|
|
|
|
InitializeUnicodeCollationSupport (
|
|
|
|
IN EFI_HANDLE AgentHandle
|
|
|
|
)
|
|
|
|
{
|
|
|
|
|
|
|
|
EFI_STATUS Status;
|
|
|
|
|
|
|
|
Status = EFI_UNSUPPORTED;
|
2008-10-10 04:33:21 +02:00
|
|
|
|
|
|
|
//
|
2009-03-24 15:19:12 +01:00
|
|
|
// First try to use RFC 4646 Unicode Collation 2 Protocol.
|
2008-10-10 04:33:21 +02:00
|
|
|
//
|
2009-04-08 09:36:44 +02:00
|
|
|
Status = InitializeUnicodeCollationSupportWorker (
|
|
|
|
AgentHandle,
|
|
|
|
&gEfiUnicodeCollation2ProtocolGuid,
|
|
|
|
L"PlatformLang",
|
|
|
|
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang)
|
|
|
|
);
|
2008-10-10 04:33:21 +02:00
|
|
|
//
|
|
|
|
// If the attempt to use Unicode Collation 2 Protocol fails, then we fall back
|
|
|
|
// on the ISO 639-2 Unicode Collation Protocol.
|
|
|
|
//
|
2009-04-08 09:36:44 +02:00
|
|
|
if (EFI_ERROR (Status)) {
|
2009-03-24 15:19:12 +01:00
|
|
|
Status = InitializeUnicodeCollationSupportWorker (
|
|
|
|
AgentHandle,
|
|
|
|
&gEfiUnicodeCollationProtocolGuid,
|
|
|
|
L"Lang",
|
|
|
|
(CONST CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultLang)
|
|
|
|
);
|
2007-12-20 10:16:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2009-03-24 15:19:12 +01:00
|
|
|
|
2007-12-20 10:16:45 +01:00
|
|
|
/**
|
|
|
|
Performs a case-insensitive comparison of two Null-terminated Unicode strings.
|
|
|
|
|
|
|
|
@param S1 A pointer to a Null-terminated Unicode string.
|
|
|
|
@param S2 A pointer to a Null-terminated Unicode string.
|
|
|
|
|
|
|
|
@retval 0 S1 is equivalent to S2.
|
|
|
|
@retval >0 S1 is lexically greater than S2.
|
|
|
|
@retval <0 S1 is lexically less than S2.
|
|
|
|
**/
|
|
|
|
INTN
|
|
|
|
FatStriCmp (
|
|
|
|
IN CHAR16 *S1,
|
|
|
|
IN CHAR16 *S2
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (StrSize (S1) != 0);
|
|
|
|
ASSERT (StrSize (S2) != 0);
|
|
|
|
ASSERT (mUnicodeCollationInterface != NULL);
|
|
|
|
|
|
|
|
return mUnicodeCollationInterface->StriColl (
|
|
|
|
mUnicodeCollationInterface,
|
|
|
|
S1,
|
|
|
|
S2
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Uppercase a string.
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param String The string which will be upper-cased.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
FatStrUpr (
|
|
|
|
IN OUT CHAR16 *String
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (StrSize (String) != 0);
|
|
|
|
ASSERT (mUnicodeCollationInterface != NULL);
|
|
|
|
|
|
|
|
mUnicodeCollationInterface->StrUpr (mUnicodeCollationInterface, String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Lowercase a string
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param String The string which will be lower-cased.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
FatStrLwr (
|
|
|
|
IN OUT CHAR16 *String
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (StrSize (String) != 0);
|
|
|
|
ASSERT (mUnicodeCollationInterface != NULL);
|
|
|
|
|
|
|
|
mUnicodeCollationInterface->StrLwr (mUnicodeCollationInterface, String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Convert FAT string to unicode string.
|
|
|
|
|
|
|
|
@param FatSize The size of FAT string.
|
|
|
|
@param Fat The FAT string.
|
|
|
|
@param String The unicode string.
|
|
|
|
|
|
|
|
@return None.
|
|
|
|
|
|
|
|
**/
|
|
|
|
VOID
|
|
|
|
FatFatToStr (
|
|
|
|
IN UINTN FatSize,
|
|
|
|
IN CHAR8 *Fat,
|
|
|
|
OUT CHAR16 *String
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (Fat != NULL);
|
|
|
|
ASSERT (String != NULL);
|
2008-05-05 09:06:57 +02:00
|
|
|
ASSERT (((UINTN) String & 0x01) == 0);
|
2007-12-20 10:16:45 +01:00
|
|
|
ASSERT (mUnicodeCollationInterface != NULL);
|
|
|
|
|
|
|
|
mUnicodeCollationInterface->FatToStr (mUnicodeCollationInterface, FatSize, Fat, String);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Convert unicode string to Fat string.
|
|
|
|
|
|
|
|
@param String The unicode string.
|
|
|
|
@param FatSize The size of the FAT string.
|
|
|
|
@param Fat The FAT string.
|
|
|
|
|
|
|
|
@retval TRUE Convert successfully.
|
|
|
|
@retval FALSE Convert error.
|
|
|
|
|
|
|
|
**/
|
|
|
|
BOOLEAN
|
|
|
|
FatStrToFat (
|
|
|
|
IN CHAR16 *String,
|
|
|
|
IN UINTN FatSize,
|
|
|
|
OUT CHAR8 *Fat
|
|
|
|
)
|
|
|
|
{
|
|
|
|
ASSERT (Fat != NULL);
|
|
|
|
ASSERT (StrSize (String) != 0);
|
|
|
|
ASSERT (mUnicodeCollationInterface != NULL);
|
|
|
|
|
|
|
|
return mUnicodeCollationInterface->StrToFat (
|
|
|
|
mUnicodeCollationInterface,
|
|
|
|
String,
|
|
|
|
FatSize,
|
|
|
|
Fat
|
|
|
|
);
|
|
|
|
}
|