]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Application/Shell/ShellManParser.c
ShellPkg: Rename duplicate STRING ID
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellManParser.c
CommitLineData
a405b86d 1/** @file\r
2 Provides interface to shell MAN file parser.\r
3\r
733f138d 4 Copyright (c) 2009 - 2011, 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
494 TitleLen = StrLen(TitleString);\r
495 for (;!ShellFileHandleEof(Handle);Size = 1024) {\r
496 Status = ShellFileHandleReadLine(Handle, ReadLine, &Size, TRUE, Ascii);\r
497 if (ReadLine[0] == L'#') {\r
498 //\r
499 // Skip comment lines\r
500 //\r
501 continue;\r
502 }\r
503 //\r
504 // ignore too small of buffer...\r
505 //\r
506 if (Status == EFI_BUFFER_TOO_SMALL) {\r
507 Status = EFI_SUCCESS;\r
508 }\r
509 if (EFI_ERROR(Status)) {\r
510 break;\r
511 }\r
512 if (StrnCmp(ReadLine, TitleString, TitleLen) == 0) {\r
513 Found = TRUE;\r
514 //\r
515 // we found it so copy out the rest of the line into BriefDesc\r
516 // After skipping any spaces or zeroes\r
517 //\r
518 for ( TitleEnd = ReadLine+TitleLen\r
519 ; *TitleEnd == L' ' || *TitleEnd == L'0' || *TitleEnd == L'1'\r
520 ; TitleEnd++);\r
521 if (BriefDesc != NULL) {\r
522 *BriefSize = StrSize(TitleEnd);\r
523 *BriefDesc = AllocateZeroPool(*BriefSize);\r
524 if (*BriefDesc == NULL) {\r
525 Status = EFI_OUT_OF_RESOURCES;\r
526 break;\r
527 }\r
528 StrCpy(*BriefDesc, TitleEnd);\r
529 }\r
530 break;\r
531 }\r
532 }\r
533 FreePool(ReadLine);\r
534 FreePool(TitleString);\r
535 if (!Found && !EFI_ERROR(Status)) {\r
536 return (EFI_NOT_FOUND);\r
537 }\r
538 return (Status);\r
539}\r
540\r
541/**\r
542 This function returns the help information for the specified command. The help text\r
543 will be parsed from a UEFI Shell manual page. (see UEFI Shell 2.0 Appendix B)\r
544\r
545 If Sections is specified, then each section name listed will be compared in a casesensitive\r
546 manner, to the section names described in Appendix B. If the section exists,\r
547 it will be appended to the returned help text. If the section does not exist, no\r
548 information will be returned. If Sections is NULL, then all help text information\r
549 available will be returned.\r
550\r
551 if BriefDesc is NULL, then the breif description will not be savedd seperatly,\r
552 but placed first in the main HelpText.\r
553\r
554 @param[in] ManFileName Points to the NULL-terminated UEFI Shell MAN file name.\r
555 @param[in] Command Points to the NULL-terminated UEFI Shell command name.\r
556 @param[in] Sections Points to the NULL-terminated comma-delimited\r
557 section names to return. If NULL, then all\r
558 sections will be returned.\r
559 @param[out] BriefDesc On return, points to a callee-allocated buffer\r
560 containing brief description text.\r
561 @param[out] HelpText On return, points to a callee-allocated buffer\r
562 containing all specified help text.\r
563\r
564 @retval EFI_SUCCESS The help text was returned.\r
565 @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the\r
566 returned help text.\r
ecae5117 567 @retval EFI_INVALID_PARAMETER HelpText is NULL.\r
568 @retval EFI_INVALID_PARAMETER ManFileName is invalid.\r
a405b86d 569 @retval EFI_NOT_FOUND There is no help text available for Command.\r
570**/\r
571EFI_STATUS\r
572EFIAPI\r
573ProcessManFile(\r
574 IN CONST CHAR16 *ManFileName,\r
575 IN CONST CHAR16 *Command,\r
576 IN CONST CHAR16 *Sections OPTIONAL,\r
577 OUT CHAR16 **BriefDesc OPTIONAL,\r
578 OUT CHAR16 **HelpText\r
579 )\r
580{\r
581 CHAR16 *TempString;\r
582 SHELL_FILE_HANDLE FileHandle;\r
583 EFI_STATUS Status;\r
584 UINTN HelpSize;\r
585 UINTN BriefSize;\r
586 BOOLEAN Ascii;\r
587 CHAR16 *TempString2;\r
588 EFI_DEVICE_PATH_PROTOCOL *FileDevPath;\r
589 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
590\r
591 if ( ManFileName == NULL\r
592 || Command == NULL\r
593 || HelpText == NULL\r
594 ){\r
595 return (EFI_INVALID_PARAMETER);\r
596 }\r
597\r
598 HelpSize = 0;\r
599 BriefSize = 0;\r
600 TempString = NULL;\r
601 //\r
602 // See if it's in HII first\r
603 //\r
604 TempString = ShellCommandGetCommandHelp(Command);\r
605 if (TempString != NULL) {\r
606 TempString2 = TempString;\r
607 Status = ManBufferFindTitleSection(&TempString2, Command, BriefDesc, &BriefSize);\r
608 if (!EFI_ERROR(Status) && HelpText != NULL){\r
609 Status = ManBufferFindSections(TempString2, Sections, HelpText, &HelpSize);\r
610 }\r
611 } else {\r
612 FileHandle = NULL;\r
613 TempString = GetManFileName(ManFileName);\r
ecae5117 614 if (TempString == NULL) {\r
615 return (EFI_INVALID_PARAMETER);\r
616 }\r
a405b86d 617\r
618 Status = SearchPathForFile(TempString, &FileHandle);\r
619 if (EFI_ERROR(Status)) {\r
620 FileDevPath = FileDevicePath(NULL, TempString);\r
621 DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, FileDevPath);\r
622 Status = InternalOpenFileDevicePath(DevPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r
623 FreePool(FileDevPath);\r
624 FreePool(DevPath);\r
625 }\r
626\r
627 if (!EFI_ERROR(Status)) {\r
628 HelpSize = 0;\r
629 BriefSize = 0;\r
630 Status = ManFileFindTitleSection(FileHandle, Command, BriefDesc, &BriefSize, &Ascii);\r
631 if (!EFI_ERROR(Status) && HelpText != NULL){\r
632 Status = ManFileFindSections(FileHandle, Sections, HelpText, &HelpSize, Ascii);\r
633 }\r
634 ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r
635 } else {\r
636 *HelpText = NULL;\r
637 }\r
638 }\r
639 if (TempString != NULL) {\r
640 FreePool(TempString);\r
641 }\r
642\r
643 return (Status);\r
644}\r