VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c

Last change on this file was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
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
14STATIC 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**/
26SHELL_STATUS
27EFIAPI
28ShellCommandRunEcho (
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 //
76 ShellCommandSetEchoState (TRUE);
77 } else if (ShellCommandLineGetFlag (Package, L"-off")) {
78 //
79 // turn it off
80 //
81 ShellCommandSetEchoState (FALSE);
82 } else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
83 //
84 // output its current state
85 //
86 if (ShellCommandGetEchoState ()) {
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 //
113 ShellCommandLineFreeVarList (Package);
114 }
115
116 return (ShellStatus);
117}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette