1 /*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7 #ifndef lint
8 char copyright[] =
9 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
10 All rights reserved.\n";
11 #endif not lint
12
13 #ifndef lint
14 static char sccsid[] = "@(#)reset.c 5.2 (Berkeley) 08/13/85";
15 #endif not lint
16
17 /*
18 * reset - restore tty to sensible state after crapping out in raw mode.
19 */
20 #include <sgtty.h>
21
main()22 main()
23 {
24 struct sgttyb buf;
25 struct tchars tbuf;
26 struct ltchars ltbuf;
27 static int lclear = LMDMBUF|LLITOUT|LPASS8;
28
29 ioctl(2, TIOCGETP, &buf);
30 ioctl(2, TIOCGETC, &tbuf);
31 ioctl(2, TIOCGLTC, <buf);
32 buf.sg_flags &= ~(RAW|CBREAK|VTDELAY|ALLDELAY);
33 buf.sg_flags |= XTABS|ECHO|CRMOD|ANYP;
34 reset(&buf.sg_erase, CERASE);
35 reset(&buf.sg_kill, CKILL);
36 reset(&tbuf.t_intrc, CINTR);
37 reset(&tbuf.t_quitc, CQUIT);
38 reset(&tbuf.t_startc, CSTART);
39 reset(&tbuf.t_stopc, CSTOP);
40 reset(&tbuf.t_eofc, CEOF);
41 reset(<buf.t_suspc, CSUSP);
42 reset(<buf.t_dsuspc, CDSUSP);
43 reset(<buf.t_rprntc, CRPRNT);
44 reset(<buf.t_flushc, CFLUSH);
45 reset(<buf.t_lnextc, CLNEXT);
46 reset(<buf.t_werasc, CWERASE);
47 /* brkc is left alone */
48 ioctl(2, TIOCLBIC, &lclear);
49 ioctl(2, TIOCSETN, &buf);
50 ioctl(2, TIOCSETC, &tbuf);
51 ioctl(2, TIOCSLTC, <buf);
52 execlp("tset", "tset", "-Q", "-I", 0); /* fix term dependent stuff */
53 exit(1);
54 }
55
reset(cp,def)56 reset(cp, def)
57 char *cp;
58 int def;
59 {
60
61 if (*cp == 0 || (*cp&0377)==0377)
62 *cp = def;
63 }
64