* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)tty.c 5.9 (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
);
int (*old_action
)() = signal(s
, SIG_DFL
);
sigsetmask(sigblock(0) & ~sigmask(s
));