+/**\r
+ Take the original command line, substitute any variables, free \r
+ the original string, return the modified copy\r
+\r
+ @param[in] CmdLine pointer to the command line to update\r
+ @param[out]CmdName upon successful return the name of the command to be run\r
+\r
+ @retval EFI_SUCCESS the function was successful\r
+ @retval EFI_OUT_OF_RESOURCES a memory allocation failed\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellSubstituteVariables(\r
+ IN CHAR16 **CmdLine\r
+ )\r
+{\r
+ CHAR16 *NewCmdLine;\r
+ NewCmdLine = ShellConvertVariables(*CmdLine);\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ if (NewCmdLine == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ *CmdLine = NewCmdLine;\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Take the original command line, substitute any alias in the first group of space delimited characters, free \r
+ the original string, return the modified copy\r
+\r
+ @param[in] CmdLine pointer to the command line to update\r
+ @param[out]CmdName upon successful return the name of the command to be run\r
+\r
+ @retval EFI_SUCCESS the function was successful\r
+ @retval EFI_OUT_OF_RESOURCES a memory allocation failed\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ShellSubstituteAliases(\r
+ IN CHAR16 **CmdLine\r
+ )\r
+{\r
+ CHAR16 *NewCmdLine;\r
+ CHAR16 *CommandName;\r
+ EFI_STATUS Status;\r
+ UINTN PostAliasSize;\r
+ ASSERT(CmdLine != NULL);\r
+ ASSERT(*CmdLine!= NULL);\r
+\r
+\r
+ CommandName = NULL;\r
+ if (StrStr((*CmdLine), L" ") == NULL){\r
+ StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);\r
+ } else {\r
+ StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine));\r
+ }\r
+\r
+ //\r
+ // This cannot happen 'inline' since the CmdLine can need extra space.\r
+ //\r
+ NewCmdLine = NULL;\r
+ if (!ShellCommandIsCommandOnList(CommandName)) {\r
+ //\r
+ // Convert via alias\r
+ //\r
+ Status = ShellConvertAlias(&CommandName);\r
+ if (EFI_ERROR(Status)){\r
+ return (Status);\r
+ }\r
+ PostAliasSize = 0;\r
+ NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);\r
+ if (NewCmdLine == NULL) {\r
+ SHELL_FREE_NON_NULL(CommandName);\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0);\r
+ if (NewCmdLine == NULL) {\r
+ SHELL_FREE_NON_NULL(CommandName);\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
+ } else {\r
+ NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);\r
+ }\r
+\r
+ SHELL_FREE_NON_NULL(*CmdLine);\r
+ SHELL_FREE_NON_NULL(CommandName);\r
+ \r
+ //\r
+ // re-assign the passed in double pointer to point to our newly allocated buffer\r
+ //\r
+ *CmdLine = NewCmdLine;\r
+\r
+ return (EFI_SUCCESS);\r
+}\r
+\r
+/**\r
+ Takes the Argv[0] part of the command line and determine the meaning of it.\r
+**/\r
+SHELL_OPERATION_TYPES\r
+EFIAPI\r
+GetOperationType(\r
+ IN CONST CHAR16 *CmdName\r
+ )\r
+{\r
+ CHAR16* FileWithPath;\r
+ CONST CHAR16* TempLocation;\r
+ CONST CHAR16* TempLocation2;\r
+\r
+ FileWithPath = NULL;\r
+ //\r
+ // test for an internal command.\r
+ //\r
+ if (ShellCommandIsCommandOnList(CmdName)) {\r
+ return (INTERNAL_COMMAND);\r
+ }\r
+\r
+ //\r
+ // Test for file system change request. anything ending with : and cant have spaces.\r
+ //\r
+ if (CmdName[(StrLen(CmdName)-1)] == L':') {\r
+ if (StrStr(CmdName, L" ") != NULL) {\r
+ return (UNKNOWN_INVALID);\r
+ }\r
+ return (FILE_SYS_CHANGE);\r
+ }\r
+\r
+ //\r
+ // Test for a file\r
+ //\r
+ if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {\r
+ //\r
+ // See if that file has a script file extension\r
+ //\r
+ if (StrLen(FileWithPath) > 4) {\r
+ TempLocation = FileWithPath+StrLen(FileWithPath)-4;\r
+ TempLocation2 = mScriptExtension;\r
+ if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {\r
+ SHELL_FREE_NON_NULL(FileWithPath);\r
+ return (SCRIPT_FILE_NAME);\r
+ }\r
+ }\r
+\r
+ //\r
+ // Was a file, but not a script. we treat this as an application.\r
+ //\r
+ SHELL_FREE_NON_NULL(FileWithPath);\r
+ return (EFI_APPLICATION);\r
+ }\r
+ \r
+ SHELL_FREE_NON_NULL(FileWithPath);\r
+ //\r
+ // No clue what this is... return invalid flag...\r
+ //\r
+ return (UNKNOWN_INVALID);\r
+}\r
+\r