]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
md5sum: print a summary warning for improperly formatted lines
authorBenno Schulenberg <bensberg@justemail.net>
Mon, 18 Oct 2010 20:35:39 +0000 (22:35 +0200)
committerJim Meyering <meyering@redhat.com>
Tue, 19 Oct 2010 07:32:38 +0000 (09:32 +0200)
And remove the now-superfluous totals from the other two warnings,
so the plurals will also work in other languages than English.

* src/md5sum.c (digest_check): Change as above.
* tests/misc/md5sum (check-quiet2): Adjust accordingly.

src/md5sum.c
tests/misc/md5sum

index 10d4fa26c702cc37aedd5d1e259ef848219a46b8..a660e3b2cd65001d079841bd0e49db19437cf3ce 100644 (file)
@@ -431,6 +431,7 @@ static bool
 digest_check (const char *checkfile_name)
 {
   FILE *checkfile_stream;
+  uintmax_t n_misformatted_lines = 0;
   uintmax_t n_properly_formatted_lines = 0;
   uintmax_t n_mismatched_checksums = 0;
   uintmax_t n_open_or_read_failures = 0;
@@ -489,6 +490,8 @@ digest_check (const char *checkfile_name)
              && ! (is_stdin && STREQ (filename, "-"))
              && hex_digits (hex_digest)))
         {
+          ++n_misformatted_lines;
+
           if (warn)
             {
               error (0, 0,
@@ -571,27 +574,26 @@ digest_check (const char *checkfile_name)
     {
       if (!status_only)
         {
+          if (n_misformatted_lines != 0)
+            error (0, 0,
+                   ngettext ("WARNING: %" PRIuMAX " line is improperly formatted",
+                             "WARNING: %" PRIuMAX " lines are improperly formatted",
+                             select_plural (n_misformatted_lines)),
+                   n_misformatted_lines);
+
           if (n_open_or_read_failures != 0)
             error (0, 0,
-                   ngettext ("WARNING: %" PRIuMAX " of %" PRIuMAX
-                             " listed file could not be read",
-                             "WARNING: %" PRIuMAX " of %" PRIuMAX
-                             " listed files could not be read",
-                             select_plural (n_properly_formatted_lines)),
-                   n_open_or_read_failures, n_properly_formatted_lines);
+                   ngettext ("WARNING: %" PRIuMAX " listed file could not be read",
+                             "WARNING: %" PRIuMAX " listed files could not be read",
+                             select_plural (n_open_or_read_failures)),
+                   n_open_or_read_failures);
 
           if (n_mismatched_checksums != 0)
-            {
-              uintmax_t n_computed_checksums =
-                (n_properly_formatted_lines - n_open_or_read_failures);
-              error (0, 0,
-                     ngettext ("WARNING: %" PRIuMAX " of %" PRIuMAX
-                               " computed checksum did NOT match",
-                               "WARNING: %" PRIuMAX " of %" PRIuMAX
-                               " computed checksums did NOT match",
-                               select_plural (n_computed_checksums)),
-                     n_mismatched_checksums, n_computed_checksums);
-            }
+            error (0, 0,
+                   ngettext ("WARNING: %" PRIuMAX " computed checksum did NOT match",
+                             "WARNING: %" PRIuMAX " computed checksums did NOT match",
+                             select_plural (n_mismatched_checksums)),
+                   n_mismatched_checksums);
         }
     }
 
index d3c523e7ab8b4d0f88acb58bd7c8774c01518e89..92cc0fb16fe9e35070e422631039b00aa857ced8 100755 (executable)
@@ -51,7 +51,7 @@ my @Tests =
      ['check-quiet2', '--check', '--quiet',
                                 {IN=>{'f.md5' => "$degenerate  f\n"}},
                                 {AUX=> {f=> 'foo'}}, {OUT=>"f: FAILED\n"},
-                                {ERR=>"md5sum: WARNING: 1 of 1 computed"
+                                {ERR=>"md5sum: WARNING: 1 computed"
                                        . " checksum did NOT match\n"},
                                 {EXIT=> 1}],
      # The sha1sum and md5sum drivers share a lot of code.