* Copyright (c) 1983 Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Edward Wang at The University of California, Berkeley.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)wwinit.c 3.40 (Berkeley) 8/12/90";
wwdtablesize
= getdtablesize();
wwhead
.ww_forw
= &wwhead
;
wwhead
.ww_back
= &wwhead
;
s
= sigblock(sigmask(SIGIO
));
if (signal(SIGIO
, wwrint
) == SIG_ERR
||
signal(SIGCHLD
, wwchild
) == SIG_ERR
||
signal(SIGPIPE
, SIG_IGN
) == SIG_ERR
) {
if (wwgettty(0, &wwoldtty
) < 0)
wwwintty
.ww_sgttyb
.sg_flags
&= ~XTABS
;
wwnewtty
.ww_sgttyb
= wwoldtty
.ww_sgttyb
;
wwnewtty
.ww_sgttyb
.sg_erase
= -1;
wwnewtty
.ww_sgttyb
.sg_kill
= -1;
wwnewtty
.ww_sgttyb
.sg_flags
|= CBREAK
;
wwnewtty
.ww_sgttyb
.sg_flags
&= ~(ECHO
|CRMOD
);
wwnewtty
.ww_tchars
.t_intrc
= -1;
wwnewtty
.ww_tchars
.t_quitc
= -1;
wwnewtty
.ww_tchars
.t_startc
= -1;
wwnewtty
.ww_tchars
.t_stopc
= -1;
wwnewtty
.ww_tchars
.t_eofc
= -1;
wwnewtty
.ww_tchars
.t_brkc
= -1;
wwnewtty
.ww_ltchars
.t_suspc
= -1;
wwnewtty
.ww_ltchars
.t_dsuspc
= -1;
wwnewtty
.ww_ltchars
.t_rprntc
= -1;
wwnewtty
.ww_ltchars
.t_flushc
= -1;
wwnewtty
.ww_ltchars
.t_werasc
= -1;
wwnewtty
.ww_ltchars
.t_lnextc
= -1;
wwnewtty
.ww_lmode
= wwoldtty
.ww_lmode
| LLITOUT
;
wwnewtty
.ww_ldisc
= wwoldtty
.ww_ldisc
;
#define _POSIX_VDISABLE -1
wwwintty
.ww_termios
.c_oflag
&= ~OXTABS
;
wwnewtty
.ww_termios
= wwoldtty
.ww_termios
;
wwnewtty
.ww_termios
.c_iflag
&=
~(ISTRIP
| INLCR
| IGNCR
| ICRNL
| IXON
| IXOFF
| IMAXBEL
);
wwnewtty
.ww_termios
.c_iflag
|= INPCK
;
wwnewtty
.ww_termios
.c_oflag
= 0;
wwnewtty
.ww_termios
.c_cflag
&= ~(CSIZE
| PARENB
);
wwnewtty
.ww_termios
.c_cflag
|= CS8
;
wwnewtty
.ww_termios
.c_lflag
= 0;
for (i
= 0; i
< NCCS
; i
++)
wwnewtty
.ww_termios
.c_cc
[i
] = _POSIX_VDISABLE
;
wwnewtty
.ww_fflags
= wwoldtty
.ww_fflags
| FASYNC
;
if (wwsettty(0, &wwnewtty
) < 0)
if ((wwterm
= getenv("TERM")) == 0) {
if (tgetent(wwtermcap
, wwterm
) != 1) {
wwospeed
= wwoldtty
.ww_sgttyb
.sg_ospeed
;
wwospeed
= cfgetospeed(&wwoldtty
.ww_termios
);
wwavailmodes
= tt
.tt_availmodes
;
if (wwavailmodes
& WWM_REV
)
wwcursormodes
= WWM_REV
| wwavailmodes
& WWM_BLK
;
else if (wwavailmodes
& WWM_UL
)
if ((wwib
= malloc((unsigned) 512)) == 0)
if ((wwsmap
= wwalloc(0, 0, wwnrow
, wwncol
, sizeof (char))) == 0)
for (i
= 0; i
< wwnrow
; i
++)
for (j
= 0; j
< wwncol
; j
++)
wwsmap
[i
][j
] = WWX_NOBODY
;
wwos
= (union ww_char
**)
wwalloc(0, 0, wwnrow
, wwncol
, sizeof (union ww_char
));
for (i
= 0; i
< wwnrow
; i
++)
for (j
= 0; j
< wwncol
; j
++)
wwns
= (union ww_char
**)
wwalloc(0, 0, wwnrow
, wwncol
, sizeof (union ww_char
));
for (i
= 0; i
< wwnrow
; i
++)
for (j
= 0; j
< wwncol
; j
++)
wwtouched
= malloc((unsigned) wwnrow
);
for (i
= 0; i
< wwnrow
; i
++)
wwupd
= (struct ww_update
*) malloc((unsigned) wwnrow
* sizeof *wwupd
);
wwindex
[WWX_NOBODY
] = &wwnobody
;
if (wwavailmodes
& WWM_REV
)
if (wwavailmodes
& WWM_BLK
)
if (wwavailmodes
& WWM_UL
)
if (wwavailmodes
& WWM_GRP
)
if (wwavailmodes
& WWM_DIM
)
if (wwavailmodes
& WWM_USR
)
if (tt
.tt_insline
&& tt
.tt_delline
|| tt
.tt_setscroll
)
wwaddcap1(WWT_ALDL
, &kp
);
wwaddcap1(WWT_IMEI
, &kp
);
if ((j
= tgetnum("kn")) >= 0) {
(void) sprintf(kp
, "kn#%d:", j
);
for (i
= 1; i
<= j
; i
++) {
(void) sprintf(cap
, "k%d", i
);
* It's ok to do this here even if setenv() is destructive
* since tt_init() has already made its own copy of it and
* wwterm now points to the copy.
(void) setenv("TERM", WWT_TERM
, 1);
/* catch typeahead before ASYNC was set */
(void) kill(getpid(), SIGIO
);
* Don't bother to free storage. We're supposed
* to exit when wwinit fails anyway.
(void) wwsettty(0, &wwoldtty
);
(void) signal(SIGIO
, SIG_DFL
);
if ((str
= tgetstr(cap
, &tp
)) != 0) {
while (*(*kp
)++ = *cap
++)
for (p
= unctrl(*str
++); *(*kp
)++ = *p
++;)
while (*(*kp
)++ = *cap
++)