2 Main file for attrib shell level 2 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2015, 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
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.
16 #include "UefiShellLevel2CommandsLib.h"
19 Print out each environment variable registered with the Shell 2.0 GUID.
21 If you spawn a pre 2.0 shell from the Shell 2.0 the environment variable may not carry through.
23 @retval STATUS_SUCCESS the printout was sucessful
24 @return any return code from GetNextVariableName except EFI_NOT_FOUND
33 CONST CHAR16
*ConstEnvNameList
;
35 ConstEnvNameList
= gEfiShellProtocol
->GetEnv(NULL
);
36 if (ConstEnvNameList
== NULL
) {
37 return (SHELL_SUCCESS
);
39 while (*ConstEnvNameList
!= CHAR_NULL
){
40 Value
= gEfiShellProtocol
->GetEnv(ConstEnvNameList
);
41 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, ConstEnvNameList
, Value
);
42 ConstEnvNameList
+= StrLen(ConstEnvNameList
)+1;
45 return (SHELL_SUCCESS
);
48 STATIC CONST SHELL_PARAM_ITEM SetParamList
[] = {
55 Function for 'set' command.
57 @param[in] ImageHandle Handle to the Image (NULL if Internal).
58 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
63 IN EFI_HANDLE ImageHandle
,
64 IN EFI_SYSTEM_TABLE
*SystemTable
69 CONST CHAR16
*KeyName
;
72 SHELL_STATUS ShellStatus
;
75 ShellStatus
= SHELL_SUCCESS
;
78 // initialize the shell lib (we must be in non-auto-init...)
80 Status
= ShellInitialize();
81 ASSERT_EFI_ERROR(Status
);
84 // Make sure globals are good...
86 Status
= CommandInit();
87 ASSERT_EFI_ERROR(Status
);
90 // parse the command line
92 Status
= ShellCommandLineParse (SetParamList
, &Package
, &ProblemParam
, TRUE
);
93 if (EFI_ERROR(Status
)) {
94 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
95 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellLevel2HiiHandle
, L
"set", ProblemParam
);
96 FreePool(ProblemParam
);
97 return (SHELL_INVALID_PARAMETER
);
105 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
107 } else if (ShellCommandLineGetRawValue(Package
, 3) != NULL
) {
108 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"set");
109 ShellStatus
= SHELL_INVALID_PARAMETER
;
110 } else if (ShellCommandLineGetRawValue(Package
, 1) != NULL
&& ShellCommandLineGetFlag(Package
, L
"-d")) {
111 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellLevel2HiiHandle
, L
"set");
112 ShellStatus
= SHELL_INVALID_PARAMETER
;
113 } else if (ShellCommandLineGetFlag(Package
, L
"-d")) {
115 // delete a environment variable
117 KeyName
= ShellCommandLineGetValue(Package
, L
"-d");
118 if (KeyName
== NULL
) {
119 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_NO_VALUE
), gShellLevel2HiiHandle
, L
"set", L
"-d");
120 ShellStatus
= SHELL_INVALID_PARAMETER
;
122 Status
= ShellSetEnvironmentVariable(KeyName
, L
"", ShellCommandLineGetFlag(Package
, L
"-v"));
123 if (EFI_ERROR(Status
)) {
124 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_ND
), gShellLevel2HiiHandle
, L
"set", KeyName
);
125 ShellStatus
= SHELL_DEVICE_ERROR
;
128 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
130 // print out all current environment variables
132 return(PrintAllShellEnvVars());
135 // we are either printing one or assigning one
137 KeyName
= ShellCommandLineGetRawValue(Package
, 1);
138 Value
= ShellCommandLineGetRawValue(Package
, 2);
139 if (KeyName
!= NULL
&& Value
!= NULL
) {
143 Status
= ShellSetEnvironmentVariable(KeyName
, Value
, ShellCommandLineGetFlag(Package
, L
"-v"));
144 if (EFI_ERROR(Status
)) {
145 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_ERROR_SET
), gShellLevel2HiiHandle
, L
"set", KeyName
);
146 ShellStatus
= (SHELL_STATUS
) (Status
& (~MAX_BIT
));
150 if (KeyName
!= NULL
) {
152 // print out value for this one only.
154 Value
= ShellGetEnvironmentVariable(KeyName
);
156 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_NF
), gShellLevel2HiiHandle
, L
"set", KeyName
);
157 ShellStatus
= SHELL_SUCCESS
;
159 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, KeyName
, Value
);
160 ShellStatus
= SHELL_SUCCESS
;
170 // free the command line package
172 ShellCommandLineFreeVarList (Package
);
174 return (ShellStatus
);