* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)tty.c 5.12 (Berkeley) 4/1/91";
* 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
));