]> granicus.if.org Git - vim/commitdiff
patch 8.2.3714: some unused assignments and ugly code in xxd v8.2.3714
authorDungSaga <dungsaga@users.noreply.github.com>
Wed, 1 Dec 2021 11:24:52 +0000 (11:24 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 1 Dec 2021 11:24:52 +0000 (11:24 +0000)
Problem:    Some unused assignments and ugly code in xxd.
Solution:   Leave out assignments.  Use marcro for fprintf(). (closes #9246)

src/version.c
src/xxd/xxd.c

index 30be8aedf8f9335037a77f4e2149e081f490c66f..080c687edc0fff1e5f51a3528d03b81cf4c98ff9 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3714,
 /**/
     3713,
 /**/
index d2b3b832c1f9d1434a5c0f15b604c72849358493..cf2a3569f52e50eb7a58b866c0d18585bb8fcfdd 100644 (file)
@@ -275,12 +275,8 @@ fputs_or_die(char *s, FILE *fpo)
     perror_exit(3);
 }
 
-  static void
-fprintf_or_die(FILE *fpo, char *format, char *s, int d)
-{
-  if (fprintf(fpo, format, s, d) < 0)
-    perror_exit(3);
-}
+/* Use a macro to allow for different arguments. */
+#define FPRINTF_OR_DIE(args) if (fprintf args < 0) perror_exit(3)
 
   static void
 fclose_or_die(FILE *fpi, FILE *fpo)
@@ -377,7 +373,7 @@ huntype(
            have_off = base_off + want_off;
 #endif
          if (base_off + want_off < have_off)
-           error_exit(5, "sorry, cannot seek backwards.");
+           error_exit(5, "Sorry, cannot seek backwards.");
          for (; have_off < base_off + want_off; have_off++)
            putc_or_die(0, fpo);
        }
@@ -714,7 +710,7 @@ main(int argc, char *argv[])
   if (revert)
     {
       if (hextype && (hextype != HEX_POSTSCRIPT))
-       error_exit(-1, "sorry, cannot revert this type of hexdump");
+       error_exit(-1, "Sorry, cannot revert this type of hexdump");
       return huntype(fp, fpo, cols, hextype,
                negseek ? -seekoff : seekoff);
     }
@@ -728,7 +724,7 @@ main(int argc, char *argv[])
        e = fseek(fp, negseek ? -seekoff : seekoff,
                                                negseek ? SEEK_END : SEEK_SET);
       if (e < 0 && negseek)
-       error_exit(4, "sorry cannot seek.");
+       error_exit(4, "Sorry, cannot seek.");
       if (e >= 0)
        seekoff = ftell(fp);
       else
@@ -737,9 +733,9 @@ main(int argc, char *argv[])
          long s = seekoff;
 
          while (s--)
-           if ((c = getc_or_die(fp)) == EOF)
+           if (getc_or_die(fp) == EOF)
            {
-             error_exit(4, "sorry cannot seek.");
+             error_exit(4, "Sorry, cannot seek.");
            }
        }
     }
@@ -748,7 +744,7 @@ main(int argc, char *argv[])
     {
       if (fp != stdin)
        {
-         fprintf_or_die(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "", 0);
+         FPRINTF_OR_DIE((fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : ""));
          for (e = 0; (c = argv[1][e]) != 0; e++)
            putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo);
          fputs_or_die("[] = {\n", fpo);
@@ -758,8 +754,8 @@ main(int argc, char *argv[])
       c = 0;
       while ((length < 0 || p < length) && (c = getc_or_die(fp)) != EOF)
        {
-         fprintf_or_die(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
-               (p % cols) ? ", " : (!p ? "  " : ",\n  "),  c);
+         FPRINTF_OR_DIE((fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
+               (p % cols) ? ", " : (!p ? "  " : ",\n  "), c));
          p++;
        }
 
@@ -769,10 +765,10 @@ main(int argc, char *argv[])
       if (fp != stdin)
        {
          fputs_or_die("};\n", fpo);
-         fprintf_or_die(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "", 0);
+         FPRINTF_OR_DIE((fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : ""));
          for (e = 0; (c = argv[1][e]) != 0; e++)
            putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo);
-         fprintf_or_die(fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p);
+         FPRINTF_OR_DIE((fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p));
        }
 
       fclose_or_die(fp, fpo);
@@ -782,7 +778,6 @@ main(int argc, char *argv[])
   if (hextype == HEX_POSTSCRIPT)
     {
       p = cols;
-      e = 0;
       while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF)
        {
          putc_or_die(hexx[(e >> 4) & 0xf], fpo);
@@ -807,7 +802,6 @@ main(int argc, char *argv[])
   else /* hextype == HEX_BITS */
     grplen = 8 * octspergrp + 1;
 
-  e = 0;
   while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF)
     {
       int x;