Last change
on this file since 2859 was 2725, checked in by Bruno Cornec, 14 years ago |
- Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
|
File size:
1.5 KB
|
Rev | Line | |
---|
[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * cat -v implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2006 Rob Landley <rob@landley.net>
|
---|
| 6 | *
|
---|
[2725] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
---|
[821] | 8 | */
|
---|
| 9 |
|
---|
| 10 | /* See "Cat -v considered harmful" at
|
---|
| 11 | * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
|
---|
| 12 |
|
---|
[1765] | 13 | #include "libbb.h"
|
---|
[821] | 14 |
|
---|
[2725] | 15 | int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 16 | int catv_main(int argc UNUSED_PARAM, char **argv)
|
---|
[821] | 17 | {
|
---|
[1765] | 18 | int retval = EXIT_SUCCESS;
|
---|
| 19 | int fd;
|
---|
| 20 | unsigned flags;
|
---|
[821] | 21 |
|
---|
[1765] | 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)
|
---|
| 26 | flags ^= CATV_OPT_v;
|
---|
| 27 | argv += optind;
|
---|
[821] | 28 |
|
---|
[1765] | 29 | /* Read from stdin if there's nothing else to do. */
|
---|
[2725] | 30 | if (!argv[0])
|
---|
| 31 | *--argv = (char*)"-";
|
---|
[821] | 32 | do {
|
---|
[2725] | 33 | fd = open_or_warn_stdin(*argv);
|
---|
[1765] | 34 | if (fd < 0) {
|
---|
| 35 | retval = EXIT_FAILURE;
|
---|
| 36 | continue;
|
---|
| 37 | }
|
---|
| 38 | for (;;) {
|
---|
[821] | 39 | int i, res;
|
---|
| 40 |
|
---|
[1765] | 41 | #define read_buf bb_common_bufsiz1
|
---|
| 42 | res = read(fd, read_buf, COMMON_BUFSIZE);
|
---|
| 43 | if (res < 0)
|
---|
| 44 | retval = EXIT_FAILURE;
|
---|
| 45 | if (res < 1)
|
---|
| 46 | break;
|
---|
| 47 | for (i = 0; i < res; i++) {
|
---|
| 48 | unsigned char c = read_buf[i];
|
---|
[821] | 49 |
|
---|
[1765] | 50 | if (c > 126 && (flags & CATV_OPT_v)) {
|
---|
[821] | 51 | if (c == 127) {
|
---|
| 52 | printf("^?");
|
---|
| 53 | continue;
|
---|
| 54 | }
|
---|
[1765] | 55 | printf("M-");
|
---|
| 56 | c -= 128;
|
---|
[821] | 57 | }
|
---|
| 58 | if (c < 32) {
|
---|
| 59 | if (c == 10) {
|
---|
[1765] | 60 | if (flags & CATV_OPT_e)
|
---|
[2725] | 61 | bb_putchar('$');
|
---|
[1765] | 62 | } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
|
---|
[821] | 63 | printf("^%c", c+'@');
|
---|
| 64 | continue;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
[2725] | 67 | bb_putchar(c);
|
---|
[821] | 68 | }
|
---|
| 69 | }
|
---|
[1765] | 70 | if (ENABLE_FEATURE_CLEAN_UP && fd)
|
---|
| 71 | close(fd);
|
---|
[821] | 72 | } while (*++argv);
|
---|
| 73 |
|
---|
[1765] | 74 | fflush_stdout_and_exit(retval);
|
---|
[821] | 75 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.