Ver código fonte

[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 anos atrás
pai
commit
46116d8d03
1 arquivos alterados com 17 adições e 34 exclusões
  1. 17
    34
      src/hci/commands/route_cmd.c

+ 17
- 34
src/hci/commands/route_cmd.c Ver arquivo

@@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
21 21
 #include <stdio.h>
22 22
 #include <getopt.h>
23 23
 #include <ipxe/command.h>
24
+#include <ipxe/parseopt.h>
24 25
 #include <usr/route.h>
25 26
 
26 27
 /** @file
@@ -29,52 +30,34 @@ FILE_LICENCE ( GPL2_OR_LATER );
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 45
  * The "route" command
47 46
  *
48 47
  * @v argc		Argument count
49 48
  * @v argv		Argument list
50
- * @ret rc		Exit code
49
+ * @ret rc		Return status code
51 50
  */
52 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 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 59
 	route();
60
+
78 61
 	return 0;
79 62
 }
80 63
 

Carregando…
Cancelar
Salvar