]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Cls.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Cls.c
1 /** @file
2 Main file for attrib shell level 2 function.
3
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiShellLevel3CommandsLib.h"
16
17 /**
18 Function for 'cls' command.
19
20 @param[in] ImageHandle Handle to the Image (NULL if Internal).
21 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
22 **/
23 SHELL_STATUS
24 EFIAPI
25 ShellCommandRunCls (
26 IN EFI_HANDLE ImageHandle,
27 IN EFI_SYSTEM_TABLE *SystemTable
28 )
29 {
30 EFI_STATUS Status;
31 LIST_ENTRY *Package;
32 CHAR16 *Message;
33 UINTN Background;
34 UINTN ForeColor;
35 CHAR16 *ProblemParam;
36 SHELL_STATUS ShellStatus;
37 CONST CHAR16 *Param1;
38
39 ShellStatus = SHELL_SUCCESS;
40 ProblemParam = NULL;
41 Background = 0;
42
43 //
44 // Initialize variables
45 //
46 Message = NULL;
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 (EmptyParamList, &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, 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 {
73 //
74 // If there are 0 value parameters, clear sceen
75 //
76 Param1 = ShellCommandLineGetRawValue(Package, 1);
77 if (Param1 == NULL) {
78 //
79 // clear screen
80 //
81 gST->ConOut->ClearScreen (gST->ConOut);
82 } else if (ShellCommandLineGetCount(Package) > 2) {
83 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);
84 ShellStatus = SHELL_INVALID_PARAMETER;
85 } else {
86 if (StrDecimalToUintn(Param1) > 7 || StrLen(Param1) > 1 || !ShellIsDecimalDigitCharacter(*Param1)) {
87 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, Param1);
88 ShellStatus = SHELL_INVALID_PARAMETER;
89 } else {
90 switch (StrDecimalToUintn(Param1)) {
91 case 0:
92 Background = EFI_BACKGROUND_BLACK;
93 break;
94 case 1:
95 Background = EFI_BACKGROUND_BLUE;
96 break;
97 case 2:
98 Background = EFI_BACKGROUND_GREEN;
99 break;
100 case 3:
101 Background = EFI_BACKGROUND_CYAN;
102 break;
103 case 4:
104 Background = EFI_BACKGROUND_RED;
105 break;
106 case 5:
107 Background = EFI_BACKGROUND_MAGENTA;
108 break;
109 case 6:
110 Background = EFI_BACKGROUND_BROWN;
111 break;
112 case 7:
113 Background = EFI_BACKGROUND_LIGHTGRAY;
114 break;
115 }
116 ForeColor = (~StrDecimalToUintn(Param1)) & 0xF;
117 Status = gST->ConOut->SetAttribute (gST->ConOut, ForeColor | Background);
118 ASSERT_EFI_ERROR(Status);
119 Status = gST->ConOut->ClearScreen (gST->ConOut);
120 ASSERT_EFI_ERROR(Status);
121 }
122 }
123 }
124 }
125 //
126 // free the command line package
127 //
128 ShellCommandLineFreeVarList (Package);
129
130 //
131 // return the status
132 //
133 return (ShellStatus);
134 }
135