TianoCore EDK2 master
Loading...
Searching...
No Matches
Alias.c
Go to the documentation of this file.
1
11
12#include <Library/ShellLib.h>
13
24 IN CONST CHAR16 *Alias
25 )
26{
27 CONST CHAR16 *ConstAliasVal;
28 SHELL_STATUS ShellStatus;
29 BOOLEAN Volatile;
30
31 ShellStatus = SHELL_SUCCESS;
32 ConstAliasVal = gEfiShellProtocol->GetAlias (Alias, &Volatile);
33 if (ConstAliasVal == NULL) {
34 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"alias", Alias);
35 ShellStatus = SHELL_INVALID_PARAMETER;
36 } else {
37 if (ShellCommandIsOnAliasList (Alias)) {
38 Volatile = FALSE;
39 }
40
41 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_ALIAS_OUTPUT), gShellLevel3HiiHandle, !Volatile ? L' ' : L'*', Alias, ConstAliasVal);
42 }
43
44 return ShellStatus;
45}
46
55 VOID
56 )
57{
58 CONST CHAR16 *ConstAllAliasList;
59 CHAR16 *Alias;
60 CHAR16 *Walker;
61
62 ConstAllAliasList = gEfiShellProtocol->GetAlias (NULL, NULL);
63 if (ConstAllAliasList == NULL) {
64 return (SHELL_SUCCESS);
65 }
66
67 Alias = AllocateZeroPool (StrSize (ConstAllAliasList));
68 if (Alias == NULL) {
70 }
71
72 Walker = (CHAR16 *)ConstAllAliasList;
73
74 do {
75 CopyMem (Alias, Walker, StrSize (Walker));
76 Walker = StrStr (Alias, L";");
77 if (Walker != NULL) {
78 Walker[0] = CHAR_NULL;
79 Walker = Walker + 1;
80 }
81
83 } while (Walker != NULL && Walker[0] != CHAR_NULL);
84
85 FreePool (Alias);
86
87 return (SHELL_SUCCESS);
88}
89
113 IN CONST CHAR16 *Command,
114 IN CONST CHAR16 *Alias,
115 IN BOOLEAN Replace,
116 IN BOOLEAN Volatile
117 )
118{
119 SHELL_STATUS ShellStatus;
120 EFI_STATUS Status;
121
122 ShellStatus = SHELL_SUCCESS;
123 Status = gEfiShellProtocol->SetAlias (Command, Alias, Replace, Volatile);
124 if (EFI_ERROR (Status)) {
125 if (Status == EFI_ACCESS_DENIED) {
126 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel3HiiHandle, L"alias");
127 ShellStatus = SHELL_ACCESS_DENIED;
128 } else if (Status == EFI_NOT_FOUND) {
129 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_NOT_FOUND), gShellLevel3HiiHandle, L"alias", Command);
130 ShellStatus = SHELL_NOT_FOUND;
131 } else {
132 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel3HiiHandle, L"alias", Status);
133 ShellStatus = SHELL_DEVICE_ERROR;
134 }
135 }
136
137 return ShellStatus;
138}
139
140STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
141 { L"-v", TypeFlag },
142 { L"-d", TypeValue },
143 { NULL, TypeMax }
144};
145
153EFIAPI
155 IN EFI_HANDLE ImageHandle,
156 IN EFI_SYSTEM_TABLE *SystemTable
157 )
158{
159 EFI_STATUS Status;
160 LIST_ENTRY *Package;
161 CHAR16 *ProblemParam;
162 SHELL_STATUS ShellStatus;
163 CONST CHAR16 *Param1;
164 CONST CHAR16 *Param2;
165 CONST CHAR16 *ParamStrD;
166 CHAR16 *CleanParam2;
167 BOOLEAN DeleteFlag;
168 BOOLEAN VolatileFlag;
169
170 ProblemParam = NULL;
171 ShellStatus = SHELL_SUCCESS;
172 CleanParam2 = NULL;
173
174 //
175 // initialize the shell lib (we must be in non-auto-init...)
176 //
177 Status = ShellInitialize ();
178 ASSERT_EFI_ERROR (Status);
179
180 Status = CommandInit ();
181 ASSERT_EFI_ERROR (Status);
182
183 //
184 // parse the command line
185 //
186 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
187 if (EFI_ERROR (Status)) {
188 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
189 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"alias", ProblemParam);
190 FreePool (ProblemParam);
191 ShellStatus = SHELL_INVALID_PARAMETER;
192 } else {
193 ASSERT (FALSE);
194 }
195 } else {
196 Param1 = ShellCommandLineGetRawValue (Package, 1);
197 Param2 = ShellCommandLineGetRawValue (Package, 2);
198
199 DeleteFlag = ShellCommandLineGetFlag (Package, L"-d");
200 VolatileFlag = ShellCommandLineGetFlag (Package, L"-v");
201
202 if (Param2 != NULL) {
203 CleanParam2 = AllocateCopyPool (StrSize (Param2), Param2);
204 if (CleanParam2 == NULL) {
207 }
208
209 if ((CleanParam2[0] == L'\"') && (CleanParam2[StrLen (CleanParam2)-1] == L'\"')) {
210 CleanParam2[StrLen (CleanParam2)-1] = L'\0';
211 CopyMem (CleanParam2, CleanParam2 + 1, StrSize (CleanParam2) - sizeof (CleanParam2[0]));
212 }
213 }
214
215 if (!DeleteFlag && !VolatileFlag) {
216 switch (ShellCommandLineGetCount (Package)) {
217 case 1:
218 //
219 // "alias"
220 //
221 ShellStatus = PrintAllShellAlias ();
222 break;
223 case 2:
224 //
225 // "alias Param1"
226 //
227 ShellStatus = PrintSingleShellAlias (Param1);
228 break;
229 case 3:
230 //
231 // "alias Param1 CleanParam2"
232 //
233 ShellStatus = ShellLevel3CommandsLibSetAlias (CleanParam2, Param1, FALSE, VolatileFlag);
234 break;
235 default:
236 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"alias");
237 ShellStatus = SHELL_INVALID_PARAMETER;
238 }
239 } else if (DeleteFlag) {
240 if (VolatileFlag || (ShellCommandLineGetCount (Package) > 1)) {
241 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"alias");
242 ShellStatus = SHELL_INVALID_PARAMETER;
243 } else {
244 ParamStrD = ShellCommandLineGetValue (Package, L"-d");
245 if (ParamStrD == NULL) {
246 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle, L"alias");
247 ShellStatus = SHELL_INVALID_PARAMETER;
248 } else {
249 //
250 // Delete an alias: "alias -d ParamStrD"
251 //
252 ShellStatus = ShellLevel3CommandsLibSetAlias (ParamStrD, NULL, TRUE, FALSE);
253 }
254 }
255 } else {
256 //
257 // Set volatile alias.
258 //
259 ASSERT (VolatileFlag);
260 ASSERT (!DeleteFlag);
261 switch (ShellCommandLineGetCount (Package)) {
262 case 1:
263 case 2:
264 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle, L"alias");
265 ShellStatus = SHELL_INVALID_PARAMETER;
266 break;
267 case 3:
268 //
269 // "alias -v Param1 CleanParam2"
270 //
271 ShellStatus = ShellLevel3CommandsLibSetAlias (CleanParam2, Param1, FALSE, VolatileFlag);
272 break;
273 default:
274 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"alias");
275 ShellStatus = SHELL_INVALID_PARAMETER;
276 }
277 }
278
279 //
280 // free the command line package
281 //
283 }
284
285 SHELL_FREE_NON_NULL (CleanParam2);
286 return (ShellStatus);
287}
SHELL_STATUS PrintAllShellAlias(VOID)
Definition: Alias.c:54
SHELL_STATUS PrintSingleShellAlias(IN CONST CHAR16 *Alias)
Definition: Alias.c:23
SHELL_STATUS EFIAPI ShellCommandRunAlias(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Alias.c:154
SHELL_STATUS ShellLevel3CommandsLibSetAlias(IN CONST CHAR16 *Command, IN CONST CHAR16 *Alias, IN BOOLEAN Replace, IN BOOLEAN Volatile)
Definition: Alias.c:112
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_OUT_OF_RESOURCES
Definition: Shell.h:73
@ SHELL_ACCESS_DENIED
Definition: Shell.h:106
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_NOT_FOUND
Definition: Shell.h:101
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI CommandInit(VOID)
BOOLEAN EFIAPI ShellCommandIsOnAliasList(IN CONST CHAR16 *Alias)
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define STRING_TOKEN(t)