From 4aca87515a5083ae0e31ce3177189fd43b6d05ac Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 3 Jan 2015 13:58:15 +0100 Subject: patch to Vanilla Tomato 1.28 --- release/src/router/busybox/coreutils/od.c | 98 +++++++++++++++---------------- 1 file changed, 46 insertions(+), 52 deletions(-) (limited to 'release/src/router/busybox/coreutils/od.c') diff --git a/release/src/router/busybox/coreutils/od.c b/release/src/router/busybox/coreutils/od.c index b18c53c3..e4179a36 100644 --- a/release/src/router/busybox/coreutils/od.c +++ b/release/src/router/busybox/coreutils/od.c @@ -1,3 +1,4 @@ +/* vi: set sw=4 ts=4: */ /* * od implementation for busybox * Based on code from util-linux v 2.11l @@ -5,37 +6,27 @@ * Copyright (c) 1990 * The Regents of the University of California. All rights reserved. * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * * Original copyright notice is retained at the end of this file. */ -#include -#include -#include -#include -#include "busybox.h" + +#include "libbb.h" +#if ENABLE_DESKTOP +/* This one provides -t (busybox's own build script needs it) */ +#include "od_bloaty.c" +#else + #include "dump.h" -#define isdecdigit(c) (isdigit)(c) +#define isdecdigit(c) isdigit(c) #define ishexdigit(c) (isxdigit)(c) static void -odoffset(int argc, char ***argvp) +odoffset(dumper_t *dumper, int argc, char ***argvp) { - register char *num, *p; + char *num, *p; int base; char *end; @@ -66,7 +57,7 @@ odoffset(int argc, char ***argvp) base = 0; /* - * bb_dump_skip over leading '+', 'x[0-9a-fA-f]' or '0x', and + * skip over leading '+', 'x[0-9a-fA-f]' or '0x', and * set base. */ if (p[0] == '+') @@ -79,11 +70,13 @@ odoffset(int argc, char ***argvp) base = 16; } - /* bb_dump_skip over the number */ + /* skip over the number */ if (base == 16) - for (num = p; ishexdigit(*p); ++p); + for (num = p; ishexdigit(*p); ++p) + continue; else - for (num = p; isdecdigit(*p); ++p); + for (num = p; isdecdigit(*p); ++p) + continue; /* check for no number */ if (num == p) @@ -96,23 +89,23 @@ odoffset(int argc, char ***argvp) base = 10; } - bb_dump_skip = strtol(num, &end, base ? base : 8); + dumper->dump_skip = strtol(num, &end, base ? base : 8); /* if end isn't the same as p, we got a non-octal digit */ if (end != p) - bb_dump_skip = 0; + dumper->dump_skip = 0; else { if (*p) { if (*p == 'b') { - bb_dump_skip *= 512; + dumper->dump_skip *= 512; ++p; } else if (*p == 'B') { - bb_dump_skip *= 1024; + dumper->dump_skip *= 1024; ++p; } } if (*p) - bb_dump_skip = 0; + dumper->dump_skip = 0; else { ++*argvp; /* @@ -129,9 +122,9 @@ odoffset(int argc, char ***argvp) } if (base == 10) { x_or_d = 'd'; - DO_X_OR_D: - bb_dump_fshead->nextfu->fmt[TYPE_OFFSET] - = bb_dump_fshead->nextfs->nextfu->fmt[TYPE_OFFSET] + DO_X_OR_D: + dumper->fshead->nextfu->fmt[TYPE_OFFSET] + = dumper->fshead->nextfs->nextfu->fmt[TYPE_OFFSET] = x_or_d; } } @@ -139,7 +132,7 @@ odoffset(int argc, char ***argvp) } } -static const char * const add_strings[] = { +static const char *const add_strings[] = { "16/1 \"%3_u \" \"\\n\"", /* a */ "8/2 \" %06o \" \"\\n\"", /* B, o */ "16/1 \"%03o \" \"\\n\"", /* b */ @@ -155,51 +148,52 @@ static const char * const add_strings[] = { "4/4 \" %011o \" \"\\n\"", /* O */ }; -static const signed char od_opts[] = "aBbcDdeFfHhIiLlOovXx"; +static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxv"; -static const signed char od_o2si[] = { +static const char od_o2si[] ALIGN1 = { 0, 1, 2, 3, 5, 4, 6, 6, 7, 8, 9, 0xa, 0xb, 0xa, 0xa, - 0xb, 1, -1, 8, 9, + 0xb, 1, 8, 9, }; +int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int od_main(int argc, char **argv) { int ch; int first = 1; - signed char *p; - bb_dump_vflag = FIRST; - bb_dump_length = -1; + char *p; + dumper_t *dumper = alloc_dumper(); while ((ch = getopt(argc, argv, od_opts)) > 0) { - if (((p = strchr(od_opts, ch)) != NULL) && (*p >= 0)) { + if (ch == 'v') { + dumper->dump_vflag = ALL; + } else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) { if (first) { first = 0; - bb_dump_add("\"%07.7_Ao\n\""); - bb_dump_add("\"%07.7_ao \""); + bb_dump_add(dumper, "\"%07.7_Ao\n\""); + bb_dump_add(dumper, "\"%07.7_ao \""); } else { - bb_dump_add("\" \""); + bb_dump_add(dumper, "\" \""); } - bb_dump_add(add_strings[od_o2si[(int)(p-od_opts)]]); - } else if (ch == 'v') { - bb_dump_vflag = ALL; + bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]); } else { /* P, p, s, w, or other unhandled */ bb_show_usage(); } } - if (!bb_dump_fshead) { - bb_dump_add("\"%07.7_Ao\n\""); - bb_dump_add("\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); + if (!dumper->fshead) { + bb_dump_add(dumper, "\"%07.7_Ao\n\""); + bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\""); } argc -= optind; argv += optind; - odoffset(argc, &argv); + odoffset(dumper, argc, &argv); - return(bb_dump_dump(argv)); + return bb_dump_dump(dumper, argv); } +#endif /* ENABLE_DESKTOP */ /*- * Copyright (c) 1990 The Regents of the University of California. -- cgit v1.2.3-54-g00ecf