Rewrote .ini file code - should be much faster (especially in bochs)
authorBrian Palmer <brianp@sginet.com>
Wed, 20 Mar 2002 00:39:32 +0000 (00:39 +0000)
committerBrian Palmer <brianp@sginet.com>
Wed, 20 Mar 2002 00:39:32 +0000 (00:39 +0000)
Leading whitespace in a line is now ignored
Changed .ini file comment character from '#' to ';' to be compatible with MS
There is still a mysterious memory allocation failed bug however!?

svn path=/trunk/; revision=2741

16 files changed:
freeldr/FREELDR.INI
freeldr/freeldr/Makefile
freeldr/freeldr/freeldr.c
freeldr/freeldr/inifile.h [new file with mode: 0644]
freeldr/freeldr/inifile/ini.h
freeldr/freeldr/inifile/inifile.c
freeldr/freeldr/inifile/inifile.h [deleted file]
freeldr/freeldr/inifile/init.c
freeldr/freeldr/inifile/parse.c
freeldr/freeldr/miscboot.c
freeldr/freeldr/multiboot.c
freeldr/freeldr/oslist.c
freeldr/freeldr/parseini.c [deleted file]
freeldr/freeldr/parseini.h [deleted file]
freeldr/freeldr/reactos/reactos.c
freeldr/freeldr/ui/tui.c

