OSDN Git Service

Use getopt() for options parsing.
[android-x86/external-exfat.git] / dump / main.c
index 07c8b05..8650d51 100644 (file)
@@ -2,7 +2,7 @@
        main.c (08.11.10)
        Prints detailed information about exFAT volume.
 
-       Copyright (C) 2011, 2012  Andrew Nayenko
+       Copyright (C) 2011-2013  Andrew Nayenko
 
        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
@@ -112,7 +112,7 @@ static void dump_sectors(struct exfat* ef)
        puts("");
 }
 
-static int dump_full(const char* spec, int used_sectors)
+static int dump_full(const char* spec, bool used_sectors)
 {
        struct exfat ef;
        uint32_t free_clusters;
@@ -140,38 +140,40 @@ static int dump_full(const char* spec, int used_sectors)
 
 static void usage(const char* prog)
 {
-       fprintf(stderr, "Usage: %s [-s] [-u] [-v] <device>\n", prog);
+       fprintf(stderr, "Usage: %s [-s] [-u] [-V] <device>\n", prog);
        exit(1);
 }
 
 int main(int argc, char* argv[])
 {
-       char** pp;
+       int opt;
        const char* spec = NULL;
-       int sb_only = 0;
-       int used_sectors = 0;
+       bool sb_only = false;
+       bool used_sectors = false;
 
        printf("dumpexfat %u.%u.%u\n",
                        EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
 
-       for (pp = argv + 1; *pp; pp++)
+       while ((opt = getopt(argc, argv, "suV")) != -1)
        {
-               if (strcmp(*pp, "-s") == 0)
-                       sb_only = 1;
-               else if (strcmp(*pp, "-u") == 0)
-                       used_sectors = 1;
-               else if (strcmp(*pp, "-v") == 0)
+               switch (opt)
                {
-                       puts("Copyright (C) 2011, 2012  Andrew Nayenko");
+               case 's':
+                       sb_only = true;
+                       break;
+               case 'u':
+                       used_sectors = true;
+                       break;
+               case 'V':
+                       puts("Copyright (C) 2011-2013  Andrew Nayenko");
                        return 0;
-               }
-               else if (spec == NULL)
-                       spec = *pp;
-               else
+               default:
                        usage(argv[0]);
+               }
        }
-       if (spec == NULL)
+       if (argc - optind != 1)
                usage(argv[0]);
+       spec = argv[optind];
 
        if (sb_only)
                return dump_sb(spec);