]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Main file for Help shell level 3 function.\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved. <BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "UefiShellLevel3CommandsLib.h"\r | |
16 | \r | |
17 | #include <Library/ShellLib.h>\r | |
18 | #include <Library/HandleParsingLib.h>\r | |
19 | \r | |
20 | #include <Protocol/EfiShellDynamicCommand.h>\r | |
21 | \r | |
22 | /**\r | |
23 | Attempt to print help from a dynamically added command.\r | |
24 | \r | |
25 | @param[in] CommandToGetHelpOn The unicode name of the command that help is requested on.\r | |
26 | \r | |
27 | @retval EFI_SUCCESS The help was displayed\r | |
28 | @retval FI_NOT_FOUND The command name could not be found\r | |
29 | **/\r | |
30 | STATIC\r | |
31 | EFI_STATUS\r | |
32 | EFIAPI\r | |
33 | PrintDynamicCommandHelp(\r | |
34 | IN CHAR16 *CommandToGetHelpOn\r | |
35 | )\r | |
36 | {\r | |
37 | EFI_STATUS Status;\r | |
38 | BOOLEAN Found;\r | |
39 | EFI_HANDLE *CommandHandleList;\r | |
40 | EFI_HANDLE *NextCommand;\r | |
41 | EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *DynamicCommand;\r | |
42 | CHAR16 *OutText;\r | |
43 | \r | |
44 | Found = FALSE;\r | |
45 | CommandHandleList = NULL;\r | |
46 | OutText = NULL;\r | |
47 | \r | |
48 | CommandHandleList = GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid);\r | |
49 | \r | |
50 | if (CommandHandleList == NULL) {\r | |
51 | //\r | |
52 | // not found or out of resources\r | |
53 | //\r | |
54 | return FALSE;\r | |
55 | }\r | |
56 | \r | |
57 | for (NextCommand = CommandHandleList; *NextCommand != NULL; NextCommand++) {\r | |
58 | Status = gBS->HandleProtocol(\r | |
59 | *NextCommand,\r | |
60 | &gEfiShellDynamicCommandProtocolGuid,\r | |
61 | (VOID **)&DynamicCommand\r | |
62 | );\r | |
63 | \r | |
64 | if (EFI_ERROR(Status)) {\r | |
65 | continue;\r | |
66 | }\r | |
67 | \r | |
68 | if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16 *)DynamicCommand->CommandName, CommandToGetHelpOn)) ||\r | |
69 | (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, (CHAR16 *)DynamicCommand->CommandName, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {\r | |
70 | //\r | |
71 | // TODO: how to get proper language?\r | |
72 | //\r | |
73 | OutText = DynamicCommand->GetHelp(DynamicCommand, "en");\r | |
74 | \r | |
75 | if (OutText == NULL) {\r | |
76 | continue;\r | |
77 | }\r | |
78 | \r | |
79 | //\r | |
80 | // Trim extra characters from the end the the string before printing\r | |
81 | //\r | |
82 | while (StrLen(OutText) > 0 \r | |
83 | && (OutText[StrLen(OutText) - 1] == L'\r' || OutText[StrLen(OutText) - 1] == L'\n' || OutText[StrLen(OutText) - 1] == L' ')) {\r | |
84 | OutText[StrLen(OutText) - 1] = CHAR_NULL;\r | |
85 | }\r | |
86 | \r | |
87 | //\r | |
88 | // Make sure we have something to print still.\r | |
89 | //\r | |
90 | if (StrLen(OutText) == 0) {\r | |
91 | FreePool(OutText);\r | |
92 | OutText = NULL;\r | |
93 | continue;\r | |
94 | }\r | |
95 | \r | |
96 | //\r | |
97 | // Print and move on.\r | |
98 | //\r | |
99 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_HELP_COMMAND), gShellLevel3HiiHandle, DynamicCommand->CommandName, OutText);\r | |
100 | FreePool(OutText);\r | |
101 | OutText = NULL;\r | |
102 | Found = TRUE;\r | |
103 | break;\r | |
104 | }\r | |
105 | \r | |
106 | }\r | |
107 | \r | |
108 | FreePool(CommandHandleList);\r | |
109 | \r | |
110 | return Found ? EFI_SUCCESS : EFI_NOT_FOUND;\r | |
111 | }\r | |
112 | \r | |
113 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r | |
114 | {L"-usage", TypeFlag},\r | |
115 | {L"-section", TypeMaxValue},\r | |
116 | {L"-verbose", TypeFlag},\r | |
117 | {L"-v", TypeFlag},\r | |
118 | {NULL, TypeMax}\r | |
119 | };\r | |
120 | \r | |
121 | /**\r | |
122 | Function for 'help' command.\r | |
123 | \r | |
124 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
125 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
126 | **/\r | |
127 | SHELL_STATUS\r | |
128 | EFIAPI\r | |
129 | ShellCommandRunHelp (\r | |
130 | IN EFI_HANDLE ImageHandle,\r | |
131 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
132 | )\r | |
133 | {\r | |
134 | EFI_STATUS Status;\r | |
135 | LIST_ENTRY *Package;\r | |
136 | CHAR16 *ProblemParam;\r | |
137 | SHELL_STATUS ShellStatus;\r | |
138 | CONST COMMAND_LIST *CommandList;\r | |
139 | CONST COMMAND_LIST *Node;\r | |
140 | CHAR16 *CommandToGetHelpOn;\r | |
141 | CHAR16 *SectionToGetHelpOn;\r | |
142 | CHAR16 *HiiString;\r | |
143 | BOOLEAN Found;\r | |
144 | BOOLEAN PrintCommandText;\r | |
145 | \r | |
146 | PrintCommandText = TRUE;\r | |
147 | ProblemParam = NULL;\r | |
148 | ShellStatus = SHELL_SUCCESS;\r | |
149 | CommandToGetHelpOn = NULL;\r | |
150 | SectionToGetHelpOn = NULL;\r | |
151 | Found = FALSE;\r | |
152 | \r | |
153 | //\r | |
154 | // initialize the shell lib (we must be in non-auto-init...)\r | |
155 | //\r | |
156 | Status = ShellInitialize();\r | |
157 | ASSERT_EFI_ERROR(Status);\r | |
158 | \r | |
159 | Status = CommandInit();\r | |
160 | ASSERT_EFI_ERROR(Status);\r | |
161 | \r | |
162 | //\r | |
163 | // parse the command line\r | |
164 | //\r | |
165 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r | |
166 | if (EFI_ERROR(Status)) {\r | |
167 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
168 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, ProblemParam);\r | |
169 | FreePool(ProblemParam);\r | |
170 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
171 | } else {\r | |
172 | ASSERT(FALSE);\r | |
173 | }\r | |
174 | } else {\r | |
175 | //\r | |
176 | // Check for conflicting parameters.\r | |
177 | //\r | |
178 | if (ShellCommandLineGetFlag(Package, L"-usage")\r | |
179 | &&ShellCommandLineGetFlag(Package, L"-section")\r | |
180 | &&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))\r | |
181 | ){\r | |
182 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel3HiiHandle);\r | |
183 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
184 | } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r | |
185 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle);\r | |
186 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
187 | } else {\r | |
188 | //\r | |
189 | // Get the command name we are getting help on\r | |
190 | //\r | |
191 | ASSERT(CommandToGetHelpOn == NULL);\r | |
192 | StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);\r | |
193 | if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {\r | |
194 | //\r | |
195 | // If we dont have a command and we got a simple -?\r | |
196 | // we are looking for help on help command.\r | |
197 | //\r | |
198 | StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);\r | |
199 | }\r | |
200 | \r | |
201 | if (CommandToGetHelpOn == NULL) {\r | |
202 | StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);\r | |
203 | ASSERT(SectionToGetHelpOn == NULL);\r | |
204 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);\r | |
205 | } else {\r | |
206 | PrintCommandText = FALSE;\r | |
207 | ASSERT(SectionToGetHelpOn == NULL);\r | |
208 | //\r | |
209 | // Get the section name for the given command name\r | |
210 | //\r | |
211 | if (ShellCommandLineGetFlag(Package, L"-section")) {\r | |
212 | StrnCatGrow(&SectionToGetHelpOn, NULL, ShellCommandLineGetValue(Package, L"-section"), 0);\r | |
213 | } else if (ShellCommandLineGetFlag(Package, L"-usage")) {\r | |
214 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS", 0);\r | |
215 | } else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {\r | |
216 | } else {\r | |
217 | //\r | |
218 | // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.\r | |
219 | //\r | |
220 | StrnCatGrow (&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);\r | |
221 | }\r | |
222 | }\r | |
223 | \r | |
224 | if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {\r | |
225 | //\r | |
226 | // we need info on the special characters\r | |
227 | //\r | |
228 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);\r | |
229 | HiiString = HiiGetString(gShellLevel3HiiHandle, STRING_TOKEN(STR_HELP_SC_DATA), NULL);\r | |
230 | ShellPrintEx(-1, -1, L"%s", HiiString);\r | |
231 | FreePool(HiiString);\r | |
232 | Found = TRUE;\r | |
233 | } else {\r | |
234 | CommandList = ShellCommandGetCommandList(TRUE);\r | |
235 | ASSERT(CommandList != NULL);\r | |
236 | for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link)\r | |
237 | ; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link)\r | |
238 | ; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)\r | |
239 | ){\r | |
240 | //\r | |
241 | // Checking execution break flag when print multiple command help information.\r | |
242 | //\r | |
243 | if (ShellGetExecutionBreakFlag ()) {\r | |
244 | break;\r | |
245 | } \r | |
246 | if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||\r | |
247 | (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {\r | |
248 | //\r | |
249 | // We have a command to look for help on.\r | |
250 | //\r | |
251 | Status = ShellPrintHelp(Node->CommandString, SectionToGetHelpOn, PrintCommandText);\r | |
252 | if (Status == EFI_DEVICE_ERROR) {\r | |
253 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, Node->CommandString);\r | |
254 | } else if (EFI_ERROR(Status)) {\r | |
255 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);\r | |
256 | } else {\r | |
257 | Found = TRUE;\r | |
258 | }\r | |
259 | }\r | |
260 | }\r | |
261 | //\r | |
262 | // Search the .man file for Shell applications (Shell external commands).\r | |
263 | //\r | |
264 | if (!Found) {\r | |
265 | Status = ShellPrintHelp(CommandToGetHelpOn, SectionToGetHelpOn, FALSE);\r | |
266 | if (Status == EFI_DEVICE_ERROR) {\r | |
267 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
268 | } else if (EFI_ERROR(Status)) {\r | |
269 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
270 | } else {\r | |
271 | Found = TRUE;\r | |
272 | }\r | |
273 | }\r | |
274 | \r | |
275 | //\r | |
276 | // now try to match against the dynamic command list and print help\r | |
277 | //\r | |
278 | Status = PrintDynamicCommandHelp(CommandToGetHelpOn);\r | |
279 | if (Status == EFI_SUCCESS) {\r | |
280 | Found = TRUE;\r | |
281 | }\r | |
282 | \r | |
283 | }\r | |
284 | \r | |
285 | if (!Found) {\r | |
286 | ShellStatus = SHELL_NOT_FOUND;\r | |
287 | }\r | |
288 | \r | |
289 | //\r | |
290 | // free the command line package\r | |
291 | //\r | |
292 | ShellCommandLineFreeVarList (Package);\r | |
293 | }\r | |
294 | }\r | |
295 | \r | |
296 | if (CommandToGetHelpOn != NULL && StrCmp(CommandToGetHelpOn, L"*") == 0){\r | |
297 | //\r | |
298 | // If '*' then the command entered was 'Help' without qualifiers, This footer\r | |
299 | // provides additional info on help switches\r | |
300 | //\r | |
301 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_FOOTER), gShellLevel3HiiHandle);\r | |
302 | }\r | |
303 | if (CommandToGetHelpOn != NULL) {\r | |
304 | FreePool(CommandToGetHelpOn);\r | |
305 | }\r | |
306 | if (SectionToGetHelpOn != NULL) {\r | |
307 | FreePool(SectionToGetHelpOn);\r | |
308 | }\r | |
309 | \r | |
310 | return (ShellStatus);\r | |
311 | }\r |