]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index a0a7da87daec09f3d4d352a9ca6f965cc6fe384b..a72767bd869fa6930e8b7b141c8922b3ecd7e612 100644 (file)
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
-  Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
-  This program and the accompanying materials\r
-  are licensed and made available under the terms and conditions of the BSD License\r
-  which accompanies this distribution.  The full text of the license may be found at\r
-  http://opensource.org/licenses/bsd-license.php\r
-\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+  (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+  Copyright 2016-2018 Dell Technologies.<BR>\r
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "UefiShellLib.h"\r
 \r
 **/\r
 \r
 #include "UefiShellLib.h"\r
-#include <ShellBase.h>\r
 #include <Library/SortLib.h>\r
 #include <Library/SortLib.h>\r
-\r
-#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
+#include <Library/BaseLib.h>\r
 \r
 //\r
 // globals...\r
 //\r
 \r
 //\r
 // globals...\r
 //\r
-SHELL_PARAM_ITEM EmptyParamList[] = {\r
-  {NULL, TypeMax}\r
-  };\r
-SHELL_PARAM_ITEM SfoParamList[] = {\r
-  {L"-sfo", TypeFlag},\r
-  {NULL, TypeMax}\r
-  };\r
-EFI_SHELL_ENVIRONMENT2        *mEfiShellEnvironment2;\r
-EFI_SHELL_INTERFACE           *mEfiShellInterface;\r
-EFI_SHELL_PROTOCOL            *gEfiShellProtocol;\r
-EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;\r
-EFI_HANDLE                    mEfiShellEnvironment2Handle;\r
-FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;\r
+SHELL_PARAM_ITEM                EmptyParamList[] = {\r
+  { NULL, TypeMax }\r
+};\r
+SHELL_PARAM_ITEM                SfoParamList[] = {\r
+  { L"-sfo", TypeFlag },\r
+  { NULL,    TypeMax  }\r
+};\r
+EFI_SHELL_ENVIRONMENT2          *mEfiShellEnvironment2;\r
+EFI_SHELL_INTERFACE             *mEfiShellInterface;\r
+EFI_SHELL_PROTOCOL              *gEfiShellProtocol;\r
+EFI_SHELL_PARAMETERS_PROTOCOL   *gEfiShellParametersProtocol;\r
+EFI_HANDLE                      mEfiShellEnvironment2Handle;\r
+FILE_HANDLE_FUNCTION_MAP        FileFunctionMap;\r
+EFI_UNICODE_COLLATION_PROTOCOL  *mUnicodeCollationProtocol;\r
+\r
+/**\r
+  Return a clean, fully-qualified version of an input path.  If the return value\r
+  is non-NULL the caller must free the memory when it is no longer needed.\r
+\r
+  If asserts are disabled, and if the input parameter is NULL, NULL is returned.\r
+\r
+  If there is not enough memory available to create the fully-qualified path or\r
+  a copy of the input path, NULL is returned.\r
+\r
+  If there is no working directory, a clean copy of Path is returned.\r
+\r
+  Otherwise, the current file system or working directory (as appropriate) is\r
+  prepended to Path and the resulting path is cleaned and returned.\r
+\r
+  NOTE: If the input path is an empty string, then the current working directory\r
+  (if it exists) is returned.  In other words, an empty input path is treated\r
+  exactly the same as ".".\r
+\r
+  @param[in] Path  A pointer to some file or directory path.\r
+\r
+  @retval NULL          The input path is NULL or out of memory.\r
+\r
+  @retval non-NULL      A pointer to a clean, fully-qualified version of Path.\r
+                        If there is no working directory, then a pointer to a\r
+                        clean, but not necessarily fully-qualified version of\r
+                        Path.  The caller must free this memory when it is no\r
+                        longer needed.\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+FullyQualifyPath (\r
+  IN     CONST CHAR16  *Path\r
+  )\r
+{\r
+  CONST CHAR16  *WorkingPath;\r
+  CONST CHAR16  *InputPath;\r
+  CHAR16        *CharPtr;\r
+  CHAR16        *InputFileSystem;\r
+  UINTN         FileSystemCharCount;\r
+  CHAR16        *FullyQualifiedPath;\r
+  UINTN         Size;\r
+\r
+  FullyQualifiedPath = NULL;\r
+\r
+  ASSERT (Path != NULL);\r
+  //\r
+  // Handle erroneous input when asserts are disabled.\r
+  //\r
+  if (Path == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // In paths that contain ":", like fs0:dir/file.ext and fs2:\fqpath\file.ext,\r
+  // we  have to consider the file system part separately from the "path" part.\r
+  // If there is a file system in the path, we have to get the current working\r
+  // directory for that file system. Then we need to use the part of the path\r
+  // following the ":".  If a path does not contain ":", we use it as given.\r
+  //\r
+  InputPath = StrStr (Path, L":");\r
+  if (InputPath != NULL) {\r
+    InputPath++;\r
+    FileSystemCharCount = ((UINTN)InputPath - (UINTN)Path + sizeof (CHAR16)) / sizeof (CHAR16);\r
+    InputFileSystem     = AllocateCopyPool (FileSystemCharCount * sizeof (CHAR16), Path);\r
+    if (InputFileSystem != NULL) {\r
+      InputFileSystem[FileSystemCharCount - 1] = CHAR_NULL;\r
+    }\r
+\r
+    WorkingPath = ShellGetCurrentDir (InputFileSystem);\r
+    SHELL_FREE_NON_NULL (InputFileSystem);\r
+  } else {\r
+    InputPath   = Path;\r
+    WorkingPath = ShellGetEnvironmentVariable (L"cwd");\r
+  }\r
+\r
+  if (WorkingPath == NULL) {\r
+    //\r
+    // With no working directory, all we can do is copy and clean the input path.\r
+    //\r
+    FullyQualifiedPath = AllocateCopyPool (StrSize (Path), Path);\r
+  } else {\r
+    //\r
+    // Allocate space for both strings plus one more character.\r
+    //\r
+    Size               = StrSize (WorkingPath) + StrSize (InputPath);\r
+    FullyQualifiedPath = AllocateZeroPool (Size);\r
+    if (FullyQualifiedPath == NULL) {\r
+      //\r
+      // Try to copy and clean just the input. No harm if not enough memory.\r
+      //\r
+      FullyQualifiedPath = AllocateCopyPool (StrSize (Path), Path);\r
+    } else {\r
+      if ((*InputPath == L'\\') || (*InputPath == L'/')) {\r
+        //\r
+        // Absolute path: start with the current working directory, then\r
+        // truncate the new path after the file system part.\r
+        //\r
+        StrCpyS (FullyQualifiedPath, Size/sizeof (CHAR16), WorkingPath);\r
+        CharPtr = StrStr (FullyQualifiedPath, L":");\r
+        if (CharPtr != NULL) {\r
+          *(CharPtr + 1) = CHAR_NULL;\r
+        }\r
+      } else {\r
+        //\r
+        // Relative path: start with the working directory and append "\".\r
+        //\r
+        StrCpyS (FullyQualifiedPath, Size/sizeof (CHAR16), WorkingPath);\r
+        StrCatS (FullyQualifiedPath, Size/sizeof (CHAR16), L"\\");\r
+      }\r
+\r
+      //\r
+      // Now append the absolute or relative path.\r
+      //\r
+      StrCatS (FullyQualifiedPath, Size/sizeof (CHAR16), InputPath);\r
+    }\r
+  }\r
+\r
+  PathCleanUpDirectories (FullyQualifiedPath);\r
+\r
+  return FullyQualifiedPath;\r
+}\r
 \r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
 \r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
@@ -51,10 +168,10 @@ FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;
 BOOLEAN\r
 EFIAPI\r
 ShellIsHexaDecimalDigitCharacter (\r
 BOOLEAN\r
 EFIAPI\r
 ShellIsHexaDecimalDigitCharacter (\r
-  IN      CHAR16                    Char\r
+  IN      CHAR16  Char\r
   )\r
 {\r
   )\r
 {\r
-  return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));\r
+  return (BOOLEAN)((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -74,10 +191,10 @@ ShellIsHexaDecimalDigitCharacter (
 BOOLEAN\r
 EFIAPI\r
 ShellIsDecimalDigitCharacter (\r
 BOOLEAN\r
 EFIAPI\r
 ShellIsDecimalDigitCharacter (\r
-  IN      CHAR16                    Char\r
+  IN      CHAR16  Char\r
   )\r
 {\r
   )\r
 {\r
-  return (BOOLEAN) (Char >= L'0' && Char <= L'9');\r
+  return (BOOLEAN)(Char >= L'0' && Char <= L'9');\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -88,9 +205,8 @@ ShellIsDecimalDigitCharacter (
   @retval EFI_OUT_OF_RESOURCES    Memory allocation failed.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_OUT_OF_RESOURCES    Memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ShellFindSE2 (\r
 ShellFindSE2 (\r
-  IN EFI_HANDLE        ImageHandle\r
+  IN EFI_HANDLE  ImageHandle\r
   )\r
 {\r
   EFI_STATUS  Status;\r
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -99,66 +215,74 @@ ShellFindSE2 (
   UINTN       HandleIndex;\r
 \r
   BufferSize = 0;\r
   UINTN       HandleIndex;\r
 \r
   BufferSize = 0;\r
-  Buffer = NULL;\r
-  Status = gBS->OpenProtocol(ImageHandle,\r
-                             &gEfiShellEnvironment2Guid,\r
-                             (VOID **)&mEfiShellEnvironment2,\r
-                             ImageHandle,\r
-                             NULL,\r
-                             EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                            );\r
+  Buffer     = NULL;\r
+  Status     = gBS->OpenProtocol (\r
+                      ImageHandle,\r
+                      &gEfiShellEnvironment2Guid,\r
+                      (VOID **)&mEfiShellEnvironment2,\r
+                      ImageHandle,\r
+                      NULL,\r
+                      EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                      );\r
   //\r
   // look for the mEfiShellEnvironment2 protocol at a higher level\r
   //\r
   //\r
   // look for the mEfiShellEnvironment2 protocol at a higher level\r
   //\r
-  if (EFI_ERROR (Status) || !(CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid))){\r
+  if (EFI_ERROR (Status) || !(CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid))) {\r
     //\r
     // figure out how big of a buffer we need.\r
     //\r
     //\r
     // figure out how big of a buffer we need.\r
     //\r
-    Status = gBS->LocateHandle (ByProtocol,\r
-                                &gEfiShellEnvironment2Guid,\r
-                                NULL, // ignored for ByProtocol\r
-                                &BufferSize,\r
-                                Buffer\r
-                               );\r
+    Status = gBS->LocateHandle (\r
+                    ByProtocol,\r
+                    &gEfiShellEnvironment2Guid,\r
+                    NULL,             // ignored for ByProtocol\r
+                    &BufferSize,\r
+                    Buffer\r
+                    );\r
     //\r
     // maybe it's not there???\r
     //\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
     //\r
     // maybe it's not there???\r
     //\r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
-      Buffer = (EFI_HANDLE*)AllocateZeroPool(BufferSize);\r
+      Buffer = (EFI_HANDLE *)AllocateZeroPool (BufferSize);\r
       if (Buffer == NULL) {\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       if (Buffer == NULL) {\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      Status = gBS->LocateHandle (ByProtocol,\r
-                                  &gEfiShellEnvironment2Guid,\r
-                                  NULL, // ignored for ByProtocol\r
-                                  &BufferSize,\r
-                                  Buffer\r
-                                 );\r
+\r
+      Status = gBS->LocateHandle (\r
+                      ByProtocol,\r
+                      &gEfiShellEnvironment2Guid,\r
+                      NULL,             // ignored for ByProtocol\r
+                      &BufferSize,\r
+                      Buffer\r
+                      );\r
     }\r
     }\r
-    if (!EFI_ERROR (Status) && Buffer != NULL) {\r
+\r
+    if (!EFI_ERROR (Status) && (Buffer != NULL)) {\r
       //\r
       // now parse the list of returned handles\r
       //\r
       Status = EFI_NOT_FOUND;\r
       //\r
       // now parse the list of returned handles\r
       //\r
       Status = EFI_NOT_FOUND;\r
-      for (HandleIndex = 0; HandleIndex < (BufferSize/sizeof(Buffer[0])); HandleIndex++) {\r
-        Status = gBS->OpenProtocol(Buffer[HandleIndex],\r
-                                   &gEfiShellEnvironment2Guid,\r
-                                   (VOID **)&mEfiShellEnvironment2,\r
-                                   ImageHandle,\r
-                                   NULL,\r
-                                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                                  );\r
-         if (CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid)) {\r
+      for (HandleIndex = 0; HandleIndex < (BufferSize/sizeof (Buffer[0])); HandleIndex++) {\r
+        Status = gBS->OpenProtocol (\r
+                        Buffer[HandleIndex],\r
+                        &gEfiShellEnvironment2Guid,\r
+                        (VOID **)&mEfiShellEnvironment2,\r
+                        ImageHandle,\r
+                        NULL,\r
+                        EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                        );\r
+        if (CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid)) {\r
           mEfiShellEnvironment2Handle = Buffer[HandleIndex];\r
           mEfiShellEnvironment2Handle = Buffer[HandleIndex];\r
-          Status = EFI_SUCCESS;\r
+          Status                      = EFI_SUCCESS;\r
           break;\r
         }\r
       }\r
     }\r
   }\r
           break;\r
         }\r
       }\r
     }\r
   }\r
+\r
   if (Buffer != NULL) {\r
     FreePool (Buffer);\r
   }\r
   if (Buffer != NULL) {\r
     FreePool (Buffer);\r
   }\r
+\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -172,7 +296,6 @@ ShellFindSE2 (
   @retval EFI_SUCCESS   The operationw as successful.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS   The operationw as successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 ShellLibConstructorWorker (\r
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
 ShellLibConstructorWorker (\r
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
@@ -180,69 +303,81 @@ ShellLibConstructorWorker (
 {\r
   EFI_STATUS  Status;\r
 \r
 {\r
   EFI_STATUS  Status;\r
 \r
-  //\r
-  // UEFI 2.0 shell interfaces (used preferentially)\r
-  //\r
-  Status = gBS->OpenProtocol(\r
-    ImageHandle,\r
-    &gEfiShellProtocolGuid,\r
-    (VOID **)&gEfiShellProtocol,\r
-    ImageHandle,\r
-    NULL,\r
-    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-   );\r
-  if (EFI_ERROR(Status)) {\r
+  if (gEfiShellProtocol == NULL) {\r
     //\r
     //\r
-    // Search for the shell protocol\r
+    // UEFI 2.0 shell interfaces (used preferentially)\r
     //\r
     //\r
-    Status = gBS->LocateProtocol(\r
-      &gEfiShellProtocolGuid,\r
-      NULL,\r
-      (VOID **)&gEfiShellProtocol\r
-     );\r
-    if (EFI_ERROR(Status)) {\r
-      gEfiShellProtocol = NULL;\r
+    Status = gBS->OpenProtocol (\r
+                    ImageHandle,\r
+                    &gEfiShellProtocolGuid,\r
+                    (VOID **)&gEfiShellProtocol,\r
+                    ImageHandle,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Search for the shell protocol\r
+      //\r
+      Status = gBS->LocateProtocol (\r
+                      &gEfiShellProtocolGuid,\r
+                      NULL,\r
+                      (VOID **)&gEfiShellProtocol\r
+                      );\r
+      if (EFI_ERROR (Status)) {\r
+        gEfiShellProtocol = NULL;\r
+      }\r
     }\r
   }\r
     }\r
   }\r
-  Status = gBS->OpenProtocol(\r
-    ImageHandle,\r
-    &gEfiShellParametersProtocolGuid,\r
-    (VOID **)&gEfiShellParametersProtocol,\r
-    ImageHandle,\r
-    NULL,\r
-    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-   );\r
-  if (EFI_ERROR(Status)) {\r
-    gEfiShellParametersProtocol = NULL;\r
+\r
+  if (gEfiShellParametersProtocol == NULL) {\r
+    Status = gBS->OpenProtocol (\r
+                    ImageHandle,\r
+                    &gEfiShellParametersProtocolGuid,\r
+                    (VOID **)&gEfiShellParametersProtocol,\r
+                    ImageHandle,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gEfiShellParametersProtocol = NULL;\r
+    }\r
   }\r
 \r
   }\r
 \r
-  if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) {\r
+  if (gEfiShellProtocol == NULL) {\r
     //\r
     // Moved to seperate function due to complexity\r
     //\r
     //\r
     // Moved to seperate function due to complexity\r
     //\r
-    Status = ShellFindSE2(ImageHandle);\r
+    Status = ShellFindSE2 (ImageHandle);\r
 \r
 \r
-    if (EFI_ERROR(Status)) {\r
-      DEBUG((DEBUG_ERROR, "Status: 0x%08x\r\n", Status));\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "Status: 0x%08x\r\n", Status));\r
       mEfiShellEnvironment2 = NULL;\r
     }\r
       mEfiShellEnvironment2 = NULL;\r
     }\r
-    Status = gBS->OpenProtocol(ImageHandle,\r
-                               &gEfiShellInterfaceGuid,\r
-                               (VOID **)&mEfiShellInterface,\r
-                               ImageHandle,\r
-                               NULL,\r
-                               EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                              );\r
-    if (EFI_ERROR(Status)) {\r
+\r
+    Status = gBS->OpenProtocol (\r
+                    ImageHandle,\r
+                    &gEfiShellInterfaceGuid,\r
+                    (VOID **)&mEfiShellInterface,\r
+                    ImageHandle,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
       mEfiShellInterface = NULL;\r
     }\r
   }\r
 \r
   //\r
       mEfiShellInterface = NULL;\r
     }\r
   }\r
 \r
   //\r
-  // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
+  // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol\r
+  //  or UEFI Shell's Shell protocol.\r
+  // When ShellLib is linked to a driver producing DynamicCommand protocol,\r
+  //  ShellParameters protocol is set by DynamicCommand.Handler().\r
   //\r
   //\r
-  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface          != NULL) ||\r
-      (gEfiShellProtocol     != NULL && gEfiShellParametersProtocol != NULL)   ) {\r
+  if (((mEfiShellEnvironment2 != NULL) && (mEfiShellInterface != NULL)) ||\r
+      (gEfiShellProtocol     != NULL)\r
+      )\r
+  {\r
     if (gEfiShellProtocol != NULL) {\r
       FileFunctionMap.GetFileInfo     = gEfiShellProtocol->GetFileInfo;\r
       FileFunctionMap.SetFileInfo     = gEfiShellProtocol->SetFileInfo;\r
     if (gEfiShellProtocol != NULL) {\r
       FileFunctionMap.GetFileInfo     = gEfiShellProtocol->GetFileInfo;\r
       FileFunctionMap.SetFileInfo     = gEfiShellProtocol->SetFileInfo;\r
@@ -266,10 +401,13 @@ ShellLibConstructorWorker (
       FileFunctionMap.FlushFile       = (EFI_SHELL_FLUSH_FILE)FileHandleFlush;\r
       FileFunctionMap.GetFileSize     = (EFI_SHELL_GET_FILE_SIZE)FileHandleGetSize;\r
     }\r
       FileFunctionMap.FlushFile       = (EFI_SHELL_FLUSH_FILE)FileHandleFlush;\r
       FileFunctionMap.GetFileSize     = (EFI_SHELL_GET_FILE_SIZE)FileHandleGetSize;\r
     }\r
+\r
     return (EFI_SUCCESS);\r
   }\r
     return (EFI_SUCCESS);\r
   }\r
+\r
   return (EFI_NOT_FOUND);\r
 }\r
   return (EFI_NOT_FOUND);\r
 }\r
+\r
 /**\r
   Constructor for the Shell library.\r
 \r
 /**\r
   Constructor for the Shell library.\r
 \r
@@ -293,15 +431,16 @@ ShellLibConstructor (
   gEfiShellParametersProtocol = NULL;\r
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
   gEfiShellParametersProtocol = NULL;\r
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
+  mUnicodeCollationProtocol   = NULL;\r
 \r
   //\r
   // verify that auto initialize is not set false\r
   //\r
 \r
   //\r
   // verify that auto initialize is not set false\r
   //\r
-  if (PcdGetBool(PcdShellLibAutoInitialize) == 0) {\r
+  if (PcdGetBool (PcdShellLibAutoInitialize) == 0) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
     return (EFI_SUCCESS);\r
   }\r
 \r
-  return (ShellLibConstructorWorker(ImageHandle, SystemTable));\r
+  return (ShellLibConstructorWorker (ImageHandle, SystemTable));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -320,35 +459,56 @@ ShellLibDestructor (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   if (mEfiShellEnvironment2 != NULL) {\r
   if (mEfiShellEnvironment2 != NULL) {\r
-    gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
-                       &gEfiShellEnvironment2Guid,\r
-                       ImageHandle,\r
-                       NULL);\r
-    mEfiShellEnvironment2 = NULL;\r
+    Status = gBS->CloseProtocol (\r
+                    mEfiShellEnvironment2Handle == NULL ? ImageHandle : mEfiShellEnvironment2Handle,\r
+                    &gEfiShellEnvironment2Guid,\r
+                    ImageHandle,\r
+                    NULL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      mEfiShellEnvironment2       = NULL;\r
+      mEfiShellEnvironment2Handle = NULL;\r
+    }\r
   }\r
   }\r
+\r
   if (mEfiShellInterface != NULL) {\r
   if (mEfiShellInterface != NULL) {\r
-    gBS->CloseProtocol(ImageHandle,\r
-                       &gEfiShellInterfaceGuid,\r
-                       ImageHandle,\r
-                       NULL);\r
-    mEfiShellInterface = NULL;\r
+    Status = gBS->CloseProtocol (\r
+                    ImageHandle,\r
+                    &gEfiShellInterfaceGuid,\r
+                    ImageHandle,\r
+                    NULL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      mEfiShellInterface = NULL;\r
+    }\r
   }\r
   }\r
+\r
   if (gEfiShellProtocol != NULL) {\r
   if (gEfiShellProtocol != NULL) {\r
-    gBS->CloseProtocol(ImageHandle,\r
-                       &gEfiShellProtocolGuid,\r
-                       ImageHandle,\r
-                       NULL);\r
-    gEfiShellProtocol = NULL;\r
+    Status = gBS->CloseProtocol (\r
+                    ImageHandle,\r
+                    &gEfiShellProtocolGuid,\r
+                    ImageHandle,\r
+                    NULL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      gEfiShellProtocol = NULL;\r
+    }\r
   }\r
   }\r
+\r
   if (gEfiShellParametersProtocol != NULL) {\r
   if (gEfiShellParametersProtocol != NULL) {\r
-    gBS->CloseProtocol(ImageHandle,\r
-                       &gEfiShellParametersProtocolGuid,\r
-                       ImageHandle,\r
-                       NULL);\r
-    gEfiShellParametersProtocol = NULL;\r
+    Status = gBS->CloseProtocol (\r
+                    ImageHandle,\r
+                    &gEfiShellParametersProtocolGuid,\r
+                    ImageHandle,\r
+                    NULL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      gEfiShellParametersProtocol = NULL;\r
+    }\r
   }\r
   }\r
-  mEfiShellEnvironment2Handle = NULL;\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
@@ -369,24 +529,28 @@ ShellLibDestructor (
 EFI_STATUS\r
 EFIAPI\r
 ShellInitialize (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellInitialize (\r
+  VOID\r
   )\r
 {\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
+\r
   //\r
   // if auto initialize is not false then skip\r
   //\r
   //\r
   // if auto initialize is not false then skip\r
   //\r
-  if (PcdGetBool(PcdShellLibAutoInitialize) != 0) {\r
+  if (PcdGetBool (PcdShellLibAutoInitialize) != 0) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
   //\r
   // deinit the current stuff\r
   //\r
     return (EFI_SUCCESS);\r
   }\r
 \r
   //\r
   // deinit the current stuff\r
   //\r
-  ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST));\r
+  Status = ShellLibDestructor (gImageHandle, gST);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // init the new stuff\r
   //\r
 \r
   //\r
   // init the new stuff\r
   //\r
-  return (ShellLibConstructorWorker(gImageHandle, gST));\r
+  return (ShellLibConstructorWorker (gImageHandle, gST));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -403,13 +567,13 @@ ShellInitialize (
 \r
   @return the information about the file\r
 **/\r
 \r
   @return the information about the file\r
 **/\r
-EFI_FILE_INFO*\r
+EFI_FILE_INFO *\r
 EFIAPI\r
 ShellGetFileInfo (\r
 EFIAPI\r
 ShellGetFileInfo (\r
-  IN SHELL_FILE_HANDLE                     FileHandle\r
+  IN SHELL_FILE_HANDLE  FileHandle\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.GetFileInfo(FileHandle));\r
+  return (FileFunctionMap.GetFileInfo (FileHandle));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -434,62 +598,56 @@ ShellGetFileInfo (
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFileInfo (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFileInfo (\r
-  IN SHELL_FILE_HANDLE                    FileHandle,\r
-  IN EFI_FILE_INFO              *FileInfo\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
+  IN EFI_FILE_INFO      *FileInfo\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.SetFileInfo(FileHandle, FileInfo));\r
+  return (FileFunctionMap.SetFileInfo (FileHandle, FileInfo));\r
 }\r
 \r
 }\r
 \r
-  /**\r
-  This function will open a file or directory referenced by DevicePath.\r
-\r
-  This function opens a file with the open mode according to the file path. The\r
-  Attributes is valid only for EFI_FILE_MODE_CREATE.\r
-\r
-  @param  FilePath        on input the device path to the file.  On output\r
-                          the remaining device path.\r
-  @param  DeviceHandle    pointer to the system device handle.\r
-  @param  FileHandle      pointer to the file handle.\r
-  @param  OpenMode        the mode to open the file with.\r
-  @param  Attributes      the file's file attributes.\r
-\r
-  @retval EFI_SUCCESS           The information was set.\r
-  @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED       Could not open the file path.\r
-  @retval EFI_NOT_FOUND         The specified file could not be found on the\r
-                                device or the file system could not be found on\r
-                                the device.\r
-  @retval EFI_NO_MEDIA          The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
-                                medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR      The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED     The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
-                                file.\r
-  @retval EFI_VOLUME_FULL       The volume is full.\r
+/**\r
+This function will open a file or directory referenced by DevicePath.\r
+\r
+This function opens a file with the open mode according to the file path. The\r
+Attributes is valid only for EFI_FILE_MODE_CREATE.\r
+\r
+@param  FilePath        on input the device path to the file.  On output\r
+                        the remaining device path.\r
+@param  FileHandle      pointer to the file handle.\r
+@param  OpenMode        the mode to open the file with.\r
+@param  Attributes      the file's file attributes.\r
+\r
+@retval EFI_SUCCESS           The information was set.\r
+@retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
+@retval EFI_UNSUPPORTED       Could not open the file path.\r
+@retval EFI_NOT_FOUND         The specified file could not be found on the\r
+                              device or the file system could not be found on\r
+                              the device.\r
+@retval EFI_NO_MEDIA          The device has no medium.\r
+@retval EFI_MEDIA_CHANGED     The device has a different medium in it or the\r
+                              medium is no longer supported.\r
+@retval EFI_DEVICE_ERROR      The device reported an error.\r
+@retval EFI_VOLUME_CORRUPTED  The file system structures are corrupted.\r
+@retval EFI_WRITE_PROTECTED   The file or medium is write protected.\r
+@retval EFI_ACCESS_DENIED     The file was opened read only.\r
+@retval EFI_OUT_OF_RESOURCES  Not enough resources were available to open the\r
+                              file.\r
+@retval EFI_VOLUME_FULL       The volume is full.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellOpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL     **FilePath,\r
-  OUT EFI_HANDLE                      *DeviceHandle,\r
-  OUT SHELL_FILE_HANDLE               *FileHandle,\r
-  IN UINT64                           OpenMode,\r
-  IN UINT64                           Attributes\r
+ShellOpenFileByDevicePath (\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  **FilePath,\r
+  OUT SHELL_FILE_HANDLE            *FileHandle,\r
+  IN UINT64                        OpenMode,\r
+  IN UINT64                        Attributes\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16                          *FileName;\r
-  EFI_STATUS                      Status;\r
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
-  EFI_FILE_PROTOCOL               *Handle1;\r
-  EFI_FILE_PROTOCOL               *Handle2;\r
-  CHAR16                          *FnafPathName;\r
-  UINTN                           PathLen;\r
-\r
-  if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
+  CHAR16             *FileName;\r
+  EFI_STATUS         Status;\r
+  EFI_FILE_PROTOCOL  *File;\r
+\r
+  if ((FilePath == NULL) || (FileHandle == NULL)) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
@@ -500,130 +658,28 @@ ShellOpenFileByDevicePath(
     //\r
     // use UEFI Shell 2.0 method.\r
     //\r
     //\r
     // use UEFI Shell 2.0 method.\r
     //\r
-    FileName = gEfiShellProtocol->GetFilePathFromDevicePath(*FilePath);\r
+    FileName = gEfiShellProtocol->GetFilePathFromDevicePath (*FilePath);\r
     if (FileName == NULL) {\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
     if (FileName == NULL) {\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
-    Status = ShellOpenFileByName(FileName, FileHandle, OpenMode, Attributes);\r
-    FreePool(FileName);\r
+\r
+    Status = ShellOpenFileByName (FileName, FileHandle, OpenMode, Attributes);\r
+    FreePool (FileName);\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-\r
   //\r
   // use old shell method.\r
   //\r
   //\r
   // use old shell method.\r
   //\r
-  Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,\r
-                                  FilePath,\r
-                                  DeviceHandle);\r
+  Status = EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attributes);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
-  Status = gBS->OpenProtocol(*DeviceHandle,\r
-                             &gEfiSimpleFileSystemProtocolGuid,\r
-                             (VOID**)&EfiSimpleFileSystemProtocol,\r
-                             gImageHandle,\r
-                             NULL,\r
-                             EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-  Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, &Handle1);\r
-  if (EFI_ERROR (Status)) {\r
-    FileHandle = NULL;\r
-    return Status;\r
-  }\r
-\r
-  //\r
-  // go down directories one node at a time.\r
-  //\r
-  while (!IsDevicePathEnd (*FilePath)) {\r
-    //\r
-    // For file system access each node should be a file path component\r
-    //\r
-    if (DevicePathType    (*FilePath) != MEDIA_DEVICE_PATH ||\r
-        DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP\r
-       ) {\r
-      FileHandle = NULL;\r
-      return (EFI_INVALID_PARAMETER);\r
-    }\r
-    //\r
-    // Open this file path node\r
-    //\r
-    Handle2  = Handle1;\r
-    Handle1 = NULL;\r
-\r
-    //\r
-    // File Name Alignment Fix (FNAF)\r
-    // Handle2->Open may be incapable of handling a unaligned CHAR16 data.\r
-    // The structure pointed to by FilePath may be not CHAR16 aligned.\r
-    // This code copies the potentially unaligned PathName data from the\r
-    // FilePath structure to the aligned FnafPathName for use in the\r
-    // calls to Handl2->Open.\r
-    //\r
-\r
-    //\r
-    // Determine length of PathName, in bytes.\r
-    //\r
-    PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
-\r
-    //\r
-    // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment\r
-    // Copy bytes from possibly unaligned location to aligned location\r
-    //\r
-    FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);\r
-    if (FnafPathName == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-\r
-    //\r
-    // Try to test opening an existing file\r
-    //\r
-    Status = Handle2->Open (\r
-                          Handle2,\r
-                          &Handle1,\r
-                          FnafPathName,\r
-                          OpenMode &~EFI_FILE_MODE_CREATE,\r
-                          0\r
-                         );\r
-\r
-    //\r
-    // see if the error was that it needs to be created\r
-    //\r
-    if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {\r
-      Status = Handle2->Open (\r
-                            Handle2,\r
-                            &Handle1,\r
-                            FnafPathName,\r
-                            OpenMode,\r
-                            Attributes\r
-                           );\r
-    }\r
-\r
-    //\r
-    // Free the alignment buffer\r
-    //\r
-    FreePool(FnafPathName);\r
-\r
-    //\r
-    // Close the last node\r
-    //\r
-    Handle2->Close (Handle2);\r
-\r
-    if (EFI_ERROR(Status)) {\r
-      return (Status);\r
-    }\r
-\r
-    //\r
-    // Get the next node\r
-    //\r
-    *FilePath = NextDevicePathNode (*FilePath);\r
-  }\r
 \r
   //\r
   // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!\r
   //\r
 \r
   //\r
   // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!\r
   //\r
-  *FileHandle = (VOID*)Handle1;\r
+  *FileHandle = (VOID *)File;\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -660,62 +716,113 @@ ShellOpenFileByDevicePath(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellOpenFileByName(\r
-  IN CONST CHAR16               *FileName,\r
-  OUT SHELL_FILE_HANDLE         *FileHandle,\r
-  IN UINT64                     OpenMode,\r
-  IN UINT64                     Attributes\r
+ShellOpenFileByName (\r
+  IN CONST CHAR16        *FileName,\r
+  OUT SHELL_FILE_HANDLE  *FileHandle,\r
+  IN UINT64              OpenMode,\r
+  IN UINT64              Attributes\r
   )\r
 {\r
   )\r
 {\r
-  EFI_HANDLE                    DeviceHandle;\r
-  EFI_DEVICE_PATH_PROTOCOL      *FilePath;\r
-  EFI_STATUS                    Status;\r
-  EFI_FILE_INFO                 *FileInfo;\r
+  EFI_DEVICE_PATH_PROTOCOL  *FilePath;\r
+  EFI_STATUS                Status;\r
+  EFI_FILE_INFO             *FileInfo;\r
+  CHAR16                    *FileNameCopy;\r
+  EFI_STATUS                Status2;\r
 \r
   //\r
   // ASSERT if FileName is NULL\r
   //\r
 \r
   //\r
   // ASSERT if FileName is NULL\r
   //\r
-  ASSERT(FileName != NULL);\r
+  ASSERT (FileName != NULL);\r
 \r
   if (FileName == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
   if (gEfiShellProtocol != NULL) {\r
 \r
   if (FileName == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \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
+    if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) {\r
+      //\r
+      // Create only a directory\r
+      //\r
+      if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
+        return ShellCreateDirectory (FileName, FileHandle);\r
+      }\r
+\r
+      //\r
+      // Create the directory to create the file in\r
+      //\r
+      FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName);\r
+      if (FileNameCopy == NULL) {\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
+\r
+      PathCleanUpDirectories (FileNameCopy);\r
+      if (PathRemoveLastItem (FileNameCopy)) {\r
+        if (!EFI_ERROR (ShellCreateDirectory (FileNameCopy, FileHandle))) {\r
+          ShellCloseFile (FileHandle);\r
+        }\r
+      }\r
+\r
+      SHELL_FREE_NON_NULL (FileNameCopy);\r
     }\r
     }\r
+\r
     //\r
     //\r
-    // Use UEFI Shell 2.0 method\r
+    // Use UEFI Shell 2.0 method to create the file\r
     //\r
     //\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
-      FileInfo = FileFunctionMap.GetFileInfo(*FileHandle);\r
-      ASSERT(FileInfo != NULL);\r
+    Status = gEfiShellProtocol->OpenFileByName (\r
+                                  FileName,\r
+                                  FileHandle,\r
+                                  OpenMode\r
+                                  );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    if (mUnicodeCollationProtocol == NULL) {\r
+      Status = gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID **)&mUnicodeCollationProtocol);\r
+      if (EFI_ERROR (Status)) {\r
+        gEfiShellProtocol->CloseFile (*FileHandle);\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    if ((mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16 *)FileName, L"NUL") != 0) &&\r
+        (mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16 *)FileName, L"NULL") != 0) &&\r
+        !EFI_ERROR (Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0))\r
+    {\r
+      FileInfo = FileFunctionMap.GetFileInfo (*FileHandle);\r
+      ASSERT (FileInfo != NULL);\r
       FileInfo->Attribute = Attributes;\r
       FileInfo->Attribute = Attributes;\r
-      Status = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo);\r
-      FreePool(FileInfo);\r
+      Status2             = FileFunctionMap.SetFileInfo (*FileHandle, FileInfo);\r
+      FreePool (FileInfo);\r
+      if (EFI_ERROR (Status2)) {\r
+        gEfiShellProtocol->CloseFile (*FileHandle);\r
+      }\r
+\r
+      Status = Status2;\r
     }\r
     }\r
+\r
     return (Status);\r
   }\r
     return (Status);\r
   }\r
+\r
   //\r
   // Using EFI Shell version\r
   // this means convert name to path and call that function\r
   // since this will use EFI method again that will open it.\r
   //\r
   //\r
   // Using EFI Shell version\r
   // this means convert name to path and call that function\r
   // since this will use EFI method again that will open it.\r
   //\r
-  ASSERT(mEfiShellEnvironment2 != NULL);\r
-  FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName);\r
+  ASSERT (mEfiShellEnvironment2 != NULL);\r
+  FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16 *)FileName);\r
   if (FilePath != NULL) {\r
   if (FilePath != NULL) {\r
-    return (ShellOpenFileByDevicePath(&FilePath,\r
-                                      &DeviceHandle,\r
-                                      FileHandle,\r
-                                      OpenMode,\r
-                                      Attributes));\r
+    return (ShellOpenFileByDevicePath (\r
+              &FilePath,\r
+              FileHandle,\r
+              OpenMode,\r
+              Attributes\r
+              ));\r
   }\r
   }\r
+\r
   return (EFI_DEVICE_ERROR);\r
 }\r
   return (EFI_DEVICE_ERROR);\r
 }\r
+\r
 /**\r
   This function create a directory\r
 \r
 /**\r
   This function create a directory\r
 \r
@@ -746,25 +853,27 @@ ShellOpenFileByName(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellCreateDirectory(\r
-  IN CONST CHAR16             *DirectoryName,\r
-  OUT SHELL_FILE_HANDLE                  *FileHandle\r
+ShellCreateDirectory (\r
+  IN CONST CHAR16        *DirectoryName,\r
+  OUT SHELL_FILE_HANDLE  *FileHandle\r
   )\r
 {\r
   if (gEfiShellProtocol != NULL) {\r
     //\r
     // Use UEFI Shell 2.0 method\r
     //\r
   )\r
 {\r
   if (gEfiShellProtocol != NULL) {\r
     //\r
     // Use UEFI Shell 2.0 method\r
     //\r
-    return (gEfiShellProtocol->CreateFile(DirectoryName,\r
-                          EFI_FILE_DIRECTORY,\r
-                          FileHandle\r
-                         ));\r
+    return (gEfiShellProtocol->CreateFile (\r
+                                 DirectoryName,\r
+                                 EFI_FILE_DIRECTORY,\r
+                                 FileHandle\r
+                                 ));\r
   } else {\r
   } else {\r
-    return (ShellOpenFileByName(DirectoryName,\r
-                                FileHandle,\r
-                                EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,\r
-                                EFI_FILE_DIRECTORY\r
-                               ));\r
+    return (ShellOpenFileByName (\r
+              DirectoryName,\r
+              FileHandle,\r
+              EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,\r
+              EFI_FILE_DIRECTORY\r
+              ));\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r
@@ -799,16 +908,15 @@ ShellCreateDirectory(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellReadFile(\r
-  IN SHELL_FILE_HANDLE                     FileHandle,\r
-  IN OUT UINTN                  *BufferSize,\r
-  OUT VOID                      *Buffer\r
+ShellReadFile (\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
+  IN OUT UINTN          *BufferSize,\r
+  OUT VOID              *Buffer\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.ReadFile(FileHandle, BufferSize, Buffer));\r
+  return (FileFunctionMap.ReadFile (FileHandle, BufferSize, Buffer));\r
 }\r
 \r
 }\r
 \r
-\r
 /**\r
   Write data to a file.\r
 \r
 /**\r
   Write data to a file.\r
 \r
@@ -835,13 +943,13 @@ ShellReadFile(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellWriteFile(\r
-  IN SHELL_FILE_HANDLE          FileHandle,\r
-  IN OUT UINTN                  *BufferSize,\r
-  IN VOID                       *Buffer\r
+ShellWriteFile (\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
+  IN OUT UINTN          *BufferSize,\r
+  IN VOID               *Buffer\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.WriteFile(FileHandle, BufferSize, Buffer));\r
+  return (FileFunctionMap.WriteFile (FileHandle, BufferSize, Buffer));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -858,10 +966,10 @@ ShellWriteFile(
 EFI_STATUS\r
 EFIAPI\r
 ShellCloseFile (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellCloseFile (\r
-  IN SHELL_FILE_HANDLE                     *FileHandle\r
+  IN SHELL_FILE_HANDLE  *FileHandle\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.CloseFile(*FileHandle));\r
+  return (FileFunctionMap.CloseFile (*FileHandle));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -881,10 +989,10 @@ ShellCloseFile (
 EFI_STATUS\r
 EFIAPI\r
 ShellDeleteFile (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellDeleteFile (\r
-  IN SHELL_FILE_HANDLE            *FileHandle\r
+  IN SHELL_FILE_HANDLE  *FileHandle\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.DeleteFile(*FileHandle));\r
+  return (FileFunctionMap.DeleteFile (*FileHandle));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -909,11 +1017,11 @@ ShellDeleteFile (
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFilePosition (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellSetFilePosition (\r
-  IN SHELL_FILE_HANDLE              FileHandle,\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
   IN UINT64             Position\r
   )\r
 {\r
   IN UINT64             Position\r
   )\r
 {\r
-  return (FileFunctionMap.SetFilePosition(FileHandle, Position));\r
+  return (FileFunctionMap.SetFilePosition (FileHandle, Position));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -934,12 +1042,13 @@ ShellSetFilePosition (
 EFI_STATUS\r
 EFIAPI\r
 ShellGetFilePosition (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellGetFilePosition (\r
-  IN SHELL_FILE_HANDLE                     FileHandle,\r
-  OUT UINT64                    *Position\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
+  OUT UINT64            *Position\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.GetFilePosition(FileHandle, Position));\r
+  return (FileFunctionMap.GetFilePosition (FileHandle, Position));\r
 }\r
 }\r
+\r
 /**\r
   Flushes data on a file\r
 \r
 /**\r
   Flushes data on a file\r
 \r
@@ -957,10 +1066,10 @@ ShellGetFilePosition (
 EFI_STATUS\r
 EFIAPI\r
 ShellFlushFile (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellFlushFile (\r
-  IN SHELL_FILE_HANDLE                     FileHandle\r
+  IN SHELL_FILE_HANDLE  FileHandle\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.FlushFile(FileHandle));\r
+  return (FileFunctionMap.FlushFile (FileHandle));\r
 }\r
 \r
 /** Retrieve first entry from a directory.\r
 }\r
 \r
 /** Retrieve first entry from a directory.\r
@@ -988,15 +1097,16 @@ ShellFlushFile (
 EFI_STATUS\r
 EFIAPI\r
 ShellFindFirstFile (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellFindFirstFile (\r
-  IN SHELL_FILE_HANDLE                     DirHandle,\r
-  OUT EFI_FILE_INFO             **Buffer\r
+  IN SHELL_FILE_HANDLE  DirHandle,\r
+  OUT EFI_FILE_INFO     **Buffer\r
   )\r
 {\r
   //\r
   // pass to file handle lib\r
   //\r
   )\r
 {\r
   //\r
   // pass to file handle lib\r
   //\r
-  return (FileHandleFindFirstFile(DirHandle, Buffer));\r
+  return (FileHandleFindFirstFile (DirHandle, Buffer));\r
 }\r
 }\r
+\r
 /** Retrieve next entries from a directory.\r
 \r
   To use this function, the caller must first call the ShellFindFirstFile()\r
 /** Retrieve next entries from a directory.\r
 \r
   To use this function, the caller must first call the ShellFindFirstFile()\r
@@ -1017,17 +1127,18 @@ ShellFindFirstFile (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellFindNextFile(\r
-  IN SHELL_FILE_HANDLE                      DirHandle,\r
-  OUT EFI_FILE_INFO              *Buffer,\r
-  OUT BOOLEAN                    *NoFile\r
+ShellFindNextFile (\r
+  IN SHELL_FILE_HANDLE  DirHandle,\r
+  OUT EFI_FILE_INFO     *Buffer,\r
+  OUT BOOLEAN           *NoFile\r
   )\r
 {\r
   //\r
   // pass to file handle lib\r
   //\r
   )\r
 {\r
   //\r
   // pass to file handle lib\r
   //\r
-  return (FileHandleFindNextFile(DirHandle, Buffer, NoFile));\r
+  return (FileHandleFindNextFile (DirHandle, Buffer, NoFile));\r
 }\r
 }\r
+\r
 /**\r
   Retrieve the size of a file.\r
 \r
 /**\r
   Retrieve the size of a file.\r
 \r
@@ -1046,12 +1157,13 @@ ShellFindNextFile(
 EFI_STATUS\r
 EFIAPI\r
 ShellGetFileSize (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellGetFileSize (\r
-  IN SHELL_FILE_HANDLE                     FileHandle,\r
-  OUT UINT64                    *Size\r
+  IN SHELL_FILE_HANDLE  FileHandle,\r
+  OUT UINT64            *Size\r
   )\r
 {\r
   )\r
 {\r
-  return (FileFunctionMap.GetFileSize(FileHandle, Size));\r
+  return (FileFunctionMap.GetFileSize (FileHandle, Size));\r
 }\r
 }\r
+\r
 /**\r
   Retrieves the status of the break execution flag\r
 \r
 /**\r
   Retrieves the status of the break execution flag\r
 \r
@@ -1062,7 +1174,7 @@ ShellGetFileSize (
 **/\r
 BOOLEAN\r
 EFIAPI\r
 **/\r
 BOOLEAN\r
 EFIAPI\r
-ShellGetExecutionBreakFlag(\r
+ShellGetExecutionBreakFlag (\r
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
@@ -1070,13 +1182,13 @@ ShellGetExecutionBreakFlag(
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
-\r
     //\r
     // We are using UEFI Shell 2.0; see if the event has been triggered\r
     //\r
     //\r
     // We are using UEFI Shell 2.0; see if the event has been triggered\r
     //\r
-    if (gBS->CheckEvent(gEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {\r
+    if (gBS->CheckEvent (gEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {\r
       return (FALSE);\r
     }\r
       return (FALSE);\r
     }\r
+\r
     return (TRUE);\r
   }\r
 \r
     return (TRUE);\r
   }\r
 \r
@@ -1084,11 +1196,12 @@ ShellGetExecutionBreakFlag(
   // using EFI Shell; call the function to check\r
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
   // using EFI Shell; call the function to check\r
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
-    return (mEfiShellEnvironment2->GetExecutionBreak());\r
+    return (mEfiShellEnvironment2->GetExecutionBreak ());\r
   }\r
 \r
   return (FALSE);\r
 }\r
   }\r
 \r
   return (FALSE);\r
 }\r
+\r
 /**\r
   return the value of an environment variable\r
 \r
 /**\r
   return the value of an environment variable\r
 \r
@@ -1100,28 +1213,29 @@ ShellGetExecutionBreakFlag(
   @retval NULL                  the named environment variable does not exist.\r
   @return != NULL               pointer to the value of the environment variable\r
 **/\r
   @retval NULL                  the named environment variable does not exist.\r
   @return != NULL               pointer to the value of the environment variable\r
 **/\r
-CONST CHAR16*\r
+CONST CHAR16 *\r
 EFIAPI\r
 ShellGetEnvironmentVariable (\r
 EFIAPI\r
 ShellGetEnvironmentVariable (\r
-  IN CONST CHAR16                *EnvKey\r
+  IN CONST CHAR16  *EnvKey\r
   )\r
 {\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
   )\r
 {\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
-    return (gEfiShellProtocol->GetEnv(EnvKey));\r
+    return (gEfiShellProtocol->GetEnv (EnvKey));\r
   }\r
 \r
   //\r
   // Check for EFI shell\r
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
   }\r
 \r
   //\r
   // Check for EFI shell\r
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
-    return (mEfiShellEnvironment2->GetEnv((CHAR16*)EnvKey));\r
+    return (mEfiShellEnvironment2->GetEnv ((CHAR16 *)EnvKey));\r
   }\r
 \r
   return NULL;\r
 }\r
   }\r
 \r
   return NULL;\r
 }\r
