Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/catv.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/coreutils/catv.c

    r3232 r3621  
    2020
    2121#include "libbb.h"
     22#include "common_bufsiz.h"
     23
     24#define CATV_OPT_e (1<<0)
     25#define CATV_OPT_t (1<<1)
     26#define CATV_OPT_v (1<<2)
     27struct BUG_const_mismatch {
     28    char BUG_const_mismatch[
     29        CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
     30        ? 1 : -1
     31    ];
     32};
    2233
    2334int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     
    2637    int retval = EXIT_SUCCESS;
    2738    int fd;
    28     unsigned flags;
    29 
    30     flags = getopt32(argv, "etv");
    31 #define CATV_OPT_e (1<<0)
    32 #define CATV_OPT_t (1<<1)
    33 #define CATV_OPT_v (1<<2)
    34     flags ^= CATV_OPT_v;
     39    unsigned opts;
     40    opts = getopt32(argv, "etv");
    3541    argv += optind;
     42#if 0 /* These consts match, we can just pass "opts" to visible() */
     43    if (opts & CATV_OPT_e)
     44        flags |= VISIBLE_ENDLINE;
     45    if (opts & CATV_OPT_t)
     46        flags |= VISIBLE_SHOW_TABS;
     47#endif
    3648
    3749    /* Read from stdin if there's nothing else to do. */
    3850    if (!argv[0])
    3951        *--argv = (char*)"-";
     52
     53#define read_buf bb_common_bufsiz1
     54    setup_common_bufsiz();
    4055    do {
    4156        fd = open_or_warn_stdin(*argv);
     
    4762            int i, res;
    4863
    49 #define read_buf bb_common_bufsiz1
    5064            res = read(fd, read_buf, COMMON_BUFSIZE);
    5165            if (res < 0)
    5266                retval = EXIT_FAILURE;
    53             if (res < 1)
     67            if (res <= 0)
    5468                break;
    5569            for (i = 0; i < res; i++) {
    5670                unsigned char c = read_buf[i];
    57 
    58                 if (c > 126 && (flags & CATV_OPT_v)) {
    59                     if (c == 127) {
    60                         printf("^?");
    61                         continue;
    62                     }
    63                     printf("M-");
    64                     c -= 128;
     71                if (opts & CATV_OPT_v) {
     72                    putchar(c);
     73                } else {
     74                    char buf[sizeof("M-^c")];
     75                    visible(c, buf, opts);
     76                    fputs(buf, stdout);
    6577                }
    66                 if (c < 32) {
    67                     if (c == 10) {
    68                         if (flags & CATV_OPT_e)
    69                             bb_putchar('$');
    70                     } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
    71                         printf("^%c", c+'@');
    72                         continue;
    73                     }
    74                 }
    75                 bb_putchar(c);
    7678            }
    7779        }
Note: See TracChangeset for help on using the changeset viewer.