X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShell.c;h=40ae68d5a81f978976856de8c4b30f804aea62fa;hb=d2a0d2e6acea4d6a3dbe31b68a9a7fe7511cb478;hp=36063227a2d84f723ec8d9ce92028f2f3c16d740;hpb=01e3a9767157e4b82ff884c745ab649b34e3cbff;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c index 36063227a2..40ae68d5a8 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1205,6 +1205,7 @@ DoShellPrompt ( CONST CHAR16 *CurDir; UINTN BufferSize; EFI_STATUS Status; + LIST_ENTRY OldBufferList; CurDir = NULL; @@ -1218,6 +1219,7 @@ DoShellPrompt ( return EFI_OUT_OF_RESOURCES; } + SaveBufferList(&OldBufferList); CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd"); // @@ -1247,6 +1249,7 @@ DoShellPrompt ( // // Done with this command // + RestoreBufferList(&OldBufferList); FreePool (CmdLine); return Status; } @@ -1276,6 +1279,36 @@ AddBufferToFreeList( return (Buffer); } + +/** + Create a new buffer list and stores the old one to OldBufferList + + @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList. +**/ +VOID +SaveBufferList ( + OUT LIST_ENTRY *OldBufferList + ) +{ + CopyMem (OldBufferList, &ShellInfoObject.BufferToFreeList.Link, sizeof (LIST_ENTRY)); + InitializeListHead (&ShellInfoObject.BufferToFreeList.Link); +} + +/** + Restore previous nodes into BufferToFreeList . + + @param OldBufferList The temporary list head used to store the nodes in BufferToFreeList. +**/ +VOID +RestoreBufferList ( + IN OUT LIST_ENTRY *OldBufferList + ) +{ + FreeBufferList (&ShellInfoObject.BufferToFreeList); + CopyMem (&ShellInfoObject.BufferToFreeList.Link, OldBufferList, sizeof (LIST_ENTRY)); +} + + /** Add a buffer to the Line History List @@ -1288,13 +1321,40 @@ AddLineToCommandHistory( ) { BUFFER_LIST *Node; + BUFFER_LIST *Walker; + UINT16 MaxHistoryCmdCount; + UINT16 Count; + + Count = 0; + MaxHistoryCmdCount = PcdGet16(PcdShellMaxHistoryCommandCount); + + if (MaxHistoryCmdCount == 0) { + return ; + } + 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); + } } /** @@ -2634,6 +2694,7 @@ RunScriptFileHandle ( CONST CHAR16 *CurDir; UINTN LineCount; CHAR16 LeString[50]; + LIST_ENTRY OldBufferList; ASSERT(!ShellCommandGetScriptExit()); @@ -2736,6 +2797,8 @@ RunScriptFileHandle ( PrintBuffSize/sizeof(CHAR16) - 1 ); + SaveBufferList(&OldBufferList); + // // NULL out comments // @@ -2870,15 +2933,19 @@ RunScriptFileHandle ( ShellCommandRegisterExit(FALSE, 0); Status = EFI_SUCCESS; + RestoreBufferList(&OldBufferList); break; } if (ShellGetExecutionBreakFlag()) { + RestoreBufferList(&OldBufferList); break; } if (EFI_ERROR(Status)) { + RestoreBufferList(&OldBufferList); break; } if (ShellCommandGetExit()) { + RestoreBufferList(&OldBufferList); break; } } @@ -2897,6 +2964,7 @@ RunScriptFileHandle ( NewScriptFile->CurrentCommand->Reset = TRUE; } } + RestoreBufferList(&OldBufferList); }