fixed warnings when compiled with -Wwrite-strings
[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 #include <cmdline.h>
23 #include <rtl.h>
24
25 static CMDLINEINFO CmdLineInfo;
26
27 static char *
28 SkipWhitespace(char *s)
29 {
30 while ('\0' != *s && isspace(*s))
31 {
32 s++;
33 }
34
35 return s;
36 }
37
38 void
39 CmdLineParse(char *CmdLine)
40 {
41 char *s;
42 char *Name;
43 char *Value;
44 char *End;
45
46 CmdLineInfo.DefaultOperatingSystem = NULL;
47 CmdLineInfo.TimeOut = -1;
48
49 if (NULL == CmdLine)
50 {
51 return;
52 }
53
54 /* Skip over "kernel name" */
55 s = CmdLine;
56 while ('\0' != *s && ! isspace(*s))
57 {
58 s++;
59 }
60 s = SkipWhitespace(s);
61
62 while ('\0' != *s)
63 {
64 Name = s;
65 while (! isspace(*s) && '=' != *s && '\0' != *s)
66 {
67 s++;
68 }
69 End = s;
70 s = SkipWhitespace(s);
71 if ('=' == *s)
72 {
73 s++;
74 *End = '\0';
75 s = SkipWhitespace(s);
76 if ('"' == *s)
77 {
78 s++;
79 Value = s;
80 while ('"' != *s && '\0' != *s)
81 {
82 s++;
83 }
84 }
85 else
86 {
87 Value = s;
88 while (! isspace(*s) && '\0' != *s)
89 {
90 s++;
91 }
92 }
93 if ('\0' != *s)
94 {
95 *s++ = '\0';
96 }
97 if (0 == stricmp(Name, "defaultos"))
98 {
99 CmdLineInfo.DefaultOperatingSystem = Value;
100 }
101 else if (0 == stricmp(Name, "timeout"))
102 {
103 CmdLineInfo.TimeOut = atoi(Value);
104 }
105 }
106 }
107 }
108
109 const char *
110 CmdLineGetDefaultOS(void)
111 {
112 return CmdLineInfo.DefaultOperatingSystem;
113 }
114
115 LONG
116 CmdLineGetTimeOut(void)
117 {
118 return CmdLineInfo.TimeOut;
119 }
120
121 /* EOF */
122