]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for attrib shell level 2 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 "UefiShellLevel2CommandsLib.h"\r | |
16 | \r | |
17 | /**\r | |
18 | Print out each environment variable registered with the Shell 2.0 GUID.\r | |
19 | \r | |
20 | If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.\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 | |
25 | SHELL_STATUS\r | |
26 | EFIAPI\r | |
27 | PrintAllShellEnvVars(\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | CONST CHAR16 *Value;\r | |
32 | CONST CHAR16 *ConstEnvNameList;\r | |
33 | \r | |
34 | ConstEnvNameList = gEfiShellProtocol->GetEnv(NULL);\r | |
35 | if (ConstEnvNameList == NULL) {\r | |
36 | return (SHELL_SUCCESS);\r | |
37 | }\r | |
38 | while (*ConstEnvNameList != CHAR_NULL){\r | |
39 | Value = gEfiShellProtocol->GetEnv(ConstEnvNameList);\r | |
40 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);\r | |
41 | ConstEnvNameList += StrLen(ConstEnvNameList)+1;\r | |
42 | }\r | |
43 | \r | |
44 | return (SHELL_SUCCESS);\r | |
45 | }\r | |
46 | \r | |
47 | STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {\r | |
48 | {L"-d", TypeValue},\r | |
49 | {L"-v", TypeFlag},\r | |
50 | {NULL, TypeMax}\r | |
51 | };\r | |
52 | \r | |
53 | /**\r | |
54 | Function for 'set' command.\r | |
55 | \r | |
56 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
57 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
58 | **/\r | |
59 | SHELL_STATUS\r | |
60 | EFIAPI\r | |
61 | ShellCommandRunSet (\r | |
62 | IN EFI_HANDLE ImageHandle,\r | |
63 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
64 | )\r | |
65 | {\r | |
66 | EFI_STATUS Status;\r | |
67 | LIST_ENTRY *Package;\r | |
68 | CONST CHAR16 *KeyName;\r | |
69 | CONST CHAR16 *Value;\r | |
70 | CHAR16 *ProblemParam;\r | |
71 | SHELL_STATUS ShellStatus;\r | |
72 | \r | |
73 | ProblemParam = NULL;\r | |
74 | ShellStatus = SHELL_SUCCESS;\r | |
75 | \r | |
76 | //\r | |
77 | // initialize the shell lib (we must be in non-auto-init...)\r | |
78 | //\r | |
79 | Status = ShellInitialize();\r | |
80 | ASSERT_EFI_ERROR(Status);\r | |
81 | \r | |
82 | //\r | |
83 | // Make sure globals are good...\r | |
84 | //\r | |
85 | Status = CommandInit();\r | |
86 | ASSERT_EFI_ERROR(Status);\r | |
87 | \r | |
88 | //\r | |
89 | // parse the command line\r | |
90 | //\r | |
91 | Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);\r | |
92 | if (EFI_ERROR(Status)) {\r | |
93 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
94 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);\r | |
95 | FreePool(ProblemParam);\r | |
96 | return (SHELL_INVALID_PARAMETER);\r | |
97 | } else {\r | |
98 | ASSERT(FALSE);\r | |
99 | }\r | |
100 | } else {\r | |
101 | //\r | |
102 | // check for "-?"\r | |
103 | //\r | |
104 | if (ShellCommandLineGetFlag(Package, L"-?")) {\r | |
105 | ASSERT(FALSE);\r | |
106 | } else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {\r | |
107 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r | |
108 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
109 | } else if (ShellCommandLineGetRawValue(Package, 1) != NULL && ShellCommandLineGetFlag(Package, L"-d")) {\r | |
110 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);\r | |
111 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
112 | } else if (ShellCommandLineGetFlag(Package, L"-d")) {\r | |
113 | //\r | |
114 | // delete a environment variable\r | |
115 | //\r | |
116 | KeyName = ShellCommandLineGetValue(Package, L"-d");\r | |
117 | if (KeyName == NULL) {\r | |
118 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-d");\r | |
119 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
120 | } else {\r | |
121 | Status = ShellSetEnvironmentVariable(KeyName, L"", ShellCommandLineGetFlag(Package, L"-v"));\r | |
122 | if (EFI_ERROR(Status)) {\r | |
123 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, KeyName, Status);\r | |
124 | ShellStatus = SHELL_DEVICE_ERROR;\r | |
125 | }\r | |
126 | }\r | |
127 | } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r | |
128 | //\r | |
129 | // print out all current environment variables\r | |
130 | //\r | |
131 | return(PrintAllShellEnvVars());\r | |
132 | } else {\r | |
133 | //\r | |
134 | // we are either printing one or assigning one\r | |
135 | //\r | |
136 | KeyName = ShellCommandLineGetRawValue(Package, 1);\r | |
137 | Value = ShellCommandLineGetRawValue(Package, 2);\r | |
138 | if (KeyName != NULL && Value != NULL) {\r | |
139 | //\r | |
140 | // assigning one\r | |
141 | //\r | |
142 | Status = ShellSetEnvironmentVariable(KeyName, Value, ShellCommandLineGetFlag(Package, L"-v"));\r | |
143 | } else {\r | |
144 | if (KeyName != NULL) {\r | |
145 | //\r | |
146 | // print out value for this one only.\r | |
147 | //\r | |
148 | Value = ShellGetEnvironmentVariable(KeyName);\r | |
149 | if (Value == NULL) {\r | |
150 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, KeyName);\r | |
151 | ShellStatus = SHELL_SUCCESS;\r | |
152 | } else {\r | |
153 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);\r | |
154 | ShellStatus = SHELL_SUCCESS;\r | |
155 | }\r | |
156 | } else {\r | |
157 | ASSERT(FALSE);\r | |
158 | }\r | |
159 | }\r | |
160 | }\r | |
161 | }\r | |
162 | \r | |
163 | //\r | |
164 | // free the command line package\r | |
165 | //\r | |
166 | ShellCommandLineFreeVarList (Package);\r | |
167 | \r | |
168 | return (ShellStatus);\r | |
169 | }\r |