1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Xxd does not check for errors from library functions.
12 Solution: Add error checks. (Florian Zumbiehl)
16 *** ../vim-7.3.151/src/xxd/xxd.c 2010-08-15 21:57:25.000000000 +0200
17 --- src/xxd/xxd.c 2011-04-01 18:56:11.000000000 +0200
21 * option -b added: 01000101 binary output in normal format.
22 * 16.05.00 Added VAXC changes by Stephen P. Wall
23 * 16.05.00 Improved MMS file and merge for VMS by Zoltan Arpadffy
24 + * 2011 March Better error handling by Florian Zumbiehl.
25 + * 2011 April Formatting by Bram Moolenaar
27 * (c) 1990-1998 by Juergen Weigert (jnweiger@informatik.uni-erlangen.de)
32 /* Let's collect some prototypes */
33 /* CodeWarrior is really picky about missing prototypes */
34 ! static void exit_with_usage __P((char *));
35 ! static int huntype __P((FILE *, FILE *, FILE *, char *, int, int, long));
36 static void xxdline __P((FILE *, char *, int));
38 #define TRY_SEEK /* attempt to use lseek, or skip forward by reading */
41 /* Let's collect some prototypes */
42 /* CodeWarrior is really picky about missing prototypes */
43 ! static void exit_with_usage __P((void));
44 ! static int huntype __P((FILE *, FILE *, FILE *, int, int, long));
45 static void xxdline __P((FILE *, char *, int));
47 #define TRY_SEEK /* attempt to use lseek, or skip forward by reading */
50 #define HEX_CINCLUDE 2
51 #define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */
54 ! exit_with_usage(pname)
57 fprintf(stderr, "Usage:\n %s [options] [infile [outfile]]\n", pname);
58 fprintf(stderr, " or\n %s -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]\n", pname);
60 #define HEX_CINCLUDE 2
61 #define HEX_BITS 3 /* not hex a dump, but bits: 01111001 */
68 fprintf(stderr, "Usage:\n %s [options] [infile [outfile]]\n", pname);
69 fprintf(stderr, " or\n %s -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]\n", pname);
80 + fprintf(stderr, "%s: ", pname);
86 * Max. cols binary characters are decoded from the input stream per line.
87 * Two adjacent garbage characters after evaluated data delimit valid data.
91 * The name is historic and came from 'undo type opt h'.
94 ! huntype(fpi, fpo, fperr, pname, cols, hextype, base_off)
95 ! FILE *fpi, *fpo, *fperr;
100 int c, ign_garb = 1, n1 = -1, n2 = 0, n3, p = cols;
101 long have_off = 0, want_off = 0;
104 * The name is historic and came from 'undo type opt h'.
107 ! huntype(fpi, fpo, fperr, cols, hextype, base_off)
108 ! FILE *fpi, *fpo, *fperr;
112 int c, ign_garb = 1, n1 = -1, n2 = 0, n3, p = cols;
113 long have_off = 0, want_off = 0;
117 if (base_off + want_off != have_off)
121 c = fseek(fpo, base_off + want_off - have_off, 1);
125 if (base_off + want_off != have_off)
127 ! if (fflush(fpo) != 0)
130 c = fseek(fpo, base_off + want_off - have_off, 1);
136 for (; have_off < base_off + want_off; have_off++)
140 if (n2 >= 0 && n1 >= 0)
142 ! putc((n2 << 4) | n1, fpo);
149 for (; have_off < base_off + want_off; have_off++)
150 ! if (putc(0, fpo) == EOF)
154 if (n2 >= 0 && n1 >= 0)
156 ! if (putc((n2 << 4) | n1, fpo) == EOF)
165 while ((c = getc(fpi)) != '\n' && c != EOF)
167 + if (c == EOF && ferror(fpi))
175 while ((c = getc(fpi)) != '\n' && c != EOF)
191 while ((c = getc(fpi)) != '\n' && c != EOF)
193 + if (c == EOF && ferror(fpi))
198 ! if (fflush(fpo) != 0)
203 ! if (fclose(fpo) != 0)
205 ! if (fclose(fpi) != 0)
213 * If nz is always positive, lines are never suppressed.
221 static char z[LLEN+1];
222 static int zero_seen = 0;
225 * If nz is always positive, lines are never suppressed.
233 static char z[LLEN+1];
234 static int zero_seen = 0;
244 if (nz >= 0 || zero_seen > 0)
253 ! if (fputs(z, fp) == EOF)
256 ! if (fputs("*\n", fp) == EOF)
259 if (nz >= 0 || zero_seen > 0)
260 ! if (fputs(l, fp) == EOF)
267 0070,0071,0372,0373,0374,0375,0376,0377
276 int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
278 0070,0071,0372,0373,0374,0375,0376,0377
287 int c, e, p = 0, relseek = 1, negseek = 0, revert = 0;
290 int grplen; /* total chars per octet group */
291 long length = -1, n = 0, seekoff = 0;
296 /* This program doesn't work when started from the Workbench */
298 int grplen; /* total chars per octet group */
299 long length = -1, n = 0, seekoff = 0;
304 /* This program doesn't work when started from the Workbench */
310 ! exit_with_usage(pname);
311 cols = (int)strtol(argv[2], NULL, 0);
319 cols = (int)strtol(argv[2], NULL, 0);
327 ! exit_with_usage(pname);
328 octspergrp = (int)strtol(argv[2], NULL, 0);
336 octspergrp = (int)strtol(argv[2], NULL, 0);
344 ! exit_with_usage(pname);
346 if (argv[2][0] == '+')
354 if (argv[2][0] == '+')
361 ! exit_with_usage(pname);
362 length = strtol(argv[2], (char **)NULL, 0);
370 length = strtol(argv[2], (char **)NULL, 0);
377 else if (pp[0] == '-' && pp[1]) /* unknown option */
378 ! exit_with_usage(pname);
380 break; /* not an option */
385 else if (pp[0] == '-' && pp[1]) /* unknown option */
388 break; /* not an option */
395 ! exit_with_usage(pname);
397 if (argc == 1 || (argv[1][0] == '-' && !argv[1][1]))
398 BIN_ASSIGN(fp = stdin, !revert);
405 if (argc == 1 || (argv[1][0] == '-' && !argv[1][1]))
406 BIN_ASSIGN(fp = stdin, !revert);
409 fprintf(stderr, "%s: sorry, cannot revert this type of hexdump\n", pname);
412 ! return huntype(fp, fpo, stderr, pname, cols, hextype,
413 negseek ? -seekoff : seekoff);
417 fprintf(stderr, "%s: sorry, cannot revert this type of hexdump\n", pname);
420 ! return huntype(fp, fpo, stderr, cols, hextype,
421 negseek ? -seekoff : seekoff);
437 ! if (getc(fp) == EOF)
444 ! fprintf(stderr, "%s: sorry cannot seek.\n", pname);
455 ! fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "");
456 for (e = 0; (c = argv[1][e]) != 0; e++)
457 ! putc(isalnum(c) ? c : '_', fpo);
458 ! fputs("[] = {\n", fpo);
462 while ((length < 0 || p < length) && (c = getc(fp)) != EOF)
464 ! fprintf(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
465 ! (p % cols) ? ", " : ",\n "+2*!p, c);
470 ! fputs("\n};\n"+3*(fp == stdin), fpo);
474 ! fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "");
475 for (e = 0; (c = argv[1][e]) != 0; e++)
476 ! putc(isalnum(c) ? c : '_', fpo);
477 ! fprintf(fpo, "_len = %d;\n", p);
485 if (hextype == HEX_POSTSCRIPT)
488 while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
490 ! putchar(hexx[(e >> 4) & 0xf]);
491 ! putchar(hexx[(e ) & 0xf]);
510 ! if (fprintf(fpo, "unsigned char %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
512 for (e = 0; (c = argv[1][e]) != 0; e++)
513 ! if (putc(isalnum(c) ? c : '_', fpo) == EOF)
515 ! if (fputs("[] = {\n", fpo) == EOF)
521 while ((length < 0 || p < length) && (c = getc(fp)) != EOF)
523 ! if (fprintf(fpo, (hexx == hexxa) ? "%s0x%02x" : "%s0X%02X",
524 ! (p % cols) ? ", " : ",\n "+2*!p, c) < 0)
528 + if (c == EOF && ferror(fp))
532 ! if (fputs("\n};\n" + 3 * (fp == stdin), fpo) == EOF)
537 ! if (fprintf(fpo, "unsigned int %s", isdigit((int)argv[1][0]) ? "__" : "") < 0)
539 for (e = 0; (c = argv[1][e]) != 0; e++)
540 ! if (putc(isalnum(c) ? c : '_', fpo) == EOF)
542 ! if (fprintf(fpo, "_len = %d;\n", p) < 0)
553 if (hextype == HEX_POSTSCRIPT)
557 while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
559 ! if (putc(hexx[(e >> 4) & 0xf], fpo) == EOF
560 ! || putc(hexx[e & 0xf], fpo) == EOF)
565 ! if (putc('\n', fpo) == EOF)
570 + if (e == EOF && ferror(fp))
573 ! if (putc('\n', fpo) == EOF)
585 else /* hextype == HEX_BITS */
586 grplen = 8 * octspergrp + 1;
589 while ((length < 0 || n < length) && (e = getc(fp)) != EOF)
598 + if (e == EOF && ferror(fp))
602 l[c = (11 + (grplen * cols - 1)/octspergrp + p)] = '\n'; l[++c] = '\0';
606 xxdline(fpo, l, -1); /* last chance to flush out suppressed lines */
614 xxdline(fpo, l, -1); /* last chance to flush out suppressed lines */
623 + /* vi:set ts=8 sw=4 sts=2 cino+={2 cino+=n-2 : */
624 *** ../vim-7.3.151/src/version.c 2011-04-01 16:28:33.000000000 +0200
625 --- src/version.c 2011-04-01 19:00:26.000000000 +0200
629 { /* Add new patch number below this line */
635 Eye have a spelling checker, it came with my PC;
636 It plainly marks four my revue mistakes I cannot sea.
637 I've run this poem threw it, I'm sure your please to no,
638 It's letter perfect in it's weigh, my checker tolled me sew!
640 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
641 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
642 \\\ an exciting new programming language -- http://www.Zimbu.org ///
643 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///