]>
Commit | Line | Data |
---|---|---|
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 |
17e59b33 | 6 | Copyright (c) 2009 - 2014, 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 |
19 | STATIC 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 | |
30 | SHELL_STATUS\r | |
31 | EFIAPI\r | |
32 | ShellCommandRunCls (\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 | |
e54a10bb | 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 | |
85 | ShellPrintHiiEx (\r | |
86 | -1,\r | |
87 | -1,\r | |
88 | NULL,\r | |
89 | STRING_TOKEN (STR_CLS_OUTPUT_SFO),\r | |
90 | gShellLevel3HiiHandle,\r | |
91 | gST->ConOut->Mode->Attribute,\r | |
92 | Foreground,\r | |
93 | Background\r | |
94 | );\r | |
95 | }\r | |
a405b86d | 96 | } else {\r |
97 | //\r | |
98 | // If there are 0 value parameters, clear sceen\r | |
99 | //\r | |
7188b455 TS |
100 | BackColorStr = ShellCommandLineGetRawValue (Package, 1);\r |
101 | ForeColorStr = ShellCommandLineGetRawValue (Package, 2);\r | |
102 | \r | |
103 | if (BackColorStr == NULL && ForeColorStr == NULL) {\r | |
a405b86d | 104 | //\r |
105 | // clear screen\r | |
106 | //\r | |
107 | gST->ConOut->ClearScreen (gST->ConOut);\r | |
7188b455 TS |
108 | } else if (ShellCommandLineGetCount (Package) > 3) {\r |
109 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"cls");\r | |
a405b86d | 110 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
111 | } else {\r | |
7188b455 TS |
112 | if (BackColorStr != NULL) {\r |
113 | if ((ShellStrToUintn (BackColorStr) > 7) || (StrLen (BackColorStr) > 1) || (!ShellIsDecimalDigitCharacter (*BackColorStr))) {\r | |
114 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", BackColorStr);\r | |
115 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
116 | } else {\r | |
117 | switch (ShellStrToUintn (BackColorStr)) {\r | |
118 | case 0:\r | |
119 | Background = EFI_BACKGROUND_BLACK;\r | |
120 | break;\r | |
121 | case 1:\r | |
122 | Background = EFI_BACKGROUND_BLUE;\r | |
123 | break;\r | |
124 | case 2:\r | |
125 | Background = EFI_BACKGROUND_GREEN;\r | |
126 | break;\r | |
127 | case 3:\r | |
128 | Background = EFI_BACKGROUND_CYAN;\r | |
129 | break;\r | |
130 | case 4:\r | |
131 | Background = EFI_BACKGROUND_RED;\r | |
132 | break;\r | |
133 | case 5:\r | |
134 | Background = EFI_BACKGROUND_MAGENTA;\r | |
135 | break;\r | |
136 | case 6:\r | |
137 | Background = EFI_BACKGROUND_BROWN;\r | |
138 | break;\r | |
139 | case 7:\r | |
140 | Background = EFI_BACKGROUND_LIGHTGRAY;\r | |
141 | break;\r | |
142 | }\r | |
143 | \r | |
144 | if (ForeColorStr != NULL) {\r | |
145 | if ((ShellStrToUintn (ForeColorStr) > 15) || (StrLen (ForeColorStr) > 2) || (!ShellIsDecimalDigitCharacter (*ForeColorStr))) {\r | |
146 | ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"cls", ForeColorStr);\r | |
147 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
148 | } else {\r | |
149 | switch (ShellStrToUintn (ForeColorStr)) {\r | |
150 | case 0:\r | |
151 | Foreground = EFI_BLACK;\r | |
152 | break;\r | |
153 | case 1:\r | |
154 | Foreground = EFI_BLUE;\r | |
155 | break;\r | |
156 | case 2:\r | |
157 | Foreground = EFI_GREEN;\r | |
158 | break;\r | |
159 | case 3:\r | |
160 | Foreground = EFI_CYAN;\r | |
161 | break;\r | |
162 | case 4:\r | |
163 | Foreground = EFI_RED;\r | |
164 | break;\r | |
165 | case 5:\r | |
166 | Foreground = EFI_MAGENTA;\r | |
167 | break;\r | |
168 | case 6:\r | |
169 | Foreground = EFI_BROWN;\r | |
170 | break;\r | |
171 | case 7:\r | |
172 | Foreground = EFI_LIGHTGRAY;\r | |
173 | break;\r | |
174 | case 8:\r | |
175 | Foreground = EFI_DARKGRAY;\r | |
176 | break;\r | |
177 | case 9:\r | |
178 | Foreground = EFI_LIGHTBLUE;\r | |
179 | break;\r | |
180 | case 10:\r | |
181 | Foreground = EFI_LIGHTGREEN;\r | |
182 | break;\r | |
183 | case 11:\r | |
184 | Foreground = EFI_LIGHTCYAN;\r | |
185 | break;\r | |
186 | case 12:\r | |
187 | Foreground = EFI_LIGHTRED;\r | |
188 | break;\r | |
189 | case 13:\r | |
190 | Foreground = EFI_LIGHTMAGENTA;\r | |
191 | break;\r | |
192 | case 14:\r | |
193 | Foreground = EFI_YELLOW;\r | |
194 | break;\r | |
195 | case 15:\r | |
196 | Foreground = EFI_WHITE;\r | |
197 | break;\r | |
198 | }\r | |
199 | }\r | |
200 | } else {\r | |
201 | //\r | |
202 | // Since foreground color is not modified, so retain\r | |
203 | // existing foreground color without any change to it.\r | |
204 | //\r | |
205 | Foreground = gST->ConOut->Mode->Attribute & 0x0F;\r | |
206 | }\r | |
207 | \r | |
208 | if (ShellStatus == SHELL_SUCCESS) {\r | |
209 | Status = gST->ConOut->SetAttribute (gST->ConOut, (Foreground | Background) & 0x7F);\r | |
210 | ASSERT_EFI_ERROR (Status);\r | |
211 | Status = gST->ConOut->ClearScreen (gST->ConOut);\r | |
212 | ASSERT_EFI_ERROR (Status);\r | |
213 | }\r | |
a405b86d | 214 | }\r |
a405b86d | 215 | }\r |
216 | }\r | |
217 | }\r | |
218 | }\r | |
219 | //\r | |
220 | // free the command line package\r | |
221 | //\r | |
222 | ShellCommandLineFreeVarList (Package);\r | |
223 | \r | |
224 | //\r | |
225 | // return the status\r | |
226 | //\r | |
227 | return (ShellStatus);\r | |
228 | }\r | |
229 | \r |