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