/** @file\r
Provides interface to shell internal functions for shell commands.\r
\r
- Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
\r
VOID\r
)\r
{\r
- EFI_STATUS Status;\r
+ UINTN NumHandles;\r
+ EFI_HANDLE *Handles;\r
+ EFI_UNICODE_COLLATION_PROTOCOL *Uc;\r
+ CHAR8 *BestLanguage;\r
+ UINTN Index;\r
+ EFI_STATUS Status;\r
+ CHAR8 *PlatformLang;\r
+\r
+ GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);\r
+ if (PlatformLang == NULL) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
if (gUnicodeCollation == NULL) {\r
- Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);\r
- if (EFI_ERROR(Status)) {\r
- return (EFI_DEVICE_ERROR);\r
+ Status = gBS->LocateHandleBuffer (\r
+ ByProtocol,\r
+ &gEfiUnicodeCollation2ProtocolGuid,\r
+ NULL,\r
+ &NumHandles,\r
+ &Handles\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ NumHandles = 0;\r
+ Handles = NULL;\r
}\r
+ for (Index = 0; Index < NumHandles; Index++) {\r
+ //\r
+ // Open Unicode Collation Protocol\r
+ //\r
+ Status = gBS->OpenProtocol (\r
+ Handles[Index],\r
+ &gEfiUnicodeCollation2ProtocolGuid,\r
+ (VOID **) &Uc,\r
+ gImageHandle,\r
+ NULL,\r
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Find the best matching matching language from the supported languages\r
+ // of Unicode Collation2 protocol.\r
+ //\r
+ BestLanguage = GetBestLanguage (\r
+ Uc->SupportedLanguages,\r
+ FALSE,\r
+ PlatformLang,\r
+ NULL\r
+ );\r
+ if (BestLanguage != NULL) {\r
+ FreePool (BestLanguage);\r
+ gUnicodeCollation = Uc;\r
+ break;\r
+ }\r
+ }\r
+ if (Handles != NULL) {\r
+ FreePool (Handles);\r
+ }\r
+ FreePool (PlatformLang);\r
}\r
- return (EFI_SUCCESS);\r
+\r
+ return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;\r
}\r
\r
/**\r
mProfileListSize = 0;\r
mProfileList = NULL;\r
\r
- if (gUnicodeCollation == NULL) {\r
- Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);\r
- if (EFI_ERROR(Status)) {\r
- return (EFI_DEVICE_ERROR);\r
- }\r
+ Status = CommandInit ();\r
+ if (EFI_ERROR (Status)) {\r
+ return EFI_DEVICE_ERROR;\r
}\r
\r
return (RETURN_SUCCESS);\r
//\r
// not found or out of resources\r
//\r
- return NULL; \r
+ return NULL;\r
}\r
\r
for (NextCommand = CommandHandleList; *NextCommand != NULL; NextCommand++) {\r
if (gUnicodeCollation->StriColl(\r
gUnicodeCollation,\r
(CHAR16*)CommandString,\r
- (CHAR16*)DynamicCommand->CommandName) == 0 \r
+ (CHAR16*)DynamicCommand->CommandName) == 0\r
){\r
FreePool(CommandHandleList);\r
return (DynamicCommand);\r
//\r
// TODO: how to get proper language?\r
//\r
- return DynamicCommand->GetHelp(DynamicCommand, "en"); \r
+ return DynamicCommand->GetHelp(DynamicCommand, "en");\r
}\r
\r
/**\r
{\r
ALIAS_LIST *Node;\r
ALIAS_LIST *CommandAlias;\r
- ALIAS_LIST *PrevCommandAlias; \r
+ ALIAS_LIST *PrevCommandAlias;\r
INTN LexicalMatchValue;\r
\r
//\r
//\r
// Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry\r
// is alphabetically greater than CommandAlias list entry\r
- // \r
+ //\r
if (LexicalMatchValue > 0) {\r
CommandAlias = (ALIAS_LIST *) SwapListEntries (&PrevCommandAlias->Link, &CommandAlias->Link);\r
} else if (LexicalMatchValue < 0) {\r
CHAR16 *NewConsistName;\r
EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable;\r
SHELL_MAP_LIST *MapListNode;\r
-\r
+ CONST CHAR16 *CurDir;\r
+ CHAR16 *SplitCurDir;\r
+ CHAR16 *MapName;\r
+ SHELL_MAP_LIST *MapListItem;\r
+\r
+ SplitCurDir = NULL;\r
+ MapName = NULL;\r
+ MapListItem = NULL;\r
HandleList = NULL;\r
\r
//\r
SHELL_FREE_NON_NULL(DevicePathList);\r
\r
HandleList = NULL;\r
+\r
+ //\r
+ //gShellCurMapping point to node of current file system in the gShellMapList. When reset all mappings,\r
+ //all nodes in the gShellMapList will be free. Then gShellCurMapping will be a dangling pointer, So,\r
+ //after created new mappings, we should reset the gShellCurMapping pointer back to node of current file system.\r
+ //\r
+ if (gShellCurMapping != NULL) {\r
+ gShellCurMapping = NULL;\r
+ CurDir = gEfiShellProtocol->GetEnv(L"cwd");\r
+ if (CurDir != NULL) {\r
+ MapName = AllocateCopyPool (StrSize(CurDir), CurDir);\r
+ if (MapName == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ SplitCurDir = StrStr (MapName, L":");\r
+ if (SplitCurDir == NULL) {\r
+ SHELL_FREE_NON_NULL (MapName);\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ *(SplitCurDir + 1) = CHAR_NULL;\r
+ MapListItem = ShellCommandFindMapItem (MapName);\r
+ if (MapListItem != NULL) {\r
+ gShellCurMapping = MapListItem;\r
+ }\r
+ SHELL_FREE_NON_NULL (MapName);\r
+ }\r
+ }\r
} else {\r
Count = (UINTN)-1;\r
}\r