Refine the select language logic.

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14629 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Eric Dong 2013-09-05 03:02:14 +00:00 committed by ydong10
parent c683aa9cd1
commit a71003f249
7 changed files with 46 additions and 111 deletions

View File

@ -645,8 +645,6 @@ EfiShellGetDeviceName(
UINTN LoopVar;
CHAR16 *DeviceNameToReturn;
CHAR8 *Lang;
CHAR8 *TempChar;
UINTN ParentControllerCount;
EFI_HANDLE *ParentControllerBuffer;
UINTN ParentDriverCount;
@ -703,23 +701,7 @@ EfiShellGetDeviceName(
if (EFI_ERROR(Status)) {
continue;
}
if (Language == NULL) {
Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, CompName2->SupportedLanguages);
TempChar = AsciiStrStr(Lang, ";");
if (TempChar != NULL){
*TempChar = CHAR_NULL;
}
} else {
Lang = AllocateZeroPool(AsciiStrSize(Language));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, Language);
}
Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);
Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);
FreePool(Lang);
Lang = NULL;
@ -762,23 +744,7 @@ EfiShellGetDeviceName(
if (EFI_ERROR(Status)) {
continue;
}
if (Language == NULL) {
Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, CompName2->SupportedLanguages);
TempChar = AsciiStrStr(Lang, ";");
if (TempChar != NULL){
*TempChar = CHAR_NULL;
}
} else {
Lang = AllocateZeroPool(AsciiStrSize(Language));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, Language);
}
Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);
Status = CompName2->GetControllerName(CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);
FreePool(Lang);
Lang = NULL;

View File

@ -1,7 +1,7 @@
/** @file
Provides interface to advanced shell functionality for parsing both handle and protocol database.
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
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
@ -95,6 +95,27 @@ GetStringNameFromHandle(
IN CONST CHAR8 *Language
);
/**
Get best support language for this driver.
First base on the user input language to search, second base on the current
platform used language to search, third get the first language from the
support language list. The caller need to free the buffer of the best language.
@param[in] SupportedLanguages The support languages for this driver.
@param[in] InputLanguage The user input language.
@param[in] Iso639Language Whether get language for ISO639.
@return The best support language for this driver.
**/
CHAR8 *
EFIAPI
GetBestLanguageForDriver (
IN CONST CHAR8 *SupportedLanguages,
IN CONST CHAR8 *InputLanguage,
IN BOOLEAN Iso639Language
);
#define HR_UNKNOWN 0
#define HR_IMAGE_HANDLE BIT1
#define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding

View File

