On 07/26/2012 12:59 PM, Ondrej Oprala wrote:
> Ok, here is my patch proposition. I hope it's satisfactory.

Thanks for doing that!
I've attached a mainly formatting cleanup patch.

BTW be careful with strlen() in a for loop test.
That may not be optimized by the compiler,
especially when the passed string is not const or restrict.

The main logic outstanding is to escape the filename
in a BSD compat fashion.
I can have a look at that if you want, but not today.

cheers,
Pádraig.
diff --git a/src/md5sum.c b/src/md5sum.c
index ae429ae..bb6650f 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -169,7 +169,6 @@ static const char *const prefixes[] =
   "SHA512 ",
   "SHA384 "
 };
-     
 
 void
 usage (int status)
@@ -655,8 +654,8 @@ digest_check (const char *checkfile_name)
           && (!strict || n_improperly_formatted_lines == 0));
 }
 
-static void 
-print_filename(char *file)
+static void
+print_filename (char *file)
 {
   size_t i;
   /* Translate each NEWLINE byte to the string, "\\n",
@@ -680,15 +679,11 @@ print_filename(char *file)
     }
 }
 
-static void 
-bsd_print_filename(char *file)
+static void
+bsd_print_filename (const char *file)
 {
-  size_t i;
-
-  for (i = 0; i < strlen (file); ++i)
-    {
-      putchar(file[i]);
-    }
+  /* TODO: Escape in BSD compatible fashion.  */
+  fputs (file, stdout);
 }
 
 int
@@ -716,7 +711,7 @@ main (int argc, char **argv)
      so that processes running in parallel do not intersperse their output.  */
   setvbuf (stdout, NULL, _IOLBF, 0);
 
-  while ((opt = getopt_long (argc, argv, "bctwl", long_options, NULL)) != -1)
+  while ((opt = getopt_long (argc, argv, "bctw", long_options, NULL)) != -1)
     switch (opt)
       {
       case 'b':
@@ -815,19 +810,19 @@ main (int argc, char **argv)
             {
               if (prefix_tag)
                 {
-                  if(!file_is_binary)
-                    putchar(' ');
-                  printf("%s", prefixes[PREFIX_INDEX]);
-                  putchar('(');
-                  bsd_print_filename(file);
-                  printf(") = ");
+                  if (!file_is_binary)
+                    putchar (' ');
+                  fputs (prefixes[PREFIX_INDEX], stdout);
+                  putchar ('(');
+                  bsd_print_filename (file);
+                  fputs (") = ", stdout);
                 }
 
               size_t i;
 
               /* Output a leading backslash if the file name contains
                  a newline or backslash.  */
-              if ((strchr (file, '\n') || strchr (file, '\\')) && !prefix_tag)
+              if (!prefix_tag && (strchr (file, '\n') || strchr (file, '\\')))
                 putchar ('\\');
 
               for (i = 0; i < (digest_hex_bytes / 2); ++i)
@@ -842,7 +837,7 @@ main (int argc, char **argv)
                   else
                     putchar (' ');
 
-                  print_filename(file);
+                  print_filename (file);
                 }
 
               putchar ('\n');

Reply via email to