index ddc948e..da0b10f 100644 (file)
@@ -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.
-
-# 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
-
-# [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
-
-# [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)
+; 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
+
+; 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
+
+; [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
+
+; [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
-
-#[Linux]
-#Name="Linux"
-# Linux boot type not implemented yet
-#BootType=Partition
-#BootDrive=0x80
-#BootPartition=2
+;[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
 
 [3« Floppy (A:)]
 Name="3« Floppy (A:)"
index 7b2e412..a9427fd 100644 (file)
@@ -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
index 7ed45be..5e4b1c4 100644 (file)
@@ -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<OperatingSystemCount; Idx++)
                {
@@ -186,12 +186,12 @@ LONG GetTimeOut(VOID)
        ULONG   TimeOut;
        ULONG   SectionId;
 
-       if (!OpenSection("FreeLoader", &SectionId))
+       if (!IniOpenSection("FreeLoader", &SectionId))
        {
                return -1;
        }
 
-       if (ReadSectionSettingByName(SectionId, "TimeOut", TimeOutText, 20))
+       if (IniReadSettingByName(SectionId, "TimeOut", TimeOutText, 20))
        {
                TimeOut = atoi(TimeOutText);
        }
diff --git a/freeldr/freeldr/inifile.h b/freeldr/freeldr/inifile.h
new file mode 100644 (file)
index 0000000..2c5d602
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  FreeLoader
+ *  Copyright (C) 1998-2002  Brian Palmer  <brianp@sginet.com>
+ *
+ *  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
index 3fc08b9..58c0acf 100644 (file)
@@ -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
index aafe033..ede7b7a 100644 (file)
  *  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 <freeldr.h>
+#include "ini.h"
+#include <ui.h>
+#include <rtl.h>
+#include <debug.h>
 
-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
-
-       // 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;
-}
+       PINI_SECTION    Section;
 
-ULONG GetNextLineOfFileData(PUCHAR Buffer, ULONG BufferSize, ULONG CurrentOffset)
-{
-       ULONG   Idx;
+       DbgPrint((DPRINT_INIFILE, "IniOpenSection() SectionName = %s\n", SectionName));
 
-       // 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++)
+       // Loop through each section and find the one they want
+       Section = (PINI_SECTION)RtlListGetHead((PLIST_ITEM)IniFileSectionListHead);
+       while (Section != NULL)
        {
-               // If we haven't exceeded our buffer size yet
-               // then store another char
-               if (Idx < (BufferSize - 1))
+               // Compare against the section name
+               if (stricmp(SectionName, Section->SectionName) == 0)
                {
-                       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;
-}
+       DbgPrint((DPRINT_INIFILE, "IniOpenSection() Section not found.\n"));
 
-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;
+       return FALSE;
 }
 
-ULONG GetNumSectionItems(ULONG SectionId)
+ULONG IniGetNumSectionItems(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;
+       PINI_SECTION    Section = (PINI_SECTION)SectionId;
 
-               // Skip comments
-               if (TempString[0] == '#')
-                       continue;
-
-               // Skip blank lines
-               if (!strlen(TempString))
-                       continue;
-
-               SectionItemCount++;
-       }
+       DbgPrint((DPRINT_INIFILE, "IniGetNumSectionItems() SectionId = 0x%x\n", SectionId));
+       DbgPrint((DPRINT_INIFILE, "IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount));
 
-       return SectionItemCount;
+       return Section->SectionItemCount;
 }
 
-BOOL ReadSectionSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize)
+BOOL IniReadSettingByNumber(ULONG SectionId, ULONG SettingNumber, PUCHAR SettingName, ULONG NameSize, PUCHAR SettingValue, ULONG ValueSize)
 {
-       UCHAR   TempString[1024];
-       ULONG   SectionItemCount = 0;
-       ULONG   Idx;
-       ULONG   FileOffset;
+       PINI_SECTION            Section = (PINI_SECTION)SectionId;
+       PINI_SECTION_ITEM       SectionItem;
+       ULONG                           RealSettingNumber = SettingNumber;
 
-       //
-       // Get to the beginning of the section
-       //
-       FileOffset = SectionId;
+       DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() SectionId = 0x%x\n", SectionId));
 
-       //
-       // Now find the setting we are looking for
-       //
-       do
+       // 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;
-
-               // Check and see if we found the setting
-               if (SectionItemCount == SettingNumber)
+               // Check to see if this is the setting they want
+               if (SettingNumber == 0)
                {
-                       for (Idx=0; Idx<strlen(TempString); Idx++)
-                       {
-                               // Check and see if this character is the separator
-                               if (TempString[Idx] == '=')
-                               {
-                                       SettingName[Idx] = '\0';
+                       DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d found.\n", RealSettingNumber));
+                       DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName));
+                       DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue));
 
-                                       strncpy(SettingValue, TempString + Idx + 1, ValueSize);
+                       strncpy(SettingName, SectionItem->ItemName, NameSize);
+                       strncpy(SettingValue, SectionItem->ItemValue, ValueSize);
 
-                                       return TRUE;
-                               }
-                               else if (Idx < NameSize)
-                               {
-                                       SettingName[Idx] = TempString[Idx];
-                               }
-                       }
+                       return TRUE;
                }
 
-               // Increment setting number
-               SectionItemCount++;
+               // Nope, keep going
+               SettingNumber--;
+
+               // Get the next section item in the list
+               SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem);
        }
-       while (FileOffset < FreeLoaderIniFileSize);
+
+       DbgPrint((DPRINT_INIFILE, "IniReadSettingByNumber() Setting number %d not found.\n", RealSettingNumber));
 
        return FALSE;
 }
 
-BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize)
+BOOL IniReadSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize)
 {
-       UCHAR   TempString[1024];
-       UCHAR   TempBuffer[80];
-       ULONG   Idx;
-       ULONG   FileOffset;
+       PINI_SECTION            Section = (PINI_SECTION)SectionId;
+       PINI_SECTION_ITEM       SectionItem;
 
-       //
-       // Get to the beginning of the section
-       //
-       FileOffset = SectionId;
+       DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() SectionId = 0x%x\n", SectionId));
 
-       //
-       // Now find the setting we are looking for
-       //
-       while (FileOffset < FreeLoaderIniFileSize)
+       // 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; Idx<strlen(TempString); Idx++)
+               // Check to see if this is the setting they want
+               if (stricmp(SettingName, SectionItem->ItemName) == 0)
                {
-                       if (TempString[Idx] != '=')
-                               TempBuffer[Idx] = TempString[Idx];
-                       else
-                       {
-                               TempBuffer[Idx] = '\0';
-                               break;
-                       }
-               }
+                       DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting \'%s\' found.\n", SettingName));
+                       DbgPrint((DPRINT_INIFILE, "IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue));
 
-               // Check and see if we found the setting
-               if (stricmp(TempBuffer, SettingName) == 0)
-               {
-                       for (Idx=0; Idx<strlen(TempString); Idx++)
-                       {
-                               // Check and see if this character is the separator
-                               if (TempString[Idx] == '=')
-                               {
-                                       strcpy(Buffer, TempString + Idx + 1);
+                       strncpy(Buffer, SectionItem->ItemValue, BufferSize);
 
-                                       return TRUE;
-                               }
-                       }
+                       return TRUE;
                }
-       }
 
-       return FALSE;
-}
-
-BOOL IsValidSetting(char *setting, char *value)
-{
-       if(stricmp(setting, "MessageBox") == 0)
-               return TRUE;
-       else if(stricmp(setting, "MessageLine") == 0)
-               return TRUE;
-       else if(stricmp(setting, "TitleText") == 0)
-               return TRUE;
-       else if(stricmp(setting, "StatusBarColor") == 0)
-       {
-               if(IsValidColor(value))
-                       return TRUE;
-       }
-       else if(stricmp(setting, "StatusBarTextColor") == 0)
-       {
-               if(IsValidColor(value))
-                       return TRUE;
-       }
-       else if(stricmp(setting, "BackdropTextColor") == 0)
-       {
-               if(IsValidColor(value))
-                       return TRUE;
+               // Get the next section item in the list
+               SectionItem = (PINI_SECTION_ITEM)RtlListGetNext((PLIST_ITEM)SectionItem);
        }
-       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 (file)
index 363e8e5..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *  FreeLoader
- *  Copyright (C) 1998-2002  Brian Palmer  <brianp@sginet.com>
- *
- *  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
index e93eed3..4bcb53d 100644 (file)
 
 #include <freeldr.h>
 #include "ini.h"
-#include <ui.h>
 #include <fs.h>
 #include <rtl.h>
 #include <mm.h>
 #include <debug.h>
 
 
-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;
 }
index ea25537..6e5212e 100644 (file)
 
 #include <freeldr.h>
 #include "ini.h"
-#include <ui.h>
-#include <fs.h>
 #include <rtl.h>
 #include <mm.h>
 #include <debug.h>
 
 
-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<TextLength; Idx++)
        {
                if ((LineOfText[Idx] == ' ') ||
@@ -188,7 +345,7 @@ ULONG IniGetSectionNameSize(PUCHAR SectionNameLine, ULONG LineLength)
        // Skip past the opening bracket
        Idx++;
 
-       // Count the characters up until the closing bracket of EOL
+       // Count the characters up until the closing bracket or EOL
        for (NameSize=0; Idx<LineLength; Idx++)
        {
                if ((SectionNameLine[Idx] == ']') ||
@@ -201,6 +358,9 @@ ULONG IniGetSectionNameSize(PUCHAR SectionNameLine, ULONG LineLength)
                NameSize++;
        }
 
+       // Add one for the NULL-terminator
+       NameSize++;
+
        return NameSize;
 }
 
@@ -226,7 +386,7 @@ VOID IniExtractSectionName(PUCHAR SectionName, PUCHAR SectionNameLine, ULONG Lin
        // Skip past the opening bracket
        Idx++;
 
-       // Count the characters up until the closing bracket of EOL
+       // Count the characters up until the closing bracket or EOL
        for (DestIdx=0; Idx<LineLength; Idx++)
        {
                if ((SectionNameLine[Idx] == ']') ||
@@ -240,4 +400,203 @@ VOID IniExtractSectionName(PUCHAR SectionName, PUCHAR SectionNameLine, ULONG Lin
                DestIdx++;
        }
 
+       // Terminate the string
+       SectionName[DestIdx] = '\0';
+}
+
+BOOL IniIsSetting(PUCHAR LineOfText, ULONG TextLength)
+{
+       ULONG   Idx;
+
+       // Basically just check for an '=' equals sign
+       for (Idx=0; Idx<TextLength; Idx++)
+       {
+               if (LineOfText[Idx] == '=')
+               {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+ULONG IniGetSettingNameSize(PUCHAR SettingNameLine, ULONG LineLength)
+{
+       ULONG   Idx;
+       ULONG   NameSize;
+
+       // Skip whitespace
+       for (Idx=0; Idx<LineLength; Idx++)
+       {
+               if ((SettingNameLine[Idx] == ' ') ||
+                       (SettingNameLine[Idx] == '\t'))
+               {
+                       continue;
+               }
+               else
+               {
+                       break;
+               }
+       }
+
+       // Count the characters up until the '=' equals sign or EOL
+       for (NameSize=0; Idx<LineLength; Idx++)
+       {
+               if ((SettingNameLine[Idx] == '=') ||
+                       (SettingNameLine[Idx] == '\0'))
+               {
+                       break;
+               }
+
+               // Increment the count
+               NameSize++;
+       }
+
+       // Add one for the NULL-terminator
+       NameSize++;
+
+       return NameSize;
+}
+
+ULONG IniGetSettingValueSize(PUCHAR SettingValueLine, ULONG LineLength)
+{
+       ULONG   Idx;
+       ULONG   ValueSize;
+
+       // Skip whitespace
+       for (Idx=0; Idx<LineLength; Idx++)
+       {
+               if ((SettingValueLine[Idx] == ' ') ||
+                       (SettingValueLine[Idx] == '\t'))
+               {
+                       continue;
+               }
+               else
+               {
+                       break;
+               }
+       }
+
+       // Skip the characters up until the '=' equals sign or EOL
+       for (; Idx<LineLength; Idx++)
+       {
+               if (SettingValueLine[Idx] == '=')
+               {
+                       Idx++;
+                       break;
+               }
+
+               // If we hit EOL then obviously the value size is zero
+               if (SettingValueLine[Idx] == '\0')
+               {
+                       return 0;
+               }
+       }
+
+       // Count the characters up until the EOL
+       for (ValueSize=0; Idx<LineLength; Idx++)
+       {
+               if (SettingValueLine[Idx] == '\0')
+               {
+                       break;
+               }
+
+               // Increment the count
+               ValueSize++;
+       }
+
+       // Add one for the NULL-terminator
+       ValueSize++;
+
+       return ValueSize;
+}
+
+VOID IniExtractSettingName(PUCHAR SettingName, PUCHAR SettingNameLine, ULONG LineLength)
+{
+       ULONG   Idx;
+       ULONG   DestIdx;
+
+       // Skip whitespace
+       for (Idx=0; Idx<LineLength; Idx++)
+       {
+               if ((SettingNameLine[Idx] == ' ') ||
+                       (SettingNameLine[Idx] == '\t'))
+               {
+                       continue;
+               }
+               else
+               {
+                       break;
+               }
+       }
+
+       // Get the characters up until the '=' equals sign or EOL
+       for (DestIdx=0; Idx<LineLength; Idx++)
+       {
+               if ((SettingNameLine[Idx] == '=') ||
+                       (SettingNameLine[Idx] == '\0'))
+               {
+                       break;
+               }
+
+               // Grab a character and increment DestIdx
+               SettingName[DestIdx] = SettingNameLine[Idx];
+               DestIdx++;
+       }
+
+       // Terminate the string
+       SettingName[DestIdx] = '\0';
+}
+
+VOID IniExtractSettingValue(PUCHAR SettingValue, PUCHAR SettingValueLine, ULONG LineLength)
+{
+       ULONG   Idx;
+       ULONG   DestIdx;
+
+       // Skip whitespace
+       for (Idx=0; Idx<LineLength; Idx++)
+       {
+               if ((SettingValueLine[Idx] == ' ') ||
+                       (SettingValueLine[Idx] == '\t'))
+               {
+                       continue;
+               }
+               else
+               {
+                       break;
+               }
+       }
+
+       // Skip the characters up until the '=' equals sign or EOL
+       for (; Idx<LineLength; Idx++)
+       {
+               if (SettingValueLine[Idx] == '=')
+               {
+                       Idx++;
+                       break;
+               }
+
+               // If we hit EOL then obviously the value size is zero
+               if (SettingValueLine[Idx] == '\0')
+               {
+                       SettingValue[0] = '\0';
+                       return;
+               }
+       }
+
+       // Get the characters up until the EOL
+       for (DestIdx=0; Idx<LineLength; Idx++)
+       {
+               if (SettingValueLine[Idx] == '\0')
+               {
+                       break;
+               }
+
+               // Grab a character and increment DestIdx
+               SettingValue[DestIdx] = SettingValueLine[Idx];
+               DestIdx++;
+       }
+
+       // Terminate the string
+       SettingValue[DestIdx] = '\0';
 }
index f92b46e..019aea3 100644 (file)
@@ -24,7 +24,7 @@
 #include "rtl.h"
 #include "fs.h"
 #include "ui.h"
-#include "parseini.h"
+#include "inifile.h"
 #include "disk.h"
 
 VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
@@ -40,14 +40,14 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
        ShowMessageBoxesInSection(OperatingSystemName);
 
        // Try to open the operating system section in the .ini file
-       if (!OpenSection(OperatingSystemName, &SectionId))
+       if (!IniOpenSection(OperatingSystemName, &SectionId))
        {
                sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
                MessageBox(SettingName);
                return;
        }
 
-       if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
+       if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
        {
                MessageBox("Boot drive not specified for selected OS!");
                return;
@@ -56,12 +56,12 @@ VOID LoadAndBootBootSector(PUCHAR OperatingSystemName)
        BootDrive = atoi(SettingValue);
 
        BootPartition = 0;
-       if (ReadSectionSettingByName(SectionId, "BootPartition", SettingValue, 80))
+       if (IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80))
        {
                BootPartition = atoi(SettingValue);
        }
 
-       if (!ReadSectionSettingByName(SectionId, "BootSectorFile", FileName, 260))
+       if (!IniReadSettingByName(SectionId, "BootSectorFile", FileName, 260))
        {
                MessageBox("Boot sector file not specified for selected OS!");
                return;
@@ -112,7 +112,7 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
        ShowMessageBoxesInSection(OperatingSystemName);
 
        // Try to open the operating system section in the .ini file
-       if (!OpenSection(OperatingSystemName, &SectionId))
+       if (!IniOpenSection(OperatingSystemName, &SectionId))
        {
                sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
                MessageBox(SettingName);
@@ -120,7 +120,7 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
        }
 
        // Read the boot drive
-       if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
+       if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
        {
                MessageBox("Boot drive not specified for selected OS!");
                return;
@@ -129,7 +129,7 @@ VOID LoadAndBootPartition(PUCHAR OperatingSystemName)
        BootDrive = atoi(SettingValue);
 
        // Read the boot partition
-       if (!ReadSectionSettingByName(SectionId, "BootPartition", SettingValue, 80))
+       if (!IniReadSettingByName(SectionId, "BootPartition", SettingValue, 80))
        {
                MessageBox("Boot partition not specified for selected OS!");
                return;
@@ -173,14 +173,14 @@ VOID LoadAndBootDrive(PUCHAR OperatingSystemName)
        ShowMessageBoxesInSection(OperatingSystemName);
 
        // Try to open the operating system section in the .ini file
-       if (!OpenSection(OperatingSystemName, &SectionId))
+       if (!IniOpenSection(OperatingSystemName, &SectionId))
        {
                sprintf(SettingName, "Section [%s] not found in freeldr.ini.\n", OperatingSystemName);
                MessageBox(SettingName);
                return;
        }
 
-       if (!ReadSectionSettingByName(SectionId, "BootDrive", SettingValue, 80))
+       if (!IniReadSettingByName(SectionId, "BootDrive", SettingValue, 80))
        {
                MessageBox("Boot drive not specified for selected OS!");
                return;
index 123e563..1f369cc 100644 (file)
@@ -24,7 +24,7 @@
 #include "fs.h"
 #include "multiboot.h"
 #include "ui.h"
-#include "parseini.h"
+#include "inifile.h"
 
 unsigned long                          next_module_load_base = 0;
 module_t*      pOpenModule = NULL;
@@ -200,9 +200,9 @@ int GetBootPartition(char *OperatingSystemName)
        char    value[1024];
        ULONG   SectionId;
 
-       if (OpenSection(OperatingSystemName, &SectionId))
+       if (IniOpenSection(OperatingSystemName, &SectionId))
        {
-               if (ReadSectionSettingByName(SectionId, "BootPartition", value, 1024))
+               if (IniReadSettingByName(SectionId, "BootPartition", value, 1024))
                {
                        BootPartitionNumber = atoi(value);
                }
index 7b54f78..9dfe7e4 100644 (file)
@@ -18,7 +18,7 @@
  */
        
 #include "freeldr.h"
-#include "parseini.h"
+#include "inifile.h"
 #include "oslist.h"
 #include "rtl.h"
 #include "mm.h"
@@ -40,13 +40,13 @@ BOOL InitOperatingSystemList(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNames
        //
        // Open the [FreeLoader] section
        //
-       if (!OpenSection("FreeLoader", &SectionId))
+       if (!IniOpenSection("FreeLoader", &SectionId))
        {
                MessageBox("Section [FreeLoader] not found in freeldr.ini.");
                return FALSE;
        }
 
-       SectionSettingCount = GetNumSectionItems(SectionId);
+       SectionSettingCount = IniGetNumSectionItems(SectionId);
        OperatingSystemCount = CountOperatingSystems(SectionId);
 
        //
@@ -63,7 +63,7 @@ BOOL InitOperatingSystemList(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNames
        CurrentOperatingSystemIndex = 0;
        for (Idx=0; Idx<SectionSettingCount; Idx++)
        {
-               ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
+               IniReadSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
 
                if (stricmp(SettingName, "OS") == 0)
                {
@@ -78,9 +78,9 @@ BOOL InitOperatingSystemList(PUCHAR **SectionNamesPointer, PUCHAR **DisplayNames
        //
        for (Idx=0; Idx<OperatingSystemCount; Idx++)
        {
-               if (OpenSection(OperatingSystemSectionNames[Idx], &OperatingSystemSectionId))
+               if (IniOpenSection(OperatingSystemSectionNames[Idx], &OperatingSystemSectionId))
                {
-                       if (ReadSectionSettingByName(OperatingSystemSectionId, "Name", SettingValue, 80))
+                       if (IniReadSettingByName(OperatingSystemSectionId, "Name", SettingValue, 80))
                        {
                                //
                                // Remove any quotes around the string
@@ -115,14 +115,14 @@ ULONG CountOperatingSystems(ULONG SectionId)
        //
        // Loop through and count the operating systems
        //
-       SectionSettingCount = GetNumSectionItems(SectionId);
+       SectionSettingCount = IniGetNumSectionItems(SectionId);
        for (Idx=0; Idx<SectionSettingCount; Idx++)
        {
-               ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
+               IniReadSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
 
                if (stricmp(SettingName, "OS") == 0)
                {
-                       if (OpenSection(SettingValue, NULL))
+                       if (IniOpenSection(SettingValue, NULL))
                        {
                                OperatingSystemCount++;
                        }
diff --git a/freeldr/freeldr/parseini.c b/freeldr/freeldr/parseini.c
deleted file mode 100644 (file)
index aafe033..0000000
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- *  FreeLoader
- *  Copyright (C) 1998-2002  Brian Palmer  <brianp@sginet.com>
- *
- *  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<strlen(TempString); Idx++)
-                       {
-                               // Check and see if this character is the separator
-                               if (TempString[Idx] == '=')
-                               {
-                                       SettingName[Idx] = '\0';
-
-                                       strncpy(SettingValue, TempString + Idx + 1, ValueSize);
-
-                                       return TRUE;
-                               }
-                               else if (Idx < NameSize)
-                               {
-                                       SettingName[Idx] = TempString[Idx];
-                               }
-                       }
-               }
-
-               // Increment setting number
-               SectionItemCount++;
-       }
-       while (FileOffset < FreeLoaderIniFileSize);
-
-       return FALSE;
-}
-
-BOOL ReadSectionSettingByName(ULONG SectionId, PUCHAR SettingName, PUCHAR Buffer, ULONG BufferSize)
-{
-       UCHAR   TempString[1024];
-       UCHAR   TempBuffer[80];
-       ULONG   Idx;
-       ULONG   FileOffset;
-
-       //
-       // Get to the beginning of the section
-       //
-       FileOffset = SectionId;
-
-       //
-       // Now find the setting we are looking for
-       //
-       while (FileOffset < FreeLoaderIniFileSize)
-       {
-               // 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; Idx<strlen(TempString); Idx++)
-               {
-                       if (TempString[Idx] != '=')
-                               TempBuffer[Idx] = TempString[Idx];
-                       else
-                       {
-                               TempBuffer[Idx] = '\0';
-                               break;
-                       }
-               }
-
-               // Check and see if we found the setting
-               if (stricmp(TempBuffer, SettingName) == 0)
-               {
-                       for (Idx=0; Idx<strlen(TempString); Idx++)
-                       {
-                               // Check and see if this character is the separator
-                               if (TempString[Idx] == '=')
-                               {
-                                       strcpy(Buffer, TempString + Idx + 1);
-
-                                       return TRUE;
-                               }
-                       }
-               }
-       }
-
-       return FALSE;
-}
-
-BOOL IsValidSetting(char *setting, char *value)
-{
-       if(stricmp(setting, "MessageBox") == 0)
-               return TRUE;
-       else if(stricmp(setting, "MessageLine") == 0)
-               return TRUE;
-       else if(stricmp(setting, "TitleText") == 0)
-               return TRUE;
-       else if(stricmp(setting, "StatusBarColor") == 0)
-       {
-               if(IsValidColor(value))
-                       return TRUE;
-       }
-       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;*/
-
-       return FALSE;
-}
diff --git a/freeldr/freeldr/parseini.h b/freeldr/freeldr/parseini.h
deleted file mode 100644 (file)
index 363e8e5..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- *  FreeLoader
- *  Copyright (C) 1998-2002  Brian Palmer  <brianp@sginet.com>
- *
- *  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
index 4657d6e..0ed2094 100644 (file)
@@ -26,7 +26,7 @@
 #include <ui.h>
 #include <multiboot.h>
 #include <mm.h>
-#include <parseini.h>
+#include <inifile.h>
 
 #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
index a9f0e69..3ed5257 100644 (file)
@@ -22,7 +22,7 @@
 #include <ui.h>
 #include <mm.h>
 #include <debug.h>
-#include <parseini.h>
+#include <inifile.h>
 
 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<GetNumSectionItems(SectionId); Idx++)
+       for (Idx=0; Idx<IniGetNumSectionItems(SectionId); Idx++)
        {
-               ReadSectionSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
+               IniReadSettingByNumber(SectionId, Idx, SettingName, 80, SettingValue, 80);
                
                if (stricmp(SettingName, "MessageBox") == 0)
                {