Commit | Line | Data |
---|---|---|
5528a91e | 1 | #ifndef lint |
3e0824a9 | 2 | static char *sccsid = "@(#)wwinit.c 1.6 83/07/26"; |
5528a91e EW |
3 | #endif |
4 | ||
5 | #include "ww.h" | |
6 | ||
4711df8b EW |
7 | struct ww_tty wwoldtty; |
8 | struct ww_tty wwnewtty = { | |
9 | { 0, 0, -1, -1, 0 }, | |
10 | { -1, -1, -1, -1, -1, -1 }, | |
11 | { -1, -1, -1, -1, -1, -1 }, | |
12 | 0, 0, 0 | |
13 | }; | |
b4be6cd6 | 14 | int _wwdtablesize; |
3e0824a9 EW |
15 | char _wwtermcap[1024]; |
16 | char _wwkeys[512]; | |
17 | static char *kp = _wwkeys; | |
c417b691 | 18 | int wwncol, wwnrow; |
5528a91e EW |
19 | |
20 | wwinit() | |
21 | { | |
4711df8b | 22 | static char done = 0; |
3e0824a9 | 23 | int kn; |
4711df8b EW |
24 | |
25 | if (done) | |
26 | return 0; | |
27 | done++; | |
b4be6cd6 | 28 | _wwdtablesize = getdtablesize(); |
4711df8b EW |
29 | if (wwgettty(0, &wwoldtty) < 0) |
30 | return -1; | |
31 | wwnewtty.ww_sgttyb.sg_flags = wwoldtty.ww_sgttyb.sg_flags; | |
32 | wwnewtty.ww_sgttyb.sg_ispeed = wwoldtty.ww_sgttyb.sg_ispeed; | |
33 | wwnewtty.ww_sgttyb.sg_ospeed = wwoldtty.ww_sgttyb.sg_ospeed; | |
34 | wwnewtty.ww_lmode = wwoldtty.ww_lmode; | |
35 | wwnewtty.ww_pgrp = wwoldtty.ww_pgrp; | |
36 | wwnewtty.ww_ldisc = wwoldtty.ww_ldisc; | |
37 | wwnewtty.ww_sgttyb.sg_flags |= CBREAK; | |
2b44d852 | 38 | wwnewtty.ww_sgttyb.sg_flags &= ~(ECHO|CRMOD); |
4711df8b EW |
39 | wwnewtty.ww_lmode |= LLITOUT; |
40 | wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc; | |
41 | if (wwsettty(0, &wwnewtty) < 0) | |
42 | return -1; | |
2b44d852 | 43 | if (Winit(2, 1) != 0) |
4711df8b EW |
44 | return -1; |
45 | WSetRealCursor = 1; | |
c417b691 | 46 | Wscreensize(&wwnrow, &wwncol); |
3e0824a9 EW |
47 | |
48 | if (tgetent(_wwtermcap, getenv("TERM")) != 1) | |
49 | return -1; | |
50 | addcap("kb"); | |
51 | addcap("ku"); | |
52 | addcap("kd"); | |
53 | addcap("kl"); | |
54 | addcap("kr"); | |
55 | addcap("kh"); | |
56 | if ((kn = tgetnum("kn")) >= 0) { | |
57 | char cap[5]; | |
58 | int i; | |
59 | ||
60 | sprintf(kp, "kn#%d:", kn); | |
61 | for (; *kp; kp++) | |
62 | ; | |
63 | for (i = 1; i <= kn; i++) { | |
64 | sprintf(cap, "k%d", i); | |
65 | addcap(cap); | |
66 | cap[0] = 'l'; | |
67 | addcap(cap); | |
68 | } | |
69 | } | |
4711df8b | 70 | return 0; |
5528a91e | 71 | } |
3e0824a9 EW |
72 | |
73 | addcap(cap) | |
74 | register char *cap; | |
75 | { | |
76 | static char tbuf[512]; | |
77 | static char *tp = tbuf; | |
78 | register char *str; | |
79 | char *tgetstr(); | |
80 | ||
81 | if ((str = tgetstr(cap, &tp)) != 0) { | |
82 | while (*kp++ = *cap++) | |
83 | ; | |
84 | kp[-1] = '='; | |
85 | while (*kp++ = *str++) | |
86 | ; | |
87 | kp[-1] = ':'; | |
88 | *kp = 0; | |
89 | } | |
90 | } |