]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
Remove 2 unnecessary modules (Ps2MouseDxe, Ps2keyboardDxe) for saving size.
[mirror_edk2.git] / ShellPkg / Library / UefiShellCommandLib / UefiShellCommandLib.c
index ebb84dd55ec1d5405221370d65b9c3b8c1bbb6f3..74d4d9e41cf848d8a2ba9021619febb2ffed80b3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell internal functions for shell commands.\r
 \r
-  (C) Copyright 2013-2014, Hewlett-Packard Development Company, L.P.\r
+  Copyright (c) 2013-2014, 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
@@ -215,7 +215,7 @@ ShellCommandLibDestructor (
 }\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
@@ -277,7 +277,7 @@ ShellCommandDynamicCommandExists (
   IN CONST CHAR16 *CommandString\r
   )\r
 {\r
-  return (ShellCommandFindDynamicCommand(CommandString) != NULL);\r
+  return (BOOLEAN) ((ShellCommandFindDynamicCommand(CommandString) != NULL));\r
 }\r
 \r
 /**\r
@@ -526,14 +526,9 @@ ShellCommandRegisterCommandName (
   //\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
@@ -777,6 +772,9 @@ ShellCommandRegisterAlias (
   )\r
 {\r
   ALIAS_LIST *Node;\r
+  ALIAS_LIST *CommandAlias;\r
+  ALIAS_LIST *PrevCommandAlias; \r
+  INTN       LexicalMatchValue;\r
 \r
   //\r
   // Asserts for NULL\r
@@ -789,21 +787,42 @@ ShellCommandRegisterAlias (
   //\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
@@ -1146,12 +1165,11 @@ ShellCommandAddMapItemAndUpdatePath(
     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