2 Main file for Alias shell level 3 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "UefiShellLevel3CommandsLib.h"
18 #include <Library/ShellLib.h>
21 Print out each alias registered with the Shell.
23 @retval STATUS_SUCCESS the printout was sucessful
24 @return any return code from GetNextVariableName except EFI_NOT_FOUND
32 CONST CHAR16
*ConstAllAliasList
;
34 CONST CHAR16
*Command
;
40 ConstAllAliasList
= gEfiShellProtocol
->GetAlias(NULL
, NULL
);
41 if (ConstAllAliasList
== NULL
) {
42 return (SHELL_SUCCESS
);
44 Alias
= AllocateZeroPool(StrSize(ConstAllAliasList
));
46 return (SHELL_OUT_OF_RESOURCES
);
48 Walker
= (CHAR16
*)ConstAllAliasList
;
51 CopyMem(Alias
, Walker
, StrSize(Walker
));
52 Walker
= StrStr(Alias
, L
";");
54 Walker
[0] = CHAR_NULL
;
57 Command
= gEfiShellProtocol
->GetAlias(Alias
, &Volatile
);
58 if (ShellCommandIsOnAliasList(Alias
)) {
61 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_ALIAS_OUTPUT
), gShellLevel3HiiHandle
, !Volatile
?L
' ':L
'*', Alias
, Command
);
62 } while (Walker
!= NULL
&& Walker
[0] != CHAR_NULL
);
66 return (SHELL_SUCCESS
);
69 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
76 Function for 'alias' command.
78 @param[in] ImageHandle Handle to the Image (NULL if Internal).
79 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
83 ShellCommandRunAlias (
84 IN EFI_HANDLE ImageHandle
,
85 IN EFI_SYSTEM_TABLE
*SystemTable
91 SHELL_STATUS ShellStatus
;
97 ShellStatus
= SHELL_SUCCESS
;
101 // initialize the shell lib (we must be in non-auto-init...)
103 Status
= ShellInitialize();
104 ASSERT_EFI_ERROR(Status
);
106 Status
= CommandInit();
107 ASSERT_EFI_ERROR(Status
);
110 // parse the command line
112 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
113 if (EFI_ERROR(Status
)) {
114 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
115 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel3HiiHandle
, L
"alias", ProblemParam
);
116 FreePool(ProblemParam
);
117 ShellStatus
= SHELL_INVALID_PARAMETER
;
122 Param1
= ShellCommandLineGetRawValue(Package
, 1);
123 Param2
= ShellCommandLineGetRawValue(Package
, 2);
125 if (Param2
!= NULL
) {
126 CleanParam2
= AllocateCopyPool (StrSize(Param2
), Param2
);
127 if (CleanParam2
== NULL
) {
128 return SHELL_OUT_OF_RESOURCES
;
131 if (CleanParam2
[0] == L
'\"' && CleanParam2
[StrLen(CleanParam2
)-1] == L
'\"') {
132 CleanParam2
[StrLen(CleanParam2
)-1] = L
'\0';
133 CopyMem (CleanParam2
, CleanParam2
+ 1, StrSize(CleanParam2
) - sizeof(CleanParam2
[0]));
140 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
143 if (ShellCommandLineGetCount(Package
) == 1) {
147 Status
= PrintAllShellAlias();
148 } else if (ShellCommandLineGetFlag(Package
, L
"-d")) {
152 Status
= gEfiShellProtocol
->SetAlias(Param1
, NULL
, TRUE
, FALSE
);
153 } else if (ShellCommandLineGetCount(Package
) == 3) {
155 // must be adding an alias
157 Status
= gEfiShellProtocol
->SetAlias(CleanParam2
, Param1
, FALSE
, ShellCommandLineGetFlag(Package
, L
"-v"));
158 if (EFI_ERROR(Status
)) {
159 if (Status
== EFI_ACCESS_DENIED
) {
160 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_AD
), gShellLevel3HiiHandle
, L
"alias");
161 ShellStatus
= SHELL_ACCESS_DENIED
;
163 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_ERR_UK
), gShellLevel3HiiHandle
, L
"alias", Status
);
164 ShellStatus
= SHELL_DEVICE_ERROR
;
167 } else if (ShellCommandLineGetCount(Package
) == 2) {
168 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_FEW
), gShellLevel3HiiHandle
, L
"alias");
169 ShellStatus
= SHELL_INVALID_PARAMETER
;
171 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel3HiiHandle
, L
"alias");
172 ShellStatus
= SHELL_INVALID_PARAMETER
;
175 // free the command line package
177 ShellCommandLineFreeVarList (Package
);
180 SHELL_FREE_NON_NULL (CleanParam2
);
181 return (ShellStatus
);