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
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
, L
"set", 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
, L
"set");
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
, L
"set");
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
"set", 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
, L
"set", KeyName
);
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"));
143 if (EFI_ERROR(Status
)) {
144 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_ERROR_SET
), gShellLevel2HiiHandle
, L
"set", KeyName
);
145 ShellStatus
= (SHELL_STATUS
) (Status
& (~MAX_BIT
));
149 if (KeyName
!= NULL
) {
151 // print out value for this one only.
153 Value
= ShellGetEnvironmentVariable(KeyName
);
155 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_NF
), gShellLevel2HiiHandle
, L
"set", KeyName
);
156 ShellStatus
= SHELL_SUCCESS
;
158 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_SET_DISP
), gShellLevel2HiiHandle
, KeyName
, Value
);
159 ShellStatus
= SHELL_SUCCESS
;
169 // free the command line package
171 ShellCommandLineFreeVarList (Package
);
173 return (ShellStatus
);