[EXT2] Upgrade to 0.69
[reactos.git] / boot / freeldr / freeldr / cmdline.c
1 /*
2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/freeldr/freeldr/cmdline.c
5 * PURPOSE: FreeLDR Command Line Parsing
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9 /* INCLUDES *******************************************************************/
10
11 #include <freeldr.h>
12
13 /* GLOBALS ********************************************************************/
14
15 typedef struct tagCMDLINEINFO
16 {
17 PCCH DebugString;
18 PCCH DefaultOperatingSystem;
19 LONG TimeOut;
20 } CMDLINEINFO, *PCMDLINEINFO;
21
22 CCHAR DebugString[256];
23 CCHAR DefaultOs[256];
24 CMDLINEINFO CmdLineInfo;
25
26 /* FUNCTIONS ******************************************************************/
27
28 VOID
29 CmdLineParse(IN PCCH CmdLine)
30 {
31 PCHAR End, Setting;
32 ULONG_PTR Length, Offset = 0;
33
34 /* Set defaults */
35 CmdLineInfo.DebugString = NULL;
36 CmdLineInfo.DefaultOperatingSystem = NULL;
37 CmdLineInfo.TimeOut = -1;
38
39 /*
40 * Get debug string, in the following format:
41 * "debug=option1=XXX;option2=YYY;..."
42 * and translate it into the format:
43 * "OPTION1=XXX OPTION2=YYY ..."
44 */
45 Setting = strstr(CmdLine, "debug=");
46 if (Setting)
47 {
48 /* Check if there are more command-line parameters following */
49 Setting += sizeof("debug=") + sizeof(ANSI_NULL);
50 End = strstr(Setting, " ");
51 if (End)
52 Length = End - Setting;
53 else
54 Length = sizeof(DebugString);
55
56 /* Copy the debug string and upcase it */
57 strncpy(DebugString, Setting, Length);
58 DebugString[Length - 1] = ANSI_NULL;
59 _strupr(DebugString);
60
61 /* Replace all separators ';' by spaces */
62 Setting = DebugString;
63 while (*Setting)
64 {
65 if (*Setting == ';') *Setting = ' ';
66 Setting++;
67 }
68
69 CmdLineInfo.DebugString = DebugString;
70 }
71
72 /* Get timeout */
73 Setting = strstr(CmdLine, "timeout=");
74 if (Setting) CmdLineInfo.TimeOut = atoi(Setting +
75 sizeof("timeout=") +
76 sizeof(ANSI_NULL));
77
78 /* Get default OS */
79 Setting = strstr(CmdLine, "defaultos=");
80 if (Setting)
81 {
82 /* Check if there are more command-line parameters following */
83 Setting += sizeof("defaultos=") + sizeof(ANSI_NULL);
84 End = strstr(Setting, " ");
85 if (End)
86 Length = End - Setting;
87 else
88 Length = sizeof(DefaultOs);
89
90 /* Copy the default OS */
91 strncpy(DefaultOs, Setting, Length);
92 DefaultOs[Length - 1] = ANSI_NULL;
93 CmdLineInfo.DefaultOperatingSystem = DefaultOs;
94 }
95
96 /* Get ramdisk base address */
97 Setting = strstr(CmdLine, "rdbase=");
98 if (Setting) gRamDiskBase = (PVOID)(ULONG_PTR)strtoull(Setting +
99 sizeof("rdbase=") -
100 sizeof(ANSI_NULL),
101 NULL,
102 0);
103
104 /* Get ramdisk size */
105 Setting = strstr(CmdLine, "rdsize=");
106 if (Setting) gRamDiskSize = strtoul(Setting +
107 sizeof("rdsize=") -
108 sizeof(ANSI_NULL),
109 NULL,
110 0);
111
112 /* Get ramdisk offset */
113 Setting = strstr(CmdLine, "rdoffset=");
114 if (Setting) Offset = strtoul(Setting +
115 sizeof("rdoffset=") -
116 sizeof(ANSI_NULL),
117 NULL,
118 0);
119
120 /* Fix it up */
121 gRamDiskBase = (PVOID)((ULONG_PTR)gRamDiskBase + Offset);
122 }
123
124 PCCH
125 CmdLineGetDebugString(VOID)
126 {
127 return CmdLineInfo.DebugString;
128 }
129
130 PCCH
131 CmdLineGetDefaultOS(VOID)
132 {
133 return CmdLineInfo.DefaultOperatingSystem;
134 }
135
136 LONG
137 CmdLineGetTimeOut(VOID)
138 {
139 return CmdLineInfo.TimeOut;
140 }