Skip to content

Commit 8b31a6f

Browse files
committed
patch 8.0.1656: no option to have xxd produce upper case variable names
Problem: No option to have xxd produce upper case variable names. Solution: Add the -C argument. (Matt Panaro closes #2772)
1 parent 25a6e8a commit 8b31a6f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ static char *(features[]) =
762762

763763
static int included_patches[] =
764764
{ /* Add new patch number below this line */
765+
/**/
766+
1656,
765767
/**/
766768
1655,
767769
/**/

src/xxd/xxd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ char hexxa[] = "0123456789abcdef0123456789ABCDEF", *hexx = hexxa;
215215
#define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */
216216
#define HEX_LITTLEENDIAN 4
217217

218+
#define CONDITIONAL_CAPITALIZE(c) (capitalize ? toupper((int)c) : c)
219+
218220
static char *pname;
219221

220222
static void
@@ -225,6 +227,7 @@ exit_with_usage(void)
225227
fprintf(stderr, "Options:\n");
226228
fprintf(stderr, " -a toggle autoskip: A single '*' replaces nul-lines. Default off.\n");
227229
fprintf(stderr, " -b binary digit dump (incompatible with -ps,-i,-r). Default hex.\n");
230+
fprintf(stderr, " -C capitalize variable names in C include file style (-i).\n");
228231
fprintf(stderr, " -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30).\n");
229232
fprintf(stderr, " -E show characters in EBCDIC. Default ASCII.\n");
230233
fprintf(stderr, " -e little-endian dump (incompatible with -ps,-i,-r).\n");
@@ -459,7 +462,7 @@ main(int argc, char *argv[])
459462
{
460463
FILE *fp, *fpo;
461464
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
462-
int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
465+
int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL, capitalize = 0;
463466
int ebcdic = 0;
464467
int octspergrp = -1; /* number of octets grouped in output */
465468
int grplen; /* total chars per octet group */
@@ -495,6 +498,7 @@ main(int argc, char *argv[])
495498
else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16;
496499
else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT;
497500
else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE;
501+
else if (!STRNCMP(pp, "-C", 2)) capitalize = 1;
498502
else if (!STRNCMP(pp, "-r", 2)) revert++;
499503
else if (!STRNCMP(pp, "-E", 2)) ebcdic++;
500504
else if (!STRNCMP(pp, "-v", 2))
@@ -722,7 +726,7 @@ main(int argc, char *argv[])
722726
if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
723727
die(3);
724728
for (e = 0; (c = argv[1][e]) != 0; e++)
725-
if (putc(isalnum(c) ? c : '_', fpo) == EOF)
729+
if (putc(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo) == EOF)
726730
die(3);
727731
if (fputs("[] = {\n", fpo) == EOF)
728732
die(3);
@@ -750,9 +754,9 @@ main(int argc, char *argv[])
750754
if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
751755
die(3);
752756
for (e = 0; (c = argv[1][e]) != 0; e++)
753-
if (putc(isalnum(c) ? c : '_', fpo) == EOF)
757+
if (putc(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo) == EOF)
754758
die(3);
755-
if (fprintf(fpo, "_len = %d;\n", p) < 0)
759+
if (fprintf(fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p) < 0)
756760
die(3);
757761
}
758762

0 commit comments

Comments
 (0)