/* stty -- change and print terminal line settings                              This is the stty utility
   Copyright (C) 1990-2018 Free Software Foundation, Inc.                       
                                                                                
   This program is free software: you can redistribute it and/or modify         
   it under the terms of the GNU General Public License as published by         
   the Free Software Foundation, either version 3 of the License, or            
   (at your option) any later version.                                          
                                                                                
   This program is distributed in the hope that it will be useful,              
   but WITHOUT ANY WARRANTY; without even the implied warranty of               
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                
   GNU General Public License for more details.                                 
                                                                                
   You should have received a copy of the GNU General Public License            
   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */   The GNUv3 license
                                                                                
/* Usage: stty [-ag] [--all] [--save] [-F device] [--file=device] [setting...]  
                                                                                
   Options:                                                                     
   -a, --all    Write all current settings to stdout in human-readable form.    
   -g, --save   Write all current settings to stdout in stty-readable form.     
   -F, --file   Open and use the specified device instead of stdin              
                                                                                
   If no args are given, write to stdout the baud rate and settings that        
   have been changed from their defaults.  Mode reading and changes             
   are done on the specified device, or stdin if none was specified.            
                                                                                
   David MacKenzie <djm@gnu.ai.mit.edu> */                                      
                                                                                
#include <config.h>                                                             Provides system specific information
                                                                                
#ifdef TERMIOS_NEEDS_XOPEN_SOURCE                                               Line 32
# define _XOPEN_SOURCE                                                          Line 33
#endif                                                                          Line 34
                                                                                
#include <stdio.h>                                                              Provides standard I/O capability
#include <sys/types.h>                                                          Provides system data types
                                                                                
#include <termios.h>                                                            ...!includes auto-comment...
#if HAVE_STROPTS_H                                                              Line 40
# include <stropts.h>                                                           Line 41
#endif                                                                          Line 42
#include <sys/ioctl.h>                                                          ...!includes auto-comment...
                                                                                
#ifdef WINSIZE_IN_PTEM                                                          Line 45
# include <sys/stream.h>                                                        Line 46
# include <sys/ptem.h>                                                          Line 47
#endif                                                                          Line 48
#ifdef GWINSZ_IN_SYS_PTY                                                        Line 49
# include <sys/tty.h>                                                           Line 50
# include <sys/pty.h>                                                           Line 51
#endif                                                                          Line 52
#include <getopt.h>                                                             ...!includes auto-comment...
#include <stdarg.h>                                                             ...!includes auto-comment...
#include <assert.h>                                                             ...!includes auto-comment...
                                                                                
#include "system.h"                                                             ...!includes auto-comment...
#include "die.h"                                                                ...!includes auto-comment...
#include "error.h"                                                              ...!includes auto-comment...
#include "fd-reopen.h"                                                          ...!includes auto-comment...
#include "quote.h"                                                              ...!includes auto-comment...
#include "xdectoint.h"                                                          ...!includes auto-comment...
#include "xstrtol.h"                                                            ...!includes auto-comment...
                                                                                
/* The official name of this program (e.g., no 'g' prefix).  */                 
#define PROGRAM_NAME "stty"                                                     Line 66
                                                                                
#define AUTHORS proper_name ("David MacKenzie")                                 Line 68
                                                                                
#ifndef _POSIX_VDISABLE                                                         Line 70
# define _POSIX_VDISABLE 0                                                      Line 71
#endif                                                                          Line 72
                                                                                
#define Control(c) ((c) & 0x1f)                                                 Line 74
/* Canonical values for control characters. */                                  
#ifndef CINTR                                                                   Line 76
# define CINTR Control ('c')                                                    Line 77
#endif                                                                          Line 78
#ifndef CQUIT                                                                   Line 79
# define CQUIT 28                                                               Line 80
#endif                                                                          Line 81
#ifndef CERASE                                                                  Line 82
# define CERASE 127                                                             Line 83
#endif                                                                          Line 84
#ifndef CKILL                                                                   Line 85
# define CKILL Control ('u')                                                    Line 86
#endif                                                                          Line 87
#ifndef CEOF                                                                    Line 88
# define CEOF Control ('d')                                                     Line 89
#endif                                                                          Line 90
#ifndef CEOL                                                                    Line 91
# define CEOL _POSIX_VDISABLE                                                   Line 92
#endif                                                                          Line 93
#ifndef CSTART                                                                  Line 94
# define CSTART Control ('q')                                                   Line 95
#endif                                                                          Line 96
#ifndef CSTOP                                                                   Line 97
# define CSTOP Control ('s')                                                    Line 98
#endif                                                                          Line 99
#ifndef CSUSP                                                                   Line 100
# define CSUSP Control ('z')                                                    Line 101
#endif                                                                          Line 102
#if defined VEOL2 && !defined CEOL2                                             Line 103
# define CEOL2 _POSIX_VDISABLE                                                  Line 104
#endif                                                                          Line 105
/* Some platforms have VSWTC, others VSWTCH.  In both cases, this control       
   character is initialized by CSWTCH, if present.  */                          
#if defined VSWTC && !defined VSWTCH                                            Line 108
# define VSWTCH VSWTC                                                           Line 109
#endif                                                                          Line 110
/* ISC renamed swtch to susp for termios, but we'll accept either name.  */     
#if defined VSUSP && !defined VSWTCH                                            Line 112
# define VSWTCH VSUSP                                                           Line 113
# if defined CSUSP && !defined CSWTCH                                           Line 114
#  define CSWTCH CSUSP                                                          Line 115
# endif                                                                         Line 116
#endif                                                                          Line 117
#if defined VSWTCH && !defined CSWTCH                                           Line 118
# define CSWTCH _POSIX_VDISABLE                                                 Line 119
#endif                                                                          Line 120
                                                                                
/* SunOS >= 5.3 loses (^Z doesn't work) if 'swtch' is the same as 'susp'.       
   So the default is to disable 'swtch.'  */                                    
#if defined __sun                                                               Line 124
# undef CSWTCH                                                                  Line 125
# define CSWTCH _POSIX_VDISABLE                                                 Line 126
#endif                                                                          Line 127
                                                                                
#if defined VWERSE && !defined VWERASE /* AIX-3.2.5 */                          Line 129
# define VWERASE VWERSE                                                         Line 130
#endif                                                                          Line 131
#if defined VDSUSP && !defined CDSUSP                                           Line 132
# define CDSUSP Control ('y')                                                   Line 133
#endif                                                                          Line 134
#if !defined VREPRINT && defined VRPRNT /* Irix 4.0.5 */                        Line 135
# define VREPRINT VRPRNT                                                        Line 136
#endif                                                                          Line 137
#if defined VREPRINT && !defined CRPRNT                                         Line 138
# define CRPRNT Control ('r')                                                   Line 139
#endif                                                                          Line 140
#if defined CREPRINT && !defined CRPRNT                                         Line 141
# define CRPRNT Control ('r')                                                   Line 142
#endif                                                                          Line 143
#if defined VWERASE && !defined CWERASE                                         Line 144
# define CWERASE Control ('w')                                                  Line 145
#endif                                                                          Line 146
#if defined VLNEXT && !defined CLNEXT                                           Line 147
# define CLNEXT Control ('v')                                                   Line 148
#endif                                                                          Line 149
#if defined VDISCARD && !defined VFLUSHO                                        Line 150
# define VFLUSHO VDISCARD                                                       Line 151
#endif                                                                          Line 152
#if defined VFLUSH && !defined VFLUSHO /* Ultrix 4.2 */                         Line 153
# define VFLUSHO VFLUSH                                                         Line 154
#endif                                                                          Line 155
#if defined CTLECH && !defined ECHOCTL /* Ultrix 4.3 */                         Line 156
# define ECHOCTL CTLECH                                                         Line 157
#endif                                                                          Line 158
#if defined TCTLECH && !defined ECHOCTL /* Ultrix 4.2 */                        Line 159
# define ECHOCTL TCTLECH                                                        Line 160
#endif                                                                          Line 161
#if defined CRTKIL && !defined ECHOKE /* Ultrix 4.2 and 4.3 */                  Line 162
# define ECHOKE CRTKIL                                                          Line 163
#endif                                                                          Line 164
#if defined VFLUSHO && !defined CFLUSHO                                         Line 165
# define CFLUSHO Control ('o')                                                  Line 166
#endif                                                                          Line 167
#if defined VSTATUS && !defined CSTATUS                                         Line 168
# define CSTATUS Control ('t')                                                  Line 169
#endif                                                                          Line 170
                                                                                
/* Which speeds to set.  */                                                     
enum speed_setting                                                              Line 173
  {                                                                             
    input_speed, output_speed, both_speeds                                      Line 175
  };                                                                            Block 1
                                                                                
/* What to output and how.  */                                                  
enum output_type                                                                Line 179
  {                                                                             
    changed, all, recoverable /* Default, -a, -g.  */                           Line 181
  };                                                                            Block 2
                                                                                
/* Which member(s) of 'struct termios' a mode uses.  */                         
enum mode_type                                                                  Line 185
  {                                                                             
    control, input, output, local, combination                                  Line 187
  };                                                                            Block 3
                                                                                
/* Flags for 'struct mode_info'. */                                             
#define SANE_SET 1  /* Set in 'sane' mode. */                                   Line 191
#define SANE_UNSET 2  /* Unset in 'sane' mode. */                               Line 192
#define REV 4   /* Can be turned off by prepending '-'. */                      Line 193
#define OMIT 8   /* Don't display value. */                                     Line 194
#define NO_SETATTR 16  /* tcsetattr not used to set mode bits.  */              Line 195
                                                                                
/* Each mode.  */                                                               
struct mode_info                                                                Line 198
  {                                                                             
    const char *name;  /* Name given on command line.  */                       Line 200
    enum mode_type type; /* Which structure element to change. */               Line 201
    char flags;   /* Setting and display options.  */                           Line 202
    unsigned long bits;  /* Bits to set for this mode.  */                      Line 203
    unsigned long mask;  /* Other bits to turn off for this mode.  */           Line 204
  };                                                                            Block 4
                                                                                
static struct mode_info const mode_info[] =                                     Line 207
{                                                                               
  {"parenb", control, REV, PARENB, 0},                                          Line 209
  {"parodd", control, REV, PARODD, 0},                                          Line 210
#ifdef CMSPAR                                                                   Line 211
  {"cmspar", control, REV, CMSPAR, 0},                                          Line 212
#endif                                                                          Line 213
  {"cs5", control, 0, CS5, CSIZE},                                              Line 214
  {"cs6", control, 0, CS6, CSIZE},                                              Line 215
  {"cs7", control, 0, CS7, CSIZE},                                              Line 216
  {"cs8", control, 0, CS8, CSIZE},                                              Line 217
  {"hupcl", control, REV, HUPCL, 0},                                            Line 218
  {"hup", control, REV | OMIT, HUPCL, 0},                                       Line 219
  {"cstopb", control, REV, CSTOPB, 0},                                          Line 220
  {"cread", control, SANE_SET | REV, CREAD, 0},                                 Line 221
  {"clocal", control, REV, CLOCAL, 0},                                          Line 222
#ifdef CRTSCTS                                                                  Line 223
  {"crtscts", control, REV, CRTSCTS, 0},                                        Line 224
#endif                                                                          Line 225
#ifdef CDTRDSR                                                                  Line 226
  {"cdtrdsr", control, REV, CDTRDSR, 0},                                        Line 227
#endif                                                                          Line 228
                                                                                
  {"ignbrk", input, SANE_UNSET | REV, IGNBRK, 0},                               Line 230
  {"brkint", input, SANE_SET | REV, BRKINT, 0},                                 Line 231
  {"ignpar", input, REV, IGNPAR, 0},                                            Line 232
  {"parmrk", input, REV, PARMRK, 0},                                            Line 233
  {"inpck", input, REV, INPCK, 0},                                              Line 234
  {"istrip", input, REV, ISTRIP, 0},                                            Line 235
  {"inlcr", input, SANE_UNSET | REV, INLCR, 0},                                 Line 236
  {"igncr", input, SANE_UNSET | REV, IGNCR, 0},                                 Line 237
  {"icrnl", input, SANE_SET | REV, ICRNL, 0},                                   Line 238
  {"ixon", input, REV, IXON, 0},                                                Line 239
  {"ixoff", input, SANE_UNSET | REV, IXOFF, 0},                                 Line 240
  {"tandem", input, REV | OMIT, IXOFF, 0},                                      Line 241
#ifdef IUCLC                                                                    Line 242
  {"iuclc", input, SANE_UNSET | REV, IUCLC, 0},                                 Line 243
#endif                                                                          Line 244
#ifdef IXANY                                                                    Line 245
  {"ixany", input, SANE_UNSET | REV, IXANY, 0},                                 Line 246
#endif                                                                          Line 247
#ifdef IMAXBEL                                                                  Line 248
  {"imaxbel", input, SANE_SET | REV, IMAXBEL, 0},                               Line 249
#endif                                                                          Line 250
#ifdef IUTF8                                                                    Line 251
  {"iutf8", input, SANE_UNSET | REV, IUTF8, 0},                                 Line 252
#endif                                                                          Line 253
                                                                                
