Partial BlConfigParseIniFile() implementation

This commit is contained in:
Jozef Nagy 2023-12-06 16:18:13 +01:00
parent 36df83431b
commit 25e3ec112d
No known key found for this signature in database
GPG Key ID: 5F72C3BF3BD614D8
4 changed files with 61 additions and 72 deletions

View File

@ -66,7 +66,7 @@ file(RELATIVE_PATH _PATH_PREFIX ${EXECTOS_BINARY_DIR} ${EXECTOS_SOURCE_DIR})
add_compiler_flags(-D__RELFILE__="&__FILE__[__FILE__[0] == '.' ? sizeof \\\"${_PATH_PREFIX}\\\" - 1 : sizeof XTOS_SOURCE_DIR]")
# Set the virtual disk image size (in MiB)
set_disk_image_size(16)
set_disk_image_size(128)
# Build all subprojects
add_subdirectory(bootdata)

View File

@ -13,7 +13,7 @@
* Parses configuration INI file contents.
*
* @param FileContents
* Supplies a pointer to a wide string containing contents of the configuration file.
* Supplies a pointer to a string containing contents of the configuration file.
*
* @param Sections
* Supplies a pointer to a linked list which will be written by this routine.
@ -27,93 +27,82 @@ XTSTATUS
BlConfigParseIniFile(IN PWCHAR FileContents,
OUT PLIST_ENTRY Sections)
{
PWCHAR Argument, LastArg, CurrentSectionName;
SIZE_T Length;
PWCHAR Line, LastLine, Key, Value;
SIZE_T Length, KeyLength;
/* Set a default section name */
CurrentSectionName = L"Unknown";
UINT Error;
/* There's not error at the moment */
Error = 0;
/* Tokenize provided options */
Argument = RtlWideStringTokenize(FileContents, L"\r\n", &LastArg);
Line = RtlWideStringTokenize(FileContents, L"\n", &LastLine);
/* Iterate over all arguments passed to boot loader */
while(Argument != NULL)
while(Line != NULL)
{
/* Check every line */
if(RtlWideStringCompare(Argument, L"\r\n", 2) == 0)
{
/* We can safely ignore a newline */
Argument += 2;
}
else if(RtlWideStringCompare(Argument, L"#", 1) == 0)
{
/* We can safely ignore a comment */
Argument += 1;
}
else if(RtlWideStringCompare(Argument, L"[", 1) == 0)
{
/* Skip to the section name */
Argument += 1;
Length = RtlWideStringLength(Argument, 0);
Length = RtlWideStringLength(Line, 0);
/* Everything until ']' belongs to the section's name */
// CurrentSectionName = RtlWideStringTokenize(Argument, L"]", &LastArg);
BlConsolePrint(L"New section: %S\n", CurrentSectionName);
}
else if(RtlWideStringCompare(Argument, L"Default=", 8) == 0)
/* Don't parse a blank line */
if(Length <= 0)
{
/* Skip to the argument value and calculate argument length */
Argument += 8;
Length = RtlWideStringLength(Argument, 0);
/* Set a default section */
BlConsolePrint(L"Setting DEFAULT value to %S\n", Argument);
continue;
}
else if(RtlWideStringCompare(Argument, L"Debug=", 6) == 0)
{
/* Skip to the argument value */
Argument += 6;
Length = RtlWideStringLength(Argument, 0);
/* Set a debug port and baud rate */
BlConsolePrint(L"Setting DEBUG value to %S\n", Argument);
/* Parse */
if (Length < 1)
{
/* Blank line */
}
else if(RtlWideStringCompare(Argument, L"Theme=", 6) == 0)
else if (RtlWideStringCompare(Line, L"#", 1) == 0 ||
RtlWideStringCompare(Line, L";", 1) == 0)
{
/* Skip to the argument value */
Argument += 6;
Length = RtlWideStringLength(Argument, 0);
/* Set a theme name */
BlConsolePrint(L"Setting THEME value to %S\n", Argument);
/* Don't parse a comment */
}
else if(RtlWideStringCompare(Argument, L"Timeout=", 8) == 0)
else if (RtlWideStringCompare(Line, L"[", 1) == 0 &&
RtlWideStringCompare(Line + Length - 3, L"]", 1) == 0)
{
/* Skip to the argument value */
Argument += 8;
Length = RtlWideStringLength(Argument, 0);
/* Remove brackets around section name */
PWCHAR SectionName = Line + 1;
SectionName[Length - 3] = 0;
/* Set a timeout */
BlConsolePrint(L"Setting TIMEOUT value to %S\n", Argument);
}
else if(RtlWideStringCompare(Argument, L"Tune=", 5) == 0)
{
/* Skip to the argument value */
Argument += 5;
Length = RtlWideStringLength(Argument, 0);
/* Set a tune */
BlConsolePrint(L"Setting TUNE value to %S\n", Argument);
/* Save section name */
BlConsolePrint(L"Section: %S\n", SectionName);
}
else
{
/* Configuration file might be corrupt */
BlConsolePrint(L"Unknown argument: %S\n", Argument);
KeyLength = 0;
/* Set key=value pair to the entire line for further processing */
Value = Line;
Key = Line;
/* Get the value */
while(Value != 0 &&
RtlWideStringCompare(Value, L"=", 1) != 0)
{
Value++;
KeyLength++;
}
/* Get rid of the leading '=' */
Value++;
/* Set the key */
Key[KeyLength] = 0;
BlConsolePrint(L"Key: %S\n Value: %S\n", Key, Value);
}
if(Error == 1)
{
/* Display error message and exit */
BlConsolePrint(L"Syntax error\n");
return STATUS_INVALID_PARAMETER;
}
/* Take next argument */
Argument = RtlWideStringTokenize(NULL, L"\n", &LastArg);
/* Take next line */
Line = RtlWideStringTokenize(NULL, L"\n", &LastLine);
}
return STATUS_SUCCESS;

View File

@ -11,7 +11,6 @@
#include <xtbmapi.h>
/* XT Boot Loader configuration data */
EXTERN XTBM_CONFIGURATION BlpConfiguration;

View File

@ -39,10 +39,11 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
/* Initialize UEFI console and early print XTLDR version */
BlConsoleInitialize();
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
/* Parse INI Configuration file */
BlConfigParseIniFile(L"# This is the XT Boot Loader (XTLDR) configuration file. It follows an INI format and is divided into sections, which\r\n# contain a properties. Each property has a name and value delimited by an equal (=) character. Comments must start\r\n# with a semicolon (;) or a hash character (#) and run to the end of the line.\r\n#\r\n# Basic section is [XTLDR] which contains a bootloader specific options:\r\n# Debug - enables the debugging port and consists of two comma-separated parameters: com port and baud rate;\r\n# it is also possible to specify custom port address with: COM0:[address],[baud_rate]\r\n# Default - specifies which operating system listen in config file will be started if no choice is made\r\n# Theme - allows to set a custom theme to personalize XTLDR's look'n'feel\r\n# Timeout - sets the countdown timer (in seconds) before the default OS get started automatically\r\n# Tune - plays a tune on the pcspeaker right before the XTLDR loads\r\n#\r\n# Another type of section is [OS-Section] which adds a new position (operating system) to the boot menu. Each type\r\n# of the operating system provides a set of available parameters. If unsupported option is added, it is being ignored\r\n# by the XT Boot Loader. The available options are:\r\n# SystemName - sets a long operating system name that will be shown on the boot menu\r\n# SystemType - specifies an OS type from a predefined list of supported boot protocols\r\n# SystemPath - the ARC path, eg. multi(0)disk(0)rdisk(0)partition(1)\r\n# KernelFile - sets kernel filename with optional path relative to SystemPath\r\n# InitrdFile - sets initramfs image filename with optional path relative to SystemPath\r\n# HalFile - sets HAL filename with optional path relative to SystemPath\r\n# Parameters - specifies extra boot options for the kernel\r\n[XTLDR]Tune=400 880 2 988 2 783 2 392 2 587 3Debug=COM1,115200Timeout=30Theme=FancyDefault=ExectOS[ExectOS]SystemName=\"ExectOS Operating System\"SystemType=XTOSSystemPath=multi(0)disk(0)rdisk(0)partition(1)/ExectOSKernelFile=xtoskrnl.exeParameters=DEBUG DEBUGPORT=COM1,115200[Windows]SystemName=\"Microsoft Windows 2000\"SystemType=NT50SystemPath=multi(0)disk(0)rdisk(0)partition(2)/WindowsKernelFile=ntoskrnl.exeHalFile=hal.dllParameters=/NOGUIBOOT /MININT[Linux]SystemName=\"GNU/Linux\"SystemType=LINUXSystemPath=multi(0)disk(0)rdisk(0)partition(3)/bootKernelFile=vmlinuzInitrdFile=initramfs.cpio.gzParameters=root=/dev/xvda3 rootfstype=ext4", &ConfigSections);
BlConfigParseIniFile(L"# This is the XT Boot Loader (XTLDR) configuration file. It follows an INI format and is divided into sections, which\n# contain a properties. Each property has a name and value delimited by an equal (=) character. Comments must start\n# with a semicolon (;) or a hash character (#) and run to the end of the line.\n#\n# Basic section is [XTLDR] which contains a bootloader specific options:\n# Debug - enables the debugging port and consists of two comma-separated parameters: com port and baud rate;\n# it is also possible to specify custom port address with: COM0:[address],[baud_rate]\n# Default - specifies which operating system listen in config file will be started if no choice is made\n# Theme - allows to set a custom theme to personalize XTLDR's look'n'feel\n# Timeout - sets the countdown timer (in seconds) before the default OS get started automatically\n# Tune - plays a tune on the pcspeaker right before the XTLDR loads\n#\n# Another type of section is [OS-Section] which adds a new position (operating system) to the boot menu. Each type\n# of the operating system provides a set of available parameters. If unsupported option is added, it is being ignored\n# by the XT Boot Loader. The available options are:\n# SystemName - sets a long operating system name that will be shown on the boot menu\n# SystemType - specifies an OS type from a predefined list of supported boot protocols\n# SystemPath - the ARC path, eg. multi(0)disk(0)rdisk(0)partition(1)\n# KernelFile - sets kernel filename with optional path relative to SystemPath\n# InitrdFile - sets initramfs image filename with optional path relative to SystemPath\n# HalFile - sets HAL filename with optional path relative to SystemPath\n# Parameters - specifies extra boot options for the kernel\n[XTLDR]Tune=400 880 2 988 2 783 2 392 2 587 3Debug=COM1,115200Timeout=30Theme=FancyDefault=ExectOS[ExectOS]SystemName=\"ExectOS Operating System\"SystemType=XTOSSystemPath=multi(0)disk(0)rdisk(0)partition(1)/ExectOSKernelFile=xtoskrnl.exeParameters=DEBUG DEBUGPORT=COM1,115200[Windows]SystemName=\"Microsoft Windows 2000\"SystemType=NT50SystemPath=multi(0)disk(0)rdisk(0)partition(2)/WindowsKernelFile=ntoskrnl.exeHalFile=hal.dllParameters=/NOGUIBOOT /MININT[Linux]SystemName=\"GNU/Linux\"SystemType=LINUXSystemPath=multi(0)disk(0)rdisk(0)partition(3)/bootKernelFile=vmlinuzInitrdFile=initramfs.cpio.gzParameters=root=/dev/xvda3 rootfstype=ext4", &ConfigSections);
BlConsolePrint(L"XTLDR boot loader v%s\n", XTOS_VERSION);
/* Temporary infinite loop */
for(;;);