INI configuration parser for XTLDR
This commit is contained in:
105
xtldr2/config.c
105
xtldr2/config.c
@@ -4,10 +4,115 @@
|
||||
* FILE: xtldr/config.c
|
||||
* DESCRIPTION: XT Boot Loader Configuration
|
||||
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||
* Jozef Nagy <schkwve@gmail.com>
|
||||
*/
|
||||
|
||||
#include <xtbm.h>
|
||||
|
||||
/**
|
||||
* Parses configuration INI file contents.
|
||||
*
|
||||
* @param FileContents
|
||||
* Supplies a pointer to a wide string containing contents of the configuration file.
|
||||
*
|
||||
* @param Sections
|
||||
* Supplies a pointer to a linked list which will be written by this routine.
|
||||
*
|
||||
* @return This routine returns a status code.
|
||||
*
|
||||
* @since XT 1.0
|
||||
*/
|
||||
XTCDECL
|
||||
XTSTATUS
|
||||
BlConfigParseIniFile(IN PWCHAR FileContents,
|
||||
OUT PLIST_ENTRY Sections)
|
||||
{
|
||||
PWCHAR Argument, LastArg, CurrentSectionName;
|
||||
SIZE_T Length;
|
||||
|
||||
/* Set a default section name */
|
||||
CurrentSectionName = L"Unknown";
|
||||
|
||||
/* Tokenize provided options */
|
||||
Argument = RtlWideStringTokenize(FileContents, L"\r\n", &LastArg);
|
||||
|
||||
/* Iterate over all arguments passed to boot loader */
|
||||
while(Argument != NULL)
|
||||
{
|
||||
/* Check every line */
|
||||
if(RtlWideStringCompare(Argument, L"[", 1) == 0)
|
||||
{
|
||||
/* Skip to the section name */
|
||||
Argument += 1;
|
||||
Length = RtlWideStringLength(Argument, 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)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else if(RtlWideStringCompare(Argument, L"Theme=", 6) == 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);
|
||||
}
|
||||
else if(RtlWideStringCompare(Argument, L"Timeout=", 8) == 0)
|
||||
{
|
||||
/* Skip to the argument value */
|
||||
Argument += 8;
|
||||
Length = RtlWideStringLength(Argument, 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);
|
||||
}
|
||||
else if(RtlWideStringCompare(Argument, L"#", 1) == 0)
|
||||
{
|
||||
/* We can safely ignore a comment */
|
||||
Argument += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Configuration file might be corrupt */
|
||||
BlConsolePrint(L"Unknown argument: %S\n", Argument);
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
/* Take next argument */
|
||||
Argument = RtlWideStringTokenize(NULL, L"\n", &LastArg);
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses command line arguments and updates global configuration.
|
||||
|
||||
Reference in New Issue
Block a user