mtd/util fcp.c,1.1,1.2
David Woodhouse
dwmw2 at infradead.org
Thu Apr 3 06:43:40 EST 2003
Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv9803
Modified Files:
fcp.c
Log Message:
From:Â Stephane Fillod <f4cfe at free.fr>
* getopt'ified fcp.c, fixes a bug with "fcp -h"
Index: fcp.c
===================================================================
RCS file: /home/cvs/mtd/util/fcp.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- fcp.c 18 Jun 2001 10:47:25 -0000 1.1
+++ fcp.c 3 Apr 2003 11:43:37 -0000 1.2
@@ -40,6 +40,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <linux/mtd/mtd.h>
+#include <getopt.h>
typedef int bool;
#define true 1
@@ -175,40 +176,49 @@
(progname = strrchr (argv[0],'/')) ? progname++ : (progname = argv[0]);
- /*************************************
- * parse cmd-line args back to front *
- *************************************/
+ /*********************
+ * parse cmd-line
+ *****************/
+
+ for (;;) {
+ int option_index = 0;
+ static const char *short_options = "hv";
+ static const struct option long_options[] = {
+ {"help", no_argument, 0, 'h'},
+ {"verbose", no_argument, 0, 'v'},
+ {0, 0, 0, 0},
+ };
+
+ int c = getopt_long(argc, argv, short_options,
+ long_options, &option_index);
+ if (c == EOF) {
+ break;
+ }
+
+ switch (c) {
+ case 'h':
+ flags |= FLAG_HELP;
+ DEBUG("Got FLAG_HELP\n");
+ break;
+ case 'v':
+ flags |= FLAG_VERBOSE;
+ DEBUG("Got FLAG_VERBOSE\n");
+ break;
+ default:
+ DEBUG("Unknown parameter: %s\n",argv[option_index]);
+ showusage (progname,true);
+ }
+ }
+ if (optind+2 == argc) {
+ flags |= FLAG_FILENAME;
+ filename = argv[optind];
+ DEBUG("Got filename: %s\n",filename);
+
+ flags |= FLAG_DEVICE;
+ device = argv[optind+1];
+ DEBUG("Got device: %s\n",device);
+ }
- while (--argc)
- {
- if (device == NULL)
- {
- flags |= FLAG_DEVICE;
- device = argv[argc];
- DEBUG("Got device: %s\n",device);
- }
- else if (filename == NULL)
- {
- flags |= FLAG_FILENAME;
- filename = argv[argc];
- DEBUG("Got filename: %s\n",filename);
- }
- else if (!strcmp (argv[argc],"-v") || !strcmp (argv[argc],"--verbose"))
- {
- flags |= FLAG_VERBOSE;
- DEBUG("Got FLAG_VERBOSE\n");
- }
- else if (!strcmp (argv[argc],"-h") || !strcmp (argv[argc],"--help"))
- {
- flags |= FLAG_HELP;
- DEBUG("Got FLAG_HELP\n");
- }
- else
- {
- DEBUG("Unknown parameter: %s\n",argv[argc]);
- showusage (progname,true);
- }
- }
if (flags & FLAG_HELP || progname == NULL || device == NULL)
showusage (progname,flags != FLAG_HELP);
More information about the linux-mtd-cvs
mailing list