diff options
author | DungSaga <dungsaga@users.noreply.github.com> | 2021-12-01 11:24:52 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-01 11:24:52 +0000 |
commit | 7e5503c17a3f142e6b28f344d899c9ab9e75a844 (patch) | |
tree | 103121972615257ad15e63f21cebb8cb47d43c35 /src/xxd | |
parent | 0b226f60be5c30c32fb01fc0b6dc11286e7e2313 (diff) | |
download | vim-git-7e5503c17a3f142e6b28f344d899c9ab9e75a844.tar.gz |
patch 8.2.3714: some unused assignments and ugly code in xxdv8.2.3714
Problem: Some unused assignments and ugly code in xxd.
Solution: Leave out assignments. Use marcro for fprintf(). (closes #9246)
Diffstat (limited to 'src/xxd')
-rw-r--r-- | src/xxd/xxd.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c index d2b3b832c..cf2a3569f 100644 --- a/src/xxd/xxd.c +++ b/src/xxd/xxd.c @@ -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; |