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