home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gnu
/
sh-utils-1.12-src.lha
/
sh-utils-1.12
/
src
/
stty.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-12
|
44KB
|
1,710 lines
/* stty -- change and print terminal line settings
Copyright (C) 90, 91, 92, 93, 1994 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 2, 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Usage: stty [-ag] [--all] [--save] [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.
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 stdin.
David MacKenzie <djm@gnu.ai.mit.edu> */
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
#include <termios.h>
#ifdef GWINSZ_IN_SYS_IOCTL
#include <sys/ioctl.h>
#endif
#ifdef WINSIZE_IN_PTEM
#include <sys/stream.h>
#include <sys/ptem.h>
#endif
#include <getopt.h>
#ifdef __STDC__
#include <stdarg.h>
#define VA_START(args, lastarg) va_start(args, lastarg)
#else
#include <varargs.h>
#define VA_START(args, lastarg) va_start(args)
#endif
#include "system.h"
#include "version.h"
#include "long-options.h"
#if defined(GWINSZ_BROKEN) /* Such as for SCO UNIX 3.2.2. */
#undef TIOCGWINSZ
#endif
#ifndef _POSIX_VDISABLE
#define _POSIX_VDISABLE ((unsigned char) 0)
#endif
#define Control(c) ((c) & 0x1f)
/* Canonical values for control characters. */
#ifndef CINTR
#define CINTR Control ('c')
#endif
#ifndef CQUIT
#define CQUIT 28
#endif
#ifndef CERASE
#define CERASE 127
#endif
#ifndef CKILL
#define CKILL Control ('u')
#endif
#ifndef CEOF
#define CEOF Control ('d')
#endif
#ifndef CEOL
#define CEOL _POSIX_VDISABLE
#endif
#ifndef CSTART
#define CSTART Control ('q')
#endif
#ifndef CSTOP
#define CSTOP Control ('s')
#endif
#ifndef CSUSP
#define CSUSP Control ('z')
#endif
#if defined(VEOL2) && !defined(CEOL2)
#define CEOL2 _POSIX_VDISABLE
#endif
#if defined(VSWTCH) && !defined(CSWTCH)
#define CSWTCH _POSIX_VDISABLE
#endif
/* SunOS 5.3 loses (^Z doesn't work) if `swtch' is the same as `susp'.
So the default is to disable `swtch.' */
#if defined (__sparc__) && defined (__svr4__)
#undef CSWTCH
#define CSWTCH _POSIX_VDISABLE
#endif
#if defined(VWERSE) && !defined (VWERASE) /* AIX-3.2.5 */
#define VWERASE VWERSE
#endif
#if defined(VDSUSP) && !defined (CDSUSP)
#define CDSUSP Control ('y')
#endif
#if !defined(VREPRINT) && defined(VRPRNT) /* Irix 4.0.5 */
#define VREPRINT VRPRNT
#endif
#if defined(VREPRINT) && !defined(CRPRNT)
#define CRPRNT Control ('r')
#endif
#if defined(VWERASE) && !defined(CWERASE)
#define CWERASE Control ('w')
#endif
#if defined(VLNEXT) && !defined(CLNEXT)
#define CLNEXT Control ('v')
#endif
#if defined(VDISCARD) && !defined(VFLUSHO)
#define VFLUSHO VDISCARD
#endif
#if defined(VFLUSH) && !defined(VFLUSHO) /* Ultrix 4.2 */
#define VFLUSHO VFLUSH
#endif
#if defined(VFLUSHO) && !defined(CFLUSHO)
#define CFLUSHO Control ('o')
#endif
#if defined(VSTATUS) && !defined(CSTATUS)
#define CSTATUS Control ('t')
#endif
static const char *visible ();
static unsigned long baud_to_value ();
static int recover_mode ();
static int screen_columns ();
static int set_mode ();
static long integer_arg ();
static speed_t string_to_baud ();
static tcflag_t *mode_type_flag ();
static void display_all ();
static void display_changed ();
static void display_recoverable ();
static void display_settings ();
static void display_speed ();
static void display_window_size ();
static void sane_mode ();
static void set_control_char ();
static void set_speed ();
static void set_window_size ();
void error ();
/* Which speeds to set. */
enum speed_setting
{
input_speed, output_speed, both_speeds
};
/* What to output and how. */
enum output_type
{
changed, all, recoverable /* Default, -a, -g. */
};
/* Which member(s) of `struct termios' a mode uses. */
enum mode_type
{
control, input, output, local, combination
};
/* Flags for `struct mode_info'. */
#define SANE_SET 1 /* Set in `sane' mode. */
#define SANE_UNSET 2 /* Unset in `sane' mode. */
#define REV 4 /* Can be turned off by prepending `-'. */
#define OMIT 8 /* Don't display value. */
/* Each mode. */
struct mode_info
{
const char *name; /* Name given on command line. */
enum mode_type type; /* Which structure element to change. */
char flags; /* Setting and display options. */
unsigned long bits; /* Bits to set for this mode. */
unsigned long mask; /* Other bits to turn off for this mode. */
};
static struct mode_info mode_info[] =
{
{"parenb", control, REV, PARENB, 0},
{"parodd", control, REV, PARODD, 0},
{"cs5", control, 0, CS5, CSIZE},
{"cs6", control, 0, CS6, CSIZE},
{"cs7", control, 0, CS7, CSIZE},
{"cs8", control, 0, CS8, CSIZE},
{"hupcl", control, REV, HUPCL, 0},
{"hup", control, REV | OMIT, HUPCL, 0},
{"cstopb", control, REV, CSTOPB, 0},
{"cread", control, SANE_SET | REV, CREAD, 0},
{"clocal", control, REV, CLOCAL, 0},
#ifdef CRTSCTS
{"crtscts", control, REV, CRTSCTS, 0},
#endif
{"ignbrk", input, SANE_UNSET | REV, IGNBRK, 0},
{"brkint", input, SANE_SET | REV, BRKINT, 0},
{"ignpar", input, REV, IGNPAR, 0},
{"parmrk", input, REV, PARMRK, 0},
{"inpck", input, REV, INPCK, 0},
{"istrip", input, REV, ISTRIP, 0},
{"inlcr", input, SANE_UNSET | REV, INLCR, 0},
{"igncr", input, SANE_UNSET | REV, IGNCR, 0},
{"icrnl", input, SANE_SET | REV, ICRNL, 0},
{"ixon", input, REV, IXON, 0},
{"ixoff", input, SANE_UNSET | REV, IXOFF, 0},
{"tandem", input, REV | OMIT, IXOFF, 0},
#ifdef IUCLC
{"iuclc", input, SANE_UNSET | REV, IUCLC, 0},
#endif
#ifdef IXANY
{"ixany", input, SANE_UNSET | REV, IXANY, 0},
#endif
#ifdef IMAXBEL
{"imaxbel", input, SANE_SET | REV, IMAXBEL, 0},
#endif
{"opost", output, SANE_SET | REV, OPOST, 0},
#ifdef OLCUC
{"olcuc", output, SANE_UNSET | REV, OLCUC, 0},
#endif
#ifdef OCRNL
{"ocrnl", output, SANE_UNSET | REV, OCRNL, 0},
#endif
#ifdef ONLCR
{"onlcr", output, SANE_SET | REV, ONLCR, 0},
#endif
#ifdef ONOCR
{"onocr", output, SANE_UNSET | REV, ONOCR, 0},
#endif
#ifdef ONLRET
{"onlret", output, SANE_UNSET | REV, ONLRET, 0},
#endif
#ifdef OFILL
{"ofill", output, SANE_UNSET | REV, OFILL, 0},
#endif
#ifdef OFDEL
{"ofdel", output, SANE_UNSET | REV, OFDEL, 0},
#endif
#ifdef NLDLY
{"nl1", output, SANE_UNSET, NL1, NLDLY},
{"nl0", output, SANE_SET, NL0, NLDLY},
#endif
#ifdef CRDLY
{"cr3", output, SANE_UNSET, CR3, CRDLY},
{"cr2", output, SANE_UNSET, CR2, CRDLY},
{"cr1", output, SANE_UNSET, CR1, CRDLY},
{"cr0", output, SANE_SET, CR0, CRDLY},
#endif
#ifdef TABDLY
{"tab3", output, SANE_UNSET, TAB3, TABDLY},
{"tab2", output, SANE_UNSET, TAB2, TABDLY},
{"tab1", output, SANE_UNSET, TAB1, TABDLY},
{"tab0", output, SANE_SET, TAB0, TABDLY},
#else
#ifdef OXTABS
{"tab3", output, SANE_UNSET, OXTABS, 0},
#endif
#endif
#ifdef BSDLY
{"bs1", output, SANE_UNSET, BS1, BSDLY},
{"bs0", output, SANE_SET, BS0, BSDLY},
#endif
#ifdef VTDLY
{"vt1", output, SANE_UNSET, VT1, VTDLY},
{"vt0", output, SANE_SET, VT0, VTDLY},
#endif
#ifdef FFDLY
{"ff1", output, SANE_UNSET, FF1, FFDLY},
{"ff0", output, SANE_SET, FF0, FFDLY},
#endif
{"isig", local, SANE_SET | REV, ISIG, 0},
{"icanon", local, SANE_SET | REV, ICANON, 0},
#ifdef IEXTEN
{"iexten", local, SANE_SET | REV, IEXTEN, 0},
#endif
{"echo", local, SANE_SET | REV, ECHO, 0},
{"echoe", local, SANE_SET | REV, ECHOE, 0},
{"crterase", local, REV | OMIT, ECHOE, 0},
{"echok", local, SANE_SET | REV, ECHOK, 0},
{"echonl", local, SANE_UNSET | REV, ECHONL, 0},
{"noflsh", local, SANE_UNSET | REV, NOFLSH, 0},
#ifdef XCASE
{"xcase", local, SAN