]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c
1428d37a64065dfc8a3108828c3b0845a736d46d
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Alias.c
1 /** @file
2 Main file for Alias shell level 3 function.
3
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
9
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.
12
13 **/
14
15 #include "UefiShellLevel3CommandsLib.h"
16
17 #include <Library/ShellLib.h>
18
19 /**
20 Print out each alias registered with the Shell.
21
22 @retval STATUS_SUCCESS the printout was sucessful
23 @return any return code from GetNextVariableName except EFI_NOT_FOUND
24 **/
25 SHELL_STATUS
26 EFIAPI
27 PrintAllShellAlias(
28 VOID
29 )
30 {
31 CONST CHAR16 *ConstAllAliasList;
32 CHAR16 *Alias;
33 CONST CHAR16 *Command;
34 CHAR16 *Walker;
35 BOOLEAN Volatile;
36
37 Volatile = FALSE;
38
39 ConstAllAliasList = gEfiShellProtocol->GetAlias(NULL, NULL);
40 if (ConstAllAliasList == NULL) {
41 return (SHELL_SUCCESS);
42 }
43 Alias = AllocateZeroPool(StrSize(ConstAllAliasList));
44 if (Alias == NULL) {
45 return (SHELL_OUT_OF_RESOURCES);
46 }
47 Walker = (CHAR16*)ConstAllAliasList;
48
49 do {
50 CopyMem(Alias, Walker, StrSize(Walker));
51 Walker = StrStr(Alias, L";");
52 if (Walker != NULL) {
53 Walker[0] = CHAR_NULL;
54 Walker = Walker + 1;
55 }
56 Command = gEfiShellProtocol->GetAlias(Alias, &Volatile);
57 if (ShellCommandIsOnAliasList(Alias)) {
58 Volatile = FALSE;
59 }
60 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ALIAS_OUTPUT), gShellLevel3HiiHandle, !Volatile?L' ':L'*', Alias, Command);
61 } while (Walker != NULL && Walker[0] != CHAR_NULL);
62
63 FreePool(Alias);
64
65 return (SHELL_SUCCESS);
66 }
67
68 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
69 {L"-v", TypeFlag},
70 {L"-d", TypeFlag},
71 {NULL, TypeMax}
72 };
73
74 /**
75 Function for 'alias' command.
76
77 @param[in] ImageHandle Handle to the Image (NULL if Internal).
78 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
79 **/
80 SHELL_STATUS
81 EFIAPI
82 ShellCommandRunAlias (
83 IN EFI_HANDLE ImageHandle,
84 IN EFI_SYSTEM_TABLE *SystemTable
85 )
86 {
87 EFI_STATUS Status;
88 LIST_ENTRY *Package;
89 CHAR16 *ProblemParam;
90 SHELL_STATUS ShellStatus;
91 CONST CHAR16 *Param1;
92 CONST CHAR16 *Param2;
93
94 ProblemParam = NULL;
95 ShellStatus = SHELL_SUCCESS;
96
97 //
98 // initialize the shell lib (we must be in non-auto-init...)
99 //
100 Status = ShellInitialize();
101 ASSERT_EFI_ERROR(Status);
102
103 Status = CommandInit();
104 ASSERT_EFI_ERROR(Status);
105
106 //
107 // parse the command line
108 //
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;
115 } else {
116 ASSERT(FALSE);
117 }
118 } else {
119 Param1 = ShellCommandLineGetRawValue(Package, 1);
120 Param2 = ShellCommandLineGetRawValue(Package, 2);
121 //
122 // check for "-?"
123 //
124 if (ShellCommandLineGetFlag(Package, L"-?")) {
125 ASSERT(FALSE);
126 }
127 if (ShellCommandLineGetCount(Package) == 1) {
128 //
129 // print out alias'
130 //
131 Status = PrintAllShellAlias();
132 } else if (ShellCommandLineGetFlag(Package, L"-d")) {
133 //
134 // delete an alias
135 //
136 Status = gEfiShellProtocol->SetAlias(Param1, NULL, TRUE, FALSE);
137 } else if (ShellCommandLineGetCount(Package) == 3) {
138 //
139 // must be adding an alias
140 //
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;
146 } else {
147 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel3HiiHandle, Status);
148 ShellStatus = SHELL_DEVICE_ERROR;
149 }
150 }
151 } else if (ShellCommandLineGetCount(Package) == 2) {
152 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
153 ShellStatus = SHELL_INVALID_PARAMETER;
154 } else {
155 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
156 ShellStatus = SHELL_INVALID_PARAMETER;
157 }
158 //
159 // free the command line package
160 //
161 ShellCommandLineFreeVarList (Package);
162 }
163
164 return (ShellStatus);
165 }