Mercurial > vim
comparison src/xxd/xxd.c @ 13567:4f2acb6a10b6 v8.0.1656
patch 8.0.1656: no option to have xxd produce upper case variable names
commit https://github.com/vim/vim/commit/8b31a6ff7a0a8184ddc9997a0cc4aa5f2350b279
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Apr 3 12:17:25 2018 +0200
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 https://github.com/vim/vim/issues/2772)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 03 Apr 2018 12:30:08 +0200 |
parents | 7f1a5e8d8289 |
children | 362b27e3f702 |
comparison
equal
deleted
inserted
replaced
13566:c9bacbda2d5b | 13567:4f2acb6a10b6 |
---|---|
213 #define HEX_POSTSCRIPT 1 | 213 #define HEX_POSTSCRIPT 1 |
214 #define HEX_CINCLUDE 2 | 214 #define HEX_CINCLUDE 2 |
215 #define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */ | 215 #define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */ |
216 #define HEX_LITTLEENDIAN 4 | 216 #define HEX_LITTLEENDIAN 4 |
217 | 217 |
218 #define CONDITIONAL_CAPITALIZE(c) (capitalize ? toupper((int)c) : c) | |
219 | |
218 static char *pname; | 220 static char *pname; |
219 | 221 |
220 static void | 222 static void |
221 exit_with_usage(void) | 223 exit_with_usage(void) |
222 { | 224 { |
223 fprintf(stderr, "Usage:\n %s [options] [infile [outfile]]\n", pname); | 225 fprintf(stderr, "Usage:\n %s [options] [infile [outfile]]\n", pname); |
224 fprintf(stderr, " or\n %s -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]\n", pname); | 226 fprintf(stderr, " or\n %s -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]\n", pname); |
225 fprintf(stderr, "Options:\n"); | 227 fprintf(stderr, "Options:\n"); |
226 fprintf(stderr, " -a toggle autoskip: A single '*' replaces nul-lines. Default off.\n"); | 228 fprintf(stderr, " -a toggle autoskip: A single '*' replaces nul-lines. Default off.\n"); |
227 fprintf(stderr, " -b binary digit dump (incompatible with -ps,-i,-r). Default hex.\n"); | 229 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"); | |
228 fprintf(stderr, " -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30).\n"); | 231 fprintf(stderr, " -c cols format <cols> octets per line. Default 16 (-i: 12, -ps: 30).\n"); |
229 fprintf(stderr, " -E show characters in EBCDIC. Default ASCII.\n"); | 232 fprintf(stderr, " -E show characters in EBCDIC. Default ASCII.\n"); |
230 fprintf(stderr, " -e little-endian dump (incompatible with -ps,-i,-r).\n"); | 233 fprintf(stderr, " -e little-endian dump (incompatible with -ps,-i,-r).\n"); |
231 fprintf(stderr, " -g number of octets per group in normal output. Default 2 (-e: 4).\n"); | 234 fprintf(stderr, " -g number of octets per group in normal output. Default 2 (-e: 4).\n"); |
232 fprintf(stderr, " -h print this summary.\n"); | 235 fprintf(stderr, " -h print this summary.\n"); |
457 int | 460 int |
458 main(int argc, char *argv[]) | 461 main(int argc, char *argv[]) |
459 { | 462 { |
460 FILE *fp, *fpo; | 463 FILE *fp, *fpo; |
461 int c, e, p = 0, relseek = 1, negseek = 0, revert = 0; | 464 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; |
463 int ebcdic = 0; | 466 int ebcdic = 0; |
464 int octspergrp = -1; /* number of octets grouped in output */ | 467 int octspergrp = -1; /* number of octets grouped in output */ |
465 int grplen; /* total chars per octet group */ | 468 int grplen; /* total chars per octet group */ |
466 long length = -1, n = 0, seekoff = 0, displayoff = 0; | 469 long length = -1, n = 0, seekoff = 0, displayoff = 0; |
467 static char l[LLEN+1]; /* static because it may be too big for stack */ | 470 static char l[LLEN+1]; /* static because it may be too big for stack */ |
493 else if (!STRNCMP(pp, "-b", 2)) hextype = HEX_BITS; | 496 else if (!STRNCMP(pp, "-b", 2)) hextype = HEX_BITS; |
494 else if (!STRNCMP(pp, "-e", 2)) hextype = HEX_LITTLEENDIAN; | 497 else if (!STRNCMP(pp, "-e", 2)) hextype = HEX_LITTLEENDIAN; |
495 else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16; | 498 else if (!STRNCMP(pp, "-u", 2)) hexx = hexxa + 16; |
496 else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT; | 499 else if (!STRNCMP(pp, "-p", 2)) hextype = HEX_POSTSCRIPT; |
497 else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE; | 500 else if (!STRNCMP(pp, "-i", 2)) hextype = HEX_CINCLUDE; |
501 else if (!STRNCMP(pp, "-C", 2)) capitalize = 1; | |
498 else if (!STRNCMP(pp, "-r", 2)) revert++; | 502 else if (!STRNCMP(pp, "-r", 2)) revert++; |
499 else if (!STRNCMP(pp, "-E", 2)) ebcdic++; | 503 else if (!STRNCMP(pp, "-E", 2)) ebcdic++; |
500 else if (!STRNCMP(pp, "-v", 2)) | 504 else if (!STRNCMP(pp, "-v", 2)) |
501 { | 505 { |
502 fprintf(stderr, "%s%s\n", version, osver); | 506 fprintf(stderr, "%s%s\n", version, osver); |
720 if (fp != stdin) | 724 if (fp != stdin) |
721 { | 725 { |
722 if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "") < 0) | 726 if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "") < 0) |
723 die(3); | 727 die(3); |
724 for (e = 0; (c = argv[1][e]) != 0; e++) | 728 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) |
726 die(3); | 730 die(3); |
727 if (fputs("[] = {\n", fpo) == EOF) | 731 if (fputs("[] = {\n", fpo) == EOF) |
728 die(3); | 732 die(3); |
729 } | 733 } |
730 | 734 |
748 if (fp != stdin) | 752 if (fp != stdin) |
749 { | 753 { |
750 if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "") < 0) | 754 if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "") < 0) |
751 die(3); | 755 die(3); |
752 for (e = 0; (c = argv[1][e]) != 0; e++) | 756 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) |
754 die(3); | 758 die(3); |
755 if (fprintf(fpo, "_len = %d;\n", p) < 0) | 759 if (fprintf(fpo, "_%s = %d;\n", capitalize ? "LEN" : "len", p) < 0) |
756 die(3); | 760 die(3); |
757 } | 761 } |
758 | 762 |
759 if (fclose(fp)) | 763 if (fclose(fp)) |
760 die(2); | 764 die(2); |