+ 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 dont 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
+ This function will eliminate unreplaced (and therefore non-found) environment variables.\r
+\r
+ @param[in,out] CmdLine The command line to update.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+StripUnreplacedEnvironmentVariables(\r
+ IN OUT CHAR16 *CmdLine\r
+ )\r
+{\r
+ CHAR16 *FirstPercent;\r
+ CHAR16 *FirstQuote;\r
+ CHAR16 *SecondPercent;\r
+ CHAR16 *SecondQuote;\r
+ CHAR16 *CurrentLocator;\r
+\r
+ for (CurrentLocator = CmdLine ; CurrentLocator != NULL ; ) {\r
+ FirstQuote = FindNextInstance(CurrentLocator, L"\"", TRUE);\r
+ FirstPercent = FindNextInstance(CurrentLocator, L"%", TRUE);\r
+ SecondPercent = FirstPercent!=NULL?FindNextInstance(FirstPercent+1, L"%", TRUE):NULL;\r
+ if (FirstPercent == NULL || SecondPercent == NULL) {\r
+ //\r
+ // If we ever dont have 2 % we are done.\r
+ //\r
+ break;\r
+ }\r
+\r
+ if (FirstQuote < FirstPercent) {\r
+ SecondQuote = FirstQuote!= NULL?FindNextInstance(FirstQuote+1, L"\"", TRUE):NULL;\r
+ //\r
+ // Quote is first found\r
+ //\r
+\r
+ if (SecondQuote < FirstPercent) {\r
+ //\r
+ // restart after the pair of "\r
+ //\r
+ CurrentLocator = SecondQuote + 1;\r
+ } else /* FirstPercent < SecondQuote */{\r
+ //\r
+ // Restart on the first percent\r
+ //\r
+ CurrentLocator = FirstPercent;\r
+ }\r
+ continue;\r
+ }\r
+ ASSERT(FirstPercent < FirstQuote);\r
+ if (SecondPercent < FirstQuote) {\r
+ FirstPercent[0] = L'\"';\r
+ SecondPercent[0] = L'\"';\r
+\r
+ //\r
+ // We need to remove from FirstPercent to SecondPercent\r
+ //\r
+ CopyMem(FirstPercent + 1, SecondPercent, StrSize(SecondPercent));\r
+ CurrentLocator = FirstPercent + 2;\r
+ continue;\r
+ }\r
+ ASSERT(FirstQuote < SecondPercent);\r
+ CurrentLocator = FirstQuote;\r
+ }\r