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