]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel3CommandsLib/Alias.c
change the en-dash to the standard dash character.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Alias.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for Alias shell level 3 function.\r
3\r
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellLevel3CommandsLib.h"\r
16\r
17#include <Library/ShellLib.h>\r
18\r
19/**\r
20 Print out each alias registered with the Shell.\r
21\r
22 @retval STATUS_SUCCESS the printout was sucessful\r
23 @return any return code from GetNextVariableName except EFI_NOT_FOUND\r
24**/\r
25SHELL_STATUS\r
26EFIAPI\r
27PrintAllShellAlias(\r
28 VOID\r
29 )\r
30{\r
31 CONST CHAR16 *ConstAllAliasList;\r
32 CHAR16 *Alias;\r
33 CONST CHAR16 *Command;\r
34 CHAR16 *Walker;\r
35 BOOLEAN Volatile;\r
36\r
37 Volatile = FALSE;\r
38\r
39 ConstAllAliasList = gEfiShellProtocol->GetAlias(NULL, NULL);\r
40 if (ConstAllAliasList == NULL) {\r
41 return (SHELL_SUCCESS);\r
42 }\r
43 Alias = AllocateZeroPool(StrSize(ConstAllAliasList));\r
44 Walker = (CHAR16*)ConstAllAliasList;\r
45\r
46 do {\r
47 CopyMem(Alias, Walker, StrSize(Walker));\r
48 Walker = StrStr(Alias, L";");\r
49 if (Walker != NULL) {\r
50 Walker[0] = CHAR_NULL;\r
51 Walker = Walker + 1;\r
52 }\r
53 Command = gEfiShellProtocol->GetAlias(Alias, &Volatile);\r
54 if (ShellCommandIsOnAliasList(Alias)) {\r
55 Volatile = FALSE;\r
56 }\r
57 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ALIAS_OUTPUT), gShellLevel3HiiHandle, !Volatile?L' ':L'*', Alias, Command);\r
58 } while (Walker != NULL && Walker[0] != CHAR_NULL);\r
59\r
60 FreePool(Alias);\r
61\r
62 return (SHELL_SUCCESS);\r
63}\r
64\r
65STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
66 {L"-v", TypeFlag},\r
67 {L"-d", TypeFlag},\r
68 {NULL, TypeMax}\r
69 };\r
70\r
71/**\r
72 Function for 'alias' command.\r
73\r
74 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
75 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
76**/\r
77SHELL_STATUS\r
78EFIAPI\r
79ShellCommandRunAlias (\r
80 IN EFI_HANDLE ImageHandle,\r
81 IN EFI_SYSTEM_TABLE *SystemTable\r
82 )\r
83{\r
84 EFI_STATUS Status;\r
85 LIST_ENTRY *Package;\r
86 CHAR16 *ProblemParam;\r
87 SHELL_STATUS ShellStatus;\r
88 CONST CHAR16 *Param1;\r
89 CONST CHAR16 *Param2;\r
90\r
91 ProblemParam = NULL;\r
92 ShellStatus = SHELL_SUCCESS;\r
93\r
94 //\r
95 // initialize the shell lib (we must be in non-auto-init...)\r
96 //\r
97 Status = ShellInitialize();\r
98 ASSERT_EFI_ERROR(Status);\r
99\r
100 Status = CommandInit();\r
101 ASSERT_EFI_ERROR(Status);\r
102\r
103 //\r
104 // parse the command line\r
105 //\r
106 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
107 if (EFI_ERROR(Status)) {\r
108 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
109 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);\r
110 FreePool(ProblemParam);\r
111 ShellStatus = SHELL_INVALID_PARAMETER;\r
112 } else {\r
113 ASSERT(FALSE);\r
114 }\r
115 } else {\r
116 Param1 = ShellCommandLineGetRawValue(Package, 1);\r
117 Param2 = ShellCommandLineGetRawValue(Package, 2);\r
118 //\r
119 // check for "-?"\r
120 //\r
121 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
122 ASSERT(FALSE);\r
123 }\r
124 if (ShellCommandLineGetCount(Package) == 1) {\r
125 //\r
126 // print out alias'\r
127 //\r
128 Status = PrintAllShellAlias();\r
129 } else if (ShellCommandLineGetFlag(Package, L"-d")) {\r
130 //\r
131 // delete an alias\r
132 //\r
133 Status = gEfiShellProtocol->SetAlias(Param1, NULL, TRUE, FALSE);\r
134 } else if (ShellCommandLineGetCount(Package) == 3) {\r
135 //\r
136 // must be adding an alias\r
137 //\r
138 Status = gEfiShellProtocol->SetAlias(Param2, Param1, FALSE, ShellCommandLineGetFlag(Package, L"-v"));\r
139 if (EFI_ERROR(Status)) {\r
140 if (Status == EFI_ACCESS_DENIED) {\r
141 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_AD), gShellLevel3HiiHandle);\r
142 ShellStatus = SHELL_ACCESS_DENIED;\r
143 } else {\r
144 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel3HiiHandle, Status);\r
145 ShellStatus = SHELL_DEVICE_ERROR;\r
146 }\r
147 }\r
148 } else if (ShellCommandLineGetCount(Package) == 2) {\r
149 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle);\r
150 ShellStatus = SHELL_INVALID_PARAMETER;\r
151 } else {\r
152 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);\r
153 ShellStatus = SHELL_INVALID_PARAMETER;\r
154 }\r
155 //\r
156 // free the command line package\r
157 //\r
158 ShellCommandLineFreeVarList (Package);\r
159 }\r
160\r
161 return (ShellStatus);\r
162}\r