]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ShellParametersProtocol.h
ShellPkg: Refactor string manipulation
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellParametersProtocol.h
CommitLineData
a405b86d 1/** @file\r
2 Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation,\r
3 manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL.\r
4\r
4ccd9214 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#ifndef _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
17#define _SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
18\r
a405b86d 19#include "Shell.h"\r
20\r
21/**\r
22 creates a new EFI_SHELL_PARAMETERS_PROTOCOL instance and populates it and then\r
23 installs it on our handle and if there is an existing version of the protocol\r
24 that one is cached for removal later.\r
25\r
4ff7e37b 26 @param[in, out] NewShellParameters on a successful return, a pointer to pointer\r
a405b86d 27 to the newly installed interface.\r
4ff7e37b 28 @param[in, out] RootShellInstance on a successful return, pointer to boolean.\r
a405b86d 29 TRUE if this is the root shell instance.\r
30\r
31 @retval EFI_SUCCESS the operation completed successfully.\r
32 @return other the operation failed.\r
33 @sa ReinstallProtocolInterface\r
34 @sa InstallProtocolInterface\r
35 @sa ParseCommandLineToArgs\r
36**/\r
37EFI_STATUS\r
38EFIAPI\r
39CreatePopulateInstallShellParametersProtocol (\r
40 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL **NewShellParameters,\r
41 IN OUT BOOLEAN *RootShellInstance\r
42 );\r
43\r
44/**\r
45 frees all memory used by createion and installation of shell parameters protocol\r
46 and if there was an old version installed it will restore that one.\r
47\r
48 @param NewShellParameters the interface of EFI_SHELL_PARAMETERS_PROTOCOL that is\r
49 being cleaned up.\r
50\r
51 @retval EFI_SUCCESS the cleanup was successful\r
52 @return other the cleanup failed\r
53 @sa ReinstallProtocolInterface\r
54 @sa UninstallProtocolInterface\r
55**/\r
56EFI_STATUS\r
57EFIAPI\r
58CleanUpShellParametersProtocol (\r
59 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *NewShellParameters\r
60 );\r
61\r
62/**\r
63 Funcion will replace the current Argc and Argv in the ShellParameters protocol\r
64 structure by parsing NewCommandLine. The current values are returned to the\r
65 user.\r
66\r
4ff7e37b 67 @param[in, out] ShellParameters pointer to parameter structure to modify\r
a405b86d 68 @param[in] NewCommandLine the new command line to parse and use\r
69 @param[out] OldArgv pointer to old list of parameters\r
70 @param[out] OldArgc pointer to old number of items in Argv list\r
71\r
72 @retval EFI_SUCCESS operation was sucessful, Argv and Argc are valid\r
73 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
74**/\r
75EFI_STATUS\r
76EFIAPI\r
77UpdateArgcArgv(\r
78 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
79 IN CONST CHAR16 *NewCommandLine,\r
80 OUT CHAR16 ***OldArgv,\r
81 OUT UINTN *OldArgc\r
82 );\r
83\r
84/**\r
85 Funcion will replace the current Argc and Argv in the ShellParameters protocol\r
86 structure with Argv and Argc. The current values are de-allocated and the\r
87 OldArgv must not be deallocated by the caller.\r
88\r
4ff7e37b
ED
89 @param[in, out] ShellParameters pointer to parameter structure to modify\r
90 @param[in] OldArgv pointer to old list of parameters\r
91 @param[in] OldArgc pointer to old number of items in Argv list\r
a405b86d 92**/\r
93VOID\r
94EFIAPI\r
95RestoreArgcArgv(\r
96 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
97 IN CHAR16 ***OldArgv,\r
98 IN UINTN *OldArgc\r
99 );\r
100\r
8be0ba36 101typedef struct {\r
102 EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;\r
103 EFI_HANDLE ConInHandle;\r
104 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;\r
105 EFI_HANDLE ConOutHandle;\r
4ccd9214
ED
106 EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ErrOut;\r
107 EFI_HANDLE ErrOutHandle;\r
8be0ba36 108} SYSTEM_TABLE_INFO;\r
109\r
a405b86d 110/**\r
111 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
112 structure by parsing NewCommandLine. The current values are returned to the\r
113 user.\r
114\r
fb84495a 115 This will also update the system table.\r
a405b86d 116\r
4ff7e37b
ED
117 @param[in, out] ShellParameters Pointer to parameter structure to modify.\r
118 @param[in] NewCommandLine The new command line to parse and use.\r
119 @param[out] OldStdIn Pointer to old StdIn.\r
120 @param[out] OldStdOut Pointer to old StdOut.\r
121 @param[out] OldStdErr Pointer to old StdErr.\r
122 @param[out] SystemTableInfo Pointer to old system table information.\r
a405b86d 123\r
124 @retval EFI_SUCCESS Operation was sucessful, Argv and Argc are valid.\r
125 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
126**/\r
127EFI_STATUS\r
128EFIAPI\r
129UpdateStdInStdOutStdErr(\r
130 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
fb84495a 131 IN CHAR16 *NewCommandLine,\r
8be0ba36 132 OUT SHELL_FILE_HANDLE *OldStdIn,\r
133 OUT SHELL_FILE_HANDLE *OldStdOut,\r
134 OUT SHELL_FILE_HANDLE *OldStdErr,\r
135 OUT SYSTEM_TABLE_INFO *SystemTableInfo\r
a405b86d 136 );\r
137\r
138/**\r
139 Funcion will replace the current StdIn and StdOut in the ShellParameters protocol\r
140 structure with StdIn and StdOut. The current values are de-allocated.\r
141\r
4ff7e37b
ED
142 @param[in, out] ShellParameters Pointer to parameter structure to modify.\r
143 @param[in] OldStdIn Pointer to old StdIn.\r
144 @param[in] OldStdOut Pointer to old StdOut.\r
145 @param[in] OldStdErr Pointer to old StdErr.\r
146 @param[in] SystemTableInfo Pointer to old system table information.\r
a405b86d 147**/\r
148EFI_STATUS\r
149EFIAPI\r
150RestoreStdInStdOutStdErr (\r
151 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters,\r
8be0ba36 152 IN SHELL_FILE_HANDLE *OldStdIn,\r
153 IN SHELL_FILE_HANDLE *OldStdOut,\r
154 IN SHELL_FILE_HANDLE *OldStdErr,\r
155 IN SYSTEM_TABLE_INFO *SystemTableInfo\r
a405b86d 156 );\r
157\r
158/**\r
159 function to populate Argc and Argv.\r
160\r
161 This function parses the CommandLine and divides it into standard C style Argc/Argv\r
162 parameters for inclusion in EFI_SHELL_PARAMETERS_PROTOCOL. this supports space\r
163 delimited and quote surrounded parameter definition.\r
164\r
4ff7e37b
ED
165 @param[in] CommandLine String of command line to parse\r
166 @param[in, out] Argv pointer to array of strings; one for each parameter\r
167 @param[in, out] Argc pointer to number of strings in Argv array\r
a405b86d 168\r
169 @return EFI_SUCCESS the operation was sucessful\r
170 @return EFI_OUT_OF_RESOURCES a memory allocation failed.\r
171**/\r
172EFI_STATUS\r
173EFIAPI\r
174ParseCommandLineToArgs(\r
175 IN CONST CHAR16 *CommandLine,\r
176 IN OUT CHAR16 ***Argv,\r
177 IN OUT UINTN *Argc\r
178 );\r
179\r
180/**\r
181 return the next parameter from a command line string;\r
182\r
183 This function moves the next parameter from Walker into TempParameter and moves\r
184 Walker up past that parameter for recursive calling. When the final parameter\r
185 is moved *Walker will be set to NULL;\r
186\r
187 Temp Parameter must be large enough to hold the parameter before calling this\r
188 function.\r
189\r
4ff7e37b 190 @param[in, out] Walker pointer to string of command line. Adjusted to\r
a405b86d 191 reminaing command line on return\r
4ff7e37b 192 @param[in, out] TempParameter pointer to string of command line item extracted.\r
7f79b01e 193 @param[in] Length Length of (*TempParameter) in bytes\r
a405b86d 194\r
195**/\r
196VOID\r
197EFIAPI\r
198GetNextParameter(\r
7f79b01e
JC
199 IN OUT CHAR16 **Walker,\r
200 IN OUT CHAR16 **TempParameter,\r
201 IN CONST UINTN Length\r
a405b86d 202 );\r
203\r
204#endif //_SHELL_PARAMETERS_PROTOCOL_PROVIDER_HEADER_\r
205\r