-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathcmdline.c
119 lines (105 loc) · 2.94 KB
/
cmdline.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* Command line
*
*/
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "wimboot.h"
#include "cmdline.h"
/** Use raw (unpatched) BCD files */
int cmdline_rawbcd;
/** Use raw (unpatched) WIM files */
int cmdline_rawwim;
/** Allow graphical output from bootmgr/bootmgfw */
int cmdline_gui;
/** Pause before booting OS */
int cmdline_pause;
/** Pause without displaying any prompt */
int cmdline_pause_quiet;
/** WIM boot index */
unsigned int cmdline_index;
/**
* Process command line
*
* @v cmdline Command line
*/
void process_cmdline ( char *cmdline ) {
char *tmp = cmdline;
char *key;
char *value;
char *endp;
/* Do nothing if we have no command line */
if ( ( cmdline == NULL ) || ( cmdline[0] == '\0' ) )
return;
DBG ( "Command line: \"%s\"\n", cmdline );
/* Parse command line */
while ( *tmp ) {
/* Skip whitespace */
while ( isspace ( *tmp ) )
tmp++;
/* Find value (if any) and end of this argument */
key = tmp;
value = NULL;
while ( *tmp ) {
if ( isspace ( *tmp ) ) {
*(tmp++) = '\0';
break;
} else if ( *tmp == '=' ) {
*(tmp++) = '\0';
value = tmp;
} else {
tmp++;
}
}
/* Process this argument */
if ( strcmp ( key, "rawbcd" ) == 0 ) {
cmdline_rawbcd = 1;
} else if ( strcmp ( key, "rawwim" ) == 0 ) {
cmdline_rawwim = 1;
} else if ( strcmp ( key, "gui" ) == 0 ) {
cmdline_gui = 1;
} else if ( strcmp ( key, "pause" ) == 0 ) {
cmdline_pause = 1;
if ( value && ( strcmp ( value, "quiet" ) == 0 ) )
cmdline_pause_quiet = 1;
} else if ( strcmp ( key, "index" ) == 0 ) {
if ( ( ! value ) || ( ! value[0] ) )
die ( "Argument \"index\" needs a value\n" );
cmdline_index = strtoul ( value, &endp, 0 );
if ( *endp )
die ( "Invalid index \"%s\"\n", value );
} else if ( strcmp ( key, "initrdfile" ) == 0 ) {
/* Ignore this keyword to allow for use with syslinux */
} else if ( key == cmdline ) {
/* Ignore unknown initial arguments, which may
* be the program name.
*/
} else {
die ( "Unrecognised argument \"%s%s%s\"\n", key,
( value ? "=" : "" ), ( value ? value : "" ) );
}
}
}