/** @file\r
Provides interface to shell internal functions for shell commands.\r
\r
- (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
+ (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>\r
Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
STATIC UINTN mBlkMaxCount = 0;\r
STATIC BUFFER_LIST mFileHandleList;\r
\r
+STATIC CONST CHAR8 Hex[] = {\r
+ '0',\r
+ '1',\r
+ '2',\r
+ '3',\r
+ '4',\r
+ '5',\r
+ '6',\r
+ '7',\r
+ '8',\r
+ '9',\r
+ 'A',\r
+ 'B',\r
+ 'C',\r
+ 'D',\r
+ 'E',\r
+ 'F'\r
+};\r
+\r
// global variables required by library class.\r
EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation = NULL;\r
SHELL_MAP_LIST gShellMapList;\r
}\r
\r
/**\r
- Find a dynamic command protocol instance given a command name string\r
+ Find a dynamic command protocol instance given a command name string.\r
\r
@param CommandString the command name string\r
\r
IN CONST CHAR16 *CommandString\r
)\r
{\r
- return (ShellCommandFindDynamicCommand(CommandString) != NULL);\r
+ return (BOOLEAN) ((ShellCommandFindDynamicCommand(CommandString) != NULL));\r
}\r
\r
/**\r
//\r
Node = AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY));\r
ASSERT(Node != NULL);\r
- Node->CommandString = AllocateZeroPool(StrSize(CommandString));\r
+ Node->CommandString = AllocateCopyPool(StrSize(CommandString), CommandString);\r
ASSERT(Node->CommandString != NULL);\r
\r
- //\r
- // populate the new struct\r
- //\r
- StrCpy(Node->CommandString, CommandString);\r
-\r
Node->GetManFileName = GetManFileName;\r
Node->CommandHandler = CommandHandler;\r
Node->LastError = CanAffectLE;\r
)\r
{\r
ALIAS_LIST *Node;\r
+ ALIAS_LIST *CommandAlias;\r
+ ALIAS_LIST *PrevCommandAlias; \r
+ INTN LexicalMatchValue;\r
\r
//\r
// Asserts for NULL\r
//\r
Node = AllocateZeroPool(sizeof(ALIAS_LIST));\r
ASSERT(Node != NULL);\r
- Node->CommandString = AllocateZeroPool(StrSize(Command));\r
- Node->Alias = AllocateZeroPool(StrSize(Alias));\r
+ Node->CommandString = AllocateCopyPool(StrSize(Command), Command);\r
+ Node->Alias = AllocateCopyPool(StrSize(Alias), Alias);\r
ASSERT(Node->CommandString != NULL);\r
ASSERT(Node->Alias != NULL);\r
\r
- //\r
- // populate the new struct\r
- //\r
- StrCpy(Node->CommandString, Command);\r
- StrCpy(Node->Alias , Alias );\r
+ InsertHeadList (&mAliasList.Link, &Node->Link);\r
\r
//\r
- // add the new struct to the list\r
+ // Move a new pre-defined registered alias to its sorted ordered location in the list\r
//\r
- InsertTailList (&mAliasList.Link, &Node->Link);\r
+ for ( CommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link),\r
+ PrevCommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link)\r
+ ; !IsNull (&mAliasList.Link, &CommandAlias->Link)\r
+ ; CommandAlias = (ALIAS_LIST *) GetNextNode (&mAliasList.Link, &CommandAlias->Link) ) {\r
+ //\r
+ // Get Lexical comparison value between PrevCommandAlias and CommandAlias List Entry\r
+ //\r
+ LexicalMatchValue = gUnicodeCollation->StriColl (\r
+ gUnicodeCollation,\r
+ PrevCommandAlias->Alias,\r
+ CommandAlias->Alias\r
+ );\r
+\r
+ //\r
+ // Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry\r
+ // is alphabetically greater than CommandAlias list entry\r
+ // \r
+ if (LexicalMatchValue > 0) {\r
+ CommandAlias = (ALIAS_LIST *) SwapListEntries (&PrevCommandAlias->Link, &CommandAlias->Link);\r
+ } else if (LexicalMatchValue < 0) {\r
+ //\r
+ // PrevCommandAlias entry is lexically lower than CommandAlias entry\r
+ //\r
+ break;\r
+ }\r
+ }\r
\r
return (RETURN_SUCCESS);\r
}\r
}\r
\r
/**\r
- Function to determine current state of ECHO. Echo determins if lines from scripts\r
+ Function to determine current state of ECHO. Echo determines if lines from scripts\r
and ECHO commands are enabled.\r
\r
@retval TRUE Echo is currently enabled\r
}\r
\r
/**\r
- Function to set current state of ECHO. Echo determins if lines from scripts\r
+ Function to set current state of ECHO. Echo determines if lines from scripts\r
and ECHO commands are enabled.\r
\r
If State is TRUE, Echo will be enabled.\r
Status = EFI_OUT_OF_RESOURCES;\r
} else {\r
MapListNode->Flags = Flags;\r
- MapListNode->MapName = AllocateZeroPool(StrSize(Name));\r
+ MapListNode->MapName = AllocateCopyPool(StrSize(Name), Name);\r
MapListNode->DevicePath = DuplicateDevicePath(DevicePath);\r
if ((MapListNode->MapName == NULL) || (MapListNode->DevicePath == NULL)){\r
Status = EFI_OUT_OF_RESOURCES;\r
} else {\r
- StrCpy(MapListNode->MapName, Name);\r
InsertTailList(&gShellMapList.Link, &MapListNode->Link);\r
}\r
}\r
; MapListNode = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r
){\r
RemoveEntryList(&MapListNode->Link);\r
+ SHELL_FREE_NON_NULL(MapListNode->DevicePath);\r
+ SHELL_FREE_NON_NULL(MapListNode->MapName);\r
+ SHELL_FREE_NON_NULL(MapListNode->CurrentDirectoryPath);\r
FreePool(MapListNode);\r
} // for loop\r
}\r
// Get all Device Paths\r
//\r
DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count);\r
- ASSERT(DevicePathList != NULL);\r
+ if (DevicePathList == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
\r
for (Count = 0 ; HandleList[Count] != NULL ; Count++) {\r
DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]);\r
//\r
// Assign new Mappings to remainders\r
//\r
- for (Count = 0 ; HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {\r
+ for (Count = 0 ; !EFI_ERROR(Status) && HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) {\r
//\r
// Skip ones that already have\r
//\r
// Get default name\r
//\r
NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem);\r
- ASSERT(NewDefaultName != NULL);\r
+ if (NewDefaultName == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ break;\r
+ }\r
\r
//\r
// Call shell protocol SetMap function now...\r
}\r
NewNode = AllocateZeroPool(sizeof(BUFFER_LIST));\r
if (NewNode == NULL) {\r
+ SHELL_FREE_NON_NULL(Buffer);\r
return (NULL);\r
}\r
Buffer->FileHandle = (EFI_FILE_PROTOCOL*)Handle;\r
Buffer->Path = StrnCatGrow(&Buffer->Path, NULL, Path, 0);\r
if (Buffer->Path == NULL) {\r
+ SHELL_FREE_NON_NULL(NewNode);\r
+ SHELL_FREE_NON_NULL(Buffer);\r
return (NULL);\r
}\r
NewNode->Buffer = Buffer;\r
\r
gEfiShellProtocol->GetFilePosition(Handle, &Pos);\r
Info = gEfiShellProtocol->GetFileInfo (Handle);\r
- ASSERT(Info != NULL);\r
gEfiShellProtocol->SetFilePosition(Handle, Pos);\r
\r
if (Info == NULL) {\r
; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link)\r
){\r
RemoveEntryList(&BufferListEntry->Link);\r
- ASSERT(BufferListEntry->Buffer != NULL);\r
if (BufferListEntry->Buffer != NULL) {\r
FreePool(BufferListEntry->Buffer);\r
}\r
}\r
}\r
\r
+/**\r
+ Dump some hexadecimal data to the screen.\r
+\r
+ @param[in] Indent How many spaces to indent the output.\r
+ @param[in] Offset The offset of the printing.\r
+ @param[in] DataSize The size in bytes of UserData.\r
+ @param[in] UserData The data to print out.\r
+**/\r
+VOID\r
+DumpHex (\r
+ IN UINTN Indent,\r
+ IN UINTN Offset,\r
+ IN UINTN DataSize,\r
+ IN VOID *UserData\r
+ )\r
+{\r
+ UINT8 *Data;\r
+\r
+ CHAR8 Val[50];\r
+\r
+ CHAR8 Str[20];\r
+\r
+ UINT8 TempByte;\r
+ UINTN Size;\r
+ UINTN Index;\r
+\r
+ Data = UserData;\r
+ while (DataSize != 0) {\r
+ Size = 16;\r
+ if (Size > DataSize) {\r
+ Size = DataSize;\r
+ }\r
+\r
+ for (Index = 0; Index < Size; Index += 1) {\r
+ TempByte = Data[Index];\r
+ Val[Index * 3 + 0] = Hex[TempByte >> 4];\r
+ Val[Index * 3 + 1] = Hex[TempByte & 0xF];\r
+ Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' ');\r
+ Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);\r
+ }\r
+\r
+ Val[Index * 3] = 0;\r
+ Str[Index] = 0;\r
+ ShellPrintEx(-1, -1, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str);\r
+\r
+ Data += Size;\r
+ Offset += Size;\r
+ DataSize -= Size;\r
+ }\r
+}\r