2 Main file for Echo shell level 3 function.
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
10 #include "UefiShellLevel3CommandsLib.h"
12 #include <Library/ShellLib.h>
14 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
21 Function for 'echo' command.
23 @param[in] ImageHandle Handle to the Image (NULL if Internal).
24 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
29 IN EFI_HANDLE ImageHandle
,
30 IN EFI_SYSTEM_TABLE
*SystemTable
35 SHELL_STATUS ShellStatus
;
44 ShellStatus
= SHELL_SUCCESS
;
47 // initialize the shell lib (we must be in non-auto-init...)
49 Status
= ShellInitialize();
50 ASSERT_EFI_ERROR(Status
);
53 // parse the command line
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
;
68 if (ShellCommandLineGetFlag(Package
, L
"-?")) {
71 if (ShellCommandLineGetFlag(Package
, L
"-on")) {
75 ShellCommandSetEchoState(TRUE
);
76 } else if (ShellCommandLineGetFlag(Package
, L
"-off")) {
80 ShellCommandSetEchoState(FALSE
);
81 } else if (ShellCommandLineGetRawValue(Package
, 1) == NULL
) {
83 // output its current state
85 if (ShellCommandGetEchoState()) {
86 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_ECHO_ON
), gShellLevel3HiiHandle
);
88 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_ECHO_OFF
), gShellLevel3HiiHandle
);
95 ; ShellCommandLineGetRawValue(Package
, ParamCount
) != NULL
98 StrnCatGrow(&PrintString
, &Size
, ShellCommandLineGetRawValue(Package
, ParamCount
), 0);
99 if (ShellCommandLineGetRawValue(Package
, ParamCount
+1) != NULL
) {
100 StrnCatGrow(&PrintString
, &Size
, L
" ", 0);
103 ShellPrintEx(-1, -1, L
"%s\r\n", PrintString
);
104 SHELL_FREE_NON_NULL(PrintString
);
108 // free the command line package
110 ShellCommandLineFreeVarList (Package
);
113 return (ShellStatus
);