* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
* %sccs.include.redist.c%
static char sccsid
[] = "@(#)tty.c 8.1 (Berkeley) %G%";
* Generally useful tty stuff.
static int c_erase
; /* Current erase char */
static int c_kill
; /* Current kill char */
static jmp_buf rewrite
; /* Place to go when continued */
static jmp_buf intjmp
; /* Place to go when interrupted */
static int ttyset
; /* We must now do erase/kill */
* Read all relevant header fields.
savetstp
= signal(SIGTSTP
, SIG_DFL
);
savettou
= signal(SIGTTOU
, SIG_DFL
);
savettin
= signal(SIGTTIN
, SIG_DFL
);
if (ioctl(fileno(stdin
), TIOCGETP
, &ttybuf
) < 0) {
c_erase
= ttybuf
.sg_erase
;
if ((saveint
= signal(SIGINT
, SIG_IGN
)) == SIG_DFL
)
if ((savequit
= signal(SIGQUIT
, SIG_IGN
)) == SIG_DFL
)
signal(SIGQUIT
, SIG_DFL
);
saveint
= signal(SIGINT
, ttyint
);
if (!ttyset
&& hp
->h_to
!= NIL
)
ttyset
++, stty(fileno(stdin
), &ttybuf
);
extract(readtty("To: ", detract(hp
->h_to
, 0)), GTO
);
if (!ttyset
&& hp
->h_subject
!= NOSTR
)
ttyset
++, stty(fileno(stdin
), &ttybuf
);
hp
->h_subject
= readtty("Subject: ", hp
->h_subject
);
if (!ttyset
&& hp
->h_cc
!= NIL
)
ttyset
++, stty(fileno(stdin
), &ttybuf
);
extract(readtty("Cc: ", detract(hp
->h_cc
, 0)), GCC
);
if (!ttyset
&& hp
->h_bcc
!= NIL
)
ttyset
++, stty(fileno(stdin
), &ttybuf
);
extract(readtty("Bcc: ", detract(hp
->h_bcc
, 0)), GBCC
);
signal(SIGTSTP
, savetstp
);
signal(SIGTTOU
, savettou
);
signal(SIGTTIN
, savettin
);
ttybuf
.sg_erase
= c_erase
;
stty(fileno(stdin
), &ttybuf
);
signal(SIGQUIT
, savequit
);
* Read up a header from standard input.
* The source string has the preliminary contents to
if (src
!= NOSTR
&& strlen(src
) > BUFSIZ
- 2) {
printf("too long to edit\n");
cp
= src
== NOSTR
? "" : src
;
if (c
== c_erase
|| c
== c_kill
) {
while (cp2
< canonb
+ BUFSIZ
)
signal(SIGTSTP
, ttystop
);
signal(SIGTTOU
, ttystop
);
signal(SIGTTIN
, ttystop
);
while (cp2
< canonb
+ BUFSIZ
) {
if (c
== EOF
|| c
== '\n')
signal(SIGTSTP
, SIG_DFL
);
signal(SIGTTOU
, SIG_DFL
);
signal(SIGTTIN
, SIG_DFL
);
if (c
== EOF
&& ferror(stdin
)) {
cp
= strlen(canonb
) > 0 ? canonb
: NOSTR
;
if (cp
== NOSTR
|| *cp
== '\0')
return(strlen(canonb
) > 0 ? savestr(canonb
) : NOSTR
);
sig_t old_action
= signal(s
, SIG_DFL
);
sigsetmask(sigblock(0) & ~sigmask(s
));