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