+\r
 /**\r
   set the value of an environment variable\r
 \r
 /**\r
   set the value of an environment variable\r
 \r
@@ -1145,16 +1259,16 @@ environment variable is created and assigned the specified value.
 EFI_STATUS\r
 EFIAPI\r
 ShellSetEnvironmentVariable (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellSetEnvironmentVariable (\r
-  IN CONST CHAR16               *EnvKey,\r
-  IN CONST CHAR16               *EnvVal,\r
-  IN BOOLEAN                    Volatile\r
+  IN CONST CHAR16  *EnvKey,\r
+  IN CONST CHAR16  *EnvVal,\r
+  IN BOOLEAN       Volatile\r
   )\r
 {\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
   )\r
 {\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
-    return (gEfiShellProtocol->SetEnv(EnvKey, EnvVal, Volatile));\r
+    return (gEfiShellProtocol->SetEnv (EnvKey, EnvVal, Volatile));\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -1175,7 +1289,7 @@ ShellSetEnvironmentVariable (
   The CommandLine is executed from the current working directory on the current\r
   device.\r
 \r
   The CommandLine is executed from the current working directory on the current\r
   device.\r
 \r
-  The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0\r
+  The EnvironmentVariables pararemeter is ignored in a pre-UEFI Shell 2.0\r
   environment.  The values pointed to by the parameters will be unchanged by the\r
   ShellExecute() function.  The Output parameter has no effect in a\r
   UEFI Shell 2.0 environment.\r
   environment.  The values pointed to by the parameters will be unchanged by the\r
   ShellExecute() function.  The Output parameter has no effect in a\r
   UEFI Shell 2.0 environment.\r
@@ -1196,13 +1310,15 @@ ShellSetEnvironmentVariable (
 EFI_STATUS\r
 EFIAPI\r
 ShellExecute (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellExecute (\r
-  IN EFI_HANDLE                 *ParentHandle,\r
-  IN CHAR16                     *CommandLine OPTIONAL,\r
-  IN BOOLEAN                    Output OPTIONAL,\r
-  IN CHAR16                     **EnvironmentVariables OPTIONAL,\r
-  OUT EFI_STATUS                *Status OPTIONAL\r
+  IN EFI_HANDLE   *ParentHandle,\r
+  IN CHAR16       *CommandLine OPTIONAL,\r
+  IN BOOLEAN      Output OPTIONAL,\r
+  IN CHAR16       **EnvironmentVariables OPTIONAL,\r
+  OUT EFI_STATUS  *Status OPTIONAL\r
   )\r
 {\r
   )\r
 {\r
+  EFI_STATUS  CmdStatus;\r
+\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
@@ -1210,10 +1326,12 @@ ShellExecute (
     //\r
     // Call UEFI Shell 2.0 version (not using Output parameter)\r
     //\r
     //\r
     // Call UEFI Shell 2.0 version (not using Output parameter)\r
     //\r
-    return (gEfiShellProtocol->Execute(ParentHandle,\r
-                                      CommandLine,\r
-                                      EnvironmentVariables,\r
-                                      Status));\r
+    return (gEfiShellProtocol->Execute (\r
+                                 ParentHandle,\r
+                                 CommandLine,\r
+                                 EnvironmentVariables,\r
+                                 Status\r
+                                 ));\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -1221,16 +1339,50 @@ ShellExecute (
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
     //\r
   //\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
+    // Call EFI Shell version.\r
+    //\r
+    // Due to an unfixable bug in the EdkShell implementation, we must\r
+    // dereference "ParentHandle" here:\r
+    //\r
+    // 1. The EFI shell installs the EFI_SHELL_ENVIRONMENT2 protocol,\r
+    //    identified by gEfiShellEnvironment2Guid.\r
+    // 2. The Execute() member function takes "ParentImageHandle" as first\r
+    //    parameter, with type (EFI_HANDLE*).\r
+    // 3. In the EdkShell implementation, SEnvExecute() implements the\r
+    //    Execute() member function. It passes "ParentImageHandle" correctly to\r
+    //    SEnvDoExecute().\r
+    // 4. SEnvDoExecute() takes the (EFI_HANDLE*), and passes it directly --\r
+    //    without de-referencing -- to the HandleProtocol() boot service.\r
+    // 5. But HandleProtocol() takes an EFI_HANDLE.\r
+    //\r
+    // Therefore we must\r
+    // - de-reference "ParentHandle" here, to mask the bug in\r
+    //   SEnvDoExecute(), and\r
+    // - pass the resultant EFI_HANDLE as an (EFI_HANDLE*).\r
     //\r
     //\r
-    return (mEfiShellEnvironment2->Execute(*ParentHandle,\r
+    CmdStatus = (mEfiShellEnvironment2->Execute (\r
+                                          (EFI_HANDLE *)*ParentHandle,\r
                                           CommandLine,\r
                                           CommandLine,\r
-                                          Output));\r
+                                          Output\r
+                                          ));\r
+    //\r
+    // No Status output parameter so just use the returned status\r
+    //\r
+    if (Status != NULL) {\r
+      *Status = CmdStatus;\r
+    }\r
+\r
+    //\r
+    // If there was an error, we can't tell if it was from the command or from\r
+    // the Execute() function, so we'll just assume the shell ran successfully\r
+    // and the error came from the command.\r
+    //\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   return (EFI_UNSUPPORTED);\r
 }\r
   }\r
 \r
   return (EFI_UNSUPPORTED);\r
 }\r
+\r
 /**\r
   Retreives the current directory path\r
 \r
 /**\r
   Retreives the current directory path\r
 \r
@@ -1238,33 +1390,36 @@ ShellExecute (
   name. If the DeviceName is not NULL, it returns the current directory name\r
   on specified drive.\r
 \r
   name. If the DeviceName is not NULL, it returns the current directory name\r
   on specified drive.\r
 \r
+  Note that the current directory string should exclude the tailing backslash character.\r
+\r
   @param DeviceName             the name of the drive to get directory on\r
 \r
   @retval NULL                  the directory does not exist\r
   @return != NULL               the directory\r
 **/\r
   @param DeviceName             the name of the drive to get directory on\r
 \r
   @retval NULL                  the directory does not exist\r
   @return != NULL               the directory\r
 **/\r
