]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Main file for Help shell level 3 function.\r | |
3 | \r | |
cab102c3 | 4 | Copyright (c) 2009 - 2014, 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 | |
710db4e8 | 100 | return (Found ? EFI_SUCCESS : Status);\r |
cab102c3 | 101 | \r |
cab102c3 | 102 | }\r |
a405b86d | 103 | \r |
104 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r | |
105 | {L"-usage", TypeFlag},\r | |
345cd235 | 106 | {L"-section", TypeMaxValue},\r |
a405b86d | 107 | {L"-verbose", TypeFlag},\r |
108 | {L"-v", TypeFlag},\r | |
109 | {NULL, TypeMax}\r | |
110 | };\r | |
111 | \r | |
112 | /**\r | |
113 | Function for 'help' command.\r | |
114 | \r | |
115 | @param[in] ImageHandle Handle to the Image (NULL if Internal).\r | |
116 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r | |
117 | **/\r | |
118 | SHELL_STATUS\r | |
119 | EFIAPI\r | |
120 | ShellCommandRunHelp (\r | |
121 | IN EFI_HANDLE ImageHandle,\r | |
122 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
123 | )\r | |
124 | {\r | |
125 | EFI_STATUS Status;\r | |
126 | LIST_ENTRY *Package;\r | |
127 | CHAR16 *ProblemParam;\r | |
128 | SHELL_STATUS ShellStatus;\r | |
a405b86d | 129 | CONST COMMAND_LIST *CommandList;\r |
130 | CONST COMMAND_LIST *Node;\r | |
131 | CHAR16 *CommandToGetHelpOn;\r | |
132 | CHAR16 *SectionToGetHelpOn;\r | |
133 | CHAR16 *HiiString;\r | |
134 | BOOLEAN Found;\r | |
7c8e7960 | 135 | BOOLEAN PrintCommandText;\r |
a405b86d | 136 | \r |
7c8e7960 | 137 | PrintCommandText = TRUE;\r |
a405b86d | 138 | ProblemParam = NULL;\r |
139 | ShellStatus = SHELL_SUCCESS;\r | |
a405b86d | 140 | CommandToGetHelpOn = NULL;\r |
141 | SectionToGetHelpOn = NULL;\r | |
142 | Found = FALSE;\r | |
143 | \r | |
144 | //\r | |
145 | // initialize the shell lib (we must be in non-auto-init...)\r | |
146 | //\r | |
147 | Status = ShellInitialize();\r | |
148 | ASSERT_EFI_ERROR(Status);\r | |
149 | \r | |
150 | Status = CommandInit();\r | |
151 | ASSERT_EFI_ERROR(Status);\r | |
152 | \r | |
153 | //\r | |
154 | // parse the command line\r | |
155 | //\r | |
156 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r | |
157 | if (EFI_ERROR(Status)) {\r | |
158 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r | |
e54a10bb | 159 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"help", ProblemParam); \r |
a405b86d | 160 | FreePool(ProblemParam);\r |
161 | ShellStatus = SHELL_INVALID_PARAMETER;\r | |
162 | } else {\r | |
163 | ASSERT(FALSE);\r | |
164 | }\r | |
165 | } else {\r | |
166 | //\r | |
167 | // Check for conflicting parameters.\r | |
168 | //\r | |
169 | if (ShellCommandLineGetFlag(Package, L"-usage")\r | |
170 | &&ShellCommandLineGetFlag(Package, L"-section")\r | |
171 | &&(ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v"))\r | |
172 | ){\r | |
e54a10bb | 173 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel3HiiHandle, L"help"); \r |
a405b86d | 174 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
175 | } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {\r | |
e54a10bb | 176 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel3HiiHandle, L"help"); \r |
a405b86d | 177 | ShellStatus = SHELL_INVALID_PARAMETER;\r |
178 | } else {\r | |
179 | //\r | |
180 | // Get the command name we are getting help on\r | |
181 | //\r | |
182 | ASSERT(CommandToGetHelpOn == NULL);\r | |
183 | StrnCatGrow(&CommandToGetHelpOn, NULL, ShellCommandLineGetRawValue(Package, 1), 0);\r | |
184 | if (CommandToGetHelpOn == NULL && ShellCommandLineGetFlag(Package, L"-?")) {\r | |
185 | //\r | |
186 | // If we dont have a command and we got a simple -?\r | |
187 | // we are looking for help on help command.\r | |
188 | //\r | |
189 | StrnCatGrow(&CommandToGetHelpOn, NULL, L"help", 0);\r | |
190 | }\r | |
191 | \r | |
192 | if (CommandToGetHelpOn == NULL) {\r | |
193 | StrnCatGrow(&CommandToGetHelpOn, NULL, L"*", 0);\r | |
194 | ASSERT(SectionToGetHelpOn == NULL);\r | |
195 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME", 0);\r | |
196 | } else {\r | |
7c8e7960 | 197 | PrintCommandText = FALSE;\r |
a405b86d | 198 | ASSERT(SectionToGetHelpOn == NULL);\r |
199 | //\r | |
200 | // Get the section name for the given command name\r | |
201 | //\r | |
202 | if (ShellCommandLineGetFlag(Package, L"-section")) {\r | |
203 | StrnCatGrow(&SectionToGetHelpOn, NULL, ShellCommandLineGetValue(Package, L"-section"), 0);\r | |
204 | } else if (ShellCommandLineGetFlag(Package, L"-usage")) {\r | |
205 | StrnCatGrow(&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS", 0);\r | |
206 | } else if (ShellCommandLineGetFlag(Package, L"-verbose") || ShellCommandLineGetFlag(Package, L"-v")) {\r | |
207 | } else {\r | |
d51088b7 | 208 | //\r |
209 | // The output of help <command> will display NAME, SYNOPSIS, OPTIONS, DESCRIPTION, and EXAMPLES sections.\r | |
210 | //\r | |
211 | StrnCatGrow (&SectionToGetHelpOn, NULL, L"NAME,SYNOPSIS,OPTIONS,DESCRIPTION,EXAMPLES", 0);\r | |
a405b86d | 212 | }\r |
213 | }\r | |
214 | \r | |
215 | if (gUnicodeCollation->StriColl(gUnicodeCollation, CommandToGetHelpOn, L"special") == 0) {\r | |
216 | //\r | |
217 | // we need info on the special characters\r | |
218 | //\r | |
219 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_SC_HEADER), gShellLevel3HiiHandle);\r | |
220 | HiiString = HiiGetString(gShellLevel3HiiHandle, STRING_TOKEN(STR_HELP_SC_DATA), NULL);\r | |
221 | ShellPrintEx(-1, -1, L"%s", HiiString);\r | |
222 | FreePool(HiiString);\r | |
223 | Found = TRUE;\r | |
224 | } else {\r | |
345cd235 | 225 | CommandList = ShellCommandGetCommandList(TRUE);\r |
a405b86d | 226 | ASSERT(CommandList != NULL);\r |
227 | for ( Node = (COMMAND_LIST*)GetFirstNode(&CommandList->Link)\r | |
228 | ; CommandList != NULL && !IsListEmpty(&CommandList->Link) && !IsNull(&CommandList->Link, &Node->Link)\r | |
229 | ; Node = (COMMAND_LIST*)GetNextNode(&CommandList->Link, &Node->Link)\r | |
230 | ){\r | |
d51088b7 | 231 | //\r |
232 | // Checking execution break flag when print multiple command help information.\r | |
233 | //\r | |
234 | if (ShellGetExecutionBreakFlag ()) {\r | |
235 | break;\r | |
236 | } \r | |
345cd235 | 237 | if ((gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, CommandToGetHelpOn)) ||\r |
238 | (gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL) != NULL && (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Node->CommandString, (CHAR16*)(gEfiShellProtocol->GetAlias(CommandToGetHelpOn, NULL)))))) {\r | |
a405b86d | 239 | //\r |
240 | // We have a command to look for help on.\r | |
241 | //\r | |
7c8e7960 | 242 | Status = ShellPrintHelp(Node->CommandString, SectionToGetHelpOn, PrintCommandText);\r |
243 | if (Status == EFI_DEVICE_ERROR) {\r | |
345cd235 | 244 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, Node->CommandString);\r |
7c8e7960 | 245 | } else if (EFI_ERROR(Status)) {\r |
345cd235 | 246 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, Node->CommandString);\r |
a405b86d | 247 | } else {\r |
7c8e7960 | 248 | Found = TRUE;\r |
a405b86d | 249 | }\r |
250 | }\r | |
251 | }\r | |
710db4e8 HL |
252 | \r |
253 | //\r | |
254 | // now try to match against the dynamic command list and print help\r | |
255 | //\r | |
256 | Status = PrintDynamicCommandHelp (CommandToGetHelpOn, SectionToGetHelpOn,\r | |
257 | PrintCommandText);\r | |
258 | if (!EFI_ERROR(Status)) {\r | |
259 | Found = TRUE;\r | |
260 | }\r | |
261 | \r | |
d51088b7 | 262 | //\r |
263 | // Search the .man file for Shell applications (Shell external commands).\r | |
264 | //\r | |
265 | if (!Found) {\r | |
cab102c3 JC |
266 | Status = ShellPrintHelp(CommandToGetHelpOn, SectionToGetHelpOn, FALSE);\r |
267 | if (Status == EFI_DEVICE_ERROR) {\r | |
268 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_INV), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
269 | } else if (EFI_ERROR(Status)) {\r | |
270 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_NF), gShellLevel3HiiHandle, CommandToGetHelpOn);\r | |
271 | } else {\r | |
272 | Found = TRUE;\r | |
273 | }\r | |
274 | }\r | |
a405b86d | 275 | }\r |
276 | \r | |
7c8e7960 | 277 | if (!Found) {\r |
a405b86d | 278 | ShellStatus = SHELL_NOT_FOUND;\r |
279 | }\r | |
280 | \r | |
281 | //\r | |
282 | // free the command line package\r | |
283 | //\r | |
284 | ShellCommandLineFreeVarList (Package);\r | |
285 | }\r | |
286 | }\r | |
7c8e7960 | 287 | \r |
288 | if (CommandToGetHelpOn != NULL && StrCmp(CommandToGetHelpOn, L"*") == 0){\r | |
289 | //\r | |
290 | // If '*' then the command entered was 'Help' without qualifiers, This footer\r | |
291 | // provides additional info on help switches\r | |
292 | //\r | |
293 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_HELP_FOOTER), gShellLevel3HiiHandle);\r | |
294 | }\r | |
a405b86d | 295 | if (CommandToGetHelpOn != NULL) {\r |
296 | FreePool(CommandToGetHelpOn);\r | |
297 | }\r | |
298 | if (SectionToGetHelpOn != NULL) {\r | |
299 | FreePool(SectionToGetHelpOn);\r | |
300 | }\r | |
301 | \r | |
302 | return (ShellStatus);\r | |
303 | }\r |