/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* mailx -- a modified version of a University of California at Berkeley
* mail program
*
* Generally useful tty stuff.
*/
#include "rcv.h"
#include <locale.h>
#ifdef USG_TTY
static int savetty(void);
static void ttycont(int);
/* processing */
#ifndef TIOCSTI
static int countcol(void);
static void outstr(register char *s);
static void resetty(void);
static int setty(void);
#else
#endif
#ifdef SIGCONT
# ifdef preSVr4
typedef int sig_atomic_t;
# endif
/*ARGSUSED*/
static void
#ifdef __cplusplus
ttycont(int)
#else
/* ARGSUSED */
ttycont(int s)
#endif
{
hadcont++;
}
#ifndef TIOCSTI
/*ARGSUSED*/
static void
ttystop(int s)
{
resetty();
}
#endif
#endif
/*
* Read all relevant header fields.
*/
int
{
#ifdef SIGCONT
void (*savecont)(int);
#ifndef TIOCSTI
void (*savestop)(int);
#endif
#endif
if (savetty())
return -1;
#ifdef SIGCONT
#ifndef TIOCSTI
#endif
#endif
}
}
}
}
}
#ifdef SIGCONT
#ifndef TIOCSTI
#endif
#endif
return(0);
}
/*
* Read up a header from standard input.
* The source string has the preliminary contents to
* be read.
*
*/
static char *
{
int c;
register char *cp;
#ifndef TIOCSTI
register char *cp2;
erasing = 0;
Col = 0;
#else
#endif
return(src);
}
#ifndef TIOCSTI
if (setty())
return(src);
*cp = '\0';
#else
while (c = *cp++) {
char ch;
ch = '\\';
}
ch = c;
}
*cp = 0;
goto redo;
#endif
for (;;) {
#ifdef SIGCONT
hadcont = 0;
#endif
#ifndef TIOCSTI
if (c==c_erase) {
*cp++ = (char)c;
Echo(c);
} else {
}
} else if (c==c_kill) {
*cp++ = (char)c;
Echo(c);
}
} else if (c==c_word) {
*cp++ = (char)c;
Echo(c);
} else {
break;
else
else
break;
else if (*cp)
cp++;
}
} else
#endif
#ifdef SIGCONT
if (hadcont) {
#ifndef TIOCSTI
(void) setty();
outstr("(continue)\n");
Col = 0;
*cp = '\0';
continue;
#else
redo:
hadcont = 0;
#endif
}
#endif
#ifndef TIOCSTI
resetty();
#endif
} else switch (c) {
case '\n':
case '\r':
#ifndef TIOCSTI
resetty();
putchar('\n');
#endif
if (canonb[0]=='\0')
return(NOSTR);
default:
*cp++ = (char)c;
*cp = '\0';
#ifndef TIOCSTI
erasing = 0;
Echo(c);
#endif
}
}
}
static int
savetty(void)
{
{ perror("ioctl");
return(-1);
}
#ifndef TIOCSTI
#ifdef u370
#endif /* u370 */
#endif
return 0;
}
#ifndef TIOCSTI
static int
setty(void)
{
perror("ioctl");
return(-1);
}
return(0);
}
static void
resetty(void)
{
perror("ioctl");
}
static void
outstr(register char *s)
{
while (*s)
Echo(*s++);
}
static void
{
register int oldcol;
register int c = *cp;
erasing = 1;
*cp = '\0';
switch (c) {
case '\t':
do
putchar('\b');
break;
case '\b':
else
putchar(' ');
Col++;
break;
default:
if (isprint(c)) {
Col--;
}
}
}
static int
countcol(void)
{
register int col;
register char *s;
switch (*s) {
case '\t':
while (++col % 8)
;
break;
case '\b':
col--;
break;
default:
if (isprint(*s))
col++;
}
return(col);
}
static void
{
char c = (char)cc;
switch (c) {
case '\t':
do
putchar(' ');
while (++Col % 8);
break;
case '\b':
if (Col > 0) {
putchar('\b');
Col--;
}
break;
case '\r':
case '\n':
Col = 0;
break;
default:
if (isprint(c)) {
Col++;
putchar(c);
}
}
}
#endif
#else
#ifdef SIGCONT
static void signull(int);
#endif
#ifndef TIOCSTI
#endif
/*
* Read all relevant header fields.
*/
int
{
void (*savecont)(int);
register int s;
int errs;
#ifndef TIOCSTI
void (*savesigs[2])(int);
#endif
#ifdef SIGCONT
#endif
errs = 0;
#ifndef TIOCSTI
ttyset = 0;
#endif
perror("gtty");
return(-1);
}
#ifndef TIOCSTI
#endif
#ifndef TIOCSTI
#endif
}
#ifndef TIOCSTI
#endif
}
#ifndef TIOCSTI
#endif
}
#ifndef TIOCSTI
#endif
}
#ifndef TIOCSTI
#endif
}
#ifdef SIGCONT
#endif
#ifndef TIOCSTI
if (ttyset)
#endif
return(errs);
}
/*
* Read up a header from standard input.
* The source string has the preliminary contents to
* be read.
*
*/
char *
{
int c;
return(src);
}
#ifndef TIOCSTI
else
#else
while (c = *cp++) {
ch = '\\';
}
ch = c;
}
*cp = 0;
#endif
*cp2++ = 0;
goto redo;
#ifdef SIGCONT
#endif
if (c == EOF || c == '\n')
break;
*cp2++ = c;
}
*cp2 = 0;
#ifdef SIGCONT
#endif
redo:
hadcont = 0;
}
#ifndef TIOCSTI
return(src);
if (!ttyset)
while (*cp != '\0') {
c = *cp++;
if (c == c_erase) {
continue;
cp2[-1] = c;
continue;
}
cp2--;
continue;
}
if (c == c_kill) {
continue;
cp2[-1] = c;
continue;
}
continue;
}
*cp2++ = c;
}
*cp2 = '\0';
#endif
return(NOSTR);
}
#ifdef SIGCONT
/*
* Receipt continuation.
*/
/*ARGSUSED*/
void
ttycont(int)
{
hadcont++;
}
/*
* Null routine to allow us to hold SIGCONT
*/
/*ARGSUSED*/
static void
signull(int)
{}
#endif
#endif /* USG_TTY */