From c8ad718b729a58a7cdc62c485efbe6266510d9ad Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 25 Apr 2025 15:18:46 -0500 Subject: [PATCH] Add a simple no option hd. --- toys/other/hd.c | 62 ++++++++++++++++++++++++++++++++++++++++++ toys/pending/hexdump.c | 9 ------ 2 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 toys/other/hd.c diff --git a/toys/other/hd.c b/toys/other/hd.c new file mode 100644 index 00000000..6817e843 --- /dev/null +++ b/toys/other/hd.c @@ -0,0 +1,62 @@ +/* hd.c - Display traditional 16 byte/line hex+ascii. + * + * Copyright 2025 Rob Landley + * + * No standard + +USE_HD(NEWTOY(hd, 0, TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LINEBUF)) + +config HD + bool "hd" + default y + help + usage: hd [FILE...] + + Display traditional 16 byte/line ascii+hex. +*/ + +#define FOR_hd +#include "toys.h" + +GLOBALS( + long len; + int pos; + char flush[16]; +) + +static void flush(void) +{ + int i; + + if (!TT.pos) return; + printf("%*c", 3*(17-TT.pos)+(TT.pos<8), '|'); + for (i = 0; i127) ? '.' : TT.flush[i]); + printf("|\n"); + TT.pos = 0; +} + +static void do_hd(int fd, char *name) +{ + int off, len; + + while (0<(len = xread(fd, toybuf, sizeof(toybuf)))) { + for (off = 0; off