1
0
forked from aniani/vim

patch 8.2.3714: some unused assignments and ugly code in xxd

Problem:    Some unused assignments and ugly code in xxd.
Solution:   Leave out assignments.  Use marcro for fprintf(). (closes #9246)
This commit is contained in:
DungSaga
2021-12-01 11:24:52 +00:00
committed by Bram Moolenaar
parent 0b226f60be
commit 7e5503c17a
2 changed files with 14 additions and 18 deletions

View File

@@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3714,
/**/ /**/
3713, 3713,
/**/ /**/

View File

@@ -275,12 +275,8 @@ fputs_or_die(char *s, FILE *fpo)
perror_exit(3); perror_exit(3);
} }
static void /* Use a macro to allow for different arguments. */
fprintf_or_die(FILE *fpo, char *format, char *s, int d) #define FPRINTF_OR_DIE(args) if (fprintf args < 0) perror_exit(3)
{
if (fprintf(fpo, format, s, d) < 0)
perror_exit(3);
}
static void static void
fclose_or_die(FILE *fpi, FILE *fpo) fclose_or_die(FILE *fpi, FILE *fpo)
@@ -377,7 +373,7 @@ huntype(
have_off = base_off + want_off; have_off = base_off + want_off;
#endif #endif
if (base_off + want_off < have_off) 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++) for (; have_off < base_off + want_off; have_off++)
putc_or_die(0, fpo); putc_or_die(0, fpo);
} }
@@ -714,7 +710,7 @@ main(int argc, char *argv[])
if (revert) if (revert)
{ {
if (hextype && (hextype != HEX_POSTSCRIPT)) 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, return huntype(fp, fpo, cols, hextype,
negseek ? -seekoff : seekoff); negseek ? -seekoff : seekoff);
} }
@@ -728,7 +724,7 @@ main(int argc, char *argv[])
e = fseek(fp, negseek ? -seekoff : seekoff, e = fseek(fp, negseek ? -seekoff : seekoff,
negseek ? SEEK_END : SEEK_SET); negseek ? SEEK_END : SEEK_SET);
if (e < 0 && negseek) if (e < 0 && negseek)
error_exit(4, "sorry cannot seek."); error_exit(4, "Sorry, cannot seek.");
if (e >= 0) if (e >= 0)
seekoff = ftell(fp); seekoff = ftell(fp);
else else
@@ -737,9 +733,9 @@ main(int argc, char *argv[])
long s = seekoff; long s = seekoff;
while (s--) 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) 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++) for (e = 0; (c = argv[1][e]) != 0; e++)
putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo);
fputs_or_die("[] = {\n", fpo); fputs_or_die("[] = {\n", fpo);
@@ -758,8 +754,8 @@ main(int argc, char *argv[])
c = 0; c = 0;
while ((length < 0 || p < length) && (c = getc_or_die(fp)) != EOF) while ((length < 0 || p < length) && (c = getc_or_die(fp)) != EOF)
{ {
fprintf_or_die(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X", FPRINTF_OR_DIE((fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
(p % cols) ? ", " : (!p ? " " : ",\n "), c); (p % cols) ? ", " : (!p ? " " : ",\n "), c));
p++; p++;
} }
@@ -769,10 +765,10 @@ main(int argc, char *argv[])
if (fp != stdin) if (fp != stdin)
{ {
fputs_or_die("};\n", fpo); 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++) for (e = 0; (c = argv[1][e]) != 0; e++)
putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); 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); fclose_or_die(fp, fpo);
@@ -782,7 +778,6 @@ main(int argc, char *argv[])
if (hextype == HEX_POSTSCRIPT) if (hextype == HEX_POSTSCRIPT)
{ {
p = cols; p = cols;
e = 0;
while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF) while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF)
{ {
putc_or_die(hexx[(e >> 4) & 0xf], fpo); putc_or_die(hexx[(e >> 4) & 0xf], fpo);
@@ -807,7 +802,6 @@ main(int argc, char *argv[])
else /* hextype == HEX_BITS */ else /* hextype == HEX_BITS */
grplen = 8 * octspergrp + 1; grplen = 8 * octspergrp + 1;
e = 0;
while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF) while ((length < 0 || n < length) && (e = getc_or_die(fp)) != EOF)
{ {
int x; int x;