Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

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

    r821 r1765  
    1111 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
    1212
    13 #include "busybox.h"
    14 #include <unistd.h>
    15 #include <fcntl.h>
     13#include "libbb.h"
    1614
     15int catv_main(int argc, char **argv);
    1716int catv_main(int argc, char **argv)
    1817{
    19     int retval = EXIT_SUCCESS, fd, flags;
     18    int retval = EXIT_SUCCESS;
     19    int fd;
     20    unsigned flags;
    2021
    21     flags = bb_getopt_ulflags(argc, argv, "etv");
    22     flags ^= 4;
     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;
    2328
    24     // Loop through files.
    25 
    26     argv += optind;
     29    /* Read from stdin if there's nothing else to do. */
     30    fd = 0;
     31    if (!argv[0]) {
     32        argv--;
     33        goto jump_in;
     34    }
    2735    do {
    28         // Read from stdin if there's nothing else to do.
    29 
    30         fd = 0;
    31         if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
    32         else for(;;) {
     36        fd = open_or_warn(*argv, O_RDONLY);
     37        if (fd < 0) {
     38            retval = EXIT_FAILURE;
     39            continue;
     40        }
     41 jump_in:
     42        for (;;) {
    3343            int i, res;
    3444
    35             res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
    36             if (res < 0) retval = EXIT_FAILURE;
    37             if (res <1) break;
    38             for (i=0; i<res; i++) {
    39                 char c=bb_common_bufsiz1[i];
     45#define read_buf bb_common_bufsiz1
     46            res = read(fd, read_buf, COMMON_BUFSIZE);
     47            if (res < 0)
     48                retval = EXIT_FAILURE;
     49            if (res < 1)
     50                break;
     51            for (i = 0; i < res; i++) {
     52                unsigned char c = read_buf[i];
    4053
    41                 if (c > 126 && (flags & 4)) {
     54                if (c > 126 && (flags & CATV_OPT_v)) {
    4255                    if (c == 127) {
    4356                        printf("^?");
    4457                        continue;
    45                     } else {
    46                         printf("M-");
    47                         c -= 128;
    4858                    }
     59                    printf("M-");
     60                    c -= 128;
    4961                }
    5062                if (c < 32) {
    5163                    if (c == 10) {
    52                        if (flags & 1) putchar('$');
    53                     } else if (flags & (c==9 ? 2 : 4)) {
     64                        if (flags & CATV_OPT_e)
     65                            putchar('$');
     66                    } else if (flags & (c==9 ? CATV_OPT_t : CATV_OPT_v)) {
    5467                        printf("^%c", c+'@');
    5568                        continue;
     
    5972            }
    6073        }
    61         if (ENABLE_FEATURE_CLEAN_UP && fd) close(fd);
     74        if (ENABLE_FEATURE_CLEAN_UP && fd)
     75            close(fd);
    6276    } while (*++argv);
    6377
    64     return retval;
     78    fflush_stdout_and_exit(retval);
    6579}
Note: See TracChangeset for help on using the changeset viewer.