From 8a5e89bccf04d2d838f96bb063fb3f84f73f980f Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 31 Aug 2019 21:27:55 -0700 Subject: find: support -printf \0 octal escapes and \c. 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. Add the missing escapes and corresponding tests. Fixes #139. --- toys/posix/find.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'toys') diff --git a/toys/posix/find.c b/toys/posix/find.c index 3317448a..64270c00 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -569,7 +569,15 @@ static int do_find(struct dirtree *new) if (check) for (fmt = ss[1]; *fmt; fmt++) { // Print the parts that aren't escapes if (*fmt == '\\') { - if (!(ch = unescape(*++fmt))) error_exit("bad \\%c", *fmt); + int slash = *++fmt, n = unescape(slash); + + if (n) ch = n; + else if (slash=='c') break; + else if (slash=='0') { + ch = 0; + while (*fmt>='0' && *fmt<='7' && n++<3) ch=(ch*8)+*(fmt++)-'0'; + --fmt; + } else error_exit("bad \\%c", *fmt); putchar(ch); } else if (*fmt != '%') putchar(*fmt); else if (*++fmt == '%') putchar('%'); -- cgit v1.2.3