TianoCore EDK2 master
Loading...
Searching...
No Matches
Cls.c
Go to the documentation of this file.
1
12
13STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
14 { L"-sfo", TypeFlag },
15 { NULL, TypeMax }
16};
17
25EFIAPI
27 IN EFI_HANDLE ImageHandle,
28 IN EFI_SYSTEM_TABLE *SystemTable
29 )
30{
31 EFI_STATUS Status;
32 LIST_ENTRY *Package;
33 UINTN Background;
34 UINTN Foreground;
35 CHAR16 *ProblemParam;
36 SHELL_STATUS ShellStatus;
37 CONST CHAR16 *BackColorStr;
38 CONST CHAR16 *ForeColorStr;
39
40 //
41 // Initialize variables
42 //
43 ShellStatus = SHELL_SUCCESS;
44 ProblemParam = NULL;
45 Background = 0;
46 Foreground = 0;
47
48 //
49 // initialize the shell lib (we must be in non-auto-init...)
50 //
51 Status = ShellInitialize ();
52 ASSERT_EFI_ERROR (Status);
53
54 //
55 // parse the command line
56 //
57 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
58 if (EFI_ERROR (Status)) {
59 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
60 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"cls", ProblemParam);
61 FreePool (ProblemParam);
62 ShellStatus = SHELL_INVALID_PARAMETER;
63 } else {
64 ASSERT (FALSE);
65 }
66 } else {
67 //
68 // check for "-?"
69 //
70 if (ShellCommandLineGetFlag (Package, L"-?")) {
71 ASSERT (FALSE);
72 } else if (ShellCommandLineGetFlag (Package, L"-sfo")) {
73 if (ShellCommandLineGetCount (Package) > 1) {
74 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");
75 ShellStatus = SHELL_INVALID_PARAMETER;
76 } else {
77 Background = (gST->ConOut->Mode->Attribute >> 4) & 0x7;
78 Foreground = gST->ConOut->Mode->Attribute & 0x0F;
79 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel3HiiHandle, L"cls");
81 -1,
82 -1,
83 NULL,
84 STRING_TOKEN (STR_CLS_OUTPUT_SFO),
85 gShellLevel3HiiHandle,
87 Foreground,
88 Background
89 );
90 }
91 } else {
92 //
93 // If there are 0 value parameters, clear sceen
94 //
95 BackColorStr = ShellCommandLineGetRawValue (Package, 1);
96 ForeColorStr = ShellCommandLineGetRawValue (Package, 2);
97
98 if ((BackColorStr == NULL) && (ForeColorStr == NULL)) {
99 //
100 // clear screen
101 //
102 gST->ConOut->ClearScreen (gST->ConOut);
103 } else if (ShellCommandLineGetCount (Package) > 3) {
104 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");
105 ShellStatus = SHELL_INVALID_PARAMETER;
106 } else {
107 if (BackColorStr != NULL) {
108 if ((ShellStrToUintn (BackColorStr) > 7) || (StrLen (BackColorStr) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr))) {
109 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", BackColorStr);
110 ShellStatus = SHELL_INVALID_PARAMETER;
111 } else {
112 switch (ShellStrToUintn (BackColorStr)) {
113 case 0:
114 Background = EFI_BACKGROUND_BLACK;
115 break;
116 case 1:
117 Background = EFI_BACKGROUND_BLUE;
118 break;
119 case 2:
120 Background = EFI_BACKGROUND_GREEN;
121 break;
122 case 3:
123 Background = EFI_BACKGROUND_CYAN;
124 break;
125 case 4:
126 Background = EFI_BACKGROUND_RED;
127 break;
128 case 5:
129 Background = EFI_BACKGROUND_MAGENTA;
130 break;
131 case 6:
132 Background = EFI_BACKGROUND_BROWN;
133 break;
134 case 7:
135 Background = EFI_BACKGROUND_LIGHTGRAY;
136 break;
137 }
138
139 if (ForeColorStr != NULL) {
140 if ((ShellStrToUintn (ForeColorStr) > 15) || (StrLen (ForeColorStr) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr))) {
141 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", ForeColorStr);
142 ShellStatus = SHELL_INVALID_PARAMETER;
143 } else {
144 switch (ShellStrToUintn (ForeColorStr)) {
145 case 0:
146 Foreground = EFI_BLACK;
147 break;
148 case 1:
149 Foreground = EFI_BLUE;
150 break;
151 case 2:
152 Foreground = EFI_GREEN;
153 break;
154 case 3:
155 Foreground = EFI_CYAN;
156 break;
157 case 4:
158 Foreground = EFI_RED;
159 break;
160 case 5:
161 Foreground = EFI_MAGENTA;
162 break;
163 case 6:
164 Foreground = EFI_BROWN;
165 break;
166 case 7:
167 Foreground = EFI_LIGHTGRAY;
168 break;
169 case 8:
170 Foreground = EFI_DARKGRAY;
171 break;
172 case 9:
173 Foreground = EFI_LIGHTBLUE;
174 break;
175 case 10:
176 Foreground = EFI_LIGHTGREEN;
177 break;
178 case 11:
179 Foreground = EFI_LIGHTCYAN;
180 break;
181 case 12:
182 Foreground = EFI_LIGHTRED;
183 break;
184 case 13:
185 Foreground = EFI_LIGHTMAGENTA;
186 break;
187 case 14:
188 Foreground = EFI_YELLOW;
189 break;
190 case 15:
191 Foreground = EFI_WHITE;
192 break;
193 }
194 }
195 } else {
196 //
197 // Since foreground color is not modified, so retain
198 // existing foreground color without any change to it.
199 //
200 Foreground = gST->ConOut->Mode->Attribute & 0x0F;
201 }
202
203 if (ShellStatus == SHELL_SUCCESS) {
204 Status = gST->ConOut->SetAttribute (gST->ConOut, (Foreground | Background) & 0x7F);
205 ASSERT_EFI_ERROR (Status);
206 Status = gST->ConOut->ClearScreen (gST->ConOut);
207 ASSERT_EFI_ERROR (Status);
208 }
209 }
210 }
211 }
212 }
213 }
214
215 //
216 // free the command line package
217 //
219
220 //
221 // return the status
222 //
223 return (ShellStatus);
224}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
SHELL_STATUS EFIAPI ShellCommandRunCls(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Cls.c:26
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_INVALID_PARAMETER
Definition: Shell.h:35
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
#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)
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
BOOLEAN EFIAPI ShellIsDecimalDigitCharacter(IN CHAR16 Char)
Definition: UefiShellLib.c:194
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)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_SYSTEM_TABLE * gST
#define STRING_TOKEN(t)
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064