]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Echo.c
1 /** @file
2 Main file for Echo shell level 3 function.
3
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiShellLevel3CommandsLib.h"
16
17 #include <Library/ShellLib.h>
18
19 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
20 {L"-on", TypeFlag},
21 {L"-off", TypeFlag},
22 {NULL, TypeMax}
23 };
24
25 /**
26 Function for 'echo' command.
27
28 @param[in] ImageHandle Handle to the Image (NULL if Internal).
29 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
30 **/
31 SHELL_STATUS
32 EFIAPI
33 ShellCommandRunEcho (
34 IN EFI_HANDLE ImageHandle,
35 IN EFI_SYSTEM_TABLE *SystemTable
36 )
37 {
38 EFI_STATUS Status;
39 LIST_ENTRY *Package;
40 // CHAR16 *ProblemParam;
41 SHELL_STATUS ShellStatus;
42 UINTN ParamCount;
43
44 // ProblemParam = NULL;
45 ShellStatus = SHELL_SUCCESS;
46
47 //
48 // initialize the shell lib (we must be in non-auto-init...)
49 //
50 Status = ShellInitialize();
51 ASSERT_EFI_ERROR(Status);
52
53 //
54 // parse the command line
55 //
56 Status = ShellCommandLineParseEx (ParamList, &Package, NULL, TRUE, TRUE);
57 // if (EFI_ERROR(Status)) {
58 // if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
59 // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
60 // FreePool(ProblemParam);
61 // ShellStatus = SHELL_INVALID_PARAMETER;
62 // } else {
63 // ASSERT(FALSE);
64 // }
65 // } else {
66 //
67 // check for "-?"
68 //
69 if (ShellCommandLineGetFlag(Package, L"-?")) {
70 ASSERT(FALSE);
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 if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {
100 ShellPrintEx(-1, -1, L"%s ", ShellCommandLineGetRawValue(Package, ParamCount));
101 } else {
102 ShellPrintEx(-1, -1, L"%s", ShellCommandLineGetRawValue(Package, ParamCount));
103 }
104 }
105 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CRLF), gShellLevel3HiiHandle);
106 }
107
108 //
109 // free the command line package
110 //
111 ShellCommandLineFreeVarList (Package);
112 // }
113
114 return (ShellStatus);
115 }
116