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