xref: /original-bsd/usr.bin/tset/reset.c (revision f71cd02e)
1 #ifndef lint
2 static	char *sccsid = "@(#)reset.c	4.4 (Berkeley) 07/01/83";
3 #endif
4 /*
5  * reset - restore tty to sensible state after crapping out in raw mode.
6  */
7 #include <sgtty.h>
8 
9 main()
10 {
11 	struct sgttyb buf;
12 	struct tchars tbuf;
13 	struct ltchars ltbuf;
14 
15 	ioctl(2, TIOCGETP, &buf);
16 	ioctl(2, TIOCGETC, &tbuf);
17 	ioctl(2, TIOCGLTC, &ltbuf);
18 	buf.sg_flags &= ~(RAW|CBREAK|VTDELAY|ALLDELAY);
19 	buf.sg_flags |= XTABS|ECHO|CRMOD|ANYP;
20 	reset(&buf.sg_erase, CERASE);
21 	reset(&buf.sg_kill, CKILL);
22 	reset(&tbuf.t_intrc, CINTR);
23 	reset(&tbuf.t_quitc, CQUIT);
24 	reset(&tbuf.t_startc, CSTART);
25 	reset(&tbuf.t_stopc, CSTOP);
26 	reset(&tbuf.t_eofc, CEOF);
27 	reset(&ltbuf.t_suspc, CSUSP);
28 	reset(&ltbuf.t_dsuspc, CDSUSP);
29 	reset(&ltbuf.t_rprntc, CRPRNT);
30 	reset(&ltbuf.t_flushc, CFLUSH);
31 	reset(&ltbuf.t_lnextc, CLNEXT);
32 	reset(&ltbuf.t_werasc, CWERASE);
33 	/* brkc is left alone */
34 	ioctl(2, TIOCSETN, &buf);
35 	ioctl(2, TIOCSETC, &tbuf);
36 	ioctl(2, TIOCSLTC, &ltbuf);
37 	execlp("tset", "tset", "-Q", "-I", 0);	/* fix term dependent stuff */
38 	exit(1);
39 }
40 
41 reset(cp, def)
42 	char *cp;
43 	int def;
44 {
45 
46 	if (*cp == 0 || (*cp&0377)==0377)
47 		*cp = def;
48 }
49