2 Main file for Alias shell level 3 function.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "UefiShellLevel3CommandsLib.h"
17 #include <Library/ShellLib.h>
20 Print out each alias registered with the Shell.
22 @retval STATUS_SUCCESS the printout was sucessful
23 @return any return code from GetNextVariableName except EFI_NOT_FOUND
31 CONST CHAR16
*ConstAllAliasList
;
33 CONST CHAR16
*Command
;
39 ConstAllAliasList
= gEfiShellProtocol
->GetAlias(NULL
, NULL
);
40 if (ConstAllAliasList
== NULL
) {
41 return (SHELL_SUCCESS
);
43 Alias
= AllocateZeroPool(StrSize(ConstAllAliasList
));
45 return (SHELL_OUT_OF_RESOURCES
);
47 Walker
= (CHAR16
*)ConstAllAliasList
;
50 CopyMem(Alias
, Walker
, StrSize(Walker
));
51 Walker
= StrStr(Alias
, L
";");
53 Walker
[0] = CHAR_NULL
;
56 Command
= gEfiShellProtocol
->GetAlias(Alias
, &Volatile
);
57 if (ShellCommandIsOnAliasList(Alias
)) {
60 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_ALIAS_OUTPUT
), gShellLevel3HiiHandle
, !Volatile
?L
' ':L
'*', Alias
, Command
);
61 } while (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
);
65 return (SHELL_SUCCESS
);
68 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
75 Function for 'alias' command.
77 @param[in] ImageHandle Handle to the Image (NULL if Internal).
78 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
82 ShellCommandRunAlias (
83 IN EFI_HANDLE ImageHandle
,
84 IN EFI_SYSTEM_TABLE
*SystemTable
90 SHELL_STATUS ShellStatus
;
95 ShellStatus
= SHELL_SUCCESS
;
98 // initialize the shell lib (we must be in non-auto-init...)
100 Status
= ShellInitialize();
101 ASSERT_EFI_ERROR(Status
);
103 Status
= CommandInit();
104 ASSERT_EFI_ERROR(Status
);
107 // parse the command line
109 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
110 if (EFI_ERROR(Status
)) {
111 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
112 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, ProblemParam
);
113 FreePool(ProblemParam
);
114 ShellStatus
= SHELL_INVALID_PARAMETER
;
119 Param1
= ShellCommandLineGetRawValue(Package
, 1);
120 Param2
= ShellCommandLineGetRawValue(Package
, 2);
124 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
127 if (ShellCommandLineGetCount(Package
) == 1) {
131 Status
= PrintAllShellAlias();
132 } else if (ShellCommandLineGetFlag(Package
, L
"-d")) {
136 Status
= gEfiShellProtocol
->SetAlias(Param1
, NULL
, TRUE
, FALSE
);
137 } else if (ShellCommandLineGetCount(Package
) == 3) {
139 // must be adding an alias
141 Status
= gEfiShellProtocol
->SetAlias(Param2
, Param1
, FALSE
, ShellCommandLineGetFlag(Package
, L
"-v"));
142 if (EFI_ERROR(Status
)) {
143 if (Status
== EFI_ACCESS_DENIED
) {
144 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel3HiiHandle
);
145 ShellStatus
= SHELL_ACCESS_DENIED
;
147 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel3HiiHandle
, Status
);
148 ShellStatus
= SHELL_DEVICE_ERROR
;
151 } else if (ShellCommandLineGetCount(Package
) == 2) {
152 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel3HiiHandle
);
153 ShellStatus
= SHELL_INVALID_PARAMETER
;
155 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
);
156 ShellStatus
= SHELL_INVALID_PARAMETER
;
159 // free the command line package
161 ShellCommandLineFreeVarList (Package
);
164 return (ShellStatus
);