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)
17 int retval = EXIT_SUCCESS, fd;
20 flags = getopt32(argc, argv, "etv");
21 #define CATV_OPT_e (1<<0)
22 #define CATV_OPT_t (1<<1)
23 #define CATV_OPT_v (1<<2)
28 /* Read from stdin if there's nothing else to do. */
30 if (*argv && 0 > (fd = xopen(*argv, O_RDONLY)))
31 retval = EXIT_FAILURE;
35 res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
37 retval = EXIT_FAILURE;
40 for (i = 0; i < res; i++) {
41 char c = bb_common_bufsiz1[i];
43 if (c > 126 && (flags & CATV_OPT_v)) {
54 if (flags & CATV_OPT_e)
56 } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
64 if (ENABLE_FEATURE_CLEAN_UP && fd)
68 fflush_stdout_and_exit(retval);