String function Support library
Add string functionality in Osloader to a common library Signed-off-by: Subash Lakkimsetti <subash.lakkimsetti@intel.com>
This commit is contained in:
parent
163d60408f
commit
47a15937a1
|
@ -0,0 +1,109 @@
|
|||
/** @file
|
||||
Header file for string function support library
|
||||
|
||||
Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _STRING_SUPPORT_LIB_H_
|
||||
#define _STRING_SUPPORT_LIB_H_
|
||||
|
||||
#include <Library/BootloaderCommonLib.h>
|
||||
|
||||
/**
|
||||
Get next line start pointer.
|
||||
|
||||
@param[in] Start The pointer for current line.
|
||||
@param[out] Length The UINT32 pointer to receive the length of current line.
|
||||
|
||||
@retval The pointer for next line.
|
||||
NULL if no more line is available.
|
||||
**/
|
||||
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
GetNextLine (
|
||||
IN CHAR8 *Start,
|
||||
OUT UINT32 *Length
|
||||
);
|
||||
|
||||
/**
|
||||
Trim leading white space for a line.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
TrimLeft (
|
||||
IN CHAR8 *Line
|
||||
);
|
||||
|
||||
/**
|
||||
Get next space for the start of a line.
|
||||
|
||||
@param[in] LineStart The pointer to the start of the line buffer.
|
||||
@param[in] LineEnd The pointer to the end of the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
GetNextSpace (
|
||||
IN CHAR8 *LineStart,
|
||||
IN CHAR8 *LineEnd
|
||||
);
|
||||
|
||||
/**
|
||||
Trim trailing white space for a line.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
TrimRight (
|
||||
IN CHAR8 *Line
|
||||
);
|
||||
|
||||
/**
|
||||
Check if a line starts with a known keyword.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
@param[in] Keyword The pointer to the keyword.
|
||||
|
||||
@retval Length of the matched keyword.
|
||||
0 if there is no match.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
EFIAPI
|
||||
MatchKeyWord (
|
||||
IN CHAR8 *Line,
|
||||
IN CHAR8 *Keyword
|
||||
);
|
||||
|
||||
/**
|
||||
Check if a line matches varaible assignment syntax.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
@param[in] Variable The pointer to the variable name.
|
||||
|
||||
@retval Length of the matched variable name.
|
||||
0 if there is no match.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
EFIAPI
|
||||
MatchAssignment (
|
||||
IN CHAR8 *Line,
|
||||
IN CHAR8 *Variable
|
||||
);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,195 @@
|
|||
/** @file
|
||||
String support library implementation.
|
||||
|
||||
Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
|
||||
**/
|
||||
|
||||
#include <Library/StringSupportLib.h>
|
||||
|
||||
/**
|
||||
Get next line start pointer.
|
||||
|
||||
@param[in] Start The pointer for current line.
|
||||
@param[out] Length The UINT32 pointer to receive the length of current line.
|
||||
|
||||
@retval The pointer for next line.
|
||||
NULL if no more line is available.
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
GetNextLine (
|
||||
IN CHAR8 *Start,
|
||||
OUT UINT32 *Length
|
||||
)
|
||||
{
|
||||
CHAR8 *Ptr;
|
||||
|
||||
if (Start == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Ptr = Start;
|
||||
while ((Ptr[0] != 0) && (Ptr[0] != '\n')) {
|
||||
Ptr++;
|
||||
}
|
||||
|
||||
if (Length != NULL){
|
||||
*Length = (UINT32)(Ptr - Start);
|
||||
}
|
||||
|
||||
if (Ptr[0] == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
return Ptr + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Trim leading white space for a line.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
TrimLeft (
|
||||
IN CHAR8 *Line
|
||||
)
|
||||
{
|
||||
if (Line == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((Line[0] == ' ') || (Line[0] == '\t')) {
|
||||
Line++;
|
||||
}
|
||||
return Line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get next space for the start of a line.
|
||||
|
||||
@param[in] LineStart The pointer to the start of the line buffer.
|
||||
@param[in] LineEnd The pointer to the end of the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
GetNextSpace (
|
||||
IN CHAR8 *LineStart,
|
||||
IN CHAR8 *LineEnd
|
||||
)
|
||||
{
|
||||
CHAR8 *Line;
|
||||
|
||||
if ((LineStart == NULL) || (LineEnd == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Line = LineStart;
|
||||
while ((Line[0] != 0) && (Line[0] != ' ') && (Line[0] != '\t') && (Line < LineEnd)) {
|
||||
Line++;
|
||||
}
|
||||
return Line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Trim trailing white space for a line.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
CHAR8 *
|
||||
EFIAPI
|
||||
TrimRight (
|
||||
IN CHAR8 *Line
|
||||
)
|
||||
{
|
||||
if (Line == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while ((Line[0] == ' ') || (Line[0] == '\t') || (Line[0] == '\r') || (Line[0] == '\n')) {
|
||||
Line--;
|
||||
}
|
||||
return Line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Check if a line starts with a known keyword.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
@param[in] Keyword The pointer to the keyword.
|
||||
|
||||
@retval Length of the matched keyword.
|
||||
0 if there is no match.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
EFIAPI
|
||||
MatchKeyWord (
|
||||
IN CHAR8 *Line,
|
||||
IN CHAR8 *Keyword
|
||||
)
|
||||
{
|
||||
UINT32 KeywordLen;
|
||||
|
||||
if ((Line == NULL) || (Keyword == NULL)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
KeywordLen = (UINT32)AsciiStrLen (Keyword);
|
||||
if (AsciiStrnCmp (Line, Keyword, KeywordLen) == 0) {
|
||||
// A separator is required to follow the keyword
|
||||
if (((Line[KeywordLen] == 0)) || (Line[KeywordLen] == ' ') || (Line[KeywordLen] == '\t')) {
|
||||
return KeywordLen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Check if a line matches varaible assignment syntax.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
@param[in] Variable The pointer to the variable name.
|
||||
|
||||
@retval Length of the matched variable name.
|
||||
0 if there is no match.
|
||||
|
||||
**/
|
||||
UINT32
|
||||
EFIAPI
|
||||
MatchAssignment (
|
||||
IN CHAR8 *Line,
|
||||
IN CHAR8 *Variable
|
||||
)
|
||||
{
|
||||
UINT32 VarLen;
|
||||
|
||||
if ((Line == NULL) || (Variable == NULL)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
VarLen = (UINT32)AsciiStrLen (Variable);
|
||||
if (AsciiStrnCmp (Line, Variable, VarLen) == 0) {
|
||||
if (Line[VarLen] == '=') {
|
||||
return VarLen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
## @file
|
||||
# String Support Library Instance.
|
||||
#
|
||||
# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = StringSupportLib
|
||||
FILE_GUID = BB1506A8-93C9-11EA-BB37-0242AC130002
|
||||
MODULE_TYPE = BASE
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = StringSupportLib
|
||||
|
||||
[Sources]
|
||||
StringSupportLib.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
BootloaderCommonPkg/BootloaderCommonPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
|
|
@ -118,6 +118,8 @@
|
|||
SortLib|BootloaderCommonPkg/Library/SortLib/SortLib.inf
|
||||
IoMmuLib|BootloaderCommonPkg/Library/IoMmuLib/IoMmuLib.inf
|
||||
MtrrLib|BootloaderCommonPkg/Library/MtrrLib/MtrrLib.inf
|
||||
StringSupportLib|BootloaderCommonPkg/Library/StringSupportLib/StringSupportLib.inf
|
||||
|
||||
|
||||
!if $(ENABLE_SOURCE_DEBUG)
|
||||
DebugAgentLib|BootloaderCommonPkg/Library/DebugAgentLib/DebugAgentLib.inf
|
||||
|
|
|
@ -7,164 +7,6 @@
|
|||
|
||||
#include "OsLoader.h"
|
||||
|
||||
/**
|
||||
Get next line start pointer.
|
||||
|
||||
@param[in] Start The pointer for current line.
|
||||
@param[out] Length The UINT32 pointer to receive the length of current line.
|
||||
|
||||
@retval The pointer for next line.
|
||||
NULL if no more line is available.
|
||||
**/
|
||||
STATIC
|
||||
CHAR8 *
|
||||
GetNextLine (
|
||||
IN CHAR8 *Start,
|
||||
OUT UINT32 *Length
|
||||
)
|
||||
{
|
||||
CHAR8 *Ptr;
|
||||
|
||||
Ptr = Start;
|
||||
while ((Ptr[0] != 0) && (Ptr[0] != '\n')) {
|
||||
Ptr++;
|
||||
}
|
||||
|
||||
*Length = (UINT32)(Ptr - Start);
|
||||
if (Ptr[0] == 0) {
|
||||
return NULL;
|
||||
} else {
|
||||
return Ptr + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Trim leading white space for a line.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
CHAR8 *
|
||||
TrimLeft (
|
||||
IN CHAR8 *Line
|
||||
)
|
||||
{
|
||||
while ((Line[0] == ' ') || (Line[0] == '\t')) {
|
||||
Line++;
|
||||
}
|
||||
return Line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Get next space for the start of a line.
|
||||
|
||||
@param[in] LineStart The pointer to the start of the line buffer.
|
||||
@param[in] LineEnd The pointer to the end of the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
CHAR8 *
|
||||
GetNextSpace (
|
||||
IN CHAR8 *LineStart,
|
||||
IN CHAR8 *LineEnd
|
||||
)
|
||||
{
|
||||
CHAR8 *Line;
|
||||
|
||||
Line = LineStart;
|
||||
while ((Line[0] != 0) && (Line[0] != ' ') && (Line[0] != '\t') && (Line < LineEnd)) {
|
||||
Line++;
|
||||
}
|
||||
return Line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Trim trailing white space for a line.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
|
||||
@retval The pointer to the trimmed line.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
CHAR8 *
|
||||
TrimRight (
|
||||
IN CHAR8 *Line
|
||||
)
|
||||
{
|
||||
while ((Line[0] == ' ') || (Line[0] == '\t') || (Line[0] == '\r') || (Line[0] == '\n')) {
|
||||
Line--;
|
||||
}
|
||||
return Line;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Check if a line starts with a known keyword.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
@param[in] Keyword The pointer to the keyword.
|
||||
|
||||
@retval Length of the matched keyword.
|
||||
0 if there is no match.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
UINT32
|
||||
MatchKeyWord (
|
||||
IN CHAR8 *Line,
|
||||
IN CHAR8 *Keyword
|
||||
)
|
||||
{
|
||||
UINT32 KeywordLen;
|
||||
|
||||
KeywordLen = (UINT32)AsciiStrLen (Keyword);
|
||||
if (AsciiStrnCmp (Line, Keyword, KeywordLen) == 0) {
|
||||
// A separator is required to follow the keyword
|
||||
if (((Line[KeywordLen] == 0)) || (Line[KeywordLen] == ' ') || (Line[KeywordLen] == '\t')) {
|
||||
return KeywordLen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Check if a line matches varaible assignment syntax.
|
||||
|
||||
@param[in] Line The pointer to the line buffer.
|
||||
@param[in] Variable The pointer to the variable name.
|
||||
|
||||
@retval Length of the matched variable name.
|
||||
0 if there is no match.
|
||||
|
||||
**/
|
||||
STATIC
|
||||
UINT32
|
||||
MatchAssignment (
|
||||
IN CHAR8 *Line,
|
||||
IN CHAR8 *Variable
|
||||
)
|
||||
{
|
||||
UINT32 VarLen;
|
||||
|
||||
VarLen = (UINT32)AsciiStrLen (Variable);
|
||||
if (AsciiStrnCmp (Line, Variable, VarLen) == 0) {
|
||||
if (Line[VarLen] == '=') {
|
||||
return VarLen;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Parse the Linux boot configuration file.
|
||||
|
|
|
@ -62,6 +62,8 @@
|
|||
#include <ConfigDataCommonDefs.h>
|
||||
#include <Register/Intel/Msr/ArchitecturalMsr.h>
|
||||
#include "PreOsChecker.h"
|
||||
#include <Library/StringSupportLib.h>
|
||||
|
||||
|
||||
#define MKHI_BOOTLOADER_SEED_LEN 64
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@
|
|||
LiteFvLib
|
||||
LinuxLib
|
||||
ContainerLib
|
||||
StringSupportLib
|
||||
|
||||
[Guids]
|
||||
gOsConfigDataGuid
|
||||
|
|
Loading…
Reference in New Issue