1 /** @file
2 Main file for Echo shell level 3 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "UefiShellLevel3CommandsLib.h"
11
12 #include <Library/ShellLib.h>
13
14 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
15 {L"-on", TypeFlag},
16 {L"-off", TypeFlag},
17 {NULL, TypeMax}
18 };
19
20 /**
21 Function for 'echo' command.
22
23 @param[in] ImageHandle Handle to the Image (NULL if Internal).
24 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
25 **/
26 SHELL_STATUS
27 EFIAPI
ShellCommandRunEcho(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)28 ShellCommandRunEcho (
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 if (ShellCommandLineGetFlag(Package, L"-on")) {
72 //
73 // Turn it on
74 //
75 ShellCommandSetEchoState(TRUE);
76 } else if (ShellCommandLineGetFlag(Package, L"-off")) {
77 //
78 // turn it off
79 //
80 ShellCommandSetEchoState(FALSE);
81 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
82 //
83 // output its current state
84 //
85 if (ShellCommandGetEchoState()) {
86 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);
87 } else {
88 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);
89 }
90 } else {
91 //
92 // print the line
93 //
94 for ( ParamCount = 1
95 ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
96 ; ParamCount++
97 ) {
98 StrnCatGrow(&PrintString, &Size, ShellCommandLineGetRawValue(Package, ParamCount), 0);
99 if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {
100 StrnCatGrow(&PrintString, &Size, L" ", 0);
101 }
102 }
103 ShellPrintEx(-1, -1, L"%s\r\n", PrintString);
104 SHELL_FREE_NON_NULL(PrintString);
105 }
106
107 //
108 // free the command line package
109 //
110 ShellCommandLineFreeVarList (Package);
111 }
112
113 return (ShellStatus);
114 }
115
116