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