ReactOS  0.4.13-dev-247-g0f29b3f
cmdline.c
Go to the documentation of this file.
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 {
21 
25 
26 /* FUNCTIONS ******************************************************************/
27 
28 VOID
30 {
31  PCHAR End, Setting;
32  ULONG_PTR Length, Offset = 0;
33 
34  /* Set defaults */
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);
60 
61  /* Replace all separators ';' by spaces */
62  Setting = DebugString;
63  while (*Setting)
64  {
65  if (*Setting == ';') *Setting = ' ';
66  Setting++;
67  }
68 
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;
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 */
122 }
123 
124 PCCH
126 {
127  return CmdLineInfo.DebugString;
128 }
129 
130 PCCH
132 {
134 }
135 
136 LONG
138 {
139  return CmdLineInfo.TimeOut;
140 }
signed char * PCHAR
Definition: retypes.h:7
char CmdLine[0x100]
Definition: mach.c:35
#define IN
Definition: typedefs.h:38
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
Definition: utclib.c:696
LONG CmdLineGetTimeOut(VOID)
Definition: cmdline.c:137
PCCH CmdLineGetDebugString(VOID)
Definition: cmdline.c:125
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define ANSI_NULL
long LONG
Definition: pedump.c:60
PCCH CmdLineGetDefaultOS(VOID)
Definition: cmdline.c:131
smooth NULL
Definition: ftsmooth.c:416
PCCH DefaultOperatingSystem
Definition: cmdline.c:18
void * PVOID
Definition: retypes.h:9
struct tagCMDLINEINFO CMDLINEINFO
CONST CHAR * PCCH
Definition: ntbasedef.h:399
CMDLINEINFO CmdLineInfo
Definition: cmdline.c:24
#define strtoull
Definition: stabs.c:72
LONG TimeOut
Definition: cmdline.c:19
char CCHAR
Definition: typedefs.h:50
ULONG gRamDiskSize
Definition: ramdisk.c:19
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
PCCH DebugString
Definition: cmdline.c:17
struct tagCMDLINEINFO * PCMDLINEINFO
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
VOID CmdLineParse(IN PCCH CmdLine)
Definition: cmdline.c:29
CCHAR DefaultOs[256]
Definition: cmdline.c:23
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
PVOID gRamDiskBase
Definition: ramdisk.c:18
CCHAR DebugString[256]
Definition: cmdline.c:22