diff options
author | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-11-11 16:52:09 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-11-11 16:52:09 +0000 |
commit | 031acf6336e92392966825b05600e4da1c24c655 (patch) | |
tree | eba7c984c049331412b87d53694710e4438d2baf /ShellPkg/Application/Shell/ShellParametersProtocol.c | |
parent | d16efcae829976ea4ebacb989a25382c875abdeb (diff) | |
download | edk2-platforms-031acf6336e92392966825b05600e4da1c24c655.tar.xz |
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/edk2@12686 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Application/Shell/ShellParametersProtocol.c')
-rw-r--r-- | ShellPkg/Application/Shell/ShellParametersProtocol.c | 82 |
1 files changed, 70 insertions, 12 deletions
diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index 9e50225674..2d29ab1f2e 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/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;
+ }
}
//
|