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