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; UINTN LoopVar;
CHAR16 *DeviceNameToReturn; CHAR16 *DeviceNameToReturn;
CHAR8 *Lang; CHAR8 *Lang;
CHAR8 *TempChar;
UINTN ParentControllerCount; UINTN ParentControllerCount;
EFI_HANDLE *ParentControllerBuffer; EFI_HANDLE *ParentControllerBuffer;
UINTN ParentDriverCount; UINTN ParentDriverCount;
@ -703,23 +701,7 @@ EfiShellGetDeviceName(
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
continue; continue;
} }
if (Language == NULL) { Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);
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);
}
Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn); Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);
FreePool(Lang); FreePool(Lang);
Lang = NULL; Lang = NULL;
@ -762,23 +744,7 @@ EfiShellGetDeviceName(
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
continue; continue;
} }
if (Language == NULL) { Lang = GetBestLanguageForDriver(CompName2->SupportedLanguages, Language, FALSE);
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);
}
Status = CompName2->GetControllerName(CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn); Status = CompName2->GetControllerName(CompName2, ParentControllerBuffer[LoopVar], DeviceHandle, Lang, &DeviceNameToReturn);
FreePool(Lang); FreePool(Lang);
Lang = NULL; Lang = NULL;

View File

@ -1,7 +1,7 @@
/** @file /** @file
Provides interface to advanced shell functionality for parsing both handle and protocol database. 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 This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@ -95,6 +95,27 @@ GetStringNameFromHandle(
IN CONST CHAR8 *Language 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_UNKNOWN 0
#define HR_IMAGE_HANDLE BIT1 #define HR_IMAGE_HANDLE BIT1
#define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding #define HR_DRIVER_BINDING_HANDLE BIT2 // has driver binding

View File

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

View File

@ -1,7 +1,7 @@
/** @file /** @file
Provides interface to advanced shell functionality for parsing both handle and protocol database. 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 This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 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. Get best support language for this driver.
First base on the current platform used language to search,Second base on the First base on the user input language to search, second base on the current
default language to search. The caller need to free the buffer of the best platform used language to search, third get the first language from the
language. 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] SupportedLanguages The support languages for this driver.
@param[in] InputLanguage The user input language.
@param[in] Iso639Language Whether get language for ISO639. @param[in] Iso639Language Whether get language for ISO639.
@return The best support language for this driver. @return The best support language for this driver.
**/ **/
CHAR8 * CHAR8 *
EFIAPI
GetBestLanguageForDriver ( GetBestLanguageForDriver (
IN CONST CHAR8 *SupportedLanguages, IN CONST CHAR8 *SupportedLanguages,
IN CONST CHAR8 *InputLanguage,
IN BOOLEAN Iso639Language IN BOOLEAN Iso639Language
) )
{ {
@ -801,8 +804,9 @@ GetBestLanguageForDriver (
BestLanguage = GetBestLanguage( BestLanguage = GetBestLanguage(
SupportedLanguages, SupportedLanguages,
Iso639Language, Iso639Language,
(InputLanguage != NULL) ? InputLanguage : "",
(LanguageVariable != NULL) ? LanguageVariable : "", (LanguageVariable != NULL) ? LanguageVariable : "",
Iso639Language ? "en" : "en-US", SupportedLanguages,
NULL NULL
); );
@ -845,12 +849,8 @@ GetStringNameFromHandle(
NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL); EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
if (Language == NULL) { BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, FALSE); Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
Language = BestLang;
}
Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);
if (BestLang != NULL) { if (BestLang != NULL) {
FreePool (BestLang); FreePool (BestLang);
BestLang = NULL; BestLang = NULL;
@ -867,12 +867,8 @@ GetStringNameFromHandle(
NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL); EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
if (Language == NULL) { BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, Language, FALSE);
BestLang = GetBestLanguageForDriver (CompNameStruct->SupportedLanguages, FALSE); Status = CompNameStruct->GetDriverName(CompNameStruct, BestLang, &RetVal);
Language = BestLang;
}
Status = CompNameStruct->GetDriverName(CompNameStruct, (CHAR8*)Language, &RetVal);
if (BestLang != NULL) { if (BestLang != NULL) {
FreePool (BestLang); FreePool (BestLang);
} }

View File

@ -60,7 +60,6 @@ GetDriverName (
) )
{ {
CHAR8 *Lang; CHAR8 *Lang;
CHAR8 *TempChar;
EFI_STATUS Status; EFI_STATUS Status;
EFI_COMPONENT_NAME2_PROTOCOL *CompName2; EFI_COMPONENT_NAME2_PROTOCOL *CompName2;
CHAR16 *NameToReturn; CHAR16 *NameToReturn;
@ -87,23 +86,7 @@ GetDriverName (
if (EFI_ERROR(Status)) { if (EFI_ERROR(Status)) {
return (EFI_NOT_FOUND); return (EFI_NOT_FOUND);
} }
if (Language == NULL) { Lang = GetBestLanguageForDriver (CompName2->SupportedLanguages, Language, FALSE);
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);
}
Status = CompName2->GetDriverName(CompName2, Lang, &NameToReturn); Status = CompName2->GetDriverName(CompName2, Lang, &NameToReturn);
FreePool(Lang); FreePool(Lang);

View File

@ -1,7 +1,7 @@
/** @file /** @file
Main file for DrvDiag shell Driver1 function. 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 This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License 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 which accompanies this distribution. The full text of the license may be found at
@ -71,7 +71,6 @@ DoDiagnostics (
UINTN HandleIndex1; UINTN HandleIndex1;
UINTN HandleIndex2; UINTN HandleIndex2;
CHAR8 *Language; CHAR8 *Language;
CHAR8 *TempChar;
BOOLEAN Found; BOOLEAN Found;
if ((ChildHandle != NULL && AllChilds) || (Mode >= TestModeMax)){ if ((ChildHandle != NULL && AllChilds) || (Mode >= TestModeMax)){
@ -180,24 +179,8 @@ DoDiagnostics (
gImageHandle, gImageHandle,
NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL); EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status) && (DriverDiagnostics2 != NULL)) {
if (Lang == NULL) { Language = GetBestLanguageForDriver(DriverDiagnostics2->SupportedLanguages, Lang, FALSE);
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);
}
Found = TRUE; Found = TRUE;
Status = DriverDiagnostics2->RunDiagnostics( Status = DriverDiagnostics2->RunDiagnostics(
DriverDiagnostics2, DriverDiagnostics2,
@ -220,23 +203,7 @@ DoDiagnostics (
NULL, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL); EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (!EFI_ERROR(Status)) { if (!EFI_ERROR(Status)) {
if (Lang == NULL) { Language = GetBestLanguageForDriver(DriverDiagnostics->SupportedLanguages, Lang, FALSE);
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);
}
Status = DriverDiagnostics->RunDiagnostics( Status = DriverDiagnostics->RunDiagnostics(
DriverDiagnostics, DriverDiagnostics,
ControllerHandleList[ControllerHandleListLoop], ControllerHandleList[ControllerHandleListLoop],

View File

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