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 */
15 int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16 int catv_main(int argc UNUSED_PARAM, char **argv)
18 int retval = EXIT_SUCCESS;
22 flags = getopt32(argv, "etv");
23 #define CATV_OPT_e (1<<0)
24 #define CATV_OPT_t (1<<1)
25 #define CATV_OPT_v (1<<2)
29 /* Read from stdin if there's nothing else to do. */
33 fd = open_or_warn_stdin(*argv);
35 retval = EXIT_FAILURE;
41 #define read_buf bb_common_bufsiz1
42 res = read(fd, read_buf, COMMON_BUFSIZE);
44 retval = EXIT_FAILURE;
47 for (i = 0; i < res; i++) {
48 unsigned char c = read_buf[i];
50 if (c > 126 && (flags & CATV_OPT_v)) {
60 if (flags & CATV_OPT_e)
62 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
70 if (ENABLE_FEATURE_CLEAN_UP && fd)
74 fflush_stdout_and_exit(retval);