-CONST CHAR16*\r
+CONST CHAR16 *\r
 EFIAPI\r
 ShellGetCurrentDir (\r
 EFIAPI\r
 ShellGetCurrentDir (\r
-  IN CHAR16                     * CONST DeviceName OPTIONAL\r
+  IN CHAR16                     *CONST  DeviceName OPTIONAL\r
   )\r
 {\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
   )\r
 {\r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
-    return (gEfiShellProtocol->GetCurDir(DeviceName));\r
+    return (gEfiShellProtocol->GetCurDir (DeviceName));\r
   }\r
 \r
   //\r
   // Check for EFI shell\r
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
   }\r
 \r
   //\r
   // Check for EFI shell\r
   //\r
   if (mEfiShellEnvironment2 != NULL) {\r
-    return (mEfiShellEnvironment2->CurDir(DeviceName));\r
+    return (mEfiShellEnvironment2->CurDir (DeviceName));\r
   }\r
 \r
   return (NULL);\r
 }\r
   }\r
 \r
   return (NULL);\r
 }\r
+\r
 /**\r
   sets (enabled or disabled) the page break mode\r
 \r
 /**\r
   sets (enabled or disabled) the page break mode\r
 \r
@@ -1276,7 +1431,7 @@ ShellGetCurrentDir (
 VOID\r
 EFIAPI\r
 ShellSetPageBreakMode (\r
 VOID\r
 EFIAPI\r
 ShellSetPageBreakMode (\r
-  IN BOOLEAN                    CurrentState\r
+  IN BOOLEAN  CurrentState\r
   )\r
 {\r
   //\r
   )\r
 {\r
   //\r
@@ -1290,7 +1445,7 @@ ShellSetPageBreakMode (
       //\r
       // Enable with UEFI 2.0 Shell\r
       //\r
       //\r
       // Enable with UEFI 2.0 Shell\r
       //\r
-      gEfiShellProtocol->EnablePageBreak();\r
+      gEfiShellProtocol->EnablePageBreak ();\r
       return;\r
     } else {\r
       //\r
       return;\r
     } else {\r
       //\r
@@ -1312,7 +1467,7 @@ ShellSetPageBreakMode (
       //\r
       // Disable with UEFI 2.0 Shell\r
       //\r
       //\r
       // Disable with UEFI 2.0 Shell\r
       //\r
-      gEfiShellProtocol->DisablePageBreak();\r
+      gEfiShellProtocol->DisablePageBreak ();\r
       return;\r
     } else {\r
       //\r
       return;\r
     } else {\r
       //\r
@@ -1334,12 +1489,12 @@ ShellSetPageBreakMode (
 /// This allows for the struct to be populated.\r
 ///\r
 typedef struct {\r
 /// This allows for the struct to be populated.\r
 ///\r
 typedef struct {\r
-  LIST_ENTRY Link;\r
-  EFI_STATUS Status;\r
-  CHAR16 *FullName;\r
-  CHAR16 *FileName;\r
-  SHELL_FILE_HANDLE          Handle;\r
-  EFI_FILE_INFO *Info;\r
+  LIST_ENTRY           Link;\r
+  EFI_STATUS           Status;\r
+  CHAR16               *FullName;\r
+  CHAR16               *FileName;\r
+  SHELL_FILE_HANDLE    Handle;\r
+  EFI_FILE_INFO        *Info;\r
 } EFI_SHELL_FILE_INFO_NO_CONST;\r
 \r
 /**\r
 } EFI_SHELL_FILE_INFO_NO_CONST;\r
 \r
 /**\r
@@ -1356,11 +1511,10 @@ typedef struct {
 \r
   @retval the resultant head of the double linked new format list;\r
 **/\r
 \r
   @retval the resultant head of the double linked new format list;\r
 **/\r
-LIST_ENTRY*\r
-EFIAPI\r
+LIST_ENTRY *\r
 InternalShellConvertFileListType (\r
 InternalShellConvertFileListType (\r
-  IN LIST_ENTRY                 *FileList,\r
-  IN OUT LIST_ENTRY             *ListHead\r
+  IN LIST_ENTRY      *FileList,\r
+  IN OUT LIST_ENTRY  *ListHead\r
   )\r
 {\r
   SHELL_FILE_ARG                *OldInfo;\r
   )\r
 {\r
   SHELL_FILE_ARG                *OldInfo;\r
@@ -1370,15 +1524,15 @@ InternalShellConvertFileListType (
   //\r
   // ASSERTs\r
   //\r
   //\r
   // ASSERTs\r
   //\r
-  ASSERT(FileList  != NULL);\r
-  ASSERT(ListHead  != NULL);\r
+  ASSERT (FileList  != NULL);\r
+  ASSERT (ListHead  != NULL);\r
 \r
   //\r
   // enumerate through each member of the old list and copy\r
   //\r
   for (Link = FileList->ForwardLink; Link != FileList; Link = Link->ForwardLink) {\r
     OldInfo = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);\r
 \r
   //\r
   // enumerate through each member of the old list and copy\r
   //\r
   for (Link = FileList->ForwardLink; Link != FileList; Link = Link->ForwardLink) {\r
     OldInfo = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);\r
-    ASSERT(OldInfo           != NULL);\r
+    ASSERT (OldInfo           != NULL);\r
 \r
     //\r
     // Skip ones that failed to open...\r
 \r
     //\r
     // Skip ones that failed to open...\r
@@ -1390,16 +1544,16 @@ InternalShellConvertFileListType (
     //\r
     // make sure the old list was valid\r
     //\r
     //\r
     // make sure the old list was valid\r
     //\r
-    ASSERT(OldInfo->Info     != NULL);\r
-    ASSERT(OldInfo->FullName != NULL);\r
-    ASSERT(OldInfo->FileName != NULL);\r
+    ASSERT (OldInfo->Info     != NULL);\r
+    ASSERT (OldInfo->FullName != NULL);\r
+    ASSERT (OldInfo->FileName != NULL);\r
 \r
     //\r
     // allocate a new EFI_SHELL_FILE_INFO object\r
     //\r
 \r
     //\r
     // allocate a new EFI_SHELL_FILE_INFO object\r
     //\r
-    NewInfo               = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+    NewInfo = AllocateZeroPool (sizeof (EFI_SHELL_FILE_INFO));\r
     if (NewInfo == NULL) {\r
     if (NewInfo == NULL) {\r
-      ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));\r
+      ShellCloseFileMetaArg ((EFI_SHELL_FILE_INFO **)(&ListHead));\r
       ListHead = NULL;\r
       break;\r
     }\r
       ListHead = NULL;\r
       break;\r
     }\r
@@ -1407,8 +1561,8 @@ InternalShellConvertFileListType (
     //\r
     // copy the simple items\r
     //\r
     //\r
     // copy the simple items\r
     //\r
-    NewInfo->Handle       = OldInfo->Handle;\r
-    NewInfo->Status       = OldInfo->Status;\r
+    NewInfo->Handle = OldInfo->Handle;\r
+    NewInfo->Status = OldInfo->Status;\r
 \r
     // old shell checks for 0 not NULL\r
     OldInfo->Handle = 0;\r
 \r
     // old shell checks for 0 not NULL\r
     OldInfo->Handle = 0;\r
@@ -1416,39 +1570,45 @@ InternalShellConvertFileListType (
     //\r
     // allocate new space to copy strings and structure\r
     //\r
     //\r
     // allocate new space to copy strings and structure\r
     //\r
-    NewInfo->FullName     = AllocateZeroPool(StrSize(OldInfo->FullName));\r
-    NewInfo->FileName     = AllocateZeroPool(StrSize(OldInfo->FileName));\r
-    NewInfo->Info         = AllocateZeroPool((UINTN)OldInfo->Info->Size);\r
+    NewInfo->FullName = AllocateCopyPool (StrSize (OldInfo->FullName), OldInfo->FullName);\r
+    NewInfo->FileName = AllocateCopyPool (StrSize (OldInfo->FileName), OldInfo->FileName);\r
+    NewInfo->Info     = AllocateCopyPool ((UINTN)OldInfo->Info->Size, OldInfo->Info);\r
 \r
     //\r
     // make sure all the memory allocations were sucessful\r
     //\r
 \r
     //\r
     // make sure all the memory allocations were sucessful\r
     //\r
-    if (NULL == NewInfo->FullName || NewInfo->FileName == NULL || NewInfo->Info == NULL) {\r
-      ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));\r
+    if ((NULL == NewInfo->FullName) || (NewInfo->FileName == NULL) || (NewInfo->Info == NULL)) {\r
+      //\r
+      // Free the partially allocated new node\r
+      //\r
+      SHELL_FREE_NON_NULL (NewInfo->FullName);\r
+      SHELL_FREE_NON_NULL (NewInfo->FileName);\r
+      SHELL_FREE_NON_NULL (NewInfo->Info);\r
+      SHELL_FREE_NON_NULL (NewInfo);\r
+\r
+      //\r
+      // Free the previously converted stuff\r
+      //\r
+      ShellCloseFileMetaArg ((EFI_SHELL_FILE_INFO **)(&ListHead));\r
       ListHead = NULL;\r
       break;\r
     }\r
 \r
       ListHead = NULL;\r
       break;\r
     }\r
 \r
-    //\r
-    // Copt the strings and structure\r
-    //\r
-    StrCpy(NewInfo->FullName, OldInfo->FullName);\r
-    StrCpy(NewInfo->FileName, OldInfo->FileName);\r
-    gBS->CopyMem (NewInfo->Info, OldInfo->Info, (UINTN)OldInfo->Info->Size);\r
-\r
     //\r
     // add that to the list\r
     //\r
     //\r
     // add that to the list\r
     //\r
-    InsertTailList(ListHead, &NewInfo->Link);\r
+    InsertTailList (ListHead, &NewInfo->Link);\r
   }\r
   }\r
+\r
   return (ListHead);\r
 }\r
   return (ListHead);\r
 }\r
