From e2172b4eef7aac4ce09b661da4c09f0b3f0a4710 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 5 Dec 2012 13:01:13 -0300 Subject: [PATCH] tornado/fw/ben/ben.c (main): use getopt --- tornado/fw/ben/ben.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tornado/fw/ben/ben.c b/tornado/fw/ben/ben.c index 2c51c14..ec74c2a 100644 --- a/tornado/fw/ben/ben.c +++ b/tornado/fw/ben/ben.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -92,6 +93,9 @@ static void usage(const char *name) int main(int argc, char **argv) { + int do_read = 1; + int c; + io_setup(); if (!mmc_init()) { @@ -99,11 +103,21 @@ int main(int argc, char **argv) exit(1); } - if (argc == 1) - read_block(); - else if (!strcmp(argv[1], "-w")) - write_block(); - else + while ((c = getopt(argc, argv, "w")) != EOF) + switch (c) { + case 'w': + do_read = 0; + break; + default: + usage(*argv); + } + if (optind != argc) usage(*argv); + + if (do_read) + read_block(); + else + write_block(); + return 0; }