Create a branch for Aleksandar Andrejevic for his work on NTVDM. See http://jira...
[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/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 CCHAR DefaultOs[256];
16 CMDLINEINFO CmdLineInfo;
17
18 /* FUNCTIONS ******************************************************************/
19
20 VOID
21 CmdLineParse(IN PCHAR CmdLine)
22 {
23 PCHAR End, Setting;
24 ULONG_PTR Length, Offset = 0;
25
26 //
27 // Set defaults
28 //
29 CmdLineInfo.DefaultOperatingSystem = NULL;
30 CmdLineInfo.TimeOut = -1;
31
32 //
33 // Get timeout
34 //
35 Setting = strstr(CmdLine, "timeout=");
36 if (Setting) CmdLineInfo.TimeOut = atoi(Setting +
37 sizeof("timeout=") +
38 sizeof(ANSI_NULL));
39
40 //
41 // Get default OS
42 //
43 Setting = strstr(CmdLine, "defaultos=");
44 if (Setting)
45 {
46 //
47 // Check if there's more command-line parameters following
48 //
49 Setting += sizeof("defaultos=") + sizeof(ANSI_NULL);
50 End = strstr(Setting, " ");
51 if (End) Length = End - Setting; else Length = sizeof(DefaultOs);
52
53 //
54 // Copy the default OS
55 //
56 strncpy(DefaultOs, Setting, Length);
57 CmdLineInfo.DefaultOperatingSystem = DefaultOs;
58 }
59
60 //
61 // Get ramdisk base address
62 //
63 Setting = strstr(CmdLine, "rdbase=");
64 if (Setting) gRamDiskBase = (PVOID)(ULONG_PTR)strtoull(Setting +
65 sizeof("rdbase=") -
66 sizeof(ANSI_NULL),
67 NULL,
68 0);
69
70 //
71 // Get ramdisk size
72 //
73 Setting = strstr(CmdLine, "rdsize=");
74 if (Setting) gRamDiskSize = strtoul(Setting +
75 sizeof("rdsize=") -
76 sizeof(ANSI_NULL),
77 NULL,
78 0);
79
80 //
81 // Get ramdisk offset
82 //
83 Setting = strstr(CmdLine, "rdoffset=");
84 if (Setting) Offset = strtoul(Setting +
85 sizeof("rdoffset=") -
86 sizeof(ANSI_NULL),
87 NULL,
88 0);
89
90 //
91 // Fix it up
92 //
93 gRamDiskBase = (PVOID)((ULONG_PTR)gRamDiskBase + Offset);
94 }
95
96 PCCH
97 CmdLineGetDefaultOS(VOID)
98 {
99 return CmdLineInfo.DefaultOperatingSystem;
100 }
101
102 LONG
103 CmdLineGetTimeOut(VOID)
104 {
105 return CmdLineInfo.TimeOut;
106 }