+\r
 /**\r
   Opens a group of files based on a path.\r
 \r
   This function uses the Arg to open all the matching files. Each matched\r
 /**\r
   Opens a group of files based on a path.\r
 \r
   This function uses the Arg to open all the matching files. Each matched\r
-  file has a SHELL_FILE_ARG structure to record the file information. These\r
-  structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG\r
+  file has a SHELL_FILE_INFO structure to record the file information. These\r
+  structures are placed on the list ListHead. Users can get the SHELL_FILE_INFO\r
   structures from ListHead to access each file. This function supports wildcards\r
   and will process '?' and '*' as such.  the list must be freed with a call to\r
   ShellCloseFileMetaArg().\r
   structures from ListHead to access each file. This function supports wildcards\r
   and will process '?' and '*' as such.  the list must be freed with a call to\r
   ShellCloseFileMetaArg().\r
@@ -1469,44 +1629,61 @@ InternalShellConvertFileListType (
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileMetaArg (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellOpenFileMetaArg (\r
-  IN CHAR16                     *Arg,\r
-  IN UINT64                     OpenMode,\r
-  IN OUT EFI_SHELL_FILE_INFO    **ListHead\r
+  IN CHAR16                   *Arg,\r
+  IN UINT64                   OpenMode,\r
+  IN OUT EFI_SHELL_FILE_INFO  **ListHead\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  LIST_ENTRY                    mOldStyleFileList;\r
+  EFI_STATUS  Status;\r
+  LIST_ENTRY  mOldStyleFileList;\r
+  CHAR16      *CleanFilePathStr;\r
 \r
   //\r
   // ASSERT that Arg and ListHead are not NULL\r
   //\r
 \r
   //\r
   // ASSERT that Arg and ListHead are not NULL\r
   //\r
-  ASSERT(Arg      != NULL);\r
-  ASSERT(ListHead != NULL);\r
+  ASSERT (Arg      != NULL);\r
+  ASSERT (ListHead != NULL);\r
+\r
+  CleanFilePathStr = NULL;\r
+\r
+  Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
 \r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
     if (*ListHead == NULL) {\r
 \r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
     if (*ListHead == NULL) {\r
-      *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+      *ListHead = (EFI_SHELL_FILE_INFO *)AllocateZeroPool (sizeof (EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
       if (*ListHead == NULL) {\r
+        FreePool (CleanFilePathStr);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      InitializeListHead(&((*ListHead)->Link));\r
+\r
+      InitializeListHead (&((*ListHead)->Link));\r
     }\r
     }\r
-    Status = gEfiShellProtocol->OpenFileList(Arg,\r
-                                           OpenMode,\r
-                                           ListHead);\r
-    if (EFI_ERROR(Status)) {\r
-      gEfiShellProtocol->RemoveDupInFileList(ListHead);\r
+\r
+    Status = gEfiShellProtocol->OpenFileList (\r
+                                  CleanFilePathStr,\r
+                                  OpenMode,\r
+                                  ListHead\r
+                                  );\r
+    if (EFI_ERROR (Status)) {\r
+      gEfiShellProtocol->RemoveDupInFileList (ListHead);\r
     } else {\r
     } else {\r
-      Status = gEfiShellProtocol->RemoveDupInFileList(ListHead);\r
+      Status = gEfiShellProtocol->RemoveDupInFileList (ListHead);\r
     }\r
     }\r
-    if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {\r
-      FreePool(*ListHead);\r
+\r
+    if ((*ListHead != NULL) && IsListEmpty (&(*ListHead)->Link)) {\r
+      FreePool (*ListHead);\r
+      FreePool (CleanFilePathStr);\r
       *ListHead = NULL;\r
       return (EFI_NOT_FOUND);\r
     }\r
       *ListHead = NULL;\r
       return (EFI_NOT_FOUND);\r
     }\r
+\r
+    FreePool (CleanFilePathStr);\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
@@ -1517,45 +1694,52 @@ ShellOpenFileMetaArg (
     //\r
     // make sure the list head is initialized\r
     //\r
     //\r
     // make sure the list head is initialized\r
     //\r
-    InitializeListHead(&mOldStyleFileList);\r
+    InitializeListHead (&mOldStyleFileList);\r
 \r
     //\r
     // Get the EFI Shell list of files\r
     //\r
 \r
     //\r
     // Get the EFI Shell list of files\r
     //\r
-    Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);\r
-    if (EFI_ERROR(Status)) {\r
+    Status = mEfiShellEnvironment2->FileMetaArg (CleanFilePathStr, &mOldStyleFileList);\r
+    if (EFI_ERROR (Status)) {\r
       *ListHead = NULL;\r
       *ListHead = NULL;\r
+      FreePool (CleanFilePathStr);\r
       return (Status);\r
     }\r
 \r
     if (*ListHead == NULL) {\r
       return (Status);\r
     }\r
 \r
     if (*ListHead == NULL) {\r
-      *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
+      *ListHead = (EFI_SHELL_FILE_INFO    *)AllocateZeroPool (sizeof (EFI_SHELL_FILE_INFO));\r
       if (*ListHead == NULL) {\r
       if (*ListHead == NULL) {\r
+        FreePool (CleanFilePathStr);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\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
     }\r
 \r
     //\r
     // Convert that to equivalent of UEFI Shell 2.0 structure\r
     //\r
-    InternalShellConvertFileListType(&mOldStyleFileList, &(*ListHead)->Link);\r
+    InternalShellConvertFileListType (&mOldStyleFileList, &(*ListHead)->Link);\r
 \r
     //\r
     // Free the EFI Shell version that was converted.\r
     //\r
 \r
     //\r
     // Free the EFI Shell version that was converted.\r
     //\r
-    mEfiShellEnvironment2->FreeFileList(&mOldStyleFileList);\r
+    mEfiShellEnvironment2->FreeFileList (&mOldStyleFileList);\r
 \r
 \r
-    if ((*ListHead)->Link.ForwardLink == (*ListHead)->Link.BackLink && (*ListHead)->Link.BackLink == &((*ListHead)->Link)) {\r
-      FreePool(*ListHead);\r
+    if (((*ListHead)->Link.ForwardLink == (*ListHead)->Link.BackLink) && ((*ListHead)->Link.BackLink == &((*ListHead)->Link))) {\r
+      FreePool (*ListHead);\r
       *ListHead = NULL;\r
       *ListHead = NULL;\r
-      Status = EFI_NOT_FOUND;\r
+      Status    = EFI_NOT_FOUND;\r
     }\r
     }\r
+\r
+    FreePool (CleanFilePathStr);\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
+  FreePool (CleanFilePathStr);\r
   return (EFI_UNSUPPORTED);\r
 }\r
   return (EFI_UNSUPPORTED);\r
 }\r
+\r
 /**\r
   Free the linked list returned from ShellOpenFileMetaArg.\r
 \r
 /**\r
   Free the linked list returned from ShellOpenFileMetaArg.\r
 \r
@@ -1568,36 +1752,39 @@ ShellOpenFileMetaArg (
 EFI_STATUS\r
 EFIAPI\r
 ShellCloseFileMetaArg (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellCloseFileMetaArg (\r
-  IN OUT EFI_SHELL_FILE_INFO    **ListHead\r
+  IN OUT EFI_SHELL_FILE_INFO  **ListHead\r
   )\r
 {\r
   )\r
 {\r
-  LIST_ENTRY                    *Node;\r
+  LIST_ENTRY  *Node;\r
 \r
   //\r
   // ASSERT that ListHead is not NULL\r
   //\r
 \r
   //\r
   // ASSERT that ListHead is not NULL\r
   //\r
-  ASSERT(ListHead != NULL);\r
+  ASSERT (ListHead != NULL);\r
 \r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
 \r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellProtocol != NULL) {\r
-    return (gEfiShellProtocol->FreeFileList(ListHead));\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
     //\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
     //\r
-    for ( Node = GetFirstNode(&(*ListHead)->Link)\r
-        ; *ListHead != NULL && !IsListEmpty(&(*ListHead)->Link)\r
-        ; Node = GetFirstNode(&(*ListHead)->Link)) {\r
-      RemoveEntryList(Node);\r
-      ((EFI_FILE_PROTOCOL*)((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
-      FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FileName);\r
-      FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info);\r
-      FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node);\r
+    for ( Node = GetFirstNode (&(*ListHead)->Link)\r
+          ; *ListHead != NULL && !IsListEmpty (&(*ListHead)->Link)\r
+          ; Node = GetFirstNode (&(*ListHead)->Link))\r
+    {\r
+      RemoveEntryList (Node);\r
+      ((EFI_FILE_PROTOCOL *)((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
+      FreePool (((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->FileName);\r
+      FreePool (((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->Info);\r
+      FreePool ((EFI_SHELL_FILE_INFO_NO_CONST *)Node);\r
     }\r
     }\r
+\r
+    SHELL_FREE_NON_NULL (*ListHead);\r
     return EFI_SUCCESS;\r
   }\r
 \r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -1619,102 +1806,113 @@ ShellCloseFileMetaArg (
 CHAR16 *\r
 EFIAPI\r
 ShellFindFilePath (\r
 CHAR16 *\r
 EFIAPI\r
 ShellFindFilePath (\r
-  IN CONST CHAR16 *FileName\r
+  IN CONST CHAR16  *FileName\r
   )\r
 {\r
   )\r
 {\r
-  CONST CHAR16      *Path;\r
-  SHELL_FILE_HANDLE Handle;\r
-  EFI_STATUS        Status;\r
-  CHAR16            *RetVal;\r
-  CHAR16            *TestPath;\r
-  CONST CHAR16      *Walker;\r
-  UINTN             Size;\r
-  CHAR16            *TempChar;\r
+  CONST CHAR16       *Path;\r
+  SHELL_FILE_HANDLE  Handle;\r
+  EFI_STATUS         Status;\r
+  CHAR16             *RetVal;\r
+  CHAR16             *TestPath;\r
+  CONST CHAR16       *Walker;\r
+  UINTN              Size;\r
+  CHAR16             *TempChar;\r
 \r
   RetVal = NULL;\r
 \r
   //\r
   // First make sure its not an absolute path.\r
   //\r
 \r
   RetVal = NULL;\r
 \r
   //\r
   // First make sure its not an absolute path.\r
   //\r
-  Status = ShellOpenFileByName(FileName, &Handle, EFI_FILE_MODE_READ, 0);\r
-  if (!EFI_ERROR(Status)){\r
-    if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
-      ASSERT(RetVal == NULL);\r
-      RetVal = StrnCatGrow(&RetVal, NULL, FileName, 0);\r
-      ShellCloseFile(&Handle);\r
+  Status = ShellOpenFileByName (FileName, &Handle, EFI_FILE_MODE_READ, 0);\r
+  if (!EFI_ERROR (Status)) {\r
+    if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {\r
+      ASSERT (RetVal == NULL);\r
+      RetVal = StrnCatGrow (&RetVal, NULL, FileName, 0);\r
+      ShellCloseFile (&Handle);\r
       return (RetVal);\r
     } else {\r
       return (RetVal);\r
     } else {\r
-      ShellCloseFile(&Handle);\r
+      ShellCloseFile (&Handle);\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  Path = ShellGetEnvironmentVariable(L"cwd");\r
+  Path = ShellGetEnvironmentVariable (L"cwd");\r
   if (Path != NULL) {\r
   if (Path != NULL) {\r
-    Size = StrSize(Path);\r
-    Size += StrSize(FileName);\r
-    TestPath = AllocateZeroPool(Size);\r
+    Size     = StrSize (Path) + sizeof (CHAR16);\r
+    Size    += StrSize (FileName);\r
+    TestPath = AllocateZeroPool (Size);\r
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
-    StrCpy(TestPath, Path);\r
-    StrCat(TestPath, FileName);\r
-    Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
-    if (!EFI_ERROR(Status)){\r
-      if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
-        ASSERT(RetVal == NULL);\r
-        RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);\r
-        ShellCloseFile(&Handle);\r
-        FreePool(TestPath);\r
+\r
+    StrCpyS (TestPath, Size/sizeof (CHAR16), Path);\r
+    StrCatS (TestPath, Size/sizeof (CHAR16), L"\\");\r
+    StrCatS (TestPath, Size/sizeof (CHAR16), FileName);\r
+    Status = ShellOpenFileByName (TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
+    if (!EFI_ERROR (Status)) {\r
+      if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {\r
+        ASSERT (RetVal == NULL);\r
+        RetVal = StrnCatGrow (&RetVal, NULL, TestPath, 0);\r
+        ShellCloseFile (&Handle);\r
+        FreePool (TestPath);\r
         return (RetVal);\r
       } else {\r
         return (RetVal);\r
       } else {\r
-        ShellCloseFile(&Handle);\r
+        ShellCloseFile (&Handle);\r
       }\r
     }\r
       }\r
     }\r
-    FreePool(TestPath);\r
+\r
+    FreePool (TestPath);\r
   }\r
   }\r
-  Path = ShellGetEnvironmentVariable(L"path");\r
+\r
+  Path = ShellGetEnvironmentVariable (L"path");\r
   if (Path != NULL) {\r
   if (Path != NULL) {\r
-    Size = StrSize(Path)+sizeof(CHAR16);\r
-    Size += StrSize(FileName);\r
-    TestPath = AllocateZeroPool(Size);\r
+    Size     = StrSize (Path)+sizeof (CHAR16);\r
+    Size    += StrSize (FileName);\r
+    TestPath = AllocateZeroPool (Size);\r
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
     if (TestPath == NULL) {\r
       return (NULL);\r
     }\r
-    Walker = (CHAR16*)Path;\r
+\r
+    Walker = (CHAR16 *)Path;\r
     do {\r
     do {\r
-      CopyMem(TestPath, Walker, StrSize(Walker));\r
+      CopyMem (TestPath, Walker, StrSize (Walker));\r
       if (TestPath != NULL) {\r
       if (TestPath != NULL) {\r
-        TempChar = StrStr(TestPath, L";");\r
+        TempChar = StrStr (TestPath, L";");\r
         if (TempChar != NULL) {\r
           *TempChar = CHAR_NULL;\r
         }\r
         if (TempChar != NULL) {\r
           *TempChar = CHAR_NULL;\r
         }\r
-        if (TestPath[StrLen(TestPath)-1] != L'\\') {\r
-          StrCat(TestPath, L"\\");\r
+\r
+        if (TestPath[StrLen (TestPath)-1] != L'\\') {\r
+          StrCatS (TestPath, Size/sizeof (CHAR16), L"\\");\r
         }\r
         }\r
+\r
         if (FileName[0] == L'\\') {\r
           FileName++;\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
+\r
+        StrCatS (TestPath, Size/sizeof (CHAR16), FileName);\r
+        if (StrStr (Walker, L";") != NULL) {\r
+          Walker = StrStr (Walker, L";") + 1;\r
         } else {\r
           Walker = NULL;\r
         }\r
         } else {\r
           Walker = NULL;\r
         }\r
-        Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
-        if (!EFI_ERROR(Status)){\r
-          if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
-            ASSERT(RetVal == NULL);\r
-            RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);\r
-            ShellCloseFile(&Handle);\r
+\r
+        Status = ShellOpenFileByName (TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
+        if (!EFI_ERROR (Status)) {\r
+          if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {\r
+            ASSERT (RetVal == NULL);\r
+            RetVal = StrnCatGrow (&RetVal, NULL, TestPath, 0);\r
+            ShellCloseFile (&Handle);\r
             break;\r
           } else {\r
             break;\r
           } else {\r
-            ShellCloseFile(&Handle);\r
+            ShellCloseFile (&Handle);\r
           }\r
         }\r
       }\r
     } while (Walker != NULL && Walker[0] != CHAR_NULL);\r
           }\r
         }\r
       }\r
     } while (Walker != NULL && Walker[0] != CHAR_NULL);\r
-    FreePool(TestPath);\r
+\r
+    FreePool (TestPath);\r
   }\r
   }\r
+\r
   return (RetVal);\r
 }\r
 \r
   return (RetVal);\r
 }\r
 \r
@@ -1737,57 +1935,64 @@ ShellFindFilePath (
 CHAR16 *\r
 EFIAPI\r
 ShellFindFilePathEx (\r
 CHAR16 *\r
 EFIAPI\r
 ShellFindFilePathEx (\r
-  IN CONST CHAR16 *FileName,\r
-  IN CONST CHAR16 *FileExtension\r
+  IN CONST CHAR16  *FileName,\r
+  IN CONST CHAR16  *FileExtension\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16            *TestPath;\r
-  CHAR16            *RetVal;\r
-  CONST CHAR16      *ExtensionWalker;\r
-  UINTN             Size;\r
-  CHAR16            *TempChar;\r
-  CHAR16            *TempChar2;\r
-\r
-  ASSERT(FileName != NULL);\r
+  CHAR16        *TestPath;\r
+  CHAR16        *RetVal;\r
+  CONST CHAR16  *ExtensionWalker;\r
+  UINTN         Size;\r
+  CHAR16        *TempChar;\r
+  CHAR16        *TempChar2;\r
+\r
+  ASSERT (FileName != NULL);\r
   if (FileExtension == NULL) {\r
   if (FileExtension == NULL) {\r
-    return (ShellFindFilePath(FileName));\r
+    return (ShellFindFilePath (FileName));\r
   }\r
   }\r
-  RetVal = ShellFindFilePath(FileName);\r
+\r
+  RetVal = ShellFindFilePath (FileName);\r
   if (RetVal != NULL) {\r
     return (RetVal);\r
   }\r
   if (RetVal != NULL) {\r
     return (RetVal);\r
   }\r
-  Size =  StrSize(FileName);\r
-  Size += StrSize(FileExtension);\r
-  TestPath = AllocateZeroPool(Size);\r
+\r
+  Size     =  StrSize (FileName);\r
+  Size    += StrSize (FileExtension);\r
+  TestPath = AllocateZeroPool (Size);\r
   if (TestPath == NULL) {\r
     return (NULL);\r
   }\r
   if (TestPath == NULL) {\r
     return (NULL);\r
   }\r
-  for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension;  TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){\r
-    StrCpy(TestPath, FileName);\r
+\r
+  for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16 *)FileExtension; TempChar2 != NULL; ExtensionWalker = TempChar2 + 1) {\r
+    StrCpyS (TestPath, Size/sizeof (CHAR16), FileName);\r
     if (ExtensionWalker != NULL) {\r
     if (ExtensionWalker != NULL) {\r
-      StrCat(TestPath, ExtensionWalker);\r
+      StrCatS (TestPath, Size/sizeof (CHAR16), ExtensionWalker);\r
     }\r
     }\r
-    TempChar = StrStr(TestPath, L";");\r
+\r
+    TempChar = StrStr (TestPath, L";");\r
     if (TempChar != NULL) {\r
       *TempChar = CHAR_NULL;\r
     }\r
     if (TempChar != NULL) {\r
       *TempChar = CHAR_NULL;\r
     }\r
-    RetVal = ShellFindFilePath(TestPath);\r
+\r
+    RetVal = ShellFindFilePath (TestPath);\r
     if (RetVal != NULL) {\r
       break;\r
     }\r
     if (RetVal != NULL) {\r
       break;\r
     }\r
-    ASSERT(ExtensionWalker != NULL);\r
-    TempChar2 = StrStr(ExtensionWalker, L";");\r
+\r
+    ASSERT (ExtensionWalker != NULL);\r
+    TempChar2 = StrStr (ExtensionWalker, L";");\r
   }\r
   }\r
-  FreePool(TestPath);\r
+\r
+  FreePool (TestPath);\r
   return (RetVal);\r
 }\r
 \r
 typedef struct {\r
   return (RetVal);\r
 }\r
 \r
 typedef struct {\r
-  LIST_ENTRY     Link;\r
-  CHAR16         *Name;\r
-  SHELL_PARAM_TYPE      Type;\r
-  CHAR16         *Value;\r
-  UINTN          OriginalPosition;\r
+  LIST_ENTRY          Link;\r
+  CHAR16              *Name;\r
+  SHELL_PARAM_TYPE    Type;\r
+  CHAR16              *Value;\r
+  UINTN               OriginalPosition;\r
 } SHELL_PARAM_PACKAGE;\r
 \r
 /**\r
 } SHELL_PARAM_PACKAGE;\r
 \r
 /**\r
@@ -1806,57 +2011,59 @@ typedef struct {
   @retval FALSE                 the Parameter was not found.  Type is not valid.\r
 **/\r
 BOOLEAN\r
   @retval FALSE                 the Parameter was not found.  Type is not valid.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 InternalIsOnCheckList (\r
 InternalIsOnCheckList (\r
-  IN CONST CHAR16               *Name,\r
-  IN CONST SHELL_PARAM_ITEM     *CheckList,\r
-  OUT SHELL_PARAM_TYPE          *Type\r
+  IN CONST CHAR16            *Name,\r
+  IN CONST SHELL_PARAM_ITEM  *CheckList,\r
+  OUT SHELL_PARAM_TYPE       *Type\r
   )\r
 {\r
   )\r
 {\r
-  SHELL_PARAM_ITEM              *TempListItem;\r
-  CHAR16                        *TempString;\r
+  SHELL_PARAM_ITEM  *TempListItem;\r
+  CHAR16            *TempString;\r
 \r
   //\r
   // ASSERT that all 3 pointer parameters aren't NULL\r
   //\r
 \r
   //\r
   // ASSERT that all 3 pointer parameters aren't NULL\r
   //\r
-  ASSERT(CheckList  != NULL);\r
-  ASSERT(Type       != NULL);\r
-  ASSERT(Name       != NULL);\r
+  ASSERT (CheckList  != NULL);\r
+  ASSERT (Type       != NULL);\r
+  ASSERT (Name       != NULL);\r
 \r
   //\r
   // question mark and page break mode are always supported\r
   //\r
 \r
   //\r
   // question mark and page break mode are always supported\r
   //\r
-  if ((StrCmp(Name, L"-?") == 0) ||\r
-      (StrCmp(Name, L"-b") == 0)\r
-     ) {\r
-     *Type = TypeFlag;\r
-     return (TRUE);\r
+  if ((StrCmp (Name, L"-?") == 0) ||\r
+      (StrCmp (Name, L"-b") == 0)\r
+      )\r
+  {\r
+    *Type = TypeFlag;\r
+    return (TRUE);\r
   }\r
 \r
   //\r
   // Enumerate through the list\r
   //\r
   }\r
 \r
   //\r
   // Enumerate through the list\r
   //\r
-  for (TempListItem = (SHELL_PARAM_ITEM*)CheckList ; TempListItem->Name != NULL ; TempListItem++) {\r
+  for (TempListItem = (SHELL_PARAM_ITEM *)CheckList; TempListItem->Name != NULL; TempListItem++) {\r
     //\r
     // If the Type is TypeStart only check the first characters of the passed in param\r
     // If it matches set the type and return TRUE\r
     //\r
     if (TempListItem->Type == TypeStart) {\r
     //\r
     // If the Type is TypeStart only check the first characters of the passed in param\r
     // If it matches set the type and return TRUE\r
     //\r
     if (TempListItem->Type == TypeStart) {\r
-      if (StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) {\r
+      if (StrnCmp (Name, TempListItem->Name, StrLen (TempListItem->Name)) == 0) {\r
         *Type = TempListItem->Type;\r
         return (TRUE);\r
       }\r
         *Type = TempListItem->Type;\r
         return (TRUE);\r
       }\r
+\r
       TempString = NULL;\r
       TempString = NULL;\r
-      TempString = StrnCatGrow(&TempString, NULL, Name, StrLen(TempListItem->Name));\r
+      TempString = StrnCatGrow (&TempString, NULL, Name, StrLen (TempListItem->Name));\r
       if (TempString != NULL) {\r
       if (TempString != NULL) {\r
-        if (StringNoCaseCompare(&TempString, &TempListItem->Name) == 0) {\r
+        if (StringNoCaseCompare (&TempString, &TempListItem->Name) == 0) {\r
           *Type = TempListItem->Type;\r
           *Type = TempListItem->Type;\r
-          FreePool(TempString);\r
+          FreePool (TempString);\r
           return (TRUE);\r
         }\r
           return (TRUE);\r
         }\r
-        FreePool(TempString);\r
+\r
+        FreePool (TempString);\r
       }\r
       }\r
-    } else if (StringNoCaseCompare(&Name, &TempListItem->Name) == 0) {\r
+    } else if (StringNoCaseCompare (&Name, &TempListItem->Name) == 0) {\r
       *Type = TempListItem->Type;\r
       return (TRUE);\r
     }\r
       *Type = TempListItem->Type;\r
       return (TRUE);\r
     }\r
@@ -1864,31 +2071,33 @@ InternalIsOnCheckList (
 \r
   return (FALSE);\r
 }\r
 \r
   return (FALSE);\r
 }\r
+\r
 /**\r
   Checks the string for indicators of "flag" status.  this is a leading '/', '-', or '+'\r
 \r
   @param[in] Name               pointer to Name of parameter found\r
   @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.\r
 /**\r
   Checks the string for indicators of "flag" status.  this is a leading '/', '-', or '+'\r
 \r
   @param[in] Name               pointer to Name of parameter found\r
   @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE                  the Parameter is a flag.\r
   @retval FALSE                 the Parameter not a flag.\r
 **/\r
 BOOLEAN\r
 \r
   @retval TRUE                  the Parameter is a flag.\r
   @retval FALSE                 the Parameter not a flag.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 InternalIsFlag (\r
 InternalIsFlag (\r
-  IN CONST CHAR16               *Name,\r
-  IN BOOLEAN                    AlwaysAllowNumbers\r
+  IN CONST CHAR16   *Name,\r
+  IN CONST BOOLEAN  AlwaysAllowNumbers,\r
+  IN CONST BOOLEAN  TimeNumbers\r
   )\r
 {\r
   //\r
   // ASSERT that Name isn't NULL\r
   //\r
   )\r
 {\r
   //\r
   // ASSERT that Name isn't NULL\r
   //\r
-  ASSERT(Name != NULL);\r
+  ASSERT (Name != NULL);\r
 \r
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
 \r
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
-  if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers) {\r
+  if ((((Name[0] == L'-') || (Name[0] == L'+')) && InternalShellIsHexOrDecimalNumber (Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) {\r
     return (FALSE);\r
   }\r
 \r
     return (FALSE);\r
   }\r
 \r
@@ -1898,9 +2107,11 @@ InternalIsFlag (
   if ((Name[0] == L'/') ||\r
       (Name[0] == L'-') ||\r
       (Name[0] == L'+')\r
   if ((Name[0] == L'/') ||\r
       (Name[0] == L'-') ||\r
       (Name[0] == L'+')\r
-     ) {\r
-      return (TRUE);\r
+      )\r
+  {\r
+    return (TRUE);\r
   }\r
   }\r
+\r
   return (FALSE);\r
 }\r
 \r
   return (FALSE);\r
 }\r
 \r
@@ -1930,29 +2141,30 @@ InternalIsFlag (
                                 ProblemParam if provided.\r
 **/\r
 EFI_STATUS\r
                                 ProblemParam if provided.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalCommandLineParse (\r
 InternalCommandLineParse (\r
-  IN CONST SHELL_PARAM_ITEM     *CheckList,\r
-  OUT LIST_ENTRY                **CheckPackage,\r
-  OUT CHAR16                    **ProblemParam OPTIONAL,\r
-  IN BOOLEAN                    AutoPageBreak,\r
-  IN CONST CHAR16               **Argv,\r
-  IN UINTN                      Argc,\r
-  IN BOOLEAN                    AlwaysAllowNumbers\r
+  IN CONST SHELL_PARAM_ITEM  *CheckList,\r
+  OUT LIST_ENTRY             **CheckPackage,\r
+  OUT CHAR16                 **ProblemParam OPTIONAL,\r
+  IN BOOLEAN                 AutoPageBreak,\r
+  IN CONST CHAR16            **Argv,\r
+  IN UINTN                   Argc,\r
+  IN BOOLEAN                 AlwaysAllowNumbers\r
   )\r
 {\r
   )\r
 {\r
-  UINTN                         LoopCounter;\r
-  SHELL_PARAM_TYPE              CurrentItemType;\r
-  SHELL_PARAM_PACKAGE           *CurrentItemPackage;\r
-  UINTN                         GetItemValue;\r
-  UINTN                         ValueSize;\r
-  UINTN                         Count;\r
-  CONST CHAR16                  *TempPointer;\r
+  UINTN                LoopCounter;\r
+  SHELL_PARAM_TYPE     CurrentItemType;\r
+  SHELL_PARAM_PACKAGE  *CurrentItemPackage;\r
+  UINTN                GetItemValue;\r
+  UINTN                ValueSize;\r
+  UINTN                Count;\r
+  CONST CHAR16         *TempPointer;\r
+  UINTN                CurrentValueSize;\r
+  CHAR16               *NewValue;\r
 \r
   CurrentItemPackage = NULL;\r
 \r
   CurrentItemPackage = NULL;\r
-  GetItemValue = 0;\r
-  ValueSize = 0;\r
-  Count = 0;\r
+  GetItemValue       = 0;\r
+  ValueSize          = 0;\r
+  Count              = 0;\r
 \r
   //\r
   // If there is only 1 item we dont need to do anything\r
 \r
   //\r
   // If there is only 1 item we dont need to do anything\r
@@ -1965,54 +2177,56 @@ InternalCommandLineParse (
   //\r
   // ASSERTs\r
   //\r
   //\r
   // ASSERTs\r
   //\r
-  ASSERT(CheckList  != NULL);\r
-  ASSERT(Argv       != NULL);\r
+  ASSERT (CheckList  != NULL);\r
+  ASSERT (Argv       != NULL);\r
 \r
   //\r
   // initialize the linked list\r
   //\r
 \r
   //\r
   // initialize the linked list\r
   //\r
-  *CheckPackage = (LIST_ENTRY*)AllocateZeroPool(sizeof(LIST_ENTRY));\r
+  *CheckPackage = (LIST_ENTRY *)AllocateZeroPool (sizeof (LIST_ENTRY));\r
   if (*CheckPackage == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
   if (*CheckPackage == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  InitializeListHead(*CheckPackage);\r
+  InitializeListHead (*CheckPackage);\r
 \r
   //\r
   // loop through each of the arguments\r
   //\r
 \r
   //\r
   // loop through each of the arguments\r
   //\r
-  for (LoopCounter = 0 ; LoopCounter < Argc ; ++LoopCounter) {\r
+  for (LoopCounter = 0; LoopCounter < Argc; ++LoopCounter) {\r
     if (Argv[LoopCounter] == NULL) {\r
       //\r
       // do nothing for NULL argv\r
       //\r
     if (Argv[LoopCounter] == NULL) {\r
       //\r
       // do nothing for NULL argv\r
       //\r
-    } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType)) {\r
+    } else if (InternalIsOnCheckList (Argv[LoopCounter], CheckList, &CurrentItemType)) {\r
       //\r
       // We might have leftover if last parameter didnt have optional value\r
       //\r
       if (GetItemValue != 0) {\r
         GetItemValue = 0;\r
       //\r
       // We might have leftover if last parameter didnt have optional value\r
       //\r
       if (GetItemValue != 0) {\r
         GetItemValue = 0;\r
-        InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+        InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
       }\r
+\r
       //\r
       // this is a flag\r
       //\r
       //\r
       // this is a flag\r
       //\r
-      CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));\r
+      CurrentItemPackage = AllocateZeroPool (sizeof (SHELL_PARAM_PACKAGE));\r
       if (CurrentItemPackage == NULL) {\r
       if (CurrentItemPackage == NULL) {\r
-        ShellCommandLineFreeVarList(*CheckPackage);\r
+        ShellCommandLineFreeVarList (*CheckPackage);\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      CurrentItemPackage->Name  = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
+\r
+      CurrentItemPackage->Name = AllocateCopyPool (StrSize (Argv[LoopCounter]), Argv[LoopCounter]);\r
       if (CurrentItemPackage->Name == NULL) {\r
       if (CurrentItemPackage->Name == NULL) {\r
-        ShellCommandLineFreeVarList(*CheckPackage);\r
+        ShellCommandLineFreeVarList (*CheckPackage);\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      StrCpy(CurrentItemPackage->Name,  Argv[LoopCounter]);\r
-      CurrentItemPackage->Type  = CurrentItemType;\r
+\r
+      CurrentItemPackage->Type             = CurrentItemType;\r
       CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
       CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
-      CurrentItemPackage->Value = NULL;\r
+      CurrentItemPackage->Value            = NULL;\r
 \r
       //\r
       // Does this flag require a value\r
 \r
       //\r
       // Does this flag require a value\r
@@ -2022,116 +2236,124 @@ InternalCommandLineParse (
         // possibly trigger the next loop(s) to populate the value of this item\r
         //\r
         case TypeValue:\r
         // possibly trigger the next loop(s) to populate the value of this item\r
         //\r
         case TypeValue:\r
+        case TypeTimeValue:\r
           GetItemValue = 1;\r
           GetItemValue = 1;\r
-          ValueSize = 0;\r
+          ValueSize    = 0;\r
           break;\r
         case TypeDoubleValue:\r
           GetItemValue = 2;\r
           break;\r
         case TypeDoubleValue:\r
           GetItemValue = 2;\r
-          ValueSize = 0;\r
+          ValueSize    = 0;\r
           break;\r
         case TypeMaxValue:\r
           GetItemValue = (UINTN)(-1);\r
           break;\r
         case TypeMaxValue:\r
           GetItemValue = (UINTN)(-1);\r
-          ValueSize = 0;\r
+          ValueSize    = 0;\r
           break;\r
         default:\r
           //\r
           // this item has no value expected; we are done\r
           //\r
           break;\r
         default:\r
           //\r
           // this item has no value expected; we are done\r
           //\r
-          InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
-          ASSERT(GetItemValue == 0);\r
+          InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);\r
+          ASSERT (GetItemValue == 0);\r
           break;\r
       }\r
           break;\r
       }\r
-    } else if (GetItemValue != 0 && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers)) {\r
-      ASSERT(CurrentItemPackage != NULL);\r
+    } else if ((GetItemValue != 0) && (CurrentItemPackage != NULL) && !InternalIsFlag (Argv[LoopCounter], AlwaysAllowNumbers, (BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) {\r
       //\r
       // get the item VALUE for a previous flag\r
       //\r
       //\r
       // get the item VALUE for a previous flag\r
       //\r
-      if (StrStr(Argv[LoopCounter], L" ") == NULL) {\r
-        CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);\r
-        ASSERT(CurrentItemPackage->Value != NULL);\r
-        if (ValueSize == 0) {\r
-          StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-        } else {\r
-          StrCat(CurrentItemPackage->Value, L" ");\r
-          StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-        }\r
-        ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
+      CurrentValueSize = ValueSize + StrSize (Argv[LoopCounter]) + sizeof (CHAR16);\r
+      NewValue         = ReallocatePool (ValueSize, CurrentValueSize, CurrentItemPackage->Value);\r
+      if (NewValue == NULL) {\r
+        SHELL_FREE_NON_NULL (CurrentItemPackage->Value);\r
+        SHELL_FREE_NON_NULL (CurrentItemPackage);\r
+        ShellCommandLineFreeVarList (*CheckPackage);\r
+        *CheckPackage = NULL;\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+\r
+      CurrentItemPackage->Value = NewValue;\r
+      if (ValueSize == 0) {\r
+        StrCpyS (\r
+          CurrentItemPackage->Value,\r
+          CurrentValueSize/sizeof (CHAR16),\r
+          Argv[LoopCounter]\r
+          );\r
       } else {\r
       } else {\r
-        //\r
-        // the parameter has spaces.  must be quoted.\r
-        //\r
-        CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16) + sizeof(CHAR16) + sizeof(CHAR16), CurrentItemPackage->Value);\r
-        ASSERT(CurrentItemPackage->Value != NULL);\r
-        if (ValueSize == 0) {\r
-          StrCpy(CurrentItemPackage->Value, L"\"");\r
-          StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-          StrCat(CurrentItemPackage->Value, L"\"");\r
-        } else {\r
-          StrCat(CurrentItemPackage->Value, L" ");\r
-          StrCat(CurrentItemPackage->Value, L"\"");\r
-          StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-          StrCat(CurrentItemPackage->Value, L"\"");\r
-       }\r
-        ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r
+        StrCatS (\r
+          CurrentItemPackage->Value,\r
+          CurrentValueSize/sizeof (CHAR16),\r
+          L" "\r
+          );\r
+        StrCatS (\r
+          CurrentItemPackage->Value,\r
+          CurrentValueSize/sizeof (CHAR16),\r
+          Argv[LoopCounter]\r
+          );\r
       }\r
       }\r
+\r
+      ValueSize += StrSize (Argv[LoopCounter]) + sizeof (CHAR16);\r
+\r
       GetItemValue--;\r
       if (GetItemValue == 0) {\r
       GetItemValue--;\r
       if (GetItemValue == 0) {\r
-        InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+        InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
       }\r
-    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) ){ //|| ProblemParam == NULL) {\r
+    } else if (!InternalIsFlag (Argv[LoopCounter], AlwaysAllowNumbers, FALSE)) {\r
       //\r
       // add this one as a non-flag\r
       //\r
 \r
       TempPointer = Argv[LoopCounter];\r
       //\r
       // add this one as a non-flag\r
       //\r
 \r
       TempPointer = Argv[LoopCounter];\r
-      if ((*TempPointer == L'^' && *(TempPointer+1) == L'-')\r
-       || (*TempPointer == L'^' && *(TempPointer+1) == L'/')\r
-       || (*TempPointer == L'^' && *(TempPointer+1) == L'+')\r
-      ){\r
+      if (  ((*TempPointer == L'^') && (*(TempPointer+1) == L'-'))\r
+         || ((*TempPointer == L'^') && (*(TempPointer+1) == L'/'))\r
+         || ((*TempPointer == L'^') && (*(TempPointer+1) == L'+'))\r
+            )\r
+      {\r
         TempPointer++;\r
       }\r
         TempPointer++;\r
       }\r
-      CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));\r
+\r
+      CurrentItemPackage = AllocateZeroPool (sizeof (SHELL_PARAM_PACKAGE));\r
       if (CurrentItemPackage == NULL) {\r
       if (CurrentItemPackage == NULL) {\r
-        ShellCommandLineFreeVarList(*CheckPackage);\r
+        ShellCommandLineFreeVarList (*CheckPackage);\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
+\r
       CurrentItemPackage->Name  = NULL;\r
       CurrentItemPackage->Type  = TypePosition;\r
       CurrentItemPackage->Name  = NULL;\r
       CurrentItemPackage->Type  = TypePosition;\r
-      CurrentItemPackage->Value = AllocateZeroPool(StrSize(TempPointer));\r
+      CurrentItemPackage->Value = AllocateCopyPool (StrSize (TempPointer), TempPointer);\r
       if (CurrentItemPackage->Value == NULL) {\r
       if (CurrentItemPackage->Value == NULL) {\r
-        ShellCommandLineFreeVarList(*CheckPackage);\r
+        ShellCommandLineFreeVarList (*CheckPackage);\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
         *CheckPackage = NULL;\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      StrCpy(CurrentItemPackage->Value, TempPointer);\r
+\r
       CurrentItemPackage->OriginalPosition = Count++;\r
       CurrentItemPackage->OriginalPosition = Count++;\r
-      InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+      InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);\r
     } else {\r
       //\r
       // this was a non-recognised flag... error!\r
       //\r
       if (ProblemParam != NULL) {\r
     } else {\r
       //\r
       // this was a non-recognised flag... error!\r
       //\r
       if (ProblemParam != NULL) {\r
-        *ProblemParam = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
-        if (*ProblemParam != NULL) {\r
-          StrCpy(*ProblemParam, Argv[LoopCounter]);\r
-        }\r
+        *ProblemParam = AllocateCopyPool (StrSize (Argv[LoopCounter]), Argv[LoopCounter]);\r
       }\r
       }\r
-      ShellCommandLineFreeVarList(*CheckPackage);\r
+\r
+      ShellCommandLineFreeVarList (*CheckPackage);\r
       *CheckPackage = NULL;\r
       return (EFI_VOLUME_CORRUPTED);\r
     }\r
   }\r
       *CheckPackage = NULL;\r
       return (EFI_VOLUME_CORRUPTED);\r
     }\r
   }\r
+\r
   if (GetItemValue != 0) {\r
     GetItemValue = 0;\r
   if (GetItemValue != 0) {\r
     GetItemValue = 0;\r
-    InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+    InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);\r
   }\r
   }\r
+\r
   //\r
   // support for AutoPageBreak\r
   //\r
   //\r
   // support for AutoPageBreak\r
   //\r
-  if (AutoPageBreak && ShellCommandLineGetFlag(*CheckPackage, L"-b")) {\r
-    ShellSetPageBreakMode(TRUE);\r
+  if (AutoPageBreak && ShellCommandLineGetFlag (*CheckPackage, L"-b")) {\r
+    ShellSetPageBreakMode (TRUE);\r
   }\r
   }\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -2162,43 +2384,47 @@ InternalCommandLineParse (
 EFI_STATUS\r
 EFIAPI\r
 ShellCommandLineParseEx (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellCommandLineParseEx (\r
-  IN CONST SHELL_PARAM_ITEM     *CheckList,\r
-  OUT LIST_ENTRY                **CheckPackage,\r
-  OUT CHAR16                    **ProblemParam OPTIONAL,\r
-  IN BOOLEAN                    AutoPageBreak,\r
-  IN BOOLEAN                    AlwaysAllowNumbers\r
+  IN CONST SHELL_PARAM_ITEM  *CheckList,\r
+  OUT LIST_ENTRY             **CheckPackage,\r
+  OUT CHAR16                 **ProblemParam OPTIONAL,\r
+  IN BOOLEAN                 AutoPageBreak,\r
+  IN BOOLEAN                 AlwaysAllowNumbers\r
   )\r
 {\r
   //\r
   // ASSERT that CheckList and CheckPackage aren't NULL\r
   //\r
   )\r
 {\r
   //\r
   // ASSERT that CheckList and CheckPackage aren't NULL\r
   //\r
-  ASSERT(CheckList    != NULL);\r
-  ASSERT(CheckPackage != NULL);\r
+  ASSERT (CheckList    != NULL);\r
+  ASSERT (CheckPackage != NULL);\r
 \r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellParametersProtocol != NULL) {\r
 \r
   //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (gEfiShellParametersProtocol != NULL) {\r
-    return (InternalCommandLineParse(CheckList,\r
-                                     CheckPackage,\r
-                                     ProblemParam,\r
-                                     AutoPageBreak,\r
-                                     (CONST CHAR16**) gEfiShellParametersProtocol->Argv,\r
-                                     gEfiShellParametersProtocol->Argc,\r
-                                     AlwaysAllowNumbers));\r
+    return (InternalCommandLineParse (\r
+              CheckList,\r
+              CheckPackage,\r
+              ProblemParam,\r
+              AutoPageBreak,\r
+              (CONST CHAR16 **)gEfiShellParametersProtocol->Argv,\r
+              gEfiShellParametersProtocol->Argc,\r
+              AlwaysAllowNumbers\r
+              ));\r
   }\r
 \r
   //\r
   // ASSERT That EFI Shell is not required\r
   //\r
   ASSERT (mEfiShellInterface != NULL);\r
   }\r
 \r
   //\r
   // ASSERT That EFI Shell is not required\r
   //\r
   ASSERT (mEfiShellInterface != NULL);\r
-  return (InternalCommandLineParse(CheckList,\r
-                                   CheckPackage,\r
-                                   ProblemParam,\r
-                                   AutoPageBreak,\r
-                                   (CONST CHAR16**) mEfiShellInterface->Argv,\r
-                                   mEfiShellInterface->Argc,\r
-                                   AlwaysAllowNumbers));\r
+  return (InternalCommandLineParse (\r
+            CheckList,\r
+            CheckPackage,\r
+            ProblemParam,\r
+            AutoPageBreak,\r
+            (CONST CHAR16 **)mEfiShellInterface->Argv,\r
+            mEfiShellInterface->Argc,\r
+            AlwaysAllowNumbers\r
+            ));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -2216,10 +2442,10 @@ ShellCommandLineParseEx (
 VOID\r
 EFIAPI\r
 ShellCommandLineFreeVarList (\r
 VOID\r
 EFIAPI\r
 ShellCommandLineFreeVarList (\r
-  IN LIST_ENTRY                 *CheckPackage\r
+  IN LIST_ENTRY  *CheckPackage\r
   )\r
 {\r
   )\r
 {\r
-  LIST_ENTRY                    *Node;\r
+  LIST_ENTRY  *Node;\r
 \r
   //\r
   // check for CheckPackage == NULL\r
 \r
   //\r
   // check for CheckPackage == NULL\r
@@ -2231,39 +2457,42 @@ ShellCommandLineFreeVarList (
   //\r
   // for each node in the list\r
   //\r
   //\r
   // for each node in the list\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage)\r
-      ; !IsListEmpty(CheckPackage)\r
-      ; Node = GetFirstNode(CheckPackage)\r
-     ){\r
+  for ( Node = GetFirstNode (CheckPackage)\r
+        ; !IsListEmpty (CheckPackage)\r
+        ; Node = GetFirstNode (CheckPackage)\r
+        )\r
+  {\r
     //\r
     // Remove it from the list\r
     //\r
     //\r
     // Remove it from the list\r
     //\r
-    RemoveEntryList(Node);\r
+    RemoveEntryList (Node);\r
 \r
     //\r
     // if it has a name free the name\r
     //\r
 \r
     //\r
     // if it has a name free the name\r
     //\r
-    if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r
-      FreePool(((SHELL_PARAM_PACKAGE*)Node)->Name);\r
+    if (((SHELL_PARAM_PACKAGE *)Node)->Name != NULL) {\r
+      FreePool (((SHELL_PARAM_PACKAGE *)Node)->Name);\r
     }\r
 \r
     //\r
     // if it has a value free the value\r
     //\r
     }\r
 \r
     //\r
     // if it has a value free the value\r
     //\r
-    if (((SHELL_PARAM_PACKAGE*)Node)->Value != NULL) {\r
-      FreePool(((SHELL_PARAM_PACKAGE*)Node)->Value);\r
+    if (((SHELL_PARAM_PACKAGE *)Node)->Value != NULL) {\r
+      FreePool (((SHELL_PARAM_PACKAGE *)Node)->Value);\r
     }\r
 \r
     //\r
     // free the node structure\r
     //\r
     }\r
 \r
     //\r
     // free the node structure\r
     //\r
-    FreePool((SHELL_PARAM_PACKAGE*)Node);\r
+    FreePool ((SHELL_PARAM_PACKAGE *)Node);\r
   }\r
   }\r
+\r
   //\r
   // free the list head node\r
   //\r
   //\r
   // free the list head node\r
   //\r
-  FreePool(CheckPackage);\r
+  FreePool (CheckPackage);\r
 }\r
 }\r
+\r
 /**\r
   Checks for presence of a flag parameter\r
 \r
 /**\r
   Checks for presence of a flag parameter\r
 \r
@@ -2281,54 +2510,59 @@ ShellCommandLineFreeVarList (
 BOOLEAN\r
 EFIAPI\r
 ShellCommandLineGetFlag (\r
 BOOLEAN\r
 EFIAPI\r
 ShellCommandLineGetFlag (\r
-  IN CONST LIST_ENTRY         * CONST CheckPackage,\r
-  IN CONST CHAR16             * CONST KeyString\r
+  IN CONST LIST_ENTRY         *CONST  CheckPackage,\r
+  IN CONST CHAR16             *CONST  KeyString\r
   )\r
 {\r
   )\r
 {\r
-  LIST_ENTRY                    *Node;\r
-  CHAR16                        *TempString;\r
+  LIST_ENTRY  *Node;\r
+  CHAR16      *TempString;\r
 \r
   //\r
   // return FALSE for no package or KeyString is NULL\r
   //\r
 \r
   //\r
   // return FALSE for no package or KeyString is NULL\r
   //\r
-  if (CheckPackage == NULL || KeyString == NULL) {\r
+  if ((CheckPackage == NULL) || (KeyString == NULL)) {\r
     return (FALSE);\r
   }\r
 \r
   //\r
   // enumerate through the list of parametrs\r
   //\r
     return (FALSE);\r
   }\r
 \r
   //\r
   // enumerate through the list of parametrs\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage)\r
-      ; !IsNull (CheckPackage, Node)\r
-      ; Node = GetNextNode(CheckPackage, Node)\r
-      ){\r
+  for ( Node = GetFirstNode (CheckPackage)\r
+        ; !IsNull (CheckPackage, Node)\r
+        ; Node = GetNextNode (CheckPackage, Node)\r
+        )\r
+  {\r
     //\r
     // If the Name matches, return TRUE (and there may be NULL name)\r
     //\r
     //\r
     // If the Name matches, return TRUE (and there may be NULL name)\r
     //\r
-    if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r
+    if (((SHELL_PARAM_PACKAGE *)Node)->Name != NULL) {\r
       //\r
       // If Type is TypeStart then only compare the begining of the strings\r
       //\r
       //\r
       // If Type is TypeStart then only compare the begining of the strings\r
       //\r
-      if (((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart) {\r
-        if (StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0) {\r
+      if (((SHELL_PARAM_PACKAGE *)Node)->Type == TypeStart) {\r
+        if (StrnCmp (KeyString, ((SHELL_PARAM_PACKAGE *)Node)->Name, StrLen (KeyString)) == 0) {\r
           return (TRUE);\r
         }\r
           return (TRUE);\r
         }\r
+\r
         TempString = NULL;\r
         TempString = NULL;\r
-        TempString = StrnCatGrow(&TempString, NULL, KeyString, StrLen(((SHELL_PARAM_PACKAGE*)Node)->Name));\r
+        TempString = StrnCatGrow (&TempString, NULL, KeyString, StrLen (((SHELL_PARAM_PACKAGE *)Node)->Name));\r
         if (TempString != NULL) {\r
         if (TempString != NULL) {\r
-          if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r
-            FreePool(TempString);\r
+          if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {\r
+            FreePool (TempString);\r
             return (TRUE);\r
           }\r
             return (TRUE);\r
           }\r
-          FreePool(TempString);\r
+\r
+          FreePool (TempString);\r
         }\r
         }\r
-      } else if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r
+      } else if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {\r
         return (TRUE);\r
       }\r
     }\r
   }\r
         return (TRUE);\r
       }\r
     }\r
   }\r
+\r
   return (FALSE);\r
 }\r
   return (FALSE);\r
 }\r
+\r
 /**\r
   Returns value from command line argument.\r
 \r
 /**\r
   Returns value from command line argument.\r
 \r
@@ -2342,55 +2576,59 @@ ShellCommandLineGetFlag (
   @retval NULL                  The flag is not on the command line.\r
   @retval !=NULL                The pointer to unicode string of the value.\r
 **/\r
   @retval NULL                  The flag is not on the command line.\r
   @retval !=NULL                The pointer to unicode string of the value.\r
 **/\r
-CONST CHAR16*\r
+CONST CHAR16 *\r
 EFIAPI\r
 ShellCommandLineGetValue (\r
 EFIAPI\r
 ShellCommandLineGetValue (\r
-  IN CONST LIST_ENTRY           *CheckPackage,\r
-  IN CHAR16                     *KeyString\r
+  IN CONST LIST_ENTRY  *CheckPackage,\r
+  IN CHAR16            *KeyString\r
   )\r
 {\r
   )\r
 {\r
-  LIST_ENTRY                    *Node;\r
-  CHAR16                        *TempString;\r
+  LIST_ENTRY  *Node;\r
+  CHAR16      *TempString;\r
 \r
   //\r
   // return NULL for no package or KeyString is NULL\r
   //\r
 \r
   //\r
   // return NULL for no package or KeyString is NULL\r
   //\r
-  if (CheckPackage == NULL || KeyString == NULL) {\r
+  if ((CheckPackage == NULL) || (KeyString == NULL)) {\r
     return (NULL);\r
   }\r
 \r
   //\r
   // enumerate through the list of parametrs\r
   //\r
     return (NULL);\r
   }\r
 \r
   //\r
   // enumerate through the list of parametrs\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage)\r
-      ; !IsNull (CheckPackage, Node)\r
-      ; Node = GetNextNode(CheckPackage, Node)\r
-      ){\r
+  for ( Node = GetFirstNode (CheckPackage)\r
+        ; !IsNull (CheckPackage, Node)\r
+        ; Node = GetNextNode (CheckPackage, Node)\r
+        )\r
+  {\r
     //\r
     // If the Name matches, return TRUE (and there may be NULL name)\r
     //\r
     //\r
     // If the Name matches, return TRUE (and there may be NULL name)\r
     //\r
-    if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r
+    if (((SHELL_PARAM_PACKAGE *)Node)->Name != NULL) {\r
       //\r
       // If Type is TypeStart then only compare the begining of the strings\r
       //\r
       //\r
       // If Type is TypeStart then only compare the begining of the strings\r
       //\r
-      if (((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart) {\r
-        if (StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0) {\r
-          return (((SHELL_PARAM_PACKAGE*)Node)->Name + StrLen(KeyString));\r
+      if (((SHELL_PARAM_PACKAGE *)Node)->Type == TypeStart) {\r
+        if (StrnCmp (KeyString, ((SHELL_PARAM_PACKAGE *)Node)->Name, StrLen (KeyString)) == 0) {\r
+          return (((SHELL_PARAM_PACKAGE *)Node)->Name + StrLen (KeyString));\r
         }\r
         }\r
+\r
         TempString = NULL;\r
         TempString = NULL;\r
-        TempString = StrnCatGrow(&TempString, NULL, KeyString, StrLen(((SHELL_PARAM_PACKAGE*)Node)->Name));\r
+        TempString = StrnCatGrow (&TempString, NULL, KeyString, StrLen (((SHELL_PARAM_PACKAGE *)Node)->Name));\r
         if (TempString != NULL) {\r
         if (TempString != NULL) {\r
-          if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r
-            FreePool(TempString);\r
-            return (((SHELL_PARAM_PACKAGE*)Node)->Name + StrLen(KeyString));\r
+          if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {\r
+            FreePool (TempString);\r
+            return (((SHELL_PARAM_PACKAGE *)Node)->Name + StrLen (KeyString));\r
           }\r
           }\r
-          FreePool(TempString);\r
+\r
+          FreePool (TempString);\r
         }\r
         }\r
-      } else if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r
-        return (((SHELL_PARAM_PACKAGE*)Node)->Value);\r
+      } else if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {\r
+        return (((SHELL_PARAM_PACKAGE *)Node)->Value);\r
       }\r
     }\r
   }\r
       }\r
     }\r
   }\r
+\r
   return (NULL);\r
 }\r
 \r
   return (NULL);\r
 }\r
 \r
@@ -2407,14 +2645,14 @@ ShellCommandLineGetValue (
   @retval NULL                  The flag is not on the command line.\r
   @retval !=NULL                The pointer to unicode string of the value.\r
   **/\r
   @retval NULL                  The flag is not on the command line.\r
   @retval !=NULL                The pointer to unicode string of the value.\r
   **/\r
-CONST CHAR16*\r
+CONST CHAR16 *\r
 EFIAPI\r
 ShellCommandLineGetRawValue (\r
 EFIAPI\r
 ShellCommandLineGetRawValue (\r
-  IN CONST LIST_ENTRY           * CONST CheckPackage,\r
-  IN UINTN                      Position\r
+  IN CONST LIST_ENTRY           *CONST  CheckPackage,\r
+  IN UINTN                              Position\r
   )\r
 {\r
   )\r
 {\r
-  LIST_ENTRY                    *Node;\r
+  LIST_ENTRY  *Node;\r
 \r
   //\r
   // check for CheckPackage == NULL\r
 \r
   //\r
   // check for CheckPackage == NULL\r
@@ -2426,17 +2664,19 @@ ShellCommandLineGetRawValue (
   //\r
   // enumerate through the list of parametrs\r
   //\r
   //\r
   // enumerate through the list of parametrs\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage)\r
-      ; !IsNull (CheckPackage, Node)\r
-      ; Node = GetNextNode(CheckPackage, Node)\r
-     ){\r
+  for ( Node = GetFirstNode (CheckPackage)\r
+        ; !IsNull (CheckPackage, Node)\r
+        ; Node = GetNextNode (CheckPackage, Node)\r
+        )\r
+  {\r
     //\r
     // If the position matches, return the value\r
     //\r
     //\r
     // If the position matches, return the value\r
     //\r
-    if (((SHELL_PARAM_PACKAGE*)Node)->OriginalPosition == Position) {\r
-      return (((SHELL_PARAM_PACKAGE*)Node)->Value);\r
+    if (((SHELL_PARAM_PACKAGE *)Node)->OriginalPosition == Position) {\r
+      return (((SHELL_PARAM_PACKAGE *)Node)->Value);\r
     }\r
   }\r
     }\r
   }\r
+\r
   return (NULL);\r
 }\r
 \r
   return (NULL);\r
 }\r
 \r
@@ -2452,8 +2692,8 @@ ShellCommandLineGetRawValue (
 **/\r
 UINTN\r
 EFIAPI\r
 **/\r
 UINTN\r
 EFIAPI\r
-ShellCommandLineGetCount(\r
-  IN CONST LIST_ENTRY              *CheckPackage\r
+ShellCommandLineGetCount (\r
+  IN CONST LIST_ENTRY  *CheckPackage\r
   )\r
 {\r
   LIST_ENTRY  *Node1;\r
   )\r
 {\r
   LIST_ENTRY  *Node1;\r
@@ -2462,19 +2702,22 @@ ShellCommandLineGetCount(
   if (CheckPackage == NULL) {\r
     return (0);\r
   }\r
   if (CheckPackage == NULL) {\r
     return (0);\r
   }\r
-  for ( Node1 = GetFirstNode(CheckPackage), Count = 0\r
-      ; !IsNull (CheckPackage, Node1)\r
-      ; Node1 = GetNextNode(CheckPackage, Node1)\r
-     ){\r
-    if (((SHELL_PARAM_PACKAGE*)Node1)->Name == NULL) {\r
+\r
+  for ( Node1 = GetFirstNode (CheckPackage), Count = 0\r
+        ; !IsNull (CheckPackage, Node1)\r
+        ; Node1 = GetNextNode (CheckPackage, Node1)\r
+        )\r
+  {\r
+    if (((SHELL_PARAM_PACKAGE *)Node1)->Name == NULL) {\r
       Count++;\r
     }\r
   }\r
       Count++;\r
     }\r
   }\r
+\r
   return (Count);\r
 }\r
 \r
 /**\r
   return (Count);\r
 }\r
 \r
 /**\r
-  Determins if a parameter is duplicated.\r
+  Determines if a parameter is duplicated.\r
 \r
   If Param is not NULL then it will point to a callee allocated string buffer\r
   with the parameter value if a duplicate is found.\r
 \r
   If Param is not NULL then it will point to a callee allocated string buffer\r
   with the parameter value if a duplicate is found.\r
@@ -2490,32 +2733,36 @@ ShellCommandLineGetCount(
 EFI_STATUS\r
 EFIAPI\r
 ShellCommandLineCheckDuplicate (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellCommandLineCheckDuplicate (\r
-  IN CONST LIST_ENTRY              *CheckPackage,\r
-  OUT CHAR16                       **Param\r
+  IN CONST LIST_ENTRY  *CheckPackage,\r
+  OUT CHAR16           **Param\r
   )\r
 {\r
   )\r
 {\r
-  LIST_ENTRY                    *Node1;\r
-  LIST_ENTRY                    *Node2;\r
-\r
-  ASSERT(CheckPackage != NULL);\r
-\r
-  for ( Node1 = GetFirstNode(CheckPackage)\r
-      ; !IsNull (CheckPackage, Node1)\r
-      ; Node1 = GetNextNode(CheckPackage, Node1)\r
-     ){\r
-    for ( Node2 = GetNextNode(CheckPackage, Node1)\r
-        ; !IsNull (CheckPackage, Node2)\r
-        ; Node2 = GetNextNode(CheckPackage, Node2)\r
-       ){\r
-      if ((((SHELL_PARAM_PACKAGE*)Node1)->Name != NULL) && (((SHELL_PARAM_PACKAGE*)Node2)->Name != NULL) && StrCmp(((SHELL_PARAM_PACKAGE*)Node1)->Name, ((SHELL_PARAM_PACKAGE*)Node2)->Name) == 0) {\r
+  LIST_ENTRY  *Node1;\r
+  LIST_ENTRY  *Node2;\r
+\r
+  ASSERT (CheckPackage != NULL);\r
+\r
+  for ( Node1 = GetFirstNode (CheckPackage)\r
+        ; !IsNull (CheckPackage, Node1)\r
+        ; Node1 = GetNextNode (CheckPackage, Node1)\r
+        )\r
+  {\r
+    for ( Node2 = GetNextNode (CheckPackage, Node1)\r
+          ; !IsNull (CheckPackage, Node2)\r
+          ; Node2 = GetNextNode (CheckPackage, Node2)\r
+          )\r
+    {\r
+      if ((((SHELL_PARAM_PACKAGE *)Node1)->Name != NULL) && (((SHELL_PARAM_PACKAGE *)Node2)->Name != NULL) && (StrCmp (((SHELL_PARAM_PACKAGE *)Node1)->Name, ((SHELL_PARAM_PACKAGE *)Node2)->Name) == 0)) {\r
         if (Param != NULL) {\r
           *Param = NULL;\r
         if (Param != NULL) {\r
           *Param = NULL;\r
-          *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);\r
+          *Param = StrnCatGrow (Param, NULL, ((SHELL_PARAM_PACKAGE *)Node1)->Name, 0);\r
         }\r
         }\r
+\r
         return (EFI_DEVICE_ERROR);\r
       }\r
     }\r
   }\r
         return (EFI_DEVICE_ERROR);\r
       }\r
     }\r
   }\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -2548,67 +2795,75 @@ ShellCommandLineCheckDuplicate (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellCopySearchAndReplace(\r
-  IN CHAR16 CONST                     *SourceString,\r
-  IN OUT CHAR16                       *NewString,\r
-  IN UINTN                            NewSize,\r
-  IN CONST CHAR16                     *FindTarget,\r
-  IN CONST CHAR16                     *ReplaceWith,\r
-  IN CONST BOOLEAN                    SkipPreCarrot,\r
-  IN CONST BOOLEAN                    ParameterReplacing\r
+ShellCopySearchAndReplace (\r
+  IN CHAR16 CONST   *SourceString,\r
+  IN OUT CHAR16     *NewString,\r
+  IN UINTN          NewSize,\r
+  IN CONST CHAR16   *FindTarget,\r
+  IN CONST CHAR16   *ReplaceWith,\r
+  IN CONST BOOLEAN  SkipPreCarrot,\r
+  IN CONST BOOLEAN  ParameterReplacing\r
   )\r
 {\r
   )\r
 {\r
-  UINTN Size;\r
-  CHAR16 *Replace;\r
-\r
-  if ( (SourceString == NULL)\r
-    || (NewString    == NULL)\r
-    || (FindTarget   == NULL)\r
-    || (ReplaceWith  == NULL)\r
-    || (StrLen(FindTarget) < 1)\r
-    || (StrLen(SourceString) < 1)\r
-   ){\r
+  UINTN   Size;\r
+  CHAR16  *Replace;\r
+\r
+  if (  (SourceString == NULL)\r
+     || (NewString    == NULL)\r
+     || (FindTarget   == NULL)\r
+     || (ReplaceWith  == NULL)\r
+     || (StrLen (FindTarget) < 1)\r
+     || (StrLen (SourceString) < 1)\r
+        )\r
+  {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
+\r
   Replace = NULL;\r
   Replace = NULL;\r
-  if (StrStr(ReplaceWith, L" ") == NULL || !ParameterReplacing) {\r
-    Replace = StrnCatGrow(&Replace, NULL, ReplaceWith, 0);\r
+  if ((StrStr (ReplaceWith, L" ") == NULL) || !ParameterReplacing) {\r
+    Replace = StrnCatGrow (&Replace, NULL, ReplaceWith, 0);\r
   } else {\r
   } else {\r
-    Replace = AllocateZeroPool(StrSize(ReplaceWith) + 2*sizeof(CHAR16));\r
+    Replace = AllocateZeroPool (StrSize (ReplaceWith) + 2*sizeof (CHAR16));\r
     if (Replace != NULL) {\r
     if (Replace != NULL) {\r
-      UnicodeSPrint(Replace, StrSize(ReplaceWith) + 2*sizeof(CHAR16), L"\"%s\"", ReplaceWith);\r
+      UnicodeSPrint (Replace, StrSize (ReplaceWith) + 2*sizeof (CHAR16), L"\"%s\"", ReplaceWith);\r
     }\r
   }\r
     }\r
   }\r
+\r
   if (Replace == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
   if (Replace == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r
+\r
+  NewString = ZeroMem (NewString, NewSize);\r
   while (*SourceString != CHAR_NULL) {\r
     //\r
     // if we find the FindTarget and either Skip == FALSE or Skip  and we\r
     // dont have a carrot do a replace...\r
     //\r
   while (*SourceString != CHAR_NULL) {\r
     //\r
     // if we find the FindTarget and either Skip == FALSE or Skip  and we\r
     // dont have a carrot do a replace...\r
     //\r
-    if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0\r
-      && ((SkipPreCarrot && *(SourceString-1) != L'^') || !SkipPreCarrot)\r
-     ){\r
-      SourceString += StrLen(FindTarget);\r
-      Size = StrSize(NewString);\r
-      if ((Size + (StrLen(Replace)*sizeof(CHAR16))) > NewSize) {\r
-        FreePool(Replace);\r
+    if (  (StrnCmp (SourceString, FindTarget, StrLen (FindTarget)) == 0)\r
+       && ((SkipPreCarrot && (*(SourceString-1) != L'^')) || !SkipPreCarrot)\r
+          )\r
+    {\r
+      SourceString += StrLen (FindTarget);\r
+      Size          = StrSize (NewString);\r
+      if ((Size + (StrLen (Replace)*sizeof (CHAR16))) > NewSize) {\r
+        FreePool (Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrCat(NewString, Replace);\r
+\r
+      StrCatS (NewString, NewSize/sizeof (CHAR16), Replace);\r
     } else {\r
     } else {\r
-      Size = StrSize(NewString);\r
-      if (Size + sizeof(CHAR16) > NewSize) {\r
-        FreePool(Replace);\r
+      Size = StrSize (NewString);\r
+      if (Size + sizeof (CHAR16) > NewSize) {\r
+        FreePool (Replace);\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
         return (EFI_BUFFER_TOO_SMALL);\r
       }\r
-      StrnCat(NewString, SourceString, 1);\r
+\r
+      StrnCatS (NewString, NewSize/sizeof (CHAR16), SourceString, 1);\r
       SourceString++;\r
     }\r
   }\r
       SourceString++;\r
     }\r
   }\r
-  FreePool(Replace);\r
+\r
+  FreePool (Replace);\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -2623,29 +2878,33 @@ ShellCopySearchAndReplace(
   @retval !EFI_SUCCESS    The operation failed.\r
 **/\r
 EFI_STATUS\r
   @retval !EFI_SUCCESS    The operation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalPrintTo (\r
 InternalPrintTo (\r
-  IN CONST CHAR16 *String\r
+  IN CONST CHAR16  *String\r
   )\r
 {\r
   )\r
 {\r
-  UINTN Size;\r
-  Size = StrSize(String) - sizeof(CHAR16);\r
+  UINTN  Size;\r
+\r
+  Size = StrSize (String) - sizeof (CHAR16);\r
   if (Size == 0) {\r
     return (EFI_SUCCESS);\r
   }\r
   if (Size == 0) {\r
     return (EFI_SUCCESS);\r
   }\r
+\r
   if (gEfiShellParametersProtocol != NULL) {\r
   if (gEfiShellParametersProtocol != NULL) {\r
-    return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
+    return (gEfiShellProtocol->WriteFile (gEfiShellParametersProtocol->StdOut, &Size, (VOID *)String));\r
   }\r
   }\r
+\r
   if (mEfiShellInterface          != NULL) {\r
   if (mEfiShellInterface          != NULL) {\r
-    if (mEfiShellInterface->RedirArgc == 0) { \r
-    //\r
-    // Divide in half for old shell.  Must be string length not size.\r
-      // \r
-      Size /=2;  // Divide in half only when no redirection.\r
+    if (mEfiShellInterface->RedirArgc == 0) {\r
+      //\r
+      // Divide in half for old shell.  Must be string length not size.\r
+      //\r
+      Size /= 2;  // Divide in half only when no redirection.\r
     }\r
     }\r
-    return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
+\r
+    return (mEfiShellInterface->StdOut->Write (mEfiShellInterface->StdOut, &Size, (VOID *)String));\r
   }\r
   }\r
-  ASSERT(FALSE);\r
+\r
+  ASSERT (FALSE);\r
   return (EFI_UNSUPPORTED);\r
 }\r
 \r
   return (EFI_UNSUPPORTED);\r
 }\r
 \r
@@ -2679,27 +2938,26 @@ InternalPrintTo (
   @return EFI_DEVICE_ERROR      The console device reported an error.\r
 **/\r
 EFI_STATUS\r
   @return EFI_DEVICE_ERROR      The console device reported an error.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-InternalShellPrintWorker(\r
-  IN INT32                Col OPTIONAL,\r
-  IN INT32                Row OPTIONAL,\r
-  IN CONST CHAR16         *Format,\r
-  IN VA_LIST              Marker\r
+InternalShellPrintWorker (\r
+  IN INT32         Col OPTIONAL,\r
+  IN INT32         Row OPTIONAL,\r
+  IN CONST CHAR16  *Format,\r
+  IN VA_LIST       Marker\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  CHAR16            *ResumeLocation;\r
-  CHAR16            *FormatWalker;\r
-  UINTN             OriginalAttribute;\r
-  CHAR16            *mPostReplaceFormat;\r
-  CHAR16            *mPostReplaceFormat2;\r
-\r
-  mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
+  EFI_STATUS  Status;\r
+  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
   mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
 \r
-  if (mPostReplaceFormat == NULL || mPostReplaceFormat2 == NULL) {\r
-    SHELL_FREE_NON_NULL(mPostReplaceFormat);\r
-    SHELL_FREE_NON_NULL(mPostReplaceFormat2);\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
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
@@ -2709,24 +2967,24 @@ InternalShellPrintWorker(
   //\r
   // Back and forth each time fixing up 1 of our flags...\r
   //\r
   //\r
   // Back and forth each time fixing up 1 of our flags...\r
   //\r
-  Status = ShellCopySearchAndReplace(Format,             mPostReplaceFormat,  PcdGet16 (PcdShellPrintBufferSize), L"%N", L"%%N", FALSE, FALSE);\r
-  ASSERT_EFI_ERROR(Status);\r
-  Status = ShellCopySearchAndReplace(mPostReplaceFormat,  mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%E", L"%%E", FALSE, FALSE);\r
-  ASSERT_EFI_ERROR(Status);\r
-  Status = ShellCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat,  PcdGet16 (PcdShellPrintBufferSize), L"%H", L"%%H", FALSE, FALSE);\r
-  ASSERT_EFI_ERROR(Status);\r
-  Status = ShellCopySearchAndReplace(mPostReplaceFormat,  mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%B", L"%%B", FALSE, FALSE);\r
-  ASSERT_EFI_ERROR(Status);\r
-  Status = ShellCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat,  PcdGet16 (PcdShellPrintBufferSize), L"%V", L"%%V", FALSE, FALSE);\r
-  ASSERT_EFI_ERROR(Status);\r
+  Status = ShellCopySearchAndReplace (Format, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%N", L"%%N", FALSE, FALSE);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = ShellCopySearchAndReplace (mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%E", L"%%E", FALSE, FALSE);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = ShellCopySearchAndReplace (mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%H", L"%%H", FALSE, FALSE);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = ShellCopySearchAndReplace (mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%B", L"%%B", FALSE, FALSE);\r
+  ASSERT_EFI_ERROR (Status);\r
+  Status = ShellCopySearchAndReplace (mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%V", L"%%V", FALSE, FALSE);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
   // Use the last buffer from replacing to print from...\r
   //\r
   UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), mPostReplaceFormat, Marker);\r
 \r
 \r
   //\r
   // Use the last buffer from replacing to print from...\r
   //\r
   UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), mPostReplaceFormat, Marker);\r
 \r
-  if (Col != -1 && Row != -1) {\r
-    Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r
+  if ((Col != -1) && (Row != -1)) {\r
+    Status = gST->ConOut->SetCursorPosition (gST->ConOut, Col, Row);\r
   }\r
 \r
   FormatWalker = mPostReplaceFormat2;\r
   }\r
 \r
   FormatWalker = mPostReplaceFormat2;\r
@@ -2734,16 +2992,17 @@ InternalShellPrintWorker(
     //\r
     // Find the next attribute change request\r
     //\r
     //\r
     // Find the next attribute change request\r
     //\r
-    ResumeLocation = StrStr(FormatWalker, L"%");\r
+    ResumeLocation = StrStr (FormatWalker, L"%");\r
     if (ResumeLocation != NULL) {\r
       *ResumeLocation = CHAR_NULL;\r
     }\r
     if (ResumeLocation != NULL) {\r
       *ResumeLocation = CHAR_NULL;\r
     }\r
+\r
     //\r
     // print the current FormatWalker string\r
     //\r
     //\r
     // print the current FormatWalker string\r
     //\r
-    if (StrLen(FormatWalker)>0) {\r
-      Status = InternalPrintTo(FormatWalker);\r
-      if (EFI_ERROR(Status)) {\r
+    if (StrLen (FormatWalker) > 0) {\r
+      Status = InternalPrintTo (FormatWalker);\r
+      if (EFI_ERROR (Status)) {\r
         break;\r
       }\r
     }\r
         break;\r
       }\r
     }\r
@@ -2752,42 +3011,43 @@ InternalShellPrintWorker(
     // update the attribute\r
     //\r
     if (ResumeLocation != NULL) {\r
     // update the attribute\r
     //\r
     if (ResumeLocation != NULL) {\r
-      if (*(ResumeLocation-1) == L'^') {\r
+      if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-1) == L'^')) {\r
         //\r
         // Move cursor back 1 position to overwrite the ^\r
         //\r
         //\r
         // Move cursor back 1 position to overwrite the ^\r
         //\r
-        gST->ConOut->SetCursorPosition(gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);\r
+        gST->ConOut->SetCursorPosition (gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);\r
 \r
         //\r
         // Print a simple '%' symbol\r
         //\r
 \r
         //\r
         // Print a simple '%' symbol\r
         //\r
-        Status = InternalPrintTo(L"%");\r
+        Status         = InternalPrintTo (L"%");\r
         ResumeLocation = ResumeLocation - 1;\r
       } else {\r
         switch (*(ResumeLocation+1)) {\r
           case (L'N'):\r
         ResumeLocation = ResumeLocation - 1;\r
       } else {\r
         switch (*(ResumeLocation+1)) {\r
           case (L'N'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);\r
+            gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);\r
             break;\r
           case (L'E'):\r
             break;\r
           case (L'E'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_YELLOW, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
+            gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_YELLOW, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           case (L'H'):\r
             break;\r
           case (L'H'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
+            gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           case (L'B'):\r
             break;\r
           case (L'B'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
+            gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTBLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           case (L'V'):\r
             break;\r
           case (L'V'):\r
-            gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
+            gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
             break;\r
           default:\r
             //\r
             // Print a simple '%' symbol\r
             //\r
             break;\r
           default:\r
             //\r
             // Print a simple '%' symbol\r
             //\r
-            Status = InternalPrintTo(L"%");\r
-            if (EFI_ERROR(Status)) {\r
+            Status = InternalPrintTo (L"%");\r
+            if (EFI_ERROR (Status)) {\r
               break;\r
             }\r
               break;\r
             }\r
+\r
             ResumeLocation = ResumeLocation - 1;\r
             break;\r
         }\r
             ResumeLocation = ResumeLocation - 1;\r
             break;\r
         }\r
@@ -2805,10 +3065,10 @@ InternalShellPrintWorker(
     FormatWalker = ResumeLocation + 2;\r
   }\r
 \r
     FormatWalker = ResumeLocation + 2;\r
   }\r
 \r
-  gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);\r
+  gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);\r
 \r
 \r
-  SHELL_FREE_NON_NULL(mPostReplaceFormat);\r
-  SHELL_FREE_NON_NULL(mPostReplaceFormat2);\r
+  SHELL_FREE_NON_NULL (mPostReplaceFormat);\r
+  SHELL_FREE_NON_NULL (mPostReplaceFormat2);\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -2843,22 +3103,24 @@ InternalShellPrintWorker(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellPrintEx(\r
-  IN INT32                Col OPTIONAL,\r
-  IN INT32                Row OPTIONAL,\r
-  IN CONST CHAR16         *Format,\r
+ShellPrintEx (\r
+  IN INT32         Col OPTIONAL,\r
+  IN INT32         Row OPTIONAL,\r
+  IN CONST CHAR16  *Format,\r
   ...\r
   )\r
 {\r
   ...\r
   )\r
 {\r
-  VA_LIST           Marker;\r
-  EFI_STATUS        RetVal;\r
+  VA_LIST     Marker;\r
+  EFI_STATUS  RetVal;\r
+\r
   if (Format == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
   if (Format == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
+\r
   VA_START (Marker, Format);\r
   VA_START (Marker, Format);\r
-  RetVal = InternalShellPrintWorker(Col, Row, Format, Marker);\r
-  VA_END(Marker);\r
-  return(RetVal);\r
+  RetVal = InternalShellPrintWorker (Col, Row, Format, Marker);\r
+  VA_END (Marker);\r
+  return (RetVal);\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -2895,27 +3157,29 @@ ShellPrintEx(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellPrintHiiEx(\r
-  IN INT32                Col OPTIONAL,\r
-  IN INT32                Row OPTIONAL,\r
-  IN CONST CHAR8          *Language OPTIONAL,\r
-  IN CONST EFI_STRING_ID  HiiFormatStringId,\r
-  IN CONST EFI_HANDLE     HiiFormatHandle,\r
+ShellPrintHiiEx (\r
+  IN INT32                 Col OPTIONAL,\r
+  IN INT32                 Row OPTIONAL,\r
+  IN CONST CHAR8           *Language OPTIONAL,\r
+  IN CONST EFI_STRING_ID   HiiFormatStringId,\r
+  IN CONST EFI_HII_HANDLE  HiiFormatHandle,\r
   ...\r
   )\r
 {\r
   ...\r
   )\r
 {\r
-  VA_LIST           Marker;\r
-  CHAR16            *HiiFormatString;\r
-  EFI_STATUS        RetVal;\r
+  VA_LIST     Marker;\r
+  CHAR16      *HiiFormatString;\r
+  EFI_STATUS  RetVal;\r
 \r
 \r
-  VA_START (Marker, HiiFormatHandle);\r
-  HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language);\r
-  ASSERT(HiiFormatString != NULL);\r
+  RetVal = EFI_DEVICE_ERROR;\r
 \r
 \r
-  RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r
+  VA_START (Marker, HiiFormatHandle);\r
+  HiiFormatString = HiiGetString (HiiFormatHandle, HiiFormatStringId, Language);\r
+  if (HiiFormatString != NULL) {\r
+    RetVal = InternalShellPrintWorker (Col, Row, HiiFormatString, Marker);\r
+    SHELL_FREE_NON_NULL (HiiFormatString);\r
+  }\r
 \r
 \r
-  SHELL_FREE_NON_NULL(HiiFormatString);\r
-  VA_END(Marker);\r
+  VA_END (Marker);\r
 \r
   return (RetVal);\r
 }\r
 \r
   return (RetVal);\r
 }\r
@@ -2932,57 +3196,62 @@ ShellPrintHiiEx(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellIsDirectory(\r
-  IN CONST CHAR16 *DirName\r
+ShellIsDirectory (\r
+  IN CONST CHAR16  *DirName\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  SHELL_FILE_HANDLE Handle;\r
-  CHAR16            *TempLocation;\r
-  CHAR16            *TempLocation2;\r
+  EFI_STATUS         Status;\r
+  SHELL_FILE_HANDLE  Handle;\r
+  CHAR16             *TempLocation;\r
+  CHAR16             *TempLocation2;\r
 \r
 \r
-  ASSERT(DirName != NULL);\r
+  ASSERT (DirName != NULL);\r
 \r
 \r
-  Handle        = NULL;\r
-  TempLocation  = NULL;\r
+  Handle       = NULL;\r
+  TempLocation = NULL;\r
 \r
 \r
-  Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = ShellOpenFileByName (DirName, &Handle, EFI_FILE_MODE_READ, 0);\r
+  if (EFI_ERROR (Status)) {\r
     //\r
     // try good logic first.\r
     //\r
     if (gEfiShellProtocol != NULL) {\r
     //\r
     // try good logic first.\r
     //\r
     if (gEfiShellProtocol != NULL) {\r
-      TempLocation  = StrnCatGrow(&TempLocation, NULL, DirName, 0);\r
+      TempLocation = StrnCatGrow (&TempLocation, NULL, DirName, 0);\r
       if (TempLocation == NULL) {\r
       if (TempLocation == NULL) {\r
-        ShellCloseFile(&Handle);\r
+        ShellCloseFile (&Handle);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
-      TempLocation2 = StrStr(TempLocation, L":");\r
-      if (TempLocation2 != NULL && StrLen(StrStr(TempLocation, L":")) == 2) {\r
+\r
+      TempLocation2 = StrStr (TempLocation, L":");\r
+      if ((TempLocation2 != NULL) && (StrLen (StrStr (TempLocation, L":")) == 2)) {\r
         *(TempLocation2+1) = CHAR_NULL;\r
       }\r
         *(TempLocation2+1) = CHAR_NULL;\r
       }\r
-      if (gEfiShellProtocol->GetDevicePathFromMap(TempLocation) != NULL) {\r
-        FreePool(TempLocation);\r
+\r
+      if (gEfiShellProtocol->GetDevicePathFromMap (TempLocation) != NULL) {\r
+        FreePool (TempLocation);\r
         return (EFI_SUCCESS);\r
       }\r
         return (EFI_SUCCESS);\r
       }\r
-      FreePool(TempLocation);\r
+\r
+      FreePool (TempLocation);\r
     } else {\r
       //\r
       // probably a map name?!?!!?\r
       //\r
     } else {\r
       //\r
       // probably a map name?!?!!?\r
       //\r
-      TempLocation = StrStr(DirName, L"\\");\r
-      if (TempLocation != NULL && *(TempLocation+1) == CHAR_NULL) {\r
+      TempLocation = StrStr (DirName, L"\\");\r
+      if ((TempLocation != NULL) && (*(TempLocation+1) == CHAR_NULL)) {\r
         return (EFI_SUCCESS);\r
       }\r
     }\r
         return (EFI_SUCCESS);\r
       }\r
     }\r
+\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-  if (FileHandleIsDirectory(Handle) == EFI_SUCCESS) {\r
-    ShellCloseFile(&Handle);\r
+  if (FileHandleIsDirectory (Handle) == EFI_SUCCESS) {\r
+    ShellCloseFile (&Handle);\r
     return (EFI_SUCCESS);\r
   }\r
     return (EFI_SUCCESS);\r
   }\r
-  ShellCloseFile(&Handle);\r
+\r
+  ShellCloseFile (&Handle);\r
   return (EFI_NOT_FOUND);\r
 }\r
 \r
   return (EFI_NOT_FOUND);\r
 }\r
 \r
@@ -2997,27 +3266,28 @@ ShellIsDirectory(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellIsFile(\r
-  IN CONST CHAR16 *Name\r
+ShellIsFile (\r
+  IN CONST CHAR16  *Name\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  SHELL_FILE_HANDLE            Handle;\r
+  EFI_STATUS         Status;\r
+  SHELL_FILE_HANDLE  Handle;\r
 \r
 \r
-  ASSERT(Name != NULL);\r
+  ASSERT (Name != NULL);\r
 \r
   Handle = NULL;\r
 \r
 \r
   Handle = NULL;\r
 \r
-  Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = ShellOpenFileByName (Name, &Handle, EFI_FILE_MODE_READ, 0);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-  if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
-    ShellCloseFile(&Handle);\r
+  if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {\r
+    ShellCloseFile (&Handle);\r
     return (EFI_SUCCESS);\r
   }\r
     return (EFI_SUCCESS);\r
   }\r
-  ShellCloseFile(&Handle);\r
+\r
+  ShellCloseFile (&Handle);\r
   return (EFI_NOT_FOUND);\r
 }\r
 \r
   return (EFI_NOT_FOUND);\r
 }\r
 \r
@@ -3036,26 +3306,53 @@ ShellIsFile(
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellIsFileInPath(\r
-  IN CONST CHAR16 *Name\r
+ShellIsFileInPath (\r
+  IN CONST CHAR16  *Name\r
   )\r
 {\r
   CHAR16      *NewName;\r
   EFI_STATUS  Status;\r
 \r
   )\r
 {\r
   CHAR16      *NewName;\r
   EFI_STATUS  Status;\r
 \r
-  if (!EFI_ERROR(ShellIsFile(Name))) {\r
+  if (!EFI_ERROR (ShellIsFile (Name))) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
     return (EFI_SUCCESS);\r
   }\r
 \r
-  NewName = ShellFindFilePath(Name);\r
+  NewName = ShellFindFilePath (Name);\r
   if (NewName == NULL) {\r
     return (EFI_NOT_FOUND);\r
   }\r
   if (NewName == NULL) {\r
     return (EFI_NOT_FOUND);\r
   }\r
-  Status = ShellIsFile(NewName);\r
-  FreePool(NewName);\r
+\r
+  Status = ShellIsFile (NewName);\r
+  FreePool (NewName);\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
+/**\r
+  Function return the number converted from a hex representation of a number.\r
+\r
+  Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid\r
+  result.  Use ShellConvertStringToUint64 instead.\r
+\r
+  @param[in] String   String representation of a number.\r
+\r
+  @return             The unsigned integer result of the conversion.\r
+  @retval (UINTN)(-1) An error occurred.\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellHexStrToUintn (\r
+  IN CONST CHAR16  *String\r
+  )\r
+{\r
+  UINT64  RetVal;\r
+\r
+  if (!EFI_ERROR (ShellConvertStringToUint64 (String, &RetVal, TRUE, TRUE))) {\r
+    return ((UINTN)RetVal);\r
+  }\r
+\r
+  return ((UINTN)(-1));\r
+}\r
+\r
 /**\r
   Function to determine whether a string is decimal or hex representation of a number\r
   and return the number converted from the string.  Spaces are always skipped.\r
 /**\r
   Function to determine whether a string is decimal or hex representation of a number\r
   and return the number converted from the string.  Spaces are always skipped.\r
@@ -3067,22 +3364,23 @@ ShellIsFileInPath(
 **/\r
 UINTN\r
 EFIAPI\r
 **/\r
 UINTN\r
 EFIAPI\r
-ShellStrToUintn(\r
-  IN CONST CHAR16 *String\r
+ShellStrToUintn (\r
+  IN CONST CHAR16  *String\r
   )\r
 {\r
   )\r
 {\r
-  UINT64        RetVal;\r
-  BOOLEAN       Hex;\r
+  UINT64   RetVal;\r
+  BOOLEAN  Hex;\r
 \r
   Hex = FALSE;\r
 \r
 \r
   Hex = FALSE;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE)) {\r
+  if (!InternalShellIsHexOrDecimalNumber (String, Hex, TRUE, FALSE)) {\r
     Hex = TRUE;\r
   }\r
 \r
     Hex = TRUE;\r
   }\r
 \r
-  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, Hex, TRUE))) {\r
+  if (!EFI_ERROR (ShellConvertStringToUint64 (String, &RetVal, Hex, TRUE))) {\r
     return ((UINTN)RetVal);\r
   }\r
     return ((UINTN)RetVal);\r
   }\r
+\r
   return ((UINTN)(-1));\r
 }\r
 \r
   return ((UINTN)(-1));\r
 }\r
 \r
@@ -3118,22 +3416,22 @@ ShellStrToUintn(
 \r
   @return Destination           return the resultant string.\r
 **/\r
 \r
   @return Destination           return the resultant string.\r
 **/\r
-CHAR16*\r
+CHAR16 *\r
 EFIAPI\r
 StrnCatGrow (\r
 EFIAPI\r
 StrnCatGrow (\r
-  IN OUT CHAR16           **Destination,\r
-  IN OUT UINTN            *CurrentSize,\r
-  IN     CONST CHAR16     *Source,\r
-  IN     UINTN            Count\r
+  IN OUT CHAR16        **Destination,\r
+  IN OUT UINTN         *CurrentSize,\r
+  IN     CONST CHAR16  *Source,\r
+  IN     UINTN         Count\r
   )\r
 {\r
   )\r
 {\r
-  UINTN DestinationStartSize;\r
-  UINTN NewSize;\r
+  UINTN  DestinationStartSize;\r
+  UINTN  NewSize;\r
 \r
   //\r
   // ASSERTs\r
   //\r
 \r
   //\r
   // ASSERTs\r
   //\r
-  ASSERT(Destination != NULL);\r
+  ASSERT (Destination != NULL);\r
 \r
   //\r
   // If there's nothing to do then just return Destination\r
 \r
   //\r
   // If there's nothing to do then just return Destination\r
@@ -3145,7 +3443,7 @@ StrnCatGrow (
   //\r
   // allow for un-initialized pointers, based on size being 0\r
   //\r
   //\r
   // allow for un-initialized pointers, based on size being 0\r
   //\r
-  if (CurrentSize != NULL && *CurrentSize == 0) {\r
+  if ((CurrentSize != NULL) && (*CurrentSize == 0)) {\r
     *Destination = NULL;\r
   }\r
 \r
     *Destination = NULL;\r
   }\r
 \r
@@ -3153,19 +3451,19 @@ StrnCatGrow (
   // allow for NULL pointers address as Destination\r
   //\r
   if (*Destination != NULL) {\r
   // allow for NULL pointers address as Destination\r
   //\r
   if (*Destination != NULL) {\r
-    ASSERT(CurrentSize != 0);\r
-    DestinationStartSize = StrSize(*Destination);\r
-    ASSERT(DestinationStartSize <= *CurrentSize);\r
+    ASSERT (CurrentSize != 0);\r
+    DestinationStartSize = StrSize (*Destination);\r
+    ASSERT (DestinationStartSize <= *CurrentSize);\r
   } else {\r
     DestinationStartSize = 0;\r
   } else {\r
     DestinationStartSize = 0;\r
-//    ASSERT(*CurrentSize == 0);\r
+    //    ASSERT(*CurrentSize == 0);\r
   }\r
 \r
   //\r
   // Append all of Source?\r
   //\r
   if (Count == 0) {\r
   }\r
 \r
   //\r
   // Append all of Source?\r
   //\r
   if (Count == 0) {\r
-    Count = StrLen(Source);\r
+    Count = StrLen (Source);\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -3173,15 +3471,17 @@ StrnCatGrow (
   //\r
   if (CurrentSize != NULL) {\r
     NewSize = *CurrentSize;\r
   //\r
   if (CurrentSize != NULL) {\r
     NewSize = *CurrentSize;\r
-    if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) {\r
-      while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
-        NewSize += 2 * Count * sizeof(CHAR16);\r
+    if (NewSize < DestinationStartSize + (Count * sizeof (CHAR16))) {\r
+      while (NewSize < (DestinationStartSize + (Count*sizeof (CHAR16)))) {\r
+        NewSize += 2 * Count * sizeof (CHAR16);\r
       }\r
       }\r
-      *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+\r
+      *Destination = ReallocatePool (*CurrentSize, NewSize, *Destination);\r
       *CurrentSize = NewSize;\r
     }\r
   } else {\r
       *CurrentSize = NewSize;\r
     }\r
   } else {\r
-    *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
+    NewSize      = (Count+1)*sizeof (CHAR16);\r
+    *Destination = AllocateZeroPool (NewSize);\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -3190,14 +3490,16 @@ StrnCatGrow (
   if (*Destination == NULL) {\r
     return (NULL);\r
   }\r
   if (*Destination == NULL) {\r
     return (NULL);\r
   }\r
-  return StrnCat(*Destination, Source, Count);\r
+\r
+  StrnCatS (*Destination, NewSize/sizeof (CHAR16), Source, Count);\r
+  return *Destination;\r
 }\r
 \r
 /**\r
   Prompt the user and return the resultant answer to the requestor.\r
 \r
   This function will display the requested question on the shell prompt and then\r
 }\r
 \r
 /**\r
   Prompt the user and return the resultant answer to the requestor.\r
 \r
   This function will display the requested question on the shell prompt and then\r
-  wait for an apropriate answer to be input from the console.\r
+  wait for an appropriate answer to be input from the console.\r
 \r
   if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue\r
   or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r
 \r
   if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue\r
   or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r
@@ -3220,60 +3522,78 @@ StrnCatGrow (
 EFI_STATUS\r
 EFIAPI\r
 ShellPromptForResponse (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellPromptForResponse (\r
-  IN SHELL_PROMPT_REQUEST_TYPE   Type,\r
-  IN CHAR16         *Prompt OPTIONAL,\r
-  IN OUT VOID       **Response OPTIONAL\r
+  IN SHELL_PROMPT_REQUEST_TYPE  Type,\r
+  IN CHAR16                     *Prompt OPTIONAL,\r
+  IN OUT VOID                   **Response OPTIONAL\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  EFI_INPUT_KEY     Key;\r
-  UINTN             EventIndex;\r
-  SHELL_PROMPT_RESPONSE          *Resp;\r
-  UINTN             Size;\r
-  CHAR16            *Buffer;\r
-\r
-  Status  = EFI_UNSUPPORTED;\r
-  Resp    = NULL;\r
-  Buffer  = NULL;\r
-  Size    = 0;\r
+  EFI_STATUS             Status;\r
+  EFI_INPUT_KEY          Key;\r
+  UINTN                  EventIndex;\r
+  SHELL_PROMPT_RESPONSE  *Resp;\r
+  UINTN                  Size;\r
+  CHAR16                 *Buffer;\r
+\r
+  Status = EFI_UNSUPPORTED;\r
+  Resp   = NULL;\r
+  Buffer = NULL;\r
+  Size   = 0;\r
   if (Type != ShellPromptResponseTypeFreeform) {\r
   if (Type != ShellPromptResponseTypeFreeform) {\r
-    Resp = (SHELL_PROMPT_RESPONSE*)AllocateZeroPool(sizeof(SHELL_PROMPT_RESPONSE));\r
+    Resp = (SHELL_PROMPT_RESPONSE *)AllocateZeroPool (sizeof (SHELL_PROMPT_RESPONSE));\r
     if (Resp == NULL) {\r
     if (Resp == NULL) {\r
+      if (Response != NULL) {\r
+        *Response = NULL;\r
+      }\r
+\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
   }\r
 \r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
   }\r
 \r
-  switch(Type) {\r
+  switch (Type) {\r
     case ShellPromptResponseTypeQuitContinue:\r
       if (Prompt != NULL) {\r
     case ShellPromptResponseTypeQuitContinue:\r
       if (Prompt != NULL) {\r
-        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+        ShellPrintEx (-1, -1, L"%s", Prompt);\r
       }\r
       }\r
+\r
       //\r
       // wait for valid response\r
       //\r
       gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
       //\r
       // wait for valid response\r
       //\r
       gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-      ASSERT_EFI_ERROR(Status);\r
-      ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
-      if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {\r
+      if (EFI_ERROR (Status)) {\r
+        break;\r
+      }\r
+\r
+      ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
+      if ((Key.UnicodeChar == L'Q') || (Key.UnicodeChar == L'q')) {\r
         *Resp = ShellPromptResponseQuit;\r
       } else {\r
         *Resp = ShellPromptResponseContinue;\r
       }\r
         *Resp = ShellPromptResponseQuit;\r
       } else {\r
         *Resp = ShellPromptResponseContinue;\r
       }\r
+\r
       break;\r
     case ShellPromptResponseTypeYesNoCancel:\r
       break;\r
     case ShellPromptResponseTypeYesNoCancel:\r
-       if (Prompt != NULL) {\r
-        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+      if (Prompt != NULL) {\r
+        ShellPrintEx (-1, -1, L"%s", Prompt);\r
       }\r
       }\r
+\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
+\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
-        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+        if (EFI_ERROR (Status)) {\r
+          break;\r
+        }\r
+\r
+        ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
@@ -3289,19 +3609,33 @@ ShellPromptForResponse (
             break;\r
         }\r
       }\r
             break;\r
         }\r
       }\r
-      break;    case ShellPromptResponseTypeYesNoAllCancel:\r
-       if (Prompt != NULL) {\r
-        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+\r
+      break;\r
+    case ShellPromptResponseTypeYesNoAllCancel:\r
+      if (Prompt != NULL) {\r
+        ShellPrintEx (-1, -1, L"%s", Prompt);\r
       }\r
       }\r
+\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
+\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
-        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+        if (EFI_ERROR (Status)) {\r
+          break;\r
+        }\r
+\r
+        if ((Key.UnicodeChar <= 127) && (Key.UnicodeChar >= 32)) {\r
+          ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
+        }\r
+\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
@@ -3321,48 +3655,69 @@ ShellPromptForResponse (
             break;\r
         }\r
       }\r
             break;\r
         }\r
       }\r
+\r
       break;\r
     case ShellPromptResponseTypeEnterContinue:\r
     case ShellPromptResponseTypeAnyKeyContinue:\r
       if (Prompt != NULL) {\r
       break;\r
     case ShellPromptResponseTypeEnterContinue:\r
     case ShellPromptResponseTypeAnyKeyContinue:\r
       if (Prompt != NULL) {\r
-        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+        ShellPrintEx (-1, -1, L"%s", Prompt);\r
       }\r
       }\r
+\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
+\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         if (Type == ShellPromptResponseTypeEnterContinue) {\r
           Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         if (Type == ShellPromptResponseTypeEnterContinue) {\r
           Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-          ASSERT_EFI_ERROR(Status);\r
-          ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+          if (EFI_ERROR (Status)) {\r
+            break;\r
+          }\r
+\r
+          ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
           if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
             *Resp = ShellPromptResponseContinue;\r
             break;\r
           }\r
         }\r
           if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
             *Resp = ShellPromptResponseContinue;\r
             break;\r
           }\r
         }\r
+\r
         if (Type == ShellPromptResponseTypeAnyKeyContinue) {\r
           Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
         if (Type == ShellPromptResponseTypeAnyKeyContinue) {\r
           Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-          ASSERT_EFI_ERROR(Status);\r
+          ASSERT_EFI_ERROR (Status);\r
           *Resp = ShellPromptResponseContinue;\r
           break;\r
         }\r
       }\r
           *Resp = ShellPromptResponseContinue;\r
           break;\r
         }\r
       }\r
+\r
       break;\r
     case ShellPromptResponseTypeYesNo:\r
       break;\r
     case ShellPromptResponseTypeYesNo:\r
-       if (Prompt != NULL) {\r
-        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+      if (Prompt != NULL) {\r
+        ShellPrintEx (-1, -1, L"%s", Prompt);\r
       }\r
       }\r
+\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
       //\r
       // wait for valid response\r
       //\r
       *Resp = ShellPromptResponseMax;\r
       while (*Resp == ShellPromptResponseMax) {\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
+\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
-        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+        if (EFI_ERROR (Status)) {\r
+          break;\r
+        }\r
+\r
+        ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
         switch (Key.UnicodeChar) {\r
           case L'Y':\r
           case L'y':\r
@@ -3374,28 +3729,41 @@ ShellPromptForResponse (
             break;\r
         }\r
       }\r
             break;\r
         }\r
       }\r
+\r
       break;\r
     case ShellPromptResponseTypeFreeform:\r
       if (Prompt != NULL) {\r
       break;\r
     case ShellPromptResponseTypeFreeform:\r
       if (Prompt != NULL) {\r
-        ShellPrintEx(-1, -1, L"%s", Prompt);\r
+        ShellPrintEx (-1, -1, L"%s", Prompt);\r
       }\r
       }\r
-      while(1) {\r
+\r
+      while (1) {\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          Status = EFI_ABORTED;\r
+          break;\r
+        }\r
+\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
         gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
         Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
-        ASSERT_EFI_ERROR(Status);\r
-        ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r
+        if (EFI_ERROR (Status)) {\r
+          break;\r
+        }\r
+\r
+        ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);\r
         if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
           break;\r
         }\r
         if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
           break;\r
         }\r
-        ASSERT((Buffer == NULL && Size == 0) || (Buffer != NULL));\r
-        StrnCatGrow(&Buffer, &Size, &Key.UnicodeChar, 1);\r
+\r
+        ASSERT ((Buffer == NULL && Size == 0) || (Buffer != NULL));\r
+        StrnCatGrow (&Buffer, &Size, &Key.UnicodeChar, 1);\r
       }\r
       }\r
+\r
       break;\r
     //\r
     // This is the location to add new prompt types.\r
       break;\r
     //\r
     // This is the location to add new prompt types.\r
+    // If your new type loops remember to add ExecutionBreak support.\r
     //\r
     default:\r
     //\r
     default:\r
-      ASSERT(FALSE);\r
+      ASSERT (FALSE);\r
   }\r
 \r
   if (Response != NULL) {\r
   }\r
 \r
   if (Response != NULL) {\r
@@ -3403,17 +3771,20 @@ ShellPromptForResponse (
       *Response = Resp;\r
     } else if (Buffer != NULL) {\r
       *Response = Buffer;\r
       *Response = Resp;\r
     } else if (Buffer != NULL) {\r
       *Response = Buffer;\r
+    } else {\r
+      *Response = NULL;\r
     }\r
   } else {\r
     if (Resp != NULL) {\r
     }\r
   } else {\r
     if (Resp != NULL) {\r
-      FreePool(Resp);\r
+      FreePool (Resp);\r
     }\r
     }\r
+\r
     if (Buffer != NULL) {\r
     if (Buffer != NULL) {\r
-      FreePool(Buffer);\r
+      FreePool (Buffer);\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  ShellPrintEx(-1, -1, L"\r\n");\r
+  ShellPrintEx (-1, -1, L"\r\n");\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -3437,18 +3808,18 @@ ShellPromptForResponse (
 EFI_STATUS\r
 EFIAPI\r
 ShellPromptForResponseHii (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellPromptForResponseHii (\r
-  IN SHELL_PROMPT_REQUEST_TYPE         Type,\r
-  IN CONST EFI_STRING_ID  HiiFormatStringId,\r
-  IN CONST EFI_HANDLE     HiiFormatHandle,\r
-  IN OUT VOID             **Response\r
+  IN SHELL_PROMPT_REQUEST_TYPE  Type,\r
+  IN CONST EFI_STRING_ID        HiiFormatStringId,\r
+  IN CONST EFI_HII_HANDLE       HiiFormatHandle,\r
+  IN OUT VOID                   **Response\r
   )\r
 {\r
   CHAR16      *Prompt;\r
   EFI_STATUS  Status;\r
 \r
   )\r
 {\r
   CHAR16      *Prompt;\r
   EFI_STATUS  Status;\r
 \r
-  Prompt = HiiGetString(HiiFormatHandle, HiiFormatStringId, NULL);\r
-  Status = ShellPromptForResponse(Type, Prompt, Response);\r
-  FreePool(Prompt);\r
+  Prompt = HiiGetString (HiiFormatHandle, HiiFormatStringId, NULL);\r
+  Status = ShellPromptForResponse (Type, Prompt, Response);\r
+  FreePool (Prompt);\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -3460,47 +3831,57 @@ ShellPromptForResponseHii (
   @param[in] String       The string to evaluate.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to keep going.\r
   @param[in] String       The string to evaluate.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to keep going.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE        It is all numeric (dec/hex) characters.\r
   @retval FALSE       There is a non-numeric character.\r
 **/\r
 BOOLEAN\r
 \r
   @retval TRUE        It is all numeric (dec/hex) characters.\r
   @retval FALSE       There is a non-numeric character.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
 InternalShellIsHexOrDecimalNumber (\r
   IN CONST CHAR16   *String,\r
   IN CONST BOOLEAN  ForceHex,\r
 InternalShellIsHexOrDecimalNumber (\r
   IN CONST CHAR16   *String,\r
   IN CONST BOOLEAN  ForceHex,\r
-  IN CONST BOOLEAN  StopAtSpace\r
+  IN CONST BOOLEAN  StopAtSpace,\r
+  IN CONST BOOLEAN  TimeNumbers\r
   )\r
 {\r
   )\r
 {\r
-  BOOLEAN Hex;\r
+  BOOLEAN  Hex;\r
+  BOOLEAN  LeadingZero;\r
+\r
+  if (String == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // chop off a single negative sign\r
   //\r
 \r
   //\r
   // chop off a single negative sign\r
   //\r
-  if (String != NULL && *String == L'-') {\r
+  if (*String == L'-') {\r
     String++;\r
   }\r
 \r
     String++;\r
   }\r
 \r
-  if (String == NULL) {\r
-    return (FALSE);\r
+  if (*String == CHAR_NULL) {\r
+    return FALSE;\r
   }\r
 \r
   //\r
   // chop leading zeroes\r
   //\r
   }\r
 \r
   //\r
   // chop leading zeroes\r
   //\r
-  while(String != NULL && *String == L'0'){\r
+  LeadingZero = FALSE;\r
+  while (*String == L'0') {\r
     String++;\r
     String++;\r
+    LeadingZero = TRUE;\r
   }\r
   }\r
+\r
   //\r
   // allow '0x' or '0X', but not 'x' or 'X'\r
   //\r
   //\r
   // allow '0x' or '0X', but not 'x' or 'X'\r
   //\r
-  if (String != NULL && (*String == L'x' || *String == L'X')) {\r
-    if (*(String-1) != L'0') {\r
+  if ((*String == L'x') || (*String == L'X')) {\r
+    if (!LeadingZero) {\r
       //\r
       // we got an x without a preceeding 0\r
       //\r
       return (FALSE);\r
     }\r
       //\r
       // we got an x without a preceeding 0\r
       //\r
       return (FALSE);\r
     }\r
+\r
     String++;\r
     Hex = TRUE;\r
   } else if (ForceHex) {\r
     String++;\r
     Hex = TRUE;\r
   } else if (ForceHex) {\r
@@ -3512,13 +3893,17 @@ InternalShellIsHexOrDecimalNumber (
   //\r
   // loop through the remaining characters and use the lib function\r
   //\r
   //\r
   // loop through the remaining characters and use the lib function\r
   //\r
-  for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
+  for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' '); String++) {\r
+    if (TimeNumbers && (String[0] == L':')) {\r
+      continue;\r
+    }\r
+\r
     if (Hex) {\r
     if (Hex) {\r
-      if (!ShellIsHexaDecimalDigitCharacter(*String)) {\r
+      if (!ShellIsHexaDecimalDigitCharacter (*String)) {\r
         return (FALSE);\r
       }\r
     } else {\r
         return (FALSE);\r
       }\r
     } else {\r
-      if (!ShellIsDecimalDigitCharacter(*String)) {\r
+      if (!ShellIsDecimalDigitCharacter (*String)) {\r
         return (FALSE);\r
       }\r
     }\r
         return (FALSE);\r
       }\r
     }\r
@@ -3538,54 +3923,26 @@ InternalShellIsHexOrDecimalNumber (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellFileExists(\r
-  IN CONST CHAR16 *Name\r
+ShellFileExists (\r
+  IN CONST CHAR16  *Name\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  EFI_SHELL_FILE_INFO *List;\r
+  EFI_STATUS           Status;\r
+  EFI_SHELL_FILE_INFO  *List;\r
 \r
 \r
-  ASSERT(Name != NULL);\r
+  ASSERT (Name != NULL);\r
 \r
 \r
-  List = NULL;\r
-  Status = ShellOpenFileMetaArg((CHAR16*)Name, EFI_FILE_MODE_READ, &List);\r
-  if (EFI_ERROR(Status)) {\r
+  List   = NULL;\r
+  Status = ShellOpenFileMetaArg ((CHAR16 *)Name, EFI_FILE_MODE_READ, &List);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-  ShellCloseFileMetaArg(&List);\r
+  ShellCloseFileMetaArg (&List);\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
-/**\r
-  Convert a Unicode character to upper case only if\r
-  it maps to a valid small-case ASCII character.\r
-\r
-  This internal function only deal with Unicode character\r
-  which maps to a valid small-case ASCII character, i.e.\r
-  L'a' to L'z'. For other Unicode character, the input character\r
-  is returned directly.\r
-\r
-  @param  Char  The character to convert.\r
-\r
-  @retval LowerCharacter   If the Char is with range L'a' to L'z'.\r
-  @retval Unchanged        Otherwise.\r
-\r
-**/\r
-CHAR16\r
-EFIAPI\r
-InternalShellCharToUpper (\r
-  IN      CHAR16                    Char\r
-  )\r
-{\r
-  if (Char >= L'a' && Char <= L'z') {\r
-    return (CHAR16) (Char - (L'a' - L'A'));\r
-  }\r
-\r
-  return Char;\r
-}\r
-\r
 /**\r
   Convert a Unicode character to numerical value.\r
 \r
 /**\r
   Convert a Unicode character to numerical value.\r
 \r
@@ -3600,22 +3957,21 @@ InternalShellCharToUpper (
 \r
 **/\r
 UINTN\r
 \r
 **/\r
 UINTN\r
-EFIAPI\r
 InternalShellHexCharToUintn (\r
 InternalShellHexCharToUintn (\r
-  IN      CHAR16                    Char\r
+  IN      CHAR16  Char\r
   )\r
 {\r
   if (ShellIsDecimalDigitCharacter (Char)) {\r
     return Char - L'0';\r
   }\r
 \r
   )\r
 {\r
   if (ShellIsDecimalDigitCharacter (Char)) {\r
     return Char - L'0';\r
   }\r
 \r
-  return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A');\r
+  return (10 + CharToUpper (Char) - L'A');\r
 }\r
 \r
 /**\r
   Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.\r
 \r
 }\r
 \r
 /**\r
   Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.\r
 \r
-  This function returns a value of type UINTN by interpreting the contents\r
+  This function returns a value of type UINT64 by interpreting the contents\r
   of the Unicode string specified by String as a hexadecimal number.\r
   The format of the input Unicode string String is:\r
 \r
   of the Unicode string specified by String as a hexadecimal number.\r
   The format of the input Unicode string String is:\r
 \r
@@ -3640,19 +3996,18 @@ InternalShellHexCharToUintn (
 \r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   A parameter was NULL or invalid.\r
 \r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   A parameter was NULL or invalid.\r
-  @retval EFI_DEVICE_ERROR        An overflow occured.\r
+  @retval EFI_DEVICE_ERROR        An overflow occurred.\r
 **/\r
 EFI_STATUS\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalShellStrHexToUint64 (\r
   IN CONST CHAR16   *String,\r
 InternalShellStrHexToUint64 (\r
   IN CONST CHAR16   *String,\r
-     OUT   UINT64   *Value,\r
+  OUT   UINT64      *Value,\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
 {\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
 {\r
-  UINT64    Result;\r
+  UINT64  Result;\r
 \r
 \r
-  if (String == NULL || StrSize(String) == 0 || Value == NULL) {\r
+  if ((String == NULL) || (StrSize (String) == 0) || (Value == NULL)) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
@@ -3670,10 +4025,11 @@ InternalShellStrHexToUint64 (
     String++;\r
   }\r
 \r
     String++;\r
   }\r
 \r
-  if (InternalShellCharToUpper (*String) == L'X') {\r
+  if (CharToUpper (*String) == L'X') {\r
     if (*(String - 1) != L'0') {\r
       return 0;\r
     }\r
     if (*(String - 1) != L'0') {\r
       return 0;\r
     }\r
+\r
     //\r
     // Skip the 'X'\r
     //\r
     //\r
     // Skip the 'X'\r
     //\r
@@ -3683,30 +4039,30 @@ InternalShellStrHexToUint64 (
   Result = 0;\r
 \r
   //\r
   Result = 0;\r
 \r
   //\r
-  // Skip spaces if requested\r
+  // there is a space where there should't be\r
   //\r
   //\r
-  while (StopAtSpace && *String == L' ') {\r
-    String++;\r
+  if (*String == L' ') {\r
+    return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
   while (ShellIsHexaDecimalDigitCharacter (*String)) {\r
     //\r
     // If the Hex Number represented by String overflows according\r
   }\r
 \r
   while (ShellIsHexaDecimalDigitCharacter (*String)) {\r
     //\r
     // If the Hex Number represented by String overflows according\r
-    // to the range defined by UINTN, then ASSERT().\r
+    // to the range defined by UINT64, then return EFI_DEVICE_ERROR.\r
     //\r
     //\r
-    if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) {\r
-//    if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) {\r
+    if (!(Result <= (RShiftU64 ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) {\r
+      //    if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) {\r
       return (EFI_DEVICE_ERROR);\r
     }\r
 \r
       return (EFI_DEVICE_ERROR);\r
     }\r
 \r
-    Result = (LShiftU64(Result, 4));\r
+    Result  = (LShiftU64 (Result, 4));\r
     Result += InternalShellHexCharToUintn (*String);\r
     String++;\r
 \r
     //\r
     // stop at spaces if requested\r
     //\r
     Result += InternalShellHexCharToUintn (*String);\r
     String++;\r
 \r
     //\r
     // stop at spaces if requested\r
     //\r
-    if (StopAtSpace && *String == L' ') {\r
+    if (StopAtSpace && (*String == L' ')) {\r
       break;\r
     }\r
   }\r
       break;\r
     }\r
   }\r
@@ -3742,19 +4098,18 @@ InternalShellStrHexToUint64 (
 \r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   A parameter was NULL or invalid.\r
 \r
   @retval EFI_SUCCESS             The conversion was successful.\r
   @retval EFI_INVALID_PARAMETER   A parameter was NULL or invalid.\r
-  @retval EFI_DEVICE_ERROR        An overflow occured.\r
+  @retval EFI_DEVICE_ERROR        An overflow occurred.\r
 **/\r
 EFI_STATUS\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 InternalShellStrDecimalToUint64 (\r
 InternalShellStrDecimalToUint64 (\r
-  IN CONST CHAR16 *String,\r
-     OUT   UINT64 *Value,\r
+  IN CONST CHAR16   *String,\r
+  OUT   UINT64      *Value,\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
 {\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
 {\r
-  UINT64     Result;\r
+  UINT64  Result;\r
 \r
 \r
-  if (String == NULL || StrSize (String) == 0 || Value == NULL) {\r
+  if ((String == NULL) || (StrSize (String) == 0) || (Value == NULL)) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
@@ -3775,28 +4130,31 @@ InternalShellStrDecimalToUint64 (
   Result = 0;\r
 \r
   //\r
   Result = 0;\r
 \r
   //\r
-  // Skip spaces if requested\r
+  // Stop upon space if requested\r
+  // (if the whole value was 0)\r
   //\r
   //\r
-  while (StopAtSpace && *String == L' ') {\r
-    String++;\r
+  if (StopAtSpace && (*String == L' ')) {\r
+    *Value = Result;\r
+    return (EFI_SUCCESS);\r
   }\r
   }\r
+\r
   while (ShellIsDecimalDigitCharacter (*String)) {\r
     //\r
     // If the number represented by String overflows according\r
   while (ShellIsDecimalDigitCharacter (*String)) {\r
     //\r
     // If the number represented by String overflows according\r
-    // to the range defined by UINT64, then ASSERT().\r
+    // to the range defined by UINT64, then return EFI_DEVICE_ERROR.\r
     //\r
 \r
     //\r
 \r
-    if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) {\r
+    if (!(Result <= (DivU64x32 ((((UINT64) ~0) - (*String - L'0')), 10)))) {\r
       return (EFI_DEVICE_ERROR);\r
     }\r
 \r
       return (EFI_DEVICE_ERROR);\r
     }\r
 \r
-    Result = MultU64x32(Result, 10) + (*String - L'0');\r
+    Result = MultU64x32 (Result, 10) + (*String - L'0');\r
     String++;\r
 \r
     //\r
     // Stop at spaces if requested\r
     //\r
     String++;\r
 \r
     //\r
     // Stop at spaces if requested\r
     //\r
-    if (StopAtSpace && *String == L' ') {\r
+    if (StopAtSpace && (*String == L' ')) {\r
       break;\r
     }\r
   }\r
       break;\r
     }\r
   }\r
@@ -3822,9 +4180,9 @@ InternalShellStrDecimalToUint64 (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellConvertStringToUint64(\r
+ShellConvertStringToUint64 (\r
   IN CONST CHAR16   *String,\r
   IN CONST CHAR16   *String,\r
-     OUT   UINT64   *Value,\r
+  OUT   UINT64      *Value,\r
   IN CONST BOOLEAN  ForceHex,\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
   IN CONST BOOLEAN  ForceHex,\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
@@ -3836,10 +4194,10 @@ ShellConvertStringToUint64(
 \r
   Hex = ForceHex;\r
 \r
 \r
   Hex = ForceHex;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+  if (!InternalShellIsHexOrDecimalNumber (String, Hex, StopAtSpace, FALSE)) {\r
     if (!Hex) {\r
       Hex = TRUE;\r
     if (!Hex) {\r
       Hex = TRUE;\r
-      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+      if (!InternalShellIsHexOrDecimalNumber (String, Hex, StopAtSpace, FALSE)) {\r
         return (EFI_INVALID_PARAMETER);\r
       }\r
     } else {\r
         return (EFI_INVALID_PARAMETER);\r
       }\r
     } else {\r
@@ -3850,25 +4208,26 @@ ShellConvertStringToUint64(
   //\r
   // Chop off leading spaces\r
   //\r
   //\r
   // Chop off leading spaces\r
   //\r
-  for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++);\r
+  for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++) {\r
+  }\r
 \r
   //\r
   // make sure we have something left that is numeric.\r
   //\r
 \r
   //\r
   // make sure we have something left that is numeric.\r
   //\r
-  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace)) {\r
+  if ((Walker == NULL) || (*Walker == CHAR_NULL) || !InternalShellIsHexOrDecimalNumber (Walker, Hex, StopAtSpace, FALSE)) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
   //\r
   // do the conversion.\r
   //\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
   //\r
   // do the conversion.\r
   //\r
-  if (Hex || StrnCmp(Walker, L"0x", 2) == 0 || StrnCmp(Walker, L"0X", 2) == 0){\r
-    Status = InternalShellStrHexToUint64(Walker, &RetVal, StopAtSpace);\r
+  if (Hex || (StrnCmp (Walker, L"0x", 2) == 0) || (StrnCmp (Walker, L"0X", 2) == 0)) {\r
+    Status = InternalShellStrHexToUint64 (Walker, &RetVal, StopAtSpace);\r
   } else {\r
   } else {\r
-    Status = InternalShellStrDecimalToUint64(Walker, &RetVal, StopAtSpace);\r
+    Status = InternalShellStrDecimalToUint64 (Walker, &RetVal, StopAtSpace);\r
   }\r
 \r
   }\r
 \r
-  if (Value == NULL && !EFI_ERROR(Status)) {\r
+  if ((Value == NULL) && !EFI_ERROR (Status)) {\r
     return (EFI_NOT_FOUND);\r
   }\r
 \r
     return (EFI_NOT_FOUND);\r
   }\r
 \r
@@ -3899,9 +4258,10 @@ ShellIsHexOrDecimalNumber (
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
 {\r
   IN CONST BOOLEAN  StopAtSpace\r
   )\r
 {\r
-  if (ShellConvertStringToUint64(String, NULL, ForceHex, StopAtSpace) == EFI_NOT_FOUND) {\r
+  if (ShellConvertStringToUint64 (String, NULL, ForceHex, StopAtSpace) == EFI_NOT_FOUND) {\r
     return (TRUE);\r
   }\r
     return (TRUE);\r
   }\r
+\r
   return (FALSE);\r
 }\r
 \r
   return (FALSE);\r
 }\r
 \r
@@ -3921,33 +4281,39 @@ ShellIsHexOrDecimalNumber (
 \r
   @sa ShellFileHandleReadLine\r
 **/\r
 \r
   @sa ShellFileHandleReadLine\r
 **/\r
-CHAR16*\r
+CHAR16 *\r
 EFIAPI\r
 EFIAPI\r
-ShellFileHandleReturnLine(\r
-  IN SHELL_FILE_HANDLE            Handle,\r
-  IN OUT BOOLEAN                *Ascii\r
+ShellFileHandleReturnLine (\r
+  IN SHELL_FILE_HANDLE  Handle,\r
+  IN OUT BOOLEAN        *Ascii\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16          *RetVal;\r
-  UINTN           Size;\r
-  EFI_STATUS      Status;\r
+  CHAR16      *RetVal;\r
+  UINTN       Size;\r
+  EFI_STATUS  Status;\r
 \r
 \r
-  Size = 0;\r
+  Size   = 0;\r
   RetVal = NULL;\r
 \r
   RetVal = NULL;\r
 \r
-  Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
+  Status = ShellFileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
   if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    RetVal = AllocateZeroPool(Size);\r
+    RetVal = AllocateZeroPool (Size);\r
     if (RetVal == NULL) {\r
       return (NULL);\r
     }\r
     if (RetVal == NULL) {\r
       return (NULL);\r
     }\r
-    Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
 \r
 \r
+    Status = ShellFileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);\r
+  }\r
+\r
+  if ((Status == EFI_END_OF_FILE) && (RetVal != NULL) && (*RetVal != CHAR_NULL)) {\r
+    Status = EFI_SUCCESS;\r
   }\r
   }\r
-  if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
-    FreePool(RetVal);\r
+\r
+  if (EFI_ERROR (Status) && (RetVal != NULL)) {\r
+    FreePool (RetVal);\r
     RetVal = NULL;\r
   }\r
     RetVal = NULL;\r
   }\r
+\r
   return (RetVal);\r
 }\r
 \r
   return (RetVal);\r
 }\r
 \r
@@ -3957,9 +4323,20 @@ ShellFileHandleReturnLine(
   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
   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
+  NOTE: LINES THAT ARE RETURNED BY THIS FUNCTION ARE UCS2, EVEN IF THE FILE BEING READ\r
+        IS IN ASCII FORMAT.\r
+\r
   @param[in]       Handle        SHELL_FILE_HANDLE to read from.\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, out]  Buffer        The pointer to buffer to read into. If this function\r
+                                 returns EFI_SUCCESS, then on output Buffer will\r
+                                 contain a UCS2 string, even if the file being\r
+                                 read is ASCII.\r
+  @param[in, out]  Size          On input, pointer to number of bytes in Buffer.\r
+                                 On output, unchanged unless Buffer is too small\r
+                                 to contain the next line of the file. In that\r
+                                 case Size is set to the number of bytes needed\r
+                                 to hold the next line of the file (as a UCS2\r
+                                 string, even if it is an ASCII file).\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
   @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
@@ -3971,6 +4348,7 @@ ShellFileHandleReturnLine(
 \r
   @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
                                 Buffer.\r
 \r
   @retval EFI_SUCCESS           The operation was successful.  The line is stored in\r
                                 Buffer.\r
+  @retval EFI_END_OF_FILE       There are no more lines in the file.\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
   @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
@@ -3978,12 +4356,12 @@ ShellFileHandleReturnLine(
 **/\r
 EFI_STATUS\r
 EFIAPI\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
+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
   )\r
 {\r
   EFI_STATUS  Status;\r
@@ -3992,69 +4370,80 @@ ShellFileHandleReadLine(
   UINTN       CountSoFar;\r
   UINT64      OriginalFilePosition;\r
 \r
   UINTN       CountSoFar;\r
   UINT64      OriginalFilePosition;\r
 \r
-\r
-  if (Handle == NULL\r
-    ||Size   == NULL\r
-   ){\r
+  if (  (Handle == NULL)\r
+     || (Size   == NULL)\r
+        )\r
+  {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
+\r
   if (Buffer == NULL) {\r
   if (Buffer == NULL) {\r
-    ASSERT(*Size == 0);\r
+    ASSERT (*Size == 0);\r
   } else {\r
     *Buffer = CHAR_NULL;\r
   }\r
   } else {\r
     *Buffer = CHAR_NULL;\r
   }\r
-  gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);\r
+\r
+  gEfiShellProtocol->GetFilePosition (Handle, &OriginalFilePosition);\r
   if (OriginalFilePosition == 0) {\r
   if (OriginalFilePosition == 0) {\r
-    CharSize = sizeof(CHAR16);\r
-    Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);\r
-    ASSERT_EFI_ERROR(Status);\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
     if (CharBuffer == gUnicodeFileTag) {\r
       *Ascii = FALSE;\r
     } else {\r
       *Ascii = TRUE;\r
-      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
+      gEfiShellProtocol->SetFilePosition (Handle, OriginalFilePosition);\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  for (CountSoFar = 0;;CountSoFar++){\r
+  if (*Ascii) {\r
+    CharSize = sizeof (CHAR8);\r
+  } else {\r
+    CharSize = sizeof (CHAR16);\r
+  }\r
+\r
+  for (CountSoFar = 0; ; CountSoFar++) {\r
     CharBuffer = 0;\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
+    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
+    {\r
+      if (CharSize == 0) {\r
+        Status = EFI_END_OF_FILE;\r
+      }\r
+\r
       break;\r
     }\r
       break;\r
     }\r
+\r
     //\r
     // if we have space save it...\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
+    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
     }\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 ((CountSoFar+1)*sizeof (CHAR16) > *Size) {\r
+    *Size = (CountSoFar+1)*sizeof (CHAR16);\r
     if (!Truncate) {\r
     if (!Truncate) {\r
-      gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);\r
+      gEfiShellProtocol->SetFilePosition (Handle, OriginalFilePosition);\r
     } else {\r
     } else {\r
-      DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
+      DEBUG ((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));\r
     }\r
     }\r
+\r
     return (EFI_BUFFER_TOO_SMALL);\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
+  while (Buffer[StrLen (Buffer)-1] == L'\r') {\r
+    Buffer[StrLen (Buffer)-1] = CHAR_NULL;\r
   }\r
 \r
   return (Status);\r
   }\r
 \r
   return (Status);\r
@@ -4065,7 +4454,7 @@ ShellFileHandleReadLine(
 \r
   @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.\r
   @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).\r
 \r
   @param[in] CommandToGetHelpOn  Pointer to a string containing the command name of help file to be printed.\r
   @param[in] SectionToGetHelpOn  Pointer to the section specifier(s).\r
-  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints \r
+  @param[in] PrintCommandText    If TRUE, prints the command followed by the help content, otherwise prints\r
                                  the help content only.\r
   @retval EFI_DEVICE_ERROR       The help data format was incorrect.\r
   @retval EFI_NOT_FOUND          The help data could not be found.\r
                                  the help content only.\r
   @retval EFI_DEVICE_ERROR       The help data format was incorrect.\r
   @retval EFI_NOT_FOUND          The help data could not be found.\r
@@ -4074,57 +4463,58 @@ ShellFileHandleReadLine(
 EFI_STATUS\r
 EFIAPI\r
 ShellPrintHelp (\r
 EFI_STATUS\r
 EFIAPI\r
 ShellPrintHelp (\r
-  IN CONST CHAR16     *CommandToGetHelpOn,\r
-  IN CONST CHAR16     *SectionToGetHelpOn,\r
-  IN BOOLEAN          PrintCommandText\r
+  IN CONST CHAR16  *CommandToGetHelpOn,\r
+  IN CONST CHAR16  *SectionToGetHelpOn,\r
+  IN BOOLEAN       PrintCommandText\r
   )\r
 {\r
   )\r
 {\r
-       EFI_STATUS          Status;\r
-       CHAR16              *OutText;\r
-         \r
-       OutText = NULL;\r
-       \r
+  EFI_STATUS  Status;\r
+  CHAR16      *OutText;\r
+\r
+  OutText = NULL;\r
+\r
   //\r
   // Get the string to print based\r
   //\r
   //\r
   // Get the string to print based\r
   //\r
-       Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
-  \r
+  Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);\r
+\r
   //\r
   // make sure we got a valid string\r
   //\r
   //\r
   // make sure we got a valid string\r
   //\r
-  if (EFI_ERROR(Status)){\r
+  if (EFI_ERROR (Status)) {\r
     return Status;\r
     return Status;\r
-       } \r
-  if (OutText == NULL || StrLen(OutText) == 0) {\r
-    return EFI_NOT_FOUND;  \r
-       }\r
-  \r
+  }\r
+\r
+  if ((OutText == NULL) || (StrLen (OutText) == 0)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
   //\r
   // Chop off trailing stuff we dont need\r
   //\r
   //\r
   // Chop off trailing stuff we dont need\r
   //\r
-  while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {\r
-    OutText[StrLen(OutText)-1] = CHAR_NULL;\r
+  while (OutText[StrLen (OutText)-1] == L'\r' || OutText[StrLen (OutText)-1] == L'\n' || OutText[StrLen (OutText)-1] == L' ') {\r
+    OutText[StrLen (OutText)-1] = CHAR_NULL;\r
   }\r
   }\r
-  \r
+\r
   //\r
   // Print this out to the console\r
   //\r
   if (PrintCommandText) {\r
   //\r
   // Print this out to the console\r
   //\r
   if (PrintCommandText) {\r
-    ShellPrintEx(-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);\r
+    ShellPrintEx (-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);\r
   } else {\r
   } else {\r
-    ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);\r
+    ShellPrintEx (-1, -1, L"%N%s\r\n", OutText);\r
   }\r
   }\r
-  \r
-  SHELL_FREE_NON_NULL(OutText);\r
 \r
 \r
-       return EFI_SUCCESS;\r
+  SHELL_FREE_NON_NULL (OutText);\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
   Function to delete a file by name\r
 }\r
 \r
 /**\r
   Function to delete a file by name\r
-  \r
+\r
   @param[in]       FileName       Pointer to file name to delete.\r
   @param[in]       FileName       Pointer to file name to delete.\r
-  \r
+\r
   @retval EFI_SUCCESS             the file was deleted sucessfully\r
   @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                   deleted\r
   @retval EFI_SUCCESS             the file was deleted sucessfully\r
   @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                   deleted\r
@@ -4145,22 +4535,57 @@ ShellPrintHelp (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-ShellDeleteFileByName(\r
-  IN CONST CHAR16               *FileName\r
+ShellDeleteFileByName (\r
+  IN CONST CHAR16  *FileName\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  SHELL_FILE_HANDLE         FileHandle;\r
-  \r
-  Status = ShellFileExists(FileName);\r
-  \r
-  if (Status == EFI_SUCCESS){\r
-    Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);\r
-    if (Status == EFI_SUCCESS){\r
-      Status = ShellDeleteFile(&FileHandle);\r
+  EFI_STATUS         Status;\r
+  SHELL_FILE_HANDLE  FileHandle;\r
+\r
+  Status = ShellFileExists (FileName);\r
+\r
+  if (Status == EFI_SUCCESS) {\r
+    Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);\r
+    if (Status == EFI_SUCCESS) {\r
+      Status = ShellDeleteFile (&FileHandle);\r
     }\r
     }\r
-  } \r
+  }\r
+\r
+  return (Status);\r
+}\r
+\r
+/**\r
+  Cleans off all the quotes in the string.\r
+\r
+  @param[in]     OriginalString   pointer to the string to be cleaned.\r
+  @param[out]   CleanString      The new string with all quotes removed.\r
+                                                  Memory allocated in the function and free\r
+                                                  by caller.\r
+\r
+  @retval EFI_SUCCESS   The operation was successful.\r
+**/\r
+EFI_STATUS\r
+InternalShellStripQuotes (\r
+  IN  CONST CHAR16  *OriginalString,\r
+  OUT CHAR16        **CleanString\r
+  )\r
+{\r
+  CHAR16  *Walker;\r
+\r
+  if ((OriginalString == NULL) || (CleanString == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);\r
+  if (*CleanString == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL; Walker++) {\r
+    if (*Walker == L'\"') {\r
+      CopyMem (Walker, Walker+1, StrSize (Walker) - sizeof (Walker[0]));\r
+    }\r
+  }\r
 \r
 \r
-  return(Status);\r
-  \r
+  return EFI_SUCCESS;\r
 }\r
 }\r