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);
16 int catv_main(int argc, 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. */
36 fd = open_or_warn(*argv, O_RDONLY);
38 retval = EXIT_FAILURE;
45 #define read_buf bb_common_bufsiz1
46 res = read(fd, read_buf, COMMON_BUFSIZE);
48 retval = EXIT_FAILURE;
51 for (i = 0; i < res; i++) {
52 unsigned char c = read_buf[i];
54 if (c > 126 && (flags & CATV_OPT_v)) {
64 if (flags & CATV_OPT_e)
66 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
74 if (ENABLE_FEATURE_CLEAN_UP && fd)
78 fflush_stdout_and_exit(retval);