Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

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

    r821 r1765  
     1/* vi: set sw=4 ts=4: */
    12/*
    23 * hexdump implementation for busybox
     
    910 */
    1011
    11 #include "busybox.h"
    1212#include <getopt.h>
    13 #include <string.h>
     13#include "libbb.h"
    1414#include "dump.h"
     15
     16/* This is a NOEXEC applet. Be very careful! */
     17
    1518
    1619static void bb_dump_addfile(char *name)
    1720{
    18     register char *p;
     21    char *p;
    1922    FILE *fp;
    2023    char *buf;
    2124
    22     fp = bb_xfopen(name, "r");
     25    fp = xfopen(name, "r");
    2326
    24     while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) {
     27    while ((buf = xmalloc_getline(fp)) != NULL) {
    2528        p = skip_whitespace(buf);
    2629
     
    3336}
    3437
    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 */
     38static 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 */
    4144};
    4245
    43 static const char add_first[] = "\"%07.7_Ax\n\"";
     46static const char add_first[] ALIGN1 = "\"%07.7_Ax\n\"";
    4447
    45 static const char hexdump_opts[] = "bcdoxCe:f:n:s:v";
     48static const char hexdump_opts[] ALIGN1 = "bcdoxCe:f:n:s:v";
    4649
    4750static const struct suffix_mult suffixes[] = {
    48     {"b", 512 },
    49     {"k", 1024 },
    50     {"m", 1024*1024 },
    51     {NULL, 0 }
     51    { "b", 512 },
     52    { "k", 1024 },
     53    { "m", 1024*1024 },
     54    { }
    5255};
    5356
     57int hexdump_main(int argc, char **argv);
    5458int hexdump_main(int argc, char **argv)
    5559{
    56 //  register FS *tfs;
    5760    const char *p;
    5861    int ch;
     
    6265
    6366    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\"");
    72             } else {
    73                 /* Sae a little bit of space below by omitting the 'else's. */
    74                 if (ch == 'e') {
    75                     bb_dump_add(optarg);
    76                 } /* else */
    77                 if (ch == 'f') {
    78                     bb_dump_addfile(optarg);
    79                 } /* else */
    80                 if (ch == 'n') {
    81                     bb_dump_length = bb_xgetularg10_bnd(optarg, 0, INT_MAX);
    82                 } /* else */
    83                 if (ch == 's') {
    84                     bb_dump_skip = bb_xgetularg_bnd_sfx(optarg, 10, 0, LONG_MAX, suffixes);
    85                 } /* else */
    86                 if (ch == 'v') {
    87                     bb_dump_vflag = ALL;
    88                 }
     67        p = strchr(hexdump_opts, ch);
     68        if (!p)
     69            bb_show_usage();
     70        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;
    8993            }
    90         } else {
    91             bb_show_usage();
    9294        }
    9395    }
     
    100102    argv += optind;
    101103
    102     return(bb_dump_dump(argv));
     104    return bb_dump_dump(argv);
    103105}
Note: See TracChangeset for help on using the changeset viewer.