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