summaryrefslogtreecommitdiff
path: root/edk2/ShellPkg/Application
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-11-11 16:52:09 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-11-11 16:52:09 +0000
commitf5719a8d6af21ed39702281e2480b30ea3b8b001 (patch)
treee45850d1021fa993c44a10ec487215c63643abac /edk2/ShellPkg/Application
parent341d1b33f4f6caa5d59a7ee6a0420fed0880bca6 (diff)
Shellpkg: Add support for filenames with spaces.
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@12686 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'edk2/ShellPkg/Application')
-rw-r--r--edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c82
1 files changed, 70 insertions, 12 deletions
diff --git a/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c b/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c
index 9e5022567..2d29ab1f2 100644
--- a/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c
+++ b/edk2/ShellPkg/Application/Shell/ShellParametersProtocol.c
@@ -496,6 +496,46 @@ CalculateEfiHdrCrc (
}
/**
+ Fix a string to only have the file name, removing starting at the first space of whatever is quoted.
+
+ @param[in] FileName The filename to start with.
+
+ @retval NULL FileName was invalid.
+ @return The modified FileName.
+**/
+CHAR16*
+EFIAPI
+FixFileName (
+ IN CHAR16 *FileName
+ )
+{
+ CHAR16 *Copy;
+ CHAR16 *TempLocation;
+
+ if (FileName == NULL) {
+ return (NULL);
+ }
+
+ if (FileName[0] == L'\"') {
+ Copy = FileName+1;
+ if ((TempLocation = StrStr(Copy , L"\"")) != NULL) {
+ TempLocation[0] = CHAR_NULL;
+ }
+ } else {
+ Copy = FileName;
+ if ((TempLocation = StrStr(Copy , L" ")) != NULL) {
+ TempLocation[0] = CHAR_NULL;
+ }
+ }
+
+ if (Copy[0] == CHAR_NULL) {
+ return (NULL);
+ }
+
+ return (Copy);
+}
+
+/**
Funcion will replace the current StdIn and StdOut in the ShellParameters protocol
structure by parsing NewCommandLine. The current values are returned to the
user.
@@ -842,6 +882,11 @@ UpdateStdInStdOutStdErr(
}
}
+ //
+ // re-populate the string to support any filenames that were in quotes.
+ //
+ StrCpy(CommandLineCopy, NewCommandLine);
+
if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
&& ((UINTN)(FirstLocation - CommandLineCopy) < StrLen(NewCommandLine))
){
@@ -849,23 +894,36 @@ UpdateStdInStdOutStdErr(
}
if (!EFI_ERROR(Status)) {
- if (StdErrFileName != NULL && (CommandLineWalker = StrStr(StdErrFileName, L" ")) != NULL) {
- CommandLineWalker[0] = CHAR_NULL;
+
+ if (StdErrFileName != NULL) {
+ if ((StdErrFileName = FixFileName(StdErrFileName)) == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
}
- if (StdOutFileName != NULL && (CommandLineWalker = StrStr(StdOutFileName, L" ")) != NULL) {
- CommandLineWalker[0] = CHAR_NULL;
+ if (StdOutFileName != NULL) {
+ if ((StdOutFileName = FixFileName(StdOutFileName)) == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
}
- if (StdInFileName != NULL && (CommandLineWalker = StrStr(StdInFileName , L" ")) != NULL) {
- CommandLineWalker[0] = CHAR_NULL;
+ if (StdInFileName != NULL) {
+ if ((StdInFileName = FixFileName(StdInFileName)) == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
}
- if (StdErrVarName != NULL && (CommandLineWalker = StrStr(StdErrVarName , L" ")) != NULL) {
- CommandLineWalker[0] = CHAR_NULL;
+ if (StdErrVarName != NULL) {
+ if ((StdErrVarName = FixFileName(StdErrVarName)) == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
}
- if (StdOutVarName != NULL && (CommandLineWalker = StrStr(StdOutVarName , L" ")) != NULL) {
- CommandLineWalker[0] = CHAR_NULL;
+ if (StdOutVarName != NULL) {
+ if ((StdOutVarName = FixFileName(StdOutVarName)) == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
}
- if (StdInVarName != NULL && (CommandLineWalker = StrStr(StdInVarName , L" ")) != NULL) {
- CommandLineWalker[0] = CHAR_NULL;
+ if (StdInVarName != NULL) {
+ if ((StdInVarName = FixFileName(StdInVarName)) == NULL) {
+ Status = EFI_INVALID_PARAMETER;
+ }
}
//