]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
EmulatorPkg: Remove framework pkgs dependency from EmulatorPkg
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Echo.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for Echo shell level 3 function.\r
3\r
c011b6c9 4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
ba0014b9 5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved. <BR>\r
56ba3746 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a405b86d 7\r
8**/\r
9\r
10#include "UefiShellLevel3CommandsLib.h"\r
11\r
12#include <Library/ShellLib.h>\r
13\r
8e16ac3d
RN
14STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
15 {L"-on", TypeFlag},\r
16 {L"-off", TypeFlag},\r
17 {NULL, TypeMax}\r
18 };\r
19\r
a405b86d 20/**\r
21 Function for 'echo' command.\r
22\r
23 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
24 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
25**/\r
26SHELL_STATUS\r
27EFIAPI\r
28ShellCommandRunEcho (\r
29 IN EFI_HANDLE ImageHandle,\r
30 IN EFI_SYSTEM_TABLE *SystemTable\r
31 )\r
32{\r
8e16ac3d
RN
33 EFI_STATUS Status;\r
34 LIST_ENTRY *Package;\r
35 SHELL_STATUS ShellStatus;\r
36 UINTN ParamCount;\r
37 CHAR16 *ProblemParam;\r
eefe286b 38 UINTN Size;\r
8e16ac3d
RN
39 CHAR16 *PrintString;\r
40\r
41 Size = 0;\r
42 ProblemParam = NULL;\r
43 PrintString = NULL;\r
44 ShellStatus = SHELL_SUCCESS;\r
45\r
46 //\r
47 // initialize the shell lib (we must be in non-auto-init...)\r
48 //\r
49 Status = ShellInitialize();\r
50 ASSERT_EFI_ERROR(Status);\r
51\r
52 //\r
53 // parse the command line\r
54 //\r
55 Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, TRUE);\r
56 if (EFI_ERROR(Status)) {\r
57 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
ba0014b9 58 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"echo", ProblemParam);\r
8e16ac3d
RN
59 FreePool(ProblemParam);\r
60 ShellStatus = SHELL_INVALID_PARAMETER;\r
61 } else {\r
62 ASSERT(FALSE);\r
a405b86d 63 }\r
8e16ac3d
RN
64 } else {\r
65 //\r
66 // check for "-?"\r
67 //\r
68 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
69 ASSERT(FALSE);\r
70 }\r
71 if (ShellCommandLineGetFlag(Package, L"-on")) {\r
72 //\r
73 // Turn it on\r
74 //\r
75 ShellCommandSetEchoState(TRUE);\r
76 } else if (ShellCommandLineGetFlag(Package, L"-off")) {\r
77 //\r
78 // turn it off\r
79 //\r
80 ShellCommandSetEchoState(FALSE);\r
81 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
82 //\r
83 // output its current state\r
84 //\r
85 if (ShellCommandGetEchoState()) {\r
86 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);\r
87 } else {\r
88 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);\r
a405b86d 89 }\r
8e16ac3d
RN
90 } else {\r
91 //\r
92 // print the line\r
93 //\r
94 for ( ParamCount = 1\r
95 ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL\r
96 ; ParamCount++\r
97 ) {\r
98 StrnCatGrow(&PrintString, &Size, ShellCommandLineGetRawValue(Package, ParamCount), 0);\r
99 if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {\r
100 StrnCatGrow(&PrintString, &Size, L" ", 0);\r
ba0014b9 101 }\r
a405b86d 102 }\r
8e16ac3d
RN
103 ShellPrintEx(-1, -1, L"%s\r\n", PrintString);\r
104 SHELL_FREE_NON_NULL(PrintString);\r
a405b86d 105 }\r
106\r
8e16ac3d
RN
107 //\r
108 // free the command line package\r
109 //\r
110 ShellCommandLineFreeVarList (Package);\r
345cd235 111 }\r
a405b86d 112\r
8e16ac3d 113 return (ShellStatus);\r
a405b86d 114}\r
115\r