diff --git a/freeldr/FREELDR.INI b/freeldr/FREELDR.INI index ddc948ecc3d..da0b10f4940 100644 --- a/freeldr/FREELDR.INI +++ b/freeldr/FREELDR.INI @@ -1,71 +1,71 @@ -# FreeLoader by Brian Palmer -# FREELDR.INI - FreeLoader Initialization file -# -# Each line must be less than 1024 characters long -# and must be either a section heading (i.e. [section_name]) -# or a setting (i.e. name=value) or a blank line. -# Comments start with a '#' character. +; FreeLoader by Brian Palmer +; FREELDR.INI - FreeLoader Initialization file +; +; Each line must be less than 1024 characters long +; and must be either a section heading (i.e. [section_name]) +; or a setting (i.e. name=value) or a blank line. +; Comments start with a ';' character. -# Background colors can be any one of the following: -# Black -# Blue -# Green -# Cyan -# Red -# Magenta -# Brown -# Gray +; Background colors can be any one of the following: +; Black +; Blue +; Green +; Cyan +; Red +; Magenta +; Brown +; Gray -# Text colors can be any one of the background -# colors and any of the following: -# DarkGray -# LightBlue -# LightGreen -# LightCyan -# LightRed -# LightMagenta -# Yellow -# White +; Text colors can be any one of the background +; colors and any of the following: +; DarkGray +; LightBlue +; LightGreen +; LightCyan +; LightRed +; LightMagenta +; Yellow +; White -# [FREELOADER] Section Commands: -# -# MessageBox - displays the specified text in a message box upon bootup -# MessageLine - adds a new line of text to a message box (must come before MessageBox command) -# TitleText - text that is displayed in the title box -# StatusBarColor - color of status bar's background -# StatusBarTextColor - color of status bar's text -# BackdropTextColor - color of the backdrop's fill -# BackdropColor - color of the backdrop's background -# BackdropFillStyle - backdrop fill style - can be Light, Medium, or Dark -# TitleBoxTextColor - title box text color -# TitleBoxColor - title box background color -# MessageBoxTextColor - message box text color -# MessageBoxColor - message box background color -# MenuTextColor - menu text color -# MenuColor - menu color -# TextColor - normal text color -# SelectedTextColor - selected text color -# SelectedColor - selected text background color -# TimeOut - sets the timeout (in seconds) before the first OS listed gets booted automagically +; [FREELOADER] Section Commands: +; +; MessageBox - displays the specified text in a message box upon bootup +; MessageLine - adds a new line of text to a message box (must come before MessageBox command) +; TitleText - text that is displayed in the title box +; StatusBarColor - color of status bar's background +; StatusBarTextColor - color of status bar's text +; BackdropTextColor - color of the backdrop's fill +; BackdropColor - color of the backdrop's background +; BackdropFillStyle - backdrop fill style - can be Light, Medium, or Dark +; TitleBoxTextColor - title box text color +; TitleBoxColor - title box background color +; MessageBoxTextColor - message box text color +; MessageBoxColor - message box background color +; MenuTextColor - menu text color +; MenuColor - menu color +; TextColor - normal text color +; SelectedTextColor - selected text color +; SelectedColor - selected text background color +; TimeOut - sets the timeout (in seconds) before the first OS listed gets booted automagically -# [OS-General] Section Commands: -# -# BootType - sets the boot type: ReactOS, Linux, BootSector, Partition, Drive -# BootDrive - sets the boot drive: 0 - first floppy, 1 - second floppy, 0x80 - first hard disk, 0x81 - second hard disk -# BootPartition - sets the boot partition +; [OS-General] Section Commands: +; +; BootType - sets the boot type: ReactOS, Linux, BootSector, Partition, Drive +; BootDrive - sets the boot drive: 0 - first floppy, 1 - second floppy, 0x80 - first hard disk, 0x81 - second hard disk +; BootPartition - sets the boot partition -# [BootSector OSType] Section Commands: -# -# BootSector - sets the filename of the bootsector to be loaded +; [BootSector OSType] Section Commands: +; +; BootSector - sets the filename of the bootsector to be loaded -# [ReactOS OSType] Section Commands: -# -# SystemPath - sets the system root path (must be a valid ARC - Path): -# multi(0)disk(0)rdisk(0)partition(1)\reactos -# multi(0)disk(0)fdisk(0) -# Options - sets the command line options for the kernel being booted -# Kernel - sets the kernel filename -# Driver - sets the name of one or more drivers to be loaded (one entry per driver) +; [ReactOS OSType] Section Commands: +; +; SystemPath - sets the system root path (must be a valid ARC - Path): +; multi(0)disk(0)rdisk(0)partition(1)\reactos +; multi(0)disk(0)fdisk(0) +; Options - sets the command line options for the kernel being booted +; Kernel - sets the kernel filename +; Driver - sets the name of one or more drivers to be loaded (one entry per driver) @@ -76,8 +76,8 @@ MessageLine= MessageBox=Edit your FREELDR.INI file to change your boot settings. OS=ReactOS (HD) OS=ReactOS (Floppy) -#OS=ReactOS (Debug) -#OS=Linux +;OS=ReactOS (Debug) +;OS=Linux OS=3« Floppy (A:) OS=Microsoft Windows (C:) OS=Drive D: @@ -101,8 +101,8 @@ TextColor=Yellow SelectedTextColor=Black SelectedColor=Gray -# Load ReactOS from harddisk (drive C:) -# - does not work on large harddisks +; Load ReactOS from harddisk (drive C:) +; - does not work on large harddisks [ReactOS (HD)] Name="ReactOS (HardDrive)" BootType=ReactOS @@ -113,7 +113,7 @@ Hal=\REACTOS\SYSTEM32\HAL.DLL Driver=\REACTOS\SYSTEM32\DRIVERS\IDE.SYS Driver=\REACTOS\SYSTEM32\DRIVERS\VFATFS.SYS -# Load ReactOS from floppy (drive A:) +; Load ReactOS from floppy (drive A:) [ReactOS (Floppy)] Name="ReactOS (Floppy)" BootType=ReactOS @@ -124,22 +124,22 @@ Hal=\reactos\HAL.DLL Driver=\reactos\IDE.SYS Driver=\reactos\VFATFS.SYS -#[ReactOS (Debug)] -#Name="ReactOS (Debug)" -#BootType=ReactOS -#BootDrive=0 -#Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=19200 -#Kernel=\NTOSKRNL.EXE -#Hal=\HAL.DLL -#Driver=\DRIVERS\IDE.SYS -#Driver=\DRIVERS\VFATFS.SYS +;[ReactOS (Debug)] +;Name="ReactOS (Debug)" +;BootType=ReactOS +;BootDrive=0 +;Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=19200 +;Kernel=\NTOSKRNL.EXE +;Hal=\HAL.DLL +;Driver=\DRIVERS\IDE.SYS +;Driver=\DRIVERS\VFATFS.SYS -#[Linux] -#Name="Linux" -# Linux boot type not implemented yet -#BootType=Partition -#BootDrive=0x80 -#BootPartition=2 +;[Linux] +;Name="Linux" +; Linux boot type not implemented yet +;BootType=Partition +;BootDrive=0x80 +;BootPartition=2 [3« Floppy (A:)] Name="3« Floppy (A:)" diff --git a/freeldr/freeldr/Makefile b/freeldr/freeldr/Makefile index 7b2e4127eaa..a9427fdb6d2 100644 --- a/freeldr/freeldr/Makefile +++ b/freeldr/freeldr/Makefile @@ -24,10 +24,10 @@ include rules.mk # reactos.o tui.o menu.o miscboot.o options.o linux.o multiboot.o arcname.o \ # mem.o memory.o debug.o parseini.o registry.o import.o #ASM_OBJS = asmcode.o mb.o boot.o mem.o -OBJS = freeldr.o miscboot.o options.o linux.o multiboot.o debug.o parseini.o oslist.o -LIBS = arch rtl fs ui reactos comm disk mm cache +OBJS = freeldr.o miscboot.o options.o linux.o multiboot.o debug.o oslist.o +LIBS = arch rtl fs ui reactos comm disk mm cache inifile LIB_FILES = arch/arch.a rtl/rtl.a fs/fs.a ui/ui.a reactos/reactos.a -LIB_FILES2 = comm/comm.a disk/disk.a mm/mm.a cache/cache.a +LIB_FILES2 = comm/comm.a disk/disk.a mm/mm.a cache/cache.a inifile/inifile.a .PHONY : clean @@ -67,9 +67,6 @@ multiboot.o: multiboot.c freeldr.h rtl.h fs.h multiboot.h ui.h debug.o: debug.c debug.h $(CC) $(FLAGS) -o debug.o -c debug.c -parseini.o: parseini.c parseini.h - $(CC) $(FLAGS) -o parseini.o -c parseini.c - oslist.o: oslist.c oslist.h $(CC) $(FLAGS) -o oslist.o -c oslist.c @@ -103,6 +100,9 @@ mm: cache: $(MAKE) -C cache +inifile: + $(MAKE) -C inifile + .PHONY : $(LIBS) clean: @@ -118,3 +118,4 @@ clean: $(MAKE) -C fs clean $(MAKE) -C rtl clean $(MAKE) -C cache clean + $(MAKE) -C inifile clean diff --git a/freeldr/freeldr/freeldr.c b/freeldr/freeldr/freeldr.c index 7ed45be6a80..5e4b1c435b3 100644 --- a/freeldr/freeldr/freeldr.c +++ b/freeldr/freeldr/freeldr.c @@ -26,7 +26,7 @@ #include "miscboot.h" #include "linux.h" #include "mm.h" -#include "parseini.h" +#include "inifile.h" #include "debug.h" #include "oslist.h" #include "cache.h" @@ -58,14 +58,14 @@ VOID BootMain(VOID) InitMemoryManager(); - if (!ParseIniFile()) + if (!IniFileInitialize()) { printf("Press any key to reboot.\n"); getch(); return; } - if (!OpenSection("FreeLoader", &SectionId)) + if (!IniOpenSection("FreeLoader", &SectionId)) { printf("Section [FreeLoader] not found in freeldr.ini.\n"); getch(); @@ -109,7 +109,7 @@ VOID BootMain(VOID) } // Try to open the operating system section in the .ini file - if (!OpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId)) + if (!IniOpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId)) { sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]); MessageBox(SettingName); @@ -117,7 +117,7 @@ VOID BootMain(VOID) } // Try to read the boot type - if (!ReadSectionSettingByName(SectionId, "BootType", SettingValue, 80)) + if (!IniReadSettingByName(SectionId, "BootType", SettingValue, 80)) { sprintf(SettingName, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames[SelectedOperatingSystem]); MessageBox(SettingName); @@ -160,12 +160,12 @@ ULONG GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], ULONG OperatingSys ULONG DefaultOS = 0; ULONG Idx; - if (!OpenSection("FreeLoader", &SectionId)) + if (!IniOpenSection("FreeLoader", &SectionId)) { return 0; } - if (ReadSectionSettingByName(SectionId, "DefaultOS", DefaultOSText, 80)) + if (IniReadSettingByName(SectionId, "DefaultOS", DefaultOSText, 80)) { for (Idx=0; Idx + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __PARSEINI_H +#define __PARSEINI_H + +BOOL IniFileInitialize(VOID); + +BOOL IniOpenSection(PUCHAR SectionName, PULONG SectionId); +ULONG IniGetNumSectionItems(ULONG SectionId); +BOOL IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize); +BOOL IniReadSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize); + + +#endif // defined __PARSEINI_H diff --git a/freeldr/freeldr/inifile/ini.h b/freeldr/freeldr/inifile/ini.h index 3fc08b97250..58c0acfec9a 100644 --- a/freeldr/freeldr/inifile/ini.h +++ b/freeldr/freeldr/inifile/ini.h @@ -52,4 +52,21 @@ typedef struct } INI_SECTION, *PINI_SECTION; +extern PINI_SECTION IniFileSectionListHead; +extern ULONG IniFileSectionListCount; + +BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize); +ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset); +ULONG IniGetNextLine(PUCHAR IniFileData, ULONG IniFileSize, PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset); +BOOL IniIsLineEmpty(PUCHAR LineOfText, ULONG TextLength); +BOOL IniIsCommentLine(PUCHAR LineOfText, ULONG TextLength); +BOOL IniIsSectionName(PUCHAR LineOfText, ULONG TextLength); +ULONG IniGetSectionNameSize(PUCHAR SectionNameLine, ULONG LineLength); +VOID IniExtractSectionName(PUCHAR SectionName, PUCHAR SectionNameLine, ULONG LineLength); +BOOL IniIsSetting(PUCHAR LineOfText, ULONG TextLength); +ULONG IniGetSettingNameSize(PUCHAR SettingNameLine, ULONG LineLength); +ULONG IniGetSettingValueSize(PUCHAR SettingValueLine, ULONG LineLength); +VOID IniExtractSettingName(PUCHAR SettingName, PUCHAR SettingNameLine, ULONG LineLength); +VOID IniExtractSettingValue(PUCHAR SettingValue, PUCHAR SettingValueLine, ULONG LineLength); + #endif // defined __INI_H diff --git a/freeldr/freeldr/inifile/inifile.c b/freeldr/freeldr/inifile/inifile.c index aafe03357c2..ede7b7a94de 100644 --- a/freeldr/freeldr/inifile/inifile.c +++ b/freeldr/freeldr/inifile/inifile.c @@ -17,417 +17,114 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "freeldr.h" -#include "parseini.h" -#include "ui.h" -#include "fs.h" -#include "rtl.h" -#include "mm.h" -#include "debug.h" +#include +#include "ini.h" +#include +#include +#include -PUCHAR FreeLoaderIniFileData = NULL; -ULONG FreeLoaderIniFileSize = 0; - -BOOL ParseIniFile(VOID) +BOOL IniOpenSection(PUCHAR SectionName, PULONG SectionId) { - //int i; - //char name[1024]; - //char value[1024]; - PFILE Freeldr_Ini; // File handle for freeldr.ini + PINI_SECTION Section; - // Open the boot drive for file access - if (!OpenDiskDrive(BootDrive, 0)) + DbgPrint((DPRINT_INIFILE, "IniOpenSection() SectionName = %s\n", SectionName)); + + // Loop through each section and find the one they want + Section = (PINI_SECTION)RtlListGetHead((PLIST_ITEM)IniFileSectionListHead); + while (Section != NULL) { - printf("Error opening boot drive for file access.\n"); - return FALSE; - } - - // Try to open freeldr.ini or fail - Freeldr_Ini = OpenFile("freeldr.ini"); - if (Freeldr_Ini == NULL) - { - printf("FREELDR.INI not found.\nYou need to re-install FreeLoader.\n"); - return FALSE; - } - - // Get the file size & allocate enough memory for it - FreeLoaderIniFileSize = GetFileSize(Freeldr_Ini); - FreeLoaderIniFileData = AllocateMemory(FreeLoaderIniFileSize); - - // If we are out of memory then return FALSE - if (FreeLoaderIniFileData == NULL) - { - printf("Out of memory while loading FREELDR.INI.\n"); - CloseFile(Freeldr_Ini); - return FALSE; - } - - // Read freeldr.ini off the disk - ReadFile(Freeldr_Ini, FreeLoaderIniFileSize, NULL, FreeLoaderIniFileData); - CloseFile(Freeldr_Ini); - - // Make sure the [FREELOADER] section exists - /*if (OpenSection("FREELOADER", NULL)) - { - printf("Section [FREELOADER] not found in FREELDR.INI.\nYou need to re-install FreeLoader.\n"); - return FALSE; - } - - // Validate the settings in the [FREELOADER] section - for (i=1; i<=GetNumSectionItems("FREELOADER"); i++) - { - ReadSectionSettingByNumber("FREELOADER", i, name, value); - if (!IsValidSetting(name, value)) + // Compare against the section name + if (stricmp(SectionName, Section->SectionName) == 0) { - printf("Invalid setting in freeldr.ini.\nName: \"%s\", Value: \"%s\"\n", name, value); - printf("Press any key to continue.\n"); - getch(); - } - else - SetSetting(name, value); - }*/ - - return TRUE; -} - -ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset) -{ - ULONG Idx; - - // Loop through grabbing chars until we hit the end of the - // file or we encounter a new line char - for (Idx=0; (CurrentOffset < FreeLoaderIniFileSize); CurrentOffset++) - { - // If we haven't exceeded our buffer size yet - // then store another char - if (Idx < (BufferSize - 1)) - { - Buffer[Idx++] = FreeLoaderIniFileData[CurrentOffset]; + // We found it + *SectionId = (ULONG)Section; + DbgPrint((DPRINT_INIFILE, "IniOpenSection() Found it! SectionId = 0x%x\n", SectionId)); + return TRUE; } - // Check for new line char - if (FreeLoaderIniFileData[CurrentOffset] == '\n') - { - CurrentOffset++; - break; - } + // Get the next section in the list + Section = (PINI_SECTION)RtlListGetNext((PLIST_ITEM)Section); } - // Terminate the string - Buffer[Idx] = '\0'; - - // Get rid of newline & linefeed characters (if any) - if((Buffer[strlen(Buffer)-1] == '\n') || (Buffer[strlen(Buffer)-1] == '\r')) - Buffer[strlen(Buffer)-1] = '\0'; - if((Buffer[strlen(Buffer)-1] == '\n') || (Buffer[strlen(Buffer)-1] == '\r')) - Buffer[strlen(Buffer)-1] = '\0'; - - // Send back new offset - return CurrentOffset; -} - -BOOL OpenSection(PUCHAR SectionName, PULONG SectionId) -{ - UCHAR TempString[80]; - UCHAR RealSectionName[80]; - ULONG FileOffset; - BOOL SectionFound = FALSE; - - // - // Get the real section name - // - strcpy(RealSectionName, "["); - strcat(RealSectionName, SectionName); - strcat(RealSectionName, "]"); - - // - // Get to the beginning of the file - // - FileOffset = 0; - - // - // Find the section - // - while (FileOffset < FreeLoaderIniFileSize) - { - // - // Read a line - // - FileOffset = GetNextLineOfFileData(TempString, 80, FileOffset); - - // - // If it isn't a section header then continue on - // - if (TempString[0] != '[') - continue; - - // - // Check and see if we found it - // - if (stricmp(TempString, RealSectionName) == 0) - { - SectionFound = TRUE; - break; - } - } - - if (SectionId) - { - *SectionId = FileOffset; - } - - return SectionFound; -} - -ULONG GetNumSectionItems(ULONG SectionId) -{ - UCHAR TempString[80]; - ULONG SectionItemCount = 0; - - // Now count how many settings are in this section - while (SectionId < FreeLoaderIniFileSize) - { - // Read a line - SectionId = GetNextLineOfFileData(TempString, 80, SectionId); - - // If we hit a new section then we're done - if (TempString[0] == '[') - break; - - // Skip comments - if (TempString[0] == '#') - continue; - - // Skip blank lines - if (!strlen(TempString)) - continue; - - SectionItemCount++; - } - - return SectionItemCount; -} - -BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize) -{ - UCHAR TempString[1024]; - ULONG SectionItemCount = 0; - ULONG Idx; - ULONG FileOffset; - - // - // Get to the beginning of the section - // - FileOffset = SectionId; - - // - // Now find the setting we are looking for - // - do - { - // Read a line - FileOffset = GetNextLineOfFileData(TempString, 1024, FileOffset); - - // Skip comments - if (TempString[0] == '#') - continue; - - // Skip blank lines - if (!strlen(TempString)) - continue; - - // If we hit a new section then we're done - if (TempString[0] == '[') - break; - - // Check and see if we found the setting - if (SectionItemCount == SettingNumber) - { - for (Idx=0; IdxSectionItemCount)); - // - // Now find the setting we are looking for - // - while (FileOffset < FreeLoaderIniFileSize) + return Section->SectionItemCount; +} + +BOOL IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize) +{ + PINI_SECTION Section = (PINI_SECTION)SectionId; + PINI_SECTION_ITEM SectionItem; + ULONG RealSettingNumber = SettingNumber; + + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId)); + + // Loop through each section item and find the one they want + SectionItem = (PINI_SECTION_ITEM)RtlListGetHead((PLIST_ITEM)Section->SectionItemList); + while (SectionItem != NULL) { - // Read a line - FileOffset = GetNextLineOfFileData(TempString, 1024, FileOffset); - - // Skip comments - if (TempString[0] == '#') - continue; - - // Skip blank lines - if (!strlen(TempString)) - continue; - - // If we hit a new section then we're done - if (TempString[0] == '[') - break; - - // Extract the setting name - for (Idx=0; IdxItemName)); + DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue)); + + strncpy(SettingName, SectionItem->ItemName, NameSize); + strncpy(SettingValue, SectionItem->ItemValue, ValueSize); + + return TRUE; } - // Check and see if we found the setting - if (stricmp(TempBuffer, SettingName) == 0) - { - for (Idx=0; IdxItemValue)); + + strncpy(Buffer, SectionItem->ItemValue, BufferSize); + return TRUE; + } + + // Get the next section item in the list + SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem); } - else if(stricmp(setting, "StatusBarTextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "BackdropTextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "BackdropColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "BackdropFillStyle") == 0) - { - if(IsValidFillStyle(value)) - return TRUE; - } - else if(stricmp(setting, "TitleBoxTextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "TitleBoxColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "MessageBoxTextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "MessageBoxColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "MenuTextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "MenuColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "TextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "SelectedTextColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "SelectedColor") == 0) - { - if(IsValidColor(value)) - return TRUE; - } - else if(stricmp(setting, "OS") == 0) - return TRUE; - else if(stricmp(setting, "TimeOut") == 0) - return TRUE; - /*else if(stricmp(setting, "") == 0) - return TRUE; - else if(stricmp(setting, "") == 0) - return TRUE; - else if(stricmp(setting, "") == 0) - return TRUE; - else if(stricmp(setting, "") == 0) - return TRUE; - else if(stricmp(setting, "") == 0) - return TRUE; - else if(stricmp(setting, "") == 0) - return TRUE; - else if(stricmp(setting, "") == 0) - return TRUE;*/ + + DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' not found.\n", SettingName)); return FALSE; } diff --git a/freeldr/freeldr/inifile/inifile.h b/freeldr/freeldr/inifile/inifile.h deleted file mode 100644 index 363e8e591be..00000000000 --- a/freeldr/freeldr/inifile/inifile.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * FreeLoader - * Copyright (C) 1998-2002 Brian Palmer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef __PARSEINI_H -#define __PARSEINI_H - -/*BOOL ParseIniFile(void); -ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset); // Gets the next line of text (up to BufferSize) after CurrentOffset and returns the offset of the next line -ULONG GetOffsetOfFirstLineOfSection(PUCHAR SectionName); // Returns the offset of the first line in the section or zero if the section wasn't found -ULONG GetNumSectionItems(PUCHAR SectionName); // returns the number of items in a particular section (i.e. [FREELOADER]) -BOOL ReadSectionSettingByNumber(PUCHAR SectionName, ULONG SettingNumber, PUCHAR SettingName, PUCHAR SettingValue); // Reads the num'th value from section -BOOL ReadSectionSettingByName(PUCHAR SectionName, PUCHAR SettingName, PUCHAR SettingValue); // Reads the value named name from section -BOOL IsValidSetting(char *setting, char *value); -void SetSetting(char *setting, char *value);*/ - -BOOL ParseIniFile(VOID); -ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset); -BOOL OpenSection(PUCHAR SectionName, PULONG SectionId); -ULONG GetNumSectionItems(ULONG SectionId); -BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize); -BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize); -BOOL IsValidSetting(char *setting, char *value); - - -#endif // defined __PARSEINI_H diff --git a/freeldr/freeldr/inifile/init.c b/freeldr/freeldr/inifile/init.c index e93eed3f019..4bcb53d875f 100644 --- a/freeldr/freeldr/inifile/init.c +++ b/freeldr/freeldr/inifile/init.c @@ -19,18 +19,18 @@ #include #include "ini.h" -#include #include #include #include #include -BOOL InitializeIniFile(VOID) +BOOL IniFileInitialize(VOID) { PFILE Freeldr_Ini; // File handle for freeldr.ini PUCHAR FreeLoaderIniFileData; ULONG FreeLoaderIniFileSize; + BOOL Success; // Open the boot drive for file access if (!OpenDiskDrive(BootDrive, 0)) @@ -68,7 +68,11 @@ BOOL InitializeIniFile(VOID) } CloseFile(Freeldr_Ini); + + // Parse the .ini file data + Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize); + FreeMemory(FreeLoaderIniFileData); - return TRUE; + return Success; } diff --git a/freeldr/freeldr/inifile/parse.c b/freeldr/freeldr/inifile/parse.c index ea255370ab3..6e5212e3d71 100644 --- a/freeldr/freeldr/inifile/parse.c +++ b/freeldr/freeldr/inifile/parse.c @@ -19,15 +19,170 @@ #include #include "ini.h" -#include -#include #include #include #include -VOID IniParseFile(PUCHAR IniFileData, ULONG IniFileSize) +PINI_SECTION IniFileSectionListHead = NULL; +ULONG IniFileSectionCount = 0; +ULONG IniFileSettingCount = 0; + + +BOOL IniParseFile(PUCHAR IniFileData, ULONG IniFileSize) { + ULONG CurrentOffset; + ULONG CurrentLineNumber; + PUCHAR IniFileLine; + ULONG IniFileLineSize; + ULONG LineLength; + PINI_SECTION CurrentSection = NULL; + PINI_SECTION_ITEM CurrentItem = NULL; + + DbgPrint((DPRINT_INIFILE, "IniParseFile() IniFileSize: %d\n", IniFileSize)); + + // Start with an 80-byte buffer + IniFileLineSize = 80; + IniFileLine = AllocateMemory(IniFileLineSize); + if (!IniFileLine) + { + return FALSE; + } + + // Loop through each line and parse it + CurrentLineNumber = 0; + CurrentOffset = 0; + while (CurrentOffset < IniFileSize) + { + // First check the line size and increase our buffer if necessary + if (IniFileLineSize < IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset)) + { + IniFileLineSize = IniGetNextLineSize(IniFileData, IniFileSize, CurrentOffset); + FreeMemory(IniFileLine); + IniFileLine = AllocateMemory(IniFileLineSize); + if (!IniFileLine) + { + return FALSE; + } + } + + // Get the line of data + CurrentOffset = IniGetNextLine(IniFileData, IniFileSize, IniFileLine, IniFileLineSize, CurrentOffset); + LineLength = strlen(IniFileLine); + + // If it is a blank line or a comment then skip it + if (IniIsLineEmpty(IniFileLine, LineLength) || IniIsCommentLine(IniFileLine, LineLength)) + { + CurrentLineNumber++; + continue; + } + + // Check if it is a new section + if (IniIsSectionName(IniFileLine, LineLength)) + { + // Allocate a new section structure + CurrentSection = AllocateMemory(sizeof(INI_SECTION)); + if (!CurrentSection) + { + FreeMemory(IniFileLine); + return FALSE; + } + + RtlZeroMemory(CurrentSection, sizeof(INI_SECTION)); + + // Allocate the section name buffer + CurrentSection->SectionName = AllocateMemory(IniGetSectionNameSize(IniFileLine, LineLength)); + if (!CurrentSection->SectionName) + { + FreeMemory(CurrentSection); + FreeMemory(IniFileLine); + return FALSE; + } + + // Get the section name + IniExtractSectionName(CurrentSection->SectionName, IniFileLine, LineLength); + + // Add it to the section list head + IniFileSectionCount++; + if (IniFileSectionListHead == NULL) + { + IniFileSectionListHead = CurrentSection; + } + else + { + RtlListInsertTail((PLIST_ITEM)IniFileSectionListHead, (PLIST_ITEM)CurrentSection); + } + + CurrentLineNumber++; + continue; + } + + // Check if it is a setting + if (IniIsSetting(IniFileLine, LineLength)) + { + // First check to make sure we're inside a [section] + if (CurrentSection == NULL) + { + printf("Error: freeldr.ini:%d: Setting \'%s\' found outside of a [section].\n", CurrentLineNumber, IniFileLine); + CurrentLineNumber++; + continue; + } + + // Allocate a new item structure + CurrentItem = AllocateMemory(sizeof(INI_SECTION_ITEM)); + if (!CurrentItem) + { + FreeMemory(IniFileLine); + return FALSE; + } + + RtlZeroMemory(CurrentItem, sizeof(INI_SECTION_ITEM)); + + // Allocate the setting name buffer + CurrentItem->ItemName = AllocateMemory(IniGetSettingNameSize(IniFileLine, LineLength)); + if (!CurrentItem->ItemName) + { + FreeMemory(CurrentItem); + FreeMemory(IniFileLine); + return FALSE; + } + + // Allocate the setting value buffer + CurrentItem->ItemValue = AllocateMemory(IniGetSettingValueSize(IniFileLine, LineLength)); + if (!CurrentItem->ItemValue) + { + FreeMemory(CurrentItem); + FreeMemory(IniFileLine); + return FALSE; + } + + // Get the section name + IniExtractSettingName(CurrentItem->ItemName, IniFileLine, LineLength); + IniExtractSettingValue(CurrentItem->ItemValue, IniFileLine, LineLength); + + // Add it to the current section + IniFileSettingCount++; + CurrentSection->SectionItemCount++; + if (CurrentSection->SectionItemList == NULL) + { + CurrentSection->SectionItemList = CurrentItem; + } + else + { + RtlListInsertTail((PLIST_ITEM)CurrentSection->SectionItemList, (PLIST_ITEM)CurrentItem); + } + + CurrentLineNumber++; + continue; + } + + CurrentLineNumber++; + } + + DbgPrint((DPRINT_INIFILE, "Parsed %d sections and %d settings.\n", IniFileSectionCount, IniFileSettingCount)); + DbgPrint((DPRINT_INIFILE, "IniParseFile() done.\n")); + + return TRUE; } ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOffset) @@ -35,7 +190,7 @@ ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOff ULONG Idx; ULONG LineCharCount = 0; - // Loop through grabbing chars until we hit the end of the + // Loop through counting chars until we hit the end of the // file or we encounter a new line char for (Idx=0; (CurrentOffset < IniFileSize); CurrentOffset++) { @@ -50,6 +205,9 @@ ULONG IniGetNextLineSize(PUCHAR IniFileData, ULONG IniFileSize, ULONG CurrentOff } } + // Add one for the NULL-terminator + LineCharCount++; + // Send back line character count return LineCharCount; } @@ -94,8 +252,7 @@ BOOL IniIsLineEmpty(PUCHAR LineOfText, ULONG TextLength) { ULONG Idx; - // Check the first character (skipping whitespace) - // and make sure that it is an opening bracket + // Check for text (skipping whitespace) for (Idx=0; Idx - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "freeldr.h" -#include "parseini.h" -#include "ui.h" -#include "fs.h" -#include "rtl.h" -#include "mm.h" -#include "debug.h" - -PUCHAR FreeLoaderIniFileData = NULL; -ULONG FreeLoaderIniFileSize = 0; - -BOOL ParseIniFile(VOID) -{ - //int i; - //char name[1024]; - //char value[1024]; - PFILE Freeldr_Ini; // File handle for freeldr.ini - - // Open the boot drive for file access - if (!OpenDiskDrive(BootDrive, 0)) - { - printf("Error opening boot drive for file access.\n"); - return FALSE; - } - - // Try to open freeldr.ini or fail - Freeldr_Ini = OpenFile("freeldr.ini"); - if (Freeldr_Ini == NULL) - { - printf("FREELDR.INI not found.\nYou need to re-install FreeLoader.\n"); - return FALSE; - } - - // Get the file size & allocate enough memory for it - FreeLoaderIniFileSize = GetFileSize(Freeldr_Ini); - FreeLoaderIniFileData = AllocateMemory(FreeLoaderIniFileSize); - - // If we are out of memory then return FALSE - if (FreeLoaderIniFileData == NULL) - { - printf("Out of memory while loading FREELDR.INI.\n"); - CloseFile(Freeldr_Ini); - return FALSE; - } - - // Read freeldr.ini off the disk - ReadFile(Freeldr_Ini, FreeLoaderIniFileSize, NULL, FreeLoaderIniFileData); - CloseFile(Freeldr_Ini); - - // Make sure the [FREELOADER] section exists - /*if (OpenSection("FREELOADER", NULL)) - { - printf("Section [FREELOADER] not found in FREELDR.INI.\nYou need to re-install FreeLoader.\n"); - return FALSE; - } - - // Validate the settings in the [FREELOADER] section - for (i=1; i<=GetNumSectionItems("FREELOADER"); i++) - { - ReadSectionSettingByNumber("FREELOADER", i, name, value); - if (!IsValidSetting(name, value)) - { - printf("Invalid setting in freeldr.ini.\nName: \"%s\", Value: \"%s\"\n", name, value); - printf("Press any key to continue.\n"); - getch(); - } - else - SetSetting(name, value); - }*/ - - return TRUE; -} - -ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset) -{ - ULONG Idx; - - // Loop through grabbing chars until we hit the end of the - // file or we encounter a new line char - for (Idx=0; (CurrentOffset < FreeLoaderIniFileSize); CurrentOffset++) - { - // If we haven't exceeded our buffer size yet - // then store another char - if (Idx < (BufferSize - 1)) - { - Buffer[Idx++] = FreeLoaderIniFileData[CurrentOffset]; - } - - // Check for new line char - if (FreeLoaderIniFileData[CurrentOffset] == '\n') - { - CurrentOffset++; - break; - } - } - - // Terminate the string - Buffer[Idx] = '\0'; - - // Get rid of newline & linefeed characters (if any) - if((Buffer[strlen(Buffer)-1] == '\n') || (Buffer[strlen(Buffer)-1] == '\r')) - Buffer[strlen(Buffer)-1] = '\0'; - if((Buffer[strlen(Buffer)-1] == '\n') || (Buffer[strlen(Buffer)-1] == '\r')) - Buffer[strlen(Buffer)-1] = '\0'; - - // Send back new offset - return CurrentOffset; -} - -BOOL OpenSection(PUCHAR SectionName, PULONG SectionId) -{ - UCHAR TempString[80]; - UCHAR RealSectionName[80]; - ULONG FileOffset; - BOOL SectionFound = FALSE; - - // - // Get the real section name - // - strcpy(RealSectionName, "["); - strcat(RealSectionName, SectionName); - strcat(RealSectionName, "]"); - - // - // Get to the beginning of the file - // - FileOffset = 0; - - // - // Find the section - // - while (FileOffset < FreeLoaderIniFileSize) - { - // - // Read a line - // - FileOffset = GetNextLineOfFileData(TempString, 80, FileOffset); - - // - // If it isn't a section header then continue on - // - if (TempString[0] != '[') - continue; - - // - // Check and see if we found it - // - if (stricmp(TempString, RealSectionName) == 0) - { - SectionFound = TRUE; - break; - } - } - - if (SectionId) - { - *SectionId = FileOffset; - } - - return SectionFound; -} - -ULONG GetNumSectionItems(ULONG SectionId) -{ - UCHAR TempString[80]; - ULONG SectionItemCount = 0; - - // Now count how many settings are in this section - while (SectionId < FreeLoaderIniFileSize) - { - // Read a line - SectionId = GetNextLineOfFileData(TempString, 80, SectionId); - - // If we hit a new section then we're done - if (TempString[0] == '[') - break; - - // Skip comments - if (TempString[0] == '#') - continue; - - // Skip blank lines - if (!strlen(TempString)) - continue; - - SectionItemCount++; - } - - return SectionItemCount; -} - -BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize) -{ - UCHAR TempString[1024]; - ULONG SectionItemCount = 0; - ULONG Idx; - ULONG FileOffset; - - // - // Get to the beginning of the section - // - FileOffset = SectionId; - - // - // Now find the setting we are looking for - // - do - { - // Read a line - FileOffset = GetNextLineOfFileData(TempString, 1024, FileOffset); - - // Skip comments - if (TempString[0] == '#') - continue; - - // Skip blank lines - if (!strlen(TempString)) - continue; - - // If we hit a new section then we're done - if (TempString[0] == '[') - break; - - // Check and see if we found the setting - if (SectionItemCount == SettingNumber) - { - for (Idx=0; Idx #include #include -#include +#include #include "registry.h" #include "hwdetect.h" @@ -384,7 +384,7 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) // Open the operating system section // specified in the .ini file // - if (!OpenSection(OperatingSystemName, &SectionId)) + if (!IniOpenSection(OperatingSystemName, &SectionId)) { sprintf(MsgBuffer,"Operating System section '%s' not found in freeldr.ini", OperatingSystemName); MessageBox(MsgBuffer); @@ -421,7 +421,7 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) /* * Make sure the system path is set in the .ini file */ - if (!ReadSectionSettingByName(SectionId, "SystemPath", value, 1024)) + if (!IniReadSettingByName(SectionId, "SystemPath", value, 1024)) { MessageBox("System path not specified for selected operating system."); return; @@ -447,7 +447,7 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) /* * Read the optional kernel parameters (if any) */ - if (ReadSectionSettingByName(SectionId, "Options", value, 1024)) + if (IniReadSettingByName(SectionId, "Options", value, 1024)) { strcat(multiboot_kernel_cmdline, " "); strcat(multiboot_kernel_cmdline, value); @@ -481,7 +481,7 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) * Find the kernel image name * and try to load the kernel off the disk */ - if(ReadSectionSettingByName(SectionId, "Kernel", value, 1024)) + if(IniReadSettingByName(SectionId, "Kernel", value, 1024)) { /* * Set the name and @@ -512,7 +512,7 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) * Find the HAL image name * and try to load the kernel off the disk */ - if(ReadSectionSettingByName(SectionId, "Hal", value, 1024)) + if(IniReadSettingByName(SectionId, "Hal", value, 1024)) { /* * Set the name and @@ -543,7 +543,7 @@ void LoadAndBootReactOS(PUCHAR OperatingSystemName) * Find the System hive image name * and try to load it off the disk */ - if(ReadSectionSettingByName(SectionId, "SystemHive", value, 1024)) + if(IniReadSettingByName(SectionId, "SystemHive", value, 1024)) { /* * Set the name and diff --git a/freeldr/freeldr/ui/tui.c b/freeldr/freeldr/ui/tui.c index a9f0e6926d8..3ed5257e67d 100644 --- a/freeldr/freeldr/ui/tui.c +++ b/freeldr/freeldr/ui/tui.c @@ -22,7 +22,7 @@ #include #include #include -#include +#include ULONG nScreenWidth = 80; // Screen Width ULONG nScreenHeight = 25; // Screen Height @@ -64,65 +64,65 @@ BOOL InitUserInterface(VOID) DbgPrint((DPRINT_UI, "Reading in UI settings from [Display] section.\n")); - if (OpenSection("Display", &SectionId)) + if (IniOpenSection("Display", &SectionId)) { - if (ReadSectionSettingByName(SectionId, "TitleText", SettingText, 260)) + if (IniReadSettingByName(SectionId, "TitleText", SettingText, 260)) { strcpy(szTitleBoxTitleText, SettingText); } - if (ReadSectionSettingByName(SectionId, "StatusBarColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "StatusBarColor", SettingText, 260)) { cStatusBarBgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "StatusBarTextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "StatusBarTextColor", SettingText, 260)) { cStatusBarFgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "BackdropTextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "BackdropTextColor", SettingText, 260)) { cBackdropFgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "BackdropColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "BackdropColor", SettingText, 260)) { cBackdropBgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "BackdropFillStyle", SettingText, 260)) + if (IniReadSettingByName(SectionId, "BackdropFillStyle", SettingText, 260)) { cBackdropFillStyle = TextToFillStyle(SettingText); } - if (ReadSectionSettingByName(SectionId, "TitleBoxTextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "TitleBoxTextColor", SettingText, 260)) { cTitleBoxFgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "TitleBoxColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "TitleBoxColor", SettingText, 260)) { cTitleBoxBgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "MessageBoxTextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "MessageBoxTextColor", SettingText, 260)) { cMessageBoxFgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "MessageBoxColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "MessageBoxColor", SettingText, 260)) { cMessageBoxBgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "MenuTextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "MenuTextColor", SettingText, 260)) { cMenuFgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "MenuColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "MenuColor", SettingText, 260)) { cMenuBgColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "TextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "TextColor", SettingText, 260)) { cTextColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "SelectedTextColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "SelectedTextColor", SettingText, 260)) { cSelectedTextColor = TextToColor(SettingText); } - if (ReadSectionSettingByName(SectionId, "SelectedColor", SettingText, 260)) + if (IniReadSettingByName(SectionId, "SelectedColor", SettingText, 260)) { cSelectedTextBgColor = TextToColor(SettingText); } @@ -724,7 +724,7 @@ void ShowMessageBoxesInSection(PUCHAR SectionName) UCHAR SettingValue[80]; ULONG SectionId; - if (!OpenSection(SectionName, &SectionId)) + if (!IniOpenSection(SectionName, &SectionId)) { sprintf(SettingName, "Section %s not found in freeldr.ini.\n", SectionName); MessageBox(SettingName); @@ -734,9 +734,9 @@ void ShowMessageBoxesInSection(PUCHAR SectionName) // // Find all the message box settings and run them // - for (Idx=0; Idx