967b4149fb285c5ad33068232d855b04e7f10602
[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 /* INCLUDES *******************************************************************/
21
22 #include <freeldr.h>
23
24 #define TAG_STRING ' rtS'
25 #define TAG_OS_ITEM 'tISO'
26
27 /* FUNCTIONS ******************************************************************/
28
29 static PCSTR CopyString(PCSTR Source)
30 {
31 PSTR Dest;
32
33 if (!Source)
34 return NULL;
35
36 Dest = FrLdrHeapAlloc(strlen(Source) + 1, TAG_STRING);
37 if (Dest)
38 strcpy(Dest, Source);
39
40 return Dest;
41 }
42
43 OperatingSystemItem* InitOperatingSystemList(ULONG* OperatingSystemCountPointer)
44 {
45 ULONG Idx;
46 CHAR SettingName[260];
47 CHAR SettingValue[260];
48 ULONG_PTR SectionId;
49 PCHAR TitleStart, TitleEnd;
50 PCSTR OsLoadOptions;
51 ULONG Count;
52 OperatingSystemItem* Items;
53
54 /* Open the [FreeLoader] section */
55 if (!IniOpenSection("Operating Systems", &SectionId))
56 return NULL;
57
58 /* Count number of operating systems in the section */
59 Count = IniGetNumSectionItems(SectionId);
60
61 /* Allocate memory to hold operating system lists */
62 Items = FrLdrHeapAlloc(Count * sizeof(OperatingSystemItem), TAG_OS_ITEM);
63 if (!Items)
64 return NULL;
65
66 /* Now loop through and read the operating system section and display names */
67 for (Idx = 0; Idx < Count; Idx++)
68 {
69 IniReadSettingByNumber(SectionId, Idx, SettingName, sizeof(SettingName), SettingValue, sizeof(SettingValue));
70
71 /* Search start and end of the title */
72 OsLoadOptions = NULL;
73 TitleStart = SettingValue;
74 while (*TitleStart == ' ' || *TitleStart == '"')
75 TitleStart++;
76 TitleEnd = TitleStart;
77 if (*TitleEnd != ANSI_NULL)
78 TitleEnd++;
79 while (*TitleEnd != ANSI_NULL && *TitleEnd != '"')
80 TitleEnd++;
81 if (*TitleEnd != ANSI_NULL)
82 {
83 *TitleEnd = ANSI_NULL;
84 OsLoadOptions = TitleEnd + 1;
85 }
86
87 /* Copy the system partition, identifier and options */
88 Items[Idx].SystemPartition = CopyString(SettingName);
89 Items[Idx].LoadIdentifier = CopyString(TitleStart);
90 Items[Idx].OsLoadOptions = CopyString(OsLoadOptions);
91 }
92
93 /* Return success */
94 *OperatingSystemCountPointer = Count;
95 return Items;
96 }