1 /* cat.c - copy inputs to stdout.
3 * Copyright 2006 Rob Landley <rob@landley.net>
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/cat.html
7 * And "Cat -v considered harmful" at
8 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz
10 USE_CAT(NEWTOY(cat, "u"USE_CAT_V("vte"), TOYFLAG_BIN))
11 USE_CATV(NEWTOY(catv, USE_CATV("vte"), TOYFLAG_USR|TOYFLAG_BIN))
17 usage: cat [-u] [file...]
19 Copy (concatenate) files to stdout. If no files listed, copy from stdin.
20 Filename "-" is a synonym for stdin.
22 -u Copy one byte at a time (slow).
31 -e Mark each newline with $
33 -v Display nonprinting characters as escape sequences. Use M-x for
34 high ascii characters (>127), and ^x for other nonprinting chars.
40 usage: catv [-evt] [filename...]
42 Display nonprinting characters as escape sequences. Use M-x for
43 high ascii characters (>127), and ^x for other nonprinting chars.
45 -e Mark each newline with $
47 -v Don't use ^x or M-x escapes.
54 static void do_cat(int fd, char *name)
56 int i, len, size=(toys.optflags & FLAG_u) ? 1 : sizeof(toybuf);
59 len = read(fd, toybuf, size);
61 toys.exitval = EXIT_FAILURE;
62 perror_msg("%s", name);
65 if ((CFG_CAT_V || CFG_CATV) && (toys.optflags&~FLAG_u)) {
66 for (i=0; i<len; i++) {
69 if (c > 126 && (toys.optflags & FLAG_v)) {
81 if (toys.optflags & FLAG_e) xputc('$');
82 } else if (toys.optflags & (c==9 ? FLAG_t : FLAG_v)) {
89 } else xwrite(1, toybuf, len);
95 loopfiles(toys.optargs, do_cat);
100 toys.optflags ^= FLAG_v;
101 loopfiles(toys.optargs, do_cat);