Browse Source

[route] Use generic option-parsing library

Total saving: 71 bytes.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
46116d8d03
1 changed files with 17 additions and 34 deletions
  1. 17
    34
      src/hci/commands/route_cmd.c

+ 17
- 34
src/hci/commands/route_cmd.c View File

21
 #include <stdio.h>
21
 #include <stdio.h>
22
 #include <getopt.h>
22
 #include <getopt.h>
23
 #include <ipxe/command.h>
23
 #include <ipxe/command.h>
24
+#include <ipxe/parseopt.h>
24
 #include <usr/route.h>
25
 #include <usr/route.h>
25
 
26
 
26
 /** @file
27
 /** @file
29
  *
30
  *
30
  */
31
  */
31
 
32
 
32
-/**
33
- * "route" command syntax message
34
- *
35
- * @v argv		Argument list
36
- */
37
-static void route_syntax ( char **argv ) {
38
-	printf ( "Usage:\n"
39
-		 "  %s\n"
40
-		 "\n"
41
-		 "Displays the routing table\n",
42
-		 argv[0] );
43
-}
33
+/** "route" options */
34
+struct route_options {};
35
+
36
+/** "route" option list */
37
+static struct option_descriptor route_opts[] = {};
38
+
39
+/** "route" command descriptor */
40
+static struct command_descriptor route_cmd =
41
+	COMMAND_DESC ( struct route_options, route_opts, 0, 0,
42
+		       "", "Display the routing table" );
44
 
43
 
45
 /**
44
 /**
46
  * The "route" command
45
  * The "route" command
47
  *
46
  *
48
  * @v argc		Argument count
47
  * @v argc		Argument count
49
  * @v argv		Argument list
48
  * @v argv		Argument list
50
- * @ret rc		Exit code
49
+ * @ret rc		Return status code
51
  */
50
  */
52
 static int route_exec ( int argc, char **argv ) {
51
 static int route_exec ( int argc, char **argv ) {
53
-	static struct option longopts[] = {
54
-		{ "help", 0, NULL, 'h' },
55
-		{ NULL, 0, NULL, 0 },
56
-	};
57
-
58
-	int c;
52
+	struct route_options opts;
53
+	int rc;
59
 
54
 
60
 	/* Parse options */
55
 	/* Parse options */
61
-	while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
62
-		switch ( c ) {
63
-		case 'h':
64
-			/* Display help text */
65
-		default:
66
-			/* Unrecognised/invalid option */
67
-			route_syntax ( argv );
68
-			return 1;
69
-		}
70
-	}
71
-
72
-	if ( optind != argc ) {
73
-		route_syntax ( argv );
74
-		return 1;
75
-	}
56
+	if ( ( rc = parse_options ( argc, argv, &route_cmd, &opts ) ) != 0 )
57
+		return rc;
76
 
58
 
77
 	route();
59
 	route();
60
+
78
 	return 0;
61
 	return 0;
79
 }
62
 }
80
 
63
 

Loading…
Cancel
Save