bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

md5sum minor cleanup


From: Paul Eggert
Subject: md5sum minor cleanup
Date: Sat, 18 Sep 2004 20:30:02 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

I installed this minor code cleanup; it doesn't fix any bugs.

I notice that md5sum's --string option isn't documented; is this
intentional?

2004-09-18  Paul Eggert  <address@hidden>

        * src/md5sum.c (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.

Index: md5sum.c
===================================================================
RCS file: /home/eggert/coreutils/cu/src/md5sum.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -p -u -r1.126 -r1.127
--- md5sum.c    9 Aug 2004 18:16:26 -0000       1.126
+++ md5sum.c    19 Sep 2004 02:21:09 -0000      1.127
@@ -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;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]