TianoCore EDK2 master
Loading...
Searching...
No Matches
Mode.c
Go to the documentation of this file.
1
11
19EFIAPI
21 IN EFI_HANDLE ImageHandle,
22 IN EFI_SYSTEM_TABLE *SystemTable
23 )
24{
25 EFI_STATUS Status;
26 LIST_ENTRY *Package;
27 CHAR16 *ProblemParam;
28 SHELL_STATUS ShellStatus;
29 UINTN NewCol;
30 UINTN NewRow;
31 UINTN Col;
32 UINTN Row;
33 CONST CHAR16 *Temp;
34 BOOLEAN Done;
35 INT32 LoopVar;
36
37 ShellStatus = SHELL_SUCCESS;
38 Status = EFI_SUCCESS;
39
40 //
41 // initialize the shell lib (we must be in non-auto-init...)
42 //
43 Status = ShellInitialize ();
44 ASSERT_EFI_ERROR (Status);
45
46 Status = CommandInit ();
47 ASSERT_EFI_ERROR (Status);
48
49 //
50 // parse the command line
51 //
52 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
53 if (EFI_ERROR (Status)) {
54 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
55 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"mode", ProblemParam);
56 FreePool (ProblemParam);
57 ShellStatus = SHELL_INVALID_PARAMETER;
58 } else {
59 ASSERT (FALSE);
60 }
61 } else {
62 if (ShellCommandLineGetCount (Package) > 3) {
63 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"mode");
64 ShellStatus = SHELL_INVALID_PARAMETER;
65 } else if (ShellCommandLineGetCount (Package) == 2) {
66 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"mode");
67 ShellStatus = SHELL_INVALID_PARAMETER;
68 } else if (ShellCommandLineGetCount (Package) == 3) {
69 Temp = ShellCommandLineGetRawValue (Package, 1);
70 if (Temp == NULL) {
71 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
72 ShellStatus = SHELL_INVALID_PARAMETER;
73 } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
74 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
75 ShellStatus = SHELL_INVALID_PARAMETER;
76 }
77
78 NewCol = ShellStrToUintn (Temp);
79 Temp = ShellCommandLineGetRawValue (Package, 2);
80 if (Temp == NULL) {
81 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
82 ShellStatus = SHELL_INVALID_PARAMETER;
83 } else if (!ShellIsHexOrDecimalNumber (Temp, FALSE, FALSE)) {
84 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"mode", Temp);
85 ShellStatus = SHELL_INVALID_PARAMETER;
86 }
87
88 NewRow = ShellStrToUintn (Temp);
89
90 for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) {
91 Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row);
92 if (EFI_ERROR (Status)) {
93 continue;
94 }
95
96 if ((Col == NewCol) && (Row == NewRow)) {
97 Status = gST->ConOut->SetMode (gST->ConOut, LoopVar);
98 if (EFI_ERROR (Status)) {
99 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_SET_FAIL), gShellDebug1HiiHandle, L"mode");
100 ShellStatus = SHELL_DEVICE_ERROR;
101 } else {
102 // worked fine...
103 Done = TRUE;
104 }
105
106 break;
107 }
108 }
109
110 if (!Done) {
111 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_NO_MATCH), gShellDebug1HiiHandle, L"mode");
112 ShellStatus = SHELL_INVALID_PARAMETER;
113 }
114 } else if (ShellCommandLineGetCount (Package) == 1) {
115 //
116 // print out valid
117 //
118 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_HEAD), gShellDebug1HiiHandle);
119 for (LoopVar = 0, Done = FALSE; LoopVar < gST->ConOut->Mode->MaxMode && ShellStatus == SHELL_SUCCESS; LoopVar++) {
120 Status = gST->ConOut->QueryMode (gST->ConOut, LoopVar, &Col, &Row);
121 if (EFI_ERROR (Status)) {
122 continue;
123 }
124
125 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MODE_LIST_ITEM), gShellDebug1HiiHandle, Col, Row, LoopVar == gST->ConOut->Mode->Mode ? L'*' : L' ');
126 }
127 }
128
130 }
131
132 return (ShellStatus);
133}
UINT64 UINTN
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_DEVICE_ERROR
Definition: Shell.h:63
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
SHELL_STATUS EFIAPI ShellCommandRunMode(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Mode.c:20
EFI_STATUS EFIAPI CommandInit(VOID)
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellIsHexOrDecimalNumber(IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
#define STRING_TOKEN(t)
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064