]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
Move the 2 functions associated with reading whole lines at a single time from the...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index ba0395dec2a45b333ddd156ab8d36751bf969d9e..3c1b983a6028526787ef0f07f91d97f04cf14c57 100644 (file)
@@ -30,12 +30,10 @@ SHELL_PARAM_ITEM SfoParamList[] = {
   };\r
 EFI_SHELL_ENVIRONMENT2        *mEfiShellEnvironment2;\r
 EFI_SHELL_INTERFACE           *mEfiShellInterface;\r
-EFI_SHELL_PROTOCOL            *mEfiShellProtocol;\r
-EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;\r
+EFI_SHELL_PROTOCOL            *gEfiShellProtocol;\r
+EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;\r
 EFI_HANDLE                    mEfiShellEnvironment2Handle;\r
 FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;\r
-CHAR16                        *mPostReplaceFormat;\r
-CHAR16                        *mPostReplaceFormat2;\r
 \r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
@@ -177,10 +175,6 @@ ShellLibConstructorWorker (
   )\r
 {\r
   EFI_STATUS  Status;\r
-  mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
-  ASSERT (mPostReplaceFormat != NULL);\r
-  mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
-  ASSERT (mPostReplaceFormat2 != NULL);\r
 \r
   //\r
   // UEFI 2.0 shell interfaces (used preferentially)\r
@@ -188,7 +182,7 @@ ShellLibConstructorWorker (
   Status = gBS->OpenProtocol(\r
     ImageHandle,\r
     &gEfiShellProtocolGuid,\r
-    (VOID **)&mEfiShellProtocol,\r
+    (VOID **)&gEfiShellProtocol,\r
     ImageHandle,\r
     NULL,\r
     EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
@@ -200,25 +194,25 @@ ShellLibConstructorWorker (
     Status = gBS->LocateProtocol(\r
       &gEfiShellProtocolGuid,\r
       NULL,\r
-      (VOID **)&mEfiShellProtocol\r
+      (VOID **)&gEfiShellProtocol\r
      );\r
     if (EFI_ERROR(Status)) {\r
-      mEfiShellProtocol = NULL;\r
+      gEfiShellProtocol = NULL;\r
     }\r
   }\r
   Status = gBS->OpenProtocol(\r
     ImageHandle,\r
     &gEfiShellParametersProtocolGuid,\r
-    (VOID **)&mEfiShellParametersProtocol,\r
+    (VOID **)&gEfiShellParametersProtocol,\r
     ImageHandle,\r
     NULL,\r
     EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
    );\r
   if (EFI_ERROR(Status)) {\r
-    mEfiShellParametersProtocol = NULL;\r
+    gEfiShellParametersProtocol = NULL;\r
   }\r
 \r
-  if (mEfiShellParametersProtocol == NULL || mEfiShellProtocol == NULL) {\r
+  if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) {\r
     //\r
     // Moved to seperate function due to complexity\r
     //\r
@@ -244,18 +238,18 @@ ShellLibConstructorWorker (
   // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
   //\r
   if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface          != NULL) ||\r
-      (mEfiShellProtocol     != NULL && mEfiShellParametersProtocol != NULL)   ) {\r
-    if (mEfiShellProtocol != NULL) {\r
-      FileFunctionMap.GetFileInfo     = mEfiShellProtocol->GetFileInfo;\r
-      FileFunctionMap.SetFileInfo     = mEfiShellProtocol->SetFileInfo;\r
-      FileFunctionMap.ReadFile        = mEfiShellProtocol->ReadFile;\r
-      FileFunctionMap.WriteFile       = mEfiShellProtocol->WriteFile;\r
-      FileFunctionMap.CloseFile       = mEfiShellProtocol->CloseFile;\r
-      FileFunctionMap.DeleteFile      = mEfiShellProtocol->DeleteFile;\r
-      FileFunctionMap.GetFilePosition = mEfiShellProtocol->GetFilePosition;\r
-      FileFunctionMap.SetFilePosition = mEfiShellProtocol->SetFilePosition;\r
-      FileFunctionMap.FlushFile       = mEfiShellProtocol->FlushFile;\r
-      FileFunctionMap.GetFileSize     = mEfiShellProtocol->GetFileSize;\r
+      (gEfiShellProtocol     != NULL && gEfiShellParametersProtocol != NULL)   ) {\r
+    if (gEfiShellProtocol != NULL) {\r
+      FileFunctionMap.GetFileInfo     = gEfiShellProtocol->GetFileInfo;\r
+      FileFunctionMap.SetFileInfo     = gEfiShellProtocol->SetFileInfo;\r
+      FileFunctionMap.ReadFile        = gEfiShellProtocol->ReadFile;\r
+      FileFunctionMap.WriteFile       = gEfiShellProtocol->WriteFile;\r
+      FileFunctionMap.CloseFile       = gEfiShellProtocol->CloseFile;\r
+      FileFunctionMap.DeleteFile      = gEfiShellProtocol->DeleteFile;\r
+      FileFunctionMap.GetFilePosition = gEfiShellProtocol->GetFilePosition;\r
+      FileFunctionMap.SetFilePosition = gEfiShellProtocol->SetFilePosition;\r
+      FileFunctionMap.FlushFile       = gEfiShellProtocol->FlushFile;\r
+      FileFunctionMap.GetFileSize     = gEfiShellProtocol->GetFileSize;\r
     } else {\r
       FileFunctionMap.GetFileInfo     = (EFI_SHELL_GET_FILE_INFO)FileHandleGetInfo;\r
       FileFunctionMap.SetFileInfo     = (EFI_SHELL_SET_FILE_INFO)FileHandleSetInfo;\r
@@ -291,12 +285,10 @@ ShellLibConstructor (
   )\r
 {\r
   mEfiShellEnvironment2       = NULL;\r
-  mEfiShellProtocol           = NULL;\r
-  mEfiShellParametersProtocol = NULL;\r
+  gEfiShellProtocol           = NULL;\r
+  gEfiShellParametersProtocol = NULL;\r
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
-  mPostReplaceFormat          = NULL;\r
-  mPostReplaceFormat2         = NULL;\r
 \r
   //\r
   // verify that auto initialize is not set false\r
@@ -338,31 +330,22 @@ ShellLibDestructor (
                        NULL);\r
     mEfiShellInterface = NULL;\r
   }\r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
     gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellProtocolGuid,\r
                        ImageHandle,\r
                        NULL);\r
-    mEfiShellProtocol = NULL;\r
+    gEfiShellProtocol = NULL;\r
   }\r
-  if (mEfiShellParametersProtocol != NULL) {\r
+  if (gEfiShellParametersProtocol != NULL) {\r
     gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellParametersProtocolGuid,\r
                        ImageHandle,\r
                        NULL);\r
-    mEfiShellParametersProtocol = NULL;\r
+    gEfiShellParametersProtocol = NULL;\r
   }\r
   mEfiShellEnvironment2Handle = NULL;\r
 \r
-  if (mPostReplaceFormat != NULL) {\r
-    FreePool(mPostReplaceFormat);\r
-  }\r
-  if (mPostReplaceFormat2 != NULL) {\r
-    FreePool(mPostReplaceFormat2);\r
-  }\r
-  mPostReplaceFormat          = NULL;\r
-  mPostReplaceFormat2         = NULL;\r
-\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -500,20 +483,18 @@ ShellOpenFileByDevicePath(
   EFI_FILE_PROTOCOL               *Handle1;\r
   EFI_FILE_PROTOCOL               *Handle2;\r
 \r
-  //\r
-  // ASERT for FileHandle, FilePath, and DeviceHandle being NULL\r
-  //\r
-  ASSERT(FilePath != NULL);\r
-  ASSERT(FileHandle != NULL);\r
-  ASSERT(DeviceHandle != NULL);\r
+  if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   //\r
   // which shell interface should we use\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
     //\r
     // use UEFI Shell 2.0 method.\r
     //\r
-    FileName = mEfiShellProtocol->GetFilePathFromDevicePath(*FilePath);\r
+    FileName = gEfiShellProtocol->GetFilePathFromDevicePath(*FilePath);\r
     if (FileName == NULL) {\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
@@ -618,7 +599,7 @@ ShellOpenFileByDevicePath(
   otherwise, the Filehandle is NULL. The Attributes is valid only for\r
   EFI_FILE_MODE_CREATE.\r
 \r
-  if FileNAme is NULL then ASSERT()\r
+  if FileName is NULL then ASSERT()\r
 \r
   @param  FileName               pointer to file name\r
   @param  FileHandle           pointer to the file handle.\r
@@ -665,14 +646,14 @@ ShellOpenFileByName(
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
     if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE && (Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
       return ShellCreateDirectory(FileName, FileHandle);\r
     }\r
     //\r
     // Use UEFI Shell 2.0 method\r
     //\r
-    Status = mEfiShellProtocol->OpenFileByName(FileName,\r
+    Status = gEfiShellProtocol->OpenFileByName(FileName,\r
                                                FileHandle,\r
                                                OpenMode);\r
     if (StrCmp(FileName, L"NUL") != 0 && !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){\r
@@ -735,11 +716,11 @@ ShellCreateDirectory(
   OUT SHELL_FILE_HANDLE                  *FileHandle\r
   )\r
 {\r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
     //\r
     // Use UEFI Shell 2.0 method\r
     //\r
-    return (mEfiShellProtocol->CreateFile(DirectoryName,\r
+    return (gEfiShellProtocol->CreateFile(DirectoryName,\r
                           EFI_FILE_DIRECTORY,\r
                           FileHandle\r
                          ));\r
@@ -1050,12 +1031,12 @@ ShellGetExecutionBreakFlag(
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
 \r
     //\r
     // We are using UEFI Shell 2.0; see if the event has been triggered\r
     //\r
-    if (gBS->CheckEvent(mEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {\r
+    if (gBS->CheckEvent(gEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {\r
       return (FALSE);\r
     }\r
     return (TRUE);\r
@@ -1064,8 +1045,11 @@ ShellGetExecutionBreakFlag(
   //\r
   // using EFI Shell; call the function to check\r
   //\r
-  ASSERT(mEfiShellEnvironment2 != NULL);\r
-  return (mEfiShellEnvironment2->GetExecutionBreak());\r
+  if (mEfiShellEnvironment2 != NULL) {\r
+    return (mEfiShellEnvironment2->GetExecutionBreak());\r
+  }\r
+\r
+  return (FALSE);\r
 }\r
 /**\r
   return the value of an environment variable\r
@@ -1087,19 +1071,18 @@ ShellGetEnvironmentVariable (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
-    return (mEfiShellProtocol->GetEnv(EnvKey));\r
+  if (gEfiShellProtocol != NULL) {\r
+    return (gEfiShellProtocol->GetEnv(EnvKey));\r
   }\r
 \r
   //\r
-  // ASSERT that we must have EFI shell\r
+  // Check for EFI shell\r
   //\r
-  ASSERT(mEfiShellEnvironment2 != NULL);\r
+  if (mEfiShellEnvironment2 != NULL) {\r
+    return (mEfiShellEnvironment2->GetEnv((CHAR16*)EnvKey));\r
+  }\r
 \r
-  //\r
-  // using EFI Shell\r
-  //\r
-  return (mEfiShellEnvironment2->GetEnv((CHAR16*)EnvKey));\r
+  return NULL;\r
 }\r
 /**\r
   set the value of an environment variable\r
@@ -1132,8 +1115,8 @@ ShellSetEnvironmentVariable (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
-    return (mEfiShellProtocol->SetEnv(EnvKey, EnvVal, Volatile));\r
+  if (gEfiShellProtocol != NULL) {\r
+    return (gEfiShellProtocol->SetEnv(EnvKey, EnvVal, Volatile));\r
   }\r
 \r
   //\r
@@ -1185,26 +1168,30 @@ ShellExecute (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
     //\r
     // Call UEFI Shell 2.0 version (not using Output parameter)\r
     //\r
-    return (mEfiShellProtocol->Execute(ParentHandle,\r
+    return (gEfiShellProtocol->Execute(ParentHandle,\r
                                       CommandLine,\r
                                       EnvironmentVariables,\r
                                       Status));\r
   }\r
+\r
   //\r
-  // ASSERT that we must have EFI shell\r
-  //\r
-  ASSERT(mEfiShellEnvironment2 != NULL);\r
-  //\r
-  // Call EFI Shell version (not using EnvironmentVariables or Status parameters)\r
-  // Due to oddity in the EFI shell we want to dereference the ParentHandle here\r
+  // Check for EFI shell\r
   //\r
-  return (mEfiShellEnvironment2->Execute(*ParentHandle,\r
-                                        CommandLine,\r
-                                        Output));\r
+  if (mEfiShellEnvironment2 != NULL) {\r
+    //\r
+    // Call EFI Shell version (not using EnvironmentVariables or Status parameters)\r
+    // Due to oddity in the EFI shell we want to dereference the ParentHandle here\r
+    //\r
+    return (mEfiShellEnvironment2->Execute(*ParentHandle,\r
+                                          CommandLine,\r
+                                          Output));\r
+  }\r
+\r
+  return (EFI_UNSUPPORTED);\r
 }\r
 /**\r
   Retreives the current directory path\r
@@ -1227,14 +1214,18 @@ ShellGetCurrentDir (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
-    return (mEfiShellProtocol->GetCurDir(DeviceName));\r
+  if (gEfiShellProtocol != NULL) {\r
+    return (gEfiShellProtocol->GetCurDir(DeviceName));\r
   }\r
+\r
   //\r
-  // ASSERT that we must have EFI shell\r
+  // Check for EFI shell\r
   //\r
-  ASSERT(mEfiShellEnvironment2 != NULL);\r
-  return (mEfiShellEnvironment2->CurDir(DeviceName));\r
+  if (mEfiShellEnvironment2 != NULL) {\r
+    return (mEfiShellEnvironment2->CurDir(DeviceName));\r
+  }\r
+\r
+  return (NULL);\r
 }\r
 /**\r
   sets (enabled or disabled) the page break mode\r
@@ -1257,43 +1248,45 @@ ShellSetPageBreakMode (
     //\r
     // check for UEFI Shell 2.0\r
     //\r
-    if (mEfiShellProtocol != NULL) {\r
+    if (gEfiShellProtocol != NULL) {\r
       //\r
       // Enable with UEFI 2.0 Shell\r
       //\r
-      mEfiShellProtocol->EnablePageBreak();\r
+      gEfiShellProtocol->EnablePageBreak();\r
       return;\r
     } else {\r
       //\r
-      // ASSERT that must have EFI Shell\r
-      //\r
-      ASSERT(mEfiShellEnvironment2 != NULL);\r
+      // Check for EFI shell\r
       //\r
-      // Enable with EFI Shell\r
-      //\r
-      mEfiShellEnvironment2->EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);\r
-      return;\r
+      if (mEfiShellEnvironment2 != NULL) {\r
+        //\r
+        // Enable with EFI Shell\r
+        //\r
+        mEfiShellEnvironment2->EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);\r
+        return;\r
+      }\r
     }\r
   } else {\r
     //\r
     // check for UEFI Shell 2.0\r
     //\r
-    if (mEfiShellProtocol != NULL) {\r
+    if (gEfiShellProtocol != NULL) {\r
       //\r
       // Disable with UEFI 2.0 Shell\r
       //\r
-      mEfiShellProtocol->DisablePageBreak();\r
+      gEfiShellProtocol->DisablePageBreak();\r
       return;\r
     } else {\r
       //\r
-      // ASSERT that must have EFI Shell\r
-      //\r
-      ASSERT(mEfiShellEnvironment2 != NULL);\r
-      //\r
-      // Disable with EFI Shell\r
+      // Check for EFI shell\r
       //\r
-      mEfiShellEnvironment2->DisablePageBreak ();\r
-      return;\r
+      if (mEfiShellEnvironment2 != NULL) {\r
+        //\r
+        // Disable with EFI Shell\r
+        //\r
+        mEfiShellEnvironment2->DisablePageBreak ();\r
+        return;\r
+      }\r
     }\r
   }\r
 }\r
@@ -1452,7 +1445,7 @@ ShellOpenFileMetaArg (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
+  if (gEfiShellProtocol != NULL) {\r
     if (*ListHead == NULL) {\r
       *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
@@ -1460,13 +1453,13 @@ ShellOpenFileMetaArg (
       }\r
       InitializeListHead(&((*ListHead)->Link));\r
     }\r
-    Status = mEfiShellProtocol->OpenFileList(Arg,\r
+    Status = gEfiShellProtocol->OpenFileList(Arg,\r
                                            OpenMode,\r
                                            ListHead);\r
     if (EFI_ERROR(Status)) {\r
-      mEfiShellProtocol->RemoveDupInFileList(ListHead);\r
+      gEfiShellProtocol->RemoveDupInFileList(ListHead);\r
     } else {\r
-      Status = mEfiShellProtocol->RemoveDupInFileList(ListHead);\r
+      Status = gEfiShellProtocol->RemoveDupInFileList(ListHead);\r
     }\r
     if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {\r
       FreePool(*ListHead);\r
@@ -1477,49 +1470,50 @@ ShellOpenFileMetaArg (
   }\r
 \r
   //\r
-  // ASSERT that we must have EFI shell\r
-  //\r
-  ASSERT(mEfiShellEnvironment2 != NULL);\r
-\r
-  //\r
-  // make sure the list head is initialized\r
+  // Check for EFI shell\r
   //\r
-  InitializeListHead(&mOldStyleFileList);\r
+  if (mEfiShellEnvironment2 != NULL) {\r
+    //\r
+    // make sure the list head is initialized\r
+    //\r
+    InitializeListHead(&mOldStyleFileList);\r
 \r
-  //\r
-  // Get the EFI Shell list of files\r
-  //\r
-  Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);\r
-  if (EFI_ERROR(Status)) {\r
-    *ListHead = NULL;\r
-    return (Status);\r
-  }\r
+    //\r
+    // Get the EFI Shell list of files\r
+    //\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
+      *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+      if (*ListHead == NULL) {\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
+      InitializeListHead(&((*ListHead)->Link));\r
     }\r
-    InitializeListHead(&((*ListHead)->Link));\r
-  }\r
 \r
-  //\r
-  // Convert that to equivalent of UEFI Shell 2.0 structure\r
-  //\r
-  InternalShellConvertFileListType(&mOldStyleFileList, &(*ListHead)->Link);\r
+    //\r
+    // Convert that to equivalent of UEFI Shell 2.0 structure\r
+    //\r
+    InternalShellConvertFileListType(&mOldStyleFileList, &(*ListHead)->Link);\r
 \r
-  //\r
-  // Free the EFI Shell version that was converted.\r
-  //\r
-  mEfiShellEnvironment2->FreeFileList(&mOldStyleFileList);\r
+    //\r
+    // Free the EFI Shell version that was converted.\r
+    //\r
+    mEfiShellEnvironment2->FreeFileList(&mOldStyleFileList);\r
 \r
-  if ((*ListHead)->Link.ForwardLink == (*ListHead)->Link.BackLink && (*ListHead)->Link.BackLink == &((*ListHead)->Link)) {\r
-    FreePool(*ListHead);\r
-    *ListHead = NULL;\r
-    Status = EFI_NOT_FOUND;\r
+    if ((*ListHead)->Link.ForwardLink == (*ListHead)->Link.BackLink && (*ListHead)->Link.BackLink == &((*ListHead)->Link)) {\r
+      FreePool(*ListHead);\r
+      *ListHead = NULL;\r
+      Status = EFI_NOT_FOUND;\r
+    }\r
+    return (Status);\r
   }\r
 \r
-  return (Status);\r
+  return (EFI_UNSUPPORTED);\r
 }\r
 /**\r
   Free the linked list returned from ShellOpenFileMetaArg.\r
@@ -1546,9 +1540,9 @@ ShellCloseFileMetaArg (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellProtocol != NULL) {\r
-    return (mEfiShellProtocol->FreeFileList(ListHead));\r
-  } else {\r
+  if (gEfiShellProtocol != NULL) {\r
+    return (gEfiShellProtocol->FreeFileList(ListHead));\r
+  } else if (mEfiShellEnvironment2 != NULL) {\r
     //\r
     // Since this is EFI Shell version we need to free our internally made copy\r
     // of the list\r
@@ -1565,6 +1559,8 @@ ShellCloseFileMetaArg (
     }\r
     return EFI_SUCCESS;\r
   }\r
+\r
+  return (EFI_UNSUPPORTED);\r
 }\r
 \r
 /**\r
@@ -1655,6 +1651,9 @@ ShellFindFilePath (
         if (TestPath[StrLen(TestPath)-1] != L'\\') {\r
           StrCat(TestPath, L"\\");\r
         }\r
+        if (FileName[0] == L'\\') {\r
+          FileName++;\r
+        }\r
         StrCat(TestPath, FileName);\r
         if (StrStr(Walker, L";") != NULL) {\r
           Walker = StrStr(Walker, L";") + 1;\r
@@ -2100,13 +2099,13 @@ ShellCommandLineParseEx (
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
-  if (mEfiShellParametersProtocol != NULL) {\r
+  if (gEfiShellParametersProtocol != NULL) {\r
     return (InternalCommandLineParse(CheckList,\r
                                      CheckPackage,\r
                                      ProblemParam,\r
                                      AutoPageBreak,\r
-                                     (CONST CHAR16**) mEfiShellParametersProtocol->Argv,\r
-                                     mEfiShellParametersProtocol->Argc,\r
+                                     (CONST CHAR16**) gEfiShellParametersProtocol->Argv,\r
+                                     gEfiShellParametersProtocol->Argc,\r
                                      AlwaysAllowNumbers));\r
   }\r
 \r
@@ -2558,8 +2557,8 @@ InternalPrintTo (
   if (Size == 0) {\r
     return (EFI_SUCCESS);\r
   }\r
-  if (mEfiShellParametersProtocol != NULL) {\r
-    return (mEfiShellProtocol->WriteFile(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
+  if (gEfiShellParametersProtocol != NULL) {\r
+    return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
   }\r
   if (mEfiShellInterface          != NULL) {\r
     //\r
@@ -2614,6 +2613,17 @@ InternalShellPrintWorker(
   CHAR16            *ResumeLocation;\r
   CHAR16            *FormatWalker;\r
   UINTN             OriginalAttribute;\r
+  CHAR16            *mPostReplaceFormat;\r
+  CHAR16            *mPostReplaceFormat2;\r
+\r
+  mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
+  mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
+\r
+  if (mPostReplaceFormat == NULL || mPostReplaceFormat2 == NULL) {\r
+    SHELL_FREE_NON_NULL(mPostReplaceFormat);\r
+    SHELL_FREE_NON_NULL(mPostReplaceFormat2);\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
 \r
   Status            = EFI_SUCCESS;\r
   OriginalAttribute = gST->ConOut->Mode->Attribute;\r
@@ -2705,6 +2715,9 @@ InternalShellPrintWorker(
   }\r
 \r
   gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);\r
+\r
+  SHELL_FREE_NON_NULL(mPostReplaceFormat);\r
+  SHELL_FREE_NON_NULL(mPostReplaceFormat2);\r
   return (Status);\r
 }\r
 \r
@@ -2846,13 +2859,13 @@ ShellIsDirectory(
     //\r
     // try good logic first.\r
     //\r
-    if (mEfiShellProtocol != NULL) {\r
+    if (gEfiShellProtocol != NULL) {\r
       TempLocation  = StrnCatGrow(&TempLocation, NULL, DirName, 0);\r
       TempLocation2 = StrStr(TempLocation, L":");\r
       if (TempLocation2 != NULL && StrLen(StrStr(TempLocation, L":")) == 2) {\r
         *(TempLocation2+1) = CHAR_NULL;\r
       }\r
-      if (mEfiShellProtocol->GetDevicePathFromMap(TempLocation) != NULL) {\r
+      if (gEfiShellProtocol->GetDevicePathFromMap(TempLocation) != NULL) {\r
         FreePool(TempLocation);\r
         return (EFI_SUCCESS);\r
       }\r
@@ -3795,3 +3808,154 @@ ShellIsHexOrDecimalNumber (
   }\r
   return (FALSE);\r
 }\r
+\r
+/**\r
+  Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned\r
+  buffer.  The returned buffer must be callee freed.\r
+\r
+  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
+  maintained and not changed for all operations with the same file.\r
+\r
+  @param[in]      Handle        SHELL_FILE_HANDLE to read from.\r
+  @param[in,out]  Ascii         Boolean value for indicating whether the file is\r
+                                Ascii (TRUE) or UCS2 (FALSE).\r
+\r
+  @return                       The line of text from the file.\r
+\r
+  @sa ShellFileHandleReadLine\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+ShellFileHandleReturnLine(\r
+  IN SHELL_FILE_HANDLE            Handle,\r
+  IN OUT BOOLEAN                *Ascii\r
+  )\r
+{\r
+  CHAR16          *RetVal;\r
+  UINTN           Size;\r
+  EFI_STATUS      Status;\r
+\r
+  Size = 0;\r
+  RetVal = NULL;\r
+\r
+  Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    RetVal = AllocateZeroPool(Size);\r
+    Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
+  }\r
+  ASSERT_EFI_ERROR(Status);\r
+  if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
+    FreePool(RetVal);\r
+    RetVal = NULL;\r
+  }\r
+  return (RetVal);\r
+}\r
+\r
+/**\r
+  Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE.\r
+\r
+  If the position upon start is 0, then the Ascii Boolean will be set.  This should be\r
+  maintained and not changed for all operations with the same file.\r
+\r
+  @param[in]      Handle        SHELL_FILE_HANDLE to read from.\r
+  @param[in,out]  Buffer        The pointer to buffer to read into.\r
+  @param[in,out]  Size          The pointer to number of bytes in Buffer.\r
+  @param[in]      Truncate      If the buffer is large enough, this has no effect.\r
+                                If the buffer is is too small and Truncate is TRUE,\r
+                                the line will be truncated.\r
+                                If the buffer is is too small and Truncate is FALSE,\r
+                                then no read will occur.\r
+\r
+  @param[in,out]  Ascii         Boolean value for indicating whether the file is\r
+                                Ascii (TRUE) or UCS2 (FALSE).\r
+\r
+  @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
+                                Buffer.\r
+  @retval EFI_INVALID_PARAMETER Handle was NULL.\r
+  @retval EFI_INVALID_PARAMETER Size was NULL.\r
+  @retval EFI_BUFFER_TOO_SMALL  Size was not large enough to store the line.\r
+                                Size was updated to the minimum space required.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellFileHandleReadLine(\r
+  IN SHELL_FILE_HANDLE          Handle,\r
+  IN OUT CHAR16                 *Buffer,\r
+  IN OUT UINTN                  *Size,\r
+  IN BOOLEAN                    Truncate,\r
+  IN OUT BOOLEAN                *Ascii\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  CHAR16      CharBuffer;\r
+  UINTN       CharSize;\r
+  UINTN       CountSoFar;\r
+  UINT64      OriginalFilePosition;\r
+\r
+\r
+  if (Handle == NULL\r
+    ||Size   == NULL\r
+   ){\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+  if (Buffer == NULL) {\r
+    ASSERT(*Size == 0);\r
+  } else {\r
+    *Buffer = CHAR_NULL;\r
+  }\r
+  gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);\r
+  if (OriginalFilePosition == 0) {\r
+    CharSize = sizeof(CHAR16);\r
+    Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
+    ASSERT_EFI_ERROR(Status);\r
+    if (CharBuffer == gUnicodeFileTag) {\r
+      *Ascii = FALSE;\r
+    } else {\r
+      *Ascii = TRUE;\r
+      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
+    }\r
+  }\r
+\r
+  for (CountSoFar = 0;;CountSoFar++){\r
+    CharBuffer = 0;\r
+    if (*Ascii) {\r
+      CharSize = sizeof(CHAR8);\r
+    } else {\r
+      CharSize = sizeof(CHAR16);\r
+    }\r
+    Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
+    if (  EFI_ERROR(Status)\r
+       || CharSize == 0\r
+       || (CharBuffer == L'\n' && !(*Ascii))\r
+       || (CharBuffer ==  '\n' && *Ascii)\r
+     ){\r
+      break;\r
+    }\r
+    //\r
+    // if we have space save it...\r
+    //\r
+    if ((CountSoFar+1)*sizeof(CHAR16) < *Size){\r
+      ASSERT(Buffer != NULL);\r
+      ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;\r
+      ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;\r
+    }\r
+  }\r
+\r
+  //\r
+  // if we ran out of space tell when...\r
+  //\r
+  if ((CountSoFar+1)*sizeof(CHAR16) > *Size){\r
+    *Size = (CountSoFar+1)*sizeof(CHAR16);\r
+    if (!Truncate) {\r
+      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
+    } else {\r
+      DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
+    }\r
+    return (EFI_BUFFER_TOO_SMALL);\r
+  }\r
+  while(Buffer[StrLen(Buffer)-1] == L'\r') {\r
+    Buffer[StrLen(Buffer)-1] = CHAR_NULL;\r
+  }\r
+\r
+  return (Status);\r
+}\r