return (Status);\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
Function will process and run a command line.\r
\r
CHAR16 **Argv;\r
BOOLEAN LastError;\r
CHAR16 LeString[19];\r
- CHAR16 *PostAliasCmdLine;\r
- UINTN PostAliasSize;\r
CHAR16 *PostVariableCmdLine;\r
CHAR16 *CommandWithPath;\r
CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
\r
CommandName = NULL;\r
PostVariableCmdLine = NULL;\r
- PostAliasCmdLine = NULL;\r
CommandWithPath = NULL;\r
DevPath = NULL;\r
Status = EFI_SUCCESS;\r
return (EFI_SUCCESS);\r
}\r
\r
- CommandName = NULL;\r
- if (StrStr(CleanOriginal, L" ") == NULL){\r
- StrnCatGrow(&CommandName, NULL, CleanOriginal, 0);\r
- } else {\r
- StrnCatGrow(&CommandName, NULL, CleanOriginal, StrStr(CleanOriginal, L" ") - CleanOriginal);\r
- }\r
-\r
- ASSERT(PostAliasCmdLine == NULL);\r
- if (!ShellCommandIsCommandOnList(CommandName)) {\r
- //\r
- // Convert via alias\r
- //\r
- Status = ShellConvertAlias(&CommandName);\r
- PostAliasSize = 0;\r
- PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize, CommandName, 0);\r
- PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize, StrStr(CleanOriginal, L" "), 0);\r
- ASSERT_EFI_ERROR(Status);\r
- } else {\r
- PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, NULL, CleanOriginal, 0);\r
- }\r
-\r
- if (CleanOriginal != NULL) {\r
- FreePool(CleanOriginal);\r
- CleanOriginal = NULL;\r
- }\r
-\r
- if (CommandName != NULL) {\r
- FreePool(CommandName);\r
- CommandName = NULL;\r
+ Status = ShellSubstituteAliases(&CleanOriginal);\r
+ if (EFI_ERROR(Status)) {\r
+ return (Status);\r
}\r
\r
- PostVariableCmdLine = ShellConvertVariables(PostAliasCmdLine);\r
-\r
- //\r
- // we can now free the modified by alias command line\r
- //\r
- if (PostAliasCmdLine != NULL) {\r
- FreePool(PostAliasCmdLine);\r
- PostAliasCmdLine = NULL;\r
- }\r
+ PostVariableCmdLine = ShellConvertVariables(CleanOriginal);\r
\r
if (PostVariableCmdLine == NULL) {\r
return (EFI_OUT_OF_RESOURCES);\r
SHELL_FREE_NON_NULL(CommandName);\r
SHELL_FREE_NON_NULL(CommandWithPath);\r
SHELL_FREE_NON_NULL(PostVariableCmdLine);\r
+ SHELL_FREE_NON_NULL(CleanOriginal);\r
\r
return (Status);\r
}\r