  {"opost", output, SANE_SET | REV, OPOST, 0},                                  Line 255
#ifdef OLCUC                                                                    Line 256
  {"olcuc", output, SANE_UNSET | REV, OLCUC, 0},                                Line 257
#endif                                                                          Line 258
#ifdef OCRNL                                                                    Line 259
  {"ocrnl", output, SANE_UNSET | REV, OCRNL, 0},                                Line 260
#endif                                                                          Line 261
#ifdef ONLCR                                                                    Line 262
  {"onlcr", output, SANE_SET | REV, ONLCR, 0},                                  Line 263
#endif                                                                          Line 264
#ifdef ONOCR                                                                    Line 265
  {"onocr", output, SANE_UNSET | REV, ONOCR, 0},                                Line 266
#endif                                                                          Line 267
#ifdef ONLRET                                                                   Line 268
  {"onlret", output, SANE_UNSET | REV, ONLRET, 0},                              Line 269
#endif                                                                          Line 270
#ifdef OFILL                                                                    Line 271
  {"ofill", output, SANE_UNSET | REV, OFILL, 0},                                Line 272
#endif                                                                          Line 273
#ifdef OFDEL                                                                    Line 274
  {"ofdel", output, SANE_UNSET | REV, OFDEL, 0},                                Line 275
#endif                                                                          Line 276
#ifdef NLDLY                                                                    Line 277
  {"nl1", output, SANE_UNSET, NL1, NLDLY},                                      Line 278
  {"nl0", output, SANE_SET, NL0, NLDLY},                                        Line 279
#endif                                                                          Line 280
#ifdef CRDLY                                                                    Line 281
  {"cr3", output, SANE_UNSET, CR3, CRDLY},                                      Line 282
  {"cr2", output, SANE_UNSET, CR2, CRDLY},                                      Line 283
  {"cr1", output, SANE_UNSET, CR1, CRDLY},                                      Line 284
  {"cr0", output, SANE_SET, CR0, CRDLY},                                        Line 285
#endif                                                                          Line 286
#ifdef TABDLY                                                                   Line 287
# ifdef TAB3                                                                    Line 288
  {"tab3", output, SANE_UNSET, TAB3, TABDLY},                                   Line 289
# endif                                                                         Line 290
# ifdef TAB2                                                                    Line 291
  {"tab2", output, SANE_UNSET, TAB2, TABDLY},                                   Line 292
# endif                                                                         Line 293
# ifdef TAB1                                                                    Line 294
  {"tab1", output, SANE_UNSET, TAB1, TABDLY},                                   Line 295
# endif                                                                         Line 296
# ifdef TAB0                                                                    Line 297
  {"tab0", output, SANE_SET, TAB0, TABDLY},                                     Line 298
# endif                                                                         Line 299
#else                                                                           Line 300
# ifdef OXTABS                                                                  Line 301
  {"tab3", output, SANE_UNSET, OXTABS, 0},                                      Line 302
# endif                                                                         Line 303
#endif                                                                          Line 304
#ifdef BSDLY                                                                    Line 305
  {"bs1", output, SANE_UNSET, BS1, BSDLY},                                      Line 306
  {"bs0", output, SANE_SET, BS0, BSDLY},                                        Line 307
#endif                                                                          Line 308
#ifdef VTDLY                                                                    Line 309
  {"vt1", output, SANE_UNSET, VT1, VTDLY},                                      Line 310
  {"vt0", output, SANE_SET, VT0, VTDLY},                                        Line 311
#endif                                                                          Line 312
#ifdef FFDLY                                                                    Line 313
  {"ff1", output, SANE_UNSET, FF1, FFDLY},                                      Line 314
  {"ff0", output, SANE_SET, FF0, FFDLY},                                        Line 315
#endif                                                                          Line 316
                                                                                
  {"isig", local, SANE_SET | REV, ISIG, 0},                                     Line 318
  {"icanon", local, SANE_SET | REV, ICANON, 0},                                 Line 319
#ifdef IEXTEN                                                                   Line 320
  {"iexten", local, SANE_SET | REV, IEXTEN, 0},                                 Line 321
#endif                                                                          Line 322
  {"echo", local, SANE_SET | REV, ECHO, 0},                                     Line 323
  {"echoe", local, SANE_SET | REV, ECHOE, 0},                                   Line 324
  {"crterase", local, REV | OMIT, ECHOE, 0},                                    Line 325
  {"echok", local, SANE_SET | REV, ECHOK, 0},                                   Line 326
  {"echonl", local, SANE_UNSET | REV, ECHONL, 0},                               Line 327
  {"noflsh", local, SANE_UNSET | REV, NOFLSH, 0},                               Line 328
#ifdef XCASE                                                                    Line 329
  {"xcase", local, SANE_UNSET | REV, XCASE, 0},                                 Line 330
#endif                                                                          Line 331
#ifdef TOSTOP                                                                   Line 332
  {"tostop", local, SANE_UNSET | REV, TOSTOP, 0},                               Line 333
#endif                                                                          Line 334
#ifdef ECHOPRT                                                                  Line 335
  {"echoprt", local, SANE_UNSET | REV, ECHOPRT, 0},                             Line 336
  {"prterase", local, REV | OMIT, ECHOPRT, 0},                                  Line 337
#endif                                                                          Line 338
#ifdef ECHOCTL                                                                  Line 339
  {"echoctl", local, SANE_SET | REV, ECHOCTL, 0},                               Line 340
  {"ctlecho", local, REV | OMIT, ECHOCTL, 0},                                   Line 341
#endif                                                                          Line 342
#ifdef ECHOKE                                                                   Line 343
  {"echoke", local, SANE_SET | REV, ECHOKE, 0},                                 Line 344
  {"crtkill", local, REV | OMIT, ECHOKE, 0},                                    Line 345
#endif                                                                          Line 346
#ifdef FLUSHO                                                                   Line 347
  {"flusho", local, SANE_UNSET | REV, FLUSHO, 0},                               Line 348
#endif                                                                          Line 349
#if defined TIOCEXT                                                             Line 350
  {"extproc", local, SANE_UNSET | REV | NO_SETATTR, EXTPROC, 0},                Line 351
#elif defined EXTPROC                                                           Line 352
  {"extproc", local, SANE_UNSET | REV, EXTPROC, 0},                             Line 353
#endif                                                                          Line 354
                                                                                
  {"evenp", combination, REV | OMIT, 0, 0},                                     Line 356
  {"parity", combination, REV | OMIT, 0, 0},                                    Line 357
  {"oddp", combination, REV | OMIT, 0, 0},                                      Line 358
  {"nl", combination, REV | OMIT, 0, 0},                                        Line 359
  {"ek", combination, OMIT, 0, 0},                                              Line 360
  {"sane", combination, OMIT, 0, 0},                                            Line 361
  {"cooked", combination, REV | OMIT, 0, 0},                                    Line 362
  {"raw", combination, REV | OMIT, 0, 0},                                       Line 363
  {"pass8", combination, REV | OMIT, 0, 0},                                     Line 364
  {"litout", combination, REV | OMIT, 0, 0},                                    Line 365
  {"cbreak", combination, REV | OMIT, 0, 0},                                    Line 366
#ifdef IXANY                                                                    Line 367
  {"decctlq", combination, REV | OMIT, 0, 0},                                   Line 368
#endif                                                                          Line 369
#if defined TABDLY || defined OXTABS                                            Line 370
  {"tabs", combination, REV | OMIT, 0, 0},                                      Line 371
#endif                                                                          Line 372
#if defined XCASE && defined IUCLC && defined OLCUC                             Line 373
  {"lcase", combination, REV | OMIT, 0, 0},                                     Line 374
  {"LCASE", combination, REV | OMIT, 0, 0},                                     Line 375
#endif                                                                          Line 376
  {"crt", combination, OMIT, 0, 0},                                             Line 377
  {"dec", combination, OMIT, 0, 0},                                             Line 378
                                                                                
  {NULL, control, 0, 0, 0}                                                      Line 380
};                                                                              Block 5
                                                                                
/* Control character settings.  */                                              
struct control_info                                                             Line 384
  {                                                                             
    const char *name;  /* Name given on command line.  */                       Line 386
    cc_t saneval;  /* Value to set for 'stty sane'.  */                         Line 387
    size_t offset;  /* Offset in c_cc.  */                                      Line 388
  };                                                                            Block 6
                                                                                
/* Control characters. */                                                       
                                                                                
static struct control_info const control_info[] =                               Line 393
{                                                                               
  {"intr", CINTR, VINTR},                                                       Line 395
  {"quit", CQUIT, VQUIT},                                                       Line 396
  {"erase", CERASE, VERASE},                                                    Line 397
  {"kill", CKILL, VKILL},                                                       Line 398
  {"eof", CEOF, VEOF},                                                          Line 399
  {"eol", CEOL, VEOL},                                                          Line 400
#ifdef VEOL2                                                                    Line 401
  {"eol2", CEOL2, VEOL2},                                                       Line 402
#endif                                                                          Line 403
#ifdef VSWTCH                                                                   Line 404
  {"swtch", CSWTCH, VSWTCH},                                                    Line 405
#endif                                                                          Line 406
  {"start", CSTART, VSTART},                                                    Line 407
  {"stop", CSTOP, VSTOP},                                                       Line 408
  {"susp", CSUSP, VSUSP},                                                       Line 409
#ifdef VDSUSP                                                                   Line 410
  {"dsusp", CDSUSP, VDSUSP},                                                    Line 411
#endif                                                                          Line 412
#ifdef VREPRINT                                                                 Line 413
  {"rprnt", CRPRNT, VREPRINT},                                                  Line 414
#else                                                                           Line 415
# ifdef CREPRINT /* HPUX 10.20 needs this */                                    Line 416
  {"rprnt", CRPRNT, CREPRINT},                                                  Line 417
# endif                                                                         Line 418
#endif                                                                          Line 419
#ifdef VWERASE                                                                  Line 420
  {"werase", CWERASE, VWERASE},                                                 Line 421
#endif                                                                          Line 422
#ifdef VLNEXT                                                                   Line 423
  {"lnext", CLNEXT, VLNEXT},                                                    Line 424
#endif                                                                          Line 425
#ifdef VFLUSHO                                                                  Line 426
  {"flush", CFLUSHO, VFLUSHO},   /* deprecated compat option.  */               Line 427
  {"discard", CFLUSHO, VFLUSHO},                                                Line 428
#endif                                                                          Line 429
#ifdef VSTATUS                                                                  Line 430
  {"status", CSTATUS, VSTATUS},                                                 Line 431
#endif                                                                          Line 432
                                                                                
  /* These must be last because of the display routines. */                     
  {"min", 1, VMIN},                                                             Line 435
  {"time", 0, VTIME},                                                           Line 436
  {NULL, 0, 0}                                                                  Line 437
};                                                                              Block 7
                                                                                
static char const *visible (cc_t ch);                                           Line 440
static unsigned long int baud_to_value (speed_t speed);                         Line 441
static bool recover_mode (char const *arg, struct termios *mode);               Line 442
static int screen_columns (void);                                               Line 443
static bool set_mode (struct mode_info const *info, bool reversed,              Line 444
                      struct termios *mode);                                    Line 445
static unsigned long int integer_arg (const char *s, unsigned long int max);    Line 446
static speed_t string_to_baud (const char *arg);                                Line 447
static tcflag_t *mode_type_flag (enum mode_type type, struct termios *mode);    Line 448
static void display_all (struct termios *mode, char const *device_name);        Line 449
static void display_changed (struct termios *mode);                             Line 450
static void display_recoverable (struct termios *mode);                         Line 451
static void display_settings (enum output_type output_type,                     Line 452
                              struct termios *mode,                             Line 453
                              const char *device_name);                         Line 454
static void display_speed (struct termios *mode, bool fancy);                   Line 455
static void display_window_size (bool fancy, char const *device_name);          Line 456
static void sane_mode (struct termios *mode);                                   Line 457
static void set_control_char (struct control_info const *info,                  Line 458
                              const char *arg,                                  Line 459
                              struct termios *mode);                            Line 460
static void set_speed (enum speed_setting type, const char *arg,                Line 461
                       struct termios *mode);                                   Line 462
static void set_window_size (int rows, int cols, char const *device_name);      Line 463
                                                                                
/* The width of the screen, for output wrapping. */                             
static int max_col;                                                             Line 466
                                                                                
/* Current position, to know when to wrap. */                                   
static int current_col;                                                         Line 469
                                                                                
/* Default "drain" mode for tcsetattr.  */                                      
static int tcsetattr_options = TCSADRAIN;                                       Line 472
                                                                                
static struct option const longopts[] =                                         Line 474
{                                                                               
  {"all", no_argument, NULL, 'a'},                                              Line 476
  {"save", no_argument, NULL, 'g'},                                             Line 477
  {"file", required_argument, NULL, 'F'},                                       Line 478
  {GETOPT_HELP_OPTION_DECL},                                                    Line 479
  {GETOPT_VERSION_OPTION_DECL},                                                 Line 480
  {NULL, 0, NULL, 0}                                                            Line 481
};                                                                              Block 8
                                                                                
static void wrapf (const char *message, ...)                                    Line 484
     __attribute__ ((__format__ (__printf__, 1, 2)));                           Line 485
                                                                                
/* Print format string MESSAGE and optional args.                               
   Wrap to next line first if it won't fit.                                     
   Print a space first unless MESSAGE will start a new line. */                 
                                                                                
static void                                                                     Line 491
wrapf (const char *message,...)                                                 Line 492
{                                                                               
  va_list args;                                                                 Line 494
  char *buf;                                                                    Line 495
  int buflen;                                                                   Line 496
                                                                                
  va_start (args, message);                                                     Line 498
  buflen = vasprintf (&buf, message, args);                                     Line 499
  va_end (args);                                                                Line 500
                                                                                
  if (buflen < 0)                                                               Line 502
    xalloc_die ();                                                              ...!common auto-comment...
                                                                                
  if (0 < current_col)                                                          Line 505
    {                                                                           
      if (max_col - current_col < buflen)                                       Line 507
        {                                                                       
          putchar ('\n');                                                       Line 509
          current_col = 0;                                                      Line 510
        }                                                                       
      else                                                                      Line 512
        {                                                                       
          putchar (' ');                                                        Line 514
          current_col++;                                                        Line 515
        }                                                                       
    }                                                                           
                                                                                
  fputs (buf, stdout);                                                          Line 519
  free (buf);                                                                   Line 520
  current_col += buflen;                                                        Line 521
}                                                                               Block 9
                                                                                
