Selaa lähdekoodia

[san] Use generic option-parsing library

Total saving: 73 bytes.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 vuotta sitten
vanhempi
commit
72b4464c89
1 muutettua tiedostoa jossa 41 lisäystä ja 33 poistoa
  1. 41
    33
      src/hci/commands/sanboot_cmd.c

+ 41
- 33
src/hci/commands/sanboot_cmd.c Näytä tiedosto

@@ -1,69 +1,77 @@
1
+/*
2
+ * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
1 19
 #include <stdio.h>
2 20
 #include <string.h>
3 21
 #include <getopt.h>
4 22
 #include <ipxe/command.h>
23
+#include <ipxe/parseopt.h>
5 24
 #include <usr/autoboot.h>
6 25
 
7 26
 FILE_LICENCE ( GPL2_OR_LATER );
8 27
 
9
-/**
10
- * "sanboot" command syntax message
28
+/** @file
29
+ *
30
+ * SAN commands
11 31
  *
12
- * @v argv		Argument list
13 32
  */
14
-static void sanboot_syntax ( char **argv ) {
15
-	printf ( "Usage:\n"
16
-		 "  %s <root-path>\n"
17
-		 "\n"
18
-		 "Boot from SAN target\n",
19
-		 argv[0] );
20
-}
33
+
34
+/** "sanboot" options */
35
+struct sanboot_options {};
36
+
37
+/** "sanboot" option list */
38
+static struct option_descriptor sanboot_opts[] = {};
39
+
40
+/** "sanboot" command descriptor */
41
+static struct command_descriptor sanboot_cmd =
42
+	COMMAND_DESC ( struct sanboot_options, sanboot_opts, 1, 1,
43
+		       "<root-path>", "Boot from SAN target" );
21 44
 
22 45
 /**
23 46
  * The "sanboot" command
24 47
  *
25 48
  * @v argc		Argument count
26 49
  * @v argv		Argument list
27
- * @ret rc		Exit code
50
+ * @ret rc		Return status code
28 51
  */
29 52
 static int sanboot_exec ( int argc, char **argv ) {
30
-	static struct option longopts[] = {
31
-		{ "help", 0, NULL, 'h' },
32
-		{ NULL, 0, NULL, 0 },
33
-	};
34
-	const char *root_path = NULL;
35
-	int c;
53
+	struct sanboot_options opts;
54
+	const char *root_path;
36 55
 	int rc;
37 56
 
38 57
 	/* Parse options */
39
-	while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
40
-		switch ( c ) {
41
-		case 'h':
42
-			/* Display help text */
43
-		default:
44
-			/* Unrecognised/invalid option */
45
-			sanboot_syntax ( argv );
46
-			return 1;
47
-		}
48
-	}
58
+	if ( ( rc = parse_options ( argc, argv, &sanboot_cmd, &opts ) ) != 0 )
59
+		return rc;
49 60
 
50
-	/* Need exactly one image name remaining after the options */
51
-	if ( optind != ( argc - 1 ) ) {
52
-		sanboot_syntax ( argv );
53
-		return 1;
54
-	}
61
+	/* Parse root path */
55 62
 	root_path = argv[optind];
56 63
 
57 64
 	/* Boot from root path */
58 65
 	if ( ( rc = boot_root_path ( root_path ) ) != 0 ) {
59 66
 		printf ( "Could not boot from %s: %s\n",
60 67
 			 root_path, strerror ( rc ) );
61
-		return 1;
68
+		return rc;
62 69
 	}
63 70
 
64 71
 	return 0;
65 72
 }
66 73
 
74
+/** SAN commands */
67 75
 struct command sanboot_command __command = {
68 76
 	.name = "sanboot",
69 77
 	.exec = sanboot_exec,

Loading…
Peruuta
Tallenna