1 | /** @file
|
---|
2 | Main file for Echo shell level 3 function.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2012, 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 | SHELL_STATUS ShellStatus;
|
---|
41 | UINTN ParamCount;
|
---|
42 | CHAR16 *ProblemParam;
|
---|
43 | UINTN Size;
|
---|
44 | CHAR16 *PrintString;
|
---|
45 |
|
---|
46 | Size = 0;
|
---|
47 | ProblemParam = NULL;
|
---|
48 | PrintString = NULL;
|
---|
49 | ShellStatus = SHELL_SUCCESS;
|
---|
50 |
|
---|
51 | //
|
---|
52 | // initialize the shell lib (we must be in non-auto-init...)
|
---|
53 | //
|
---|
54 | Status = ShellInitialize();
|
---|
55 | ASSERT_EFI_ERROR(Status);
|
---|
56 |
|
---|
57 | //
|
---|
58 | // parse the command line
|
---|
59 | //
|
---|
60 | Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, TRUE);
|
---|
61 | if (EFI_ERROR(Status)) {
|
---|
62 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
---|
63 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);
|
---|
64 | FreePool(ProblemParam);
|
---|
65 | ShellStatus = SHELL_INVALID_PARAMETER;
|
---|
66 | } else {
|
---|
67 | ASSERT(FALSE);
|
---|
68 | }
|
---|
69 | } else {
|
---|
70 | //
|
---|
71 | // check for "-?"
|
---|
72 | //
|
---|
73 | if (ShellCommandLineGetFlag(Package, L"-?")) {
|
---|
74 | ASSERT(FALSE);
|
---|
75 | }
|
---|
76 | if (ShellCommandLineGetFlag(Package, L"-on")) {
|
---|
77 | //
|
---|
78 | // Turn it on
|
---|
79 | //
|
---|
80 | ShellCommandSetEchoState(TRUE);
|
---|
81 | } else if (ShellCommandLineGetFlag(Package, L"-off")) {
|
---|
82 | //
|
---|
83 | // turn it off
|
---|
84 | //
|
---|
85 | ShellCommandSetEchoState(FALSE);
|
---|
86 | } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
|
---|
87 | //
|
---|
88 | // output its current state
|
---|
89 | //
|
---|
90 | if (ShellCommandGetEchoState()) {
|
---|
91 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);
|
---|
92 | } else {
|
---|
93 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);
|
---|
94 | }
|
---|
95 | } else {
|
---|
96 | //
|
---|
97 | // print the line
|
---|
98 | //
|
---|
99 | for ( ParamCount = 1
|
---|
100 | ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
|
---|
101 | ; ParamCount++
|
---|
102 | ) {
|
---|
103 | StrnCatGrow(&PrintString, &Size, ShellCommandLineGetRawValue(Package, ParamCount), 0);
|
---|
104 | if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {
|
---|
105 | StrnCatGrow(&PrintString, &Size, L" ", 0);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | ShellPrintEx(-1, -1, L"%s\r\n", PrintString);
|
---|
109 | SHELL_FREE_NON_NULL(PrintString);
|
---|
110 | }
|
---|
111 |
|
---|
112 | //
|
---|
113 | // free the command line package
|
---|
114 | //
|
---|
115 | ShellCommandLineFreeVarList (Package);
|
---|
116 | }
|
---|
117 |
|
---|
118 | return (ShellStatus);
|
---|
119 | }
|
---|
120 |
|
---|