Browse Source

[parseopt] Allow parsed option to be modified

Parsing a setting name requires the ability to modify the text being
parsed.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
b87020a090

+ 7
- 7
src/core/parseopt.c View File

59
  * @ret value		String value
59
  * @ret value		String value
60
  * @ret rc		Return status code
60
  * @ret rc		Return status code
61
  */
61
  */
62
-int parse_string ( const char *text, const char **value ) {
62
+int parse_string ( char *text, char **value ) {
63
 
63
 
64
 	/* Sanity check */
64
 	/* Sanity check */
65
 	assert ( text != NULL );
65
 	assert ( text != NULL );
77
  * @ret value		Integer value
77
  * @ret value		Integer value
78
  * @ret rc		Return status code
78
  * @ret rc		Return status code
79
  */
79
  */
80
-int parse_integer ( const char *text, unsigned int *value ) {
80
+int parse_integer ( char *text, unsigned int *value ) {
81
 	char *endp;
81
 	char *endp;
82
 
82
 
83
 	/* Sanity check */
83
 	/* Sanity check */
100
  * @ret netdev		Network device
100
  * @ret netdev		Network device
101
  * @ret rc		Return status code
101
  * @ret rc		Return status code
102
  */
102
  */
103
-int parse_netdev ( const char *text, struct net_device **netdev ) {
103
+int parse_netdev ( char *text, struct net_device **netdev ) {
104
 
104
 
105
 	/* Sanity check */
105
 	/* Sanity check */
106
 	assert ( text != NULL );
106
 	assert ( text != NULL );
122
  * @ret menu		Menu
122
  * @ret menu		Menu
123
  * @ret rc		Return status code
123
  * @ret rc		Return status code
124
  */
124
  */
125
-int parse_menu ( const char *text, struct menu **menu ) {
125
+int parse_menu ( char *text, struct menu **menu ) {
126
 
126
 
127
 	/* Find menu */
127
 	/* Find menu */
128
 	*menu = find_menu ( text );
128
 	*menu = find_menu ( text );
145
  * @ret flag		Flag to set
145
  * @ret flag		Flag to set
146
  * @ret rc		Return status code
146
  * @ret rc		Return status code
147
  */
147
  */
148
-int parse_flag ( const char *text __unused, int *flag ) {
148
+int parse_flag ( char *text __unused, int *flag ) {
149
 
149
 
150
 	/* Set flag */
150
 	/* Set flag */
151
 	*flag = 1;
151
 	*flag = 1;
160
  * @ret key		Key
160
  * @ret key		Key
161
  * @ret rc		Return status code
161
  * @ret rc		Return status code
162
  */
162
  */
163
-int parse_key ( const char *text, unsigned int *key ) {
163
+int parse_key ( char *text, unsigned int *key ) {
164
 
164
 
165
 	/* Interpret single characters as being a literal key character */
165
 	/* Interpret single characters as being a literal key character */
166
 	if ( text[0] && ! text[1] ) {
166
 	if ( text[0] && ! text[1] ) {
198
 	char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
198
 	char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
199
 			+ 1 /* NUL */ ];
199
 			+ 1 /* NUL */ ];
200
 	unsigned int shortopt_idx = 0;
200
 	unsigned int shortopt_idx = 0;
201
-	int ( * parse ) ( const char *text, void *value );
201
+	int ( * parse ) ( char *text, void *value );
202
 	void *value;
202
 	void *value;
203
 	unsigned int i;
203
 	unsigned int i;
204
 	unsigned int j;
204
 	unsigned int j;

+ 3
- 4
src/hci/commands/fcmgmt_cmd.c View File

43
  * @ret port		Fibre Channel port
43
  * @ret port		Fibre Channel port
44
  * @ret rc		Return status code
44
  * @ret rc		Return status code
45
  */
45
  */
46
-static int parse_fc_port ( const char *text, struct fc_port **port ) {
46
+static int parse_fc_port ( char *text, struct fc_port **port ) {
47
 
47
 
48
 	/* Sanity check */
48
 	/* Sanity check */
49
 	assert ( text != NULL );
49
 	assert ( text != NULL );
65
  * @ret port_id		Fibre Channel port ID
65
  * @ret port_id		Fibre Channel port ID
66
  * @ret rc		Return status code
66
  * @ret rc		Return status code
67
  */
67
  */
68
-static int parse_fc_port_id ( const char *text, struct fc_port_id *port_id ) {
68
+static int parse_fc_port_id ( char *text, struct fc_port_id *port_id ) {
69
 	int rc;
69
 	int rc;
70
 
70
 
71
 	/* Sanity check */
71
 	/* Sanity check */
87
  * @ret handler		Fibre Channel ELS handler
87
  * @ret handler		Fibre Channel ELS handler
88
  * @ret rc		Return status code
88
  * @ret rc		Return status code
89
  */
89
  */
90
-static int parse_fc_els_handler ( const char *text,
91
-				  struct fc_els_handler **handler ) {
90
+static int parse_fc_els_handler ( char *text, struct fc_els_handler **handler ){
92
 
91
 
93
 	for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
92
 	for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
94
 		if ( strcasecmp ( (*handler)->name, text ) == 0 )
93
 		if ( strcasecmp ( (*handler)->name, text ) == 0 )

+ 1
- 1
src/hci/commands/image_cmd.c View File

39
 /** "img{single}" options */
39
 /** "img{single}" options */
40
 struct imgsingle_options {
40
 struct imgsingle_options {
41
 	/** Image name */
41
 	/** Image name */
42
-	const char *name;
42
+	char *name;
43
 	/** Replace image */
43
 	/** Replace image */
44
 	int replace;
44
 	int replace;
45
 	/** Free image after execution */
45
 	/** Free image after execution */

+ 1
- 1
src/hci/commands/image_trust_cmd.c View File

84
 /** "imgverify" options */
84
 /** "imgverify" options */
85
 struct imgverify_options {
85
 struct imgverify_options {
86
 	/** Required signer common name */
86
 	/** Required signer common name */
87
-	const char *signer;
87
+	char *signer;
88
 	/** Keep signature after verification */
88
 	/** Keep signature after verification */
89
 	int keep;
89
 	int keep;
90
 };
90
 };

+ 4
- 4
src/hci/commands/menu_cmd.c View File

41
 /** "menu" options */
41
 /** "menu" options */
42
 struct menu_options {
42
 struct menu_options {
43
 	/** Name */
43
 	/** Name */
44
-	const char *name;
44
+	char *name;
45
 	/** Delete */
45
 	/** Delete */
46
 	int delete;
46
 	int delete;
47
 };
47
 };
107
 /** "item" options */
107
 /** "item" options */
108
 struct item_options {
108
 struct item_options {
109
 	/** Menu name */
109
 	/** Menu name */
110
-	const char *menu;
110
+	char *menu;
111
 	/** Shortcut key */
111
 	/** Shortcut key */
112
 	unsigned int key;
112
 	unsigned int key;
113
 	/** Use as default */
113
 	/** Use as default */
192
 /** "choose" options */
192
 /** "choose" options */
193
 struct choose_options {
193
 struct choose_options {
194
 	/** Menu name */
194
 	/** Menu name */
195
-	const char *menu;
195
+	char *menu;
196
 	/** Timeout */
196
 	/** Timeout */
197
 	unsigned int timeout;
197
 	unsigned int timeout;
198
 	/** Default selection */
198
 	/** Default selection */
199
-	const char *select;
199
+	char *select;
200
 	/** Keep menu */
200
 	/** Keep menu */
201
 	int keep;
201
 	int keep;
202
 };
202
 };

+ 9
- 9
src/include/ipxe/parseopt.h View File

31
 	 * @v value		Option value to fill in
31
 	 * @v value		Option value to fill in
32
 	 * @ret rc		Return status code
32
 	 * @ret rc		Return status code
33
 	 */
33
 	 */
34
-	int ( * parse ) ( const char *text, void *value );
34
+	int ( * parse ) ( char *text, void *value );
35
 };
35
 };
36
 
36
 
37
 /**
37
 /**
43
  * @ret _parse		Generic option parser
43
  * @ret _parse		Generic option parser
44
  */
44
  */
45
 #define OPTION_PARSER( _struct, _field, _parse )			      \
45
 #define OPTION_PARSER( _struct, _field, _parse )			      \
46
-	( ( int ( * ) ( const char *text, void *value ) )		      \
46
+	( ( int ( * ) ( char *text, void *value ) )			      \
47
 	  ( ( ( ( typeof ( _parse ) * ) NULL ) ==			      \
47
 	  ( ( ( ( typeof ( _parse ) * ) NULL ) ==			      \
48
-	      ( ( int ( * ) ( const char *text,				      \
48
+	      ( ( int ( * ) ( char *text,				      \
49
 			      typeof ( ( ( _struct * ) NULL )->_field ) * ) ) \
49
 			      typeof ( ( ( _struct * ) NULL )->_field ) * ) ) \
50
 		NULL ) ) ? _parse : _parse ) )
50
 		NULL ) ) ? _parse : _parse ) )
51
 
51
 
114
 		.usage = _usage,					      \
114
 		.usage = _usage,					      \
115
 	 }
115
 	 }
116
 
116
 
117
-extern int parse_string ( const char *text, const char **value );
118
-extern int parse_integer ( const char *text, unsigned int *value );
119
-extern int parse_netdev ( const char *text, struct net_device **netdev );
120
-extern int parse_menu ( const char *text, struct menu **menu );
121
-extern int parse_flag ( const char *text __unused, int *flag );
122
-extern int parse_key ( const char *text, unsigned int *key );
117
+extern int parse_string ( char *text, char **value );
118
+extern int parse_integer ( char *text, unsigned int *value );
119
+extern int parse_netdev ( char *text, struct net_device **netdev );
120
+extern int parse_menu ( char *text, struct menu **menu );
121
+extern int parse_flag ( char *text __unused, int *flag );
122
+extern int parse_key ( char *text, unsigned int *key );
123
 extern void print_usage ( struct command_descriptor *cmd, char **argv );
123
 extern void print_usage ( struct command_descriptor *cmd, char **argv );
124
 extern int reparse_options ( int argc, char **argv,
124
 extern int reparse_options ( int argc, char **argv,
125
 			     struct command_descriptor *cmd, void *opts );
125
 			     struct command_descriptor *cmd, void *opts );

Loading…
Cancel
Save