Make the debugging functions slightly more portable.
[reactos.git] / reactos / boot / freeldr / freeldr / bootmgr.c
index 23fc12e..a191b18 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-       
+
 #include <freeldr.h>
-#include <rtl.h>
-#include <fs.h>
-#include <reactos.h>
-#include <ui.h>
-#include <arch.h>
-#include <miscboot.h>
-#include <linux.h>
-#include <mm.h>
-#include <inifile.h>
-#include <debug.h>
-#include <options.h>
-#include <oslist.h>
-#include <video.h>
-#include <bootmgr.h>
-#include <drivemap.h>
-#include <keycodes.h>
-#include <cmdline.h>
-#include <machine.h>
 
 VOID RunLoader(VOID)
 {
-       UCHAR   SettingName[80];
-       UCHAR   SettingValue[80];
-       U32             SectionId;
-       U32             OperatingSystemCount;
-       PUCHAR  *OperatingSystemSectionNames;
-       PUCHAR  *OperatingSystemDisplayNames;
-       U32             DefaultOperatingSystem;
-       S32             TimeOut;
-       U32             SelectedOperatingSystem;
+       CHAR    SettingName[80];
+       CHAR    SettingValue[80];
+       ULONG           SectionId;
+       ULONG           OperatingSystemCount;
+       PCSTR   *OperatingSystemSectionNames;
+       PCSTR   *OperatingSystemDisplayNames;
+       ULONG           DefaultOperatingSystem;
+       LONG            TimeOut;
+       ULONG           SelectedOperatingSystem;
+
+       if (!FsOpenBootVolume())
+       {
+               printf("Error opening boot partition for file access.\n");
+               MachConsGetCh();
+               return;
+       }
 
        if (!IniFileInitialize())
        {
@@ -70,14 +59,14 @@ VOID RunLoader(VOID)
                MachConsGetCh();
                return;
        }
-       
+
 
        if (!InitOperatingSystemList(&OperatingSystemSectionNames, &OperatingSystemDisplayNames, &OperatingSystemCount))
        {
                UiMessageBox("Press ENTER to reboot.\n");
                goto reboot;
        }
-       
+
        if (OperatingSystemCount == 0)
        {
                UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
@@ -85,7 +74,7 @@ VOID RunLoader(VOID)
        }
 
        DefaultOperatingSystem = GetDefaultOperatingSystem(OperatingSystemSectionNames, OperatingSystemCount);
-       
+
        //
        // Find all the message box settings and run them
        //
@@ -93,12 +82,13 @@ VOID RunLoader(VOID)
 
        for (;;)
        {
-       
+
                /* If Timeout is 0, don't even bother loading any gui */
                if (!UserInterfaceUp) {
+                       SelectedOperatingSystem = DefaultOperatingSystem;
                        goto NoGui;
                }
-               
+
                // Redraw the backdrop
                UiDrawBackdrop();
 
@@ -108,10 +98,9 @@ VOID RunLoader(VOID)
                        UiMessageBox("Press ENTER to reboot.\n");
                        goto reboot;
                }
-               
+
 NoGui:
                TimeOut = -1;
-               DefaultOperatingSystem = SelectedOperatingSystem;
 
                // Try to open the operating system section in the .ini file
                if (!IniOpenSection(OperatingSystemSectionNames[SelectedOperatingSystem], &SectionId))
@@ -131,41 +120,41 @@ NoGui:
 
                // Install the drive mapper according to this sections drive mappings
                DriveMapMapDrivesInSection(OperatingSystemSectionNames[SelectedOperatingSystem]);
-               if (stricmp(SettingValue, "ReactOS") == 0)
+               if (_stricmp(SettingValue, "ReactOS") == 0)
                {
                        LoadAndBootReactOS(OperatingSystemSectionNames[SelectedOperatingSystem]);
                }
-               else if (stricmp(SettingValue, "Linux") == 0)
+               else if (_stricmp(SettingValue, "Linux") == 0)
                {
                        LoadAndBootLinux(OperatingSystemSectionNames[SelectedOperatingSystem], OperatingSystemDisplayNames[SelectedOperatingSystem]);
                }
-               else if (stricmp(SettingValue, "BootSector") == 0)
+               else if (_stricmp(SettingValue, "BootSector") == 0)
                {
                        LoadAndBootBootSector(OperatingSystemSectionNames[SelectedOperatingSystem]);
                }
-               else if (stricmp(SettingValue, "Partition") == 0)
+               else if (_stricmp(SettingValue, "Partition") == 0)
                {
                        LoadAndBootPartition(OperatingSystemSectionNames[SelectedOperatingSystem]);
                }
-               else if (stricmp(SettingValue, "Drive") == 0)
+               else if (_stricmp(SettingValue, "Drive") == 0)
                {
                        LoadAndBootDrive(OperatingSystemSectionNames[SelectedOperatingSystem]);
                }
        }
 
-       
+
 reboot:
        UiUnInitialize("Rebooting...");
        return;
 }
 
-U32     GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], U32     OperatingSystemCount)
+ULONG   GetDefaultOperatingSystem(PCSTR OperatingSystemList[], ULONG    OperatingSystemCount)
 {
-       UCHAR   DefaultOSText[80];
-       char*   DefaultOSName;
-       U32     SectionId;
-       U32     DefaultOS = 0;
-       U32     Idx;
+       CHAR    DefaultOSText[80];
+       PCSTR   DefaultOSName;
+       ULONG   SectionId;
+       ULONG   DefaultOS = 0;
+       ULONG   Idx;
 
        if (!IniOpenSection("FreeLoader", &SectionId))
        {
@@ -185,7 +174,7 @@ U32  GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], U32     OperatingSyste
        {
                for (Idx=0; Idx<OperatingSystemCount; Idx++)
                {
-                       if (stricmp(DefaultOSName, OperatingSystemList[Idx]) == 0)
+                       if (_stricmp(DefaultOSName, OperatingSystemList[Idx]) == 0)
                        {
                                DefaultOS = Idx;
                                break;
@@ -196,11 +185,11 @@ U32        GetDefaultOperatingSystem(PUCHAR OperatingSystemList[], U32     OperatingSyste
        return DefaultOS;
 }
 
-S32 GetTimeOut(VOID)
+LONG GetTimeOut(VOID)
 {
-       UCHAR   TimeOutText[20];
-       S32             TimeOut;
-       U32             SectionId;
+       CHAR    TimeOutText[20];
+       LONG            TimeOut;
+       ULONG           SectionId;
 
        TimeOut = CmdLineGetTimeOut();
        if (0 <= TimeOut)
@@ -225,7 +214,7 @@ S32 GetTimeOut(VOID)
        return TimeOut;
 }
 
-BOOL MainBootMenuKeyPressFilter(U32 KeyPress)
+BOOL MainBootMenuKeyPressFilter(ULONG KeyPress)
 {
        if (KeyPress == KEY_F8)
        {