|
| 1 | +commit 83e11800cc3775de3135ac7d823137c8c1e87fa1 |
| 2 | +Author: David Gow <david@ingeniumdigital.com> |
| 3 | +Date: Wed Jun 29 20:24:49 2022 +0100 |
| 4 | + |
| 5 | + patch 9.0.0008: cannot specify the variable name for "xxd -i" |
| 6 | + |
| 7 | + Problem: Cannot specify the variable name for "xxd -i". |
| 8 | + Solution: Add the "-name" argument. (David Gow, closes #10599) |
| 9 | + |
| 10 | +diff --git a/xxd/xxd.c b/xxd/xxd.c |
| 11 | +index 0e056c93d..8429b98ec 100644 |
| 12 | +--- a/xxd/xxd.c |
| 13 | ++++ b/xxd/xxd.c |
| 14 | +@@ -55,6 +55,7 @@ |
| 15 | + * 11.01.2019 Add full 64/32 bit range to -o and output by Christer Jensen. |
| 16 | + * 04.02.2020 Add -d for decimal offsets by Aapo Rantalainen |
| 17 | + * 14.01.2022 Disable extra newlines with -c0 -p by Erik Auerswald. |
| 18 | ++ * 20.06.2022 Permit setting the variable names used by -i by David Gow |
| 19 | + * |
| 20 | + * (c) 1990-1998 by Juergen Weigert (jnweiger@gmail.com) |
| 21 | + * |
| 22 | +@@ -226,6 +227,7 @@ exit_with_usage(void) |
| 23 | + fprintf(stderr, " -h print this summary.\n"); |
| 24 | + fprintf(stderr, " -i output in C include file style.\n"); |
| 25 | + fprintf(stderr, " -l len stop after <len> octets.\n"); |
| 26 | ++ fprintf(stderr, " -n name set the variable name used in C include output (-i).\n"); |
| 27 | + fprintf(stderr, " -o off add <off> to the displayed file position.\n"); |
| 28 | + fprintf(stderr, " -ps output in postscript plain hexdump style.\n"); |
| 29 | + fprintf(stderr, " -r reverse operation: convert (or patch) hexdump into binary.\n"); |
| 30 | +@@ -497,6 +499,7 @@ main(int argc, char *argv[]) |
| 31 | + unsigned long displayoff = 0; |
| 32 | + static char l[LLEN+1]; /* static because it may be too big for stack */ |
| 33 | + char *pp; |
| 34 | ++ char *varname = NULL; |
| 35 | + int addrlen = 9; |
| 36 | + |
| 37 | + #ifdef AMIGA |
| 38 | +@@ -635,6 +638,19 @@ main(int argc, char *argv[]) |
| 39 | + argc--; |
| 40 | + } |
| 41 | + } |
| 42 | ++ else if (!STRNCMP(pp, "-n", 2)) |
| 43 | ++ { |
| 44 | ++ if (pp[2] && STRNCMP("ame", pp + 2, 3)) |
| 45 | ++ varname = pp + 2; |
| 46 | ++ else |
| 47 | ++ { |
| 48 | ++ if (!argv[2]) |
| 49 | ++ exit_with_usage(); |
| 50 | ++ varname = argv[2]; |
| 51 | ++ argv++; |
| 52 | ++ argc--; |
| 53 | ++ } |
| 54 | ++ } |
| 55 | + else if (!strcmp(pp, "--")) /* end of options */ |
| 56 | + { |
| 57 | + argv++; |
| 58 | +@@ -753,10 +769,14 @@ main(int argc, char *argv[]) |
| 59 | + |
| 60 | + if (hextype == HEX_CINCLUDE) |
| 61 | + { |
| 62 | +- if (fp != stdin) |
| 63 | ++ /* A user-set variable name overrides fp == stdin */ |
| 64 | ++ if (varname == NULL && fp != stdin) |
| 65 | ++ varname = argv[1]; |
| 66 | ++ |
| 67 | ++ if (varname != NULL) |
| 68 | + { |
| 69 | +- FPRINTF_OR_DIE((fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "")); |
| 70 | +- for (e = 0; (c = argv[1][e]) != 0; e++) |
| 71 | ++ FPRINTF_OR_DIE((fpo, "unsigned char %s", isdigit((int)varname[0]) ? "__" : "")); |
| 72 | ++ for (e = 0; (c = varname[e]) != 0; e++) |
| 73 | + putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); |
| 74 | + fputs_or_die("[] = {\n", fpo); |
| 75 | + } |
| 76 | +@@ -773,11 +793,11 @@ main(int argc, char *argv[]) |
| 77 | + if (p) |
| 78 | + fputs_or_die("\n", fpo); |
| 79 | + |
| 80 | +- if (fp != stdin) |
| 81 | ++ if (varname != NULL) |
| 82 | + { |
| 83 | + fputs_or_die("};\n", fpo); |
| 84 | +- FPRINTF_OR_DIE((fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "")); |
| 85 | +- for (e = 0; (c = argv[1][e]) != 0; e++) |
| 86 | ++ FPRINTF_OR_DIE((fpo, "unsigned int %s", isdigit((int)varname[0]) ? "__" : "")); |
| 87 | ++ for (e = 0; (c = varname[e]) != 0; e++) |
| 88 | + putc_or_die(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo); |
| 89 | + FPRINTF_OR_DIE((fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p)); |
| 90 | + } |
0 commit comments