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