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,7 +59,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
59 59
  * @ret value		String value
60 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 64
 	/* Sanity check */
65 65
 	assert ( text != NULL );
@@ -77,7 +77,7 @@ int parse_string ( const char *text, const char **value ) {
77 77
  * @ret value		Integer value
78 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 81
 	char *endp;
82 82
 
83 83
 	/* Sanity check */
@@ -100,7 +100,7 @@ int parse_integer ( const char *text, unsigned int *value ) {
100 100
  * @ret netdev		Network device
101 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 105
 	/* Sanity check */
106 106
 	assert ( text != NULL );
@@ -122,7 +122,7 @@ int parse_netdev ( const char *text, struct net_device **netdev ) {
122 122
  * @ret menu		Menu
123 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 127
 	/* Find menu */
128 128
 	*menu = find_menu ( text );
@@ -145,7 +145,7 @@ int parse_menu ( const char *text, struct menu **menu ) {
145 145
  * @ret flag		Flag to set
146 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 150
 	/* Set flag */
151 151
 	*flag = 1;
@@ -160,7 +160,7 @@ int parse_flag ( const char *text __unused, int *flag ) {
160 160
  * @ret key		Key
161 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 165
 	/* Interpret single characters as being a literal key character */
166 166
 	if ( text[0] && ! text[1] ) {
@@ -198,7 +198,7 @@ int reparse_options ( int argc, char **argv, struct command_descriptor *cmd,
198 198
 	char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
199 199
 			+ 1 /* NUL */ ];
200 200
 	unsigned int shortopt_idx = 0;
201
-	int ( * parse ) ( const char *text, void *value );
201
+	int ( * parse ) ( char *text, void *value );
202 202
 	void *value;
203 203
 	unsigned int i;
204 204
 	unsigned int j;

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

@@ -43,7 +43,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
43 43
  * @ret port		Fibre Channel port
44 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 48
 	/* Sanity check */
49 49
 	assert ( text != NULL );
@@ -65,7 +65,7 @@ static int parse_fc_port ( const char *text, struct fc_port **port ) {
65 65
  * @ret port_id		Fibre Channel port ID
66 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 69
 	int rc;
70 70
 
71 71
 	/* Sanity check */
@@ -87,8 +87,7 @@ static int parse_fc_port_id ( const char *text, struct fc_port_id *port_id ) {
87 87
  * @ret handler		Fibre Channel ELS handler
88 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 92
 	for_each_table_entry ( (*handler), FC_ELS_HANDLERS ) {
94 93
 		if ( strcasecmp ( (*handler)->name, text ) == 0 )

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

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

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

@@ -84,7 +84,7 @@ static int imgtrust_exec ( int argc, char **argv ) {
84 84
 /** "imgverify" options */
85 85
 struct imgverify_options {
86 86
 	/** Required signer common name */
87
-	const char *signer;
87
+	char *signer;
88 88
 	/** Keep signature after verification */
89 89
 	int keep;
90 90
 };

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

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

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

@@ -31,7 +31,7 @@ struct option_descriptor {
31 31
 	 * @v value		Option value to fill in
32 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,9 +43,9 @@ struct option_descriptor {
43 43
  * @ret _parse		Generic option parser
44 44
  */
45 45
 #define OPTION_PARSER( _struct, _field, _parse )			      \
46
-	( ( int ( * ) ( const char *text, void *value ) )		      \
46
+	( ( int ( * ) ( char *text, void *value ) )			      \
47 47
 	  ( ( ( ( typeof ( _parse ) * ) NULL ) ==			      \
48
-	      ( ( int ( * ) ( const char *text,				      \
48
+	      ( ( int ( * ) ( char *text,				      \
49 49
 			      typeof ( ( ( _struct * ) NULL )->_field ) * ) ) \
50 50
 		NULL ) ) ? _parse : _parse ) )
51 51
 
@@ -114,12 +114,12 @@ struct command_descriptor {
114 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 123
 extern void print_usage ( struct command_descriptor *cmd, char **argv );
124 124
 extern int reparse_options ( int argc, char **argv,
125 125
 			     struct command_descriptor *cmd, void *opts );

Loading…
Cancel
Save