]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ShellManParser.c
Cleanup UefiShellDebug1CommandsLib strings to :
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellManParser.c
CommitLineData
a405b86d 1/** @file\r
2 Provides interface to shell MAN file parser.\r
3\r
d233c122 4 Copyright (c) 2009 - 2013, 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 "Shell.h"\r
16\r
17/**\r
18 Verifies that the filename has .MAN on the end.\r
19\r
20 allocates a new buffer and copies the name (appending .MAN if necessary)\r
21\r
22 ASSERT if ManFileName is NULL\r
23\r
24 @param[in] ManFileName original filename\r
25\r
26 @return the new filename with .man as the extension.\r
27**/\r
28CHAR16 *\r
29EFIAPI\r
30GetManFileName(\r
31 IN CONST CHAR16 *ManFileName\r
32 )\r
33{\r
34 CHAR16 *Buffer;\r
3c865f20 35 if (ManFileName == NULL) {\r
36 return (NULL);\r
37 }\r
a405b86d 38 //\r
39 // Fix the file name\r
40 //\r
41 if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {\r
42 Buffer = AllocateZeroPool(StrSize(ManFileName));\r
3c865f20 43 if (Buffer != NULL) {\r
44 StrCpy(Buffer, ManFileName);\r
45 }\r
a405b86d 46 } else {\r
47 Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));\r
3c865f20 48 if (Buffer != NULL) {\r
49 StrCpy(Buffer, ManFileName);\r
50 StrCat(Buffer, L".man");\r
51 }\r
a405b86d 52 }\r
53 return (Buffer);\r
54}\r
55\r
56/**\r
57 Search the path environment variable for possible locations and test for\r
58 which one contains a man file with the name specified. If a valid file is found\r
59 stop searching and return the (opened) SHELL_FILE_HANDLE for that file.\r
60\r
61 @param[in] FileName Name of the file to find and open.\r
62 @param[out] Handle Pointer to the handle of the found file. The\r
63 value of this is undefined for return values\r
64 except EFI_SUCCESS.\r
65\r
66 @retval EFI_SUCCESS The file was found. Handle is a valid SHELL_FILE_HANDLE\r
67 @retval EFI_INVALID_PARAMETER A parameter had an invalid value.\r
68 @retval EFI_NOT_FOUND The file was not found.\r
69**/\r
70EFI_STATUS\r
71EFIAPI\r
72SearchPathForFile(\r
73 IN CONST CHAR16 *FileName,\r
74 OUT SHELL_FILE_HANDLE *Handle\r
75 )\r
76{\r
77 CHAR16 *FullFileName;\r
78 EFI_STATUS Status;\r
79\r
80 if ( FileName == NULL\r
81 || Handle == NULL\r
82 || StrLen(FileName) == 0\r
83 ){\r
84 return (EFI_INVALID_PARAMETER);\r
85 }\r
86\r
87 FullFileName = ShellFindFilePath(FileName);\r
88 if (FullFileName == NULL) {\r
89 return (EFI_NOT_FOUND);\r
90 }\r
91\r
92 //\r
93 // now open that file\r
94 //\r
95 Status = EfiShellOpenFileByName(FullFileName, Handle, EFI_FILE_MODE_READ);\r
96 FreePool(FullFileName);\r
97\r
98 return (Status);\r
99}\r
100\r
101/**\r
102 parses through Buffer (which is MAN file formatted) and returns the\r
103 detailed help for any sub section specified in the comma seperated list of\r
104 sections provided. If the end of the file or a .TH section is found then\r
105 return.\r
106\r
107 Upon a sucessful return the caller is responsible to free the memory in *HelpText\r
108\r
109 @param[in] Buffer Buffer to read from\r
110 @param[in] Sections name of command's sub sections to find\r
111 @param[in] HelpText pointer to pointer to string where text goes.\r
112 @param[in] HelpSize pointer to size of allocated HelpText (may be updated)\r
113\r
114 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
115 @retval EFI_SUCCESS the section was found and its description sotred in\r
116 an alloceted buffer.\r
117**/\r
118EFI_STATUS\r
119EFIAPI\r
120ManBufferFindSections(\r
121 IN CONST CHAR16 *Buffer,\r
122 IN CONST CHAR16 *Sections,\r
123 IN CHAR16 **HelpText,\r
124 IN UINTN *HelpSize\r
125 )\r
126{\r
127 EFI_STATUS Status;\r
128 CONST CHAR16 *CurrentLocation;\r
129 BOOLEAN CurrentlyReading;\r
130 CHAR16 *SectionName;\r
131 UINTN SectionLen;\r
132 BOOLEAN Found;\r
133 CHAR16 *TempString;\r
134 CHAR16 *TempString2;\r
135\r
136 if ( Buffer == NULL\r
137 || HelpText == NULL\r
138 || HelpSize == NULL\r
139 ){\r
140 return (EFI_INVALID_PARAMETER);\r
141 }\r
142\r
143 Status = EFI_SUCCESS;\r
144 CurrentlyReading = FALSE;\r
145 Found = FALSE;\r
146\r
147 for (CurrentLocation = Buffer,TempString = NULL\r
148 ; CurrentLocation != NULL && *CurrentLocation != CHAR_NULL\r
149 ; CurrentLocation=StrStr(CurrentLocation, L"\r\n"),TempString = NULL\r
150 ){\r
151 while(CurrentLocation[0] == L'\r' || CurrentLocation[0] == L'\n') {\r
152 CurrentLocation++;\r
153 }\r
154 if (CurrentLocation[0] == L'#') {\r
155 //\r
156 // Skip comment lines\r
157 //\r
158 continue;\r
159 }\r
160 if (StrnCmp(CurrentLocation, L".TH", 3) == 0) {\r
161 //\r
162 // we hit the end of this commands section so stop.\r
163 //\r
164 break;\r
165 }\r
166 if (StrnCmp(CurrentLocation, L".SH ", 4) == 0) {\r
167 if (Sections == NULL) {\r
168 CurrentlyReading = TRUE;\r
169 continue;\r
170 } else if (CurrentlyReading) {\r
171 CurrentlyReading = FALSE;\r
172 }\r
173 CurrentLocation += 4;\r
174 //\r
175 // is this a section we want to read in?\r
176 //\r
177 if (StrLen(CurrentLocation)!=0) {\r
178 TempString2 = StrStr(CurrentLocation, L" ");\r
179 TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\r"));\r
180 TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
181 ASSERT(TempString == NULL);\r
182 TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
532691c8 183 if (TempString == NULL) {\r
184 Status = EFI_OUT_OF_RESOURCES;\r
185 break;\r
186 }\r
a405b86d 187 SectionName = TempString;\r
188 SectionLen = StrLen(SectionName);\r
189 SectionName = StrStr(Sections, SectionName);\r
190 if (SectionName == NULL) {\r
191 continue;\r
192 }\r
193 if (*(SectionName + SectionLen) == CHAR_NULL || *(SectionName + SectionLen) == L',') {\r
194 CurrentlyReading = TRUE;\r
195 }\r
196 }\r
197 } else if (CurrentlyReading) {\r
198 Found = TRUE;\r
199 if (StrLen(CurrentLocation)!=0) {\r
200 TempString2 = StrStr(CurrentLocation, L"\r");\r
201 TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
202 ASSERT(TempString == NULL);\r
203 TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
532691c8 204 if (TempString == NULL) {\r
205 Status = EFI_OUT_OF_RESOURCES;\r
206 break;\r
207 }\r
a405b86d 208 //\r
209 // copy and save the current line.\r
210 //\r
211 ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));\r
212 StrnCatGrow (HelpText, HelpSize, TempString, 0);\r
532691c8 213 if (HelpText == NULL) {\r
214 Status = EFI_OUT_OF_RESOURCES;\r
215 break;\r
216 }\r
a405b86d 217 StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);\r
532691c8 218 if (HelpText == NULL) {\r
219 Status = EFI_OUT_OF_RESOURCES;\r
220 break;\r
221 }\r
a405b86d 222 }\r
223 }\r
224 SHELL_FREE_NON_NULL(TempString);\r
225 }\r
226 if (!Found && !EFI_ERROR(Status)) {\r
227 return (EFI_NOT_FOUND);\r
228 }\r
229 return (Status);\r
230}\r
231\r
232/**\r
233 parses through the MAN file specified by SHELL_FILE_HANDLE and returns the\r
234 detailed help for any sub section specified in the comma seperated list of\r
235 sections provided. If the end of the file or a .TH section is found then\r
236 return.\r
237\r
238 Upon a sucessful return the caller is responsible to free the memory in *HelpText\r
239\r
240 @param[in] Handle FileHandle to read from\r
241 @param[in] Sections name of command's sub sections to find\r
242 @param[out] HelpText pointer to pointer to string where text goes.\r
243 @param[out] HelpSize pointer to size of allocated HelpText (may be updated)\r
244 @param[in] Ascii TRUE if the file is ASCII, FALSE otherwise.\r
245\r
246 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
247 @retval EFI_SUCCESS the section was found and its description sotred in\r
248 an alloceted buffer.\r
249**/\r
250EFI_STATUS\r
251EFIAPI\r
252ManFileFindSections(\r
253 IN SHELL_FILE_HANDLE Handle,\r
254 IN CONST CHAR16 *Sections,\r
255 OUT CHAR16 **HelpText,\r
256 OUT UINTN *HelpSize,\r
257 IN BOOLEAN Ascii\r
258 )\r
259{\r
260 EFI_STATUS Status;\r
261 CHAR16 *ReadLine;\r
262 UINTN Size;\r
263 BOOLEAN CurrentlyReading;\r
264 CHAR16 *SectionName;\r
265 UINTN SectionLen;\r
266 BOOLEAN Found;\r
267\r
268 if ( Handle == NULL\r
269 || HelpText == NULL\r
270 || HelpSize == NULL\r
271 ){\r
272 return (EFI_INVALID_PARAMETER);\r
273 }\r
274\r
275 Status = EFI_SUCCESS;\r
276 CurrentlyReading = FALSE;\r
277 Size = 1024;\r
278 Found = FALSE;\r
279\r
280 ReadLine = AllocateZeroPool(Size);\r
281 if (ReadLine == NULL) {\r
282 return (EFI_OUT_OF_RESOURCES);\r
283 }\r
284\r
285 for (;!ShellFileHandleEof(Handle);Size = 1024) {\r
286 Status = ShellFileHandleReadLine(Handle, ReadLine, &Size, TRUE, &Ascii);\r
287 if (ReadLine[0] == L'#') {\r
288 //\r
289 // Skip comment lines\r
290 //\r
291 continue;\r
292 }\r
293 //\r
294 // ignore too small of buffer...\r
295 //\r
296 if (Status == EFI_BUFFER_TOO_SMALL) {\r
297 Status = EFI_SUCCESS;\r
298 }\r
299 if (EFI_ERROR(Status)) {\r
300 break;\r
301 } else if (StrnCmp(ReadLine, L".TH", 3) == 0) {\r
302 //\r
303 // we hit the end of this commands section so stop.\r
304 //\r
305 break;\r
306 } else if (StrnCmp(ReadLine, L".SH", 3) == 0) {\r
307 if (Sections == NULL) {\r
308 CurrentlyReading = TRUE;\r
309 continue;\r
310 }\r
311 //\r
312 // we found a section\r
313 //\r
314 if (CurrentlyReading) {\r
315 CurrentlyReading = FALSE;\r
316 }\r
317 //\r
318 // is this a section we want to read in?\r
319 //\r
320 for ( SectionName = ReadLine + 3\r
321 ; *SectionName == L' '\r
322 ; SectionName++);\r
323 SectionLen = StrLen(SectionName);\r
324 SectionName = StrStr(Sections, SectionName);\r
325 if (SectionName == NULL) {\r
326 continue;\r
327 }\r
328 if (*(SectionName + SectionLen) == CHAR_NULL || *(SectionName + SectionLen) == L',') {\r
329 CurrentlyReading = TRUE;\r
330 }\r
331 } else if (CurrentlyReading) {\r
332 Found = TRUE;\r
333 //\r
334 // copy and save the current line.\r
335 //\r
336 ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));\r
337 StrnCatGrow (HelpText, HelpSize, ReadLine, 0);\r
338 StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);\r
339 }\r
340 }\r
341 FreePool(ReadLine);\r
342 if (!Found && !EFI_ERROR(Status)) {\r
343 return (EFI_NOT_FOUND);\r
344 }\r
345 return (Status);\r
346}\r
347\r
348/**\r
349 parses through the MAN file formatted Buffer and returns the\r
350 "Brief Description" for the .TH section as specified by Command. If the\r
351 command section is not found return EFI_NOT_FOUND.\r
352\r
353 Upon a sucessful return the caller is responsible to free the memory in *BriefDesc\r
354\r
355 @param[in] Handle Buffer to read from\r
356 @param[in] Command name of command's section to find\r
357 @param[in] BriefDesc pointer to pointer to string where description goes.\r
358 @param[in] BriefSize pointer to size of allocated BriefDesc\r
359\r
360 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
361 @retval EFI_SUCCESS the section was found and its description sotred in\r
362 an alloceted buffer.\r
363**/\r
364EFI_STATUS\r
365EFIAPI\r
366ManBufferFindTitleSection(\r
367 IN CHAR16 **Buffer,\r
368 IN CONST CHAR16 *Command,\r
369 IN CHAR16 **BriefDesc,\r
370 IN UINTN *BriefSize\r
371 )\r
372{\r
373 EFI_STATUS Status;\r
374 CHAR16 *TitleString;\r
375 CHAR16 *TitleEnd;\r
376 CHAR16 *CurrentLocation;\r
377\r
378 if ( Buffer == NULL\r
379 || Command == NULL\r
380 || (BriefDesc != NULL && BriefSize == NULL)\r
381 ){\r
382 return (EFI_INVALID_PARAMETER);\r
383 }\r
384\r
385 Status = EFI_SUCCESS;\r
386\r
733f138d 387 TitleString = AllocateZeroPool((7*sizeof(CHAR16)) + StrSize(Command));\r
a405b86d 388 if (TitleString == NULL) {\r
389 return (EFI_OUT_OF_RESOURCES);\r
390 }\r
391 StrCpy(TitleString, L".TH ");\r
392 StrCat(TitleString, Command);\r
393 StrCat(TitleString, L" 0 ");\r
394\r
395 CurrentLocation = StrStr(*Buffer, TitleString);\r
396 if (CurrentLocation == NULL){\r
397 Status = EFI_NOT_FOUND;\r
398 } else {\r
399 //\r
400 // we found it so copy out the rest of the line into BriefDesc\r
401 // After skipping any spaces or zeroes\r
402 //\r
403 for (CurrentLocation += StrLen(TitleString)\r
404 ; *CurrentLocation == L' ' || *CurrentLocation == L'0' || *CurrentLocation == L'1' || *CurrentLocation == L'\"'\r
405 ; CurrentLocation++);\r
406\r
407 TitleEnd = StrStr(CurrentLocation, L"\"");\r
733f138d 408 if (TitleEnd == NULL) {\r
409 Status = EFI_DEVICE_ERROR;\r
410 } else {\r
411 if (BriefDesc != NULL) {\r
412 *BriefSize = StrSize(TitleEnd);\r
413 *BriefDesc = AllocateZeroPool(*BriefSize);\r
414 if (*BriefDesc == NULL) {\r
415 Status = EFI_OUT_OF_RESOURCES;\r
416 } else {\r
417 StrnCpy(*BriefDesc, CurrentLocation, TitleEnd-CurrentLocation);\r
418 }\r
a405b86d 419 }\r
a405b86d 420\r
733f138d 421 for (CurrentLocation = TitleEnd\r
422 ; *CurrentLocation != L'\n'\r
423 ; CurrentLocation++);\r
424 for (\r
425 ; *CurrentLocation == L' ' || *CurrentLocation == L'\n' || *CurrentLocation == L'\r'\r
426 ; CurrentLocation++);\r
427 *Buffer = CurrentLocation;\r
428 }\r
a405b86d 429 }\r
430\r
431 FreePool(TitleString);\r
432 return (Status);\r
433}\r
434\r
435/**\r
436 parses through the MAN file specified by SHELL_FILE_HANDLE and returns the\r
437 "Brief Description" for the .TH section as specified by Command. if the\r
438 command section is not found return EFI_NOT_FOUND.\r
439\r
440 Upon a sucessful return the caller is responsible to free the memory in *BriefDesc\r
441\r
4ff7e37b
ED
442 @param[in] Handle FileHandle to read from\r
443 @param[in] Command name of command's section to find\r
444 @param[out] BriefDesc pointer to pointer to string where description goes.\r
445 @param[out] BriefSize pointer to size of allocated BriefDesc\r
446 @param[in, out] Ascii TRUE if the file is ASCII, FALSE otherwise, will be\r
447 set if the file handle is at the 0 position.\r
a405b86d 448\r
449 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
450 @retval EFI_SUCCESS the section was found and its description sotred in\r
451 an alloceted buffer.\r
452**/\r
453EFI_STATUS\r
454EFIAPI\r
455ManFileFindTitleSection(\r
456 IN SHELL_FILE_HANDLE Handle,\r
457 IN CONST CHAR16 *Command,\r
458 OUT CHAR16 **BriefDesc OPTIONAL,\r
459 OUT UINTN *BriefSize OPTIONAL,\r
460 IN OUT BOOLEAN *Ascii\r
461 )\r
462{\r
463 EFI_STATUS Status;\r
464 CHAR16 *TitleString;\r
465 CHAR16 *ReadLine;\r
466 UINTN Size;\r
467 CHAR16 *TitleEnd;\r
468 UINTN TitleLen;\r
469 BOOLEAN Found;\r
470\r
471 if ( Handle == NULL\r
472 || Command == NULL\r
473 || (BriefDesc != NULL && BriefSize == NULL)\r
474 ){\r
475 return (EFI_INVALID_PARAMETER);\r
476 }\r
477\r
478 Status = EFI_SUCCESS;\r
479 Size = 1024;\r
480 Found = FALSE;\r
481\r
482 ReadLine = AllocateZeroPool(Size);\r
483 if (ReadLine == NULL) {\r
484 return (EFI_OUT_OF_RESOURCES);\r
485 }\r
486\r
733f138d 487 TitleString = AllocateZeroPool((4*sizeof(CHAR16)) + StrSize(Command));\r
a405b86d 488 if (TitleString == NULL) {\r
489 FreePool(ReadLine);\r
490 return (EFI_OUT_OF_RESOURCES);\r
491 }\r
492 StrCpy(TitleString, L".TH ");\r
493 StrCat(TitleString, Command);\r
d233c122 494\r
a405b86d 495 TitleLen = StrLen(TitleString);\r
496 for (;!ShellFileHandleEof(Handle);Size = 1024) {\r
497 Status = ShellFileHandleReadLine(Handle, ReadLine, &Size, TRUE, Ascii);\r
498 if (ReadLine[0] == L'#') {\r
499 //\r
500 // Skip comment lines\r
501 //\r
502 continue;\r
503 }\r
504 //\r
505 // ignore too small of buffer...\r
506 //\r
507 if (Status == EFI_BUFFER_TOO_SMALL) {\r
508 Status = EFI_SUCCESS;\r
509 }\r
510 if (EFI_ERROR(Status)) {\r
511 break;\r
512 }\r
513 if (StrnCmp(ReadLine, TitleString, TitleLen) == 0) {\r
514 Found = TRUE;\r
515 //\r
516 // we found it so copy out the rest of the line into BriefDesc\r
517 // After skipping any spaces or zeroes\r
518 //\r
519 for ( TitleEnd = ReadLine+TitleLen\r
520 ; *TitleEnd == L' ' || *TitleEnd == L'0' || *TitleEnd == L'1'\r
521 ; TitleEnd++);\r
522 if (BriefDesc != NULL) {\r
523 *BriefSize = StrSize(TitleEnd);\r
524 *BriefDesc = AllocateZeroPool(*BriefSize);\r
525 if (*BriefDesc == NULL) {\r
526 Status = EFI_OUT_OF_RESOURCES;\r
527 break;\r
528 }\r
529 StrCpy(*BriefDesc, TitleEnd);\r
530 }\r
531 break;\r
532 }\r
533 }\r
534 FreePool(ReadLine);\r
535 FreePool(TitleString);\r
536 if (!Found && !EFI_ERROR(Status)) {\r
537 return (EFI_NOT_FOUND);\r
538 }\r
539 return (Status);\r
540}\r
541\r
542/**\r
543 This function returns the help information for the specified command. The help text\r
544 will be parsed from a UEFI Shell manual page. (see UEFI Shell 2.0 Appendix B)\r
545\r
546 If Sections is specified, then each section name listed will be compared in a casesensitive\r
547 manner, to the section names described in Appendix B. If the section exists,\r
548 it will be appended to the returned help text. If the section does not exist, no\r
549 information will be returned. If Sections is NULL, then all help text information\r
550 available will be returned.\r
551\r
552 if BriefDesc is NULL, then the breif description will not be savedd seperatly,\r
553 but placed first in the main HelpText.\r
554\r
555 @param[in] ManFileName Points to the NULL-terminated UEFI Shell MAN file name.\r
556 @param[in] Command Points to the NULL-terminated UEFI Shell command name.\r
557 @param[in] Sections Points to the NULL-terminated comma-delimited\r
558 section names to return. If NULL, then all\r
559 sections will be returned.\r
560 @param[out] BriefDesc On return, points to a callee-allocated buffer\r
561 containing brief description text.\r
562 @param[out] HelpText On return, points to a callee-allocated buffer\r
563 containing all specified help text.\r
564\r
565 @retval EFI_SUCCESS The help text was returned.\r
566 @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the\r
567 returned help text.\r
ecae5117 568 @retval EFI_INVALID_PARAMETER HelpText is NULL.\r
569 @retval EFI_INVALID_PARAMETER ManFileName is invalid.\r
a405b86d 570 @retval EFI_NOT_FOUND There is no help text available for Command.\r
571**/\r
572EFI_STATUS\r
573EFIAPI\r
574ProcessManFile(\r
575 IN CONST CHAR16 *ManFileName,\r
576 IN CONST CHAR16 *Command,\r
577 IN CONST CHAR16 *Sections OPTIONAL,\r
578 OUT CHAR16 **BriefDesc OPTIONAL,\r
579 OUT CHAR16 **HelpText\r
580 )\r
581{\r
582 CHAR16 *TempString;\r
583 SHELL_FILE_HANDLE FileHandle;\r
584 EFI_STATUS Status;\r
585 UINTN HelpSize;\r
586 UINTN BriefSize;\r
587 BOOLEAN Ascii;\r
588 CHAR16 *TempString2;\r
589 EFI_DEVICE_PATH_PROTOCOL *FileDevPath;\r
590 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
591\r
592 if ( ManFileName == NULL\r
593 || Command == NULL\r
594 || HelpText == NULL\r
595 ){\r
596 return (EFI_INVALID_PARAMETER);\r
597 }\r
598\r
599 HelpSize = 0;\r
600 BriefSize = 0;\r
601 TempString = NULL;\r
602 //\r
603 // See if it's in HII first\r
604 //\r
605 TempString = ShellCommandGetCommandHelp(Command);\r
606 if (TempString != NULL) {\r
607 TempString2 = TempString;\r
608 Status = ManBufferFindTitleSection(&TempString2, Command, BriefDesc, &BriefSize);\r
609 if (!EFI_ERROR(Status) && HelpText != NULL){\r
610 Status = ManBufferFindSections(TempString2, Sections, HelpText, &HelpSize);\r
611 }\r
612 } else {\r
613 FileHandle = NULL;\r
614 TempString = GetManFileName(ManFileName);\r
ecae5117 615 if (TempString == NULL) {\r
616 return (EFI_INVALID_PARAMETER);\r
617 }\r
a405b86d 618\r
619 Status = SearchPathForFile(TempString, &FileHandle);\r
620 if (EFI_ERROR(Status)) {\r
621 FileDevPath = FileDevicePath(NULL, TempString);\r
622 DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, FileDevPath);\r
623 Status = InternalOpenFileDevicePath(DevPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r
624 FreePool(FileDevPath);\r
625 FreePool(DevPath);\r
626 }\r
627\r
628 if (!EFI_ERROR(Status)) {\r
629 HelpSize = 0;\r
630 BriefSize = 0;\r
631 Status = ManFileFindTitleSection(FileHandle, Command, BriefDesc, &BriefSize, &Ascii);\r
632 if (!EFI_ERROR(Status) && HelpText != NULL){\r
633 Status = ManFileFindSections(FileHandle, Sections, HelpText, &HelpSize, Ascii);\r
634 }\r
635 ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r
636 } else {\r
637 *HelpText = NULL;\r
638 }\r
639 }\r
640 if (TempString != NULL) {\r
641 FreePool(TempString);\r
642 }\r
643\r
644 return (Status);\r
645}\r