Browse Source

[parseopt] Disambiguate the various EINVAL errors

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
c49659c4f2
1 changed files with 16 additions and 2 deletions
  1. 16
    2
      src/core/parseopt.c

+ 16
- 2
src/core/parseopt.c View File

40
 #define EINFO_ECANCELED_NO_OP \
40
 #define EINFO_ECANCELED_NO_OP \
41
 	__einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" )
41
 	__einfo_uniqify ( EINFO_ECANCELED, 0x01, "Nothing to do" )
42
 
42
 
43
+/* Disambiguate the various error codes */
44
+#define EINVAL_INTEGER __einfo_error ( EINFO_EINVAL_INTEGER )
45
+#define EINFO_EINVAL_INTEGER \
46
+	__einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid integer value" )
47
+#define EINVAL_UNKNOWN_OPTION __einfo_error ( EINFO_EINVAL_UNKNOWN_OPTION )
48
+#define EINFO_EINVAL_UNKNOWN_OPTION \
49
+	__einfo_uniqify ( EINFO_EINVAL, 0x02, "Unrecognised option" )
50
+#define EINVAL_MISSING_ARGUMENT __einfo_error ( EINFO_EINVAL_MISSING_ARGUMENT )
51
+#define EINFO_EINVAL_MISSING_ARGUMENT \
52
+	__einfo_uniqify ( EINFO_EINVAL, 0x03, "Missing argument" )
53
+
43
 /**
54
 /**
44
 * Parse string value
55
 * Parse string value
45
  *
56
  *
75
 	*value = strtoul ( text, &endp, 0 );
86
 	*value = strtoul ( text, &endp, 0 );
76
 	if ( *endp ) {
87
 	if ( *endp ) {
77
 		printf ( "\"%s\": invalid integer value\n", text );
88
 		printf ( "\"%s\": invalid integer value\n", text );
78
-		return -EINVAL;
89
+		return -EINVAL_INTEGER;
79
 	}
90
 	}
80
 
91
 
81
 	return 0;
92
 	return 0;
202
 			print_usage ( cmd, argv );
213
 			print_usage ( cmd, argv );
203
 			return -ECANCELED_NO_OP;
214
 			return -ECANCELED_NO_OP;
204
 		case '?' :
215
 		case '?' :
216
+			/* Print usage message */
217
+			print_usage ( cmd, argv );
218
+			return -EINVAL_UNKNOWN_OPTION;
205
 		case ':' :
219
 		case ':' :
206
 			/* Print usage message */
220
 			/* Print usage message */
207
 			print_usage ( cmd, argv );
221
 			print_usage ( cmd, argv );
208
-			return -EINVAL;
222
+			return -EINVAL_MISSING_ARGUMENT;
209
 		default:
223
 		default:
210
 			/* Search for an option to parse */
224
 			/* Search for an option to parse */
211
 			for ( i = 0 ; i < cmd->num_options ; i++ ) {
225
 			for ( i = 0 ; i < cmd->num_options ; i++ ) {

Loading…
Cancel
Save