]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/wwinit.c
1 /* $NetBSD: wwinit.c,v 1.12 1997/11/21 08:37:26 lukem Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)wwinit.c 8.2 (Berkeley) 4/28/95";
44 __RCSID("$NetBSD: wwinit.c,v 1.12 1997/11/21 08:37:26 lukem Exp $");
67 sigset_t sigset
, osigset
;
70 wwhead
.ww_forw
= &wwhead
;
71 wwhead
.ww_back
= &wwhead
;
74 sigaddset(&sigset
, SIGCHLD
);
75 sigaddset(&sigset
, SIGALRM
);
76 sigaddset(&sigset
, SIGHUP
);
77 sigaddset(&sigset
, SIGTERM
);
78 sigprocmask(SIG_BLOCK
, &sigset
, &osigset
);
80 if (signal(SIGCHLD
, wwchild
) == BADSIG
||
81 signal(SIGHUP
, wwquit
) == BADSIG
||
82 signal(SIGTERM
, wwquit
) == BADSIG
||
83 signal(SIGPIPE
, SIG_IGN
) == BADSIG
) {
88 if (wwgettty(0, &wwoldtty
) < 0)
92 wwwintty
.ww_sgttyb
.sg_flags
&= ~XTABS
;
93 wwnewtty
.ww_sgttyb
= wwoldtty
.ww_sgttyb
;
94 wwnewtty
.ww_sgttyb
.sg_erase
= -1;
95 wwnewtty
.ww_sgttyb
.sg_kill
= -1;
96 wwnewtty
.ww_sgttyb
.sg_flags
|= CBREAK
;
97 wwnewtty
.ww_sgttyb
.sg_flags
&= ~(ECHO
|CRMOD
);
98 wwnewtty
.ww_tchars
.t_intrc
= -1;
99 wwnewtty
.ww_tchars
.t_quitc
= -1;
100 wwnewtty
.ww_tchars
.t_startc
= -1;
101 wwnewtty
.ww_tchars
.t_stopc
= -1;
102 wwnewtty
.ww_tchars
.t_eofc
= -1;
103 wwnewtty
.ww_tchars
.t_brkc
= -1;
104 wwnewtty
.ww_ltchars
.t_suspc
= -1;
105 wwnewtty
.ww_ltchars
.t_dsuspc
= -1;
106 wwnewtty
.ww_ltchars
.t_rprntc
= -1;
107 wwnewtty
.ww_ltchars
.t_flushc
= -1;
108 wwnewtty
.ww_ltchars
.t_werasc
= -1;
109 wwnewtty
.ww_ltchars
.t_lnextc
= -1;
110 wwnewtty
.ww_lmode
= wwoldtty
.ww_lmode
| LLITOUT
;
111 wwnewtty
.ww_ldisc
= wwoldtty
.ww_ldisc
;
116 #ifndef _POSIX_VDISABLE
117 #define _POSIX_VDISABLE -1
119 wwwintty
.ww_termios
.c_oflag
&= ~OXTABS
;
120 wwnewtty
.ww_termios
= wwoldtty
.ww_termios
;
121 wwnewtty
.ww_termios
.c_iflag
&=
122 ~(ISTRIP
| INLCR
| IGNCR
| ICRNL
| IXON
| IXOFF
| IMAXBEL
);
123 wwnewtty
.ww_termios
.c_oflag
= 0;
124 wwnewtty
.ww_termios
.c_cflag
&= ~(CSIZE
| PARENB
);
125 wwnewtty
.ww_termios
.c_cflag
|= CS8
;
126 wwnewtty
.ww_termios
.c_lflag
= 0;
127 for (i
= 0; i
< NCCS
; i
++)
128 wwnewtty
.ww_termios
.c_cc
[i
] = _POSIX_VDISABLE
;
129 wwnewtty
.ww_termios
.c_cc
[VMIN
] = 1;
130 wwnewtty
.ww_termios
.c_cc
[VTIME
] = 0;
132 if (wwsettty(0, &wwnewtty
) < 0)
135 if ((wwterm
= getenv("TERM")) == 0) {
136 wwerrno
= WWE_BADTERM
;
139 if (tgetent(wwtermcap
, wwterm
) != 1) {
140 wwerrno
= WWE_BADTERM
;
144 wwospeed
= wwoldtty
.ww_sgttyb
.sg_ospeed
;
146 wwospeed
= cfgetospeed(&wwoldtty
.ww_termios
);
223 wwavailmodes
= tt
.tt_availmodes
;
226 if (wwavailmodes
& WWM_REV
)
227 wwcursormodes
= WWM_REV
| (wwavailmodes
& WWM_BLK
);
228 else if (wwavailmodes
& WWM_UL
)
229 wwcursormodes
= WWM_UL
;
231 if ((wwib
= malloc((unsigned) 512)) == 0)
234 wwibq
= wwibp
= wwib
;
236 wwsmap
= (unsigned char **)
237 wwalloc(0, 0, wwnrow
, wwncol
, sizeof (unsigned char));
240 for (i
= 0; i
< wwnrow
; i
++)
241 for (j
= 0; j
< wwncol
; j
++)
242 wwsmap
[i
][j
] = WWX_NOBODY
;
244 wwos
= (union ww_char
**)
245 wwalloc(0, 0, wwnrow
, wwncol
, sizeof (union ww_char
));
248 /* wwos is cleared in wwstart1() */
249 wwns
= (union ww_char
**)
250 wwalloc(0, 0, wwnrow
, wwncol
, sizeof (union ww_char
));
253 for (i
= 0; i
< wwnrow
; i
++)
254 for (j
= 0; j
< wwncol
; j
++)
255 wwns
[i
][j
].c_w
= ' ';
256 if (tt
.tt_checkpoint
) {
257 /* wwcs is also cleared in wwstart1() */
258 wwcs
= (union ww_char
**)
259 wwalloc(0, 0, wwnrow
, wwncol
, sizeof (union ww_char
));
264 wwtouched
= malloc((unsigned) wwnrow
);
265 if (wwtouched
== 0) {
269 for (i
= 0; i
< wwnrow
; i
++)
272 wwupd
= (struct ww_update
*) malloc((unsigned) wwnrow
* sizeof *wwupd
);
278 wwindex
[WWX_NOBODY
] = &wwnobody
;
279 wwnobody
.ww_order
= NWW
;
282 if (wwavailmodes
& WWM_REV
)
283 wwaddcap1(WWT_REV
, &kp
);
284 if (wwavailmodes
& WWM_BLK
)
285 wwaddcap1(WWT_BLK
, &kp
);
286 if (wwavailmodes
& WWM_UL
)
287 wwaddcap1(WWT_UL
, &kp
);
288 if (wwavailmodes
& WWM_GRP
)
289 wwaddcap1(WWT_GRP
, &kp
);
290 if (wwavailmodes
& WWM_DIM
)
291 wwaddcap1(WWT_DIM
, &kp
);
292 if (wwavailmodes
& WWM_USR
)
293 wwaddcap1(WWT_USR
, &kp
);
294 if ((tt
.tt_insline
&& tt
.tt_delline
) || tt
.tt_setscroll
)
295 wwaddcap1(WWT_ALDL
, &kp
);
297 wwaddcap1(WWT_IMEI
, &kp
);
299 wwaddcap1(WWT_IC
, &kp
);
301 wwaddcap1(WWT_DC
, &kp
);
308 if ((j
= tgetnum("kn")) >= 0) {
311 (void) sprintf(kp
, "kn#%d:", j
);
314 for (i
= 1; i
<= j
; i
++) {
315 (void) sprintf(cap
, "k%d", i
);
322 * It's ok to do this here even if setenv() is destructive
323 * since tt_init() has already made its own copy of it and
324 * wwterm now points to the copy.
326 (void) setenv("TERM", WWT_TERM
, 1);
328 if (wwterminfoinit() < 0)
332 if (tt
.tt_checkpoint
)
333 if (signal(SIGALRM
, wwalarm
) == BADSIG
) {
339 sigprocmask(SIG_SETMASK
, &osigset
, (sigset_t
*)0);
344 * Don't bother to free storage. We're supposed
345 * to exit when wwinit fails anyway.
347 (void) wwsettty(0, &wwoldtty
);
349 sigprocmask(SIG_SETMASK
, &osigset
, (sigset_t
*)0);
362 if ((str
= tgetstr(cap
, &tp
)) != 0) {
363 while ((*(*kp
)++ = *cap
++))
367 for (p
= unctrl(*str
++); (*(*kp
)++ = *p
++);)
381 while ((*(*kp
)++ = *cap
++))
391 (void) wwsettty(0, &wwnewtty
);
392 for (i
= 0; i
< wwnrow
; i
++)
393 wwtouched
[i
] = WWU_TOUCHED
;
402 for (i
= 0; i
< wwnrow
; i
++)
403 for (j
= 0; j
< wwncol
; j
++) {
404 wwos
[i
][j
].c_w
= ' ';
405 if (tt
.tt_checkpoint
)
406 wwcs
[i
][j
].c_w
= ' ';
409 if (tt
.tt_checkpoint
)
414 * Reset data structures and terminal from an unknown state.
415 * Restoring wwos has been taken care of elsewhere.
423 for (i
= 0; i
< wwnrow
; i
++)
424 wwtouched
[i
] = WWU_TOUCHED
;