@ -23,6 +23,7 @@
#include <Library/PcdLib.h>
#include <Library/UefiLib.h>
#include <Library/DevicePathLib.h>
#include <Library/HandleParsingLib.h>
#include <Pi/PiFirmwareFile.h>
#include <Library/DxeServicesLib.h>
@ -252,7 +253,7 @@ GetNameFromHandle (
//
// Get the current platform language setting
//
GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);
PlatformLanguage = GetBestLanguageForDriver(ComponentName2->SupportedLanguages, NULL, FALSE);
Status = ComponentName2->GetDriverName (
ComponentName2,
PlatformLanguage != NULL ? PlatformLanguage : "en-US",

View File

@ -1,7 +1,7 @@
/** @file
Provides interface to advanced shell functionality for parsing both handle and protocol database.
Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
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
@ -778,18 +778,21 @@ GetGuidFromStringName(
/**
Get best support language for this driver.
First base on the current platform used language to search,Second base on the
default language to search. The caller need to free the buffer of the best
language.
First base on the user input language to search, second base on the current
platform used language to search, third get the first language from the
support language list. The caller need to free the buffer of the best language.
@param[in] SupportedLanguages The support languages for this driver.
@param[in] InputLanguage The user input language.
@param[in] Iso639Language Whether get language for ISO639.
@return The best support language for this driver.
**/
CHAR8 *
EFIAPI
GetBestLanguageForDriver (
IN CONST CHAR8 *SupportedLanguages,
IN CONST CHAR8 *SupportedLanguages,
IN CONST CHAR8 *InputLanguage,
IN BOOLEAN Iso639Language
)
{
@ -801,8 +804,9 @@ GetBestLanguageForDriver (
BestLanguage = GetBestLanguage(
SupportedLanguages,
Iso639Language,
(InputLanguage != NULL) ? InputLanguage : "",
(LanguageVariable != NULL) ? LanguageVariable : "",
Iso639Language ? "en" : "en-US",
SupportedLanguages,
NULL
);
@ -845,12 +849,8 @@ GetStringNameFromHandle(
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) {
if (Language == NULL) {
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, FALSE);
Language = BestLang;
}
Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
if (BestLang != NULL) {
FreePool (BestLang);
BestLang = NULL;
@ -867,12 +867,8 @@ GetStringNameFromHandle(
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) {
if (Language == NULL) {
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, FALSE);
Language = BestLang;
}
Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
if (BestLang != NULL) {
FreePool (BestLang);
}

View File

@ -60,7 +60,6 @@ GetDriverName (
)
{
CHAR8 *Lang;
CHAR8 *TempChar;
EFI_STATUS Status;
EFI_COMPONENT_NAME2_PROTOCOL *CompName2;
CHAR16 *NameToReturn;
@ -87,23 +86,7 @@ GetDriverName (
if (EFI_ERROR(Status)) {
return (EFI_NOT_FOUND);
}
if (Language == NULL) {
Lang = AllocateZeroPool(AsciiStrSize(CompName2->SupportedLanguages));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, CompName2->SupportedLanguages);
TempChar = AsciiStrStr(Lang, ";");
if (TempChar != NULL){
*TempChar = CHAR_NULL;
}
} else {
Lang = AllocateZeroPool(AsciiStrSize(Language));
if (Lang == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Lang, Language);
}
Lang = GetBestLanguageForDriver (CompName2->SupportedLanguages, Language, FALSE);
Status = CompName2->GetDriverName(CompName2, Lang, &NameToReturn);
FreePool(Lang);

View File

@ -1,7 +1,7 @@
/** @file
Main file for DrvDiag shell Driver1 function.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>
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
@ -71,7 +71,6 @@ DoDiagnostics (
UINTN HandleIndex1;
UINTN HandleIndex2;
CHAR8 *Language;
CHAR8 *TempChar;
BOOLEAN Found;
if ((ChildHandle != NULL && AllChilds) || (Mode >= TestModeMax)){
@ -180,24 +179,8 @@ DoDiagnostics (
gImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) {
if (Lang == NULL) {
Language = AllocateZeroPool(AsciiStrSize(DriverDiagnostics2->SupportedLanguages));
if (Language == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Language, DriverDiagnostics2->SupportedLanguages);
TempChar = AsciiStrStr(Language, ";");
if (TempChar != NULL){
*TempChar = CHAR_NULL;
}
} else {
Language = AllocateZeroPool(AsciiStrSize(Lang));
if (Language == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Language, Lang);
}
if (!EFI_ERROR(Status) && (DriverDiagnostics2 != NULL)) {
Language = GetBestLanguageForDriver(DriverDiagnostics2->SupportedLanguages, Lang, FALSE);
Found = TRUE;
Status = DriverDiagnostics2->RunDiagnostics(
DriverDiagnostics2,
@ -220,23 +203,7 @@ DoDiagnostics (
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) {
if (Lang == NULL) {
Language = AllocateZeroPool(AsciiStrSize(DriverDiagnostics2->SupportedLanguages));
if (Language == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Language, DriverDiagnostics2->SupportedLanguages);
TempChar = AsciiStrStr(Language, ";");
if (TempChar != NULL){
*TempChar = CHAR_NULL;
}
} else {
Language = AllocateZeroPool(AsciiStrSize(Lang));
if (Language == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
AsciiStrCpy(Language, Lang);
}
Language = GetBestLanguageForDriver(DriverDiagnostics->SupportedLanguages, Lang, FALSE);
Status = DriverDiagnostics->RunDiagnostics(
DriverDiagnostics,
ControllerHandleList[ControllerHandleListLoop],

View File

@ -54,6 +54,7 @@
#include <Library/PrintLib.h>
#include <Library/HandleParsingLib.h>
#include <Library/PeCoffGetEntryPointLib.h>
#include <Library/HandleParsingLib.h>
extern EFI_HANDLE gShellDriver1HiiHandle;