1 /* vi: set sw=4 ts=4: */
3 * cat -v implementation for busybox
5 * Copyright (C) 2006 Rob Landley <rob@landley.net>
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 /* See "Cat -v considered harmful" at
11 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
17 int catv_main(int argc, char **argv)
19 int retval = EXIT_SUCCESS, fd, flags;
21 flags = bb_getopt_ulflags(argc, argv, "etv");
24 // Loop through files.
28 // Read from stdin if there's nothing else to do.
31 if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
35 res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
36 if (res < 0) retval = EXIT_FAILURE;
38 for (i=0; i<res; i++) {
39 char c=bb_common_bufsiz1[i];
41 if (c > 126 && (flags & 4)) {
52 if (flags & 1) putchar('$');
53 } else if (flags & (c==9 ? 2 : 4)) {
61 if (ENABLE_FEATURE_CLEAN_UP && fd) close(fd);