1 /* vi: set sw=4 ts=4: */
3 * hexdump implementation for busybox
4 * Based on code from util-linux v 2.11l
7 * The Regents of the University of California. All rights reserved.
9 * Licensed under GPLv2 or later, see file License in this tarball for details.
16 static void bb_dump_addfile(char *name)
22 fp = xfopen(name, "r");
24 while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) {
25 p = skip_whitespace(buf);
27 if (*p && (*p != '#')) {
35 static const char * const add_strings[] = {
36 "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"", /* b */
37 "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"", /* c */
38 "\"%07.7_ax \" 8/2 \" %05u \" \"\\n\"", /* d */
39 "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"", /* o */
40 "\"%07.7_ax \" 8/2 \" %04x \" \"\\n\"", /* x */
43 static const char add_first[] = "\"%07.7_Ax\n\"";
45 static const char hexdump_opts[] = "bcdoxCe:f:n:s:v";
47 static const struct suffix_mult suffixes[] = {
54 int hexdump_main(int argc, char **argv)
60 bb_dump_vflag = FIRST;
63 while ((ch = getopt(argc, argv, hexdump_opts)) > 0) {
64 if ((p = strchr(hexdump_opts, ch)) != NULL) {
65 if ((p - hexdump_opts) < 5) {
66 bb_dump_add(add_first);
67 bb_dump_add(add_strings[(int)(p - hexdump_opts)]);
68 } else if (ch == 'C') {
69 bb_dump_add("\"%08.8_Ax\n\"");
70 bb_dump_add("\"%08.8_ax \" 8/1 \"%02x \" \" \" 8/1 \"%02x \" ");
71 bb_dump_add("\" |\" 16/1 \"%_p\" \"|\\n\"");
73 /* Sae a little bit of space below by omitting the 'else's. */
78 bb_dump_addfile(optarg);
81 bb_dump_length = bb_xgetularg10_bnd(optarg, 0, INT_MAX);
84 bb_dump_skip = bb_xgetularg_bnd_sfx(optarg, 10, 0, LONG_MAX, suffixes);
95 if (!bb_dump_fshead) {
96 bb_dump_add(add_first);
97 bb_dump_add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
102 return(bb_dump_dump(argv));