wok-next annotate busybox/stuff/busybox-1.7.3-hexdump.u @ rev 282
Busybox: add df -i & hexdump -R
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Feb 26 12:00:01 2008 +0000 (2008-02-26) |
parents | |
children |
rev | line source |
---|---|
pascal@282 | 1 --- busybox-1.7.3/util-linux/hexdump.c |
pascal@282 | 2 +++ busybox-1.7.3/util-linux/hexdump.c |
pascal@282 | 3 @@ -45,7 +45,7 @@ |
pascal@282 | 4 |
pascal@282 | 5 static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\""; |
pascal@282 | 6 |
pascal@282 | 7 -static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v"; |
pascal@282 | 8 +static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:vR"; |
pascal@282 | 9 |
pascal@282 | 10 static const struct suffix_mult suffixes[] = { |
pascal@282 | 11 { "b", 512 }, |
pascal@282 | 12 @@ -59,6 +59,8 @@ |
pascal@282 | 13 { |
pascal@282 | 14 const char *p; |
pascal@282 | 15 int ch; |
pascal@282 | 16 + FILE *fp; |
pascal@282 | 17 + smallint rdump = 0; |
pascal@282 | 18 |
pascal@282 | 19 bb_dump_vflag = FIRST; |
pascal@282 | 20 bb_dump_length = -1; |
pascal@282 | 21 @@ -70,7 +72,7 @@ |
pascal@282 | 22 if ((p - hexdump_opts) < 5) { |
pascal@282 | 23 bb_dump_add(add_first); |
pascal@282 | 24 bb_dump_add(add_strings[(int)(p - hexdump_opts)]); |
pascal@282 | 25 - } else if (ch == 'C') { |
pascal@282 | 26 + } if (ch == 'C') { |
pascal@282 | 27 bb_dump_add("\"%08.8_Ax\n\""); |
pascal@282 | 28 bb_dump_add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" "); |
pascal@282 | 29 bb_dump_add("\" |\" 16/1 \"%_p\" \"|\\n\""); |
pascal@282 | 30 @@ -90,6 +92,9 @@ |
pascal@282 | 31 } /* else */ |
pascal@282 | 32 if (ch == 'v') { |
pascal@282 | 33 bb_dump_vflag = ALL; |
pascal@282 | 34 + } /* else */ |
pascal@282 | 35 + if (ch == 'R') { |
pascal@282 | 36 + rdump = 1; |
pascal@282 | 37 } |
pascal@282 | 38 } |
pascal@282 | 39 } |
pascal@282 | 40 @@ -101,5 +106,36 @@ |
pascal@282 | 41 |
pascal@282 | 42 argv += optind; |
pascal@282 | 43 |
pascal@282 | 44 - return bb_dump_dump(argv); |
pascal@282 | 45 + if (!rdump) { |
pascal@282 | 46 + return bb_dump_dump(argv); |
pascal@282 | 47 + } |
pascal@282 | 48 + |
pascal@282 | 49 + /* -R: reverse of 'hexdump -Cv' */ |
pascal@282 | 50 + fp = stdin; |
pascal@282 | 51 + if (!*argv) { |
pascal@282 | 52 + argv--; |
pascal@282 | 53 + goto jump_in; |
pascal@282 | 54 + } |
pascal@282 | 55 + |
pascal@282 | 56 + do { |
pascal@282 | 57 + char *buf; |
pascal@282 | 58 + fp = xfopen(*argv, "r"); |
pascal@282 | 59 + jump_in: |
pascal@282 | 60 + while ((buf = xmalloc_getline(fp)) != NULL) { |
pascal@282 | 61 + p = buf; |
pascal@282 | 62 + while (1) { |
pascal@282 | 63 + /* skip address or previous byte */ |
pascal@282 | 64 + while (isxdigit(*p)) p++; |
pascal@282 | 65 + while (*p == ' ') p++; |
pascal@282 | 66 + /* '|' char will break the line */ |
pascal@282 | 67 + if (!isxdigit(*p) || sscanf(p, "%x ", &ch) != 1) |
pascal@282 | 68 + break; |
pascal@282 | 69 + putchar(ch); |
pascal@282 | 70 + } |
pascal@282 | 71 + free(buf); |
pascal@282 | 72 + } |
pascal@282 | 73 + fclose(fp); |
pascal@282 | 74 + } while (*++argv); |
pascal@282 | 75 + |
pascal@282 | 76 + fflush_stdout_and_exit(EXIT_SUCCESS); |
pascal@282 | 77 } |