]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Cls.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for attrib shell level 2 function.\r
3\r
7188b455 4 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
c011b6c9 5 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
ba0014b9 6 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>\r
56ba3746 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a405b86d 8\r
9**/\r
10\r
11#include "UefiShellLevel3CommandsLib.h"\r
12\r
47d20b54
MK
13STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
14 { L"-sfo", TypeFlag },\r
15 { NULL, TypeMax }\r
16};\r
7188b455 17\r
a405b86d 18/**\r
19 Function for 'cls' command.\r
20\r
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
23**/\r
24SHELL_STATUS\r
25EFIAPI\r
26ShellCommandRunCls (\r
27 IN EFI_HANDLE ImageHandle,\r
28 IN EFI_SYSTEM_TABLE *SystemTable\r
29 )\r
30{\r
31 EFI_STATUS Status;\r
32 LIST_ENTRY *Package;\r
a405b86d 33 UINTN Background;\r
7188b455 34 UINTN Foreground;\r
a405b86d 35 CHAR16 *ProblemParam;\r
36 SHELL_STATUS ShellStatus;\r
7188b455
TS
37 CONST CHAR16 *BackColorStr;\r
38 CONST CHAR16 *ForeColorStr;\r
a405b86d 39\r
a405b86d 40 //\r
41 // Initialize variables\r
42 //\r
47d20b54
MK
43 ShellStatus = SHELL_SUCCESS;\r
44 ProblemParam = NULL;\r
45 Background = 0;\r
46 Foreground = 0;\r
a405b86d 47\r
48 //\r
49 // initialize the shell lib (we must be in non-auto-init...)\r
50 //\r
47d20b54
MK
51 Status = ShellInitialize ();\r
52 ASSERT_EFI_ERROR (Status);\r
a405b86d 53\r
54 //\r
55 // parse the command line\r
56 //\r
7188b455 57 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
47d20b54
MK
58 if (EFI_ERROR (Status)) {\r
59 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {\r
60 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"cls", ProblemParam);\r
61 FreePool (ProblemParam);\r
a405b86d 62 ShellStatus = SHELL_INVALID_PARAMETER;\r
63 } else {\r
47d20b54 64 ASSERT (FALSE);\r
a405b86d 65 }\r
66 } else {\r
67 //\r
68 // check for "-?"\r
69 //\r
47d20b54
MK
70 if (ShellCommandLineGetFlag (Package, L"-?")) {\r
71 ASSERT (FALSE);\r
7188b455
TS
72 } else if (ShellCommandLineGetFlag (Package, L"-sfo")) {\r
73 if (ShellCommandLineGetCount (Package) > 1) {\r
74 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");\r
75 ShellStatus = SHELL_INVALID_PARAMETER;\r
76 } else {\r
77 Background = (gST->ConOut->Mode->Attribute >> 4) & 0x7;\r
78 Foreground = gST->ConOut->Mode->Attribute & 0x0F;\r
528d74e6 79 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellLevel3HiiHandle, L"cls");\r
7188b455
TS
80 ShellPrintHiiEx (\r
81 -1,\r
82 -1,\r
83 NULL,\r
84 STRING_TOKEN (STR_CLS_OUTPUT_SFO),\r
85 gShellLevel3HiiHandle,\r
86 gST->ConOut->Mode->Attribute,\r
87 Foreground,\r
88 Background\r
89 );\r
90 }\r
a405b86d 91 } else {\r
92 //\r
93 // If there are 0 value parameters, clear sceen\r
94 //\r
7188b455
TS
95 BackColorStr = ShellCommandLineGetRawValue (Package, 1);\r
96 ForeColorStr = ShellCommandLineGetRawValue (Package, 2);\r
97\r
47d20b54 98 if ((BackColorStr == NULL) && (ForeColorStr == NULL)) {\r
a405b86d 99 //\r
100 // clear screen\r
101 //\r
102 gST->ConOut->ClearScreen (gST->ConOut);\r
7188b455
TS
103 } else if (ShellCommandLineGetCount (Package) > 3) {\r
104 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");\r
a405b86d 105 ShellStatus = SHELL_INVALID_PARAMETER;\r
106 } else {\r
7188b455
TS
107 if (BackColorStr != NULL) {\r
108 if ((ShellStrToUintn (BackColorStr) > 7) || (StrLen (BackColorStr) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr))) {\r
109 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", BackColorStr);\r
110 ShellStatus = SHELL_INVALID_PARAMETER;\r
111 } else {\r
112 switch (ShellStrToUintn (BackColorStr)) {\r
113 case 0:\r
114 Background = EFI_BACKGROUND_BLACK;\r
115 break;\r
116 case 1:\r
117 Background = EFI_BACKGROUND_BLUE;\r
118 break;\r
119 case 2:\r
120 Background = EFI_BACKGROUND_GREEN;\r
121 break;\r
122 case 3:\r
123 Background = EFI_BACKGROUND_CYAN;\r
124 break;\r
125 case 4:\r
126 Background = EFI_BACKGROUND_RED;\r
127 break;\r
128 case 5:\r
129 Background = EFI_BACKGROUND_MAGENTA;\r
130 break;\r
131 case 6:\r
132 Background = EFI_BACKGROUND_BROWN;\r
133 break;\r
134 case 7:\r
135 Background = EFI_BACKGROUND_LIGHTGRAY;\r
136 break;\r
137 }\r
138\r
139 if (ForeColorStr != NULL) {\r
140 if ((ShellStrToUintn (ForeColorStr) > 15) || (StrLen (ForeColorStr) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr))) {\r
141 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", ForeColorStr);\r
142 ShellStatus = SHELL_INVALID_PARAMETER;\r
143 } else {\r
144 switch (ShellStrToUintn (ForeColorStr)) {\r
145 case 0:\r
146 Foreground = EFI_BLACK;\r
147 break;\r
148 case 1:\r
149 Foreground = EFI_BLUE;\r
150 break;\r
151 case 2:\r
152 Foreground = EFI_GREEN;\r
153 break;\r
154 case 3:\r
155 Foreground = EFI_CYAN;\r
156 break;\r
157 case 4:\r
158 Foreground = EFI_RED;\r
159 break;\r
160 case 5:\r
161 Foreground = EFI_MAGENTA;\r
162 break;\r
163 case 6:\r
164 Foreground = EFI_BROWN;\r
165 break;\r
166 case 7:\r
167 Foreground = EFI_LIGHTGRAY;\r
168 break;\r
169 case 8:\r
170 Foreground = EFI_DARKGRAY;\r
171 break;\r
172 case 9:\r
173 Foreground = EFI_LIGHTBLUE;\r
174 break;\r
175 case 10:\r
176 Foreground = EFI_LIGHTGREEN;\r
177 break;\r
178 case 11:\r
179 Foreground = EFI_LIGHTCYAN;\r
180 break;\r
181 case 12:\r
182 Foreground = EFI_LIGHTRED;\r
183 break;\r
184 case 13:\r
185 Foreground = EFI_LIGHTMAGENTA;\r
186 break;\r
187 case 14:\r
188 Foreground = EFI_YELLOW;\r
189 break;\r
190 case 15:\r
191 Foreground = EFI_WHITE;\r
192 break;\r
193 }\r
194 }\r
195 } else {\r
196 //\r
197 // Since foreground color is not modified, so retain\r
198 // existing foreground color without any change to it.\r
199 //\r
200 Foreground = gST->ConOut->Mode->Attribute & 0x0F;\r
201 }\r
202\r
203 if (ShellStatus == SHELL_SUCCESS) {\r
204 Status = gST->ConOut->SetAttribute (gST->ConOut, (Foreground | Background) & 0x7F);\r
205 ASSERT_EFI_ERROR (Status);\r
206 Status = gST->ConOut->ClearScreen (gST->ConOut);\r
207 ASSERT_EFI_ERROR (Status);\r
208 }\r
a405b86d 209 }\r
a405b86d 210 }\r
211 }\r
212 }\r
213 }\r
47d20b54 214\r
a405b86d 215 //\r
216 // free the command line package\r
217 //\r
218 ShellCommandLineFreeVarList (Package);\r
219\r
220 //\r
221 // return the status\r
222 //\r
223 return (ShellStatus);\r
224}\r