Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/util-linux/hexdump.c

    r1765 r2725  
    55 *
    66 * Copyright (c) 1989
    7  *  The Regents of the University of California.  All rights reserved.
     7 * The Regents of the University of California.  All rights reserved.
    88 *
    9  * Licensed under GPLv2 or later, see file License in this tarball for details.
     9 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1010 */
    1111
    12 #include <getopt.h>
    1312#include "libbb.h"
    1413#include "dump.h"
     
    1615/* This is a NOEXEC applet. Be very careful! */
    1716
    18 
    19 static void bb_dump_addfile(char *name)
     17static void bb_dump_addfile(dumper_t *dumper, char *name)
    2018{
    2119    char *p;
     
    2321    char *buf;
    2422
    25     fp = xfopen(name, "r");
    26 
    27     while ((buf = xmalloc_getline(fp)) != NULL) {
     23    fp = xfopen_for_read(name);
     24    while ((buf = xmalloc_fgetline(fp)) != NULL) {
    2825        p = skip_whitespace(buf);
    29 
    3026        if (*p && (*p != '#')) {
    31             bb_dump_add(p);
     27            bb_dump_add(dumper, p);
    3228        }
    3329        free(buf);
     
    3733
    3834static const char *const add_strings[] = {
    39     "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"",     /* b */
    40     "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"",     /* c */
    41     "\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"",    /* d */
    42     "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"",     /* o */
    43     "\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"",   /* x */
     35    "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"",   /* b */
     36    "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"",   /* c */
     37    "\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"",  /* d */
     38    "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"",   /* o */
     39    "\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"", /* x */
    4440};
    4541
    4642static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\"";
    4743
    48 static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v";
     44static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v" IF_FEATURE_HEXDUMP_REVERSE("R");
    4945
    5046static const struct suffix_mult suffixes[] = {
     
    5248    { "k", 1024 },
    5349    { "m", 1024*1024 },
    54     { }
     50    { "", 0 }
    5551};
    5652
    57 int hexdump_main(int argc, char **argv);
     53int hexdump_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
    5854int hexdump_main(int argc, char **argv)
    5955{
     56    dumper_t *dumper = alloc_dumper();
    6057    const char *p;
    6158    int ch;
     59#if ENABLE_FEATURE_HEXDUMP_REVERSE
     60    FILE *fp;
     61    smallint rdump = 0;
     62#endif
    6263
    63     bb_dump_vflag = FIRST;
    64     bb_dump_length = -1;
     64    if (ENABLE_HD && !applet_name[2]) { /* we are "hd" */
     65        ch = 'C';
     66        goto hd_applet;
     67    }
    6568
     69    /* We cannot use getopt32: in hexdump options are cumulative.
     70     * E.g. "hexdump -C -C file" should dump each line twice */
    6671    while ((ch = getopt(argc, argv, hexdump_opts)) > 0) {
    6772        p = strchr(hexdump_opts, ch);
     
    6974            bb_show_usage();
    7075        if ((p - hexdump_opts) < 5) {
    71             bb_dump_add(add_first);
    72             bb_dump_add(add_strings[(int)(p - hexdump_opts)]);
    73         } else if (ch == 'C') {
    74             bb_dump_add("\"%08.8_Ax\n\"");
    75             bb_dump_add("\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
    76             bb_dump_add("\"  |\" 16/1 \"%_p\" \"|\\n\"");
    77         } else {
    78             /* Save a little bit of space below by omitting the 'else's. */
    79             if (ch == 'e') {
    80                 bb_dump_add(optarg);
    81             } /* else */
    82             if (ch == 'f') {
    83                 bb_dump_addfile(optarg);
    84             } /* else */
    85             if (ch == 'n') {
    86                 bb_dump_length = xatoi_u(optarg);
    87             } /* else */
    88             if (ch == 's') {
    89                 bb_dump_skip = xatoul_range_sfx(optarg, 0, LONG_MAX, suffixes);
    90             } /* else */
    91             if (ch == 'v') {
    92                 bb_dump_vflag = ALL;
    93             }
     76            bb_dump_add(dumper, add_first);
     77            bb_dump_add(dumper, add_strings[(int)(p - hexdump_opts)]);
    9478        }
     79        /* Save a little bit of space below by omitting the 'else's. */
     80        if (ch == 'C') {
     81 hd_applet:
     82            bb_dump_add(dumper, "\"%08.8_Ax\n\"");
     83            bb_dump_add(dumper, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
     84            bb_dump_add(dumper, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
     85        }
     86        if (ch == 'e') {
     87            bb_dump_add(dumper, optarg);
     88        } /* else */
     89        if (ch == 'f') {
     90            bb_dump_addfile(dumper, optarg);
     91        } /* else */
     92        if (ch == 'n') {
     93            dumper->dump_length = xatoi_positive(optarg);
     94        } /* else */
     95        if (ch == 's') { /* compat: -s accepts hex numbers too */
     96            dumper->dump_skip = xstrtoul_range_sfx(optarg, /*base:*/ 0, /*lo:*/ 0, /*hi:*/ LONG_MAX, suffixes);
     97        } /* else */
     98        if (ch == 'v') {
     99            dumper->dump_vflag = ALL;
     100        }
     101#if ENABLE_FEATURE_HEXDUMP_REVERSE
     102        if (ch == 'R') {
     103            rdump = 1;
     104        }
     105#endif
    95106    }
    96107
    97     if (!bb_dump_fshead) {
    98         bb_dump_add(add_first);
    99         bb_dump_add("\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
     108    if (!dumper->fshead) {
     109        bb_dump_add(dumper, add_first);
     110        bb_dump_add(dumper, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
    100111    }
    101112
    102113    argv += optind;
    103114
    104     return bb_dump_dump(argv);
     115#if !ENABLE_FEATURE_HEXDUMP_REVERSE
     116    return bb_dump_dump(dumper, argv);
     117#else
     118    if (!rdump) {
     119        return bb_dump_dump(dumper, argv);
     120    }
     121
     122    /* -R: reverse of 'hexdump -Cv' */
     123    fp = stdin;
     124    if (!*argv) {
     125        argv--;
     126        goto jump_in;
     127    }
     128
     129    do {
     130        char *buf;
     131        fp = xfopen_for_read(*argv);
     132 jump_in:
     133        while ((buf = xmalloc_fgetline(fp)) != NULL) {
     134            p = buf;
     135            while (1) {
     136                /* skip address or previous byte */
     137                while (isxdigit(*p)) p++;
     138                while (*p == ' ') p++;
     139                /* '|' char will break the line */
     140                if (!isxdigit(*p) || sscanf(p, "%x ", &ch) != 1)
     141                    break;
     142                putchar(ch);
     143            }
     144            free(buf);
     145        }
     146        fclose(fp);
     147    } while (*++argv);
     148
     149    fflush_stdout_and_exit(EXIT_SUCCESS);
     150#endif
    105151}
Note: See TracChangeset for help on using the changeset viewer.