`xxd -r` with `-p` format input (rather than the `xxd -r -p` that
you actually need to decode that) doesn't work because the input
isn't in the expected
<address/offset> : <byte...>
format. "real" xxd silently outputs nothing. toybox complains about
an invalid seek.
This patch outputs a clear error if we don't see the leading
address/offset and either ' ' or ':' as a separator (and tests for
both kinds of input).
Looking at the other use of scanf() in this code and testing against
"real" xxd, the fact that toybox allows `-r -i` to parse input
without commas actually matches (undocumented) xxd behavior, so
I've just added a test for that.
Bug: https://github.com/landley/toybox/issues/452
The original xxd doesn't support -r with -i. The original also outputs
"unsigned char name[] = { ... };" for input other than stdin, but that
actually makes it less useful --- many languages support array
initializers, but far fewer support that exact declaration syntax.
Also fix the -c range checking and defaulting: ><= in the argument string
only works for floating point arguments.
Bug: http://b/64711851
SELinux denials include hex-encoded paths in the log messages; xxd -r -p is
a convenient way to decode them.
The heuristics are a little weird to my mind, but match the documentation
and observed behavior.