Create this branch to work on loading of different Kernel-Debugger DLL providers...
[reactos.git] / boot / freeldr / freeldr / oslist.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <freeldr.h>
21
22 static PCSTR CopyString(PCSTR Source)
23 {
24 PSTR Dest;
25
26 if (!Source)
27 return NULL;
28 Dest = MmHeapAlloc(strlen(Source) + 1);
29 if (Dest)
30 {
31 strcpy(Dest, Source);
32 }
33
34 return Dest;
35 }
36
37 OperatingSystemItem* InitOperatingSystemList(ULONG* OperatingSystemCountPointer)
38 {
39 ULONG Idx;
40 CHAR SettingName[260];
41 CHAR SettingValue[260];
42 ULONG_PTR SectionId;
43 PCHAR TitleStart, TitleEnd;
44 PCSTR OsLoadOptions;
45 ULONG Count;
46 OperatingSystemItem* Items;
47
48 //
49 // Open the [FreeLoader] section
50 //
51 if (!IniOpenSection("Operating Systems", &SectionId))
52 {
53 return NULL;
54 }
55
56 //
57 // Count number of operating systems in the section
58 //
59 Count = IniGetNumSectionItems(SectionId);
60
61 //
62 // Allocate memory to hold operating system lists
63 //
64 Items = MmHeapAlloc(Count * sizeof(OperatingSystemItem));
65 if (!Items)
66 {
67 return NULL;
68 }
69
70 //
71 // Now loop through and read the operating system section and display names
72 //
73 for (Idx = 0; Idx < Count; Idx++)
74 {
75 IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue));
76
77 //
78 // Search start and end of the title
79 //
80 OsLoadOptions = NULL;
81 TitleStart = SettingValue;
82 while (*TitleStart == ' ' || *TitleStart == '"')
83 TitleStart++;
84 TitleEnd = TitleStart;
85 if (*TitleEnd != ANSI_NULL)
86 TitleEnd++;
87 while (*TitleEnd != ANSI_NULL && *TitleEnd != '"')
88 TitleEnd++;
89 if (*TitleEnd != ANSI_NULL)
90 {
91 *TitleEnd = ANSI_NULL;
92 OsLoadOptions = TitleEnd + 1;
93 }
94
95 //
96 // Copy the system partition, identifier and options
97 //
98 Items[Idx].SystemPartition = CopyString(SettingName);
99 Items[Idx].LoadIdentifier = CopyString(TitleStart);
100 Items[Idx].OsLoadOptions = CopyString(OsLoadOptions);
101 }
102
103 //
104 // Return success
105 //
106 *OperatingSystemCountPointer = Count;
107 return Items;
108 }