Add the macro MAX_HISTORY_COMMANDS_COUNT to indicate the max count of history 
commands.

Cc: Jaben Carsey <[email protected]>
Cc: Ruiyu Ni <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <[email protected]>
Reviewed-by: Ruiyu Ni <[email protected]>
---
 ShellPkg/Application/Shell/Shell.c | 24 +++++++++++++++++++++++-
 ShellPkg/Application/Shell/Shell.h |  2 ++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/ShellPkg/Application/Shell/Shell.c 
b/ShellPkg/Application/Shell/Shell.c
index 3606322..be97879 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -1288,13 +1288,35 @@ AddLineToCommandHistory(
   )
 {
   BUFFER_LIST *Node;
+  BUFFER_LIST *Walker;
+  UINT8       MaxHistoryCmdCount;
+  UINT8       Count;
+  
+  Count = 0;
+  MaxHistoryCmdCount = MAX_HISTORY_COMMANDS_COUNT;
 
   Node = AllocateZeroPool(sizeof(BUFFER_LIST));
   ASSERT(Node != NULL);
   Node->Buffer = AllocateCopyPool(StrSize(Buffer), Buffer);
   ASSERT(Node->Buffer != NULL);
 
-  InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, 
&Node->Link);
+  for ( Walker = 
(BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link)
+      ; !IsNull(&ShellInfoObject.ViewingSettings.CommandHistory.Link, 
&Walker->Link)
+      ; Walker = 
(BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, 
&Walker->Link)
+   ){
+    Count++;
+  }
+  if (Count < MaxHistoryCmdCount){
+    InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, 
&Node->Link);
+  } else {
+    Walker = 
(BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link);
+    RemoveEntryList(&Walker->Link);
+    if (Walker->Buffer != NULL) {
+      FreePool(Walker->Buffer);
+    }
+    FreePool(Walker);
+    InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, 
&Node->Link);
+  }
 }
 
 /**
diff --git a/ShellPkg/Application/Shell/Shell.h 
b/ShellPkg/Application/Shell/Shell.h
index 5726320..d5d5878 100644
--- a/ShellPkg/Application/Shell/Shell.h
+++ b/ShellPkg/Application/Shell/Shell.h
@@ -124,6 +124,8 @@ typedef struct {
 
 extern SHELL_INFO ShellInfoObject;
 
+#define MAX_HISTORY_COMMANDS_COUNT    32
+
 /**
   Converts the command line to it's post-processed form.  this replaces 
variables and alias' per UEFI Shell spec.
 
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to