]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLevel3CommandsLib/Echo.c
ShellPkg/Dp: Add null pointer check
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel3CommandsLib / Echo.c
CommitLineData
a405b86d 1/** @file\r
2 Main file for Echo shell level 3 function.\r
3\r
c011b6c9 4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
8e16ac3d 5 Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved. <BR>\r
a405b86d 6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "UefiShellLevel3CommandsLib.h"\r
17\r
18#include <Library/ShellLib.h>\r
19\r
8e16ac3d
RN
20STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
21 {L"-on", TypeFlag},\r
22 {L"-off", TypeFlag},\r
23 {NULL, TypeMax}\r
24 };\r
25\r
a405b86d 26/**\r
27 Function for 'echo' command.\r
28\r
29 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
30 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
31**/\r
32SHELL_STATUS\r
33EFIAPI\r
34ShellCommandRunEcho (\r
35 IN EFI_HANDLE ImageHandle,\r
36 IN EFI_SYSTEM_TABLE *SystemTable\r
37 )\r
38{\r
8e16ac3d
RN
39 EFI_STATUS Status;\r
40 LIST_ENTRY *Package;\r
41 SHELL_STATUS ShellStatus;\r
42 UINTN ParamCount;\r
43 CHAR16 *ProblemParam;\r
eefe286b 44 UINTN Size;\r
8e16ac3d
RN
45 CHAR16 *PrintString;\r
46\r
47 Size = 0;\r
48 ProblemParam = NULL;\r
49 PrintString = NULL;\r
50 ShellStatus = SHELL_SUCCESS;\r
51\r
52 //\r
53 // initialize the shell lib (we must be in non-auto-init...)\r
54 //\r
55 Status = ShellInitialize();\r
56 ASSERT_EFI_ERROR(Status);\r
57\r
58 //\r
59 // parse the command line\r
60 //\r
61 Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, TRUE);\r
62 if (EFI_ERROR(Status)) {\r
63 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
64 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"echo", ProblemParam); \r
65 FreePool(ProblemParam);\r
66 ShellStatus = SHELL_INVALID_PARAMETER;\r
67 } else {\r
68 ASSERT(FALSE);\r
a405b86d 69 }\r
8e16ac3d
RN
70 } else {\r
71 //\r
72 // check for "-?"\r
73 //\r
74 if (ShellCommandLineGetFlag(Package, L"-?")) {\r
75 ASSERT(FALSE);\r
76 }\r
77 if (ShellCommandLineGetFlag(Package, L"-on")) {\r
78 //\r
79 // Turn it on\r
80 //\r
81 ShellCommandSetEchoState(TRUE);\r
82 } else if (ShellCommandLineGetFlag(Package, L"-off")) {\r
83 //\r
84 // turn it off\r
85 //\r
86 ShellCommandSetEchoState(FALSE);\r
87 } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {\r
88 //\r
89 // output its current state\r
90 //\r
91 if (ShellCommandGetEchoState()) {\r
92 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_ON), gShellLevel3HiiHandle);\r
93 } else {\r
94 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_ECHO_OFF), gShellLevel3HiiHandle);\r
a405b86d 95 }\r
8e16ac3d
RN
96 } else {\r
97 //\r
98 // print the line\r
99 //\r
100 for ( ParamCount = 1\r
101 ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL\r
102 ; ParamCount++\r
103 ) {\r
104 StrnCatGrow(&PrintString, &Size, ShellCommandLineGetRawValue(Package, ParamCount), 0);\r
105 if (ShellCommandLineGetRawValue(Package, ParamCount+1) != NULL) {\r
106 StrnCatGrow(&PrintString, &Size, L" ", 0);\r
107 } \r
a405b86d 108 }\r
8e16ac3d
RN
109 ShellPrintEx(-1, -1, L"%s\r\n", PrintString);\r
110 SHELL_FREE_NON_NULL(PrintString);\r
a405b86d 111 }\r
112\r
8e16ac3d
RN
113 //\r
114 // free the command line package\r
115 //\r
116 ShellCommandLineFreeVarList (Package);\r
345cd235 117 }\r
a405b86d 118\r
8e16ac3d 119 return (ShellStatus);\r
a405b86d 120}\r
121\r