]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
fix K8 coding issues.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index 0d79880dffb026b71f7d0d84e969e0a63562d447..0d6a30e6e9ce52fb6d63c951a5f5b3d0d3541fb2 100644 (file)
@@ -1,37 +1,17 @@
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
-Copyright (c) 2006 - 2009, Intel Corporation\r
-All rights reserved. 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
+  Copyright (c) 2006 - 2010, 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
+  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
 \r
 **/\r
 \r
-#include <Uefi.h>\r
-#include <Library/ShellLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/BaseLib.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Library/DevicePathLib.h>\r
-#include <Library/PcdLib.h>\r
-#include <Library/FileHandleLib.h>\r
-#include <Library/PrintLib.h>\r
-#include <Library/UefiLib.h>\r
-#include <Library/HiiLib.h>\r
-\r
-#include <Protocol/EfiShellEnvironment2.h>\r
-#include <Protocol/EfiShellInterface.h>\r
-#include <Protocol/EfiShell.h>\r
-#include <Protocol/EfiShellParameters.h>\r
-#include <Protocol/SimpleFileSystem.h>\r
-\r
 #include "UefiShellLib.h"\r
 \r
 #define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
@@ -54,12 +34,14 @@ STATIC EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;
 STATIC EFI_HANDLE                    mEfiShellEnvironment2Handle;\r
 STATIC FILE_HANDLE_FUNCTION_MAP      FileFunctionMap;\r
 STATIC UINTN                         mTotalParameterCount;\r
+STATIC CHAR16                        *mPostReplaceFormat;\r
+STATIC CHAR16                        *mPostReplaceFormat2;\r
 \r
 /**\r
   Check if a Unicode character is a hexadecimal character.\r
 \r
-  This internal function checks if a Unicode character is a \r
-  decimal character.  The valid hexadecimal character is \r
+  This internal function checks if a Unicode character is a\r
+  decimal character.  The valid hexadecimal character is\r
   L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
 \r
 \r
@@ -71,7 +53,7 @@ STATIC UINTN                         mTotalParameterCount;
 **/\r
 BOOLEAN\r
 EFIAPI\r
-ShellInternalIsHexaDecimalDigitCharacter (\r
+ShellIsHexaDecimalDigitCharacter (\r
   IN      CHAR16                    Char\r
   ) {\r
   return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));\r
