]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8633 6f19259b...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index eb2bc6268f7560bcb3326d9e265f153ac673c1bc..3a56903789a1693b0c57a6215148e83337a6d8b7 100644 (file)
@@ -258,8 +258,7 @@ EFIAPI
 ShellLibDestructor (\r
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
-  )\r
-{\r
+  ){\r
   if (mEfiShellEnvironment2 != NULL) {\r
     gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
                        &gEfiShellEnvironment2Guid,\r
@@ -984,7 +983,7 @@ ShellGetExecutionBreakFlag(
 CONST CHAR16*\r
 EFIAPI\r
 ShellGetEnvironmentVariable (\r
-  IN CHAR16                     *EnvKey\r
+  IN CONST CHAR16                *EnvKey\r
   )\r
 {\r
   // \r
@@ -1002,7 +1001,7 @@ ShellGetEnvironmentVariable (
   //\r
   // using EFI Shell\r
   //\r
-  return (mEfiShellEnvironment2->GetEnv(EnvKey));\r
+  return (mEfiShellEnvironment2->GetEnv((CHAR16*)EnvKey));\r
 }\r
 /**\r
   set the value of an environment variable\r
@@ -1220,32 +1219,26 @@ typedef struct {
   EFI_SHELL_FILE_INFO based list.  it is up to the caller to free the memory via\r
   the ShellCloseFileMetaArg function.\r
 \r
-  @param FileList               the EFI shell list type\r
+  @param[in] FileList           the EFI shell list type\r
+  @param[in][out] ListHead      the list to add to\r
 \r
   @retval the resultant head of the double linked new format list;\r
 **/\r
 LIST_ENTRY*\r
 EFIAPI\r
 InternalShellConvertFileListType (\r
-  LIST_ENTRY                *FileList\r
-  )\r
-{\r
-  LIST_ENTRY                    *ListHead;\r
+  IN LIST_ENTRY                 *FileList,\r
+  IN OUT LIST_ENTRY             *ListHead\r
+  ){\r
   SHELL_FILE_ARG                *OldInfo;\r
-  LIST_ENTRY                *Link;\r
+  LIST_ENTRY                    *Link;\r
   EFI_SHELL_FILE_INFO_NO_CONST  *NewInfo;\r
 \r
   //\r
-  // ASSERT that FileList is not NULL\r
-  //\r
-  ASSERT(FileList != NULL);\r
-\r
-  //\r
-  // Allocate our list head and initialize the list\r
+  // ASSERTs\r
   //\r
-  ListHead = AllocateZeroPool(sizeof(LIST_ENTRY));\r
-  ASSERT (ListHead != NULL);\r
-  ListHead = InitializeListHead (ListHead);\r
+  ASSERT(FileList  != NULL);\r
+  ASSERT(ListHead  != NULL);\r
 \r
   //\r
   // enumerate through each member of the old list and copy\r
@@ -1299,7 +1292,7 @@ InternalShellConvertFileListType (
     //\r
     // add that to the list\r
     //\r
-    InsertTailList(ListHead, (LIST_ENTRY*)NewInfo);\r
+    InsertTailList(ListHead, &NewInfo->Link);\r
   }\r
   return (ListHead);\r
 }\r
@@ -1313,7 +1306,7 @@ InternalShellConvertFileListType (
   and will process '?' and '*' as such.  the list must be freed with a call to \r
   ShellCloseFileMetaArg().\r
 \r
-  This function will fail if called sequentially without freeing the list in the middle.\r
+  If you are NOT appending to an existing list *ListHead must be NULL.\r
 \r
   @param Arg                    pointer to path string\r
   @param OpenMode               mode to open files with\r
@@ -1336,8 +1329,7 @@ ShellOpenFileMetaArg (
   )\r
 {\r
   EFI_STATUS                    Status;\r
-  LIST_ENTRY                    *EmptyNode;\r
-  LIST_ENTRY                    *mOldStyleFileList;\r
+  LIST_ENTRY                    mOldStyleFileList;\r
   \r
   //\r
   // ASSERT that Arg and ListHead are not NULL\r
@@ -1359,43 +1351,36 @@ ShellOpenFileMetaArg (
   //\r
   ASSERT(mEfiShellEnvironment2 != NULL);\r
 \r
-  //\r
-  // allocate memory for old list head\r
-  //\r
-  mOldStyleFileList = (LIST_ENTRY*)AllocatePool(sizeof(LIST_ENTRY));\r
-  ASSERT(mOldStyleFileList != NULL);\r
-\r
   //\r
   // make sure the list head is initialized\r
   //\r
-  InitializeListHead((LIST_ENTRY*)mOldStyleFileList);\r
+  InitializeListHead(&mOldStyleFileList);\r
 \r
   //\r
   // Get the EFI Shell list of files\r
   //\r
-  Status = mEfiShellEnvironment2->FileMetaArg(Arg, mOldStyleFileList);\r
+  Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);\r
   if (EFI_ERROR(Status)) {\r
     *ListHead = NULL;\r
     return (Status);\r
   }\r
 \r
+  if (*ListHead == NULL) {\r
+    *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+    if (*ListHead == NULL) {\r
+      return (EFI_OUT_OF_RESOURCES);\r
+    }\r
+  }\r
+\r
   //\r
   // Convert that to equivalent of UEFI Shell 2.0 structure\r
   //\r
-  EmptyNode = InternalShellConvertFileListType(mOldStyleFileList);\r
+  InternalShellConvertFileListType(&mOldStyleFileList, &(*ListHead)->Link);\r
 \r
   //\r
   // Free the EFI Shell version that was converted.\r
   //\r
-  ASSERT_EFI_ERROR(mEfiShellEnvironment2->FreeFileList(mOldStyleFileList));\r
-  FreePool(mOldStyleFileList);\r
-  mOldStyleFileList = NULL;\r
-\r
-  //\r
-  // remove the empty head of the list\r
-  //\r
-  *ListHead = (EFI_SHELL_FILE_INFO*)RemoveEntryList(EmptyNode);\r
-  FreePool(EmptyNode);  \r
+  mEfiShellEnvironment2->FreeFileList(&mOldStyleFileList);\r
 \r
   return (Status);\r
 }\r
@@ -1431,7 +1416,9 @@ ShellCloseFileMetaArg (
     // Since this is EFI Shell version we need to free our internally made copy \r
     // of the list\r
     //\r
-    for (Node = GetFirstNode((LIST_ENTRY*)*ListHead) ; IsListEmpty((LIST_ENTRY*)*ListHead) == FALSE ; Node = GetFirstNode((LIST_ENTRY*)*ListHead)) {\r
+    for ( Node = GetFirstNode(&(*ListHead)->Link) \r
+        ; IsListEmpty(&(*ListHead)->Link) == FALSE \r
+        ; Node = GetFirstNode(&(*ListHead)->Link)) {\r
       RemoveEntryList(Node);\r
       ((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle->Close(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle);\r
       FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FullName);\r
@@ -1444,7 +1431,7 @@ ShellCloseFileMetaArg (
 }\r
 \r
 typedef struct {\r
-  LIST_ENTRY List;\r
+  LIST_ENTRY     Link;\r
   CHAR16         *Name;\r
   ParamType      Type;\r
   CHAR16         *Value;\r
@@ -1636,7 +1623,7 @@ InternalCommandLineParse (
         //\r
         // this item has no value expected; we are done\r
         //\r
-        InsertHeadList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
+        InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
     } else if (GetItemValue == TRUE && InternalIsFlag(Argv[LoopCounter]) == FALSE) {\r
       ASSERT(CurrentItemPackage != NULL);\r
@@ -1647,7 +1634,7 @@ InternalCommandLineParse (
       CurrentItemPackage->Value = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
       ASSERT(CurrentItemPackage->Value != NULL);\r
       StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-      InsertHeadList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
+      InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
     } else if (InternalIsFlag(Argv[LoopCounter]) == FALSE) {\r
       //\r
       // add this one as a non-flag\r
@@ -1660,7 +1647,7 @@ InternalCommandLineParse (
       ASSERT(CurrentItemPackage->Value != NULL);\r
       StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
       CurrentItemPackage->OriginalPosition = Count++;\r
-      InsertHeadList(*CheckPackage, (LIST_ENTRY*)CurrentItemPackage);\r
+      InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
     } else if (ProblemParam) {\r
       //\r
       // this was a non-recognised flag... error!\r
@@ -2009,11 +1996,10 @@ CopyReplace(
 /**\r
   Print at a specific location on the screen.\r
 \r
-  This function will move the cursor to a given screen location, print the specified string, \r
-  and return the cursor to the original locaiton.  \r
+  This function will move the cursor to a given screen location and print the specified string\r
   \r
   If -1 is specified for either the Row or Col the current screen location for BOTH \r
-  will be used and the cursor's position will not be moved back to an original location.\r
+  will be used.\r
 \r
   if either Row or Col is out of range for the current console, then ASSERT\r
   if Format is NULL, then ASSERT\r
@@ -2048,8 +2034,7 @@ ShellPrintEx(
   CHAR16            *PostReplaceFormat;\r
   CHAR16            *PostReplaceFormat2;\r
   UINTN             Return;\r
-  INT32             CurrentCol;\r
-  INT32             CurrentRow;\r
+\r
   EFI_STATUS        Status;\r
   UINTN             NormalAttribute;\r
   CHAR16            *ResumeLocation;\r
@@ -2085,13 +2070,8 @@ ShellPrintEx(
   FreePool(PostReplaceFormat);\r
 \r
   if (Col != -1 && Row != -1) {\r
-    CurrentCol = gST->ConOut->Mode->CursorColumn;\r
-    CurrentRow = gST->ConOut->Mode->CursorRow;\r
     Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r
     ASSERT_EFI_ERROR(Status);\r
-  } else {\r
-    CurrentCol = 0;\r
-    CurrentRow = 0;\r
   }\r
 \r
   NormalAttribute = gST->ConOut->Mode->Attribute;\r
@@ -2146,11 +2126,6 @@ ShellPrintEx(
     //\r
     FormatWalker = ResumeLocation + 2;\r
   }\r
-    \r
-  if (Col != -1 && Row != -1) {\r
-    Status = gST->ConOut->SetCursorPosition(gST->ConOut, CurrentCol, CurrentRow);\r
-    ASSERT_EFI_ERROR(Status);\r
-  }\r
 \r
   FreePool(PostReplaceFormat2);\r
 \r