From 6b6daecc7c87746aa0f38a298aecd2c38ee60520 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 3 Jul 2015 15:19:07 -0500 Subject: Promote xxd to other. --- toys/other/xxd.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ toys/pending/xxd.c | 65 ------------------------------------------------------ 2 files changed, 65 insertions(+), 65 deletions(-) create mode 100644 toys/other/xxd.c delete mode 100644 toys/pending/xxd.c (limited to 'toys') diff --git a/toys/other/xxd.c b/toys/other/xxd.c new file mode 100644 index 00000000..e9ad8393 --- /dev/null +++ b/toys/other/xxd.c @@ -0,0 +1,65 @@ +/* xxd.c - hexdump. + * + * Copyright 2015 The Android Open Source Project + * + * No obvious standard, output looks like: + * 0000000: 4c69 6e75 7820 7665 7273 696f 6e20 332e Linux version 3. + * + * TODO: support for reversing a hexdump back into the original data. + * TODO: -s seek + +USE_XXD(NEWTOY(xxd, ">1c#<1>4096=16l#g#<1=2", TOYFLAG_USR|TOYFLAG_BIN)) + +config XXD + bool "xxd" + default y + help + usage: xxd [-c n] [-g n] [-l n] [file] + + Hexdump a file to stdout. If no file is listed, copy from stdin. + Filename "-" is a synonym for stdin. + + -c n Show n bytes per line (default 16). + -g n Group bytes by adding a ' ' every n bytes (default 2). + -l n Limit of n bytes before stopping (default is no limit). +*/ + +#define FOR_xxd +#include "toys.h" + +GLOBALS( + long g; + long l; + long c; +) + +static void do_xxd(int fd, char *name) +{ + long long pos = 0; + int i, len, space; + + while (0<(len = readall(fd, toybuf, (TT.l && TT.l-pos=' ' && toybuf[i]<='~') ? toybuf[i] : '.'); + putchar('\n'); + } + if (len<0) perror_exit("read"); +} + +void xxd_main(void) +{ + loopfiles(toys.optargs, do_xxd); +} diff --git a/toys/pending/xxd.c b/toys/pending/xxd.c deleted file mode 100644 index dee8c316..00000000 --- a/toys/pending/xxd.c +++ /dev/null @@ -1,65 +0,0 @@ -/* xxd.c - hexdump. - * - * Copyright 2015 The Android Open Source Project - * - * No obvious standard, output looks like: - * 0000000: 4c69 6e75 7820 7665 7273 696f 6e20 332e Linux version 3. - * - * TODO: support for reversing a hexdump back into the original data. - * TODO: -s seek - -USE_XXD(NEWTOY(xxd, ">1c#<1>4096=16l#g#<1=2", TOYFLAG_USR|TOYFLAG_BIN)) - -config XXD - bool "xxd" - default n - help - usage: xxd [-c n] [-g n] [-l n] [file] - - Hexdump a file to stdout. If no file is listed, copy from stdin. - Filename "-" is a synonym for stdin. - - -c n Show n bytes per line (default 16). - -g n Group bytes by adding a ' ' every n bytes (default 2). - -l n Limit of n bytes before stopping (default is no limit). -*/ - -#define FOR_xxd -#include "toys.h" - -GLOBALS( - long g; - long l; - long c; -) - -static void do_xxd(int fd, char *name) -{ - long long pos = 0; - int i, len, space; - - while (0<(len = readall(fd, toybuf, (TT.l && TT.l-pos=' ' && toybuf[i]<='~') ? toybuf[i] : '.'); - putchar('\n'); - } - if (len<0) perror_exit("read"); -} - -void xxd_main(void) -{ - loopfiles(toys.optargs, do_xxd); -} -- cgit v1.2.3