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