ShellPkg: Add code to handle the split ('|') in a double-quoted string.

This patch update the code in function 'ContainsSplit', and make 'ContainsSplit' depend on 'FindNextInstance'. So we move 'FindNextInstance' in front of 'ContainsSplit'.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <shumin.qiu@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>





git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16560 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Qiu Shumin 2014-12-26 08:22:35 +00:00 committed by shenshushi
parent 12d95665cb
commit 6f6792b820
1 changed files with 75 additions and 43 deletions

View File

@ -100,6 +100,48 @@ TrimSpaces(
return (EFI_SUCCESS);
}
/**
Parse for the next instance of one string within another string. Can optionally make sure that
the string was not escaped (^ character) per the shell specification.
@param[in] SourceString The string to search within
@param[in] FindString The string to look for
@param[in] CheckForEscapeCharacter TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances
**/
CHAR16*
EFIAPI
FindNextInstance(
IN CONST CHAR16 *SourceString,
IN CONST CHAR16 *FindString,
IN CONST BOOLEAN CheckForEscapeCharacter
)
{
CHAR16 *Temp;
if (SourceString == NULL) {
return (NULL);
}
Temp = StrStr(SourceString, FindString);
//
// If nothing found, or we dont care about escape characters
//
if (Temp == NULL || !CheckForEscapeCharacter) {
return (Temp);
}
//
// If we found an escaped character, try again on the remainder of the string
//
if ((Temp > (SourceString)) && *(Temp-1) == L'^') {
return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);
}
//
// we found the right character
//
return (Temp);
}
/**
Find a command line contains a split operation
@ -142,7 +184,39 @@ ContainsSplit(
)
{
CONST CHAR16 *TempSpot;
TempSpot = FindSplit(CmdLine);
CONST CHAR16 *FirstQuote;
CONST CHAR16 *SecondQuote;
FirstQuote = FindNextInstance (CmdLine, L"\"", TRUE);
SecondQuote = NULL;
TempSpot = FindSplit(CmdLine);
if (FirstQuote == NULL ||
TempSpot == NULL ||
TempSpot == CHAR_NULL ||
FirstQuote > TempSpot
) {
return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));
}
while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {
if (FirstQuote == NULL || FirstQuote > TempSpot) {
break;
}
SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);
if (SecondQuote == NULL) {
break;
}
if (SecondQuote < TempSpot) {
FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);
continue;
} else {
FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);
TempSpot = FindSplit(TempSpot + 1);
continue;
}
}
return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));
}
@ -1232,48 +1306,6 @@ ShellConvertAlias(
return (EFI_SUCCESS);
}
/**
Parse for the next instance of one string within another string. Can optionally make sure that
the string was not escaped (^ character) per the shell specification.
@param[in] SourceString The string to search within
@param[in] FindString The string to look for
@param[in] CheckForEscapeCharacter TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances
**/
CHAR16*
EFIAPI
FindNextInstance(
IN CONST CHAR16 *SourceString,
IN CONST CHAR16 *FindString,
IN CONST BOOLEAN CheckForEscapeCharacter
)
{
CHAR16 *Temp;
if (SourceString == NULL) {
return (NULL);
}
Temp = StrStr(SourceString, FindString);
//
// If nothing found, or we dont care about escape characters
//
if (Temp == NULL || !CheckForEscapeCharacter) {
return (Temp);
}
//
// If we found an escaped character, try again on the remainder of the string
//
if ((Temp > (SourceString)) && *(Temp-1) == L'^') {
return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);
}
//
// we found the right character
//
return (Temp);
}
/**
This function will eliminate unreplaced (and therefore non-found) environment variables.