From: Paul Eggert Date: Sun, 19 Sep 2004 02:21:09 +0000 (+0000) Subject: (STATUS_OPTION, STRING_OPTION): New enums. X-Git-Tag: v5.3.0~674 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdac7ecb116b9cf3e318c3923ff840354b80eb6a;p=thirdparty%2Fcoreutils.git (STATUS_OPTION, STRING_OPTION): New enums. (long_options, main): Use them instead of magic numbers 2 and 1. For --string, optarg can't possibly be NULL. --- diff --git a/src/md5sum.c b/src/md5sum.c index 4bf353db53..9a9bdb2236 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -101,12 +101,20 @@ static bool warn = false; /* The name this program was run with. */ char *program_name; +/* For long options that have no equivalent short option, use a + non-character as a pseudo short option, starting with CHAR_MAX + 1. */ +enum +{ + STATUS_OPTION = CHAR_MAX + 1, + STRING_OPTION +}; + static const struct option long_options[] = { { "binary", no_argument, 0, 'b' }, { "check", no_argument, 0, 'c' }, - { "status", no_argument, 0, 2 }, - { "string", required_argument, 0, 1 }, + { "status", no_argument, 0, STATUS_OPTION }, + { "string", required_argument, 0, STRING_OPTION }, { "text", no_argument, 0, 't' }, { "warn", no_argument, 0, 'w' }, { GETOPT_HELP_OPTION_DECL }, @@ -576,15 +584,10 @@ main (int argc, char **argv) while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1) switch (opt) { - case 0: /* long option */ - break; - case 1: /* --string */ + case STRING_OPTION: { if (string == NULL) string = xnmalloc (argc - 1, sizeof *string); - - if (optarg == NULL) - optarg = ""; string[n_strings++] = optarg; } break; @@ -595,7 +598,7 @@ main (int argc, char **argv) case 'c': do_check = true; break; - case 2: + case STATUS_OPTION: status_only = true; warn = false; break;