stty.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1992-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* stty.c
* Written by David Korn
* Tue Apr 4 10:46:00 EDT 1995
*/
static const char usage[] =
"[-?@(#)$Id: stty (AT&T Research) 2010-04-01 $\n]"
"[+NAME?stty - set or get terminal modes]"
"[+DESCRIPTION?\bstty\b sets certain terminal I/O modes for the device "
"that is the current standard input; without arguments, it writes the "
"settings of certain modes to standard output.]"
"[a:all?Writes to standard output all of the mode settings.]"
"[f|F:fd|file?Use \afd\a as the terminal fd.]#[fd:=0]"
"[g:save?Writes the current settings to standard output in a form that "
"can be used as an argument to another \bstty\b command. The \brows\b "
"and \bcolumns\b values are not included.]"
"[t:terminal-group?Print the terminal group id of the device, -1 if "
"unknown.]"
"\n"
"\n[mode ...]\n"
"\n"
"[+EXTENDED DESCRIPTION?Modes are specified either as a single name or "
"as a name followed by a value. As indicated below, many of the mode "
"names can be preceded by a \b-\b to negate its meaning. Modes are "
"listed by group corresponding to field in the \btermios\b structure "
"defined in \b<termios.h>\b. Modes in the last group are implemented "
"using options in the previous groups. Note that many combinations of "
"modes make no sense, but no sanity checking is performed. The modes are "
"selected from the following:]"
"{\fabc\f}"
"[+EXIT STATUS?]"
"{"
"[+0?All modes reported or set successfully.]"
"[+>0?Standard input not a terminaol or one or more modes "
"failed.]"
"}"
"[+SEE ALSO?\btegetattr\b(2), \btcsetattr\b(2), \bioctl\b(2)]"
;
#include <cmd.h>
#include <ccode.h>
#include <ctype.h>
#include <ast_tty.h>
#if _sys_ioctl
#endif
#define C(x) ERROR_catalog(x)
#ifndef _POSIX_VDISABLE
# define _POSIX_VDISABLE 0
#endif
#ifndef NCCS
# ifdef NCC
# else
# endif
#endif
/* command options */
#define A_FLAG 1
#define G_FLAG 2
#define T_FLAG 4
/* termios fields */
#define C_FLAG 1
#define C_LINE 2
#define C_SPEED 3
#define I_FLAG 4
#define O_FLAG 5
#define L_FLAG 6
#define T_CHAR 7
#define W_SIZE 8
#define BIT 1
#define BITS 2
#define NUM 3
#define CHAR 4
#define SPEED 5
#define SIZE 6
#define MIXED 7
#define SANE 8
#define COOKED 9
#define CASE 10
#define TABS 11
#define WIND 12
typedef struct tty_s
{
const char name[8];
unsigned char type;
unsigned char field;
short flags;
unsigned long mask;
unsigned long val;
const char description[76];
} Tty_t;
{
#ifdef CBAUD
#endif
#ifdef TIOCSWINSZ
#endif
#ifdef VEOL2
#endif /* VEOL2 */
#ifdef VSWTCH
#endif /* VSWTCH */
#ifdef VSTART
#endif /* VSTART */
#ifdef VSTOP
#endif /* VSTOP */
#ifdef VDSUSP
{ "dsusp", CHAR, T_CHAR, SS, VDSUSP, 'Y', C("Send a terminal stop signal after flushing the input") },
#endif /* VDSUSP */
#ifdef VSUSP
#endif /* VSUSP */
#ifdef VREPRINT
#endif /* VREPRINT */
#ifdef VDISCARD
#endif /* VDISCARD */
#ifdef VWERASE
#endif /* VWERASE */
#ifdef VLNEXT
#endif /* VLNEXT */
#endif
{ "parenb", BIT, C_FLAG, 0, PARENB, PARENB, C("Enable (disable) parity generation and detection") },
#ifdef PAREXT
#endif /* PAREXT */
#ifdef CREAD
#endif /* CREAD */
#ifdef CRTSCTS
#endif /* CRTSCTS */
{ "brkint", BIT, I_FLAG, SS, BRKINT, BRKINT, C("Generate (do not generate) INTR signal on break") },
{ "ignpar", BIT, I_FLAG, 0, IGNPAR, IGNPAR, C("Ignore (do not ignore) characters with parity errors") },
{ "istrip", BIT, I_FLAG, 0, ISTRIP, ISTRIP, C("Clear (do not clear) high bit of input characters") },
{ "inlcr", BIT, I_FLAG, US, INLCR, INLCR, C("Translate (do not translate) carriage return to newline") },
#ifdef IUCLC
#endif /* IUCLC */
{ "ixon", BIT, I_FLAG, 0, IXON, IXON, C("Enable (disable) XON/XOFF flow control. \bstop\b character stops output") },
#ifdef IXANY
{ "ixany", BIT, I_FLAG, US, IXANY, IXANY, C("Any character (only start character) can restart output.") },
#endif /* IXANY */
#ifdef IMAXBEL
{ "imaxbel", BIT, I_FLAG, SS, IMAXBEL, IMAXBEL, C("Beep (do not beep) if a character arrives with full input buffer") },
#endif /* IMAXBEL */
{ "icrnl", BIT, I_FLAG, NL|SS, ICRNL, ICRNL, C("Translate (do not translate) carriage return to newline") },
{ "isig", BIT, L_FLAG, SS, ISIG, ISIG, C("Enable (disable) \bintr\b, \bquit\b, and \bsusp\b special characters") },
{ "icanon", BIT, L_FLAG, SS, ICANON, ICANON, C("Enable (disable) \berase\b, \bkill\b, \bwerase\b, and \brprnt\b special characters") },
#ifdef IEXTEN
#endif /* IEXTEN */
{ "echoe", BIT, L_FLAG, SS, ECHOE, ECHOE, C("Echo (do not echo) erase characters as backspace-space-backspace") },
{ "echok", BIT, L_FLAG, SS, ECHOK, ECHOK, C("Echo (do not echo) a newline after a kill character") },
#ifdef ECHOKE
{ "echoke", BIT, L_FLAG, SS, ECHOKE, ECHOKE, C("Echo (do not echo) a newline after a kill character") },
#endif
{ "echonl", BIT, L_FLAG, SS, ECHONL, ECHONL,"Echo (do not echo) newline even if not echoing other character" },
#ifdef ECHOCTL
{ "echoctl", BIT, L_FLAG, SS, ECHOCTL, ECHOCTL, C("Echo (do not echo) control characters as \b^\b\ac\a") },
#else
#define ECHOCTL 0
#endif /* ECHOCTL */
#ifdef ECHOPRT
{ "echoprt", BIT, L_FLAG, US, ECHOPRT, ECHOPRT, C("Echo (do not echo) erased characters backward, between '\\' and '/'") },
#else
#define ECHOPRT 0
#endif /* ECHOPRT */
#ifdef XCASE
{ "xcase", BIT, L_FLAG, US, XCASE, XCASE, C("Enable (disable) \bicanon\b uppercase as lowercase with '\\' prefix") },
#endif /* XCASE */
#ifdef DEFECHO
#endif /* DEFECHO */
#ifdef FLUSHO
{ "flusho", BIT, L_FLAG, 0, FLUSHO, FLUSHO, C("Discard (do not discard) written data. Cleared by subsequent input") },
#endif /* FLUSHO */
#ifdef PENDIN
{ "pendin", BIT, L_FLAG, 0, PENDIN, PENDIN, C("Redisplay pending input at next read and then automatically clear \bpendin\b") },
#endif /* PENDIN */
{ "noflsh", BIT, L_FLAG, US, NOFLSH, NOFLSH, C("Disable (enable) flushing after \bintr\b and \bquit\b special characters") },
#ifdef TOSTOP
{ "tostop", BIT, L_FLAG, NL|US, TOSTOP, TOSTOP, C("Stop (do not stop) background jobs that try to write to the terminal") },
#endif /* TOSTOP */
#ifdef OLCUC
{ "olcuc", BIT, O_FLAG, US, OLCUC, OLCUC, C("Translate (do not translate) lowercase characters to uppercase") },
#endif /* OLCUC */
#ifdef ONLCR
{ "onlcr", BIT, O_FLAG, SS, ONLCR, ONLCR, C("Translate (do not translate) newline to carriage return-newline") },
#endif /* ONLCR */
#ifdef ONLRET
{ "onlret", BIT, O_FLAG, US, ONLRET, ONLRET, C("Newline performs (does not perform) a carriage return") },
#endif /* ONLRET */
#ifdef OCRNL
{ "ocrnl", BIT, O_FLAG, US, OCRNL, OCRNL, C("Translate (do not translate) carriage return to newline") },
#endif /* OCRNL */
#ifdef ONOCR
{ "onocr", BIT, O_FLAG, US, ONOCR, ONOCR, C("Do not (do) print carriage returns in the first column") },
#endif /* ONOCR */
#ifdef OFILL
#endif /* OFILL */
#ifdef OFDEL
#endif /* OFDEL */
#ifdef CRDLY
#endif
#ifdef NLDLY
#endif
#ifdef TABDLY
#ifdef TAB0
#endif
#ifdef TAB1
#endif
#ifdef TAB2
#endif
#endif
#ifdef BSDLY
#endif
#ifdef VTDLY
#endif
#ifdef FFDLY
#endif
{ "ek", MIXED, C_FLAG, IG, 0, 0, C("Reset the \berase\b and \bkill\b special characters to their default values") },
};
#else
#define cntl(x) (((x)=='?')?ccmapc(0177,CC_ASCII,CC_NATIVE):ccmapc(ccmapc(x,CC_NATIVE,CC_ASCII)&037,CC_ASCII,CC_NATIVE))
#endif
{
{
case BIT:
case BITS:
{
case C_FLAG:
else
break;
case I_FLAG:
else
break;
case O_FLAG:
else
break;
case L_FLAG:
else
break;
}
break;
case CHAR:
break;
}
}
{
register int i;
if(*arg++ != ':')
return(0);
if(*arg++ != ':')
return(0);
if(*arg++ != ':')
return(0);
if(*arg++ != ':')
return(0);
if(*arg++ != ':')
return(0);
for(i=0;i< NCCS; i++)
{
if(*arg++ != ':')
return(0);
}
#endif
if(*arg++ != ':')
return(0);
if(*arg++ != ':')
return(0);
cfsetispeed(sp, i);
if(*arg++ != ':')
return(0);
cfsetospeed(sp, i);
if(*arg)
return(0);
return(1);
}
{
register int i;
for(i=0;i< NCCS; i++)
#else
#endif
}
{
register int delim = ' ';
char schar[2];
{
return;
}
for(i=0; i < elementsof(Ttable); i++)
{
{
continue;
}
{
case BIT:
case BITS:
{
case C_FLAG:
off = 0;
off2 = 0;
break;
case I_FLAG:
off = 0;
off2 = 0;
break;
case O_FLAG:
off = 0;
off2 = 0;
break;
case L_FLAG:
off = 0;
off2 = 0;
}
delim = '\n';
continue;
if(!off)
delim = ' ';
break;
case CHAR:
delim = '\n';
continue;
if(off==_POSIX_VDISABLE)
else
#else
{
}
#endif
delim = ' ';
break;
case SIZE:
continue;
break;
case SPEED:
{
schar[0]='i';
else
schar[0]=0;
}
schar[0]='o';
else
continue;
schar[1] = 0;
#ifdef TIOCSWINSZ
{
if(off>=0)
}
if(off<0)
#endif
}
}
if(delim=='\n')
}
{
register int i;
for(i=0; i < elementsof(Ttable); i++)
{
return(&Ttable[i]);
}
return(0);
}
{
register int i;
for(i=0; i < elementsof(Ttable); i++)
{
return(&Ttable[i]);
}
return(0);
}
{
if(*cp==0)
return(-1);
if(cp[1]==0)
return((unsigned)cp[0]);
{
switch(cp[1])
{
case '-':
return(-1);
default:
}
}
return(-1);
return(*((unsigned char*)cp));
}
{
register int c,off;
char *cp;
char *ep;
{
off = 0;
if(*cp=='-')
{
cp++;
off=1;
}
{
case CHAR:
if(off)
if(!*argv)
if(c>=0)
else
break;
{
case C_FLAG:
if(off)
else
break;
case I_FLAG:
if(off)
else
break;
case O_FLAG:
break;
case L_FLAG:
if(off)
else
break;
}
break;
case TABS:
if(off)
break;
#ifdef TIOCSWINSZ
case WIND:
{
int n;
{
break;
}
argv++;
if(*cp)
else
break;
}
#endif
case NUM:
if (!cp)
{
{
break;
}
}
argv++;
if (*ep)
{
case C_LINE:
break;
#endif
case C_SPEED:
if(getspeed(c))
{
cfsetispeed(sp, c);
cfsetospeed(sp, c);
}
else
break;
case T_CHAR:
break;
}
break;
case SPEED:
break;
case SIZE:
break;
case SANE:
break;
case CASE:
if(off)
{
}
else
{
}
break;
#endif /* OLCUC && IUCLC */
}
}
}
{
int i,c;
for(i=0; i < elementsof(Ttable); i++)
{
}
}
{
int i;
for(i=0; i < elementsof(Ttable); i++)
{
}
}
{
int i;
for(i=0; i < elementsof(Ttable); i++)
{
}
}
{
int i;
for(i=0; i < elementsof(Ttable); i++)
{
}
}
{
}
{
NoP(s);
listgroup(sp,SPEED,"Attempt to set input and output baud rate to number given. A value of \b0\b causes immediate hangup");
#ifdef CRDLY
#endif
#ifdef NLDLY
#endif
#ifdef TABDLY
#endif
#ifdef BSDLY
#endif
#ifdef FFDLY
#endif
#ifdef VTDLY
#endif
"string then the control assignment is disabled.]{");
return(1);
}
#ifndef _lib_tcgetpgrp
# ifdef TIOCGPGRP
static int _i_;
# else
# define tcgetpgrp(a) (-1)
# endif /* TIOCGPGRP */
#endif /* _lib_tcgetpgrp */
int
{
register int n;
register int flags = 0;
int fd = 0;
for (;;)
{
{
case 'f':
continue;
case 'a':
case 'g':
case 't':
{
switch (n)
{
case 'a':
break;
case 'g':
break;
case 't':
break;
}
continue;
}
/*FALLTHROUGH*/
case ':':
break;
case '?':
break;
}
break;
}
else if (*argv)
{
else
}
else
return error_info.errors;
}