From a8233286378a0254ade5ca2088a7bcc6a686b428 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 18 Mar 2016 20:12:04 -0700 Subject: Add od -w. I'm not an od user myself, but I copy & pasted an 'od' invocation from a bug and it didn't work. Which was embarrassing because I'd just claimed that the od user didn't need to run od on their desktop (as they had done) and could have run it on the device instead... --- toys/posix/od.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/toys/posix/od.c b/toys/posix/od.c index 99219bf4..5ccea58c 100644 --- a/toys/posix/od.c +++ b/toys/posix/od.c @@ -5,21 +5,22 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/od.html -USE_OD(NEWTOY(od, "j#vN#xsodcbA:t*", TOYFLAG_USR|TOYFLAG_BIN)) +USE_OD(NEWTOY(od, "j#vw#<1=16N#xsodcbA:t*", TOYFLAG_USR|TOYFLAG_BIN)) config OD bool "od" default y help - usage: od [-bcdosxv] [-j #] [-N #] [-A doxn] [-t acdfoux[#]] + usage: od [-bcdosxv] [-j #] [-N #] [-w #] [-A doxn] [-t acdfoux[#]] -A Address base (decimal, octal, hexdecimal, none) -j Skip this many bytes of input -N Stop dumping after this many bytes - -t output type a(scii) c(har) d(ecimal) f(loat) o(ctal) u(nsigned) (he)x + -t Output type a(scii) c(har) d(ecimal) f(loat) o(ctal) u(nsigned) (he)x plus optional size in bytes aliases: -b=-t o1, -c=-t c, -d=-t u2, -o=-t o2, -s=-t d2, -x=-t x2 -v Don't collapse repeated lines together + -w Total line width in bytes (default 16). */ #define FOR_od @@ -29,12 +30,13 @@ GLOBALS( struct arg_list *output_base; char *address_base; long max_count; + long width; long jump_bytes; int address_idx; unsigned types, leftover, star; - char *buf; - uint64_t bufs[4]; // force 64-bit alignment + char *buf; // Points to buffers[0] or buffers[1]. + char *bufs[2]; // Used to detect duplicate lines. off_t pos; ) @@ -129,11 +131,11 @@ static void od_outline(void) struct odtype *types = (struct odtype *)toybuf; int i, j, len, pad; - if (TT.leftover<16) memset(TT.buf+TT.leftover, 0, 16-TT.leftover); + if (TT.leftover(TT.address_idx = stridx("ndox", *TT.address_base))) @@ -285,4 +288,9 @@ void od_main(void) if (TT.leftover) od_outline(); od_outline(); + + if (CFG_TOYBOX_FREE) { + free(TT.bufs[0]); + free(TT.bufs[1]); + } } -- cgit v1.2.3