summaryrefslogtreecommitdiff
path: root/ShellPkg/Application/Shell/ShellManParser.c
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Application/Shell/ShellManParser.c')
-rw-r--r--ShellPkg/Application/Shell/ShellManParser.c275
1 files changed, 23 insertions, 252 deletions
diff --git a/ShellPkg/Application/Shell/ShellManParser.c b/ShellPkg/Application/Shell/ShellManParser.c
index 7a290e1..975f3c2 100644
--- a/ShellPkg/Application/Shell/ShellManParser.c
+++ b/ShellPkg/Application/Shell/ShellManParser.c
@@ -1,7 +1,7 @@
/** @file
Provides interface to shell MAN file parser.
- Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
Copyright 2015 Dell Inc.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -206,138 +206,6 @@ SearchPathForFile(
}
/**
- parses through Buffer (which is MAN file formatted) and returns the
- detailed help for any sub section specified in the comma seperated list of
- sections provided. If the end of the file or a .TH section is found then
- return.
-
- Upon a sucessful return the caller is responsible to free the memory in *HelpText
-
- @param[in] Buffer Buffer to read from
- @param[in] Sections name of command's sub sections to find
- @param[in] HelpText pointer to pointer to string where text goes.
- @param[in] HelpSize pointer to size of allocated HelpText (may be updated)
-
- @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
- @retval EFI_SUCCESS the section was found and its description sotred in
- an alloceted buffer.
-**/
-EFI_STATUS
-ManBufferFindSections(
- IN CONST CHAR16 *Buffer,
- IN CONST CHAR16 *Sections,
- IN CHAR16 **HelpText,
- IN UINTN *HelpSize
- )
-{
- EFI_STATUS Status;
- CONST CHAR16 *CurrentLocation;
- BOOLEAN CurrentlyReading;
- CHAR16 *SectionName;
- UINTN SectionLen;
- BOOLEAN Found;
- CHAR16 *TempString;
- CHAR16 *TempString2;
-
- if ( Buffer == NULL
- || HelpText == NULL
- || HelpSize == NULL
- ){
- return (EFI_INVALID_PARAMETER);
- }
-
- Status = EFI_SUCCESS;
- CurrentlyReading = FALSE;
- Found = FALSE;
-
- for (CurrentLocation = Buffer,TempString = NULL
- ; CurrentLocation != NULL && *CurrentLocation != CHAR_NULL
- ; CurrentLocation=StrStr(CurrentLocation, L"\r\n"),TempString = NULL
- ){
- while(CurrentLocation[0] == L'\r' || CurrentLocation[0] == L'\n') {
- CurrentLocation++;
- }
- if (CurrentLocation[0] == L'#') {
- //
- // Skip comment lines
- //
- continue;
- }
- if (StrnCmp(CurrentLocation, L".TH", 3) == 0) {
- //
- // we hit the end of this commands section so stop.
- //
- break;
- }
- if (StrnCmp(CurrentLocation, L".SH ", 4) == 0) {
- if (Sections == NULL) {
- CurrentlyReading = TRUE;
- continue;
- } else if (CurrentlyReading) {
- CurrentlyReading = FALSE;
- }
- CurrentLocation += 4;
- //
- // is this a section we want to read in?
- //
- if (StrLen(CurrentLocation)!=0) {
- TempString2 = StrStr(CurrentLocation, L" ");
- TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\r"));
- TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));
- ASSERT(TempString == NULL);
- TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);
- if (TempString == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- break;
- }
- SectionName = TempString;
- SectionLen = StrLen(SectionName);
- SectionName = StrStr(Sections, SectionName);
- if (SectionName == NULL) {
- SHELL_FREE_NON_NULL(TempString);
- continue;
- }
- if (*(SectionName + SectionLen) == CHAR_NULL || *(SectionName + SectionLen) == L',') {
- CurrentlyReading = TRUE;
- }
- }
- } else if (CurrentlyReading) {
- Found = TRUE;
- if (StrLen(CurrentLocation)!=0) {
- TempString2 = StrStr(CurrentLocation, L"\r");
- TempString2 = MIN(TempString2, StrStr(CurrentLocation, L"\n"));
- ASSERT(TempString == NULL);
- TempString = StrnCatGrow(&TempString, NULL, CurrentLocation, TempString2==NULL?0:TempString2 - CurrentLocation);
- if (TempString == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- break;
- }
- //
- // copy and save the current line.
- //
- ASSERT((*HelpText == NULL && *HelpSize == 0) || (*HelpText != NULL));
- StrnCatGrow (HelpText, HelpSize, TempString, 0);
- if (HelpText == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- break;
- }
- StrnCatGrow (HelpText, HelpSize, L"\r\n", 0);
- if (HelpText == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- break;
- }
- }
- }
- SHELL_FREE_NON_NULL(TempString);
- }
- SHELL_FREE_NON_NULL(TempString);
- if (!Found && !EFI_ERROR(Status)) {
- return (EFI_NOT_FOUND);
- }
- return (Status);
-}
-
-/**
parses through the MAN file specified by SHELL_FILE_HANDLE and returns the
detailed help for any sub section specified in the comma seperated list of
sections provided. If the end of the file or a .TH section is found then
@@ -453,111 +321,6 @@ ManFileFindSections(
}
/**
- parses through the MAN file formatted Buffer and returns the
- "Brief Description" for the .TH section as specified by Command. If the
- command section is not found return EFI_NOT_FOUND.
-
- Upon a sucessful return the caller is responsible to free the memory in *BriefDesc
-
- @param[in] Buffer Buffer to read from
- @param[in] Command name of command's section to find
- @param[in] BriefDesc pointer to pointer to string where description goes.
- @param[in] BriefSize pointer to size of allocated BriefDesc
-
- @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
- @retval EFI_SUCCESS the section was found and its description sotred in
- an alloceted buffer.
-**/
-EFI_STATUS
-ManBufferFindTitleSection(
- IN CHAR16 **Buffer,
- IN CONST CHAR16 *Command,
- IN CHAR16 **BriefDesc,
- IN UINTN *BriefSize
- )
-{
- EFI_STATUS Status;
- CHAR16 *TitleString;
- CHAR16 *TitleEnd;
- CHAR16 *CurrentLocation;
- UINTN TitleLength;
- UINTN Start;
- CONST CHAR16 StartString[] = L".TH ";
- CONST CHAR16 EndString[] = L" 0 ";
-
- if ( Buffer == NULL
- || Command == NULL
- || (BriefDesc != NULL && BriefSize == NULL)
- ){
- return (EFI_INVALID_PARAMETER);
- }
-
- Status = EFI_SUCCESS;
-
- //
- // Do not pass any leading path information that may be present to IsTitleHeader().
- //
- Start = StrLen(Command);
- while ((Start != 0)
- && (*(Command + Start - 1) != L'\\')
- && (*(Command + Start - 1) != L'/')
- && (*(Command + Start - 1) != L':')) {
- --Start;
- }
-
- //
- // more characters for StartString and EndString
- //
- TitleLength = StrSize(Command + Start) + (StrLen(StartString) + StrLen(EndString)) * sizeof(CHAR16);
- TitleString = AllocateZeroPool(TitleLength);
- if (TitleString == NULL) {
- return (EFI_OUT_OF_RESOURCES);
- }
- StrCpyS(TitleString, TitleLength/sizeof(CHAR16), StartString);
- StrCatS(TitleString, TitleLength/sizeof(CHAR16), Command + Start);
- StrCatS(TitleString, TitleLength/sizeof(CHAR16), EndString);
-
- CurrentLocation = StrStr(*Buffer, TitleString);
- if (CurrentLocation == NULL){
- Status = EFI_NOT_FOUND;
- } else {
- //
- // we found it so copy out the rest of the line into BriefDesc
- // After skipping any spaces or zeroes
- //
- for (CurrentLocation += StrLen(TitleString)
- ; *CurrentLocation == L' ' || *CurrentLocation == L'0' || *CurrentLocation == L'1' || *CurrentLocation == L'\"'
- ; CurrentLocation++);
-
- TitleEnd = StrStr(CurrentLocation, L"\"");
- if (TitleEnd == NULL) {
- Status = EFI_DEVICE_ERROR;
- } else {
- if (BriefDesc != NULL) {
- *BriefSize = StrSize(TitleEnd);
- *BriefDesc = AllocateZeroPool(*BriefSize);
- if (*BriefDesc == NULL) {
- Status = EFI_OUT_OF_RESOURCES;
- } else {
- StrnCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), CurrentLocation, TitleEnd-CurrentLocation);
- }
- }
-
- for (CurrentLocation = TitleEnd
- ; *CurrentLocation != L'\n'
- ; CurrentLocation++);
- for (
- ; *CurrentLocation == L' ' || *CurrentLocation == L'\n' || *CurrentLocation == L'\r'
- ; CurrentLocation++);
- *Buffer = CurrentLocation;
- }
- }
-
- FreePool(TitleString);
- return (Status);
-}
-
-/**
Parses a line from a MAN file to see if it is the Title Header. If it is, then
if the "Brief Description" is desired, allocate a buffer for it and return a
copy. Upon a sucessful return the caller is responsible to free the memory in
@@ -813,10 +576,8 @@ ProcessManFile(
UINTN BriefSize;
UINTN StringIdWalker;
BOOLEAN Ascii;
- CHAR16 *TempString2;
CHAR16 *CmdFileName;
CHAR16 *CmdFilePathName;
- CHAR16 *StringBuff;
EFI_DEVICE_PATH_PROTOCOL *FileDevPath;
EFI_DEVICE_PATH_PROTOCOL *DevPath;
EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader;
@@ -836,7 +597,6 @@ ProcessManFile(
CmdFileName = NULL;
CmdFilePathName = NULL;
CmdFileImgHandle = NULL;
- StringBuff = NULL;
PackageListHeader = NULL;
FileDevPath = NULL;
DevPath = NULL;
@@ -846,11 +606,17 @@ ProcessManFile(
//
TempString = ShellCommandGetCommandHelp(Command);
if (TempString != NULL) {
- TempString2 = TempString;
- Status = ManBufferFindTitleSection(&TempString2, Command, BriefDesc, &BriefSize);
+ FileHandle = ConvertEfiFileProtocolToShellHandle (CreateFileInterfaceMem (TRUE), NULL);
+ HelpSize = StrLen (TempString) * sizeof (CHAR16);
+ ShellWriteFile (FileHandle, &HelpSize, TempString);
+ ShellSetFilePosition (FileHandle, 0);
+ HelpSize = 0;
+ BriefSize = 0;
+ Status = ManFileFindTitleSection(FileHandle, Command, BriefDesc, &BriefSize, &Ascii);
if (!EFI_ERROR(Status) && HelpText != NULL){
- Status = ManBufferFindSections(TempString2, Sections, HelpText, &HelpSize);
+ Status = ManFileFindSections(FileHandle, Sections, HelpText, &HelpSize, Ascii);
}
+ ShellCloseFile (&FileHandle);
} else {
//
// If the image is a external app, check .MAN file first.
@@ -947,20 +713,26 @@ ProcessManFile(
StringIdWalker = 1;
do {
- SHELL_FREE_NON_NULL(StringBuff);
+ SHELL_FREE_NON_NULL(TempString);
if (BriefDesc != NULL) {
SHELL_FREE_NON_NULL(*BriefDesc);
}
- StringBuff = HiiGetString (mShellManHiiHandle, (EFI_STRING_ID)StringIdWalker, NULL);
- if (StringBuff == NULL) {
+ TempString = HiiGetString (mShellManHiiHandle, (EFI_STRING_ID)StringIdWalker, NULL);
+ if (TempString == NULL) {
Status = EFI_NOT_FOUND;
goto Done;
}
- TempString2 = StringBuff;
- Status = ManBufferFindTitleSection(&TempString2, Command, BriefDesc, &BriefSize);
+ FileHandle = ConvertEfiFileProtocolToShellHandle (CreateFileInterfaceMem (TRUE), NULL);
+ HelpSize = StrLen (TempString) * sizeof (CHAR16);
+ ShellWriteFile (FileHandle, &HelpSize, TempString);
+ ShellSetFilePosition (FileHandle, 0);
+ HelpSize = 0;
+ BriefSize = 0;
+ Status = ManFileFindTitleSection(FileHandle, Command, BriefDesc, &BriefSize, &Ascii);
if (!EFI_ERROR(Status) && HelpText != NULL){
- Status = ManBufferFindSections(TempString2, Sections, HelpText, &HelpSize);
+ Status = ManFileFindSections(FileHandle, Sections, HelpText, &HelpSize, Ascii);
}
+ ShellCloseFile (&FileHandle);
if (!EFI_ERROR(Status)){
//
// Found what we need and return
@@ -969,7 +741,7 @@ ProcessManFile(
}
StringIdWalker += 1;
- } while (StringIdWalker < 0xFFFF && StringBuff != NULL);
+ } while (StringIdWalker < 0xFFFF && TempString != NULL);
}
@@ -992,7 +764,6 @@ Done:
Status = gBS->UnloadImage (CmdFileImgHandle);
}
- SHELL_FREE_NON_NULL(StringBuff);
SHELL_FREE_NON_NULL(TempString);
SHELL_FREE_NON_NULL(CmdFileName);
SHELL_FREE_NON_NULL(CmdFilePathName);