TianoCore EDK2 master
Loading...
Searching...
No Matches
Set.c
Go to the documentation of this file.
1
11
22 VOID
23 )
24{
25 CONST CHAR16 *Value;
26 CONST CHAR16 *ConstEnvNameList;
27
28 ConstEnvNameList = gEfiShellProtocol->GetEnv (NULL);
29 if (ConstEnvNameList == NULL) {
30 return (SHELL_SUCCESS);
31 }
32
33 while (*ConstEnvNameList != CHAR_NULL) {
34 Value = gEfiShellProtocol->GetEnv (ConstEnvNameList);
35 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);
36 ConstEnvNameList += StrLen (ConstEnvNameList)+1;
37 }
38
39 return (SHELL_SUCCESS);
40}
41
42STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {
43 { L"-d", TypeValue },
44 { L"-v", TypeFlag },
45 { NULL, TypeMax }
46};
47
55EFIAPI
57 IN EFI_HANDLE ImageHandle,
58 IN EFI_SYSTEM_TABLE *SystemTable
59 )
60{
61 EFI_STATUS Status;
62 LIST_ENTRY *Package;
63 CONST CHAR16 *KeyName;
64 CONST CHAR16 *Value;
65 CHAR16 *ProblemParam;
66 SHELL_STATUS ShellStatus;
67
68 ProblemParam = NULL;
69 ShellStatus = SHELL_SUCCESS;
70
71 //
72 // initialize the shell lib (we must be in non-auto-init...)
73 //
74 Status = ShellInitialize ();
75 ASSERT_EFI_ERROR (Status);
76
77 //
78 // Make sure globals are good...
79 //
80 Status = CommandInit ();
81 ASSERT_EFI_ERROR (Status);
82
83 //
84 // parse the command line
85 //
86 Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);
87 if (EFI_ERROR (Status)) {
88 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
89 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"set", ProblemParam);
90 FreePool (ProblemParam);
92 } else {
93 ASSERT (FALSE);
94 }
95 } else {
96 //
97 // check for "-?"
98 //
99 if (ShellCommandLineGetFlag (Package, L"-?")) {
100 ASSERT (FALSE);
101 } else if (ShellCommandLineGetRawValue (Package, 3) != NULL) {
102 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
103 ShellStatus = SHELL_INVALID_PARAMETER;
104 } else if ((ShellCommandLineGetRawValue (Package, 1) != NULL) && ShellCommandLineGetFlag (Package, L"-d")) {
105 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
106 ShellStatus = SHELL_INVALID_PARAMETER;
107 } else if (ShellCommandLineGetFlag (Package, L"-d")) {
108 //
109 // delete a environment variable
110 //
111 KeyName = ShellCommandLineGetValue (Package, L"-d");
112 if (KeyName == NULL) {
113 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"set", L"-d");
114 ShellStatus = SHELL_INVALID_PARAMETER;
115 } else {
116 Status = ShellSetEnvironmentVariable (KeyName, L"", ShellCommandLineGetFlag (Package, L"-v"));
117 if (EFI_ERROR (Status)) {
118 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, L"set", KeyName);
119 ShellStatus = SHELL_DEVICE_ERROR;
120 }
121 }
122 } else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
123 //
124 // print out all current environment variables
125 //
126 return (PrintAllShellEnvVars ());
127 } else {
128 //
129 // we are either printing one or assigning one
130 //
131 KeyName = ShellCommandLineGetRawValue (Package, 1);
132 Value = ShellCommandLineGetRawValue (Package, 2);
133 if ((KeyName != NULL) && (Value != NULL)) {
134 //
135 // assigning one
136 //
137 Status = ShellSetEnvironmentVariable (KeyName, Value, ShellCommandLineGetFlag (Package, L"-v"));
138 if (EFI_ERROR (Status)) {
139 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_ERROR_SET), gShellLevel2HiiHandle, L"set", KeyName);
140 ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
141 }
142 } else {
143 if (KeyName != NULL) {
144 //
145 // print out value for this one only.
146 //
147 Value = ShellGetEnvironmentVariable (KeyName);
148 if (Value == NULL) {
149 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, L"set", KeyName);
150 ShellStatus = SHELL_SUCCESS;
151 } else {
152 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
153 ShellStatus = SHELL_SUCCESS;
154 }
155 } else {
156 ASSERT (FALSE);
157 }
158 }
159 }
160 }
161
162 //
163 // free the command line package
164 //
166
167 return (ShellStatus);
168}
#define MAX_BIT
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
SHELL_STATUS EFIAPI ShellCommandRunSet(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Set.c:56
SHELL_STATUS PrintAllShellEnvVars(VOID)
Definition: Set.c:21
EFI_STATUS EFIAPI CommandInit(VOID)
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
EFI_STATUS EFIAPI ShellSetEnvironmentVariable(IN CONST CHAR16 *EnvKey, IN CONST CHAR16 *EnvVal, IN BOOLEAN Volatile)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
CONST CHAR16 *EFIAPI ShellGetEnvironmentVariable(IN CONST CHAR16 *EnvKey)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define STRING_TOKEN(t)