]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - wimboot/wimboot-2.7.3/src/cmdline.c
1.1.07 release
[Ventoy.git] / wimboot / wimboot-2.7.3 / src / cmdline.c
1 /*
2 * Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 /**
21 * @file
22 *
23 * Command line
24 *
25 */
26
27 #include <stddef.h>
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include "wimboot.h"
33 #include "cmdline.h"
34
35 /** Use raw (unpatched) BCD files */
36 int cmdline_rawbcd;
37
38 /** Use raw (unpatched) WIM files */
39 int cmdline_rawwim;
40
41 /** Inhibit debugging output */
42 int cmdline_quiet;
43
44 /** Allow graphical output from bootmgr/bootmgfw */
45 int cmdline_gui;
46
47 /** Pause before booting OS */
48 int cmdline_pause;
49
50 /** Pause without displaying any prompt */
51 int cmdline_pause_quiet;
52
53 /** Use linear (unpaged) memory model */
54 int cmdline_linear;
55
56 /** WIM boot index */
57 unsigned int cmdline_index;
58
59 int cmdline_vf_num;
60 char cmdline_vf_path[MAX_VF][64];
61
62 file_size_pf pfventoy_file_size;
63 file_read_pf pfventoy_file_read;
64
65 /**
66 * Process command line
67 *
68 * @v cmdline Command line
69 */
70 void process_cmdline ( char *cmdline ) {
71 char *tmp = cmdline;
72 char *key;
73 char *value;
74 char *endp;
75
76 /* Do nothing if we have no command line */
77 if ( ( cmdline == NULL ) || ( cmdline[0] == '\0' ) )
78 return;
79
80 /* Parse command line */
81 while ( *tmp ) {
82
83 /* Skip whitespace */
84 while ( isspace ( *tmp ) )
85 tmp++;
86
87 /* Find value (if any) and end of this argument */
88 key = tmp;
89 value = NULL;
90 while ( *tmp ) {
91 if ( isspace ( *tmp ) ) {
92 *(tmp++) = '\0';
93 break;
94 } else if ( *tmp == '=' ) {
95 *(tmp++) = '\0';
96 value = tmp;
97 } else {
98 tmp++;
99 }
100 }
101
102 /* Process this argument */
103 if ( strcmp ( key, "rawbcd" ) == 0 ) {
104 cmdline_rawbcd = 1;
105 } else if ( strcmp ( key, "rawwim" ) == 0 ) {
106 cmdline_rawwim = 1;
107 } else if ( strcmp ( key, "gui" ) == 0 ) {
108 cmdline_gui = 1;
109 }
110
111 else if ((key[0] == 'v') && (key[1] == 'f') ) {
112 if (cmdline_vf_num >= MAX_VF)
113 die("Too many vf\n");
114 snprintf(cmdline_vf_path[cmdline_vf_num], 64, "%s", value);
115 cmdline_vf_num++;
116 }else if ( strcmp ( key, "pfsize" ) == 0 ) {
117 pfventoy_file_size = (file_size_pf)strtoul(value, &endp, 0);
118 } else if ( strcmp ( key, "pfread" ) == 0 ) {
119 pfventoy_file_read = (file_read_pf)strtoul(value, &endp, 0 );
120 }
121
122 else if ( strcmp ( key, "linear" ) == 0 ) {
123 cmdline_linear = 1;
124 } else if ( strcmp ( key, "quiet" ) == 0 ) {
125 cmdline_quiet = 1;
126 } else if ( strcmp ( key, "pause" ) == 0 ) {
127 cmdline_pause = 1;
128 if ( value && ( strcmp ( value, "quiet" ) == 0 ) )
129 cmdline_pause_quiet = 1;
130 } else if ( strcmp ( key, "index" ) == 0 ) {
131 if ( ( ! value ) || ( ! value[0] ) )
132 die ( "Argument \"index\" needs a value\n" );
133 cmdline_index = strtoul ( value, &endp, 0 );
134 if ( *endp )
135 die ( "Invalid index \"%s\"\n", value );
136 } else if ( strcmp ( key, "initrdfile" ) == 0 ) {
137 /* Ignore this keyword to allow for use with syslinux */
138 } else if ( key == cmdline ) {
139 /* Ignore unknown initial arguments, which may
140 * be the program name.
141 */
142 } else {
143 die ( "Unrecognised argument \"%s%s%s\"\n", key,
144 ( value ? "=" : "" ), ( value ? value : "" ) );
145 }
146 }
147
148 /* Show command line (after parsing "quiet" option) */
149 DBG ( "Command line: \"%s\" vf=%d pfsize=%p pfread=%p\n",
150 cmdline, cmdline_vf_num, pfventoy_file_size, pfventoy_file_read);
151 }