summaryrefslogtreecommitdiff
path: root/ShellPkg/Application
diff options
context:
space:
mode:
authorQiu Shumin <shumin.qiu@intel.com>2014-12-26 08:22:35 +0000
committershenshushi <shenshushi@Edk2>2014-12-26 08:22:35 +0000
commit6f6792b82085c125df476ed5f8347afcbad1af5d (patch)
tree8953f26290d9d1f31798bec56f00eb35c33b71dd /ShellPkg/Application
parent12d95665cb0e088afe2cd395f0acc7fdb2604acc (diff)
downloadedk2-platforms-6f6792b82085c125df476ed5f8347afcbad1af5d.tar.xz
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
Diffstat (limited to 'ShellPkg/Application')
-rw-r--r--ShellPkg/Application/Shell/Shell.c118
1 files changed, 75 insertions, 43 deletions
diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shell/Shell.c
index 41fa78004d..de46a72b44 100644
--- a/ShellPkg/Application/Shell/Shell.c
+++ b/ShellPkg/Application/Shell/Shell.c
@@ -101,6 +101,48 @@ TrimSpaces(
}
/**
+ 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
@param[in] CmdLine The command line to parse.
@@ -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));
}
@@ -1233,48 +1307,6 @@ ShellConvertAlias(
}
/**
- 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.
@param[in,out] CmdLine The command line to update.