@@ -92,7 +74,7 @@ ShellFindSE2 (
 \r
   BufferSize = 0;\r
   Buffer = NULL;\r
-  Status = gBS->OpenProtocol(ImageHandle, \r
+  Status = gBS->OpenProtocol(ImageHandle,\r
                              &gEfiShellEnvironment2Guid,\r
                              (VOID **)&mEfiShellEnvironment2,\r
                              ImageHandle,\r
@@ -125,13 +107,13 @@ ShellFindSE2 (
                                   Buffer\r
                                   );\r
     }\r
-    if (!EFI_ERROR (Status)) {\r
+    if (!EFI_ERROR (Status) && Buffer != NULL) {\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
+        Status = gBS->OpenProtocol(Buffer[HandleIndex],\r
                                    &gEfiShellEnvironment2Guid,\r
                                    (VOID **)&mEfiShellEnvironment2,\r
                                    ImageHandle,\r
@@ -160,6 +142,12 @@ ShellLibConstructorWorker (
   ) {\r
   EFI_STATUS Status;\r
 \r
+  ASSERT(PcdGet16 (PcdShellPrintBufferSize) < PcdGet32 (PcdMaximumUnicodeStringLength));\r
+  mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
+  ASSERT (mPostReplaceFormat != NULL);\r
+  mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
+  ASSERT (mPostReplaceFormat2 != NULL);\r
+\r
   //\r
   // Set the parameter count to an invalid number\r
   //\r
@@ -168,7 +156,7 @@ ShellLibConstructorWorker (
   //\r
   // UEFI 2.0 shell interfaces (used preferentially)\r
   //\r
-  Status = gBS->OpenProtocol(ImageHandle, \r
+  Status = gBS->OpenProtocol(ImageHandle,\r
                              &gEfiShellProtocolGuid,\r
                              (VOID **)&mEfiShellProtocol,\r
                              ImageHandle,\r
@@ -178,7 +166,7 @@ ShellLibConstructorWorker (
   if (EFI_ERROR(Status)) {\r
     mEfiShellProtocol = NULL;\r
   }\r
-  Status = gBS->OpenProtocol(ImageHandle, \r
+  Status = gBS->OpenProtocol(ImageHandle,\r
                              &gEfiShellParametersProtocolGuid,\r
                              (VOID **)&mEfiShellParametersProtocol,\r
                              ImageHandle,\r
@@ -199,7 +187,7 @@ ShellLibConstructorWorker (
       DEBUG((DEBUG_ERROR, "Status: 0x%08x\r\n", Status));\r
       mEfiShellEnvironment2 = NULL;\r
     }\r
-    Status = gBS->OpenProtocol(ImageHandle, \r
+    Status = gBS->OpenProtocol(ImageHandle,\r
                                &gEfiShellInterfaceGuid,\r
                                (VOID **)&mEfiShellInterface,\r
                                ImageHandle,\r
@@ -213,7 +201,7 @@ ShellLibConstructorWorker (
   //\r
   // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
   //\r
-  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface          != NULL) || \r
+  if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface          != NULL) ||\r
       (mEfiShellProtocol     != NULL && mEfiShellParametersProtocol != NULL)    ) {\r
     if (mEfiShellProtocol != NULL) {\r
       FileFunctionMap.GetFileInfo     = mEfiShellProtocol->GetFileInfo;\r
@@ -266,14 +254,16 @@ ShellLibConstructor (
   mEfiShellParametersProtocol = NULL;\r
   mEfiShellInterface          = NULL;\r
   mEfiShellEnvironment2Handle = NULL;\r
+  mPostReplaceFormat          = NULL;\r
+  mPostReplaceFormat2         = NULL;\r
 \r
   //\r
   // verify that auto initialize is not set false\r
-  // \r
+  //\r
   if (PcdGetBool(PcdShellLibAutoInitialize) == 0) {\r
     return (EFI_SUCCESS);\r
   }\r
-  \r
+\r
   return (ShellLibConstructorWorker(ImageHandle, SystemTable));\r
 }\r
 \r
@@ -297,24 +287,34 @@ ShellLibDestructor (
     gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellInterfaceGuid,\r
                        ImageHandle,\r
-                       NULL);  \r
+                       NULL);\r
     mEfiShellInterface = NULL;\r
   }\r
   if (mEfiShellProtocol != NULL) {\r
     gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellProtocolGuid,\r
                        ImageHandle,\r
-                       NULL);  \r
+                       NULL);\r
     mEfiShellProtocol = NULL;\r
   }\r
   if (mEfiShellParametersProtocol != NULL) {\r
     gBS->CloseProtocol(ImageHandle,\r
                        &gEfiShellParametersProtocolGuid,\r
                        ImageHandle,\r
-                       NULL);    \r
+                       NULL);\r
     mEfiShellParametersProtocol = NULL;\r
   }\r
   mEfiShellEnvironment2Handle = NULL;\r
+\r
+  if (mPostReplaceFormat != NULL) {\r
+    FreePool(mPostReplaceFormat);\r
+  }\r
+  if (mPostReplaceFormat2 != NULL) {\r
+    FreePool(mPostReplaceFormat2);\r
+  }\r
+  mPostReplaceFormat          = NULL;\r
+  mPostReplaceFormat2         = NULL;\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -354,13 +354,13 @@ ShellInitialize (
 }\r
 \r
 /**\r
-  This function will retrieve the information about the file for the handle \r
+  This function will retrieve the information about the file for the handle\r
   specified and store it in allocated pool memory.\r
 \r
-  This function allocates a buffer to store the file's information. It is the \r
+  This function allocates a buffer to store the file's information. It is the\r
   caller's responsibility to free the buffer\r
 \r
-  @param  FileHandle  The file handle of the file for which information is \r
+  @param  FileHandle  The file handle of the file for which information is\r
   being requested.\r
 \r
   @retval NULL information could not be retrieved.\r
@@ -376,10 +376,10 @@ ShellGetFileInfo (
 }\r
 \r
 /**\r
-  This function will set the information about the file for the opened handle \r
+  This function will set the information about the file for the opened handle\r
   specified.\r
 \r
-  @param  FileHandle            The file handle of the file for which information \r
+  @param  FileHandle            The file handle of the file for which information\r
   is being set\r
 \r
   @param  FileInfo              The infotmation to set.\r
@@ -400,15 +400,15 @@ ShellSetFileInfo (
   IN EFI_FILE_INFO              *FileInfo\r
   ) {\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
+  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
+  @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
@@ -417,18 +417,18 @@ ShellSetFileInfo (
 \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
+  @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
+  @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
+  @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
@@ -452,7 +452,7 @@ ShellOpenFileByDevicePath(
   ASSERT(FilePath != NULL);\r
   ASSERT(FileHandle != NULL);\r
   ASSERT(DeviceHandle != NULL);\r
-  // \r
+  //\r
   // which shell interface should we use\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
@@ -466,14 +466,14 @@ ShellOpenFileByDevicePath(
     Status = ShellOpenFileByName(FileName, FileHandle, OpenMode, Attributes);\r
     FreePool(FileName);\r
     return (Status);\r
-  } \r
+  }\r
 \r
 \r
   //\r
   // use old shell method.\r
   //\r
-  Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, \r
-                                  FilePath, \r
+  Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,\r
+                                  FilePath,\r
                                   DeviceHandle);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -555,8 +555,8 @@ ShellOpenFileByDevicePath(
 /**\r
   This function will open a file or directory referenced by filename.\r
 \r
-  If return is EFI_SUCCESS, the Filehandle is the opened file's handle; \r
-  otherwise, the Filehandle is NULL. The Attributes is valid only for \r
+  If return is EFI_SUCCESS, the Filehandle is the opened file's handle;\r
+  otherwise, the Filehandle is NULL. The Attributes is valid only for\r
   EFI_FILE_MODE_CREATE.\r
 \r
   if FileNAme is NULL then ASSERT()\r
@@ -568,18 +568,18 @@ ShellOpenFileByDevicePath(
 \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 \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\r
                                 on 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
+  @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
+  @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
@@ -616,7 +616,7 @@ ShellOpenFileByName(
       FreePool(FileInfo);\r
     }\r
     return (Status);\r
-  } \r
+  }\r
   //\r
   // Using EFI Shell version\r
   // this means convert name to path and call that function\r
@@ -636,8 +636,8 @@ ShellOpenFileByName(
 /**\r
   This function create a directory\r
 \r
-  If return is EFI_SUCCESS, the Filehandle is the opened directory's handle; \r
-  otherwise, the Filehandle is NULL. If the directory already existed, this \r
+  If return is EFI_SUCCESS, the Filehandle is the opened directory's handle;\r
+  otherwise, the Filehandle is NULL. If the directory already existed, this\r
   function opens the existing directory.\r
 \r
   @param  DirectoryName                pointer to directory name\r
@@ -645,18 +645,18 @@ ShellOpenFileByName(
 \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 \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\r
                                 on 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
+  @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
+  @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
   @sa ShellOpenFileByName\r
@@ -687,21 +687,21 @@ ShellCreateDirectory(
 /**\r
   This function reads information from an opened file.\r
 \r
-  If FileHandle is not a directory, the function reads the requested number of \r
-  bytes from the file at the file's current position and returns them in Buffer. \r
+  If FileHandle is not a directory, the function reads the requested number of\r
+  bytes from the file at the file's current position and returns them in Buffer.\r
   If the read goes beyond the end of the file, the read length is truncated to the\r
-  end of the file. The file's current position is increased by the number of bytes \r
-  returned.  If FileHandle is a directory, the function reads the directory entry \r
-  at the file's current position and returns the entry in Buffer. If the Buffer \r
-  is not large enough to hold the current directory entry, then \r
-  EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated. \r
-  BufferSize is set to be the size of the buffer needed to read the entry. On \r
-  success, the current position is updated to the next directory entry. If there \r
-  are no more directory entries, the read returns a zero-length buffer. \r
+  end of the file. The file's current position is increased by the number of bytes\r
+  returned.  If FileHandle is a directory, the function reads the directory entry\r
+  at the file's current position and returns the entry in Buffer. If the Buffer\r
+  is not large enough to hold the current directory entry, then\r
+  EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.\r
+  BufferSize is set to be the size of the buffer needed to read the entry. On\r
+  success, the current position is updated to the next directory entry. If there\r
+  are no more directory entries, the read returns a zero-length buffer.\r
   EFI_FILE_INFO is the structure returned as the directory entry.\r
 \r
   @param FileHandle             the opened file handle\r
-  @param BufferSize             on input the size of buffer in bytes.  on return \r
+  @param BufferSize             on input the size of buffer in bytes.  on return\r
                                 the number of bytes written.\r
   @param Buffer                 the buffer to put read data into.\r
 \r
@@ -709,7 +709,7 @@ ShellCreateDirectory(
   @retval EFI_NO_MEDIA         The device has no media.\r
   @retval EFI_DEVICE_ERROR     The device reported an error.\r
   @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
-  @retval EFI_BUFFER_TO_SMALL  Buffer is too small. ReadSize contains required \r
+  @retval EFI_BUFFER_TO_SMALL  Buffer is too small. ReadSize contains required\r
                                 size.\r
 \r
 **/\r
@@ -727,11 +727,11 @@ ShellReadFile(
 /**\r
   Write data to a file.\r
 \r
-  This function writes the specified number of bytes to the file at the current \r
-  file position. The current file position is advanced the actual number of bytes \r
-  written, which is returned in BufferSize. Partial writes only occur when there \r
-  has been a data error during the write attempt (such as "volume space full"). \r
-  The file is automatically grown to hold the data if required. Direct writes to \r
+  This function writes the specified number of bytes to the file at the current\r
+  file position. The current file position is advanced the actual number of bytes\r
+  written, which is returned in BufferSize. Partial writes only occur when there\r
+  has been a data error during the write attempt (such as "volume space full").\r
+  The file is automatically grown to hold the data if required. Direct writes to\r
   opened directories are not supported.\r
 \r
   @param FileHandle           The opened file for writing\r
@@ -758,11 +758,11 @@ ShellWriteFile(
   return (FileFunctionMap.WriteFile(FileHandle, BufferSize, Buffer));\r
 }\r
 \r
-/** \r
+/**\r
   Close an open file handle.\r
 \r
-  This function closes a specified file handle. All "dirty" cached file data is \r
-  flushed to the device, and the file is closed. In all cases the handle is \r
+  This function closes a specified file handle. All "dirty" cached file data is\r
+  flushed to the device, and the file is closed. In all cases the handle is\r
   closed.\r
 \r
 @param FileHandle               the file handle to close.\r
@@ -781,13 +781,13 @@ ShellCloseFile (
   Delete a file and close the handle\r
 \r
   This function closes and deletes a file. In all cases the file handle is closed.\r
-  If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is \r
+  If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is\r
   returned, but the handle is still closed.\r
 \r
   @param FileHandle             the file handle to delete\r
 \r
   @retval EFI_SUCCESS           the file was closed sucessfully\r
-  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not \r
+  @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
                                 deleted\r
   @retval INVALID_PARAMETER            One of the parameters has an invalid value.\r
 **/\r
@@ -802,19 +802,19 @@ ShellDeleteFile (
 /**\r
   Set the current position in a file.\r
 \r
-  This function sets the current file position for the handle to the position \r
+  This function sets the current file position for the handle to the position\r
   supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only\r
-  absolute positioning is supported, and seeking past the end of the file is \r
-  allowed (a subsequent write would grow the file). Seeking to position \r
+  absolute positioning is supported, and seeking past the end of the file is\r
+  allowed (a subsequent write would grow the file). Seeking to position\r
   0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
-  If FileHandle is a directory, the only position that may be set is zero. This \r
+  If FileHandle is a directory, the only position that may be set is zero. This\r
   has the effect of starting the read process of the directory entries over.\r
 \r
   @param FileHandle             The file handle on which the position is being set\r
   @param Position               Byte position from begining of file\r
 \r
   @retval EFI_SUCCESS           Operation completed sucessfully.\r
-  @retval EFI_UNSUPPORTED       the seek request for non-zero is not valid on \r
+  @retval EFI_UNSUPPORTED       the seek request for non-zero is not valid on\r
                                 directories.\r
   @retval INVALID_PARAMETER     One of the parameters has an invalid value.\r
 **/\r
@@ -827,11 +827,11 @@ ShellSetFilePosition (
   return (FileFunctionMap.SetFilePosition(FileHandle, Position));\r
 }\r
 \r
-/** \r
+/**\r
   Gets a file's current position\r
 \r
-  This function retrieves the current file position for the file handle. For \r
-  directories, the current file position has no meaning outside of the file \r
+  This function retrieves the current file position for the file handle. For\r
+  directories, the current file position has no meaning outside of the file\r
   system driver and as such the operation is not supported. An error is returned\r
   if FileHandle is a directory.\r
 \r
@@ -852,7 +852,7 @@ ShellGetFilePosition (
 }\r
 /**\r
   Flushes data on a file\r
-  \r
+\r
   This function flushes all modified data associated with a file to a device.\r
 \r
   @param FileHandle             The file handle on which to flush data\r
@@ -875,8 +875,8 @@ ShellFlushFile (
 /**\r
   Retrieves the first file from a directory\r
 \r
-  This function opens a directory and gets the first file's info in the \r
-  directory. Caller can use ShellFindNextFile() to get other files.  When \r
+  This function opens a directory and gets the first file's info in the\r
+  directory. Caller can use ShellFindNextFile() to get other files.  When\r
   complete the caller is responsible for calling FreePool() on Buffer.\r
 \r
   @param DirHandle              The file handle of the directory to search\r
@@ -904,12 +904,12 @@ ShellFindFirstFile (
 /**\r
   Retrieves the next file in a directory.\r
 \r
-  To use this function, caller must call the LibFindFirstFile() to get the \r
-  first file, and then use this function get other files. This function can be \r
-  called for several times to get each file's information in the directory. If \r
-  the call of ShellFindNextFile() got the last file in the directory, the next \r
-  call of this function has no file to get. *NoFile will be set to TRUE and the \r
-  Buffer memory will be automatically freed. \r
+  To use this function, caller must call the LibFindFirstFile() to get the\r
+  first file, and then use this function get other files. This function can be\r
+  called for several times to get each file's information in the directory. If\r
+  the call of ShellFindNextFile() got the last file in the directory, the next\r
+  call of this function has no file to get. *NoFile will be set to TRUE and the\r
+  Buffer memory will be automatically freed.\r
 \r
   @param DirHandle              the file handle of the directory\r
   @param Buffer                                    pointer to buffer for file's information\r
@@ -938,7 +938,7 @@ ShellFindNextFile(
   if FileHandle is NULL then ASSERT()\r
   if Size is NULL then ASSERT()\r
 \r
-  This function extracts the file size info from the FileHandle's EFI_FILE_INFO \r
+  This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
   data.\r
 \r
   @param FileHandle             file handle from which size is retrieved\r
@@ -969,7 +969,7 @@ ShellGetExecutionBreakFlag(
   VOID\r
   )\r
 {\r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
@@ -981,7 +981,7 @@ ShellGetExecutionBreakFlag(
       return (FALSE);\r
     }\r
     return (TRUE);\r
-  } \r
+  }\r
 \r
   //\r
   // using EFI Shell; call the function to check\r
@@ -992,7 +992,7 @@ ShellGetExecutionBreakFlag(
 /**\r
   return the value of an environment variable\r
 \r
-  this function gets the value of the environment variable set by the \r
+  this function gets the value of the environment variable set by the\r
   ShellSetEnvironmentVariable function\r
 \r
   @param EnvKey                 The key name of the environment variable.\r
@@ -1006,7 +1006,7 @@ ShellGetEnvironmentVariable (
   IN CONST CHAR16                *EnvKey\r
   )\r
 {\r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
@@ -1051,12 +1051,12 @@ ShellSetEnvironmentVariable (
   IN BOOLEAN                    Volatile\r
   )\r
 {\r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
     return (mEfiShellProtocol->SetEnv(EnvKey, EnvVal, Volatile));\r
-  } \r
+  }\r
 \r
   //\r
   // This feature does not exist under EFI shell\r
@@ -1079,7 +1079,7 @@ EnvironmentVariables and Status are only supported for UEFI Shell 2.0.
 Output is only supported for pre-UEFI Shell 2.0\r
 \r
   @param ImageHandle            Parent image that is starting the operation\r
-  @param CommandLine            pointer to null terminated command line.\r
+  @param CommandLine            pointer to NULL terminated command line.\r
   @param Output                 true to display debug output.  false to hide it.\r
   @param EnvironmentVariables   optional pointer to array of environment variables\r
                                 in the form "x=y".  if NULL current set is used.\r
@@ -1101,7 +1101,7 @@ ShellExecute (
   OUT EFI_STATUS                *Status OPTIONAL\r
   )\r
 {\r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
@@ -1112,7 +1112,7 @@ ShellExecute (
                                       CommandLine,\r
                                       EnvironmentVariables,\r
                                       Status));\r
-  } \r
+  }\r
   //\r
   // ASSERT that we must have EFI shell\r
   //\r
@@ -1121,15 +1121,15 @@ ShellExecute (
   // Call EFI Shell version (not using EnvironmentVariables or Status parameters)\r
   // Due to oddity in the EFI shell we want to dereference the ParentHandle here\r
   //\r
-  return (mEfiShellEnvironment2->Execute(*ParentHandle, \r
-                                        CommandLine, \r
+  return (mEfiShellEnvironment2->Execute(*ParentHandle,\r
+                                        CommandLine,\r
                                         Output));\r
 }\r
 /**\r
   Retreives the current directory path\r
 \r
-  If the DeviceName is NULL, it returns the current device's current directory \r
-  name. If the DeviceName is not NULL, it returns the current directory name \r
+  If the DeviceName is NULL, it returns the current device's current directory\r
+  name. If the DeviceName is not NULL, it returns the current directory name\r
   on specified drive.\r
 \r
   @param DeviceName             the name of the drive to get directory on\r
@@ -1143,12 +1143,12 @@ ShellGetCurrentDir (
   IN CHAR16                     *DeviceName OPTIONAL\r
   )\r
 {\r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
     return (mEfiShellProtocol->GetCurDir(DeviceName));\r
-  } \r
+  }\r
   //\r
   // ASSERT that we must have EFI shell\r
   //\r
@@ -1158,12 +1158,12 @@ ShellGetCurrentDir (
 /**\r
   sets (enabled or disabled) the page break mode\r
 \r
-  when page break mode is enabled the screen will stop scrolling \r
+  when page break mode is enabled the screen will stop scrolling\r
   and wait for operator input before scrolling a subsequent screen.\r
 \r
   @param CurrentState           TRUE to enable and FALSE to disable\r
 **/\r
-VOID \r
+VOID\r
 EFIAPI\r
 ShellSetPageBreakMode (\r
   IN BOOLEAN                    CurrentState\r
@@ -1173,7 +1173,7 @@ ShellSetPageBreakMode (
   // check for enabling\r
   //\r
   if (CurrentState != 0x00) {\r
-    // \r
+    //\r
     // check for UEFI Shell 2.0\r
     //\r
     if (mEfiShellProtocol != NULL) {\r
@@ -1183,7 +1183,7 @@ ShellSetPageBreakMode (
       mEfiShellProtocol->EnablePageBreak();\r
       return;\r
     } else {\r
-      // \r
+      //\r
       // ASSERT that must have EFI Shell\r
       //\r
       ASSERT(mEfiShellEnvironment2 != NULL);\r
@@ -1194,7 +1194,7 @@ ShellSetPageBreakMode (
       return;\r
     }\r
   } else {\r
-    // \r
+    //\r
     // check for UEFI Shell 2.0\r
     //\r
     if (mEfiShellProtocol != NULL) {\r
@@ -1204,7 +1204,7 @@ ShellSetPageBreakMode (
       mEfiShellProtocol->DisablePageBreak();\r
       return;\r
     } else {\r
-      // \r
+      //\r
       // ASSERT that must have EFI Shell\r
       //\r
       ASSERT(mEfiShellEnvironment2 != NULL);\r
@@ -1235,7 +1235,7 @@ typedef struct {
 \r
   if OldStyleFileList is NULL then ASSERT()\r
 \r
-  this function will convert a SHELL_FILE_ARG based list into a callee allocated \r
+  this function will convert a SHELL_FILE_ARG based list into a callee allocated\r
   EFI_SHELL_FILE_INFO based list.  it is up to the caller to free the memory via\r
   the ShellCloseFileMetaArg function.\r
 \r
@@ -1249,7 +1249,8 @@ EFIAPI
 InternalShellConvertFileListType (\r
   IN LIST_ENTRY                 *FileList,\r
   IN OUT LIST_ENTRY             *ListHead\r
-  ){\r
+  )\r
+{\r
   SHELL_FILE_ARG                *OldInfo;\r
   LIST_ENTRY                    *Link;\r
   EFI_SHELL_FILE_INFO_NO_CONST  *NewInfo;\r
@@ -1269,7 +1270,7 @@ InternalShellConvertFileListType (
     //\r
     // make sure the old list was valid\r
     //\r
-    ASSERT(OldInfo           != NULL); \r
+    ASSERT(OldInfo           != NULL);\r
     ASSERT(OldInfo->Info     != NULL);\r
     ASSERT(OldInfo->FullName != NULL);\r
     ASSERT(OldInfo->FileName != NULL);\r
@@ -1278,8 +1279,8 @@ InternalShellConvertFileListType (
     // allocate a new EFI_SHELL_FILE_INFO object\r
     //\r
     NewInfo               = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
-    \r
-    // \r
+\r
+    //\r
     // copy the simple items\r
     //\r
     NewInfo->Handle       = OldInfo->Handle;\r
@@ -1294,7 +1295,7 @@ InternalShellConvertFileListType (
     NewInfo->FullName     = AllocateZeroPool(StrSize(OldInfo->FullName));\r
     NewInfo->FileName     = AllocateZeroPool(StrSize(OldInfo->FileName));\r
     NewInfo->Info         = AllocateZeroPool((UINTN)OldInfo->Info->Size);\r
-    \r
+\r
     //\r
     // make sure all the memory allocations were sucessful\r
     //\r
@@ -1319,21 +1320,21 @@ InternalShellConvertFileListType (
 /**\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
+  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
   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
+  and will process '?' and '*' as such.  the list must be freed with a call to\r
   ShellCloseFileMetaArg().\r
 \r
-  If you are NOT appending to an existing list *ListHead must be NULL.  If \r
+  If you are NOT appending to an existing list *ListHead must be NULL.  If\r
   *ListHead is NULL then it must be callee freed.\r
 \r
   @param Arg                    pointer to path string\r
   @param OpenMode               mode to open files with\r
   @param ListHead               head of linked list of results\r
 \r
-  @retval EFI_SUCCESS           the operation was sucessful and the list head \r
+  @retval EFI_SUCCESS           the operation was sucessful and the list head\r
                                 contains the list of opened files\r
   #retval EFI_UNSUPPORTED       a previous ShellOpenFileMetaArg must be closed first.\r
                                 *ListHead is set to NULL.\r
@@ -1351,14 +1352,14 @@ ShellOpenFileMetaArg (
 {\r
   EFI_STATUS                    Status;\r
   LIST_ENTRY                    mOldStyleFileList;\r
-  \r
+\r
   //\r
   // ASSERT that Arg and ListHead are not NULL\r
   //\r
   ASSERT(Arg      != NULL);\r
   ASSERT(ListHead != NULL);\r
 \r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
@@ -1368,9 +1369,9 @@ ShellOpenFileMetaArg (
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       InitializeListHead(&((*ListHead)->Link));\r
-    }    \r
-    Status = mEfiShellProtocol->OpenFileList(Arg, \r
-                                           OpenMode, \r
+    }\r
+    Status = mEfiShellProtocol->OpenFileList(Arg,\r
+                                           OpenMode,\r
                                            ListHead);\r
     if (EFI_ERROR(Status)) {\r
       mEfiShellProtocol->RemoveDupInFileList(ListHead);\r
@@ -1378,7 +1379,7 @@ ShellOpenFileMetaArg (
       Status = mEfiShellProtocol->RemoveDupInFileList(ListHead);\r
     }\r
     return (Status);\r
-  } \r
+  }\r
 \r
   //\r
   // ASSERT that we must have EFI shell\r
@@ -1440,18 +1441,18 @@ ShellCloseFileMetaArg (
   //\r
   ASSERT(ListHead != NULL);\r
 \r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellProtocol != NULL) {\r
     return (mEfiShellProtocol->FreeFileList(ListHead));\r
   } else {\r
     //\r
-    // Since this is EFI Shell version we need to free our internally made copy \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
-        ; IsListEmpty(&(*ListHead)->Link) == FALSE \r
+    for ( Node = GetFirstNode(&(*ListHead)->Link)\r
+        ; IsListEmpty(&(*ListHead)->Link) == FALSE\r
         ; Node = GetFirstNode(&(*ListHead)->Link)) {\r
       RemoveEntryList(Node);\r
       ((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle->Close(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle);\r
@@ -1464,6 +1465,145 @@ ShellCloseFileMetaArg (
   }\r
 }\r
 \r
+/**\r
+  Find a file by searching the CWD and then the path.\r
+\r
+  If FileName is NULL then ASSERT.\r
+\r
+  If the return value is not NULL then the memory must be caller freed.\r
+\r
+  @param FileName               Filename string.\r
+\r
+  @retval NULL                  the file was not found\r
+  @return !NULL                 the full path to the file.\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+ShellFindFilePath (\r
+  IN CONST CHAR16 *FileName\r
+  )\r
+{\r
+  CONST CHAR16      *Path;\r
+  EFI_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
+  Path = ShellGetEnvironmentVariable(L"cwd");\r
+  if (Path != NULL) {\r
+    Size = StrSize(Path);\r
+    Size += StrSize(FileName);\r
+    TestPath = AllocateZeroPool(Size);\r
+    StrCpy(TestPath, Path);\r
+    StrCat(TestPath, FileName);\r
+    Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
+    if (!EFI_ERROR(Status)){\r
+      RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);\r
+      ShellCloseFile(&Handle);\r
+      FreePool(TestPath);\r
+      return (RetVal);\r
+    }\r
+    FreePool(TestPath);\r
+  }\r
+  Path = ShellGetEnvironmentVariable(L"path");\r
+  if (Path != NULL) {\r
+    Size = StrSize(Path);\r
+    Size += StrSize(FileName);\r
+    TestPath = AllocateZeroPool(Size);\r
+    Walker = (CHAR16*)Path;\r
+    do {\r
+      CopyMem(TestPath, Walker, StrSize(Walker));\r
+      TempChar = StrStr(TestPath, L";");\r
+      if (TempChar != NULL) {\r
+        *TempChar = CHAR_NULL;\r
+      }\r
+      StrCat(TestPath, FileName);\r
+      if (StrStr(Walker, L";") != NULL) {\r
+        Walker = StrStr(Walker, L";") + 1;\r
+      } else {\r
+        Walker = NULL;\r
+      }\r
+      Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r
+      if (!EFI_ERROR(Status)){\r
+        RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);\r
+        ShellCloseFile(&Handle);\r
+        break;\r
+      }\r
+    } while (Walker != NULL && Walker[0] != CHAR_NULL);\r
+    FreePool(TestPath);\r
+  }\r
+  return (RetVal);\r
+}\r
+\r
+/**\r
+  Find a file by searching the CWD and then the path with a variable set of file\r
+  extensions.  If the file is not found it will append each extension in the list\r
+  in the order provided and return the first one that is successful.\r
+\r
+  If FileName is NULL, then ASSERT.\r
+  If FileExtension is NULL, then behavior is identical to ShellFindFilePath.\r
+\r
+  If the return value is not NULL then the memory must be caller freed.\r
+\r
+  @param[in] FileName           Filename string.\r
+  @param[in] FileExtension      Semi-colon delimeted list of possible extensions.\r
+\r
+  @retval NULL                  The file was not found.\r
+  @retval !NULL                 The path to the file.\r
+**/\r
+CHAR16 *\r
+EFIAPI\r
+ShellFindFilePathEx (\r
+  IN CONST CHAR16 *FileName,\r
+  IN CONST CHAR16 *FileExtension\r
+  )\r
+{\r
+  CHAR16            *TestPath;\r
+  CHAR16            *RetVal;\r
+  CONST CHAR16      *ExtensionWalker;\r
+  UINTN             Size;\r
+  CHAR16            *TempChar;\r
+\r
+  ASSERT(FileName != NULL);\r
+  if (FileExtension == NULL) {\r
+    return (ShellFindFilePath(FileName));\r
+  }\r
+  RetVal = ShellFindFilePath(FileName);\r
+  if (RetVal != NULL) {\r
+    return (RetVal);\r
+  }\r
+  Size =  StrSize(FileName);\r
+  Size += StrSize(FileExtension);\r
+  TestPath = AllocateZeroPool(Size);\r
+  for (ExtensionWalker = FileExtension ;  ; ExtensionWalker = StrStr(ExtensionWalker, L";") + 1 ){\r
+    StrCpy(TestPath, FileName);\r
+    if (ExtensionWalker != NULL) {\r
+      StrCat(TestPath, ExtensionWalker);\r
+    }\r
+    TempChar = StrStr(TestPath, L";");\r
+    if (TempChar != NULL) {\r
+      *TempChar = CHAR_NULL;\r
+    }\r
+    RetVal = ShellFindFilePath(TestPath);\r
+    if (RetVal != NULL) {\r
+      break;\r
+    }\r
+    //\r
+    // Must be after first loop...\r
+    //\r
+    if (StrStr(ExtensionWalker, L";") == NULL) {\r
+      break;\r
+    }\r
+  }\r
+  FreePool(TestPath);\r
+  return (RetVal);\r
+}\r
+\r
 typedef struct {\r
   LIST_ENTRY     Link;\r
   CHAR16         *Name;\r
@@ -1473,9 +1613,9 @@ typedef struct {
 } SHELL_PARAM_PACKAGE;\r
 \r
 /**\r
-  Checks the list of valid arguments and returns TRUE if the item was found.  If the \r
+  Checks the list of valid arguments and returns TRUE if the item was found.  If the\r
   return value is TRUE then the type parameter is set also.\r
-  \r
+\r
   if CheckList is NULL then ASSERT();\r
   if Name is NULL then ASSERT();\r
   if Type is NULL then ASSERT();\r
@@ -1554,14 +1694,14 @@ InternalIsFlag (
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
-  if (((Name[0] == L'-' || Name[0] == L'+') && ShellInternalIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers == TRUE) {\r
+  if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers != FALSE) {\r
     return (FALSE);\r
   }\r
 \r
   //\r
   // If the Name has a / or - as the first character return TRUE\r
   //\r
-  if ((Name[0] == L'/') || \r
+  if ((Name[0] == L'/') ||\r
       (Name[0] == L'-') ||\r
       (Name[0] == L'+')\r
       ) {\r
@@ -1571,13 +1711,13 @@ InternalIsFlag (
 }\r
 \r
 /**\r
-  Checks the command line arguments passed against the list of valid ones.  \r
+  Checks the command line arguments passed against the list of valid ones.\r
 \r
   If no initialization is required, then return RETURN_SUCCESS.\r
-  \r
+\r
   @param CheckList              pointer to list of parameters to check\r
   @param CheckPackage           pointer to pointer to list checked values\r
-  @param ProblemParam           optional pointer to pointer to unicode string for \r
+  @param ProblemParam           optional pointer to pointer to unicode string for\r
                                 the paramater that caused failure.  If used then the\r
                                 caller is responsible for freeing the memory.\r
   @param AutoPageBreak          will automatically set PageBreakEnabled for "b" parameter\r
@@ -1587,10 +1727,10 @@ InternalIsFlag (
   @retval EFI_SUCCESS           The operation completed sucessfully.\r
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed\r
   @retval EFI_INVALID_PARAMETER A parameter was invalid\r
-  @retval EFI_VOLUME_CORRUPTED  the command line was corrupt.  an argument was \r
-                                duplicated.  the duplicated command line argument \r
+  @retval EFI_VOLUME_CORRUPTED  the command line was corrupt.  an argument was\r
+                                duplicated.  the duplicated command line argument\r
                                 was returned in ProblemParam if provided.\r
-  @retval EFI_NOT_FOUND         a argument required a value that was missing.  \r
+  @retval EFI_NOT_FOUND         a argument required a value that was missing.\r
                                 the invalid command line argument was returned in\r
                                 ProblemParam if provided.\r
 **/\r
@@ -1609,11 +1749,13 @@ InternalCommandLineParse (
   UINTN                         LoopCounter;\r
   ParamType                     CurrentItemType;\r
   SHELL_PARAM_PACKAGE           *CurrentItemPackage;\r
-  BOOLEAN                       GetItemValue;\r
+  UINTN                         GetItemValue;\r
+  UINTN                         ValueSize;\r
 \r
   CurrentItemPackage = NULL;\r
   mTotalParameterCount = 0;\r
-  GetItemValue = FALSE;\r
+  GetItemValue = 0;\r
+  ValueSize = 0;\r
 \r
   //\r
   // If there is only 1 item we dont need to do anything\r
@@ -1643,12 +1785,12 @@ InternalCommandLineParse (
       //\r
       // do nothing for NULL argv\r
       //\r
-    } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType) == TRUE) {\r
+    } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType) != FALSE) {\r
       //\r
       // We might have leftover if last parameter didnt have optional value\r
       //\r
-      if (GetItemValue == TRUE) {\r
-        GetItemValue = FALSE;\r
+      if (GetItemValue != 0) {\r
+        GetItemValue = 0;\r
         InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
       //\r
@@ -1666,27 +1808,48 @@ InternalCommandLineParse (
       //\r
       // Does this flag require a value\r
       //\r
-      if (CurrentItemPackage->Type == TypeValue) {\r
-        //\r
-        // trigger the next loop to populate the value of this item\r
-        //\r
-        GetItemValue = TRUE; \r
-      } else {\r
+      switch (CurrentItemPackage->Type) {\r
         //\r
-        // this item has no value expected; we are done\r
+        // possibly trigger the next loop(s) to populate the value of this item\r
         //\r
-        InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+        case TypeValue:\r
+          GetItemValue = 1;\r
+          ValueSize = 0;\r
+          break;\r
+        case TypeDoubleValue:\r
+          GetItemValue = 2;\r
+          ValueSize = 0;\r
+          break;\r
+        case TypeMaxValue:\r
+          GetItemValue = (UINTN)(-1);\r
+          ValueSize = 0;\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
+          break;\r
       }\r
-    } else if (GetItemValue == TRUE && InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {\r
+    } else if (GetItemValue != 0 && InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {\r
       ASSERT(CurrentItemPackage != NULL);\r
       //\r
-      // get the item VALUE for the previous flag\r
+      // get the item VALUE for a previous flag\r
       //\r
-      GetItemValue = FALSE;\r
-      CurrentItemPackage->Value = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
+      CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);\r
       ASSERT(CurrentItemPackage->Value != NULL);\r
-      StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
-      InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\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
+      GetItemValue--;\r
+      if (GetItemValue == 0) {\r
+        InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+      }\r
     } else if (InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {\r
       //\r
       // add this one as a non-flag\r
@@ -1716,6 +1879,10 @@ InternalCommandLineParse (
       return (EFI_VOLUME_CORRUPTED);\r
     }\r
   }\r
+  if (GetItemValue != 0) {\r
+    GetItemValue = 0;\r
+    InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
+  }\r
   //\r
   // support for AutoPageBreak\r
   //\r
@@ -1726,27 +1893,27 @@ InternalCommandLineParse (
 }\r
 \r
 /**\r
-  Checks the command line arguments passed against the list of valid ones.  \r
+  Checks the command line arguments passed against the list of valid ones.\r
   Optionally removes NULL values first.\r
-  \r
+\r
   If no initialization is required, then return RETURN_SUCCESS.\r
-  \r
+\r
   @param CheckList              pointer to list of parameters to check\r
   @param CheckPackage           pointer to pointer to list checked values\r
-  @param ProblemParam           optional pointer to pointer to unicode string for \r
+  @param ProblemParam           optional pointer to pointer to unicode string for\r
                                 the paramater that caused failure.\r
   @param AutoPageBreak          will automatically set PageBreakEnabled for "b" parameter\r
 \r
   @retval EFI_SUCCESS           The operation completed sucessfully.\r
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed\r
   @retval EFI_INVALID_PARAMETER A parameter was invalid\r
-  @retval EFI_VOLUME_CORRUPTED  the command line was corrupt.  an argument was \r
-                                duplicated.  the duplicated command line argument \r
+  @retval EFI_VOLUME_CORRUPTED  the command line was corrupt.  an argument was\r
+                                duplicated.  the duplicated command line argument\r
                                 was returned in ProblemParam if provided.\r
   @retval EFI_DEVICE_ERROR      the commands contained 2 opposing arguments.  one\r
-                                of the command line arguments was returned in \r
+                                of the command line arguments was returned in\r
                                 ProblemParam if provided.\r
-  @retval EFI_NOT_FOUND         a argument required a value that was missing.  \r
+  @retval EFI_NOT_FOUND         a argument required a value that was missing.\r
                                 the invalid command line argument was returned in\r
                                 ProblemParam if provided.\r
 **/\r
@@ -1759,33 +1926,33 @@ ShellCommandLineParseEx (
   IN BOOLEAN                    AutoPageBreak,\r
   IN BOOLEAN                    AlwaysAllowNumbers\r
   ) {\r
-  // \r
+  //\r
   // ASSERT that CheckList and CheckPackage aren't NULL\r
   //\r
   ASSERT(CheckList    != NULL);\r
   ASSERT(CheckPackage != NULL);\r
 \r
-  // \r
+  //\r
   // Check for UEFI Shell 2.0 protocols\r
   //\r
   if (mEfiShellParametersProtocol != NULL) {\r
-    return (InternalCommandLineParse(CheckList, \r
-                                     CheckPackage, \r
-                                     ProblemParam, \r
-                                     AutoPageBreak, \r
+    return (InternalCommandLineParse(CheckList,\r
+                                     CheckPackage,\r
+                                     ProblemParam,\r
+                                     AutoPageBreak,\r
                                      (CONST CHAR16**) mEfiShellParametersProtocol->Argv,\r
                                      mEfiShellParametersProtocol->Argc,\r
                                      AlwaysAllowNumbers));\r
   }\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
+  return (InternalCommandLineParse(CheckList,\r
+                                   CheckPackage,\r
+                                   ProblemParam,\r
+                                   AutoPageBreak,\r
                                    (CONST CHAR16**) mEfiShellInterface->Argv,\r
                                    mEfiShellInterface->Argc,\r
                                    AlwaysAllowNumbers));\r
@@ -1842,7 +2009,7 @@ ShellCommandLineFreeVarList (
     if (((SHELL_PARAM_PACKAGE*)Node)->Value != NULL) {\r
       FreePool(((SHELL_PARAM_PACKAGE*)Node)->Value);\r
     }\r
-    \r
+\r
     //\r
     // free the node structure\r
     //\r
@@ -1860,7 +2027,7 @@ ShellCommandLineFreeVarList (
 \r
   if CheckPackage is NULL then return FALSE.\r
   if KeyString is NULL then ASSERT()\r
-  \r
+\r
   @param CheckPackage           The package of parsed command line arguments\r
   @param KeyString              the Key of the command line argument to check for\r
 \r
@@ -1890,9 +2057,9 @@ ShellCommandLineGetFlag (
   //\r
   // enumerate through the list of parametrs\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage) \r
-      ; !IsNull (CheckPackage, Node) \r
-      ; Node = GetNextNode(CheckPackage, Node) \r
+  for ( Node = GetFirstNode(CheckPackage)\r
+      ; !IsNull (CheckPackage, Node)\r
+      ; Node = GetNextNode(CheckPackage, Node)\r
       ){\r
     //\r
     // If the Name matches, return TRUE (and there may be NULL name)\r
@@ -1901,7 +2068,7 @@ ShellCommandLineGetFlag (
       //\r
       // If Type is TypeStart then only compare the begining of the strings\r
       //\r
-      if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart \r
+      if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart\r
         && StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0\r
         ){\r
         return (TRUE);\r
@@ -1916,7 +2083,7 @@ ShellCommandLineGetFlag (
   returns value from command line argument\r
 \r
   value parameters are in the form of "-<Key> value" or "/<Key> value"\r
-  \r
+\r
   if CheckPackage is NULL, then return NULL;\r
 \r
   @param CheckPackage           The package of parsed command line arguments\r
@@ -1943,9 +2110,9 @@ ShellCommandLineGetValue (
   //\r
   // enumerate through the list of parametrs\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage) \r
-      ; !IsNull (CheckPackage, Node) \r
-      ; Node = GetNextNode(CheckPackage, Node) \r
+  for ( Node = GetFirstNode(CheckPackage)\r
+      ; !IsNull (CheckPackage, Node)\r
+      ; Node = GetNextNode(CheckPackage, Node)\r
       ){\r
     //\r
     // If the Name matches, return the value (name can be NULL)\r
@@ -1954,7 +2121,7 @@ ShellCommandLineGetValue (
       //\r
       // If Type is TypeStart then only compare the begining of the strings\r
       //\r
-      if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart \r
+      if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart\r
         && StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0\r
         ){\r
         //\r
@@ -1975,11 +2142,11 @@ ShellCommandLineGetValue (
   returns raw value from command line argument\r
 \r
   raw value parameters are in the form of "value" in a specific position in the list\r
-  \r
+\r
   if CheckPackage is NULL, then return NULL;\r
 \r
   @param CheckPackage           The package of parsed command line arguments\r
-  @param Position               the position of the value \r
+  @param Position               the position of the value\r
 \r
   @retval NULL                  the flag is not on the command line\r
   @return !=NULL                pointer to unicode string of the value\r
@@ -2002,9 +2169,9 @@ ShellCommandLineGetRawValue (
   //\r
   // enumerate through the list of parametrs\r
   //\r
-  for ( Node = GetFirstNode(CheckPackage) \r
-      ; !IsNull (CheckPackage, Node) \r
-      ; Node = GetNextNode(CheckPackage, Node) \r
+  for ( Node = GetFirstNode(CheckPackage)\r
+      ; !IsNull (CheckPackage, Node)\r
+      ; Node = GetNextNode(CheckPackage, Node)\r
       ){\r
     //\r
     // If the position matches, return the value\r
@@ -2017,8 +2184,8 @@ ShellCommandLineGetRawValue (
 }\r
 \r
 /**\r
-  returns the number of command line value parameters that were parsed.  \r
-  \r
+  returns the number of command line value parameters that were parsed.\r
+\r
   this will not include flags.\r
 \r
   @retval (UINTN)-1     No parsing has ocurred\r
@@ -2028,14 +2195,63 @@ UINTN
 EFIAPI\r
 ShellCommandLineGetCount(\r
   VOID\r
-  ){\r
+  )\r
+{\r
   return (mTotalParameterCount);\r
 }\r
 \r
 /**\r
-  This is a find and replace function.  it will return the NewString as a copy of \r
+  Determins 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 CheckPackage is NULL, then ASSERT.\r
+\r
+  @param[in] CheckPackage       The package of parsed command line arguments.\r
+  @param[out] Param             Upon finding one, a pointer to the duplicated parameter.\r
+\r
+  @retval EFI_SUCCESS           No parameters were duplicated.\r
+  @retval EFI_DEVICE_ERROR      A duplicate was found.\r
+  **/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellCommandLineCheckDuplicate (\r
+  IN CONST LIST_ENTRY              *CheckPackage,\r
+  OUT CHAR16                       **Param\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 (StrCmp(((SHELL_PARAM_PACKAGE*)Node1)->Name, ((SHELL_PARAM_PACKAGE*)Node2)->Name) == 0) {\r
+        if (Param != NULL) {\r
+          *Param = NULL;\r
+          *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);\r
+        }\r
+        return (EFI_DEVICE_ERROR);\r
+      }\r
+    }\r
+  }\r
+  return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+  This is a find and replace function.  Upon successful return the NewString is a copy of\r
   SourceString with each instance of FindTarget replaced with ReplaceWith.\r
 \r
+  If SourceString and NewString overlap the behavior is undefined.\r
+\r
   If the string would grow bigger than NewSize it will halt and return error.\r
 \r
   @param[in] SourceString             String with source buffer\r
@@ -2043,27 +2259,30 @@ ShellCommandLineGetCount(
   @param[in] NewSize                  Size in bytes of NewString\r
   @param[in] FindTarget               String to look for\r
   @param[in[ ReplaceWith              String to replace FindTarget with\r
-\r
-  @retval EFI_INVALID_PARAMETER       SourceString was NULL\r
-  @retval EFI_INVALID_PARAMETER       NewString was NULL\r
-  @retval EFI_INVALID_PARAMETER       FindTarget was NULL\r
-  @retval EFI_INVALID_PARAMETER       ReplaceWith was NULL\r
-  @retval EFI_INVALID_PARAMETER       FindTarget had length < 1\r
-  @retval EFI_INVALID_PARAMETER       SourceString had length < 1\r
-  @retval EFI_BUFFER_TOO_SMALL        NewSize was less than the minimum size to hold \r
-                                      the new string (truncation occurred)\r
-  @retval EFI_SUCCESS                 the string was sucessfully copied with replacement\r
+  @param[in] SkipPreCarrot            If TRUE will skip a FindTarget that has a '^'\r
+                                      immediately before it.\r
+\r
+  @retval EFI_INVALID_PARAMETER       SourceString was NULL.\r
+  @retval EFI_INVALID_PARAMETER       NewString was NULL.\r
+  @retval EFI_INVALID_PARAMETER       FindTarget was NULL.\r
+  @retval EFI_INVALID_PARAMETER       ReplaceWith was NULL.\r
+  @retval EFI_INVALID_PARAMETER       FindTarget had length < 1.\r
+  @retval EFI_INVALID_PARAMETER       SourceString had length < 1.\r
+  @retval EFI_BUFFER_TOO_SMALL        NewSize was less than the minimum size to hold\r
+                                      the new string (truncation occurred).\r
+  @retval EFI_SUCCESS                 the string was sucessfully copied with replacement.\r
 **/\r
 \r
 EFI_STATUS\r
 EFIAPI\r
-CopyReplace(\r
+ShellCopySearchAndReplace2(\r
   IN CHAR16 CONST                     *SourceString,\r
   IN CHAR16                           *NewString,\r
   IN UINTN                            NewSize,\r
   IN CONST CHAR16                     *FindTarget,\r
-  IN CONST CHAR16                     *ReplaceWith\r
-  ) \r
+  IN CONST CHAR16                     *ReplaceWith,\r
+  IN CONST BOOLEAN                    SkipPreCarrot\r
+  )\r
 {\r
   UINTN Size;\r
   if ( (SourceString == NULL)\r
@@ -2077,7 +2296,13 @@ CopyReplace(
   }\r
   NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r
   while (*SourceString != CHAR_NULL) {\r
-    if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0) {\r
+    //\r
+    // if we find the FindTarget and either Skip == FALSE or Skip == TRUE 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 == FALSE)\r
+      ){\r
       SourceString += StrLen(FindTarget);\r
       Size = StrSize(NewString);\r
       if ((Size + (StrLen(ReplaceWith)*sizeof(CHAR16))) > NewSize) {\r
@@ -2096,18 +2321,50 @@ CopyReplace(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  Internal worker function to output a string.\r
+\r
+  This function will output a string to the correct StdOut.\r
+\r
+  @param[in] String       The string to print out.\r
+\r
+  @retval EFI_SUCCESS     The operation was sucessful.\r
+  @retval !EFI_SUCCESS    The operation failed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InternalPrintTo (\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  UINTN Size;\r
+  Size = StrSize(String) - sizeof(CHAR16);\r
+  if (mEfiShellParametersProtocol != NULL) {\r
+    return (mEfiShellParametersProtocol->StdOut->Write(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r
+  }\r
+  if (mEfiShellInterface          != NULL) {\r
+    //\r
+    // Divide in half for old shell.  Must be string length not size.\r
+    //\r
+    Size /= 2;\r
+    return (         mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut,          &Size, (VOID*)String));\r
+  }\r
+  ASSERT(FALSE);\r
+  return (EFI_UNSUPPORTED);\r
+}\r
+\r
 /**\r
   Print at a specific location on the screen.\r
 \r
   This function will move the cursor to a given screen location and print the specified string\r
-  \r
-  If -1 is specified for either the Row or Col the current screen location for BOTH \r
+\r
+  If -1 is specified for either the Row or Col the current screen location for BOTH\r
   will be used.\r
 \r
   if either Row or Col is out of range for the current console, then ASSERT\r
   if Format is NULL, then ASSERT\r
 \r
-  In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
+  In addition to the standard %-based flags as supported by UefiLib Print() this supports\r
   the following additional flags:\r
     %N       -   Set output attribute to normal\r
     %H       -   Set output attribute to highlight\r
@@ -2132,43 +2389,32 @@ InternalShellPrintWorker(
   IN INT32                Row OPTIONAL,\r
   IN CONST CHAR16         *Format,\r
   VA_LIST                 Marker\r
-  ) \r
+  )\r
 {\r
-  UINTN             BufferSize;\r
-  CHAR16            *PostReplaceFormat;\r
-  CHAR16            *PostReplaceFormat2;\r
   UINTN             Return;\r
   EFI_STATUS        Status;\r
   UINTN             NormalAttribute;\r
   CHAR16            *ResumeLocation;\r
   CHAR16            *FormatWalker;\r
-  \r
-  BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
-  PostReplaceFormat = AllocateZeroPool (BufferSize);\r
-  ASSERT (PostReplaceFormat != NULL);\r
-  PostReplaceFormat2 = AllocateZeroPool (BufferSize);\r
-  ASSERT (PostReplaceFormat2 != NULL);\r
 \r
   //\r
   // Back and forth each time fixing up 1 of our flags...\r
   //\r
-  Status = CopyReplace(Format,             PostReplaceFormat,  BufferSize, L"%N", L"%%N");\r
+  Status = ShellLibCopySearchAndReplace(Format,             mPostReplaceFormat,  PcdGet16 (PcdShellPrintBufferSize), L"%N", L"%%N");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat,  PostReplaceFormat2, BufferSize, L"%E", L"%%E");\r
+  Status = ShellLibCopySearchAndReplace(mPostReplaceFormat,  mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%E", L"%%E");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat,  BufferSize, L"%H", L"%%H");\r
+  Status = ShellLibCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat,  PcdGet16 (PcdShellPrintBufferSize), L"%H", L"%%H");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat,  PostReplaceFormat2, BufferSize, L"%B", L"%%B");\r
+  Status = ShellLibCopySearchAndReplace(mPostReplaceFormat,  mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%B", L"%%B");\r
   ASSERT_EFI_ERROR(Status);\r
-  Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat,  BufferSize, L"%V", L"%%V");\r
+  Status = ShellLibCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat,  PcdGet16 (PcdShellPrintBufferSize), L"%V", L"%%V");\r
   ASSERT_EFI_ERROR(Status);\r
 \r
   //\r
   // Use the last buffer from replacing to print from...\r
   //\r
-  Return = UnicodeVSPrint (PostReplaceFormat2, BufferSize, PostReplaceFormat, Marker);\r
-\r
-  FreePool(PostReplaceFormat);\r
+  Return = UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), mPostReplaceFormat, Marker);\r
 \r
   if (Col != -1 && Row != -1) {\r
     Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r
@@ -2176,7 +2422,7 @@ InternalShellPrintWorker(
   }\r
 \r
   NormalAttribute = gST->ConOut->Mode->Attribute;\r
-  FormatWalker = PostReplaceFormat2;\r
+  FormatWalker = mPostReplaceFormat2;\r
   while (*FormatWalker != CHAR_NULL) {\r
     //\r
     // Find the next attribute change request\r
@@ -2188,7 +2434,7 @@ InternalShellPrintWorker(
     //\r
     // print the current FormatWalker string\r
     //\r
-    Status = gST->ConOut->OutputString(gST->ConOut, FormatWalker);\r
+    Status = InternalPrintTo(FormatWalker);\r
     ASSERT_EFI_ERROR(Status);\r
     //\r
     // update the attribute\r
@@ -2211,7 +2457,12 @@ InternalShellPrintWorker(
           gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
           break;\r
         default:\r
-          ASSERT(FALSE);\r
+          //\r
+          // Print a simple '%' symbol\r
+          //\r
+          Status = InternalPrintTo(L"%");\r
+          ASSERT_EFI_ERROR(Status);\r
+          ResumeLocation = ResumeLocation - 1;\r
           break;\r
       }\r
     } else {\r
@@ -2228,23 +2479,21 @@ InternalShellPrintWorker(
     FormatWalker = ResumeLocation + 2;\r
   }\r
 \r
-  FreePool(PostReplaceFormat2);\r
-\r
   return (Return);\r
 }\r
 \r
 /**\r
   Print at a specific location on the screen.\r
 \r
-  This function will move the cursor to a given screen location and print the specified string\r
-  \r
-  If -1 is specified for either the Row or Col the current screen location for BOTH \r
+  This function will move the cursor to a given screen location and print the specified string.\r
+\r
+  If -1 is specified for either the Row or Col the current screen location for BOTH\r
   will be used.\r
 \r
-  if either Row or Col is out of range for the current console, then ASSERT\r
-  if Format is NULL, then ASSERT\r
+  If either Row or Col is out of range for the current console, then ASSERT.\r
+  If Format is NULL, then ASSERT.\r
 \r
-  In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
+  In addition to the standard %-based flags as supported by UefiLib Print() this supports\r
   the following additional flags:\r
     %N       -   Set output attribute to normal\r
     %H       -   Set output attribute to highlight\r
@@ -2268,47 +2517,52 @@ ShellPrintEx(
   IN INT32                Row OPTIONAL,\r
   IN CONST CHAR16         *Format,\r
   ...\r
-  ) \r
+  )\r
 {\r
   VA_LIST           Marker;\r
+  EFI_STATUS        Status;\r
   VA_START (Marker, Format);\r
-  return (InternalShellPrintWorker(Col, Row, Format, Marker));\r
+  Status = InternalShellPrintWorker(Col, Row, Format, Marker);\r
+  VA_END(Marker);\r
+  return(Status);\r
 }\r
 \r
 /**\r
   Print at a specific location on the screen.\r
 \r
-  This function will move the cursor to a given screen location, print the specified string, \r
-  and return the cursor to the original locaiton.  \r
-  \r
-  If -1 is specified for either the Row or Col the current screen location for BOTH \r
-  will be used and the cursor's position will not be moved back to an original location.\r
+  This function will move the cursor to a given screen location and print the specified string.\r
 \r
-  if either Row or Col is out of range for the current console, then ASSERT\r
-  if Format is NULL, then ASSERT\r
+  If -1 is specified for either the Row or Col the current screen location for BOTH\r
+  will be used.\r
 \r
-  In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
+  If either Row or Col is out of range for the current console, then ASSERT.\r
+  If Format is NULL, then ASSERT.\r
+\r
+  In addition to the standard %-based flags as supported by UefiLib Print() this supports\r
   the following additional flags:\r
-    %N       -   Set output attribute to normal\r
-    %H       -   Set output attribute to highlight\r
-    %E       -   Set output attribute to error\r
-    %B       -   Set output attribute to blue color\r
-    %V       -   Set output attribute to green color\r
+    %N       -   Set output attribute to normal.\r
+    %H       -   Set output attribute to highlight.\r
+    %E       -   Set output attribute to error.\r
+    %B       -   Set output attribute to blue color.\r
+    %V       -   Set output attribute to green color.\r
 \r
   Note: The background color is controlled by the shell command cls.\r
 \r
-  @param[in] Row                the row to print at\r
-  @param[in] Col                the column to print at\r
-  @param[in] HiiFormatStringId  the format string Id for getting from Hii\r
-  @param[in] HiiFormatHandle    the format string Handle for getting from Hii\r
+  @param[in] Row                The row to print at.\r
+  @param[in] Col                The column to print at.\r
+  @param[in] Language           The language of the string to retrieve.  If this parameter\r
+                                is NULL, then the current platform language is used.\r
+  @param[in] HiiFormatStringId  The format string Id for getting from Hii.\r
+  @param[in] HiiFormatHandle    The format string Handle for getting from Hii.\r
 \r
-  @return the number of characters printed to the screen\r
+  @return the number of characters printed to the screen.\r
 **/\r
 UINTN\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
   ...\r
@@ -2319,12 +2573,13 @@ ShellPrintHiiEx(
   UINTN             RetVal;\r
 \r
   VA_START (Marker, HiiFormatHandle);\r
-  HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, NULL);\r
+  HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language);\r
   ASSERT(HiiFormatString != NULL);\r
 \r
   RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r
 \r
   FreePool(HiiFormatString);\r
+  VA_END(Marker);\r
 \r
   return (RetVal);\r
 }\r
@@ -2347,6 +2602,8 @@ ShellIsDirectory(
   EFI_STATUS        Status;\r
   EFI_FILE_HANDLE   Handle;\r
 \r
+  ASSERT(DirName != NULL);\r
+\r
   Handle = NULL;\r
 \r
   Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);\r
@@ -2362,3 +2619,199 @@ ShellIsDirectory(
   return (EFI_NOT_FOUND);\r
 }\r
 \r
+/**\r
+  Function to determine if a given filename represents a file.\r
+\r
+  @param[in] Name         Path to file to test.\r
+\r
+  @retval EFI_SUCCESS     The Path represents a file.\r
+  @retval EFI_NOT_FOUND   The Path does not represent a file.\r
+  @retval other           The path failed to open.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellIsFile(\r
+  IN CONST CHAR16 *Name\r
+  )\r
+{\r
+  EFI_STATUS        Status;\r
+  EFI_FILE_HANDLE   Handle;\r
+\r
+  ASSERT(Name != NULL);\r
+\r
+  Handle = NULL;\r
+\r
+  Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);\r
+  if (EFI_ERROR(Status)) {\r
+    return (Status);\r
+  }\r
+\r
+  if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r
+    ShellCloseFile(&Handle);\r
+    return (EFI_SUCCESS);\r
+  }\r
+  ShellCloseFile(&Handle);\r
+  return (EFI_NOT_FOUND);\r
+}\r
+\r
+/**\r
+  Function to determine if a given filename represents a file.\r
+\r
+  This will search the CWD and then the Path.\r
+\r
+  If Name is NULL, then ASSERT.\r
+\r
+  @param[in] Name         Path to file to test.\r
+\r
+  @retval EFI_SUCCESS     The Path represents a file.\r
+  @retval EFI_NOT_FOUND   The Path does not represent a file.\r
+  @retval other           The path failed to open.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellIsFileInPath(\r
+  IN CONST CHAR16 *Name\r
+  ) {\r
+  CHAR16      *NewName;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!EFI_ERROR(ShellIsFile(Name))) {\r
+    return (TRUE);\r
+  }\r
+\r
+  NewName = ShellFindFilePath(Name);\r
+  if (NewName == NULL) {\r
+    return (EFI_NOT_FOUND);\r
+  }\r
+  Status = ShellIsFile(NewName);\r
+  FreePool(NewName);\r
+  return (Status);\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.\r
+\r
+  @param[in] String   String representation of a number\r
+\r
+  @retval all         the number\r
+**/\r
+UINTN\r
+EFIAPI\r
+ShellStrToUintn(\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  CONST CHAR16  *Walker;\r
+  for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++);\r
+  if (Walker == NULL || *Walker == CHAR_NULL) {\r
+    ASSERT(FALSE);\r
+    return ((UINTN)(-1));\r
+  } else {\r
+    if (StrnCmp(Walker, L"0x", 2) == 0 || StrnCmp(Walker, L"0X", 2) == 0){\r
+      return (StrHexToUintn(Walker));\r
+    }\r
+    return (StrDecimalToUintn(Walker));\r
+  }\r
+}\r
+\r
+/**\r
+  Safely append with automatic string resizing given length of Destination and\r
+  desired length of copy from Source.\r
+\r
+  append the first D characters of Source to the end of Destination, where D is\r
+  the lesser of Count and the StrLen() of Source. If appending those D characters\r
+  will fit within Destination (whose Size is given as CurrentSize) and\r
+  still leave room for a NULL terminator, then those characters are appended,\r
+  starting at the original terminating NULL of Destination, and a new terminating\r
+  NULL is appended.\r
+\r
+  If appending D characters onto Destination will result in a overflow of the size\r
+  given in CurrentSize the string will be grown such that the copy can be performed\r
+  and CurrentSize will be updated to the new size.\r
+\r
+  If Source is NULL, there is nothing to append, just return the current buffer in\r
+  Destination.\r
+\r
+  if Destination is NULL, then ASSERT()\r
+  if Destination's current length (including NULL terminator) is already more then\r
+  CurrentSize, then ASSERT()\r
+\r
+  @param[in,out] Destination   The String to append onto\r
+  @param[in,out] CurrentSize   on call the number of bytes in Destination.  On\r
+                                return possibly the new size (still in bytes).  if NULL\r
+                                then allocate whatever is needed.\r
+  @param[in]      Source        The String to append from\r
+  @param[in]      Count         Maximum number of characters to append.  if 0 then\r
+                                all are appended.\r
+\r
+  @return Destination           return the resultant string.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+StrnCatGrow (\r
+  IN OUT CHAR16           **Destination,\r
+  IN OUT UINTN            *CurrentSize,\r
+  IN     CONST CHAR16     *Source,\r
+  IN     UINTN            Count\r
+  )\r
+{\r
+  UINTN DestinationStartSize;\r
+  UINTN NewSize;\r
+\r
+  //\r
+  // ASSERTs\r
+  //\r
+  ASSERT(Destination != NULL);\r
+\r
+  //\r
+  // If there's nothing to do then just return Destination\r
+  //\r
+  if (Source == NULL) {\r
+    return (*Destination);\r
+  }\r
+\r
+  //\r
+  // allow for un-initialized pointers, based on size being 0\r
+  //\r
+  if (CurrentSize != NULL && *CurrentSize == 0) {\r
+    *Destination = NULL;\r
+  }\r
+\r
+  //\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
+  } else {\r
+    DestinationStartSize = 0;\r
+//    ASSERT(*CurrentSize == 0);\r
+  }\r
+\r
+  //\r
+  // Append all of Source?\r
+  //\r
+  if (Count == 0) {\r
+    Count = StrLen(Source);\r
+  }\r
+\r
+  //\r
+  // Test and grow if required\r
+  //\r
+  if (CurrentSize != NULL) {\r
+    NewSize = *CurrentSize;\r
+    while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r
+      NewSize += 2 * Count * sizeof(CHAR16);\r
+    }\r
+    *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
+    *CurrentSize = NewSize;\r
+  } else {\r
+    *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r
+  }\r
+\r
+  //\r
+  // Now use standard StrnCat on a big enough buffer\r
+  //\r
+  return StrnCat(*Destination, Source, Count);\r
+}\r