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
This commit is contained in:
jcarsey 2011-11-11 16:52:09 +00:00
parent d16efcae82
commit 031acf6336
1 changed files with 70 additions and 12 deletions

View File

@ -495,6 +495,46 @@ CalculateEfiHdrCrc (
Hdr->CRC32 = Crc;
}
/**
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
@ -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;
}
}
//