Revision: 14973
http://sourceforge.net/p/edk2/code/14973
Author: jcarsey
Date: 2013-12-12 21:16:38 +0000 (Thu, 12 Dec 2013)
Log Message:
-----------
ShellPkg: Refactor Alias replacement into separate function
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <[email protected]>
Reviewed-by: Erik Bjorge <[email protected]>
Modified Paths:
--------------
trunk/edk2/ShellPkg/Application/Shell/Shell.c
Modified: trunk/edk2/ShellPkg/Application/Shell/Shell.c
===================================================================
--- trunk/edk2/ShellPkg/Application/Shell/Shell.c 2013-12-12 18:42:18 UTC
(rev 14972)
+++ trunk/edk2/ShellPkg/Application/Shell/Shell.c 2013-12-12 21:16:38 UTC
(rev 14973)
@@ -1431,6 +1431,77 @@
}
/**
+ Take the original command line, substitute any alias in the first group of
space delimited characters, free
+ the original string, return the modified copy
+
+ @param[in] CmdLine pointer to the command line to update
+ @param[out]CmdName upon successful return the name of the command to be run
+
+ @retval EFI_SUCCESS the function was successful
+ @retval EFI_OUT_OF_RESOURCES a memory allocation failed
+**/
+EFI_STATUS
+EFIAPI
+ShellSubstituteAliases(
+ IN CHAR16 **CmdLine
+ )
+{
+ CHAR16 *NewCmdLine;
+ CHAR16 *CommandName;
+ EFI_STATUS Status;
+ UINTN PostAliasSize;
+ ASSERT(CmdLine != NULL);
+ ASSERT(*CmdLine!= NULL);
+
+
+ CommandName = NULL;
+ if (StrStr((*CmdLine), L" ") == NULL){
+ StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);
+ } else {
+ StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") -
(*CmdLine));
+ }
+
+ //
+ // This cannot happen 'inline' since the CmdLine can need extra space.
+ //
+ NewCmdLine = NULL;
+ if (!ShellCommandIsCommandOnList(CommandName)) {
+ //
+ // Convert via alias
+ //
+ Status = ShellConvertAlias(&CommandName);
+ if (EFI_ERROR(Status)){
+ return (Status);
+ }
+ PostAliasSize = 0;
+ NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);
+ if (NewCmdLine == NULL) {
+ SHELL_FREE_NON_NULL(CommandName);
+ SHELL_FREE_NON_NULL(*CmdLine);
+ return (EFI_OUT_OF_RESOURCES);
+ }
+ NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine),
L" "), 0);
+ if (NewCmdLine == NULL) {
+ SHELL_FREE_NON_NULL(CommandName);
+ SHELL_FREE_NON_NULL(*CmdLine);
+ return (EFI_OUT_OF_RESOURCES);
+ }
+ } else {
+ NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);
+ }
+
+ SHELL_FREE_NON_NULL(*CmdLine);
+ SHELL_FREE_NON_NULL(CommandName);
+
+ //
+ // re-assign the passed in double pointer to point to our newly allocated
buffer
+ //
+ *CmdLine = NewCmdLine;
+
+ return (EFI_SUCCESS);
+}
+
+/**
Function will process and run a command line.
This will determine if the command line represents an internal shell
@@ -1455,8 +1526,6 @@
CHAR16 **Argv;
BOOLEAN LastError;
CHAR16 LeString[19];
- CHAR16 *PostAliasCmdLine;
- UINTN PostAliasSize;
CHAR16 *PostVariableCmdLine;
CHAR16 *CommandWithPath;
CONST EFI_DEVICE_PATH_PROTOCOL *DevPath;
@@ -1478,7 +1547,6 @@
CommandName = NULL;
PostVariableCmdLine = NULL;
- PostAliasCmdLine = NULL;
CommandWithPath = NULL;
DevPath = NULL;
Status = EFI_SUCCESS;
@@ -1503,47 +1571,13 @@
return (EFI_SUCCESS);
}
- CommandName = NULL;
- if (StrStr(CleanOriginal, L" ") == NULL){
- StrnCatGrow(&CommandName, NULL, CleanOriginal, 0);
- } else {
- StrnCatGrow(&CommandName, NULL, CleanOriginal, StrStr(CleanOriginal, L" ")
- CleanOriginal);
+ Status = ShellSubstituteAliases(&CleanOriginal);
+ if (EFI_ERROR(Status)) {
+ return (Status);
}
- ASSERT(PostAliasCmdLine == NULL);
- if (!ShellCommandIsCommandOnList(CommandName)) {
- //
- // Convert via alias
- //
- Status = ShellConvertAlias(&CommandName);
- PostAliasSize = 0;
- PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize,
CommandName, 0);
- PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, &PostAliasSize,
StrStr(CleanOriginal, L" "), 0);
- ASSERT_EFI_ERROR(Status);
- } else {
- PostAliasCmdLine = StrnCatGrow(&PostAliasCmdLine, NULL, CleanOriginal, 0);
- }
+ PostVariableCmdLine = ShellConvertVariables(CleanOriginal);
- if (CleanOriginal != NULL) {
- FreePool(CleanOriginal);
- CleanOriginal = NULL;
- }
-
- if (CommandName != NULL) {
- FreePool(CommandName);
- CommandName = NULL;
- }
-
- PostVariableCmdLine = ShellConvertVariables(PostAliasCmdLine);
-
- //
- // we can now free the modified by alias command line
- //
- if (PostAliasCmdLine != NULL) {
- FreePool(PostAliasCmdLine);
- PostAliasCmdLine = NULL;
- }
-
if (PostVariableCmdLine == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
@@ -1739,6 +1773,7 @@
SHELL_FREE_NON_NULL(CommandName);
SHELL_FREE_NON_NULL(CommandWithPath);
SHELL_FREE_NON_NULL(PostVariableCmdLine);
+ SHELL_FREE_NON_NULL(CleanOriginal);
return (Status);
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits