+/**\r
+ Cleans off leading and trailing spaces and tabs.\r
+\r
+ @param[in] String pointer to the string to trim them off.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+TrimSpaces(\r
+ IN CHAR16 **String\r
+ )\r
+{\r
+ ASSERT(String != NULL);\r
+ ASSERT(*String!= NULL);\r
+ //\r
+ // Remove any spaces and tabs at the beginning of the (*String).\r
+ //\r
+ while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {\r
+ CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));\r
+ }\r
+\r
+ //\r
+ // Remove any spaces and tabs at the end of the (*String).\r
+ //\r
+ while ((StrLen (*String) > 0) && (((*String)[StrLen((*String))-1] == L' ') || ((*String)[StrLen((*String))-1] == L'\t'))) {\r
+ (*String)[StrLen((*String))-1] = CHAR_NULL;\r
+ }\r
+\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Parse for the next instance of one string within another string. Can optionally make sure that \r
+ the string was not escaped (^ character) per the shell specification.\r
+\r
+ @param[in] SourceString The string to search within\r
+ @param[in] FindString The string to look for\r
+ @param[in] CheckForEscapeCharacter TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+FindNextInstance(\r
+ IN CONST CHAR16 *SourceString,\r
+ IN CONST CHAR16 *FindString,\r
+ IN CONST BOOLEAN CheckForEscapeCharacter\r
+ )\r
+{\r
+ CHAR16 *Temp;\r
+ if (SourceString == NULL) {\r
+ return (NULL);\r
+ }\r
+ Temp = StrStr(SourceString, FindString);\r
+\r
+ //\r
+ // If nothing found, or we don't care about escape characters\r
+ //\r
+ if (Temp == NULL || !CheckForEscapeCharacter) {\r
+ return (Temp);\r
+ }\r
+\r
+ //\r
+ // If we found an escaped character, try again on the remainder of the string\r
+ //\r
+ if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r
+ return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r
+ }\r
+\r
+ //\r
+ // we found the right character\r
+ //\r
+ return (Temp);\r
+}\r
+\r
+/**\r
+ Check whether the string between a pair of % is a valid environment variable name.\r
+\r
+ @param[in] BeginPercent pointer to the first percent.\r
+ @param[in] EndPercent pointer to the last percent.\r
+\r
+ @retval TRUE is a valid environment variable name.\r
+ @retval FALSE is NOT a valid environment variable name.\r
+**/\r
+BOOLEAN\r
+IsValidEnvironmentVariableName(\r
+ IN CONST CHAR16 *BeginPercent,\r
+ IN CONST CHAR16 *EndPercent\r
+ )\r
+{\r
+ CONST CHAR16 *Walker;\r
+ \r
+ Walker = NULL;\r
+\r
+ ASSERT (BeginPercent != NULL);\r
+ ASSERT (EndPercent != NULL);\r
+ ASSERT (BeginPercent < EndPercent);\r
+ \r
+ if ((BeginPercent + 1) == EndPercent) {\r
+ return FALSE;\r
+ }\r
+\r
+ for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {\r
+ if (\r
+ (*Walker >= L'0' && *Walker <= L'9') ||\r
+ (*Walker >= L'A' && *Walker <= L'Z') ||\r
+ (*Walker >= L'a' && *Walker <= L'z') ||\r
+ (*Walker == L'_')\r
+ ) {\r
+ if (Walker == BeginPercent + 1 && (*Walker >= L'0' && *Walker <= L'9')) {\r
+ return FALSE;\r
+ } else {\r
+ continue;\r
+ }\r
+ } else {\r
+ return FALSE;\r
+ }\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+/**\r
+ Determine if a command line contains a split operation\r
+\r
+ @param[in] CmdLine The command line to parse.\r
+\r
+ @retval TRUE CmdLine has a valid split.\r
+ @retval FALSE CmdLine does not have a valid split.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+ContainsSplit(\r
+ IN CONST CHAR16 *CmdLine\r
+ )\r
+{\r
+ CONST CHAR16 *TempSpot;\r
+ CONST CHAR16 *FirstQuote;\r
+ CONST CHAR16 *SecondQuote;\r
+\r
+ FirstQuote = FindNextInstance (CmdLine, L"\"", TRUE);\r
+ SecondQuote = NULL;\r
+ TempSpot = FindFirstCharacter(CmdLine, L"|", L'^');\r
+\r
+ if (FirstQuote == NULL || \r
+ TempSpot == NULL || \r
+ TempSpot == CHAR_NULL || \r
+ FirstQuote > TempSpot\r
+ ) {\r
+ return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
+ }\r
+\r
+ while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {\r
+ if (FirstQuote == NULL || FirstQuote > TempSpot) {\r
+ break;\r
+ } \r
+ SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);\r
+ if (SecondQuote == NULL) {\r
+ break;\r
+ }\r
+ if (SecondQuote < TempSpot) {\r
+ FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
+ continue;\r
+ } else {\r
+ FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
+ TempSpot = FindFirstCharacter(TempSpot + 1, L"|", L'^');\r
+ continue;\r
+ } \r
+ }\r
+ \r
+ return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
+}\r
+\r