Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/coreutils/stty.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/stty.c

    r3232 r3621  
    3333
    3434#include "libbb.h"
     35#include "common_bufsiz.h"
    3536
    3637#ifndef _POSIX_VDISABLE
     
    247248/* Which member(s) of 'struct termios' a mode uses */
    248249enum {
    249     /* Do NOT change the order or values, as mode_type_flag()
    250      * depends on them */
    251250    control, input, output, local, combination
    252251};
     252static tcflag_t *get_ptr_to_tcflag(unsigned type, const struct termios *mode)
     253{
     254    static const uint8_t tcflag_offsets[] ALIGN1 = {
     255        offsetof(struct termios, c_cflag), /* control */
     256        offsetof(struct termios, c_iflag), /* input */
     257        offsetof(struct termios, c_oflag), /* output */
     258        offsetof(struct termios, c_lflag)  /* local */
     259    };
     260    if (type <= local) {
     261        return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
     262    }
     263    return NULL;
     264}
    253265
    254266/* Flags for 'struct mode_info' */
     
    307319
    308320/* Mode names given on command line */
    309 static const char mode_name[] =
     321static const char mode_name[] ALIGN1 =
    310322    MI_ENTRY("evenp",    combination, REV        | OMIT, 0,          0 )
    311323    MI_ENTRY("parity",   combination, REV        | OMIT, 0,          0 )
     
    670682
    671683/* Name given on command line */
    672 static const char control_name[] =
     684static const char control_name[] ALIGN1 =
    673685    CI_ENTRY("intr",     CINTR,   VINTR   )
    674686    CI_ENTRY("quit",     CQUIT,   VQUIT   )
     
    712724#define CI_ENTRY(n,s,o) { s, o },
    713725
    714 static const struct control_info control_info[] = {
     726static const struct control_info control_info[] ALIGN2 = {
    715727    /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */
    716728    CI_ENTRY("intr",     CINTR,   VINTR   )
     
    765777    char buf[10];
    766778} FIX_ALIASING;
    767 #define G (*(struct globals*)&bb_common_bufsiz1)
     779#define G (*(struct globals*)bb_common_bufsiz1)
    768780#define INIT_G() do { \
    769781    G.device_name = bb_msg_standard_input; \
    770782    G.max_col = 80; \
    771783} while (0)
    772 
    773 
    774 /* Return a string that is the printable representation of character CH */
    775 /* Adapted from 'cat' by Torbjorn Granlund */
    776 static const char *visible(unsigned ch)
    777 {
    778     char *bpout = G.buf;
    779 
    780     if (ch == _POSIX_VDISABLE)
    781         return "<undef>";
    782 
    783     if (ch >= 128) {
    784         ch -= 128;
    785         *bpout++ = 'M';
    786         *bpout++ = '-';
    787     }
    788 
    789     if (ch < 32) {
    790         *bpout++ = '^';
    791         *bpout++ = ch + 64;
    792     } else if (ch < 127) {
    793         *bpout++ = ch;
    794     } else {
    795         *bpout++ = '^';
    796         *bpout++ = '?';
    797     }
    798 
    799     *bpout = '\0';
    800     return G.buf;
    801 }
    802 
    803 static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
    804 {
    805     static const uint8_t tcflag_offsets[] ALIGN1 = {
    806         offsetof(struct termios, c_cflag), /* control */
    807         offsetof(struct termios, c_iflag), /* input */
    808         offsetof(struct termios, c_oflag), /* output */
    809         offsetof(struct termios, c_lflag)  /* local */
    810     };
    811 
    812     if (type <= local) {
    813         return (tcflag_t*) (((char*)mode) + tcflag_offsets[type]);
    814     }
    815     return NULL;
    816 }
    817784
    818785static void set_speed_or_die(enum speed_setting type, const char *arg,
     
    10431010
    10441011    for (i = 0; i != CIDX_min; ++i) {
     1012        char ch;
    10451013        /* If swtch is the same as susp, don't print both */
    10461014#if VSWTCH == VSUSP
     
    10561024        }
    10571025#endif
    1058         wrapf("%s = %s;", nth_string(control_name, i),
    1059                 visible(mode->c_cc[control_info[i].offset]));
     1026        ch = mode->c_cc[control_info[i].offset];
     1027        if (ch == _POSIX_VDISABLE)
     1028            strcpy(G.buf, "<undef>");
     1029        else
     1030            visible(ch, G.buf, 0);
     1031        wrapf("%s = %s;", nth_string(control_name, i), G.buf);
    10601032    }
    10611033#if VEOF == VMIN
     
    10731045        }
    10741046
    1075         bitsp = mode_type_flag(mode_info[i].type, mode);
     1047        bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
    10761048        mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;
    10771049        if ((*bitsp & mask) == mode_info[i].bits) {
     
    10921064{
    10931065    int i;
    1094     tcflag_t *bitsp;
    10951066
    10961067    for (i = 0; i < NUM_control_info; ++i) {
     
    11031074
    11041075    for (i = 0; i < NUM_mode_info; ++i) {
     1076        tcflag_t val;
     1077        tcflag_t *bitsp = get_ptr_to_tcflag(mode_info[i].type, mode);
     1078
     1079        if (!bitsp)
     1080            continue;
     1081        val = *bitsp & ~((unsigned long)mode_info[i].mask);
    11051082        if (mode_info[i].flags & SANE_SET) {
    1106             bitsp = mode_type_flag(mode_info[i].type, mode);
    1107             *bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask))
    1108                 | mode_info[i].bits;
    1109         } else if (mode_info[i].flags & SANE_UNSET) {
    1110             bitsp = mode_type_flag(mode_info[i].type, mode);
    1111             *bitsp = *bitsp & ~((unsigned long)mode_info[i].mask)
    1112                 & ~mode_info[i].bits;
     1083            *bitsp = val | mode_info[i].bits;
     1084        } else
     1085        if (mode_info[i].flags & SANE_UNSET) {
     1086            *bitsp = val & ~mode_info[i].bits;
    11131087        }
    11141088    }
     
    11201094    tcflag_t *bitsp;
    11211095
    1122     bitsp = mode_type_flag(info->type, mode);
     1096    bitsp = get_ptr_to_tcflag(info->type, mode);
    11231097
    11241098    if (bitsp) {
     1099        tcflag_t val = *bitsp & ~info->mask;
    11251100        if (reversed)
    1126             *bitsp = *bitsp & ~info->mask & ~info->bits;
     1101            *bitsp = val & ~info->bits;
    11271102        else
    1128             *bitsp = (*bitsp & ~info->mask) | info->bits;
     1103            *bitsp = val | info->bits;
    11291104        return;
    11301105    }
    11311106
    1132     /* Combination mode */
     1107    /* !bitsp - it's a "combination" mode */
    11331108    if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) {
    11341109        if (reversed)
     
    14301405
    14311406    if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
    1432         get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);
     1407        G.max_col = get_terminal_width(STDOUT_FILENO);
    14331408        output_func(&mode, display_all);
    14341409        return EXIT_SUCCESS;
     
    15351510
    15361511        if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
    1537 #if CIBAUD
     1512/*
     1513 * I think the below chunk is not necessary on Linux.
     1514 * If you are deleting it, also delete STTY_speed_was_set bit -
     1515 * it is only ever checked here.
     1516 */
     1517#if 0 /* was "if CIBAUD" */
    15381518            /* SunOS 4.1.3 (at least) has the problem that after this sequence,
    15391519               tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
Note: See TracChangeset for help on using the changeset viewer.