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