2 Main file for attrib shell level 2 function.
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
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.
15 #include "UefiShellLevel2CommandsLib.h"
18 Print out each environment variable registered with the Shell 2.0 GUID.
20 If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.
22 @retval STATUS_SUCCESS the printout was sucessful
23 @return any return code from GetNextVariableName except EFI_NOT_FOUND
32 CONST CHAR16
*ConstEnvNameList
;
34 ConstEnvNameList
= gEfiShellProtocol
->GetEnv(NULL
);
35 if (ConstEnvNameList
== NULL
) {
36 return (SHELL_SUCCESS
);
38 while (*ConstEnvNameList
!= CHAR_NULL
){
39 Value
= gEfiShellProtocol
->GetEnv(ConstEnvNameList
);
40 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, ConstEnvNameList
, Value
);
41 ConstEnvNameList
+= StrLen(ConstEnvNameList
)+1;
44 return (SHELL_SUCCESS
);
47 STATIC CONST SHELL_PARAM_ITEM SetParamList
[] = {
54 Function for 'set' command.
56 @param[in] ImageHandle Handle to the Image (NULL if Internal).
57 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
62 IN EFI_HANDLE ImageHandle
,
63 IN EFI_SYSTEM_TABLE
*SystemTable
68 CONST CHAR16
*KeyName
;
71 SHELL_STATUS ShellStatus
;
74 ShellStatus
= SHELL_SUCCESS
;
77 // initialize the shell lib (we must be in non-auto-init...)
79 Status
= ShellInitialize();
80 ASSERT_EFI_ERROR(Status
);
83 // Make sure globals are good...
85 Status
= CommandInit();
86 ASSERT_EFI_ERROR(Status
);
89 // parse the command line
91 Status
= ShellCommandLineParse (SetParamList
, &Package
, &ProblemParam
, TRUE
);
92 if (EFI_ERROR(Status
)) {
93 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
94 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, ProblemParam
);
95 FreePool(ProblemParam
);
96 return (SHELL_INVALID_PARAMETER
);
104 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
106 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
107 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
108 ShellStatus
= SHELL_INVALID_PARAMETER
;
109 } else if (ShellCommandLineGetRawValue(Package
, 1) != NULL
&& ShellCommandLineGetFlag(Package
, L
"-d")) {
110 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
);
111 ShellStatus
= SHELL_INVALID_PARAMETER
;
112 } else if (ShellCommandLineGetFlag(Package
, L
"-d")) {
114 // delete a environment variable
116 KeyName
= ShellCommandLineGetValue(Package
, L
"-d");
117 if (KeyName
== NULL
) {
118 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"-d");
119 ShellStatus
= SHELL_INVALID_PARAMETER
;
121 Status
= ShellSetEnvironmentVariable(KeyName
, L
"", ShellCommandLineGetFlag(Package
, L
"-v"));
122 if (EFI_ERROR(Status
)) {
123 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_ND
), gShellLevel2HiiHandle
, KeyName
, Status
);
124 ShellStatus
= SHELL_DEVICE_ERROR
;
127 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
129 // print out all current environment variables
131 return(PrintAllShellEnvVars());
134 // we are either printing one or assigning one
136 KeyName
= ShellCommandLineGetRawValue(Package
, 1);
137 Value
= ShellCommandLineGetRawValue(Package
, 2);
138 if (KeyName
!= NULL
&& Value
!= NULL
) {
142 Status
= ShellSetEnvironmentVariable(KeyName
, Value
, ShellCommandLineGetFlag(Package
, L
"-v"));
144 if (KeyName
!= NULL
) {
146 // print out value for this one only.
148 Value
= ShellGetEnvironmentVariable(KeyName
);
150 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_NF
), gShellLevel2HiiHandle
, KeyName
);
151 ShellStatus
= SHELL_SUCCESS
;
153 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, KeyName
, Value
);
154 ShellStatus
= SHELL_SUCCESS
;
164 // free the command line package
166 ShellCommandLineFreeVarList (Package
);
168 return (ShellStatus
);