-/**\r
- parses through Buffer (which is MAN file formatted) and returns the\r
- detailed help for any sub section specified in the comma seperated list of\r
- sections provided. If the end of the file or a .TH section is found then\r
- return.\r
-\r
- Upon a sucessful return the caller is responsible to free the memory in *HelpText\r
-\r
- @param[in] Buffer Buffer to read from\r
- @param[in] Sections name of command's sub sections to find\r
- @param[in] HelpText pointer to pointer to string where text goes.\r
- @param[in] HelpSize pointer to size of allocated HelpText (may be updated)\r
-\r
- @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
- @retval EFI_SUCCESS the section was found and its description sotred in\r
- an alloceted buffer.\r
-**/\r
-EFI_STATUS\r
-ManBufferFindSections(\r
- IN CONST CHAR16 *Buffer,\r
- IN CONST CHAR16 *Sections,\r
- IN CHAR16 **HelpText,\r
- IN UINTN *HelpSize\r
- )\r
-{\r
- EFI_STATUS Status;\r
- CONST CHAR16 *CurrentLocation;\r
- BOOLEAN CurrentlyReading;\r
- CHAR16 *SectionName;\r
- UINTN SectionLen;\r
- BOOLEAN Found;\r
- CHAR16 *TempString;\r
- CHAR16 *TempString2;\r
-\r
- if ( Buffer == NULL\r
- || HelpText == NULL\r
- || HelpSize == NULL\r
- ){\r
- return (EFI_INVALID_PARAMETER);\r
- }\r
-\r
- Status = EFI_SUCCESS;\r
- CurrentlyReading = FALSE;\r
- Found = FALSE;\r
-\r
- for (CurrentLocation = Buffer,TempString = NULL\r
- ; CurrentLocation != NULL && *CurrentLocation != CHAR_NULL\r
- ; CurrentLocation=StrStr(CurrentLocation, L"\r\n"),TempString = NULL\r
- ){\r
- while(CurrentLocation[0] == L'\r' || CurrentLocation[0] == L'\n') {\r
- CurrentLocation++;\r
- }\r
- if (CurrentLocation[0] == L'#') {\r
- //\r
- // Skip comment lines\r
- //\r
- continue;\r
- }\r
- if (StrnCmp(CurrentLocation, L".TH", 3) == 0) {\r
- //\r
- // we hit the end of this commands section so stop.\r
- //\r
- break;\r
- }\r
- if (StrnCmp(CurrentLocation, L".SH ", 4) == 0) {\r
- if (Sections == NULL) {\r
- CurrentlyReading = TRUE;\r
- continue;\r
- } else if (CurrentlyReading) {\r
- CurrentlyReading = FALSE;\r
- }\r
- CurrentLocation += 4;\r
- //\r
- // is this a section we want to read in?\r
- //\r
- if (StrLen(CurrentLocation)!=0) {\r
- TempString2 = StrStr(CurrentLocation, L" ");\r
- TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\r"));\r
- TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
- ASSERT(TempString == NULL);\r
- TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
- if (TempString == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- break;\r
- }\r
- SectionName = TempString;\r
- SectionLen = StrLen(SectionName);\r
- SectionName = StrStr(Sections, SectionName);\r
- if (SectionName == NULL) {\r
- SHELL_FREE_NON_NULL(TempString);\r
- continue;\r
- }\r
- if (*(SectionName + SectionLen) == CHAR_NULL || *(SectionName + SectionLen) == L',') {\r
- CurrentlyReading = TRUE;\r
- }\r
- }\r
- } else if (CurrentlyReading) {\r
- Found = TRUE;\r
- if (StrLen(CurrentLocation)!=0) {\r
- TempString2 = StrStr(CurrentLocation, L"\r");\r
- TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));\r
- ASSERT(TempString == NULL);\r
- TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);\r
- if (TempString == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- break;\r
- }\r
- //\r
- // copy and save the current line.\r
- //\r
- ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));\r
- StrnCatGrow (HelpText, HelpSize, TempString, 0);\r
- if (HelpText == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- break;\r
- }\r
- StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);\r
- if (HelpText == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- break;\r
- }\r
- }\r
- }\r
- SHELL_FREE_NON_NULL(TempString);\r
- }\r
- SHELL_FREE_NON_NULL(TempString);\r
- if (!Found && !EFI_ERROR(Status)) {\r
- return (EFI_NOT_FOUND);\r
- }\r
- return (Status);\r
-}\r
-\r