- Create KD branch. All debugging support is removed in this branch (no symbols,...
[reactos.git] / reactos / boot / freeldr / freeldr / cmdline.c
1 /* $Id$
2 *
3 * FreeLoader
4 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include <freeldr.h>
22
23 static CMDLINEINFO CmdLineInfo;
24
25 static char *
26 SkipWhitespace(char *s)
27 {
28 while ('\0' != *s && isspace(*s))
29 {
30 s++;
31 }
32
33 return s;
34 }
35
36 void
37 CmdLineParse(char *CmdLine)
38 {
39 char *s;
40 char *Name;
41 char *Value;
42 char *End;
43
44 CmdLineInfo.DefaultOperatingSystem = NULL;
45 CmdLineInfo.TimeOut = -1;
46
47 if (NULL == CmdLine)
48 {
49 return;
50 }
51
52 /* Skip over "kernel name" */
53 s = CmdLine;
54 while ('\0' != *s && ! isspace(*s))
55 {
56 s++;
57 }
58 s = SkipWhitespace(s);
59
60 while ('\0' != *s)
61 {
62 Name = s;
63 while (! isspace(*s) && '=' != *s && '\0' != *s)
64 {
65 s++;
66 }
67 End = s;
68 s = SkipWhitespace(s);
69 if ('=' == *s)
70 {
71 s++;
72 *End = '\0';
73 s = SkipWhitespace(s);
74 if ('"' == *s)
75 {
76 s++;
77 Value = s;
78 while ('"' != *s && '\0' != *s)
79 {
80 s++;
81 }
82 }
83 else
84 {
85 Value = s;
86 while (! isspace(*s) && '\0' != *s)
87 {
88 s++;
89 }
90 }
91 if ('\0' != *s)
92 {
93 *s++ = '\0';
94 }
95 if (0 == _stricmp(Name, "defaultos"))
96 {
97 CmdLineInfo.DefaultOperatingSystem = Value;
98 }
99 else if (0 == _stricmp(Name, "timeout"))
100 {
101 CmdLineInfo.TimeOut = atoi(Value);
102 }
103 }
104 }
105 }
106
107 const char *
108 CmdLineGetDefaultOS(void)
109 {
110 return CmdLineInfo.DefaultOperatingSystem;
111 }
112
113 LONG
114 CmdLineGetTimeOut(void)
115 {
116 return CmdLineInfo.TimeOut;
117 }
118
119 /* EOF */
120