]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c
udk2010.up2.shell initial release.
[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 Walker = (CHAR16*)ConstAllAliasList;
45
46 do {
47 CopyMem(Alias, Walker, StrSize(Walker));
48 Walker = StrStr(Alias, L";");
49 if (Walker != NULL) {
50 Walker[0] = CHAR_NULL;
51 Walker = Walker + 1;
52 }
53 Command = gEfiShellProtocol->GetAlias(Alias, &Volatile);
54 if (ShellCommandIsOnAliasList(Alias)) {
55 Volatile = FALSE;
56 }
57 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ALIAS_OUTPUT), gShellLevel3HiiHandle, !Volatile?L' ':L'*', Alias, Command);
58 } while (Walker != NULL && Walker[0] != CHAR_NULL);
59
60 FreePool(Alias);
61
62 return (SHELL_SUCCESS);
63 }
64
65 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
66 {L"-v", TypeFlag},
67 {L"-d", TypeFlag},
68 {NULL, TypeMax}
69 };
70
71 /**
72 Function for 'alias' command.
73
74 @param[in] ImageHandle Handle to the Image (NULL if Internal).
75 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
76 **/
77 SHELL_STATUS
78 EFIAPI
79 ShellCommandRunAlias (
80 IN EFI_HANDLE ImageHandle,
81 IN EFI_SYSTEM_TABLE *SystemTable
82 )
83 {
84 EFI_STATUS Status;
85 LIST_ENTRY *Package;
86 CHAR16 *ProblemParam;
87 SHELL_STATUS ShellStatus;
88 CONST CHAR16 *Param1;
89 CONST CHAR16 *Param2;
90
91 ProblemParam = NULL;
92 ShellStatus = SHELL_SUCCESS;
93
94 //
95 // initialize the shell lib (we must be in non-auto-init...)
96 //
97 Status = ShellInitialize();
98 ASSERT_EFI_ERROR(Status);
99
100 Status = CommandInit();
101 ASSERT_EFI_ERROR(Status);
102
103 //
104 // parse the command line
105 //
106 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
107 if (EFI_ERROR(Status)) {
108 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
109 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
110 FreePool(ProblemParam);
111 ShellStatus = SHELL_INVALID_PARAMETER;
112 } else {
113 ASSERT(FALSE);
114 }
115 } else {
116 Param1 = ShellCommandLineGetRawValue(Package, 1);
117 Param2 = ShellCommandLineGetRawValue(Package, 2);
118 //
119 // check for "-?"
120 //
121 if (ShellCommandLineGetFlag(Package, L"-?")) {
122 ASSERT(FALSE);
123 }
124 if (ShellCommandLineGetCount(Package) == 1) {
125 //
126 // print out alias'
127 //
128 Status = PrintAllShellAlias();
129 } else if (ShellCommandLineGetFlag(Package, L"-d")) {
130 //
131 // delete an alias
132 //
133 Status = gEfiShellProtocol->SetAlias(Param1, NULL, TRUE, FALSE);
134 } else if (ShellCommandLineGetCount(Package) == 3) {
135 //
136 // must be adding an alias
137 //
138 Status = gEfiShellProtocol->SetAlias(Param2, Param1, FALSE, ShellCommandLineGetFlag(Package, L"-v"));
139 if (EFI_ERROR(Status)) {
140 if (Status == EFI_ACCESS_DENIED) {
141 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel3HiiHandle);
142 ShellStatus = SHELL_ACCESS_DENIED;
143 } else {
144 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel3HiiHandle, Status);
145 ShellStatus = SHELL_DEVICE_ERROR;
146 }
147 }
148 } else if (ShellCommandLineGetCount(Package) == 2) {
149 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);
150 ShellStatus = SHELL_INVALID_PARAMETER;
151 } else {
152 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
153 ShellStatus = SHELL_INVALID_PARAMETER;
154 }
155 //
156 // free the command line package
157 //
158 ShellCommandLineFreeVarList (Package);
159 }
160
161 return (ShellStatus);
162 }