TianoCore EDK2 master
Loading...
Searching...
No Matches
Echo.c
Go to the documentation of this file.
1
11
12#include <Library/ShellLib.h>
13
14STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
15 { L"-on", TypeFlag },
16 { L"-off", TypeFlag },
17 { NULL, TypeMax }
18};
19
27EFIAPI
29 IN EFI_HANDLE ImageHandle,
30 IN EFI_SYSTEM_TABLE *SystemTable
31 )
32{
33 EFI_STATUS Status;
34 LIST_ENTRY *Package;
35 SHELL_STATUS ShellStatus;
36 UINTN ParamCount;
37 CHAR16 *ProblemParam;
38 UINTN Size;
39 CHAR16 *PrintString;
40
41 Size = 0;
42 ProblemParam = NULL;
43 PrintString = NULL;
44 ShellStatus = SHELL_SUCCESS;
45
46 //
47 // initialize the shell lib (we must be in non-auto-init...)
48 //
49 Status = ShellInitialize ();
50 ASSERT_EFI_ERROR (Status);
51
52 //
53 // parse the command line
54 //
55 Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, TRUE);
56 if (EFI_ERROR (Status)) {
57 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
58 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"echo", ProblemParam);
59 FreePool (ProblemParam);
60 ShellStatus = SHELL_INVALID_PARAMETER;
61 } else {
62 ASSERT (FALSE);
63 }
64 } else {
65 //
66 // check for "-?"
67 //
68 if (ShellCommandLineGetFlag (Package, L"-?")) {
69 ASSERT (FALSE);
70 }
71
72 if (ShellCommandLineGetFlag (Package, L"-on")) {
73 //
74 // Turn it on
75 //
77 } else if (ShellCommandLineGetFlag (Package, L"-off")) {
78 //
79 // turn it off
80 //
82 } else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
83 //
84 // output its current state
85 //
87 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);
88 } else {
89 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);
90 }
91 } else {
92 //
93 // print the line
94 //
95 for ( ParamCount = 1
96 ; ShellCommandLineGetRawValue (Package, ParamCount) != NULL
97 ; ParamCount++
98 )
99 {
100 StrnCatGrow (&PrintString, &Size, ShellCommandLineGetRawValue (Package, ParamCount), 0);
101 if (ShellCommandLineGetRawValue (Package, ParamCount+1) != NULL) {
102 StrnCatGrow (&PrintString, &Size, L" ", 0);
103 }
104 }
105
106 ShellPrintEx (-1, -1, L"%s\r\n", PrintString);
107 SHELL_FREE_NON_NULL (PrintString);
108 }
109
110 //
111 // free the command line package
112 //
114 }
115
116 return (ShellStatus);
117}
UINT64 UINTN
SHELL_STATUS EFIAPI ShellCommandRunEcho(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Echo.c:28
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#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_INVALID_PARAMETER
Definition: Shell.h:35
BOOLEAN EFIAPI ShellCommandGetEchoState(VOID)
VOID EFIAPI ShellCommandSetEchoState(IN BOOLEAN State)
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 ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellCommandLineParseEx(IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, OUT CHAR16 **ProblemParam OPTIONAL, IN BOOLEAN AutoPageBreak, IN BOOLEAN AlwaysAllowNumbers)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define STRING_TOKEN(t)