[Toybox] [PATCH] find: support -printf \0 octal escapes and \c.

enh enh at google.com
Mon Sep 2 14:19:12 PDT 2019


On Sun, Sep 1, 2019 at 6:18 PM Rob Landley <rob at landley.net> wrote:
>
> On 8/31/19 11:31 PM, enh via Toybox wrote:
> > I think when I wrote this I tested the named escapes like \n and hex
> > escapes, and when I found \x wasn't supported I didn't even think of
> > octal. And I only learned about \c when I was looking at echo and printf
> > to compare their escape implementations a few weeks back.
>
> I was fixing this by implementing octal escapes, I just haven't gotten back to
> that tab yet. :)

well, now you have a patch :-)

> > Add the missing escapes and corresponding tests.
>
> I'm kinda frustrated that we've already implemented \c support twice elsewhere,
> and it's not sharing code. :(

my plan -- after realizing how different all these commands' behavior
is in GNU land -- is basically to fix everything and then, when we
have a complete set of all the differences, worry about trying to
factor out into unescape_buf/unescape_out (my hexedit changes require
the former, and vi presumably will too).

> $ grep "'c'" toys/*/{echo,printf}.c
> toys/posix/echo.c:        else if (slash=='c') return;
> toys/posix/printf.c:  if (*ptr == 'c') xexit();
> toys/posix/printf.c:        } else if (c == 'c') printf(toybuf, wp[0], wp[1], *aa);
>
> I should take a look at that...

(as an aside, i still haven't understood \c. i've never seen it used
in practice, and the examples i've seen are all of the form "x\cy"
which would be better written as just "x".)

> Yay tests,

one concern i have here is that we're copying the cigarette burns
(https://www.wired.com/1995/09/tognazzini/).

does anyone actually benefit from all these slightly different
behaviors? is anything relying on it? (different behaviors for invalid
octal escapes, say, seems somewhat likely to matter in practice. "find
doesn't support \x", though, seems very unlikely to me. especially
because GNU considers that an error.)

> Rob



More information about the Toybox mailing list