summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-04-03 12:17:25 +0200
committerBram Moolenaar <Bram@vim.org>2018-04-03 12:17:25 +0200
commit8b31a6ff7a0a8184ddc9997a0cc4aa5f2350b279 (patch)
tree7e4bf66c312a5614533fdbd05556be0d0564e139
parent25a6e8a769aa1c0d308b5f871132961f37986d0a (diff)
downloadvim-git-8b31a6ff7a0a8184ddc9997a0cc4aa5f2350b279.tar.gz
patch 8.0.1656: no option to have xxd produce upper case variable namesv8.0.1656
Problem: No option to have xxd produce upper case variable names. Solution: Add the -C argument. (Matt Panaro closes #2772)
-rw-r--r--src/version.c2
-rw-r--r--src/xxd/xxd.c12
2 files changed, 10 insertions, 4 deletions
diff --git a/src/version.c b/src/version.c
index 8403bf4ae..1c2d802d0 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1656,
+/**/
1655,
/**/
1654,
diff --git a/src/xxd/xxd.c b/src/xxd/xxd.c
index f89f4d3b0..bbd9c08a3 100644
--- a/src/xxd/xxd.c
+++ b/src/xxd/xxd.c
@@ -215,6 +215,8 @@ char hexxa[] = "0123456789abcdef0123456789ABCDEF", *hexx = hexxa;
#define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */
#define HEX_LITTLEENDIAN 4
+#define CONDITIONAL_CAPITALIZE(c) (capitalize ? toupper((int)c) : c)
+
static char *pname;
static void
@@ -225,6 +227,7 @@ exit_with_usage(void)
fprintf(stderr, "Options:\n");
fprintf(stderr, " -a toggle autoskip: A single '*' replaces nul-lines. Default off.\n");
fprintf(stderr, " -b binary digit dump (incompatible with -ps,-i,-r). Default hex.\n");
+ fprintf(stderr, " -C capitalize variable names in C include file style (-i).\n");
fprintf(stderr, " -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30).\n");
fprintf(stderr, " -E show characters in EBCDIC. Default ASCII.\n");
fprintf(stderr, " -e little-endian dump (incompatible with -ps,-i,-r).\n");
@@ -459,7 +462,7 @@ main(int argc, char *argv[])
{
FILE *fp, *fpo;
int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
- int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL;
+ int cols = 0, nonzero = 0, autoskip = 0, hextype = HEX_NORMAL, capitalize = 0;
int ebcdic = 0;
int octspergrp = -1; /* number of octets grouped in output */
int grplen; /* total chars per octet group */
@@ -495,6 +498,7 @@ main(int argc, char *argv[])
else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16;
else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT;
else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE;
+ else if (!STRNCMP(pp, "-C", 2)) capitalize = 1;
else if (!STRNCMP(pp, "-r", 2)) revert++;
else if (!STRNCMP(pp, "-E", 2)) ebcdic++;
else if (!STRNCMP(pp, "-v", 2))
@@ -722,7 +726,7 @@ main(int argc, char *argv[])
if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
die(3);
for (e = 0; (c = argv[1][e]) != 0; e++)
- if (putc(isalnum(c) ? c : '_', fpo) == EOF)
+ if (putc(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo) == EOF)
die(3);
if (fputs("[] = {\n", fpo) == EOF)
die(3);
@@ -750,9 +754,9 @@ main(int argc, char *argv[])
if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
die(3);
for (e = 0; (c = argv[1][e]) != 0; e++)
- if (putc(isalnum(c) ? c : '_', fpo) == EOF)
+ if (putc(isalnum(c) ? CONDITIONAL_CAPITALIZE(c) : '_', fpo) == EOF)
die(3);
- if (fprintf(fpo, "_len = %d;\n", p) < 0)
+ if (fprintf(fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p) < 0)
die(3);
}