[Toybox] [PATCH] xxd: -d Decimal Lables flag, Don't cap at one file

Oliver Webb aquahobbyist at proton.me
Sat Apr 20 19:37:44 PDT 2024


Looking at xxd, I noticed that the -b[inary] flag wasn't there,
Having some facility to print binary is nice, but since printf
doesn't have anything in built for it implementing it isn't hard,
but it looks _ugly_. Which is why I decided not to do that in this
patch.

xxd also runs on average about 5 times slower than vim xxd, this is
because of read reading 16 bytes at a time, also not hard to fix, but
very hard to fix cleanly.

xxd has a -d flag to do decimal address lables that I added in this patch.

Toybox xxd intentionally caps itself at 1 file per invocation, "Why?": Vim xxd is
a bloated pile of garbage with things like EBCDIC support. They added a 
"improvement" where if you gave 2 files to it, it would rewrite the contents
of the second with the output of the first because it was made for operating
systems where file redirection wasn't a built in thing. As someone who's lost
data because of this, I'm glad there isn't support for this in toybox xxd.

But even though we do loopfiles() over the arguments, There isn't any actual way
to take advantage of that code since we cap it at one file. Removing the cap doesn't
break anything that wouldn't already be broken, so I removed the ">1" in the option
string in this patch.

-   Oliver Webb <aquahobbyist at proton.me>

P.S. As someone who once did a cleanup pass on a vim xxd fork a while back,
a reason to not do colorized output is that you are outputting ANSI codes
for _every byte, twice_. And unless you have code to optimize that down, your
files can take 3/4 times longer to print out via colorized xxd since every
line goes from 68 bytes to 420:

Colored xxd: 
0001d590: 306d 201b 5b31 3b33 376d 3030 1b5b 306d  0m .[1;37m00.[0m
0001d5a0: 1b5b 313b 3337 6d30 301b 5b30 6d20 1b5b  .[1;37m00.[0m .[
0001d5b0: 313b 3337 6d30 301b 5b30 6d1b 5b31 3b33  1;37m00.[0m.[1;3
Normal xxd:
000159a0: 3030 2030 3030 3020 3030 3030 2030 3030  00 0000 0000 000
000159b0: 3020 3030 3030 2030 3030 3020 3030 3030  0 0000 0000 0000
000159c0: 2030 3030 3020 202e 2e2e 2e2e 2e2e 2e2e   0000  .........
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-xxd-d-Decimal-Address-Label-Don-t-cap-at-one-file-Wr.patch
Type: text/x-patch
Size: 1696 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20240421/b94eb92e/attachment.bin>


More information about the Toybox mailing list