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 - 2012, 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 STATIC CONST SHELL_PARAM_ITEM ParamList[] = { 21 {L"-on", TypeFlag}, 22 {L"-off", TypeFlag}, 23 {NULL, TypeMax} 24 }; 25 26 /** 27 Function for 'echo' command. 28 29 @param[in] ImageHandle Handle to the Image (NULL if Internal). 30 @param[in] SystemTable Pointer to the System Table (NULL if Internal). 31 **/ 32 SHELL_STATUS 33 EFIAPI 34 ShellCommandRunEcho ( 35 IN EFI_HANDLE ImageHandle, 36 IN EFI_SYSTEM_TABLE *SystemTable 37 ) 38 { 39 EFI_STATUS Status; 40 LIST_ENTRY *Package; 41 SHELL_STATUS ShellStatus; 42 UINTN ParamCount; 43 CHAR16 *ProblemParam; 44 UINTN Size; 45 CHAR16 *PrintString; 46 47 Size = 0; 48 ProblemParam = NULL; 49 PrintString = NULL; 50 ShellStatus = SHELL_SUCCESS; 51 52 // 53 // initialize the shell lib (we must be in non-auto-init...) 54 // 55 Status = ShellInitialize(); 56 ASSERT_EFI_ERROR(Status); 57 58 // 59 // parse the command line 60 // 61 Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, TRUE); 62 if (EFI_ERROR(Status)) { 63 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { 64 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"echo", ProblemParam); 65 FreePool(ProblemParam); 66 ShellStatus = SHELL_INVALID_PARAMETER; 67 } else { 68 ASSERT(FALSE); 69 } 70 } else { 71 // 72 // check for "-?" 73 // 74 if (ShellCommandLineGetFlag(Package, L"-?")) { 75 ASSERT(FALSE); 76 } 77 if (ShellCommandLineGetFlag(Package, L"-on")) { 78 // 79 // Turn it on 80 // 81 ShellCommandSetEchoState(TRUE); 82 } else if (ShellCommandLineGetFlag(Package, L"-off")) { 83 // 84 // turn it off 85 // 86 ShellCommandSetEchoState(FALSE); 87 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) { 88 // 89 // output its current state 90 // 91 if (ShellCommandGetEchoState()) { 92 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle); 93 } else { 94 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle); 95 } 96 } else { 97 // 98 // print the line 99 // 100 for ( ParamCount = 1 101 ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL 102 ; ParamCount++ 103 ) { 104 StrnCatGrow(&PrintString, &Size, ShellCommandLineGetRawValue(Package, ParamCount), 0); 105 if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) { 106 StrnCatGrow(&PrintString, &Size, L" ", 0); 107 } 108 } 109 ShellPrintEx(-1, -1, L"%s\r\n", PrintString); 110 SHELL_FREE_NON_NULL(PrintString); 111 } 112 113 // 114 // free the command line package 115 // 116 ShellCommandLineFreeVarList (Package); 117 } 118 119 return (ShellStatus); 120 } 121 122