]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
ShellPkg: Fix echo to support displaying special characters
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Echo.c
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 - 2016, Intel Corporation. All rights reserved. <BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "UefiShellLevel3CommandsLib.h"
17
18 #include <Library/ShellLib.h>
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
28 ShellCommandRunEcho (
29 IN EFI_HANDLE ImageHandle,
30 IN EFI_SYSTEM_TABLE *SystemTable
31 )
32 {
33 CHAR16 *RawCmdLine;
34 SHELL_STATUS Status;
35 UINTN Size;
36 CHAR16 *Walker;
37 CHAR16 *TempParameter;
38 BOOLEAN OnFlag;
39 BOOLEAN OffFlag;
40 UINTN Count;
41
42 RawCmdLine = ShellGetRawCmdLine ();
43 if (RawCmdLine == NULL) {
44 return SHELL_OUT_OF_RESOURCES;
45 }
46
47 OnFlag = FALSE;
48 OffFlag = FALSE;
49
50 Size = StrSize (RawCmdLine);
51 TempParameter = AllocateZeroPool(Size);
52 if (TempParameter == NULL) {
53 Status = SHELL_OUT_OF_RESOURCES;
54 goto Done;
55 }
56
57 for ( Count = 0
58 , Walker = RawCmdLine
59 ; Walker != NULL && *Walker != CHAR_NULL
60 ; Count++
61 ) {
62 if (EFI_ERROR (ShellGetNextParameter (&Walker, TempParameter, Size, FALSE))) {
63 break;
64 }
65
66 if (Count == 1) {
67 if (gUnicodeCollation->StriColl(gUnicodeCollation, TempParameter, L"-on") == 0 ) {
68 OnFlag = TRUE;
69 }
70 if (gUnicodeCollation->StriColl(gUnicodeCollation, TempParameter, L"-off") == 0 ) {
71 OffFlag = TRUE;
72 }
73 }
74 }
75
76 if (OnFlag || OffFlag) {
77 if (Count != 2) {
78 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_INVALID_PARAM), gShellLevel3HiiHandle, L"echo", L"-on/-off");
79 Status = SHELL_INVALID_PARAMETER;
80 goto Done;
81 }
82
83 ShellCommandSetEchoState(OnFlag);
84 Status = SHELL_SUCCESS;
85 goto Done;
86 }
87
88 Walker = RawCmdLine + StrLen (L"echo");
89 if (*Walker != CHAR_NULL) {
90 Walker++;
91 ShellPrintEx (-1, -1, L"%s\r\n", Walker);
92 }
93
94 Status = SHELL_SUCCESS;
95
96 Done:
97 SHELL_FREE_NON_NULL (TempParameter);
98 SHELL_FREE_NON_NULL (RawCmdLine);
99 return Status;
100
101 }
102