]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Shellpkg: Add support for filenames with spaces.
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 11 Nov 2011 16:52:09 +0000 (16:52 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 11 Nov 2011 16:52:09 +0000 (16:52 +0000)
This patch changes the file redirection support to allow for quote delimited filenames that contain spaces and updates the edit command to allow spaces in the filename.  This also properly fails for attempts to redirect to "" (empty quotes).

This was missing from the first portion of the commit.

signed-off-by: jcarsey
reviewed-by: jliu66

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12686 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Application/Shell/ShellParametersProtocol.c

index 9e502256746c7e81ce648054b1149f8e3056b61a..2d29ab1f2e11d12b67fbb3b4257420c3d5012ebe 100644 (file)
@@ -495,6 +495,46 @@ CalculateEfiHdrCrc (
   Hdr->CRC32 = Crc;\r
 }\r
 \r
+/**\r
+  Fix a string to only have the file name, removing starting at the first space of whatever is quoted.\r
+\r
+  @param[in]  FileName    The filename to start with.\r
+\r
+  @retval NULL  FileName was invalid.\r
+  @return       The modified FileName.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FixFileName (\r
+  IN CHAR16 *FileName\r
+  )\r
+{\r
+  CHAR16  *Copy;\r
+  CHAR16  *TempLocation;\r
+\r
+  if (FileName == NULL) {\r
+    return (NULL);\r
+  }\r
+\r
+  if (FileName[0] == L'\"') {\r
+    Copy = FileName+1;\r
+    if ((TempLocation = StrStr(Copy , L"\"")) != NULL) {\r
+      TempLocation[0] = CHAR_NULL;\r
+    }    \r
+  } else {\r
+    Copy = FileName;\r
+    if ((TempLocation = StrStr(Copy , L" ")) != NULL) {\r
+      TempLocation[0] = CHAR_NULL;\r
+    }    \r
+  }\r
+\r
+  if (Copy[0] == CHAR_NULL) {\r
+    return (NULL);\r
+  }\r
+\r
+  return (Copy);\r
+}\r
+\r
 /**\r
   Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
   structure by parsing NewCommandLine.  The current values are returned to the\r
@@ -842,6 +882,11 @@ UpdateStdInStdOutStdErr(
     }\r
   }\r
 \r
+  //\r
+  // re-populate the string to support any filenames that were in quotes.\r
+  //\r
+  StrCpy(CommandLineCopy, NewCommandLine);\r
+\r
   if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)\r
     && ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))\r
     ){\r
@@ -849,23 +894,36 @@ UpdateStdInStdOutStdErr(
   }\r
 \r
   if (!EFI_ERROR(Status)) {\r
-    if (StdErrFileName != NULL && (CommandLineWalker = StrStr(StdErrFileName, L" ")) != NULL) {\r
-      CommandLineWalker[0] = CHAR_NULL;\r
+\r
+    if (StdErrFileName != NULL) {\r
+      if ((StdErrFileName    = FixFileName(StdErrFileName)) == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
-    if (StdOutFileName != NULL && (CommandLineWalker = StrStr(StdOutFileName, L" ")) != NULL) {\r
-      CommandLineWalker[0] = CHAR_NULL;\r
+    if (StdOutFileName != NULL) {\r
+      if ((StdOutFileName    = FixFileName(StdOutFileName)) == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
-    if (StdInFileName  != NULL && (CommandLineWalker = StrStr(StdInFileName , L" ")) != NULL) {\r
-      CommandLineWalker[0] = CHAR_NULL;\r
+    if (StdInFileName  != NULL) {\r
+      if ((StdInFileName     = FixFileName(StdInFileName)) == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
-    if (StdErrVarName  != NULL && (CommandLineWalker = StrStr(StdErrVarName , L" ")) != NULL) {\r
-      CommandLineWalker[0] = CHAR_NULL;\r
+    if (StdErrVarName  != NULL) {\r
+      if ((StdErrVarName     = FixFileName(StdErrVarName)) == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
-    if (StdOutVarName  != NULL && (CommandLineWalker = StrStr(StdOutVarName , L" ")) != NULL) {\r
-      CommandLineWalker[0] = CHAR_NULL;\r
+    if (StdOutVarName  != NULL) {\r
+      if ((StdOutVarName     = FixFileName(StdOutVarName)) == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
-    if (StdInVarName   != NULL && (CommandLineWalker = StrStr(StdInVarName  , L" ")) != NULL) {\r
-      CommandLineWalker[0] = CHAR_NULL;\r
+    if (StdInVarName   != NULL) {\r
+      if ((StdInVarName      = FixFileName(StdInVarName)) == NULL) {\r
+        Status = EFI_INVALID_PARAMETER;\r
+      }\r
     }\r
 \r
     //\r