3 * cat -v implementation for toybox
5 * Copyright (C) 2006, 2007 Rob Landley <rob@landley.net>
7 * Not in SUSv3, but see "Cat -v considered harmful" at
8 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz
10 USE_CATV(NEWTOY(catv, "vte", TOYFLAG_USR|TOYFLAG_BIN))
16 usage: catv [-evt] [filename...]
18 Display nonprinting characters as escape sequences. Use M-x for
19 high ascii characters (>127), and ^x for other nonprinting chars.
21 -e Mark each newline with $
23 -v Don't use ^x or M-x escapes.
28 // Callback function for loopfiles()
30 static void do_catv(int fd, char *name)
35 len = read(fd, toybuf, sizeof(toybuf));
36 if (len < 0) toys.exitval = EXIT_FAILURE;
38 for (i=0; i<len; i++) {
41 if (c > 126 && (toys.optflags & 4)) {
52 if (toys.optflags & 1) xputc('$');
53 } else if (toys.optflags & (c==9 ? 2 : 4)) {
66 loopfiles(toys.optargs, do_catv);