void                                                                            Line 524
usage (int status)                                                              Line 525
{                                                                               
  if (status != EXIT_SUCCESS)                                                   Line 527
    emit_try_help ();                                                           ...!common auto-comment...
  else                                                                          Line 529
    {                                                                           
      printf (_("\                                                              Line 531
Usage: %s [-F DEVICE | --file=DEVICE] [SETTING]...\n\                           Line 532
  or:  %s [-F DEVICE | --file=DEVICE] [-a|--all]\n\                             Line 533
  or:  %s [-F DEVICE | --file=DEVICE] [-g|--save]\n\                            Line 534
"),                                                                             Line 535
              program_name, program_name, program_name);                        Line 536
      fputs (_("\                                                               Line 537
Print or change terminal characteristics.\n\                                    Line 538
"), stdout);                                                                    Line 539
                                                                                
      emit_mandatory_arg_note ();                                               ...!common auto-comment...
                                                                                
      fputs (_("\                                                               Line 543
  -a, --all          print all current settings in human-readable form\n\       Line 544
  -g, --save         print all current settings in a stty-readable form\n\      Line 545
  -F, --file=DEVICE  open and use the specified DEVICE instead of stdin\n\      Line 546
"), stdout);                                                                    Line 547
      fputs (HELP_OPTION_DESCRIPTION, stdout);                                  Line 548
      fputs (VERSION_OPTION_DESCRIPTION, stdout);                               Line 549
      fputs (_("\                                                               Line 550
\n\                                                                             
Optional - before SETTING indicates negation.  An * marks non-POSIX\n\          Line 552
settings.  The underlying system defines which settings are available.\n\       Line 553
"), stdout);                                                                    Line 554
      fputs (_("\                                                               Line 555
\n\                                                                             
Special characters:\n"), stdout);                                               Line 557
#ifdef VFLUSHO                                                                  Line 558
      fputs (_("\                                                               Line 559
 * discard CHAR  CHAR will toggle discarding of output\n\                       Line 560
"), stdout);                                                                    Line 561
#endif                                                                          Line 562
#ifdef VDSUSP                                                                   Line 563
      fputs (_("\                                                               Line 564
 * dsusp CHAR    CHAR will send a terminal stop signal once input flushed\n\    Line 565
"), stdout);                                                                    Line 566
#endif                                                                          Line 567
      fputs (_("\                                                               Line 568
   eof CHAR      CHAR will send an end of file (terminate the input)\n\         Line 569
   eol CHAR      CHAR will end the line\n\                                      Line 570
"), stdout);                                                                    Line 571
#ifdef VEOL2                                                                    Line 572
      fputs (_("\                                                               Line 573
 * eol2 CHAR     alternate CHAR for ending the line\n\                          Line 574
"), stdout);                                                                    Line 575
#endif                                                                          Line 576
      fputs (_("\                                                               Line 577
   erase CHAR    CHAR will erase the last character typed\n\                    Line 578
   intr CHAR     CHAR will send an interrupt signal\n\                          Line 579
   kill CHAR     CHAR will erase the current line\n\                            Line 580
"), stdout);                                                                    Line 581
#ifdef VLNEXT                                                                   Line 582
      fputs (_("\                                                               Line 583
 * lnext CHAR    CHAR will enter the next character quoted\n\                   Line 584
"), stdout);                                                                    Line 585
#endif                                                                          Line 586
#ifdef VSTATUS                                                                  Line 587
      fputs (_("\                                                               Line 588
 * status CHAR   CHAR will send an info signal\n\                               Line 589
"), stdout);                                                                    Line 590
#endif                                                                          Line 591
      fputs (_("\                                                               Line 592
   quit CHAR     CHAR will send a quit signal\n\                                Line 593
"), stdout);                                                                    Line 594
#if defined CREPRINT || defined VREPRINT                                        Line 595
      fputs (_("\                                                               Line 596
 * rprnt CHAR    CHAR will redraw the current line\n\                           Line 597
"), stdout);                                                                    Line 598
#endif                                                                          Line 599
      fputs (_("\                                                               Line 600
   start CHAR    CHAR will restart the output after stopping it\n\              Line 601
   stop CHAR     CHAR will stop the output\n\                                   Line 602
   susp CHAR     CHAR will send a terminal stop signal\n\                       Line 603
"), stdout);                                                                    Line 604
#ifdef VSWTCH                                                                   Line 605
      fputs (_("\                                                               Line 606
 * swtch CHAR    CHAR will switch to a different shell layer\n\                 Line 607
"), stdout);                                                                    Line 608
#endif                                                                          Line 609
#ifdef VWERASE                                                                  Line 610
      fputs (_("\                                                               Line 611
 * werase CHAR   CHAR will erase the last word typed\n\                         Line 612
"), stdout);                                                                    Line 613
#endif                                                                          Line 614
      fputs (_("\                                                               Line 615
\n\                                                                             
Special settings:\n\                                                            Line 617
   N             set the input and output speeds to N bauds\n\                  Line 618
"), stdout);                                                                    Line 619
#ifdef TIOCGWINSZ                                                               Line 620
      fputs (_("\                                                               Line 621
 * cols N        tell the kernel that the terminal has N columns\n\             Line 622
 * columns N     same as cols N\n\                                              Line 623
"), stdout);                                                                    Line 624
#endif                                                                          Line 625
      printf (_("\                                                              Line 626
 * [-]drain      wait for transmission before applying settings (%s by default)\Line 627
\n"), tcsetattr_options == TCSADRAIN ? _("on") : _("off"));                     Line 628
      fputs (_("\                                                               Line 629
   ispeed N      set the input speed to N\n\                                    Line 630
"), stdout);                                                                    Line 631
#ifdef HAVE_C_LINE                                                              Line 632
      fputs (_("\                                                               Line 633
 * line N        use line discipline N\n\                                       Line 634
"), stdout);                                                                    Line 635
#endif                                                                          Line 636
      fputs (_("\                                                               Line 637
   min N         with -icanon, set N characters minimum for a completed read\n\ Line 638
   ospeed N      set the output speed to N\n\                                   Line 639
"), stdout);                                                                    Line 640
#ifdef TIOCGWINSZ                                                               Line 641
      fputs (_("\                                                               Line 642
 * rows N        tell the kernel that the terminal has N rows\n\                Line 643
 * size          print the number of rows and columns according to the kernel\n\Line 644
"), stdout);                                                                    Line 645
#endif                                                                          Line 646
      fputs (_("\                                                               Line 647
   speed         print the terminal speed\n\                                    Line 648
   time N        with -icanon, set read timeout of N tenths of a second\n\      Line 649
"), stdout);                                                                    Line 650
      fputs (_("\                                                               Line 651
\n\                                                                             
Control settings:\n\                                                            Line 653
   [-]clocal     disable modem control signals\n\                               Line 654
   [-]cread      allow input to be received\n\                                  Line 655
"), stdout);                                                                    Line 656
#ifdef CRTSCTS                                                                  Line 657
      fputs (_("\                                                               Line 658
 * [-]crtscts    enable RTS/CTS handshaking\n\                                  Line 659
"), stdout);                                                                    Line 660
#endif                                                                          Line 661
#ifdef CDTRDSR                                                                  Line 662
      fputs (_("\                                                               Line 663
 * [-]cdtrdsr    enable DTR/DSR handshaking\n\                                  Line 664
"), stdout);                                                                    Line 665
#endif                                                                          Line 666
      fputs (_("\                                                               Line 667
   csN           set character size to N bits, N in [5..8]\n\                   Line 668
"), stdout);                                                                    Line 669
      fputs (_("\                                                               Line 670
   [-]cstopb     use two stop bits per character (one with '-')\n\              Line 671
   [-]hup        send a hangup signal when the last process closes the tty\n\   Line 672
   [-]hupcl      same as [-]hup\n\                                              Line 673
   [-]parenb     generate parity bit in output and expect parity bit in input\n\Line 674
   [-]parodd     set odd parity (or even parity with '-')\n\                    Line 675
"), stdout);                                                                    Line 676
#ifdef CMSPAR                                                                   Line 677
      fputs (_("\                                                               Line 678
 * [-]cmspar     use \"stick\" (mark/space) parity\n\                           Line 679
"), stdout);                                                                    Line 680
#endif                                                                          Line 681
      fputs (_("\                                                               Line 682
\n\                                                                             
Input settings:\n\                                                              Line 684
   [-]brkint     breaks cause an interrupt signal\n\                            Line 685
   [-]icrnl      translate carriage return to newline\n\                        Line 686
   [-]ignbrk     ignore break characters\n\                                     Line 687
   [-]igncr      ignore carriage return\n\                                      Line 688
   [-]ignpar     ignore characters with parity errors\n\                        Line 689
"), stdout);                                                                    Line 690
#ifdef IMAXBEL                                                                  Line 691
      fputs (_("\                                                               Line 692
 * [-]imaxbel    beep and do not flush a full input buffer on a character\n\    Line 693
"), stdout);                                                                    Line 694
#endif                                                                          Line 695
      fputs (_("\                                                               Line 696
   [-]inlcr      translate newline to carriage return\n\                        Line 697
   [-]inpck      enable input parity checking\n\                                Line 698
   [-]istrip     clear high (8th) bit of input characters\n\                    Line 699
"), stdout);                                                                    Line 700
#ifdef IUTF8                                                                    Line 701
      fputs (_("\                                                               Line 702
 * [-]iutf8      assume input characters are UTF-8 encoded\n\                   Line 703
"), stdout);                                                                    Line 704
#endif                                                                          Line 705
#ifdef IUCLC                                                                    Line 706
      fputs (_("\                                                               Line 707
 * [-]iuclc      translate uppercase characters to lowercase\n\                 Line 708
"), stdout);                                                                    Line 709
#endif                                                                          Line 710
#ifdef IXANY                                                                    Line 711
      fputs (_("\                                                               Line 712
 * [-]ixany      let any character restart output, not only start character\n\  Line 713
"), stdout);                                                                    Line 714
#endif                                                                          Line 715
      fputs (_("\                                                               Line 716
   [-]ixoff      enable sending of start/stop characters\n\                     Line 717
   [-]ixon       enable XON/XOFF flow control\n\                                Line 718
   [-]parmrk     mark parity errors (with a 255-0-character sequence)\n\        Line 719
   [-]tandem     same as [-]ixoff\n\                                            Line 720
"), stdout);                                                                    Line 721
      fputs (_("\                                                               Line 722
\n\                                                                             
Output settings:\n\                                                             Line 724
"), stdout);                                                                    Line 725
#ifdef BSDLY                                                                    Line 726
      fputs (_("\                                                               Line 727
 * bsN           backspace delay style, N in [0..1]\n\                          Line 728
"), stdout);                                                                    Line 729
#endif                                                                          Line 730
#ifdef CRDLY                                                                    Line 731
      fputs (_("\                                                               Line 732
 * crN           carriage return delay style, N in [0..3]\n\                    Line 733
"), stdout);                                                                    Line 734
#endif                                                                          Line 735
#ifdef FFDLY                                                                    Line 736
      fputs (_("\                                                               Line 737
 * ffN           form feed delay style, N in [0..1]\n\                          Line 738
"), stdout);                                                                    Line 739
#endif                                                                          Line 740
#ifdef NLDLY                                                                    Line 741
      fputs (_("\                                                               Line 742
 * nlN           newline delay style, N in [0..1]\n\                            Line 743
"), stdout);                                                                    Line 744
#endif                                                                          Line 745
#ifdef OCRNL                                                                    Line 746
      fputs (_("\                                                               Line 747
 * [-]ocrnl      translate carriage return to newline\n\                        Line 748
"), stdout);                                                                    Line 749
#endif                                                                          Line 750
#ifdef OFDEL                                                                    Line 751
      fputs (_("\                                                               Line 752
 * [-]ofdel      use delete characters for fill instead of NUL characters\n\    Line 753
"), stdout);                                                                    Line 754
#endif                                                                          Line 755
#ifdef OFILL                                                                    Line 756
      fputs (_("\                                                               Line 757
 * [-]ofill      use fill (padding) characters instead of timing for delays\n\  Line 758
"), stdout);                                                                    Line 759
#endif                                                                          Line 760
#ifdef OLCUC                                                                    Line 761
      fputs (_("\                                                               Line 762
 * [-]olcuc      translate lowercase characters to uppercase\n\                 Line 763
"), stdout);                                                                    Line 764
#endif                                                                          Line 765
#ifdef ONLCR                                                                    Line 766
      fputs (_("\                                                               Line 767
 * [-]onlcr      translate newline to carriage return-newline\n\                Line 768
"), stdout);                                                                    Line 769
#endif                                                                          Line 770
#ifdef ONLRET                                                                   Line 771
      fputs (_("\                                                               Line 772
 * [-]onlret     newline performs a carriage return\n\                          Line 773
"), stdout);                                                                    Line 774
#endif                                                                          Line 775
#ifdef ONOCR                                                                    Line 776
      fputs (_("\                                                               Line 777
 * [-]onocr      do not print carriage returns in the first column\n\           Line 778
"), stdout);                                                                    Line 779
#endif                                                                          Line 780
      fputs (_("\                                                               Line 781
   [-]opost      postprocess output\n\                                          Line 782
"), stdout);                                                                    Line 783
#if defined TABDLY || defined OXTABS                                            Line 784
      fputs (_("\                                                               Line 785
 * tabN          horizontal tab delay style, N in [0..3]\n\                     Line 786
 * tabs          same as tab0\n\                                                Line 787
 * -tabs         same as tab3\n\                                                Line 788
"), stdout);                                                                    Line 789
#endif                                                                          Line 790
#ifdef VTDLY                                                                    Line 791
      fputs (_("\                                                               Line 792
 * vtN           vertical tab delay style, N in [0..1]\n\                       Line 793
"), stdout);                                                                    Line 794
#endif                                                                          Line 795
      fputs (_("\                                                               Line 796
\n\                                                                             
Local settings:\n\                                                              Line 798
   [-]crterase   echo erase characters as backspace-space-backspace\n\          Line 799
"), stdout);                                                                    Line 800
#ifdef ECHOKE                                                                   Line 801
      fputs (_("\                                                               Line 802
 * crtkill       kill all line by obeying the echoprt and echoe settings\n\     Line 803
 * -crtkill      kill all line by obeying the echoctl and echok settings\n\     Line 804
"), stdout);                                                                    Line 805
#endif                                                                          Line 806
#ifdef ECHOCTL                                                                  Line 807
      fputs (_("\                                                               Line 808
 * [-]ctlecho    echo control characters in hat notation ('^c')\n\              Line 809
"), stdout);                                                                    Line 810
#endif                                                                          Line 811
      fputs (_("\                                                               Line 812
   [-]echo       echo input characters\n\                                       Line 813
"), stdout);                                                                    Line 814
#ifdef ECHOCTL                                                                  Line 815
      fputs (_("\                                                               Line 816
 * [-]echoctl    same as [-]ctlecho\n\                                          Line 817
"), stdout);                                                                    Line 818
#endif                                                                          Line 819
      fputs (_("\                                                               Line 820
   [-]echoe      same as [-]crterase\n\                                         Line 821
   [-]echok      echo a newline after a kill character\n\                       Line 822
"), stdout);                                                                    Line 823
#ifdef ECHOKE                                                                   Line 824
      fputs (_("\                                                               Line 825
 * [-]echoke     same as [-]crtkill\n\                                          Line 826
"), stdout);                                                                    Line 827
#endif                                                                          Line 828
      fputs (_("\                                                               Line 829
   [-]echonl     echo newline even if not echoing other characters\n\           Line 830
"), stdout);                                                                    Line 831
#ifdef ECHOPRT                                                                  Line 832
      fputs (_("\                                                               Line 833
 * [-]echoprt    echo erased characters backward, between '\\' and '/'\n\       Line 834
"), stdout);                                                                    Line 835
#endif                                                                          Line 836
#if defined EXTPROC || defined TIOCEXT                                          Line 837
      fputs (_("\                                                               Line 838
 * [-]extproc    enable \"LINEMODE\"; useful with high latency links\n\         Line 839
"), stdout);                                                                    Line 840
#endif                                                                          Line 841
#if defined FLUSHO                                                              Line 842
      fputs (_("\                                                               Line 843
 * [-]flusho     discard output\n\                                              Line 844
"), stdout);                                                                    Line 845
#endif                                                                          Line 846
      printf (_("\                                                              Line 847
   [-]icanon     enable special characters: %s\n\                               Line 848
   [-]iexten     enable non-POSIX special characters\n\                         Line 849
"), "erase, kill"                                                               Line 850
#ifdef VWERASE                                                                  Line 851
    ", werase"                                                                  Line 852
#endif                                                                          Line 853
#if defined CREPRINT || defined VREPRINT                                        Line 854
    ", rprnt"                                                                   Line 855
#endif                                                                          Line 856
);                                                                              
      fputs (_("\                                                               Line 858
   [-]isig       enable interrupt, quit, and suspend special characters\n\      Line 859
   [-]noflsh     disable flushing after interrupt and quit special characters\n\Line 860
"), stdout);                                                                    Line 861
#ifdef ECHOPRT                                                                  Line 862
      fputs (_("\                                                               Line 863
 * [-]prterase   same as [-]echoprt\n\                                          Line 864
"), stdout);                                                                    Line 865
#endif                                                                          Line 866
#ifdef TOSTOP                                                                   Line 867
      fputs (_("\                                                               Line 868
 * [-]tostop     stop background jobs that try to write to the terminal\n\      Line 869
"), stdout);                                                                    Line 870
#endif                                                                          Line 871
#ifdef XCASE                                                                    Line 872
      fputs (_("\                                                               Line 873
 * [-]xcase      with icanon, escape with '\\' for uppercase characters\n\      Line 874
"), stdout);                                                                    Line 875
#endif                                                                          Line 876
      fputs (_("\                                                               Line 877
\n\                                                                             
Combination settings:\n\                                                        Line 879
"), stdout);                                                                    Line 880
#if defined XCASE && defined IUCLC && defined OLCUC                             Line 881
      fputs (_("\                                                               Line 882
 * [-]LCASE      same as [-]lcase\n\                                            Line 883
"), stdout);                                                                    Line 884
#endif                                                                          Line 885
      fputs (_("\                                                               Line 886
   cbreak        same as -icanon\n\                                             Line 887
   -cbreak       same as icanon\n\                                              Line 888
"), stdout);                                                                    Line 889
      fputs (_("\                                                               Line 890
   cooked        same as brkint ignpar istrip icrnl ixon opost isig\n\          Line 891
                 icanon, eof and eol characters to their default values\n\      Line 892
   -cooked       same as raw\n\                                                 Line 893
"), stdout);                                                                    Line 894
      printf (_("\                                                              Line 895
   crt           same as %s\n\                                                  Line 896
"), "echoe"                                                                     Line 897
#ifdef ECHOCTL                                                                  Line 898
    " echoctl"                                                                  Line 899
#endif                                                                          Line 900
#ifdef ECHOKE                                                                   Line 901
    " echoke"                                                                   Line 902
#endif                                                                          Line 903
);                                                                              
      printf (_("\                                                              Line 905
   dec           same as %s intr ^c erase 0177\n\                               Line 906
                 kill ^u\n\                                                     Line 907
"), "echoe"                                                                     Line 908
#ifdef ECHOCTL                                                                  Line 909
    " echoctl"                                                                  Line 910
#endif                                                                          Line 911
#ifdef ECHOKE                                                                   Line 912
    " echoke"                                                                   Line 913
#endif                                                                          Line 914
#ifdef IXANY                                                                    Line 915
    " -ixany"                                                                   Line 916
#endif                                                                          Line 917
);                                                                              
#ifdef IXANY                                                                    Line 919
      fputs (_("\                                                               Line 920
 * [-]decctlq    same as [-]ixany\n\                                            Line 921
"), stdout);                                                                    Line 922
#endif                                                                          Line 923
      fputs (_("\                                                               Line 924
   ek            erase and kill characters to their default values\n\           Line 925
   evenp         same as parenb -parodd cs7\n\                                  Line 926
   -evenp        same as -parenb cs8\n\                                         Line 927
"), stdout);                                                                    Line 928
#if defined XCASE && defined IUCLC && defined OLCUC                             Line 929
      fputs (_("\                                                               Line 930
 * [-]lcase      same as xcase iuclc olcuc\n\                                   Line 931
"), stdout);                                                                    Line 932
#endif                                                                          Line 933
      fputs (_("\                                                               Line 934
   litout        same as -parenb -istrip -opost cs8\n\                          Line 935
   -litout       same as parenb istrip opost cs7\n\                             Line 936
"), stdout);                                                                    Line 937
      printf (_("\                                                              Line 938
   nl            same as %s\n\                                                  Line 939
   -nl           same as %s\n\                                                  Line 940
"), "-icrnl"                                                                    Line 941
#ifdef ONLCR                                                                    Line 942
   " -onlcr"                                                                    Line 943
#endif                                                                          Line 944
  , "icrnl -inlcr -igncr"                                                       Line 945
#ifdef ONLCR                                                                    Line 946
   " onlcr"                                                                     Line 947
#endif                                                                          Line 948
#ifdef OCRNL                                                                    Line 949
   " -ocrnl"                                                                    Line 950
#endif                                                                          Line 951
#ifdef ONLRET                                                                   Line 952
   " -onlret"                                                                   Line 953
#endif                                                                          Line 954
);                                                                              
      fputs (_("\                                                               Line 956
   oddp          same as parenb parodd cs7\n\                                   Line 957
   -oddp         same as -parenb cs8\n\                                         Line 958
   [-]parity     same as [-]evenp\n\                                            Line 959
   pass8         same as -parenb -istrip cs8\n\                                 Line 960
   -pass8        same as parenb istrip cs7\n\                                   Line 961
"), stdout);                                                                    Line 962
      printf (_("\                                                              Line 963
   raw           same as -ignbrk -brkint -ignpar -parmrk -inpck -istrip\n\      Line 964
                 -inlcr -igncr -icrnl -ixon -ixoff -icanon -opost\n\            Line 965
                 -isig%s min 1 time 0\n\                                        Line 966
   -raw          same as cooked\n\                                              Line 967
"),                                                                             Line 968
#ifdef IUCLC                                                                    Line 969
   " -iuclc"                                                                    Line 970
#endif                                                                          Line 971
#ifdef IXANY                                                                    Line 972
   " -ixany"                                                                    Line 973
#endif                                                                          Line 974
#ifdef IMAXBEL                                                                  Line 975
   " -imaxbel"                                                                  Line 976
#endif                                                                          Line 977
#ifdef XCASE                                                                    Line 978
   " -xcase"                                                                    Line 979
#endif                                                                          Line 980
);                                                                              
      printf (_("\                                                              Line 982
   sane          same as cread -ignbrk brkint -inlcr -igncr icrnl\n\            Line 983
                 icanon iexten echo echoe echok -echonl -noflsh\n\              Line 984
                 %s\n\                                                          Line 985
                 %s\n\                                                          Line 986
                 %s,\n\                                                         Line 987
                 all special characters to their default values\n\              Line 988
"),                                                                             Line 989
   "-ixoff"                                                                     Line 990
#ifdef IUTF8                                                                    Line 991
   " -iutf8"                                                                    Line 992
#endif                                                                          Line 993
#ifdef IUCLC                                                                    Line 994
   " -iuclc"                                                                    Line 995
#endif                                                                          Line 996
#ifdef IXANY                                                                    Line 997
   " -ixany"                                                                    Line 998
#endif                                                                          Line 999
#ifdef IMAXBEL                                                                  Line 1000
   " imaxbel"                                                                   Line 1001
#endif                                                                          Line 1002
#ifdef XCASE                                                                    Line 1003
   " -xcase"                                                                    Line 1004
#endif                                                                          Line 1005
#ifdef OLCUC                                                                    Line 1006
   " -olcuc"                                                                    Line 1007
#endif                                                                          Line 1008
#ifdef OCRNL                                                                    Line 1009
   " -ocrnl"                                                                    Line 1010
#endif                                                                          Line 1011
                                                                                
 , "opost"                                                                      Line 1013
#ifdef OFILL                                                                    Line 1014
   " -ofill"                                                                    Line 1015
#endif                                                                          Line 1016
#ifdef ONLCR                                                                    Line 1017
   " onlcr"                                                                     Line 1018
#endif                                                                          Line 1019
#ifdef ONOCR                                                                    Line 1020
   " -onocr"                                                                    Line 1021
#endif                                                                          Line 1022
#ifdef ONLRET                                                                   Line 1023
   " -onlret"                                                                   Line 1024
#endif                                                                          Line 1025
#ifdef NLDLY                                                                    Line 1026
   " nl0"                                                                       Line 1027
#endif                                                                          Line 1028
#ifdef CRDLY                                                                    Line 1029
   " cr0"                                                                       Line 1030
#endif                                                                          Line 1031
#ifdef TAB0                                                                     Line 1032
   " tab0"                                                                      Line 1033
#endif                                                                          Line 1034
#ifdef BSDLY                                                                    Line 1035
   " bs0"                                                                       Line 1036
#endif                                                                          Line 1037
#ifdef VTDLY                                                                    Line 1038
   " vt0"                                                                       Line 1039
#endif                                                                          Line 1040
#ifdef FFDLY                                                                    Line 1041
   " ff0"                                                                       Line 1042
#endif                                                                          Line 1043
                                                                                
 , "isig"                                                                       Line 1045
#ifdef TOSTOP                                                                   Line 1046
   " -tostop"                                                                   Line 1047
#endif                                                                          Line 1048
#ifdef OFDEL                                                                    Line 1049
   " -ofdel"                                                                    Line 1050
#endif                                                                          Line 1051
#ifdef ECHOPRT                                                                  Line 1052
   " -echoprt"                                                                  Line 1053
#endif                                                                          Line 1054
#ifdef ECHOCTL                                                                  Line 1055
   " echoctl"                                                                   Line 1056
#endif                                                                          Line 1057
#ifdef ECHOKE                                                                   Line 1058
   " echoke"                                                                    Line 1059
#endif                                                                          Line 1060
#ifdef EXTPROC                                                                  Line 1061
   " -extproc"                                                                  Line 1062
#endif                                                                          Line 1063
#ifdef FLUSHO                                                                   Line 1064
   " -flusho"                                                                   Line 1065
#endif                                                                          Line 1066
);                                                                              
      fputs (_("\                                                               Line 1068
\n\                                                                             
Handle the tty line connected to standard input.  Without arguments,\n\         Line 1070
prints baud rate, line discipline, and deviations from stty sane.  In\n\        Line 1071
settings, CHAR is taken literally, or coded as in ^c, 0x37, 0177 or\n\          Line 1072
127; special values ^- or undef used to disable special characters.\n\          Line 1073
"), stdout);                                                                    Line 1074
      emit_ancillary_info (PROGRAM_NAME);                                       Line 1075
    }                                                                           
  exit (status);                                                                Line 1077
}                                                                               Block 10
                                                                                
                                                                                
/* Apply specified settings to MODE, and update                                 
   SPEED_WAS_SET and REQUIRE_SET_ATTR as required.                              
   If CHECKING is true, this function doesn't interact                          
   with a device, and only validates specified settings.  */                    
                                                                                
static void                                                                     Line 1086
apply_settings (bool checking, const char *device_name,                         Line 1087
                char * const *settings, int n_settings,                         Line 1088
                struct termios *mode, bool *speed_was_set,                      Line 1089
                bool *require_set_attr)                                         Line 1090
{                                                                               
#define check_argument(arg)      \                                              Line 1092
  do         \                                                                  Line 1093
    {         \                                                                 Line 1094
      if (k == n_settings - 1 || ! settings[k+1])   \                           Line 1095
        {        \                                                              Line 1096
          error (0, 0, _("missing argument to %s"), quote (arg)); \             Line 1097
          usage (EXIT_FAILURE);      \                                          Line 1098
        }        \                                                              Line 1099
    }         \                                                                 Line 1100
  while (0)                                                                     Line 1101
                                                                                
  for (int k = 1; k < n_settings; k++)                                          Line 1103
    {                                                                           
      char const *arg = settings[k];                                            Line 1105
      bool match_found = false;                                                 Line 1106
      bool not_set_attr = false;                                                Line 1107
      bool reversed = false;                                                    Line 1108
      int i;                                                                    Line 1109
                                                                                
      if (! arg)                                                                Line 1111
        continue;                                                               Line 1112
                                                                                
      if (arg[0] == '-')                                                        Line 1114
        {                                                                       
          ++arg;                                                                Line 1116
          reversed = true;                                                      Line 1117
        }                                                                       
      if (STREQ (arg, "drain"))                                                 Line 1119
        {                                                                       
          tcsetattr_options = reversed ? TCSANOW : TCSADRAIN;                   Line 1121
          continue;                                                             Line 1122
        }                                                                       
      for (i = 0; mode_info[i].name != NULL; ++i)                               Line 1124
        {                                                                       
          if (STREQ (arg, mode_info[i].name))                                   Line 1126
            {                                                                   
              if ((mode_info[i].flags & NO_SETATTR) == 0)                       Line 1128
                {                                                               
                  match_found = set_mode (&mode_info[i], reversed, mode);       Line 1130
                  *require_set_attr = true;                                     Line 1131
                }                                                               
              else                                                              Line 1133
                match_found = not_set_attr = true;                              Line 1134
              break;                                                            Line 1135
            }                                                                   
        }                                                                       
      if (!match_found && reversed)                                             Line 1138
        {                                                                       
          error (0, 0, _("invalid argument %s"), quote (arg - 1));              Line 1140
          usage (EXIT_FAILURE);                                                 Line 1141
        }                                                                       
      if (!match_found)                                                         Line 1143
        {                                                                       
          for (i = 0; control_info[i].name != NULL; ++i)                        Line 1145
            {                                                                   
              if (STREQ (arg, control_info[i].name))                            Line 1147
                {                                                               
                  check_argument (arg);                                         Line 1149
                  match_found = true;                                           Line 1150
                  ++k;                                                          Line 1151
                  set_control_char (&control_info[i], settings[k], mode);       Line 1152
                  *require_set_attr = true;                                     Line 1153
                  break;                                                        Line 1154
                }                                                               
            }                                                                   
        }                                                                       
      if (!match_found || not_set_attr)                                         Line 1158
        {                                                                       
          if (STREQ (arg, "ispeed"))                                            Line 1160
            {                                                                   
              check_argument (arg);                                             Line 1162
              ++k;                                                              Line 1163
              if (checking)                                                     Line 1164
                continue;                                                       Line 1165
              set_speed (input_speed, settings[k], mode);                       Line 1166
              *speed_was_set = true;                                            Line 1167
              *require_set_attr = true;                                         Line 1168
            }                                                                   
          else if (STREQ (arg, "ospeed"))                                       Line 1170
            {                                                                   
              check_argument (arg);                                             Line 1172
              ++k;                                                              Line 1173
              if (checking)                                                     Line 1174
                continue;                                                       Line 1175
              set_speed (output_speed, settings[k], mode);                      Line 1176
              *speed_was_set = true;                                            Line 1177
              *require_set_attr = true;                                         Line 1178
            }                                                                   
#ifdef TIOCEXT                                                                  Line 1180
          /* This is the BSD interface to "extproc".                            
            Even though it's an lflag, an ioctl is used to set it.  */          
          else if (STREQ (arg, "extproc"))                                      Line 1183
            {                                                                   
              int val = ! reversed;                                             Line 1185
                                                                                
              if (checking)                                                     Line 1187
                continue;                                                       Line 1188
                                                                                
              if (ioctl (STDIN_FILENO, TIOCEXT, &val) != 0)                     Line 1190...!syscalls auto-comment...
                {                                                               
                  die (EXIT_FAILURE, errno, _("%s: error setting %s"),          Line 1192
                       quotef_n (0, device_name), quote_n (1, arg));            Line 1193
                }                                                               
            }                                                                   
#endif                                                                          Line 1196
#ifdef TIOCGWINSZ                                                               Line 1197
          else if (STREQ (arg, "rows"))                                         Line 1198
            {                                                                   
              check_argument (arg);                                             Line 1200
              ++k;                                                              Line 1201
              if (checking)                                                     Line 1202
                continue;                                                       Line 1203
              set_window_size (integer_arg (settings[k], INT_MAX), -1,          Line 1204
                               device_name);                                    Line 1205
            }                                                                   
          else if (STREQ (arg, "cols")                                          Line 1207
                   || STREQ (arg, "columns"))                                   Line 1208
            {                                                                   
              check_argument (arg);                                             Line 1210
              ++k;                                                              Line 1211
              if (checking)                                                     Line 1212
                continue;                                                       Line 1213
              set_window_size (-1, integer_arg (settings[k], INT_MAX),          Line 1214
                               device_name);                                    Line 1215
            }                                                                   
          else if (STREQ (arg, "size"))                                         Line 1217
            {                                                                   
              if (checking)                                                     Line 1219
                continue;                                                       Line 1220
              max_col = screen_columns ();                                      Line 1221
              current_col = 0;                                                  Line 1222
              display_window_size (false, device_name);                         Line 1223
            }                                                                   
#endif                                                                          Line 1225
#ifdef HAVE_C_LINE                                                              Line 1226
          else if (STREQ (arg, "line"))                                         Line 1227
            {                                                                   
              unsigned long int value;                                          Line 1229
              check_argument (arg);                                             Line 1230
              ++k;                                                              Line 1231
              mode->c_line = value = integer_arg (settings[k], ULONG_MAX);      Line 1232
              if (mode->c_line != value)                                        Line 1233
                error (0, 0, _("invalid line discipline %s"),                   Line 1234
                       quote (settings[k]));                                    Line 1235
              *require_set_attr = true;                                         Line 1236
            }                                                                   
#endif                                                                          Line 1238
          else if (STREQ (arg, "speed"))                                        Line 1239
            {                                                                   
              if (checking)                                                     Line 1241
                continue;                                                       Line 1242
              max_col = screen_columns ();                                      Line 1243
              display_speed (mode, false);                                      Line 1244
            }                                                                   
          else if (string_to_baud (arg) != (speed_t) -1)                        Line 1246
            {                                                                   
              if (checking)                                                     Line 1248
                continue;                                                       Line 1249
              set_speed (both_speeds, arg, mode);                               Line 1250
              *speed_was_set = true;                                            Line 1251
              *require_set_attr = true;                                         Line 1252
            }                                                                   
          else                                                                  Line 1254
            {                                                                   
              if (! recover_mode (arg, mode))                                   Line 1256
                {                                                               
                  error (0, 0, _("invalid argument %s"), quote (arg));          Line 1258
                  usage (EXIT_FAILURE);                                         Line 1259
                }                                                               
              *require_set_attr = true;                                         Line 1261
            }                                                                   
        }                                                                       
    }                                                                           
}                                                                               Block 11
                                                                                
int                                                                             
main (int argc, char **argv)                                                    Line 1268
{                                                                               
  /* Initialize to all zeroes so there is no risk memcmp will report a          
     spurious difference in an uninitialized portion of the structure.  */      
  static struct termios mode;                                                   Line 1272
                                                                                
  enum output_type output_type;                                                 Line 1274
  int optc;                                                                     Line 1275
  int argi = 0;                                                                 Line 1276
  int opti = 1;                                                                 Line 1277
  bool require_set_attr;                                                        Line 1278
  bool speed_was_set _GL_UNUSED;                                                Line 1279
  bool verbose_output;                                                          Line 1280
  bool recoverable_output;                                                      Line 1281
  bool noargs = true;                                                           Line 1282
  char *file_name = NULL;                                                       Line 1283
  const char *device_name;                                                      Line 1284
                                                                                
  initialize_main (&argc, &argv);                                               VMS-specific entry point handling wildcard expansion
  set_program_name (argv[0]);                                                   Retains program name and discards path
  setlocale (LC_ALL, "");                                                       Sets up internationalization (i18n)
  bindtextdomain (PACKAGE, LOCALEDIR);                                          Assigns i18n directorySets text domain for _() [gettext()] function
  textdomain (PACKAGE);                                                         Sets text domain for _() [gettext()] function
                                                                                
  atexit (close_stdout);                                                        Close stdout on exit (see gnulib)
                                                                                
  output_type = changed;                                                        Line 1294
  verbose_output = false;                                                       Line 1295
  recoverable_output = false;                                                   Line 1296
                                                                                
  /* Don't print error messages for unrecognized options.  */                   
  opterr = 0;                                                                   Line 1299
                                                                                
  /* If any new options are ever added to stty, the short options MUST          
     NOT allow any ambiguity with the stty settings.  For example, the          
     stty setting "-gagFork" would not be feasible, since it will be            
     parsed as "-g -a -g -F ork".  If you change anything about how             
     stty parses options, be sure it still works with combinations of           
     short and long options, --, POSIXLY_CORRECT, etc.  */                      
                                                                                
  while ((optc = getopt_long (argc - argi, argv + argi, "-agF:",                Line 1308
                              longopts, NULL))                                  Line 1309
         != -1)                                                                 Line 1310
    {                                                                           
      switch (optc)                                                             Line 1312
        {                                                                       
        case 'a':                                                               Line 1314
          verbose_output = true;                                                Line 1315
          output_type = all;                                                    Line 1316
          break;                                                                Line 1317
                                                                                
        case 'g':                                                               Line 1319
          recoverable_output = true;                                            Line 1320
          output_type = recoverable;                                            Line 1321
          break;                                                                Line 1322
                                                                                
        case 'F':                                                               Line 1324
          if (file_name)                                                        Line 1325
            die (EXIT_FAILURE, 0, _("only one device may be specified"));       Line 1326
          file_name = optarg;                                                   Line 1327
          break;                                                                Line 1328
                                                                                
        case_GETOPT_HELP_CHAR;                                                  Line 1330
                                                                                
        case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);                       Line 1332
                                                                                
        default:                                                                Line 1334
          /* Consider "drain" as an option rather than a setting,               
             to support: alias stty='stty -drain'  etc.  */                     
          if (! STREQ (argv[argi + opti], "-drain")                             Line 1337
              && ! STREQ (argv[argi + opti], "drain"))                          Line 1338
            noargs = false;                                                     Line 1339
                                                                                
          /* Skip the argument containing this unrecognized option;             
             the 2nd pass will analyze it.  */                                  
          argi += opti;                                                         Line 1343
                                                                                
          /* Restart getopt_long from the first unskipped argument.  */         
          opti = 1;                                                             Line 1346
          optind = 0;                                                           Line 1347
                                                                                
          break;                                                                Line 1349
        }                                                                       
                                                                                
      /* Clear fully-parsed arguments, so they don't confuse the 2nd pass.  */  
      while (opti < optind)                                                     Line 1353
        argv[argi + opti++] = NULL;                                             Line 1354
    }                                                                           
                                                                                
  /* Specifying both -a and -g gets an error.  */                               
  if (verbose_output && recoverable_output)                                     Line 1358
    die (EXIT_FAILURE, 0,                                                       Line 1359
         _("the options for verbose and stty-readable output styles are\n"      Line 1360
           "mutually exclusive"));                                              Line 1361
                                                                                
  /* Specifying any other arguments with -a or -g gets an error.  */            
  if (!noargs && (verbose_output || recoverable_output))                        Line 1364
    die (EXIT_FAILURE, 0,                                                       Line 1365
         _("when specifying an output style, modes may not be set"));           Line 1366
                                                                                
  device_name = file_name ? file_name : _("standard input");                    Line 1368
                                                                                
  if (!noargs && !verbose_output && !recoverable_output)                        Line 1370
    {                                                                           
      static struct termios check_mode;                                         Line 1372
      apply_settings (/* checking= */ true, device_name, argv, argc,            Line 1373
                      &check_mode, &speed_was_set, &require_set_attr);          Line 1374
    }                                                                           
                                                                                
  if (file_name)                                                                Line 1377
    {                                                                           
      int fdflags;                                                              Line 1379
      if (fd_reopen (STDIN_FILENO, device_name, O_RDONLY | O_NONBLOCK, 0) < 0)  Line 1380...!syscalls auto-comment...
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1381
      if ((fdflags = fcntl (STDIN_FILENO, F_GETFL)) == -1                       Line 1382...!syscalls auto-comment...
          || fcntl (STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)          Line 1383...!syscalls auto-comment...
        die (EXIT_FAILURE, errno, _("%s: couldn't reset non-blocking mode"),    Line 1384
             quotef (device_name));                                             Line 1385
    }                                                                           
                                                                                
  if (tcgetattr (STDIN_FILENO, &mode))                                          Line 1388
    die (EXIT_FAILURE, errno, "%s", quotef (device_name));                      Line 1389
                                                                                
  if (verbose_output || recoverable_output || noargs)                           Line 1391
    {                                                                           
      max_col = screen_columns ();                                              Line 1393
      current_col = 0;                                                          Line 1394
      display_settings (output_type, &mode, device_name);                       Line 1395
      return EXIT_SUCCESS;                                                      Line 1396
    }                                                                           
                                                                                
  speed_was_set = false;                                                        Line 1399
  require_set_attr = false;                                                     Line 1400
  apply_settings (/* checking= */ false, device_name, argv, argc,               Line 1401
                  &mode, &speed_was_set, &require_set_attr);                    Line 1402
                                                                                
  if (require_set_attr)                                                         Line 1404
    {                                                                           
      /* Initialize to all zeroes so there is no risk memcmp will report a      
         spurious difference in an uninitialized portion of the structure.  */  
      static struct termios new_mode;                                           Line 1408
                                                                                
      if (tcsetattr (STDIN_FILENO, tcsetattr_options, &mode))                   Line 1410
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1411
                                                                                
      /* POSIX (according to Zlotnick's book) tcsetattr returns zero if         
         it performs *any* of the requested operations.  This means it          
         can report 'success' when it has actually failed to perform            
         some proper subset of the requested operations.  To detect             
         this partial failure, get the current terminal attributes and          
         compare them to the requested ones.  */                                
                                                                                
      if (tcgetattr (STDIN_FILENO, &new_mode))                                  Line 1420
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1421
                                                                                
      /* Normally, one shouldn't use memcmp to compare structures that          
         may have 'holes' containing uninitialized data, but we have been       
         careful to initialize the storage of these two variables to all        
         zeroes.  One might think it more efficient simply to compare the       
         modified fields, but that would require enumerating those fields --    
         and not all systems have the same fields in this structure.  */        
                                                                                
      if (memcmp (&mode, &new_mode, sizeof (mode)) != 0)                        Line 1430
        {                                                                       
#ifdef CIBAUD                                                                   Line 1432
          /* SunOS 4.1.3 (at least) has the problem that after this sequence,   
             tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2);                 
             sometimes (m1 != m2).  The only difference is in the four bits     
             of the c_cflag field corresponding to the baud rate.  To save      
             Sun users a little confusion, don't report an error if this        
             happens.  But suppress the error only if we haven't tried to       
             set the baud rate explicitly -- otherwise we'd never give an       
             error for a true failure to set the baud rate.  */                 
                                                                                
          new_mode.c_cflag &= (~CIBAUD);                                        Line 1442
          if (speed_was_set || memcmp (&mode, &new_mode, sizeof (mode)) != 0)   Line 1443
#endif                                                                          Line 1444
            {                                                                   
              die (EXIT_FAILURE, 0,                                             Line 1446
                   _("%s: unable to perform all requested operations"),         Line 1447
                   quotef (device_name));                                       Line 1448
#ifdef TESTING                                                                  Line 1449
              {                                                                 
                printf ("new_mode: mode\n");                                    Line 1451
                for (size_t i = 0; i < sizeof (new_mode); i++)                  Line 1452
                  printf ("0x%02x: 0x%02x\n",                                   Line 1453
                          *(((unsigned char *) &new_mode) + i),                 Line 1454
                          *(((unsigned char *) &mode) + i));                    Line 1455
              }                                                                 
#endif                                                                          Line 1457
            }                                                                   
        }                                                                       
    }                                                                           
                                                                                
  return EXIT_SUCCESS;                                                          Line 1462
}                                                                               
                                                                                
/* Return false if not applied because not reversible; otherwise                
   return true.  */                                                             
                                                                                
static bool                                                                     Line 1468
set_mode (struct mode_info const *info, bool reversed, struct termios *mode)    Line 1469
{                                                                               
  tcflag_t *bitsp;                                                              Line 1471
                                                                                
  if (reversed && (info->flags & REV) == 0)                                     Line 1473
    return false;                                                               Line 1474
                                                                                
  bitsp = mode_type_flag (info->type, mode);                                    Line 1476
                                                                                
  if (bitsp == NULL)                                                            Line 1478
    {                                                                           
      /* Combination mode. */                                                   
      if (STREQ (info->name, "evenp") || STREQ (info->name, "parity"))          Line 1481
        {                                                                       
          if (reversed)                                                         Line 1483
            mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;           Line 1484
          else                                                                  Line 1485
            mode->c_cflag = (mode->c_cflag & ~PARODD & ~CSIZE) | PARENB | CS7;  Line 1486
        }                                                                       
      else if (STREQ (info->name, "oddp"))                                      Line 1488
        {                                                                       
          if (reversed)                                                         Line 1490
            mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;           Line 1491
          else                                                                  Line 1492
            mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARODD | PARENB;   Line 1493
        }                                                                       
      else if (STREQ (info->name, "nl"))                                        Line 1495
        {                                                                       
          if (reversed)                                                         Line 1497
            {                                                                   
              mode->c_iflag = (mode->c_iflag | ICRNL) & ~INLCR & ~IGNCR;        Line 1499
              mode->c_oflag = (mode->c_oflag                                    Line 1500
#ifdef ONLCR                                                                    Line 1501
                               | ONLCR                                          Line 1502
#endif                                                                          Line 1503
                )                                                               
#ifdef OCRNL                                                                    Line 1505
                & ~OCRNL                                                        Line 1506
#endif                                                                          Line 1507
#ifdef ONLRET                                                                   Line 1508
                & ~ONLRET                                                       Line 1509
#endif                                                                          Line 1510
                ;                                                               
            }                                                                   
          else                                                                  Line 1513
            {                                                                   
              mode->c_iflag = mode->c_iflag & ~ICRNL;                           Line 1515
#ifdef ONLCR                                                                    Line 1516
              mode->c_oflag = mode->c_oflag & ~ONLCR;                           Line 1517
#endif                                                                          Line 1518
            }                                                                   
        }                                                                       
      else if (STREQ (info->name, "ek"))                                        Line 1521
        {                                                                       
          mode->c_cc[VERASE] = CERASE;                                          Line 1523
          mode->c_cc[VKILL] = CKILL;                                            Line 1524
        }                                                                       
      else if (STREQ (info->name, "sane"))                                      Line 1526
        sane_mode (mode);                                                       Line 1527
      else if (STREQ (info->name, "cbreak"))                                    Line 1528
        {                                                                       
          if (reversed)                                                         Line 1530
            mode->c_lflag |= ICANON;                                            Line 1531
          else                                                                  Line 1532
            mode->c_lflag &= ~ICANON;                                           Line 1533
        }                                                                       
      else if (STREQ (info->name, "pass8"))                                     Line 1535
        {                                                                       
          if (reversed)                                                         Line 1537
            {                                                                   
              mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB;          Line 1539
              mode->c_iflag |= ISTRIP;                                          Line 1540
            }                                                                   
          else                                                                  Line 1542
            {                                                                   
              mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;         Line 1544
              mode->c_iflag &= ~ISTRIP;                                         Line 1545
            }                                                                   
        }                                                                       
      else if (STREQ (info->name, "litout"))                                    Line 1548
        {                                                                       
          if (reversed)                                                         Line 1550
            {                                                                   
              mode->c_cflag = (mode->c_cflag & ~CSIZE) | CS7 | PARENB;          Line 1552
              mode->c_iflag |= ISTRIP;                                          Line 1553
              mode->c_oflag |= OPOST;                                           Line 1554
            }                                                                   
          else                                                                  Line 1556
            {                                                                   
              mode->c_cflag = (mode->c_cflag & ~PARENB & ~CSIZE) | CS8;         Line 1558
              mode->c_iflag &= ~ISTRIP;                                         Line 1559
              mode->c_oflag &= ~OPOST;                                          Line 1560
            }                                                                   
        }                                                                       
      else if (STREQ (info->name, "raw") || STREQ (info->name, "cooked"))       Line 1563
        {                                                                       
          if ((info->name[0] == 'r' && reversed)                                Line 1565
              || (info->name[0] == 'c' && !reversed))                           Line 1566
            {                                                                   
              /* Cooked mode. */                                                
              mode->c_iflag |= BRKINT | IGNPAR | ISTRIP | ICRNL | IXON;         Line 1569
              mode->c_oflag |= OPOST;                                           Line 1570
              mode->c_lflag |= ISIG | ICANON;                                   Line 1571
#if VMIN == VEOF                                                                Line 1572
              mode->c_cc[VEOF] = CEOF;                                          Line 1573
#endif                                                                          Line 1574
#if VTIME == VEOL                                                               Line 1575
              mode->c_cc[VEOL] = CEOL;                                          Line 1576
#endif                                                                          Line 1577
            }                                                                   
          else                                                                  Line 1579
            {                                                                   
              /* Raw mode. */                                                   
              mode->c_iflag = 0;                                                Line 1582
              mode->c_oflag &= ~OPOST;                                          Line 1583
              mode->c_lflag &= ~(ISIG | ICANON                                  Line 1584
#ifdef XCASE                                                                    Line 1585
                                 | XCASE                                        Line 1586
#endif                                                                          Line 1587
                );                                                              
              mode->c_cc[VMIN] = 1;                                             Line 1589
              mode->c_cc[VTIME] = 0;                                            Line 1590
            }                                                                   
        }                                                                       
#ifdef IXANY                                                                    Line 1593
      else if (STREQ (info->name, "decctlq"))                                   Line 1594
        {                                                                       
          if (reversed)                                                         Line 1596
            mode->c_iflag |= IXANY;                                             Line 1597
          else                                                                  Line 1598
            mode->c_iflag &= ~IXANY;                                            Line 1599
        }                                                                       
#endif                                                                          Line 1601
#ifdef TABDLY                                                                   Line 1602
      else if (STREQ (info->name, "tabs"))                                      Line 1603
        {                                                                       
          if (reversed)                                                         Line 1605
            mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB3;                   Line 1606
          else                                                                  Line 1607
            mode->c_oflag = (mode->c_oflag & ~TABDLY) | TAB0;                   Line 1608
        }                                                                       
#else                                                                           Line 1610
# ifdef OXTABS                                                                  Line 1611
      else if (STREQ (info->name, "tabs"))                                      Line 1612
        {                                                                       
          if (reversed)                                                         Line 1614
            mode->c_oflag = mode->c_oflag | OXTABS;                             Line 1615
          else                                                                  Line 1616
            mode->c_oflag = mode->c_oflag & ~OXTABS;                            Line 1617
        }                                                                       
# endif                                                                         Line 1619
#endif                                                                          Line 1620
#if defined XCASE && defined IUCLC && defined OLCUC                             Line 1621
      else if (STREQ (info->name, "lcase")                                      Line 1622
               || STREQ (info->name, "LCASE"))                                  Line 1623
        {                                                                       
          if (reversed)                                                         Line 1625
            {                                                                   
              mode->c_lflag &= ~XCASE;                                          Line 1627
              mode->c_iflag &= ~IUCLC;                                          Line 1628
              mode->c_oflag &= ~OLCUC;                                          Line 1629
            }                                                                   
          else                                                                  Line 1631
            {                                                                   
              mode->c_lflag |= XCASE;                                           Line 1633
              mode->c_iflag |= IUCLC;                                           Line 1634
              mode->c_oflag |= OLCUC;                                           Line 1635
            }                                                                   
        }                                                                       
#endif                                                                          Line 1638
      else if (STREQ (info->name, "crt"))                                       Line 1639
        mode->c_lflag |= ECHOE                                                  Line 1640
#ifdef ECHOCTL                                                                  Line 1641
          | ECHOCTL                                                             Line 1642
#endif                                                                          Line 1643
#ifdef ECHOKE                                                                   Line 1644
          | ECHOKE                                                              Line 1645
#endif                                                                          Line 1646
          ;                                                                     
      else if (STREQ (info->name, "dec"))                                       Line 1648
        {                                                                       
          mode->c_cc[VINTR] = 3; /* ^C */                                       Line 1650
          mode->c_cc[VERASE] = 127; /* DEL */                                   Line 1651
          mode->c_cc[VKILL] = 21; /* ^U */                                      Line 1652
          mode->c_lflag |= ECHOE                                                Line 1653
#ifdef ECHOCTL                                                                  Line 1654
            | ECHOCTL                                                           Line 1655
#endif                                                                          Line 1656
#ifdef ECHOKE                                                                   Line 1657
            | ECHOKE                                                            Line 1658
#endif                                                                          Line 1659
            ;                                                                   
#ifdef IXANY                                                                    Line 1661
          mode->c_iflag &= ~IXANY;                                              Line 1662
#endif                                                                          Line 1663
        }                                                                       
    }                                                                           
  else if (reversed)                                                            Line 1666
    *bitsp = *bitsp & ~info->mask & ~info->bits;                                Line 1667
  else                                                                          Line 1668
    *bitsp = (*bitsp & ~info->mask) | info->bits;                               Line 1669
                                                                                
  return true;                                                                  Line 1671
}                                                                               Block 13
                                                                                
static void                                                                     Line 1674
set_control_char (struct control_info const *info, const char *arg,             Line 1675
                  struct termios *mode)                                         Line 1676
{                                                                               
  unsigned long int value;                                                      Line 1678
                                                                                
  if (STREQ (info->name, "min") || STREQ (info->name, "time"))                  Line 1680
    value = integer_arg (arg, TYPE_MAXIMUM (cc_t));                             Line 1681
  else if (arg[0] == '\0' || arg[1] == '\0')                                    Line 1682
    value = to_uchar (arg[0]);                                                  Line 1683
  else if (STREQ (arg, "^-") || STREQ (arg, "undef"))                           Line 1684
    value = _POSIX_VDISABLE;                                                    Line 1685
  else if (arg[0] == '^' && arg[1] != '\0') /* Ignore any trailing junk. */     Line 1686
    {                                                                           
      if (arg[1] == '?')                                                        Line 1688
        value = 127;                                                            Line 1689
      else                                                                      Line 1690
        value = to_uchar (arg[1]) & ~0140; /* Non-letters get weird results. */ Line 1691
    }                                                                           
  else                                                                          Line 1693
    value = integer_arg (arg, TYPE_MAXIMUM (cc_t));                             Line 1694
  mode->c_cc[info->offset] = value;                                             Line 1695
}                                                                               Block 14
                                                                                
static void                                                                     Line 1698
set_speed (enum speed_setting type, const char *arg, struct termios *mode)      Line 1699
{                                                                               
  speed_t baud;                                                                 Line 1701
                                                                                
  baud = string_to_baud (arg);                                                  Line 1703
  if (type == input_speed || type == both_speeds)                               Line 1704
    cfsetispeed (mode, baud);                                                   Line 1705
  if (type == output_speed || type == both_speeds)                              Line 1706
    cfsetospeed (mode, baud);                                                   Line 1707
}                                                                               Block 15
                                                                                
#ifdef TIOCGWINSZ                                                               Line 1710
                                                                                
static int                                                                      Line 1712
get_win_size (int fd, struct winsize *win)                                      Line 1713
{                                                                               
  int err = ioctl (fd, TIOCGWINSZ, (char *) win);                               Line 1715...!syscalls auto-comment...
  return err;                                                                   Line 1716
}                                                                               Block 16
                                                                                
static void                                                                     Line 1719
set_window_size (int rows, int cols, char const *device_name)                   Line 1720
{                                                                               
  struct winsize win;                                                           Line 1722
                                                                                
  if (get_win_size (STDIN_FILENO, &win))                                        Line 1724
    {                                                                           
      if (errno != EINVAL)                                                      Line 1726
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1727
      memset (&win, 0, sizeof (win));                                           Line 1728
    }                                                                           
                                                                                
  if (rows >= 0)                                                                Line 1731
    win.ws_row = rows;                                                          Line 1732
  if (cols >= 0)                                                                Line 1733
    win.ws_col = cols;                                                          Line 1734
                                                                                
# ifdef TIOCSSIZE                                                               Line 1736
  /* Alexander Dupuy <dupuy@cs.columbia.edu> wrote:                             
     The following code deals with a bug in the SunOS 4.x (and 3.x?) kernel.    
     This comment from sys/ttold.h describes Sun's twisted logic - a better     
     test would have been (ts_lines > 64k || ts_cols > 64k || ts_cols == 0).    
     At any rate, the problem is gone in Solaris 2.x.                           
                                                                                
     Unfortunately, the old TIOCSSIZE code does collide with TIOCSWINSZ,        
     but they can be disambiguated by checking whether a "struct ttysize"       
     structure's "ts_lines" field is greater than 64K or not.  If so,           
     it's almost certainly a "struct winsize" instead.                          
                                                                                
     At any rate, the bug manifests itself when ws_row == 0; the symptom is     
     that ws_row is set to ws_col, and ws_col is set to (ws_xpixel<<16)         
     + ws_ypixel.  Since GNU stty sets rows and columns separately, this bug    
     caused "stty rows 0 cols 0" to set rows to cols and cols to 0, while       
     "stty cols 0 rows 0" would do the right thing.  On a little-endian         
     machine like the sun386i, the problem is the same, but for ws_col == 0.    
                                                                                
     The workaround is to do the ioctl once with row and col = 1 to set the     
     pixel info, and then do it again using a TIOCSSIZE to set rows/cols.  */   
                                                                                
  if (win.ws_row == 0 || win.ws_col == 0)                                       Line 1758
    {                                                                           
      struct ttysize ttysz;                                                     Line 1760
                                                                                
      ttysz.ts_lines = win.ws_row;                                              Line 1762
      ttysz.ts_cols = win.ws_col;                                               Line 1763
                                                                                
      win.ws_row = 1;                                                           Line 1765
      win.ws_col = 1;                                                           Line 1766
                                                                                
      if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win))                      Line 1768...!syscalls auto-comment...
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1769
                                                                                
      if (ioctl (STDIN_FILENO, TIOCSSIZE, (char *) &ttysz))                     Line 1771...!syscalls auto-comment...
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1772
      return;                                                                   Line 1773
    }                                                                           
# endif                                                                         Line 1775
                                                                                
  if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win))                          Line 1777...!syscalls auto-comment...
    die (EXIT_FAILURE, errno, "%s", quotef (device_name));                      Line 1778
}                                                                               Block 17
                                                                                
static void                                                                     Line 1781
display_window_size (bool fancy, char const *device_name)                       Line 1782
{                                                                               
  struct winsize win;                                                           Line 1784
                                                                                
  if (get_win_size (STDIN_FILENO, &win))                                        Line 1786
    {                                                                           
      if (errno != EINVAL)                                                      Line 1788
        die (EXIT_FAILURE, errno, "%s", quotef (device_name));                  Line 1789
      if (!fancy)                                                               Line 1790
        die (EXIT_FAILURE, 0,                                                   Line 1791
             _("%s: no size information for this device"),                      Line 1792
             quotef (device_name));                                             Line 1793
    }                                                                           
  else                                                                          Line 1795
    {                                                                           
      wrapf (fancy ? "rows %d; columns %d;" : "%d %d\n",                        Line 1797
             win.ws_row, win.ws_col);                                           Line 1798
      if (!fancy)                                                               Line 1799
        current_col = 0;                                                        Line 1800
    }                                                                           
}                                                                               Block 18
#endif                                                                          Line 1803
                                                                                
static int                                                                      Line 1805
screen_columns (void)                                                           Line 1806
{                                                                               
#ifdef TIOCGWINSZ                                                               Line 1808
  struct winsize win;                                                           Line 1809
                                                                                
  /* With Solaris 2.[123], this ioctl fails and errno is set to                 
     EINVAL for telnet (but not rlogin) sessions.                               
     On ISC 3.0, it fails for the console and the serial port                   
     (but it works for ptys).                                                   
     It can also fail on any system when stdout isn't a tty.                    
     In case of any failure, just use the default.  */                          
  if (get_win_size (STDOUT_FILENO, &win) == 0 && 0 < win.ws_col)                Line 1817
    return win.ws_col;                                                          Line 1818
#endif                                                                          Line 1819
  {                                                                             
    /* Use $COLUMNS if it's in [1..INT_MAX].  */                                
    char *col_string = getenv ("COLUMNS");                                      Line 1822
    long int n_columns;                                                         Line 1823
    if (!(col_string != NULL                                                    Line 1824
          && xstrtol (col_string, NULL, 0, &n_columns, "") == LONGINT_OK        Line 1825
          && 0 < n_columns                                                      Line 1826
          && n_columns <= INT_MAX))                                             Line 1827
      n_columns = 80;                                                           Line 1828
    return n_columns;                                                           Line 1829
  }                                                                             
}                                                                               Block 19
                                                                                
static tcflag_t * _GL_ATTRIBUTE_PURE                                            Line 1833
mode_type_flag (enum mode_type type, struct termios *mode)                      Line 1834
{                                                                               
  switch (type)                                                                 Line 1836
    {                                                                           
    case control:                                                               Line 1838
      return &mode->c_cflag;                                                    Line 1839
                                                                                
    case input:                                                                 Line 1841
      return &mode->c_iflag;                                                    Line 1842
                                                                                
    case output:                                                                Line 1844
      return &mode->c_oflag;                                                    Line 1845
                                                                                
    case local:                                                                 Line 1847
      return &mode->c_lflag;                                                    Line 1848
                                                                                
    case combination:                                                           Line 1850
      return NULL;                                                              Line 1851
                                                                                
    default:                                                                    Line 1853
      abort ();                                                                 ...!common auto-comment...
    }                                                                           
}                                                                               Block 20
                                                                                
static void                                                                     Line 1858
display_settings (enum output_type output_type, struct termios *mode,           Line 1859
                  char const *device_name)                                      Line 1860
{                                                                               
  switch (output_type)                                                          Line 1862
    {                                                                           
    case changed:                                                               Line 1864
      display_changed (mode);                                                   Line 1865
      break;                                                                    Line 1866
                                                                                
    case all:                                                                   Line 1868
      display_all (mode, device_name);                                          Line 1869
      break;                                                                    Line 1870
                                                                                
    case recoverable:                                                           Line 1872
      display_recoverable (mode);                                               Line 1873
      break;                                                                    Line 1874
    }                                                                           
}                                                                               Block 21
                                                                                
static void                                                                     Line 1878
display_changed (struct termios *mode)                                          Line 1879
{                                                                               
  int i;                                                                        Line 1881
  bool empty_line;                                                              Line 1882
  tcflag_t *bitsp;                                                              Line 1883
  unsigned long mask;                                                           Line 1884
  enum mode_type prev_type = control;                                           Line 1885
                                                                                
  display_speed (mode, true);                                                   Line 1887
#ifdef HAVE_C_LINE                                                              Line 1888
  wrapf ("line = %d;", mode->c_line);                                           Line 1889
#endif                                                                          Line 1890
  putchar ('\n');                                                               Line 1891
  current_col = 0;                                                              Line 1892
                                                                                
  empty_line = true;                                                            Line 1894
  for (i = 0; !STREQ (control_info[i].name, "min"); ++i)                        Line 1895
    {                                                                           
      if (mode->c_cc[control_info[i].offset] == control_info[i].saneval)        Line 1897
        continue;                                                               Line 1898
                                                                                
#ifdef VFLUSHO                                                                  Line 1900
      /* 'flush' is the deprecated equivalent of 'discard'.  */                 
      if (STREQ (control_info[i].name, "flush"))                                Line 1902
        continue;                                                               Line 1903
#endif                                                                          Line 1904
      /* If swtch is the same as susp, don't print both.  */                    
#if VSWTCH == VSUSP                                                             Line 1906
      if (STREQ (control_info[i].name, "swtch"))                                Line 1907
        continue;                                                               Line 1908
#endif                                                                          Line 1909
      /* If eof uses the same slot as min, only print whichever applies.  */    
#if VEOF == VMIN                                                                Line 1911
      if ((mode->c_lflag & ICANON) == 0                                         Line 1912
          && (STREQ (control_info[i].name, "eof")                               Line 1913
              || STREQ (control_info[i].name, "eol")))                          Line 1914
        continue;                                                               Line 1915
#endif                                                                          Line 1916
                                                                                
      empty_line = false;                                                       Line 1918
      wrapf ("%s = %s;", control_info[i].name,                                  Line 1919
             visible (mode->c_cc[control_info[i].offset]));                     Line 1920
    }                                                                           
  if ((mode->c_lflag & ICANON) == 0)                                            Line 1922
    {                                                                           
      wrapf ("min = %lu; time = %lu;\n",                                        Line 1924
             (unsigned long int) mode->c_cc[VMIN],                              Line 1925
             (unsigned long int) mode->c_cc[VTIME]);                            Line 1926
    }                                                                           
  else if (!empty_line)                                                         Line 1928
    putchar ('\n');                                                             Line 1929
  current_col = 0;                                                              Line 1930
                                                                                
  empty_line = true;                                                            Line 1932
  for (i = 0; mode_info[i].name != NULL; ++i)                                   Line 1933
    {                                                                           
      if (mode_info[i].flags & OMIT)                                            Line 1935
        continue;                                                               Line 1936
      if (mode_info[i].type != prev_type)                                       Line 1937
        {                                                                       
          if (!empty_line)                                                      Line 1939
            {                                                                   
              putchar ('\n');                                                   Line 1941
              current_col = 0;                                                  Line 1942
              empty_line = true;                                                Line 1943
            }                                                                   
          prev_type = mode_info[i].type;                                        Line 1945
        }                                                                       
                                                                                
      bitsp = mode_type_flag (mode_info[i].type, mode);                         Line 1948
      mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;         Line 1949
                                                                                
      /* bitsp would be NULL only for "combination" modes, yet those            
         are filtered out above via the OMIT flag.  Tell static analysis        
         tools that it's ok to dereference bitsp here.  */                      
      assert (bitsp);                                                           Line 1954
                                                                                
      if ((*bitsp & mask) == mode_info[i].bits)                                 Line 1956
        {                                                                       
          if (mode_info[i].flags & SANE_UNSET)                                  Line 1958
            {                                                                   
              wrapf ("%s", mode_info[i].name);                                  Line 1960
              empty_line = false;                                               Line 1961
            }                                                                   
        }                                                                       
      else if ((mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV))     Line 1964
        {                                                                       
          wrapf ("-%s", mode_info[i].name);                                     Line 1966
          empty_line = false;                                                   Line 1967
        }                                                                       
    }                                                                           
  if (!empty_line)                                                              Line 1970
    putchar ('\n');                                                             Line 1971
  current_col = 0;                                                              Line 1972
}                                                                               Block 22
                                                                                
static void                                                                     Line 1975
display_all (struct termios *mode, char const *device_name)                     Line 1976
{                                                                               
  int i;                                                                        Line 1978
  tcflag_t *bitsp;                                                              Line 1979
  unsigned long mask;                                                           Line 1980
  enum mode_type prev_type = control;                                           Line 1981
                                                                                
  display_speed (mode, true);                                                   Line 1983
#ifdef TIOCGWINSZ                                                               Line 1984
  display_window_size (true, device_name);                                      Line 1985
#endif                                                                          Line 1986
#ifdef HAVE_C_LINE                                                              Line 1987
  wrapf ("line = %d;", mode->c_line);                                           Line 1988
#endif                                                                          Line 1989
  putchar ('\n');                                                               Line 1990
  current_col = 0;                                                              Line 1991
                                                                                
  for (i = 0; ! STREQ (control_info[i].name, "min"); ++i)                       Line 1993
    {                                                                           
#ifdef VFLUSHO                                                                  Line 1995
      /* 'flush' is the deprecated equivalent of 'discard'.  */                 
      if (STREQ (control_info[i].name, "flush"))                                Line 1997
        continue;                                                               Line 1998
#endif                                                                          Line 1999
      /* If swtch is the same as susp, don't print both.  */                    
#if VSWTCH == VSUSP                                                             Line 2001
      if (STREQ (control_info[i].name, "swtch"))                                Line 2002
        continue;                                                               Line 2003
#endif                                                                          Line 2004
      /* If eof uses the same slot as min, only print whichever applies.  */    
#if VEOF == VMIN                                                                Line 2006
      if ((mode->c_lflag & ICANON) == 0                                         Line 2007
          && (STREQ (control_info[i].name, "eof")                               Line 2008
              || STREQ (control_info[i].name, "eol")))                          Line 2009
        continue;                                                               Line 2010
#endif                                                                          Line 2011
      wrapf ("%s = %s;", control_info[i].name,                                  Line 2012
             visible (mode->c_cc[control_info[i].offset]));                     Line 2013
    }                                                                           
#if VEOF == VMIN                                                                Line 2015
  if ((mode->c_lflag & ICANON) == 0)                                            Line 2016
#endif                                                                          Line 2017
    wrapf ("min = %lu; time = %lu;",                                            Line 2018
           (unsigned long int) mode->c_cc[VMIN],                                Line 2019
           (unsigned long int) mode->c_cc[VTIME]);                              Line 2020
  if (current_col != 0)                                                         Line 2021
    putchar ('\n');                                                             Line 2022
  current_col = 0;                                                              Line 2023
                                                                                
  for (i = 0; mode_info[i].name != NULL; ++i)                                   Line 2025
    {                                                                           
      if (mode_info[i].flags & OMIT)                                            Line 2027
        continue;                                                               Line 2028
      if (mode_info[i].type != prev_type)                                       Line 2029
        {                                                                       
          putchar ('\n');                                                       Line 2031
          current_col = 0;                                                      Line 2032
          prev_type = mode_info[i].type;                                        Line 2033
        }                                                                       
                                                                                
      bitsp = mode_type_flag (mode_info[i].type, mode);                         Line 2036
      mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits;         Line 2037
      assert (bitsp); /* See the identical assertion and comment above.  */     Line 2038
      if ((*bitsp & mask) == mode_info[i].bits)                                 Line 2039
        wrapf ("%s", mode_info[i].name);                                        Line 2040
      else if (mode_info[i].flags & REV)                                        Line 2041
        wrapf ("-%s", mode_info[i].name);                                       Line 2042
    }                                                                           
  putchar ('\n');                                                               Line 2044
  current_col = 0;                                                              Line 2045
}                                                                               Block 23
                                                                                
static void                                                                     Line 2048
display_speed (struct termios *mode, bool fancy)                                Line 2049
{                                                                               
  if (cfgetispeed (mode) == 0 || cfgetispeed (mode) == cfgetospeed (mode))      Line 2051
    wrapf (fancy ? "speed %lu baud;" : "%lu\n",                                 Line 2052
           baud_to_value (cfgetospeed (mode)));                                 Line 2053
  else                                                                          Line 2054
    wrapf (fancy ? "ispeed %lu baud; ospeed %lu baud;" : "%lu %lu\n",           Line 2055
           baud_to_value (cfgetispeed (mode)),                                  Line 2056
           baud_to_value (cfgetospeed (mode)));                                 Line 2057
  if (!fancy)                                                                   Line 2058
    current_col = 0;                                                            Line 2059
}                                                                               Block 24
                                                                                
static void                                                                     Line 2062
display_recoverable (struct termios *mode)                                      Line 2063
{                                                                               
  printf ("%lx:%lx:%lx:%lx",                                                    Line 2065
          (unsigned long int) mode->c_iflag,                                    Line 2066
          (unsigned long int) mode->c_oflag,                                    Line 2067
          (unsigned long int) mode->c_cflag,                                    Line 2068
          (unsigned long int) mode->c_lflag);                                   Line 2069
  for (size_t i = 0; i < NCCS; ++i)                                             Line 2070
    printf (":%lx", (unsigned long int) mode->c_cc[i]);                         Line 2071
  putchar ('\n');                                                               Line 2072
}                                                                               Block 25
                                                                                
/* NOTE: identical to below, modulo use of tcflag_t */                          
static int                                                                      Line 2076
strtoul_tcflag_t (char const *s, int base, char **p, tcflag_t *result,          Line 2077
                  char delim)                                                   Line 2078
{                                                                               
  unsigned long ul;                                                             Line 2080
  errno = 0;                                                                    Line 2081
  ul = strtoul (s, p, base);                                                    Line 2082
  if (errno || **p != delim || *p == s || (tcflag_t) ul != ul)                  Line 2083
    return -1;                                                                  Line 2084
  *result = ul;                                                                 Line 2085
  return 0;                                                                     Line 2086
}                                                                               Block 26
                                                                                
/* NOTE: identical to above, modulo use of cc_t */                              
static int                                                                      Line 2090
strtoul_cc_t (char const *s, int base, char **p, cc_t *result, char delim)      Line 2091
{                                                                               
  unsigned long ul;                                                             Line 2093
  errno = 0;                                                                    Line 2094
  ul = strtoul (s, p, base);                                                    Line 2095
  if (errno || **p != delim || *p == s || (cc_t) ul != ul)                      Line 2096
    return -1;                                                                  Line 2097
  *result = ul;                                                                 Line 2098
  return 0;                                                                     Line 2099
}                                                                               Block 27
                                                                                
/* Parse the output of display_recoverable.                                     
   Return false if any part of it is invalid.  */                               
static bool                                                                     Line 2104
recover_mode (char const *arg, struct termios *mode)                            Line 2105
{                                                                               
  tcflag_t flag[4];                                                             Line 2107
  char const *s = arg;                                                          Line 2108
  size_t i;                                                                     Line 2109
  for (i = 0; i < 4; i++)                                                       Line 2110
    {                                                                           
      char *p;                                                                  Line 2112
      if (strtoul_tcflag_t (s, 16, &p, flag + i, ':') != 0)                     Line 2113
        return false;                                                           Line 2114
      s = p + 1;                                                                Line 2115
    }                                                                           
  mode->c_iflag = flag[0];                                                      Line 2117
  mode->c_oflag = flag[1];                                                      Line 2118
  mode->c_cflag = flag[2];                                                      Line 2119
  mode->c_lflag = flag[3];                                                      Line 2120
                                                                                
  for (i = 0; i < NCCS; ++i)                                                    Line 2122
    {                                                                           
      char *p;                                                                  Line 2124
      char delim = i < NCCS - 1 ? ':' : '\0';                                   Line 2125
      if (strtoul_cc_t (s, 16, &p, mode->c_cc + i, delim) != 0)                 Line 2126
        return false;                                                           Line 2127
      s = p + 1;                                                                Line 2128
    }                                                                           
                                                                                
  return true;                                                                  Line 2131
}                                                                               Block 28
                                                                                
struct speed_map                                                                Line 2134
{                                                                               
  const char *string;  /* ASCII representation. */                              Line 2136
  speed_t speed;  /* Internal form. */                                          Line 2137
  unsigned long int value; /* Numeric value. */                                 Line 2138
};                                                                              Block 29
                                                                                
static struct speed_map const speeds[] =                                        Line 2141
{                                                                               
  {"0", B0, 0},                                                                 Line 2143
  {"50", B50, 50},                                                              Line 2144
  {"75", B75, 75},                                                              Line 2145
  {"110", B110, 110},                                                           Line 2146
  {"134", B134, 134},                                                           Line 2147
  {"134.5", B134, 134},                                                         Line 2148
  {"150", B150, 150},                                                           Line 2149
  {"200", B200, 200},                                                           Line 2150
  {"300", B300, 300},                                                           Line 2151
  {"600", B600, 600},                                                           Line 2152
  {"1200", B1200, 1200},                                                        Line 2153
  {"1800", B1800, 1800},                                                        Line 2154
  {"2400", B2400, 2400},                                                        Line 2155
  {"4800", B4800, 4800},                                                        Line 2156
  {"9600", B9600, 9600},                                                        Line 2157
  {"19200", B19200, 19200},                                                     Line 2158
  {"38400", B38400, 38400},                                                     Line 2159
  {"exta", B19200, 19200},                                                      Line 2160
  {"extb", B38400, 38400},                                                      Line 2161
#ifdef B57600                                                                   Line 2162
  {"57600", B57600, 57600},                                                     Line 2163
#endif                                                                          Line 2164
#ifdef B115200                                                                  Line 2165
  {"115200", B115200, 115200},                                                  Line 2166
#endif                                                                          Line 2167
#ifdef B230400                                                                  Line 2168
  {"230400", B230400, 230400},                                                  Line 2169
#endif                                                                          Line 2170
#ifdef B460800                                                                  Line 2171
  {"460800", B460800, 460800},                                                  Line 2172
#endif                                                                          Line 2173
#ifdef B500000                                                                  Line 2174
  {"500000", B500000, 500000},                                                  Line 2175
#endif                                                                          Line 2176
#ifdef B576000                                                                  Line 2177
  {"576000", B576000, 576000},                                                  Line 2178
#endif                                                                          Line 2179
#ifdef B921600                                                                  Line 2180
  {"921600", B921600, 921600},                                                  Line 2181
#endif                                                                          Line 2182
#ifdef B1000000                                                                 Line 2183
  {"1000000", B1000000, 1000000},                                               Line 2184
#endif                                                                          Line 2185
#ifdef B1152000                                                                 Line 2186
  {"1152000", B1152000, 1152000},                                               Line 2187
#endif                                                                          Line 2188
#ifdef B1500000                                                                 Line 2189
  {"1500000", B1500000, 1500000},                                               Line 2190
#endif                                                                          Line 2191
#ifdef B2000000                                                                 Line 2192
  {"2000000", B2000000, 2000000},                                               Line 2193
#endif                                                                          Line 2194
#ifdef B2500000                                                                 Line 2195
  {"2500000", B2500000, 2500000},                                               Line 2196
#endif                                                                          Line 2197
#ifdef B3000000                                                                 Line 2198
  {"3000000", B3000000, 3000000},                                               Line 2199
#endif                                                                          Line 2200
#ifdef B3500000                                                                 Line 2201
  {"3500000", B3500000, 3500000},                                               Line 2202
#endif                                                                          Line 2203
#ifdef B4000000                                                                 Line 2204
  {"4000000", B4000000, 4000000},                                               Line 2205
#endif                                                                          Line 2206
  {NULL, 0, 0}                                                                  Line 2207
};                                                                              Block 30
                                                                                
static speed_t _GL_ATTRIBUTE_PURE                                               Line 2210
string_to_baud (const char *arg)                                                Line 2211
{                                                                               
  for (int i = 0; speeds[i].string != NULL; ++i)                                Line 2213
    if (STREQ (arg, speeds[i].string))                                          Line 2214
      return speeds[i].speed;                                                   Line 2215
  return (speed_t) -1;                                                          Line 2216
}                                                                               Block 31
                                                                                
static unsigned long int _GL_ATTRIBUTE_PURE                                     Line 2219
baud_to_value (speed_t speed)                                                   Line 2220
{                                                                               
  for (int i = 0; speeds[i].string != NULL; ++i)                                Line 2222
    if (speed == speeds[i].speed)                                               Line 2223
      return speeds[i].value;                                                   Line 2224
  return 0;                                                                     Line 2225
}                                                                               Block 32
                                                                                
static void                                                                     Line 2228
sane_mode (struct termios *mode)                                                Line 2229
{                                                                               
  int i;                                                                        Line 2231
  tcflag_t *bitsp;                                                              Line 2232
                                                                                
  for (i = 0; control_info[i].name; ++i)                                        Line 2234
    {                                                                           
#if VMIN == VEOF                                                                Line 2236
      if (STREQ (control_info[i].name, "min"))                                  Line 2237
        break;                                                                  Line 2238
#endif                                                                          Line 2239
      mode->c_cc[control_info[i].offset] = control_info[i].saneval;             Line 2240
    }                                                                           
                                                                                
  for (i = 0; mode_info[i].name != NULL; ++i)                                   Line 2243
    {                                                                           
      if (mode_info[i].flags & NO_SETATTR)                                      Line 2245
        continue;                                                               Line 2246
                                                                                
      if (mode_info[i].flags & SANE_SET)                                        Line 2248
        {                                                                       
          bitsp = mode_type_flag (mode_info[i].type, mode);                     Line 2250
          assert (bitsp); /* combination modes will not have SANE_SET.  */      Line 2251
          *bitsp = (*bitsp & ~mode_info[i].mask) | mode_info[i].bits;           Line 2252
        }                                                                       
      else if (mode_info[i].flags & SANE_UNSET)                                 Line 2254
        {                                                                       
          bitsp = mode_type_flag (mode_info[i].type, mode);                     Line 2256
          assert (bitsp); /* combination modes will not have SANE_UNSET.  */    Line 2257
          *bitsp = *bitsp & ~mode_info[i].mask & ~mode_info[i].bits;            Line 2258
        }                                                                       
    }                                                                           
}                                                                               Block 33
                                                                                
/* Return a string that is the printable representation of character CH.  */    
/* Adapted from 'cat' by Torbjorn Granlund.  */                                 
                                                                                
static const char *                                                             Line 2266
visible (cc_t ch)                                                               Line 2267
{                                                                               
  static char buf[10];                                                          Line 2269
  char *bpout = buf;                                                            Line 2270
                                                                                
  if (ch == _POSIX_VDISABLE)                                                    Line 2272
    return "<undef>";                                                           Line 2273
                                                                                
  if (ch >= 32)                                                                 Line 2275
    {                                                                           
      if (ch < 127)                                                             Line 2277
        *bpout++ = ch;                                                          Line 2278
      else if (ch == 127)                                                       Line 2279
        {                                                                       
          *bpout++ = '^';                                                       Line 2281
          *bpout++ = '?';                                                       Line 2282
        }                                                                       
      else                                                                      Line 2284
        {                                                                       
          *bpout++ = 'M';                                                       Line 2286
          *bpout++ = '-';                                                       Line 2287
          if (ch >= 128 + 32)                                                   Line 2288
            {                                                                   
              if (ch < 128 + 127)                                               Line 2290
                *bpout++ = ch - 128;                                            Line 2291
              else                                                              Line 2292
                {                                                               
                  *bpout++ = '^';                                               Line 2294
                  *bpout++ = '?';                                               Line 2295
                }                                                               
            }                                                                   
          else                                                                  Line 2298
            {                                                                   
              *bpout++ = '^';                                                   Line 2300
              *bpout++ = ch - 128 + 64;                                         Line 2301
            }                                                                   
        }                                                                       
    }                                                                           
  else                                                                          Line 2305
    {                                                                           
      *bpout++ = '^';                                                           Line 2307
      *bpout++ = ch + 64;                                                       Line 2308
    }                                                                           
  *bpout = '\0';                                                                Line 2310
  return (const char *) buf;                                                    Line 2311
}                                                                               Block 34
                                                                                
/* Parse string S as an integer, using decimal radix by default,                
   but allowing octal and hex numbers as in C.  Reject values                   
   larger than MAXVAL.  */                                                      
                                                                                
static unsigned long int                                                        Line 2318
integer_arg (const char *s, unsigned long int maxval)                           Line 2319
{                                                                               
  return xnumtoumax (s, 0, 0, maxval, "bB", _("invalid integer argument"), 0);  Line 2321
}                                                                               Block 35