Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • 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:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/coreutils/stty.c

    r1765 r2725  
    33   Copyright (C) 1990-1999 Free Software Foundation, Inc.
    44
    5    Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
     5   Licensed under GPLv2 or later, see file LICENSE in this source tree.
    66*/
    77/* Usage: stty [-ag] [-F device] [setting...]
     
    114114#if defined(VSTATUS) && !defined(CSTATUS)
    115115# define CSTATUS Control('t')
     116#endif
     117
     118/* Save us from #ifdef forest plague */
     119#ifndef BSDLY
     120# define BSDLY 0
     121#endif
     122#ifndef CIBAUD
     123# define CIBAUD 0
     124#endif
     125#ifndef CRDLY
     126# define CRDLY 0
     127#endif
     128#ifndef CRTSCTS
     129# define CRTSCTS 0
     130#endif
     131#ifndef ECHOCTL
     132# define ECHOCTL 0
     133#endif
     134#ifndef ECHOKE
     135# define ECHOKE 0
     136#endif
     137#ifndef ECHOPRT
     138# define ECHOPRT 0
     139#endif
     140#ifndef FFDLY
     141# define FFDLY 0
     142#endif
     143#ifndef IEXTEN
     144# define IEXTEN 0
     145#endif
     146#ifndef IMAXBEL
     147# define IMAXBEL 0
     148#endif
     149#ifndef IUCLC
     150# define IUCLC 0
     151#endif
     152#ifndef IXANY
     153# define IXANY 0
     154#endif
     155#ifndef NLDLY
     156# define NLDLY 0
     157#endif
     158#ifndef OCRNL
     159# define OCRNL 0
     160#endif
     161#ifndef OFDEL
     162# define OFDEL 0
     163#endif
     164#ifndef OFILL
     165# define OFILL 0
     166#endif
     167#ifndef OLCUC
     168# define OLCUC 0
     169#endif
     170#ifndef ONLCR
     171# define ONLCR 0
     172#endif
     173#ifndef ONLRET
     174# define ONLRET 0
     175#endif
     176#ifndef ONOCR
     177# define ONOCR 0
     178#endif
     179#ifndef OXTABS
     180# define OXTABS 0
     181#endif
     182#ifndef TABDLY
     183# define TABDLY 0
     184#endif
     185#ifndef TAB1
     186# define TAB1 0
     187#endif
     188#ifndef TAB2
     189# define TAB2 0
     190#endif
     191#ifndef TOSTOP
     192# define TOSTOP 0
     193#endif
     194#ifndef VDSUSP
     195# define VDSUSP 0
     196#endif
     197#ifndef VEOL2
     198# define VEOL2 0
     199#endif
     200#ifndef VFLUSHO
     201# define VFLUSHO 0
     202#endif
     203#ifndef VLNEXT
     204# define VLNEXT 0
     205#endif
     206#ifndef VREPRINT
     207# define VREPRINT 0
     208#endif
     209#ifndef VSTATUS
     210# define VSTATUS 0
     211#endif
     212#ifndef VSWTCH
     213# define VSWTCH 0
     214#endif
     215#ifndef VTDLY
     216# define VTDLY 0
     217#endif
     218#ifndef VWERASE
     219# define VWERASE 0
     220#endif
     221#ifndef XCASE
     222# define XCASE 0
    116223#endif
    117224
     
    128235};
    129236
    130 static const char evenp     [] ALIGN1 = "evenp";
    131 static const char raw       [] ALIGN1 = "raw";
    132 static const char stty_min  [] ALIGN1 = "min";
    133 static const char stty_time [] ALIGN1 = "time";
    134 static const char stty_swtch[] ALIGN1 = "swtch";
    135 static const char stty_eol  [] ALIGN1 = "eol";
    136 static const char stty_eof  [] ALIGN1 = "eof";
    137 static const char parity    [] ALIGN1 = "parity";
    138 static const char stty_oddp [] ALIGN1 = "oddp";
    139 static const char stty_nl   [] ALIGN1 = "nl";
    140 static const char stty_ek   [] ALIGN1 = "ek";
    141 static const char stty_sane [] ALIGN1 = "sane";
    142 static const char cbreak    [] ALIGN1 = "cbreak";
    143 static const char stty_pass8[] ALIGN1 = "pass8";
    144 static const char litout    [] ALIGN1 = "litout";
    145 static const char cooked    [] ALIGN1 = "cooked";
    146 static const char decctlq   [] ALIGN1 = "decctlq";
    147 static const char stty_tabs [] ALIGN1 = "tabs";
    148 static const char stty_lcase[] ALIGN1 = "lcase";
    149 static const char stty_LCASE[] ALIGN1 = "LCASE";
    150 static const char stty_crt  [] ALIGN1 = "crt";
    151 static const char stty_dec  [] ALIGN1 = "dec";
    152 
    153237/* Flags for 'struct mode_info' */
    154238#define SANE_SET 1              /* Set in 'sane' mode                  */
     
    157241#define OMIT 8                  /* Don't display value                 */
    158242
    159 /* Each mode */
     243
     244/* Each mode.
     245 * This structure should be kept as small as humanly possible.
     246 */
    160247struct mode_info {
    161     const char *const name;      /* Name given on command line           */
    162     const unsigned char type;     /* Which structure element to change    */
    163     const unsigned char flags;    /* Setting and display options          */
    164     /* were using short here, but ppc32 was unhappy: */
     248    const uint8_t type;           /* Which structure element to change    */
     249    const uint8_t flags;          /* Setting and display options          */
     250    /* only these values are ever used, so... */
     251#if   (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x100
     252    const uint8_t mask;
     253#elif (CSIZE | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY) < 0x10000
     254    const uint16_t mask;
     255#else
    165256    const tcflag_t mask;          /* Other bits to turn off for this mode */
     257#endif
     258    /* was using short here, but ppc32 was unhappy */
    166259    const tcflag_t bits;          /* Bits to set for this mode            */
    167260};
    168261
    169 /* We can optimize it further by using name[8] instead of char *name */
    170 /* but beware of "if (info->name == evenp)" checks! */
    171 /* Need to replace them with "if (info == &mode_info[EVENP_INDX])" */
    172 
    173 #define MI_ENTRY(N,T,F,B,M) { N, T, F, M, B }
     262enum {
     263    /* Must match mode_name[] and mode_info[] order! */
     264    IDX_evenp = 0,
     265    IDX_parity,
     266    IDX_oddp,
     267    IDX_nl,
     268    IDX_ek,
     269    IDX_sane,
     270    IDX_cooked,
     271    IDX_raw,
     272    IDX_pass8,
     273    IDX_litout,
     274    IDX_cbreak,
     275    IDX_crt,
     276    IDX_dec,
     277#if IXANY
     278    IDX_decctlq,
     279#endif
     280#if TABDLY || OXTABS
     281    IDX_tabs,
     282#endif
     283#if XCASE && IUCLC && OLCUC
     284    IDX_lcase,
     285    IDX_LCASE,
     286#endif
     287};
     288
     289#define MI_ENTRY(N,T,F,B,M) N "\0"
     290
     291/* Mode names given on command line */
     292static const char mode_name[] =
     293    MI_ENTRY("evenp",    combination, REV        | OMIT, 0,          0 )
     294    MI_ENTRY("parity",   combination, REV        | OMIT, 0,          0 )
     295    MI_ENTRY("oddp",     combination, REV        | OMIT, 0,          0 )
     296    MI_ENTRY("nl",       combination, REV        | OMIT, 0,          0 )
     297    MI_ENTRY("ek",       combination, OMIT,              0,          0 )
     298    MI_ENTRY("sane",     combination, OMIT,              0,          0 )
     299    MI_ENTRY("cooked",   combination, REV        | OMIT, 0,          0 )
     300    MI_ENTRY("raw",      combination, REV        | OMIT, 0,          0 )
     301    MI_ENTRY("pass8",    combination, REV        | OMIT, 0,          0 )
     302    MI_ENTRY("litout",   combination, REV        | OMIT, 0,          0 )
     303    MI_ENTRY("cbreak",   combination, REV        | OMIT, 0,          0 )
     304    MI_ENTRY("crt",      combination, OMIT,              0,          0 )
     305    MI_ENTRY("dec",      combination, OMIT,              0,          0 )
     306#if IXANY
     307    MI_ENTRY("decctlq",  combination, REV        | OMIT, 0,          0 )
     308#endif
     309#if TABDLY || OXTABS
     310    MI_ENTRY("tabs",     combination, REV        | OMIT, 0,          0 )
     311#endif
     312#if XCASE && IUCLC && OLCUC
     313    MI_ENTRY("lcase",    combination, REV        | OMIT, 0,          0 )
     314    MI_ENTRY("LCASE",    combination, REV        | OMIT, 0,          0 )
     315#endif
     316    MI_ENTRY("parenb",   control,     REV,               PARENB,     0 )
     317    MI_ENTRY("parodd",   control,     REV,               PARODD,     0 )
     318    MI_ENTRY("cs5",      control,     0,                 CS5,     CSIZE)
     319    MI_ENTRY("cs6",      control,     0,                 CS6,     CSIZE)
     320    MI_ENTRY("cs7",      control,     0,                 CS7,     CSIZE)
     321    MI_ENTRY("cs8",      control,     0,                 CS8,     CSIZE)
     322    MI_ENTRY("hupcl",    control,     REV,               HUPCL,      0 )
     323    MI_ENTRY("hup",      control,     REV        | OMIT, HUPCL,      0 )
     324    MI_ENTRY("cstopb",   control,     REV,               CSTOPB,     0 )
     325    MI_ENTRY("cread",    control,     SANE_SET   | REV,  CREAD,      0 )
     326    MI_ENTRY("clocal",   control,     REV,               CLOCAL,     0 )
     327#if CRTSCTS
     328    MI_ENTRY("crtscts",  control,     REV,               CRTSCTS,    0 )
     329#endif
     330    MI_ENTRY("ignbrk",   input,       SANE_UNSET | REV,  IGNBRK,     0 )
     331    MI_ENTRY("brkint",   input,       SANE_SET   | REV,  BRKINT,     0 )
     332    MI_ENTRY("ignpar",   input,       REV,               IGNPAR,     0 )
     333    MI_ENTRY("parmrk",   input,       REV,               PARMRK,     0 )
     334    MI_ENTRY("inpck",    input,       REV,               INPCK,      0 )
     335    MI_ENTRY("istrip",   input,       REV,               ISTRIP,     0 )
     336    MI_ENTRY("inlcr",    input,       SANE_UNSET | REV,  INLCR,      0 )
     337    MI_ENTRY("igncr",    input,       SANE_UNSET | REV,  IGNCR,      0 )
     338    MI_ENTRY("icrnl",    input,       SANE_SET   | REV,  ICRNL,      0 )
     339    MI_ENTRY("ixon",     input,       REV,               IXON,       0 )
     340    MI_ENTRY("ixoff",    input,       SANE_UNSET | REV,  IXOFF,      0 )
     341    MI_ENTRY("tandem",   input,       REV        | OMIT, IXOFF,      0 )
     342#if IUCLC
     343    MI_ENTRY("iuclc",    input,       SANE_UNSET | REV,  IUCLC,      0 )
     344#endif
     345#if IXANY
     346    MI_ENTRY("ixany",    input,       SANE_UNSET | REV,  IXANY,      0 )
     347#endif
     348#if IMAXBEL
     349    MI_ENTRY("imaxbel",  input,       SANE_SET   | REV,  IMAXBEL,    0 )
     350#endif
     351    MI_ENTRY("opost",    output,      SANE_SET   | REV,  OPOST,      0 )
     352#if OLCUC
     353    MI_ENTRY("olcuc",    output,      SANE_UNSET | REV,  OLCUC,      0 )
     354#endif
     355#if OCRNL
     356    MI_ENTRY("ocrnl",    output,      SANE_UNSET | REV,  OCRNL,      0 )
     357#endif
     358#if ONLCR
     359    MI_ENTRY("onlcr",    output,      SANE_SET   | REV,  ONLCR,      0 )
     360#endif
     361#if ONOCR
     362    MI_ENTRY("onocr",    output,      SANE_UNSET | REV,  ONOCR,      0 )
     363#endif
     364#if ONLRET
     365    MI_ENTRY("onlret",   output,      SANE_UNSET | REV,  ONLRET,     0 )
     366#endif
     367#if OFILL
     368    MI_ENTRY("ofill",    output,      SANE_UNSET | REV,  OFILL,      0 )
     369#endif
     370#if OFDEL
     371    MI_ENTRY("ofdel",    output,      SANE_UNSET | REV,  OFDEL,      0 )
     372#endif
     373#if NLDLY
     374    MI_ENTRY("nl1",      output,      SANE_UNSET,        NL1,     NLDLY)
     375    MI_ENTRY("nl0",      output,      SANE_SET,          NL0,     NLDLY)
     376#endif
     377#if CRDLY
     378    MI_ENTRY("cr3",      output,      SANE_UNSET,        CR3,     CRDLY)
     379    MI_ENTRY("cr2",      output,      SANE_UNSET,        CR2,     CRDLY)
     380    MI_ENTRY("cr1",      output,      SANE_UNSET,        CR1,     CRDLY)
     381    MI_ENTRY("cr0",      output,      SANE_SET,          CR0,     CRDLY)
     382#endif
     383
     384#if TABDLY
     385    MI_ENTRY("tab3",     output,      SANE_UNSET,        TAB3,   TABDLY)
     386# if TAB2
     387    MI_ENTRY("tab2",     output,      SANE_UNSET,        TAB2,   TABDLY)
     388# endif
     389# if TAB1
     390    MI_ENTRY("tab1",     output,      SANE_UNSET,        TAB1,   TABDLY)
     391# endif
     392    MI_ENTRY("tab0",     output,      SANE_SET,          TAB0,   TABDLY)
     393#else
     394# if OXTABS
     395    MI_ENTRY("tab3",     output,      SANE_UNSET,        OXTABS,     0 )
     396# endif
     397#endif
     398
     399#if BSDLY
     400    MI_ENTRY("bs1",      output,      SANE_UNSET,        BS1,     BSDLY)
     401    MI_ENTRY("bs0",      output,      SANE_SET,          BS0,     BSDLY)
     402#endif
     403#if VTDLY
     404    MI_ENTRY("vt1",      output,      SANE_UNSET,        VT1,     VTDLY)
     405    MI_ENTRY("vt0",      output,      SANE_SET,          VT0,     VTDLY)
     406#endif
     407#if FFDLY
     408    MI_ENTRY("ff1",      output,      SANE_UNSET,        FF1,     FFDLY)
     409    MI_ENTRY("ff0",      output,      SANE_SET,          FF0,     FFDLY)
     410#endif
     411    MI_ENTRY("isig",     local,       SANE_SET   | REV,  ISIG,       0 )
     412    MI_ENTRY("icanon",   local,       SANE_SET   | REV,  ICANON,     0 )
     413#if IEXTEN
     414    MI_ENTRY("iexten",   local,       SANE_SET   | REV,  IEXTEN,     0 )
     415#endif
     416    MI_ENTRY("echo",     local,       SANE_SET   | REV,  ECHO,       0 )
     417    MI_ENTRY("echoe",    local,       SANE_SET   | REV,  ECHOE,      0 )
     418    MI_ENTRY("crterase", local,       REV        | OMIT, ECHOE,      0 )
     419    MI_ENTRY("echok",    local,       SANE_SET   | REV,  ECHOK,      0 )
     420    MI_ENTRY("echonl",   local,       SANE_UNSET | REV,  ECHONL,     0 )
     421    MI_ENTRY("noflsh",   local,       SANE_UNSET | REV,  NOFLSH,     0 )
     422#if XCASE
     423    MI_ENTRY("xcase",    local,       SANE_UNSET | REV,  XCASE,      0 )
     424#endif
     425#if TOSTOP
     426    MI_ENTRY("tostop",   local,       SANE_UNSET | REV,  TOSTOP,     0 )
     427#endif
     428#if ECHOPRT
     429    MI_ENTRY("echoprt",  local,       SANE_UNSET | REV,  ECHOPRT,    0 )
     430    MI_ENTRY("prterase", local,       REV | OMIT,        ECHOPRT,    0 )
     431#endif
     432#if ECHOCTL
     433    MI_ENTRY("echoctl",  local,       SANE_SET   | REV,  ECHOCTL,    0 )
     434    MI_ENTRY("ctlecho",  local,       REV        | OMIT, ECHOCTL,    0 )
     435#endif
     436#if ECHOKE
     437    MI_ENTRY("echoke",   local,       SANE_SET   | REV,  ECHOKE,     0 )
     438    MI_ENTRY("crtkill",  local,       REV        | OMIT, ECHOKE,     0 )
     439#endif
     440    ;
     441
     442#undef MI_ENTRY
     443#define MI_ENTRY(N,T,F,B,M) { T, F, M, B },
    174444
    175445static const struct mode_info mode_info[] = {
    176     MI_ENTRY("parenb",   control,     REV,               PARENB,     0 ),
    177     MI_ENTRY("parodd",   control,     REV,               PARODD,     0 ),
    178     MI_ENTRY("cs5",      control,     0,                 CS5,     CSIZE),
    179     MI_ENTRY("cs6",      control,     0,                 CS6,     CSIZE),
    180     MI_ENTRY("cs7",      control,     0,                 CS7,     CSIZE),
    181     MI_ENTRY("cs8",      control,     0,                 CS8,     CSIZE),
    182     MI_ENTRY("hupcl",    control,     REV,               HUPCL,      0 ),
    183     MI_ENTRY("hup",      control,     REV        | OMIT, HUPCL,      0 ),
    184     MI_ENTRY("cstopb",   control,     REV,               CSTOPB,     0 ),
    185     MI_ENTRY("cread",    control,     SANE_SET   | REV,  CREAD,      0 ),
    186     MI_ENTRY("clocal",   control,     REV,               CLOCAL,     0 ),
    187 #ifdef CRTSCTS
    188     MI_ENTRY("crtscts",  control,     REV,               CRTSCTS,    0 ),
    189 #endif
    190     MI_ENTRY("ignbrk",   input,       SANE_UNSET | REV,  IGNBRK,     0 ),
    191     MI_ENTRY("brkint",   input,       SANE_SET   | REV,  BRKINT,     0 ),
    192     MI_ENTRY("ignpar",   input,       REV,               IGNPAR,     0 ),
    193     MI_ENTRY("parmrk",   input,       REV,               PARMRK,     0 ),
    194     MI_ENTRY("inpck",    input,       REV,               INPCK,      0 ),
    195     MI_ENTRY("istrip",   input,       REV,               ISTRIP,     0 ),
    196     MI_ENTRY("inlcr",    input,       SANE_UNSET | REV,  INLCR,      0 ),
    197     MI_ENTRY("igncr",    input,       SANE_UNSET | REV,  IGNCR,      0 ),
    198     MI_ENTRY("icrnl",    input,       SANE_SET   | REV,  ICRNL,      0 ),
    199     MI_ENTRY("ixon",     input,       REV,               IXON,       0 ),
    200     MI_ENTRY("ixoff",    input,       SANE_UNSET | REV,  IXOFF,      0 ),
    201     MI_ENTRY("tandem",   input,       REV        | OMIT, IXOFF,      0 ),
    202 #ifdef IUCLC
    203     MI_ENTRY("iuclc",    input,       SANE_UNSET | REV,  IUCLC,      0 ),
    204 #endif
    205 #ifdef IXANY
    206     MI_ENTRY("ixany",    input,       SANE_UNSET | REV,  IXANY,      0 ),
    207 #endif
    208 #ifdef IMAXBEL
    209     MI_ENTRY("imaxbel",  input,       SANE_SET   | REV,  IMAXBEL,    0 ),
    210 #endif
    211     MI_ENTRY("opost",    output,      SANE_SET   | REV,  OPOST,      0 ),
    212 #ifdef OLCUC
    213     MI_ENTRY("olcuc",    output,      SANE_UNSET | REV,  OLCUC,      0 ),
    214 #endif
    215 #ifdef OCRNL
    216     MI_ENTRY("ocrnl",    output,      SANE_UNSET | REV,  OCRNL,      0 ),
    217 #endif
    218 #ifdef ONLCR
    219     MI_ENTRY("onlcr",    output,      SANE_SET   | REV,  ONLCR,      0 ),
    220 #endif
    221 #ifdef ONOCR
    222     MI_ENTRY("onocr",    output,      SANE_UNSET | REV,  ONOCR,      0 ),
    223 #endif
    224 #ifdef ONLRET
    225     MI_ENTRY("onlret",   output,      SANE_UNSET | REV,  ONLRET,     0 ),
    226 #endif
    227 #ifdef OFILL
    228     MI_ENTRY("ofill",    output,      SANE_UNSET | REV,  OFILL,      0 ),
    229 #endif
    230 #ifdef OFDEL
    231     MI_ENTRY("ofdel",    output,      SANE_UNSET | REV,  OFDEL,      0 ),
    232 #endif
    233 #ifdef NLDLY
    234     MI_ENTRY("nl1",      output,      SANE_UNSET,        NL1,     NLDLY),
    235     MI_ENTRY("nl0",      output,      SANE_SET,          NL0,     NLDLY),
    236 #endif
    237 #ifdef CRDLY
    238     MI_ENTRY("cr3",      output,      SANE_UNSET,        CR3,     CRDLY),
    239     MI_ENTRY("cr2",      output,      SANE_UNSET,        CR2,     CRDLY),
    240     MI_ENTRY("cr1",      output,      SANE_UNSET,        CR1,     CRDLY),
    241     MI_ENTRY("cr0",      output,      SANE_SET,          CR0,     CRDLY),
    242 #endif
    243 
    244 #ifdef TABDLY
    245     MI_ENTRY("tab3",     output,      SANE_UNSET,        TAB3,   TABDLY),
    246     MI_ENTRY("tab2",     output,      SANE_UNSET,        TAB2,   TABDLY),
    247     MI_ENTRY("tab1",     output,      SANE_UNSET,        TAB1,   TABDLY),
    248     MI_ENTRY("tab0",     output,      SANE_SET,          TAB0,   TABDLY),
     446    /* This should be verbatim cut-n-paste copy of the above MI_ENTRYs */
     447    MI_ENTRY("evenp",    combination, REV        | OMIT, 0,          0 )
     448    MI_ENTRY("parity",   combination, REV        | OMIT, 0,          0 )
     449    MI_ENTRY("oddp",     combination, REV        | OMIT, 0,          0 )
     450    MI_ENTRY("nl",       combination, REV        | OMIT, 0,          0 )
     451    MI_ENTRY("ek",       combination, OMIT,              0,          0 )
     452    MI_ENTRY("sane",     combination, OMIT,              0,          0 )
     453    MI_ENTRY("cooked",   combination, REV        | OMIT, 0,          0 )
     454    MI_ENTRY("raw",      combination, REV        | OMIT, 0,          0 )
     455    MI_ENTRY("pass8",    combination, REV        | OMIT, 0,          0 )
     456    MI_ENTRY("litout",   combination, REV        | OMIT, 0,          0 )
     457    MI_ENTRY("cbreak",   combination, REV        | OMIT, 0,          0 )
     458    MI_ENTRY("crt",      combination, OMIT,              0,          0 )
     459    MI_ENTRY("dec",      combination, OMIT,              0,          0 )
     460#if IXANY
     461    MI_ENTRY("decctlq",  combination, REV        | OMIT, 0,          0 )
     462#endif
     463#if TABDLY || OXTABS
     464    MI_ENTRY("tabs",     combination, REV        | OMIT, 0,          0 )
     465#endif
     466#if XCASE && IUCLC && OLCUC
     467    MI_ENTRY("lcase",    combination, REV        | OMIT, 0,          0 )
     468    MI_ENTRY("LCASE",    combination, REV        | OMIT, 0,          0 )
     469#endif
     470    MI_ENTRY("parenb",   control,     REV,               PARENB,     0 )
     471    MI_ENTRY("parodd",   control,     REV,               PARODD,     0 )
     472    MI_ENTRY("cs5",      control,     0,                 CS5,     CSIZE)
     473    MI_ENTRY("cs6",      control,     0,                 CS6,     CSIZE)
     474    MI_ENTRY("cs7",      control,     0,                 CS7,     CSIZE)
     475    MI_ENTRY("cs8",      control,     0,                 CS8,     CSIZE)
     476    MI_ENTRY("hupcl",    control,     REV,               HUPCL,      0 )
     477    MI_ENTRY("hup",      control,     REV        | OMIT, HUPCL,      0 )
     478    MI_ENTRY("cstopb",   control,     REV,               CSTOPB,     0 )
     479    MI_ENTRY("cread",    control,     SANE_SET   | REV,  CREAD,      0 )
     480    MI_ENTRY("clocal",   control,     REV,               CLOCAL,     0 )
     481#if CRTSCTS
     482    MI_ENTRY("crtscts",  control,     REV,               CRTSCTS,    0 )
     483#endif
     484    MI_ENTRY("ignbrk",   input,       SANE_UNSET | REV,  IGNBRK,     0 )
     485    MI_ENTRY("brkint",   input,       SANE_SET   | REV,  BRKINT,     0 )
     486    MI_ENTRY("ignpar",   input,       REV,               IGNPAR,     0 )
     487    MI_ENTRY("parmrk",   input,       REV,               PARMRK,     0 )
     488    MI_ENTRY("inpck",    input,       REV,               INPCK,      0 )
     489    MI_ENTRY("istrip",   input,       REV,               ISTRIP,     0 )
     490    MI_ENTRY("inlcr",    input,       SANE_UNSET | REV,  INLCR,      0 )
     491    MI_ENTRY("igncr",    input,       SANE_UNSET | REV,  IGNCR,      0 )
     492    MI_ENTRY("icrnl",    input,       SANE_SET   | REV,  ICRNL,      0 )
     493    MI_ENTRY("ixon",     input,       REV,               IXON,       0 )
     494    MI_ENTRY("ixoff",    input,       SANE_UNSET | REV,  IXOFF,      0 )
     495    MI_ENTRY("tandem",   input,       REV        | OMIT, IXOFF,      0 )
     496#if IUCLC
     497    MI_ENTRY("iuclc",    input,       SANE_UNSET | REV,  IUCLC,      0 )
     498#endif
     499#if IXANY
     500    MI_ENTRY("ixany",    input,       SANE_UNSET | REV,  IXANY,      0 )
     501#endif
     502#if IMAXBEL
     503    MI_ENTRY("imaxbel",  input,       SANE_SET   | REV,  IMAXBEL,    0 )
     504#endif
     505    MI_ENTRY("opost",    output,      SANE_SET   | REV,  OPOST,      0 )
     506#if OLCUC
     507    MI_ENTRY("olcuc",    output,      SANE_UNSET | REV,  OLCUC,      0 )
     508#endif
     509#if OCRNL
     510    MI_ENTRY("ocrnl",    output,      SANE_UNSET | REV,  OCRNL,      0 )
     511#endif
     512#if ONLCR
     513    MI_ENTRY("onlcr",    output,      SANE_SET   | REV,  ONLCR,      0 )
     514#endif
     515#if ONOCR
     516    MI_ENTRY("onocr",    output,      SANE_UNSET | REV,  ONOCR,      0 )
     517#endif
     518#if ONLRET
     519    MI_ENTRY("onlret",   output,      SANE_UNSET | REV,  ONLRET,     0 )
     520#endif
     521#if OFILL
     522    MI_ENTRY("ofill",    output,      SANE_UNSET | REV,  OFILL,      0 )
     523#endif
     524#if OFDEL
     525    MI_ENTRY("ofdel",    output,      SANE_UNSET | REV,  OFDEL,      0 )
     526#endif
     527#if NLDLY
     528    MI_ENTRY("nl1",      output,      SANE_UNSET,        NL1,     NLDLY)
     529    MI_ENTRY("nl0",      output,      SANE_SET,          NL0,     NLDLY)
     530#endif
     531#if CRDLY
     532    MI_ENTRY("cr3",      output,      SANE_UNSET,        CR3,     CRDLY)
     533    MI_ENTRY("cr2",      output,      SANE_UNSET,        CR2,     CRDLY)
     534    MI_ENTRY("cr1",      output,      SANE_UNSET,        CR1,     CRDLY)
     535    MI_ENTRY("cr0",      output,      SANE_SET,          CR0,     CRDLY)
     536#endif
     537
     538#if TABDLY
     539    MI_ENTRY("tab3",     output,      SANE_UNSET,        TAB3,   TABDLY)
     540# if TAB2
     541    MI_ENTRY("tab2",     output,      SANE_UNSET,        TAB2,   TABDLY)
     542# endif
     543# if TAB1
     544    MI_ENTRY("tab1",     output,      SANE_UNSET,        TAB1,   TABDLY)
     545# endif
     546    MI_ENTRY("tab0",     output,      SANE_SET,          TAB0,   TABDLY)
    249547#else
    250 # ifdef OXTABS
    251     MI_ENTRY("tab3",     output,      SANE_UNSET,        OXTABS,     0 ),
     548# if OXTABS
     549    MI_ENTRY("tab3",     output,      SANE_UNSET,        OXTABS,     0 )
    252550# endif
    253551#endif
    254552
    255 #ifdef BSDLY
    256     MI_ENTRY("bs1",      output,      SANE_UNSET,        BS1,     BSDLY),
    257     MI_ENTRY("bs0",      output,      SANE_SET,          BS0,     BSDLY),
    258 #endif
    259 #ifdef VTDLY
    260     MI_ENTRY("vt1",      output,      SANE_UNSET,        VT1,     VTDLY),
    261     MI_ENTRY("vt0",      output,      SANE_SET,          VT0,     VTDLY),
    262 #endif
    263 #ifdef FFDLY
    264     MI_ENTRY("ff1",      output,      SANE_UNSET,        FF1,     FFDLY),
    265     MI_ENTRY("ff0",      output,      SANE_SET,          FF0,     FFDLY),
    266 #endif
    267     MI_ENTRY("isig",     local,       SANE_SET   | REV,  ISIG,       0 ),
    268     MI_ENTRY("icanon",   local,       SANE_SET   | REV,  ICANON,     0 ),
    269 #ifdef IEXTEN
    270     MI_ENTRY("iexten",   local,       SANE_SET   | REV,  IEXTEN,     0 ),
    271 #endif
    272     MI_ENTRY("echo",     local,       SANE_SET   | REV,  ECHO,       0 ),
    273     MI_ENTRY("echoe",    local,       SANE_SET   | REV,  ECHOE,      0 ),
    274     MI_ENTRY("crterase", local,       REV        | OMIT, ECHOE,      0 ),
    275     MI_ENTRY("echok",    local,       SANE_SET   | REV,  ECHOK,      0 ),
    276     MI_ENTRY("echonl",   local,       SANE_UNSET | REV,  ECHONL,     0 ),
    277     MI_ENTRY("noflsh",   local,       SANE_UNSET | REV,  NOFLSH,     0 ),
    278 #ifdef XCASE
    279     MI_ENTRY("xcase",    local,       SANE_UNSET | REV,  XCASE,      0 ),
    280 #endif
    281 #ifdef TOSTOP
    282     MI_ENTRY("tostop",   local,       SANE_UNSET | REV,  TOSTOP,     0 ),
    283 #endif
    284 #ifdef ECHOPRT
    285     MI_ENTRY("echoprt",  local,       SANE_UNSET | REV,  ECHOPRT,    0 ),
    286     MI_ENTRY("prterase", local,       REV | OMIT,        ECHOPRT,    0 ),
    287 #endif
    288 #ifdef ECHOCTL
    289     MI_ENTRY("echoctl",  local,       SANE_SET   | REV,  ECHOCTL,    0 ),
    290     MI_ENTRY("ctlecho",  local,       REV        | OMIT, ECHOCTL,    0 ),
    291 #endif
    292 #ifdef ECHOKE
    293     MI_ENTRY("echoke",   local,       SANE_SET   | REV,  ECHOKE,     0 ),
    294     MI_ENTRY("crtkill",  local,       REV        | OMIT, ECHOKE,     0 ),
    295 #endif
    296     MI_ENTRY(evenp,      combination, REV        | OMIT, 0,          0 ),
    297     MI_ENTRY(parity,     combination, REV        | OMIT, 0,          0 ),
    298     MI_ENTRY(stty_oddp,  combination, REV        | OMIT, 0,          0 ),
    299     MI_ENTRY(stty_nl,    combination, REV        | OMIT, 0,          0 ),
    300     MI_ENTRY(stty_ek,    combination, OMIT,              0,          0 ),
    301     MI_ENTRY(stty_sane,  combination, OMIT,              0,          0 ),
    302     MI_ENTRY(cooked,     combination, REV        | OMIT, 0,          0 ),
    303     MI_ENTRY(raw,        combination, REV        | OMIT, 0,          0 ),
    304     MI_ENTRY(stty_pass8, combination, REV        | OMIT, 0,          0 ),
    305     MI_ENTRY(litout,     combination, REV        | OMIT, 0,          0 ),
    306     MI_ENTRY(cbreak,     combination, REV        | OMIT, 0,          0 ),
    307 #ifdef IXANY
    308     MI_ENTRY(decctlq,    combination, REV        | OMIT, 0,          0 ),
    309 #endif
    310 #if defined(TABDLY) || defined(OXTABS)
    311     MI_ENTRY(stty_tabs,  combination, REV        | OMIT, 0,          0 ),
    312 #endif
    313 #if defined(XCASE) && defined(IUCLC) && defined(OLCUC)
    314     MI_ENTRY(stty_lcase, combination, REV        | OMIT, 0,          0 ),
    315     MI_ENTRY(stty_LCASE, combination, REV        | OMIT, 0,          0 ),
    316 #endif
    317     MI_ENTRY(stty_crt,   combination, OMIT,              0,          0 ),
    318     MI_ENTRY(stty_dec,   combination, OMIT,              0,          0 ),
     553#if BSDLY
     554    MI_ENTRY("bs1",      output,      SANE_UNSET,        BS1,     BSDLY)
     555    MI_ENTRY("bs0",      output,      SANE_SET,          BS0,     BSDLY)
     556#endif
     557#if VTDLY
     558    MI_ENTRY("vt1",      output,      SANE_UNSET,        VT1,     VTDLY)
     559    MI_ENTRY("vt0",      output,      SANE_SET,          VT0,     VTDLY)
     560#endif
     561#if FFDLY
     562    MI_ENTRY("ff1",      output,      SANE_UNSET,        FF1,     FFDLY)
     563    MI_ENTRY("ff0",      output,      SANE_SET,          FF0,     FFDLY)
     564#endif
     565    MI_ENTRY("isig",     local,       SANE_SET   | REV,  ISIG,       0 )
     566    MI_ENTRY("icanon",   local,       SANE_SET   | REV,  ICANON,     0 )
     567#if IEXTEN
     568    MI_ENTRY("iexten",   local,       SANE_SET   | REV,  IEXTEN,     0 )
     569#endif
     570    MI_ENTRY("echo",     local,       SANE_SET   | REV,  ECHO,       0 )
     571    MI_ENTRY("echoe",    local,       SANE_SET   | REV,  ECHOE,      0 )
     572    MI_ENTRY("crterase", local,       REV        | OMIT, ECHOE,      0 )
     573    MI_ENTRY("echok",    local,       SANE_SET   | REV,  ECHOK,      0 )
     574    MI_ENTRY("echonl",   local,       SANE_UNSET | REV,  ECHONL,     0 )
     575    MI_ENTRY("noflsh",   local,       SANE_UNSET | REV,  NOFLSH,     0 )
     576#if XCASE
     577    MI_ENTRY("xcase",    local,       SANE_UNSET | REV,  XCASE,      0 )
     578#endif
     579#if TOSTOP
     580    MI_ENTRY("tostop",   local,       SANE_UNSET | REV,  TOSTOP,     0 )
     581#endif
     582#if ECHOPRT
     583    MI_ENTRY("echoprt",  local,       SANE_UNSET | REV,  ECHOPRT,    0 )
     584    MI_ENTRY("prterase", local,       REV | OMIT,        ECHOPRT,    0 )
     585#endif
     586#if ECHOCTL
     587    MI_ENTRY("echoctl",  local,       SANE_SET   | REV,  ECHOCTL,    0 )
     588    MI_ENTRY("ctlecho",  local,       REV        | OMIT, ECHOCTL,    0 )
     589#endif
     590#if ECHOKE
     591    MI_ENTRY("echoke",   local,       SANE_SET   | REV,  ECHOKE,     0 )
     592    MI_ENTRY("crtkill",  local,       REV        | OMIT, ECHOKE,     0 )
     593#endif
    319594};
    320595
     
    323598};
    324599
    325 /* Control character settings */
     600
     601/* Control characters */
    326602struct control_info {
    327     const char *const name;               /* Name given on command line */
    328     const unsigned char saneval;          /* Value to set for 'stty sane' */
    329     const unsigned char offset;           /* Offset in c_cc */
     603    const uint8_t saneval;  /* Value to set for 'stty sane' */
     604    const uint8_t offset;   /* Offset in c_cc */
    330605};
    331606
    332 /* Control characters */
     607enum {
     608    /* Must match control_name[] and control_info[] order! */
     609    CIDX_intr = 0,
     610    CIDX_quit,
     611    CIDX_erase,
     612    CIDX_kill,
     613    CIDX_eof,
     614    CIDX_eol,
     615#if VEOL2
     616    CIDX_eol2,
     617#endif
     618#if VSWTCH
     619    CIDX_swtch,
     620#endif
     621    CIDX_start,
     622    CIDX_stop,
     623    CIDX_susp,
     624#if VDSUSP
     625    CIDX_dsusp,
     626#endif
     627#if VREPRINT
     628    CIDX_rprnt,
     629#endif
     630#if VWERASE
     631    CIDX_werase,
     632#endif
     633#if VLNEXT
     634    CIDX_lnext,
     635#endif
     636#if VFLUSHO
     637    CIDX_flush,
     638#endif
     639#if VSTATUS
     640    CIDX_status,
     641#endif
     642    CIDX_min,
     643    CIDX_time,
     644};
     645
     646#define CI_ENTRY(n,s,o) n "\0"
     647
     648/* Name given on command line */
     649static const char control_name[] =
     650    CI_ENTRY("intr",     CINTR,   VINTR   )
     651    CI_ENTRY("quit",     CQUIT,   VQUIT   )
     652    CI_ENTRY("erase",    CERASE,  VERASE  )
     653    CI_ENTRY("kill",     CKILL,   VKILL   )
     654    CI_ENTRY("eof",      CEOF,    VEOF    )
     655    CI_ENTRY("eol",      CEOL,    VEOL    )
     656#if VEOL2
     657    CI_ENTRY("eol2",     CEOL2,   VEOL2   )
     658#endif
     659#if VSWTCH
     660    CI_ENTRY("swtch",    CSWTCH,  VSWTCH  )
     661#endif
     662    CI_ENTRY("start",    CSTART,  VSTART  )
     663    CI_ENTRY("stop",     CSTOP,   VSTOP   )
     664    CI_ENTRY("susp",     CSUSP,   VSUSP   )
     665#if VDSUSP
     666    CI_ENTRY("dsusp",    CDSUSP,  VDSUSP  )
     667#endif
     668#if VREPRINT
     669    CI_ENTRY("rprnt",    CRPRNT,  VREPRINT)
     670#endif
     671#if VWERASE
     672    CI_ENTRY("werase",   CWERASE, VWERASE )
     673#endif
     674#if VLNEXT
     675    CI_ENTRY("lnext",    CLNEXT,  VLNEXT  )
     676#endif
     677#if VFLUSHO
     678    CI_ENTRY("flush",    CFLUSHO, VFLUSHO )
     679#endif
     680#if VSTATUS
     681    CI_ENTRY("status",   CSTATUS, VSTATUS )
     682#endif
     683    /* These must be last because of the display routines */
     684    CI_ENTRY("min",      1,       VMIN    )
     685    CI_ENTRY("time",     0,       VTIME   )
     686    ;
     687
     688#undef CI_ENTRY
     689#define CI_ENTRY(n,s,o) { s, o },
    333690
    334691static const struct control_info control_info[] = {
    335     {"intr",     CINTR,   VINTR},
    336     {"quit",     CQUIT,   VQUIT},
    337     {"erase",    CERASE,  VERASE},
    338     {"kill",     CKILL,   VKILL},
    339     {stty_eof,   CEOF,    VEOF},
    340     {stty_eol,   CEOL,    VEOL},
    341 #ifdef VEOL2
    342     {"eol2",     CEOL2,   VEOL2},
    343 #endif
    344 #ifdef VSWTCH
    345     {stty_swtch, CSWTCH,  VSWTCH},
    346 #endif
    347     {"start",    CSTART,  VSTART},
    348     {"stop",     CSTOP,   VSTOP},
    349     {"susp",     CSUSP,   VSUSP},
    350 #ifdef VDSUSP
    351     {"dsusp",    CDSUSP,  VDSUSP},
    352 #endif
    353 #ifdef VREPRINT
    354     {"rprnt",    CRPRNT,  VREPRINT},
    355 #endif
    356 #ifdef VWERASE
    357     {"werase",   CWERASE, VWERASE},
    358 #endif
    359 #ifdef VLNEXT
    360     {"lnext",    CLNEXT,  VLNEXT},
    361 #endif
    362 #ifdef VFLUSHO
    363     {"flush",    CFLUSHO, VFLUSHO},
    364 #endif
    365 #ifdef VSTATUS
    366     {"status",   CSTATUS, VSTATUS},
     692    /* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */
     693    CI_ENTRY("intr",     CINTR,   VINTR   )
     694    CI_ENTRY("quit",     CQUIT,   VQUIT   )
     695    CI_ENTRY("erase",    CERASE,  VERASE  )
     696    CI_ENTRY("kill",     CKILL,   VKILL   )
     697    CI_ENTRY("eof",      CEOF,    VEOF    )
     698    CI_ENTRY("eol",      CEOL,    VEOL    )
     699#if VEOL2
     700    CI_ENTRY("eol2",     CEOL2,   VEOL2   )
     701#endif
     702#if VSWTCH
     703    CI_ENTRY("swtch",    CSWTCH,  VSWTCH  )
     704#endif
     705    CI_ENTRY("start",    CSTART,  VSTART  )
     706    CI_ENTRY("stop",     CSTOP,   VSTOP   )
     707    CI_ENTRY("susp",     CSUSP,   VSUSP   )
     708#if VDSUSP
     709    CI_ENTRY("dsusp",    CDSUSP,  VDSUSP  )
     710#endif
     711#if VREPRINT
     712    CI_ENTRY("rprnt",    CRPRNT,  VREPRINT)
     713#endif
     714#if VWERASE
     715    CI_ENTRY("werase",   CWERASE, VWERASE )
     716#endif
     717#if VLNEXT
     718    CI_ENTRY("lnext",    CLNEXT,  VLNEXT  )
     719#endif
     720#if VFLUSHO
     721    CI_ENTRY("flush",    CFLUSHO, VFLUSHO )
     722#endif
     723#if VSTATUS
     724    CI_ENTRY("status",   CSTATUS, VSTATUS )
    367725#endif
    368726    /* These must be last because of the display routines */
    369     {stty_min,   1,       VMIN},
    370     {stty_time,  0,       VTIME},
     727    CI_ENTRY("min",      1,       VMIN    )
     728    CI_ENTRY("time",     0,       VTIME   )
    371729};
    372730
     
    375733};
    376734
    377 /* The width of the screen, for output wrapping */
    378 unsigned max_col = 80; /* default */
    379735
    380736struct globals {
     737    const char *device_name;
     738    /* The width of the screen, for output wrapping */
     739    unsigned max_col;
    381740    /* Current position, to know when to wrap */
    382741    unsigned current_col;
    383742    char buf[10];
    384 };
     743} FIX_ALIASING;
    385744#define G (*(struct globals*)&bb_common_bufsiz1)
    386 
    387 static const char *device_name = bb_msg_standard_input;
     745#define INIT_G() do { \
     746    G.device_name = bb_msg_standard_input; \
     747    G.max_col = 80; \
     748} while (0)
     749
    388750
    389751/* Return a string that is the printable representation of character CH */
     
    418780static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
    419781{
    420     static const unsigned char tcflag_offsets[] ALIGN1 = {
     782    static const uint8_t tcflag_offsets[] ALIGN1 = {
    421783        offsetof(struct termios, c_cflag), /* control */
    422784        offsetof(struct termios, c_iflag), /* input */
     
    431793}
    432794
    433 static void set_speed_or_die(enum speed_setting type, const char *const arg,
    434                     struct termios * const mode)
     795static void set_speed_or_die(enum speed_setting type, const char *arg,
     796                    struct termios *mode)
    435797{
    436798    speed_t baud;
     
    446808}
    447809
    448 static ATTRIBUTE_NORETURN void perror_on_device_and_die(const char *fmt)
    449 {
    450     bb_perror_msg_and_die(fmt, device_name);
     810static NORETURN void perror_on_device_and_die(const char *fmt)
     811{
     812    bb_perror_msg_and_die(fmt, G.device_name);
    451813}
    452814
    453815static void perror_on_device(const char *fmt)
    454816{
    455     bb_perror_msg(fmt, device_name);
     817    bb_perror_msg(fmt, G.device_name);
    456818}
    457819
     
    463825    char buf[128];
    464826    va_list args;
    465     int buflen;
     827    unsigned buflen;
    466828
    467829    va_start(args, message);
     
    475837        G.current_col++;
    476838        if (buf[0] != '\n') {
    477             if (G.current_col + buflen >= max_col) {
    478                 putchar('\n');
     839            if (G.current_col + buflen >= G.max_col) {
     840                bb_putchar('\n');
    479841                G.current_col = 0;
    480842            } else
    481                 putchar(' ');
     843                bb_putchar(' ');
    482844        }
    483845    }
     
    488850}
    489851
    490 static void set_window_size(const int rows, const int cols)
    491 {
    492     struct winsize win = { 0, 0, 0, 0};
     852static void newline(void)
     853{
     854    if (G.current_col != 0)
     855        wrapf("\n");
     856}
     857
     858#ifdef TIOCGWINSZ
     859static void set_window_size(int rows, int cols)
     860{
     861    struct winsize win = { 0, 0, 0, 0 };
    493862
    494863    if (ioctl(STDIN_FILENO, TIOCGWINSZ, &win)) {
     
    508877        perror_on_device("%s");
    509878}
    510 
    511 static void display_window_size(const int fancy)
     879#endif
     880
     881static void display_window_size(int fancy)
    512882{
    513883    const char *fmt_str = "%s\0%s: no size information for this device";
     
    519889        }
    520890    } else {
    521         wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n",
     891        wrapf(fancy ? "rows %u; columns %u;" : "%u %u\n",
    522892                height, width);
    523893    }
     
    528898    { "k", 1024 },
    529899    { "B", 1024 },
    530     { }
     900    { "", 0 }
    531901};
    532902
    533903static const struct mode_info *find_mode(const char *name)
    534904{
    535     int i;
    536     for (i = 0; i < NUM_mode_info; ++i)
    537         if (!strcmp(name, mode_info[i].name))
    538             return &mode_info[i];
    539     return 0;
     905    int i = index_in_strings(mode_name, name);
     906    return i >= 0 ? &mode_info[i] : NULL;
    540907}
    541908
    542909static const struct control_info *find_control(const char *name)
    543910{
    544     int i;
    545     for (i = 0; i < NUM_control_info; ++i)
    546         if (!strcmp(name, control_info[i].name))
    547             return &control_info[i];
    548     return 0;
     911    int i = index_in_strings(control_name, name);
     912    return i >= 0 ? &control_info[i] : NULL;
    549913}
    550914
     
    561925};
    562926
    563 static int find_param(const char *const name)
     927static int find_param(const char *name)
    564928{
    565929    static const char params[] ALIGN1 =
     
    611975
    612976static void display_recoverable(const struct termios *mode,
    613                 int ATTRIBUTE_UNUSED dummy)
     977                int UNUSED_PARAM dummy)
    614978{
    615979    int i;
     
    619983    for (i = 0; i < NCCS; ++i)
    620984        printf(":%x", (unsigned int) mode->c_cc[i]);
    621     putchar('\n');
     985    bb_putchar('\n');
    622986}
    623987
    624988static void display_speed(const struct termios *mode, int fancy)
    625989{
    626                          //01234567 8 9
     990    //____________________ 01234567 8 9
    627991    const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;";
    628992    unsigned long ispeed, ospeed;
     
    631995    if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) {
    632996        ispeed = ospeed;                /* in case ispeed was 0 */
    633                  //0123 4 5 6 7 8 9
     997        //________ 0123 4 5 6 7 8 9
    634998        fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;";
    635999    }
     
    6381002}
    6391003
    640 static void do_display(const struct termios *mode, const int all)
     1004static void do_display(const struct termios *mode, int all)
    6411005{
    6421006    int i;
     
    6491013        display_window_size(1);
    6501014#ifdef HAVE_C_LINE
    651     wrapf("line = %d;\n", mode->c_line);
     1015    wrapf("line = %u;\n", mode->c_line);
    6521016#else
    653     wrapf("\n");
    654 #endif
    655 
    656     for (i = 0; control_info[i].name != stty_min; ++i) {
     1017    newline();
     1018#endif
     1019
     1020    for (i = 0; i != CIDX_min; ++i) {
    6571021        /* If swtch is the same as susp, don't print both */
    6581022#if VSWTCH == VSUSP
    659         if (control_info[i].name == stty_swtch)
     1023        if (i == CIDX_swtch)
    6601024            continue;
    6611025#endif
    6621026        /* If eof uses the same slot as min, only print whichever applies */
    6631027#if VEOF == VMIN
    664         if ((mode->c_lflag & ICANON) == 0
    665             && (control_info[i].name == stty_eof
    666                 || control_info[i].name == stty_eol)) continue;
    667 #endif
    668         wrapf("%s = %s;", control_info[i].name,
     1028        if (!(mode->c_lflag & ICANON)
     1029         && (i == CIDX_eof || i == CIDX_eol)
     1030        ) {
     1031            continue;
     1032        }
     1033#endif
     1034        wrapf("%s = %s;", nth_string(control_name, i),
    6691035              visible(mode->c_cc[control_info[i].offset]));
    6701036    }
     
    6721038    if ((mode->c_lflag & ICANON) == 0)
    6731039#endif
    674         wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
    675     if (G.current_col) wrapf("\n");
     1040        wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
     1041    newline();
    6761042
    6771043    for (i = 0; i < NUM_mode_info; ++i) {
     
    6791045            continue;
    6801046        if (mode_info[i].type != prev_type) {
    681             /* wrapf("\n"); */
    682             if (G.current_col) wrapf("\n");
     1047            newline();
    6831048            prev_type = mode_info[i].type;
    6841049        }
     
    6881053        if ((*bitsp & mask) == mode_info[i].bits) {
    6891054            if (all || (mode_info[i].flags & SANE_UNSET))
    690                 wrapf("%s", mode_info[i].name);
     1055                wrapf("-%s"+1, nth_string(mode_name, i));
    6911056        } else {
    692             if ((all && mode_info[i].flags & REV) ||
    693                  (!all &&
    694                   (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)))
    695                 wrapf("-%s", mode_info[i].name);
    696         }
    697     }
    698     if (G.current_col) wrapf("\n");
     1057            if ((all && mode_info[i].flags & REV)
     1058             || (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV))
     1059            ) {
     1060                wrapf("-%s", nth_string(mode_name, i));
     1061            }
     1062        }
     1063    }
     1064    newline();
    6991065}
    7001066
     
    7061072    for (i = 0; i < NUM_control_info; ++i) {
    7071073#if VMIN == VEOF
    708         if (control_info[i].name == stty_min)
     1074        if (i == CIDX_min)
    7091075            break;
    7101076#endif
     
    7251091}
    7261092
    727 /* Save set_mode from #ifdef forest plague */
    728 #ifndef ONLCR
    729 #define ONLCR 0
    730 #endif
    731 #ifndef OCRNL
    732 #define OCRNL 0
    733 #endif
    734 #ifndef ONLRET
    735 #define ONLRET 0
    736 #endif
    737 #ifndef XCASE
    738 #define XCASE 0
    739 #endif
    740 #ifndef IXANY
    741 #define IXANY 0
    742 #endif
    743 #ifndef TABDLY
    744 #define TABDLY 0
    745 #endif
    746 #ifndef OXTABS
    747 #define OXTABS 0
    748 #endif
    749 #ifndef IUCLC
    750 #define IUCLC 0
    751 #endif
    752 #ifndef OLCUC
    753 #define OLCUC 0
    754 #endif
    755 #ifndef ECHOCTL
    756 #define ECHOCTL 0
    757 #endif
    758 #ifndef ECHOKE
    759 #define ECHOKE 0
    760 #endif
    761 
    7621093static void set_mode(const struct mode_info *info, int reversed,
    7631094                    struct termios *mode)
     
    7761107
    7771108    /* Combination mode */
    778     if (info->name == evenp || info->name == parity) {
     1109    if (info == &mode_info[IDX_evenp] || info == &mode_info[IDX_parity]) {
    7791110        if (reversed)
    7801111            mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
    7811112        else
    782             mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7;
    783     } else if (info->name == stty_oddp) {
     1113            mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7;
     1114    } else if (info == &mode_info[IDX_oddp]) {
    7841115        if (reversed)
    7851116            mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;
    7861117        else
    787             mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB;
    788     } else if (info->name == stty_nl) {
     1118            mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB;
     1119    } else if (info == &mode_info[IDX_nl]) {
    7891120        if (reversed) {
    7901121            mode->c_iflag = (mode->c_iflag | ICRNL) & ~INLCR & ~IGNCR;
    791             mode->c_oflag = (mode->c_oflag | ONLCR) & ~OCRNL & ~ONLRET;
     1122            mode->c_oflag = (mode->c_oflag | ONLCR) & ~OCRNL & ~ONLRET;
    7921123        } else {
    7931124            mode->c_iflag = mode->c_iflag & ~ICRNL;
    7941125            if (ONLCR) mode->c_oflag = mode->c_oflag & ~ONLCR;
    7951126        }
    796     } else if (info->name == stty_ek) {
     1127    } else if (info == &mode_info[IDX_ek]) {
    7971128        mode->c_cc[VERASE] = CERASE;
    7981129        mode->c_cc[VKILL] = CKILL;
    799     } else if (info->name == stty_sane) {
     1130    } else if (info == &mode_info[IDX_sane]) {
    8001131        sane_mode(mode);
    801     }
    802     else if (info->name == cbreak) {
     1132    } else if (info == &mode_info[IDX_cbreak]) {
    8031133        if (reversed)
    8041134            mode->c_lflag |= ICANON;
    8051135        else
    8061136            mode->c_lflag &= ~ICANON;
    807     } else if (info->name == stty_pass8) {
     1137    } else if (info == &mode_info[IDX_pass8]) {
    8081138        if (reversed) {
    8091139            mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB;
     
    8131143            mode->c_iflag &= ~ISTRIP;
    8141144        }
    815     } else if (info->name == litout) {
     1145    } else if (info == &mode_info[IDX_litout]) {
    8161146        if (reversed) {
    8171147            mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB;
     
    8231153            mode->c_oflag &= ~OPOST;
    8241154        }
    825     } else if (info->name == raw || info->name == cooked) {
    826         if ((info->name[0] == 'r' && reversed)
    827             || (info->name[0] == 'c' && !reversed)) {
     1155    } else if (info == &mode_info[IDX_raw] || info == &mode_info[IDX_cooked]) {
     1156        if ((info == &mode_info[IDX_raw] && reversed)
     1157         || (info == &mode_info[IDX_cooked] && !reversed)
     1158        ) {
    8281159            /* Cooked mode */
    8291160            mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;
     
    8451176        }
    8461177    }
    847     else if (IXANY && info->name == decctlq) {
     1178#if IXANY
     1179    else if (info == &mode_info[IDX_decctlq]) {
    8481180        if (reversed)
    8491181            mode->c_iflag |= IXANY;
     
    8511183            mode->c_iflag &= ~IXANY;
    8521184    }
    853     else if (TABDLY && info->name == stty_tabs) {
     1185#endif
     1186#if TABDLY
     1187    else if (info == &mode_info[IDX_tabs]) {
    8541188        if (reversed)
    8551189            mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3;
     
    8571191            mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0;
    8581192    }
    859     else if (OXTABS && info->name == stty_tabs) {
     1193#endif
     1194#if OXTABS
     1195    else if (info == &mode_info[IDX_tabs]) {
    8601196        if (reversed)
    8611197            mode->c_oflag |= OXTABS;
     
    8631199            mode->c_oflag &= ~OXTABS;
    8641200    }
    865     else if (XCASE && IUCLC && OLCUC
    866     && (info->name == stty_lcase || info->name == stty_LCASE)) {
     1201#endif
     1202#if XCASE && IUCLC && OLCUC
     1203    else if (info==&mode_info[IDX_lcase] || info==&mode_info[IDX_LCASE]) {
    8671204        if (reversed) {
    8681205            mode->c_lflag &= ~XCASE;
     
    8751212        }
    8761213    }
    877     else if (info->name == stty_crt) {
     1214#endif
     1215    else if (info == &mode_info[IDX_crt]) {
    8781216        mode->c_lflag |= ECHOE | ECHOCTL | ECHOKE;
    879     }
    880     else if (info->name == stty_dec) {
     1217    } else if (info == &mode_info[IDX_dec]) {
    8811218        mode->c_cc[VINTR] = 3; /* ^C */
    8821219        mode->c_cc[VERASE] = 127; /* DEL */
     
    8921229    unsigned char value;
    8931230
    894     if (info->name == stty_min || info->name == stty_time)
     1231    if (info == &control_info[CIDX_min] || info == &control_info[CIDX_time])
    8951232        value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
    8961233    else if (arg[0] == '\0' || arg[1] == '\0')
    8971234        value = arg[0];
    898     else if (!strcmp(arg, "^-") || !strcmp(arg, "undef"))
     1235    else if (strcmp(arg, "^-") == 0 || strcmp(arg, "undef") == 0)
    8991236        value = _POSIX_VDISABLE;
    9001237    else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */
     
    9071244}
    9081245
    909 #define STTY_require_set_attr   (1<<0)
    910 #define STTY_speed_was_set      (1<<1)
    911 #define STTY_verbose_output     (1<<2)
    912 #define STTY_recoverable_output (1<<3)
    913 #define STTY_noargs             (1<<4)
    914 int stty_main(int argc, char **argv);
    915 int stty_main(int argc, char **argv)
     1246#define STTY_require_set_attr   (1 << 0)
     1247#define STTY_speed_was_set      (1 << 1)
     1248#define STTY_verbose_output     (1 << 2)
     1249#define STTY_recoverable_output (1 << 3)
     1250#define STTY_noargs             (1 << 4)
     1251
     1252int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
     1253int stty_main(int argc UNUSED_PARAM, char **argv)
    9161254{
    9171255    struct termios mode;
    918     void (*output_func)(const struct termios *, const int);
     1256    void (*output_func)(const struct termios *, int);
    9191257    const char *file_name = NULL;
    9201258    int display_all = 0;
    9211259    int stty_state;
    9221260    int k;
     1261
     1262    INIT_G();
    9231263
    9241264    stty_state = STTY_noargs;
     
    9661306                            bb_error_msg_and_die(bb_msg_requires_arg, "-F");
    9671307                        /* remove -F param from arg[vc] */
    968                         --argc;
    969                         while (argv[p]) { argv[p] = argv[p+1]; ++p; }
     1308                        while (argv[p]) {
     1309                            argv[p] = argv[p+1];
     1310                            ++p;
     1311                        }
    9701312                    }
    9711313                    goto end_option;
     
    10421384        bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive");
    10431385    /* Specifying -a or -g with non-options is an error */
    1044     if (!(stty_state & STTY_noargs) &&
    1045         (stty_state & (STTY_verbose_output | STTY_recoverable_output)))
     1386    if (!(stty_state & STTY_noargs)
     1387     && (stty_state & (STTY_verbose_output | STTY_recoverable_output))
     1388    ) {
    10461389        bb_error_msg_and_die("modes may not be set when specifying an output style");
     1390    }
    10471391
    10481392    /* Now it is safe to start doing things */
    10491393    if (file_name) {
    1050         int fd, fdflags;
    1051         device_name = file_name;
    1052         fd = xopen(device_name, O_RDONLY | O_NONBLOCK);
    1053         if (fd != STDIN_FILENO) {
    1054             dup2(fd, STDIN_FILENO);
    1055             close(fd);
    1056         }
    1057         fdflags = fcntl(STDIN_FILENO, F_GETFL);
    1058         if (fdflags < 0 ||
    1059             fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
    1060             perror_on_device_and_die("%s: cannot reset non-blocking mode");
     1394        G.device_name = file_name;
     1395        xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO);
     1396        ndelay_off(STDIN_FILENO);
    10611397    }
    10621398
     
    10681404
    10691405    if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
    1070         get_terminal_width_height(STDOUT_FILENO, &max_col, NULL);
     1406        get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);
    10711407        output_func(&mode, display_all);
    10721408        return EXIT_SUCCESS;
     
    11211457#ifdef TIOCGWINSZ
    11221458        case param_cols:
     1459        case param_columns:
    11231460            set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
    11241461            break;
     
    11721509
    11731510        if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) {
    1174 #ifdef CIBAUD
     1511#if CIBAUD
    11751512            /* SunOS 4.1.3 (at least) has the problem that after this sequence,
    11761513               tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);
Note: See TracChangeset for help on using the changeset viewer.