]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Refine the code logic of 'command history'.
authorQiu Shumin <shumin.qiu@intel.com>
Thu, 24 Dec 2015 08:06:28 +0000 (08:06 +0000)
committershenshushi <shenshushi@Edk2>
Thu, 24 Dec 2015 08:06:28 +0000 (08:06 +0000)
Add the PCD to PcdShellMaxHistoryCommandCount indicate the max count of history commands.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19520 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/Shell.c
ShellPkg/Application/Shell/Shell.inf
ShellPkg/ShellPkg.dec

index 36063227a2d84f723ec8d9ce92028f2f3c16d740..97b8c8d6fbee39a890b6b48216fec8d0dd723a88 100644 (file)
@@ -1288,13 +1288,40 @@ AddLineToCommandHistory(
   )\r
 {\r
   BUFFER_LIST *Node;\r
+  BUFFER_LIST *Walker;\r
+  UINT16       MaxHistoryCmdCount;\r
+  UINT16       Count;\r
+  \r
+  Count = 0;\r
+  MaxHistoryCmdCount = PcdGet16(PcdShellMaxHistoryCommandCount);\r
+  \r
+  if (MaxHistoryCmdCount == 0) {\r
+    return ;\r
+  }\r
+\r
 \r
   Node = AllocateZeroPool(sizeof(BUFFER_LIST));\r
   ASSERT(Node != NULL);\r
   Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);\r
   ASSERT(Node->Buffer != NULL);\r
 \r
-  InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
+  for ( Walker = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link)\r
+      ; !IsNull(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r
+      ; Walker = (BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r
+   ){\r
+    Count++;\r
+  }\r
+  if (Count < MaxHistoryCmdCount){\r
+    InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
+  } else {\r
+    Walker = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r
+    RemoveEntryList(&Walker->Link);\r
+    if (Walker->Buffer != NULL) {\r
+      FreePool(Walker->Buffer);\r
+    }\r
+    FreePool(Walker);\r
+    InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
+  }\r
 }\r
 \r
 /**\r
index 09aecf717bd7a2610a5bbe87aded7460a041b2c1..253bfdbb224e9ed622dfe0be0a847a51ad340925 100644 (file)
   gEfiDevicePathProtocolGuid                              ## CONSUMES\r
 \r
 [Pcd]\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel         ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols  ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform   ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii  ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault     ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize    ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault    ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount       ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength        ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize      ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole         ## CONSUMES\r
-  gEfiShellPkgTokenSpaceGuid.PcdShellSupplier             ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel           ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellSupportOldProtocols    ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellRequireHiiPlatform     ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellSupportFrameworkHii    ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellPageBreakDefault       ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize      ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellInsertModeDefault      ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellScreenLogCount         ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellMapNameLength          ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellPrintBufferSize        ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellForceConsole           ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellSupplier               ## CONSUMES\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellMaxHistoryCommandCount ## CONSUMES\r
 \r
 [BuildOptions.AARCH64]\r
   # The tiny code model used by AARCH64 only supports binaries of up to 1 MB in\r
index b2f632601eb17b79bdb7b433ece88d078e22b33c..76a2b7db978fd4961c18a6cef7ad19e9515afddc 100644 (file)
 \r
   ## This determines how many bytes are read out of files at a time for file operations (type, copy, etc...)\r
   gEfiShellPkgTokenSpaceGuid.PcdShellFileOperationSize|0x1000|UINT32|0x0000000A\r
+  \r
+  ## This determines the max count of history commands\r
+  gEfiShellPkgTokenSpaceGuid.PcdShellMaxHistoryCommandCount|0x0020|UINT16|0x00000014\r
 \r
 [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx]\r
   ## This flag is used to control the protocols produced by the shell\r