xref: /titanic_41/usr/src/cmd/mailx/tty.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
28*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
29*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
30*7c478bd9Sstevel@tonic-gate  *
31*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
32*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
33*7c478bd9Sstevel@tonic-gate  * contributors.
34*7c478bd9Sstevel@tonic-gate  */
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate  * mailx -- a modified version of a University of California at Berkeley
40*7c478bd9Sstevel@tonic-gate  *	mail program
41*7c478bd9Sstevel@tonic-gate  *
42*7c478bd9Sstevel@tonic-gate  * Generally useful tty stuff.
43*7c478bd9Sstevel@tonic-gate  */
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate #include "rcv.h"
46*7c478bd9Sstevel@tonic-gate #include <locale.h>
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #ifdef	USG_TTY
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static char	*readtty(char pr[], char src[]);
51*7c478bd9Sstevel@tonic-gate static int	savetty(void);
52*7c478bd9Sstevel@tonic-gate static void	ttycont(int);
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate static	int	c_erase;		/* Current erase char */
55*7c478bd9Sstevel@tonic-gate static	int	c_kill;			/* Current kill char */
56*7c478bd9Sstevel@tonic-gate static	int	c_intr;			/* interrupt char */
57*7c478bd9Sstevel@tonic-gate static	int	c_quit;			/* quit character */
58*7c478bd9Sstevel@tonic-gate static	struct termio savtty;
59*7c478bd9Sstevel@tonic-gate static	char canonb[LINESIZE];		/* canonical buffer for input */
60*7c478bd9Sstevel@tonic-gate 					/* processing */
61*7c478bd9Sstevel@tonic-gate 
62*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
63*7c478bd9Sstevel@tonic-gate static void	Echo(int cc);
64*7c478bd9Sstevel@tonic-gate static int	countcol(void);
65*7c478bd9Sstevel@tonic-gate static void	outstr(register char *s);
66*7c478bd9Sstevel@tonic-gate static void	resetty(void);
67*7c478bd9Sstevel@tonic-gate static void	rubout(register char *cp);
68*7c478bd9Sstevel@tonic-gate static int	setty(void);
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate static	int	c_word;			/* Current word erase char */
71*7c478bd9Sstevel@tonic-gate static	int	Col;			/* current output column */
72*7c478bd9Sstevel@tonic-gate static	int	Pcol;			/* end column of prompt string */
73*7c478bd9Sstevel@tonic-gate static	int	Out;			/* file descriptor of stdout */
74*7c478bd9Sstevel@tonic-gate static	int	erasing;		/* we are erasing characters */
75*7c478bd9Sstevel@tonic-gate static	struct termio ttybuf;
76*7c478bd9Sstevel@tonic-gate #else
77*7c478bd9Sstevel@tonic-gate static	jmp_buf	rewrite;		/* Place to go when continued */
78*7c478bd9Sstevel@tonic-gate #endif
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
81*7c478bd9Sstevel@tonic-gate # ifdef preSVr4
82*7c478bd9Sstevel@tonic-gate typedef int	sig_atomic_t;
83*7c478bd9Sstevel@tonic-gate # endif
84*7c478bd9Sstevel@tonic-gate static	sig_atomic_t	hadcont;		/* Saw continue signal */
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
87*7c478bd9Sstevel@tonic-gate static void
88*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
ttycont(int)89*7c478bd9Sstevel@tonic-gate ttycont(int)
90*7c478bd9Sstevel@tonic-gate #else
91*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
92*7c478bd9Sstevel@tonic-gate ttycont(int s)
93*7c478bd9Sstevel@tonic-gate #endif
94*7c478bd9Sstevel@tonic-gate {
95*7c478bd9Sstevel@tonic-gate 	hadcont++;
96*7c478bd9Sstevel@tonic-gate 	longjmp(rewrite, 1);
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate 
99*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
100*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
101*7c478bd9Sstevel@tonic-gate static void
ttystop(int s)102*7c478bd9Sstevel@tonic-gate ttystop(int s)
103*7c478bd9Sstevel@tonic-gate {
104*7c478bd9Sstevel@tonic-gate 	resetty();
105*7c478bd9Sstevel@tonic-gate 	kill(mypid, SIGSTOP);
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate #endif
108*7c478bd9Sstevel@tonic-gate #endif
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate /*
111*7c478bd9Sstevel@tonic-gate  * Read all relevant header fields.
112*7c478bd9Sstevel@tonic-gate  */
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate int
grabh(register struct header * hp,int gflags,int subjtop)115*7c478bd9Sstevel@tonic-gate grabh(register struct header *hp, int gflags, int subjtop)
116*7c478bd9Sstevel@tonic-gate {
117*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
118*7c478bd9Sstevel@tonic-gate 	void (*savecont)(int);
119*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
120*7c478bd9Sstevel@tonic-gate 	void (*savestop)(int);
121*7c478bd9Sstevel@tonic-gate #endif
122*7c478bd9Sstevel@tonic-gate #endif
123*7c478bd9Sstevel@tonic-gate 	if (savetty())
124*7c478bd9Sstevel@tonic-gate 		return -1;
125*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
126*7c478bd9Sstevel@tonic-gate 	savecont = sigset(SIGCONT, ttycont);
127*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
128*7c478bd9Sstevel@tonic-gate 	savestop = sigset(SIGTSTP, ttystop);
129*7c478bd9Sstevel@tonic-gate #endif
130*7c478bd9Sstevel@tonic-gate #endif
131*7c478bd9Sstevel@tonic-gate 	if (gflags & GTO) {
132*7c478bd9Sstevel@tonic-gate 		hp->h_to = addto(NOSTR, readtty("To: ", hp->h_to));
133*7c478bd9Sstevel@tonic-gate 		if (hp->h_to != NOSTR)
134*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
135*7c478bd9Sstevel@tonic-gate 	}
136*7c478bd9Sstevel@tonic-gate 	if (gflags & GSUBJECT && subjtop) {
137*7c478bd9Sstevel@tonic-gate 		hp->h_subject = readtty("Subject: ", hp->h_subject);
138*7c478bd9Sstevel@tonic-gate 		if (hp->h_subject != NOSTR)
139*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
140*7c478bd9Sstevel@tonic-gate 	}
141*7c478bd9Sstevel@tonic-gate 	if (gflags & GCC) {
142*7c478bd9Sstevel@tonic-gate 		hp->h_cc = addto(NOSTR, readtty("Cc: ", hp->h_cc));
143*7c478bd9Sstevel@tonic-gate 		if (hp->h_cc != NOSTR)
144*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
145*7c478bd9Sstevel@tonic-gate 	}
146*7c478bd9Sstevel@tonic-gate 	if (gflags & GBCC) {
147*7c478bd9Sstevel@tonic-gate 		hp->h_bcc = addto(NOSTR, readtty("Bcc: ", hp->h_bcc));
148*7c478bd9Sstevel@tonic-gate 		if (hp->h_bcc != NOSTR)
149*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
150*7c478bd9Sstevel@tonic-gate 	}
151*7c478bd9Sstevel@tonic-gate 	if (gflags & GSUBJECT && !subjtop) {
152*7c478bd9Sstevel@tonic-gate 		hp->h_subject = readtty("Subject: ", hp->h_subject);
153*7c478bd9Sstevel@tonic-gate 		if (hp->h_subject != NOSTR)
154*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
155*7c478bd9Sstevel@tonic-gate 	}
156*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
157*7c478bd9Sstevel@tonic-gate 	(void) sigset(SIGCONT, savecont);
158*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
159*7c478bd9Sstevel@tonic-gate 	(void) sigset(SIGTSTP, savestop);
160*7c478bd9Sstevel@tonic-gate #endif
161*7c478bd9Sstevel@tonic-gate #endif
162*7c478bd9Sstevel@tonic-gate 	return(0);
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  * Read up a header from standard input.
167*7c478bd9Sstevel@tonic-gate  * The source string has the preliminary contents to
168*7c478bd9Sstevel@tonic-gate  * be read.
169*7c478bd9Sstevel@tonic-gate  *
170*7c478bd9Sstevel@tonic-gate  */
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate static char *
readtty(char pr[],char src[])173*7c478bd9Sstevel@tonic-gate readtty(char pr[], char src[])
174*7c478bd9Sstevel@tonic-gate {
175*7c478bd9Sstevel@tonic-gate 	int c;
176*7c478bd9Sstevel@tonic-gate 	register char *cp;
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
179*7c478bd9Sstevel@tonic-gate 	register char *cp2;
180*7c478bd9Sstevel@tonic-gate 
181*7c478bd9Sstevel@tonic-gate 	erasing = 0;
182*7c478bd9Sstevel@tonic-gate 	Col = 0;
183*7c478bd9Sstevel@tonic-gate 	outstr(pr);
184*7c478bd9Sstevel@tonic-gate 	Pcol = Col;
185*7c478bd9Sstevel@tonic-gate #else
186*7c478bd9Sstevel@tonic-gate 	fputs(pr, stdout);
187*7c478bd9Sstevel@tonic-gate #endif
188*7c478bd9Sstevel@tonic-gate 	fflush(stdout);
189*7c478bd9Sstevel@tonic-gate 	if (src != NOSTR && (int)strlen(src) > LINESIZE - 2) {
190*7c478bd9Sstevel@tonic-gate 		printf(gettext("too long to edit\n"));
191*7c478bd9Sstevel@tonic-gate 		return(src);
192*7c478bd9Sstevel@tonic-gate 	}
193*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
194*7c478bd9Sstevel@tonic-gate 	if (setty())
195*7c478bd9Sstevel@tonic-gate 		return(src);
196*7c478bd9Sstevel@tonic-gate 	cp2 = src==NOSTR ? "" : src;
197*7c478bd9Sstevel@tonic-gate 	for (cp=canonb; *cp2; cp++, cp2++)
198*7c478bd9Sstevel@tonic-gate 		*cp = *cp2;
199*7c478bd9Sstevel@tonic-gate 	*cp = '\0';
200*7c478bd9Sstevel@tonic-gate 	outstr(canonb);
201*7c478bd9Sstevel@tonic-gate #else
202*7c478bd9Sstevel@tonic-gate 	cp = src == NOSTR ? "" : src;
203*7c478bd9Sstevel@tonic-gate 	while (c = *cp++) {
204*7c478bd9Sstevel@tonic-gate 		char ch;
205*7c478bd9Sstevel@tonic-gate 
206*7c478bd9Sstevel@tonic-gate 		if (c == c_erase || c == c_kill) {
207*7c478bd9Sstevel@tonic-gate 			ch = '\\';
208*7c478bd9Sstevel@tonic-gate 			ioctl(0, TIOCSTI, &ch);
209*7c478bd9Sstevel@tonic-gate 		}
210*7c478bd9Sstevel@tonic-gate 		ch = c;
211*7c478bd9Sstevel@tonic-gate 		ioctl(0, TIOCSTI, &ch);
212*7c478bd9Sstevel@tonic-gate 	}
213*7c478bd9Sstevel@tonic-gate 	cp = canonb;
214*7c478bd9Sstevel@tonic-gate 	*cp = 0;
215*7c478bd9Sstevel@tonic-gate 	if (setjmp(rewrite))
216*7c478bd9Sstevel@tonic-gate 		goto redo;
217*7c478bd9Sstevel@tonic-gate #endif
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 	for (;;) {
220*7c478bd9Sstevel@tonic-gate 		fflush(stdout);
221*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
222*7c478bd9Sstevel@tonic-gate 		hadcont = 0;
223*7c478bd9Sstevel@tonic-gate #endif
224*7c478bd9Sstevel@tonic-gate 		c = getc(stdin);
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
227*7c478bd9Sstevel@tonic-gate 		if (c==c_erase) {
228*7c478bd9Sstevel@tonic-gate 			if (cp > canonb)
229*7c478bd9Sstevel@tonic-gate 				if (cp[-1]=='\\' && !erasing) {
230*7c478bd9Sstevel@tonic-gate 					*cp++ = (char)c;
231*7c478bd9Sstevel@tonic-gate 					Echo(c);
232*7c478bd9Sstevel@tonic-gate 				} else {
233*7c478bd9Sstevel@tonic-gate 					rubout(--cp);
234*7c478bd9Sstevel@tonic-gate 				}
235*7c478bd9Sstevel@tonic-gate 		} else if (c==c_kill) {
236*7c478bd9Sstevel@tonic-gate 			if (cp > canonb && cp[-1]=='\\') {
237*7c478bd9Sstevel@tonic-gate 				*cp++ = (char)c;
238*7c478bd9Sstevel@tonic-gate 				Echo(c);
239*7c478bd9Sstevel@tonic-gate 			} else while (cp > canonb) {
240*7c478bd9Sstevel@tonic-gate 				rubout(--cp);
241*7c478bd9Sstevel@tonic-gate 			}
242*7c478bd9Sstevel@tonic-gate 		} else if (c==c_word) {
243*7c478bd9Sstevel@tonic-gate 			if (cp > canonb)
244*7c478bd9Sstevel@tonic-gate 				if (cp[-1]=='\\' && !erasing) {
245*7c478bd9Sstevel@tonic-gate 					*cp++ = (char)c;
246*7c478bd9Sstevel@tonic-gate 					Echo(c);
247*7c478bd9Sstevel@tonic-gate 				} else {
248*7c478bd9Sstevel@tonic-gate 					while (--cp >= canonb)
249*7c478bd9Sstevel@tonic-gate 						if (!isspace(*cp))
250*7c478bd9Sstevel@tonic-gate 							break;
251*7c478bd9Sstevel@tonic-gate 						else
252*7c478bd9Sstevel@tonic-gate 							rubout(cp);
253*7c478bd9Sstevel@tonic-gate 					while (cp >= canonb)
254*7c478bd9Sstevel@tonic-gate 						if (!isspace(*cp))
255*7c478bd9Sstevel@tonic-gate 							rubout(cp--);
256*7c478bd9Sstevel@tonic-gate 						else
257*7c478bd9Sstevel@tonic-gate 							break;
258*7c478bd9Sstevel@tonic-gate 					if (cp < canonb)
259*7c478bd9Sstevel@tonic-gate 						cp = canonb;
260*7c478bd9Sstevel@tonic-gate 					else if (*cp)
261*7c478bd9Sstevel@tonic-gate 						cp++;
262*7c478bd9Sstevel@tonic-gate 				}
263*7c478bd9Sstevel@tonic-gate 		} else
264*7c478bd9Sstevel@tonic-gate #endif
265*7c478bd9Sstevel@tonic-gate 		if (c==EOF || ferror(stdin) || c==c_intr || c==c_quit) {
266*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
267*7c478bd9Sstevel@tonic-gate 			if (hadcont) {
268*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
269*7c478bd9Sstevel@tonic-gate 				(void) setty();
270*7c478bd9Sstevel@tonic-gate 				outstr("(continue)\n");
271*7c478bd9Sstevel@tonic-gate 				Col = 0;
272*7c478bd9Sstevel@tonic-gate 				outstr(pr);
273*7c478bd9Sstevel@tonic-gate 				*cp = '\0';
274*7c478bd9Sstevel@tonic-gate 				outstr(canonb);
275*7c478bd9Sstevel@tonic-gate 				clearerr(stdin);
276*7c478bd9Sstevel@tonic-gate 				continue;
277*7c478bd9Sstevel@tonic-gate #else
278*7c478bd9Sstevel@tonic-gate 			redo:
279*7c478bd9Sstevel@tonic-gate 				hadcont = 0;
280*7c478bd9Sstevel@tonic-gate 				cp = canonb[0] != 0 ? canonb : src;
281*7c478bd9Sstevel@tonic-gate 				clearerr(stdin);
282*7c478bd9Sstevel@tonic-gate 				return(readtty(pr, cp));
283*7c478bd9Sstevel@tonic-gate #endif
284*7c478bd9Sstevel@tonic-gate 			}
285*7c478bd9Sstevel@tonic-gate #endif
286*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
287*7c478bd9Sstevel@tonic-gate 			resetty();
288*7c478bd9Sstevel@tonic-gate #endif
289*7c478bd9Sstevel@tonic-gate 			savedead(c==c_quit? SIGQUIT: SIGINT);
290*7c478bd9Sstevel@tonic-gate 		} else switch (c) {
291*7c478bd9Sstevel@tonic-gate 			case '\n':
292*7c478bd9Sstevel@tonic-gate 			case '\r':
293*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
294*7c478bd9Sstevel@tonic-gate 				resetty();
295*7c478bd9Sstevel@tonic-gate 				putchar('\n');
296*7c478bd9Sstevel@tonic-gate 				fflush(stdout);
297*7c478bd9Sstevel@tonic-gate #endif
298*7c478bd9Sstevel@tonic-gate 				if (canonb[0]=='\0')
299*7c478bd9Sstevel@tonic-gate 					return(NOSTR);
300*7c478bd9Sstevel@tonic-gate 				return(savestr(canonb));
301*7c478bd9Sstevel@tonic-gate 			default:
302*7c478bd9Sstevel@tonic-gate 				*cp++ = (char)c;
303*7c478bd9Sstevel@tonic-gate 				*cp = '\0';
304*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
305*7c478bd9Sstevel@tonic-gate 				erasing = 0;
306*7c478bd9Sstevel@tonic-gate 				Echo(c);
307*7c478bd9Sstevel@tonic-gate #endif
308*7c478bd9Sstevel@tonic-gate 		}
309*7c478bd9Sstevel@tonic-gate 	}
310*7c478bd9Sstevel@tonic-gate }
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate static int
savetty(void)313*7c478bd9Sstevel@tonic-gate savetty(void)
314*7c478bd9Sstevel@tonic-gate {
315*7c478bd9Sstevel@tonic-gate 	if (ioctl(fileno(stdout), TCGETA, &savtty) < 0)
316*7c478bd9Sstevel@tonic-gate 	{	perror("ioctl");
317*7c478bd9Sstevel@tonic-gate 		return(-1);
318*7c478bd9Sstevel@tonic-gate 	}
319*7c478bd9Sstevel@tonic-gate 	c_erase = savtty.c_cc[VERASE];
320*7c478bd9Sstevel@tonic-gate 	c_kill = savtty.c_cc[VKILL];
321*7c478bd9Sstevel@tonic-gate 	c_intr = savtty.c_cc[VINTR];
322*7c478bd9Sstevel@tonic-gate 	c_quit = savtty.c_cc[VQUIT];
323*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
324*7c478bd9Sstevel@tonic-gate 	c_word = 'W' & 037;	/* erase word character */
325*7c478bd9Sstevel@tonic-gate 	Out = fileno(stdout);
326*7c478bd9Sstevel@tonic-gate 	ttybuf = savtty;
327*7c478bd9Sstevel@tonic-gate #ifdef	u370
328*7c478bd9Sstevel@tonic-gate 	ttybuf.c_cflag &= ~PARENB;	/* disable parity */
329*7c478bd9Sstevel@tonic-gate 	ttybuf.c_cflag |= CS8;		/* character size = 8 */
330*7c478bd9Sstevel@tonic-gate #endif	/* u370 */
331*7c478bd9Sstevel@tonic-gate 	ttybuf.c_cc[VTIME] = 0;
332*7c478bd9Sstevel@tonic-gate 	ttybuf.c_cc[VMIN] = 1;
333*7c478bd9Sstevel@tonic-gate 	ttybuf.c_iflag &= ~(BRKINT);
334*7c478bd9Sstevel@tonic-gate 	ttybuf.c_lflag &= ~(ICANON|ISIG|ECHO);
335*7c478bd9Sstevel@tonic-gate #endif
336*7c478bd9Sstevel@tonic-gate 	return 0;
337*7c478bd9Sstevel@tonic-gate }
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
340*7c478bd9Sstevel@tonic-gate static int
setty(void)341*7c478bd9Sstevel@tonic-gate setty(void)
342*7c478bd9Sstevel@tonic-gate {
343*7c478bd9Sstevel@tonic-gate 	if (ioctl(Out, TCSETAW, &ttybuf) < 0) {
344*7c478bd9Sstevel@tonic-gate 		perror("ioctl");
345*7c478bd9Sstevel@tonic-gate 		return(-1);
346*7c478bd9Sstevel@tonic-gate 	}
347*7c478bd9Sstevel@tonic-gate 	return(0);
348*7c478bd9Sstevel@tonic-gate }
349*7c478bd9Sstevel@tonic-gate 
350*7c478bd9Sstevel@tonic-gate static void
resetty(void)351*7c478bd9Sstevel@tonic-gate resetty(void)
352*7c478bd9Sstevel@tonic-gate {
353*7c478bd9Sstevel@tonic-gate 	if (ioctl(Out, TCSETAW, &savtty) < 0)
354*7c478bd9Sstevel@tonic-gate 		perror("ioctl");
355*7c478bd9Sstevel@tonic-gate }
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate static void
outstr(register char * s)358*7c478bd9Sstevel@tonic-gate outstr(register char *s)
359*7c478bd9Sstevel@tonic-gate {
360*7c478bd9Sstevel@tonic-gate 	while (*s)
361*7c478bd9Sstevel@tonic-gate 		Echo(*s++);
362*7c478bd9Sstevel@tonic-gate }
363*7c478bd9Sstevel@tonic-gate 
364*7c478bd9Sstevel@tonic-gate static void
rubout(register char * cp)365*7c478bd9Sstevel@tonic-gate rubout(register char *cp)
366*7c478bd9Sstevel@tonic-gate {
367*7c478bd9Sstevel@tonic-gate 	register int oldcol;
368*7c478bd9Sstevel@tonic-gate 	register int c = *cp;
369*7c478bd9Sstevel@tonic-gate 
370*7c478bd9Sstevel@tonic-gate 	erasing = 1;
371*7c478bd9Sstevel@tonic-gate 	*cp = '\0';
372*7c478bd9Sstevel@tonic-gate 	switch (c) {
373*7c478bd9Sstevel@tonic-gate 	case '\t':
374*7c478bd9Sstevel@tonic-gate 		oldcol = countcol();
375*7c478bd9Sstevel@tonic-gate 		do
376*7c478bd9Sstevel@tonic-gate 			putchar('\b');
377*7c478bd9Sstevel@tonic-gate 		while (--Col > oldcol);
378*7c478bd9Sstevel@tonic-gate 		break;
379*7c478bd9Sstevel@tonic-gate 	case '\b':
380*7c478bd9Sstevel@tonic-gate 		if (isprint(cp[-1]))
381*7c478bd9Sstevel@tonic-gate 			putchar(*(cp-1));
382*7c478bd9Sstevel@tonic-gate 		else
383*7c478bd9Sstevel@tonic-gate 			putchar(' ');
384*7c478bd9Sstevel@tonic-gate 		Col++;
385*7c478bd9Sstevel@tonic-gate 		break;
386*7c478bd9Sstevel@tonic-gate 	default:
387*7c478bd9Sstevel@tonic-gate 		if (isprint(c)) {
388*7c478bd9Sstevel@tonic-gate 			fputs("\b \b", stdout);
389*7c478bd9Sstevel@tonic-gate 			Col--;
390*7c478bd9Sstevel@tonic-gate 		}
391*7c478bd9Sstevel@tonic-gate 	}
392*7c478bd9Sstevel@tonic-gate }
393*7c478bd9Sstevel@tonic-gate 
394*7c478bd9Sstevel@tonic-gate static int
countcol(void)395*7c478bd9Sstevel@tonic-gate countcol(void)
396*7c478bd9Sstevel@tonic-gate {
397*7c478bd9Sstevel@tonic-gate 	register int col;
398*7c478bd9Sstevel@tonic-gate 	register char *s;
399*7c478bd9Sstevel@tonic-gate 
400*7c478bd9Sstevel@tonic-gate 	for (col=Pcol, s=canonb; *s; s++)
401*7c478bd9Sstevel@tonic-gate 		switch (*s) {
402*7c478bd9Sstevel@tonic-gate 		case '\t':
403*7c478bd9Sstevel@tonic-gate 			while (++col % 8)
404*7c478bd9Sstevel@tonic-gate 				;
405*7c478bd9Sstevel@tonic-gate 			break;
406*7c478bd9Sstevel@tonic-gate 		case '\b':
407*7c478bd9Sstevel@tonic-gate 			col--;
408*7c478bd9Sstevel@tonic-gate 			break;
409*7c478bd9Sstevel@tonic-gate 		default:
410*7c478bd9Sstevel@tonic-gate 			if (isprint(*s))
411*7c478bd9Sstevel@tonic-gate 				col++;
412*7c478bd9Sstevel@tonic-gate 		}
413*7c478bd9Sstevel@tonic-gate 	return(col);
414*7c478bd9Sstevel@tonic-gate }
415*7c478bd9Sstevel@tonic-gate 
416*7c478bd9Sstevel@tonic-gate static void
Echo(int cc)417*7c478bd9Sstevel@tonic-gate Echo(int cc)
418*7c478bd9Sstevel@tonic-gate {
419*7c478bd9Sstevel@tonic-gate 	char c = (char)cc;
420*7c478bd9Sstevel@tonic-gate 
421*7c478bd9Sstevel@tonic-gate 	switch (c) {
422*7c478bd9Sstevel@tonic-gate 	case '\t':
423*7c478bd9Sstevel@tonic-gate 		do
424*7c478bd9Sstevel@tonic-gate 			putchar(' ');
425*7c478bd9Sstevel@tonic-gate 		while (++Col % 8);
426*7c478bd9Sstevel@tonic-gate 		break;
427*7c478bd9Sstevel@tonic-gate 	case '\b':
428*7c478bd9Sstevel@tonic-gate 		if (Col > 0) {
429*7c478bd9Sstevel@tonic-gate 			putchar('\b');
430*7c478bd9Sstevel@tonic-gate 			Col--;
431*7c478bd9Sstevel@tonic-gate 		}
432*7c478bd9Sstevel@tonic-gate 		break;
433*7c478bd9Sstevel@tonic-gate 	case '\r':
434*7c478bd9Sstevel@tonic-gate 	case '\n':
435*7c478bd9Sstevel@tonic-gate 		Col = 0;
436*7c478bd9Sstevel@tonic-gate 		fputs("\r\n", stdout);
437*7c478bd9Sstevel@tonic-gate 		break;
438*7c478bd9Sstevel@tonic-gate 	default:
439*7c478bd9Sstevel@tonic-gate 		if (isprint(c)) {
440*7c478bd9Sstevel@tonic-gate 			Col++;
441*7c478bd9Sstevel@tonic-gate 			putchar(c);
442*7c478bd9Sstevel@tonic-gate 		}
443*7c478bd9Sstevel@tonic-gate 	}
444*7c478bd9Sstevel@tonic-gate }
445*7c478bd9Sstevel@tonic-gate #endif
446*7c478bd9Sstevel@tonic-gate 
447*7c478bd9Sstevel@tonic-gate #else
448*7c478bd9Sstevel@tonic-gate 
449*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
450*7c478bd9Sstevel@tonic-gate static void	signull(int);
451*7c478bd9Sstevel@tonic-gate #endif
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate static	int	c_erase;		/* Current erase char */
454*7c478bd9Sstevel@tonic-gate static	int	c_kill;			/* Current kill char */
455*7c478bd9Sstevel@tonic-gate static	int	hadcont;		/* Saw continue signal */
456*7c478bd9Sstevel@tonic-gate static	jmp_buf	rewrite;		/* Place to go when continued */
457*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
458*7c478bd9Sstevel@tonic-gate static	int	ttyset;			/* We must now do erase/kill */
459*7c478bd9Sstevel@tonic-gate #endif
460*7c478bd9Sstevel@tonic-gate 
461*7c478bd9Sstevel@tonic-gate /*
462*7c478bd9Sstevel@tonic-gate  * Read all relevant header fields.
463*7c478bd9Sstevel@tonic-gate  */
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate int
grabh(struct header * hp,int gflags,int subjtop)466*7c478bd9Sstevel@tonic-gate grabh(struct header *hp, int gflags, int subjtop)
467*7c478bd9Sstevel@tonic-gate {
468*7c478bd9Sstevel@tonic-gate 	struct sgttyb ttybuf;
469*7c478bd9Sstevel@tonic-gate 	void (*savecont)(int);
470*7c478bd9Sstevel@tonic-gate 	register int s;
471*7c478bd9Sstevel@tonic-gate 	int errs;
472*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
473*7c478bd9Sstevel@tonic-gate 	void (*savesigs[2])(int);
474*7c478bd9Sstevel@tonic-gate #endif
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
477*7c478bd9Sstevel@tonic-gate 	savecont = sigset(SIGCONT, signull);
478*7c478bd9Sstevel@tonic-gate #endif
479*7c478bd9Sstevel@tonic-gate 	errs = 0;
480*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
481*7c478bd9Sstevel@tonic-gate 	ttyset = 0;
482*7c478bd9Sstevel@tonic-gate #endif
483*7c478bd9Sstevel@tonic-gate 	if (gtty(fileno(stdin), &ttybuf) < 0) {
484*7c478bd9Sstevel@tonic-gate 		perror("gtty");
485*7c478bd9Sstevel@tonic-gate 		return(-1);
486*7c478bd9Sstevel@tonic-gate 	}
487*7c478bd9Sstevel@tonic-gate 	c_erase = ttybuf.sg_erase;
488*7c478bd9Sstevel@tonic-gate 	c_kill = ttybuf.sg_kill;
489*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
490*7c478bd9Sstevel@tonic-gate 	ttybuf.sg_erase = 0;
491*7c478bd9Sstevel@tonic-gate 	ttybuf.sg_kill = 0;
492*7c478bd9Sstevel@tonic-gate 	for (s = SIGINT; s <= SIGQUIT; s++)
493*7c478bd9Sstevel@tonic-gate 		if ((savesigs[s-SIGINT] = sigset(s, SIG_IGN)) == SIG_DFL)
494*7c478bd9Sstevel@tonic-gate 			sigset(s, SIG_DFL);
495*7c478bd9Sstevel@tonic-gate #endif
496*7c478bd9Sstevel@tonic-gate 	if (gflags & GTO) {
497*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
498*7c478bd9Sstevel@tonic-gate 		if (!ttyset && hp->h_to != NOSTR)
499*7c478bd9Sstevel@tonic-gate 			ttyset++, stty(fileno(stdin), &ttybuf);
500*7c478bd9Sstevel@tonic-gate #endif
501*7c478bd9Sstevel@tonic-gate 		hp->h_to = addto(NOSTR, readtty("To: ", hp->h_to));
502*7c478bd9Sstevel@tonic-gate 		if (hp->h_to != NOSTR)
503*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
504*7c478bd9Sstevel@tonic-gate 	}
505*7c478bd9Sstevel@tonic-gate 	if (gflags & GSUBJECT && subjtop) {
506*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
507*7c478bd9Sstevel@tonic-gate 		if (!ttyset && hp->h_subject != NOSTR)
508*7c478bd9Sstevel@tonic-gate 			ttyset++, stty(fileno(stdin), &ttybuf);
509*7c478bd9Sstevel@tonic-gate #endif
510*7c478bd9Sstevel@tonic-gate 		hp->h_subject = readtty("Subject: ", hp->h_subject);
511*7c478bd9Sstevel@tonic-gate 		if (hp->h_subject != NOSTR)
512*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
513*7c478bd9Sstevel@tonic-gate 	}
514*7c478bd9Sstevel@tonic-gate 	if (gflags & GCC) {
515*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
516*7c478bd9Sstevel@tonic-gate 		if (!ttyset && hp->h_cc != NOSTR)
517*7c478bd9Sstevel@tonic-gate 			ttyset++, stty(fileno(stdin), &ttybuf);
518*7c478bd9Sstevel@tonic-gate #endif
519*7c478bd9Sstevel@tonic-gate 		hp->h_cc = addto(NOSTR, readtty("Cc: ", hp->h_cc));
520*7c478bd9Sstevel@tonic-gate 		if (hp->h_cc != NOSTR)
521*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
522*7c478bd9Sstevel@tonic-gate 	}
523*7c478bd9Sstevel@tonic-gate 	if (gflags & GBCC) {
524*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
525*7c478bd9Sstevel@tonic-gate 		if (!ttyset && hp->h_bcc != NOSTR)
526*7c478bd9Sstevel@tonic-gate 			ttyset++, stty(fileno(stdin), &ttybuf);
527*7c478bd9Sstevel@tonic-gate #endif
528*7c478bd9Sstevel@tonic-gate 		hp->h_bcc = addto(NOSTR, readtty("Bcc: ", hp->h_bcc));
529*7c478bd9Sstevel@tonic-gate 		if (hp->h_bcc != NOSTR)
530*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
531*7c478bd9Sstevel@tonic-gate 	}
532*7c478bd9Sstevel@tonic-gate 	if (gflags & GSUBJECT && !subjtop) {
533*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
534*7c478bd9Sstevel@tonic-gate 		if (!ttyset && hp->h_subject != NOSTR)
535*7c478bd9Sstevel@tonic-gate 			ttyset++, stty(fileno(stdin), &ttybuf);
536*7c478bd9Sstevel@tonic-gate #endif
537*7c478bd9Sstevel@tonic-gate 		hp->h_subject = readtty("Subject: ", hp->h_subject);
538*7c478bd9Sstevel@tonic-gate 		if (hp->h_subject != NOSTR)
539*7c478bd9Sstevel@tonic-gate 			hp->h_seq++;
540*7c478bd9Sstevel@tonic-gate 	}
541*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
542*7c478bd9Sstevel@tonic-gate 	sigset(SIGCONT, savecont);
543*7c478bd9Sstevel@tonic-gate #endif
544*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
545*7c478bd9Sstevel@tonic-gate 	ttybuf.sg_erase = c_erase;
546*7c478bd9Sstevel@tonic-gate 	ttybuf.sg_kill = c_kill;
547*7c478bd9Sstevel@tonic-gate 	if (ttyset)
548*7c478bd9Sstevel@tonic-gate 		stty(fileno(stdin), &ttybuf);
549*7c478bd9Sstevel@tonic-gate 	for (s = SIGINT; s <= SIGQUIT; s++)
550*7c478bd9Sstevel@tonic-gate 		sigset(s, savesigs[s-SIGINT]);
551*7c478bd9Sstevel@tonic-gate #endif
552*7c478bd9Sstevel@tonic-gate 	return(errs);
553*7c478bd9Sstevel@tonic-gate }
554*7c478bd9Sstevel@tonic-gate 
555*7c478bd9Sstevel@tonic-gate /*
556*7c478bd9Sstevel@tonic-gate  * Read up a header from standard input.
557*7c478bd9Sstevel@tonic-gate  * The source string has the preliminary contents to
558*7c478bd9Sstevel@tonic-gate  * be read.
559*7c478bd9Sstevel@tonic-gate  *
560*7c478bd9Sstevel@tonic-gate  */
561*7c478bd9Sstevel@tonic-gate 
562*7c478bd9Sstevel@tonic-gate char *
readtty(char pr[],char src[])563*7c478bd9Sstevel@tonic-gate readtty(char pr[], char src[])
564*7c478bd9Sstevel@tonic-gate {
565*7c478bd9Sstevel@tonic-gate 	char ch, canonb[LINESIZE];
566*7c478bd9Sstevel@tonic-gate 	int c;
567*7c478bd9Sstevel@tonic-gate 	register char *cp, *cp2;
568*7c478bd9Sstevel@tonic-gate 
569*7c478bd9Sstevel@tonic-gate 	fputs(pr, stdout);
570*7c478bd9Sstevel@tonic-gate 	fflush(stdout);
571*7c478bd9Sstevel@tonic-gate 	if (src != NOSTR && strlen(src) > LINESIZE - 2) {
572*7c478bd9Sstevel@tonic-gate 		printf(gettext("too long to edit\n"));
573*7c478bd9Sstevel@tonic-gate 		return(src);
574*7c478bd9Sstevel@tonic-gate 	}
575*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
576*7c478bd9Sstevel@tonic-gate 	if (src != NOSTR)
577*7c478bd9Sstevel@tonic-gate 		cp = copy(src, canonb);
578*7c478bd9Sstevel@tonic-gate 	else
579*7c478bd9Sstevel@tonic-gate 		cp = copy("", canonb);
580*7c478bd9Sstevel@tonic-gate 	fputs(canonb, stdout);
581*7c478bd9Sstevel@tonic-gate 	fflush(stdout);
582*7c478bd9Sstevel@tonic-gate #else
583*7c478bd9Sstevel@tonic-gate 	cp = src == NOSTR ? "" : src;
584*7c478bd9Sstevel@tonic-gate 	while (c = *cp++) {
585*7c478bd9Sstevel@tonic-gate 		if (c == c_erase || c == c_kill) {
586*7c478bd9Sstevel@tonic-gate 			ch = '\\';
587*7c478bd9Sstevel@tonic-gate 			ioctl(0, TIOCSTI, &ch);
588*7c478bd9Sstevel@tonic-gate 		}
589*7c478bd9Sstevel@tonic-gate 		ch = c;
590*7c478bd9Sstevel@tonic-gate 		ioctl(0, TIOCSTI, &ch);
591*7c478bd9Sstevel@tonic-gate 	}
592*7c478bd9Sstevel@tonic-gate 	cp = canonb;
593*7c478bd9Sstevel@tonic-gate 	*cp = 0;
594*7c478bd9Sstevel@tonic-gate #endif
595*7c478bd9Sstevel@tonic-gate 	cp2 = cp;
596*7c478bd9Sstevel@tonic-gate 	while (cp2 < canonb + LINESIZE)
597*7c478bd9Sstevel@tonic-gate 		*cp2++ = 0;
598*7c478bd9Sstevel@tonic-gate 	cp2 = cp;
599*7c478bd9Sstevel@tonic-gate 	if (setjmp(rewrite))
600*7c478bd9Sstevel@tonic-gate 		goto redo;
601*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
602*7c478bd9Sstevel@tonic-gate 	sigset(SIGCONT, ttycont);
603*7c478bd9Sstevel@tonic-gate #endif
604*7c478bd9Sstevel@tonic-gate 	clearerr(stdin);
605*7c478bd9Sstevel@tonic-gate 	while (cp2 < canonb + LINESIZE) {
606*7c478bd9Sstevel@tonic-gate 		c = getc(stdin);
607*7c478bd9Sstevel@tonic-gate 		if (c == EOF || c == '\n')
608*7c478bd9Sstevel@tonic-gate 			break;
609*7c478bd9Sstevel@tonic-gate 		*cp2++ = c;
610*7c478bd9Sstevel@tonic-gate 	}
611*7c478bd9Sstevel@tonic-gate 	*cp2 = 0;
612*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
613*7c478bd9Sstevel@tonic-gate 	sigset(SIGCONT, signull);
614*7c478bd9Sstevel@tonic-gate #endif
615*7c478bd9Sstevel@tonic-gate 	if (c == EOF && ferror(stdin) && hadcont) {
616*7c478bd9Sstevel@tonic-gate redo:
617*7c478bd9Sstevel@tonic-gate 		hadcont = 0;
618*7c478bd9Sstevel@tonic-gate 		cp = strlen(canonb) > 0 ? canonb : NOSTR;
619*7c478bd9Sstevel@tonic-gate 		clearerr(stdin);
620*7c478bd9Sstevel@tonic-gate 		return(readtty(pr, cp));
621*7c478bd9Sstevel@tonic-gate 	}
622*7c478bd9Sstevel@tonic-gate 	clearerr(stdin);
623*7c478bd9Sstevel@tonic-gate #ifndef TIOCSTI
624*7c478bd9Sstevel@tonic-gate 	if (cp == NOSTR || *cp == '\0')
625*7c478bd9Sstevel@tonic-gate 		return(src);
626*7c478bd9Sstevel@tonic-gate 	cp2 = cp;
627*7c478bd9Sstevel@tonic-gate 	if (!ttyset)
628*7c478bd9Sstevel@tonic-gate 		return(strlen(canonb) > 0 ? savestr(canonb) : NOSTR);
629*7c478bd9Sstevel@tonic-gate 	while (*cp != '\0') {
630*7c478bd9Sstevel@tonic-gate 		c = *cp++;
631*7c478bd9Sstevel@tonic-gate 		if (c == c_erase) {
632*7c478bd9Sstevel@tonic-gate 			if (cp2 == canonb)
633*7c478bd9Sstevel@tonic-gate 				continue;
634*7c478bd9Sstevel@tonic-gate 			if (cp2[-1] == '\\') {
635*7c478bd9Sstevel@tonic-gate 				cp2[-1] = c;
636*7c478bd9Sstevel@tonic-gate 				continue;
637*7c478bd9Sstevel@tonic-gate 			}
638*7c478bd9Sstevel@tonic-gate 			cp2--;
639*7c478bd9Sstevel@tonic-gate 			continue;
640*7c478bd9Sstevel@tonic-gate 		}
641*7c478bd9Sstevel@tonic-gate 		if (c == c_kill) {
642*7c478bd9Sstevel@tonic-gate 			if (cp2 == canonb)
643*7c478bd9Sstevel@tonic-gate 				continue;
644*7c478bd9Sstevel@tonic-gate 			if (cp2[-1] == '\\') {
645*7c478bd9Sstevel@tonic-gate 				cp2[-1] = c;
646*7c478bd9Sstevel@tonic-gate 				continue;
647*7c478bd9Sstevel@tonic-gate 			}
648*7c478bd9Sstevel@tonic-gate 			cp2 = canonb;
649*7c478bd9Sstevel@tonic-gate 			continue;
650*7c478bd9Sstevel@tonic-gate 		}
651*7c478bd9Sstevel@tonic-gate 		*cp2++ = c;
652*7c478bd9Sstevel@tonic-gate 	}
653*7c478bd9Sstevel@tonic-gate 	*cp2 = '\0';
654*7c478bd9Sstevel@tonic-gate #endif
655*7c478bd9Sstevel@tonic-gate 	if (equal("", canonb))
656*7c478bd9Sstevel@tonic-gate 		return(NOSTR);
657*7c478bd9Sstevel@tonic-gate 	return(savestr(canonb));
658*7c478bd9Sstevel@tonic-gate }
659*7c478bd9Sstevel@tonic-gate 
660*7c478bd9Sstevel@tonic-gate #ifdef SIGCONT
661*7c478bd9Sstevel@tonic-gate /*
662*7c478bd9Sstevel@tonic-gate  * Receipt continuation.
663*7c478bd9Sstevel@tonic-gate  */
664*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
665*7c478bd9Sstevel@tonic-gate void
ttycont(int)666*7c478bd9Sstevel@tonic-gate ttycont(int)
667*7c478bd9Sstevel@tonic-gate {
668*7c478bd9Sstevel@tonic-gate 
669*7c478bd9Sstevel@tonic-gate 	hadcont++;
670*7c478bd9Sstevel@tonic-gate 	longjmp(rewrite, 1);
671*7c478bd9Sstevel@tonic-gate }
672*7c478bd9Sstevel@tonic-gate 
673*7c478bd9Sstevel@tonic-gate /*
674*7c478bd9Sstevel@tonic-gate  * Null routine to allow us to hold SIGCONT
675*7c478bd9Sstevel@tonic-gate  */
676*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/
677*7c478bd9Sstevel@tonic-gate static void
signull(int)678*7c478bd9Sstevel@tonic-gate signull(int)
679*7c478bd9Sstevel@tonic-gate {}
680*7c478bd9Sstevel@tonic-gate #endif
681*7c478bd9Sstevel@tonic-gate #endif	/* USG_TTY */
682