]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/wwopen.c
1 /* $NetBSD: wwopen.c,v 1.9 1998/08/25 20:59:43 ross 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
[] = "@(#)wwopen.c 8.2 (Berkeley) 4/28/95";
44 __RCSID("$NetBSD: wwopen.c,v 1.9 1998/08/25 20:59:43 ross Exp $");
48 #include <sys/types.h>
49 #include <sys/socket.h>
56 wwopen(type
, oflags
, nrow
, ncol
, row
, col
, nline
)
57 int type
, oflags
, nrow
, ncol
, row
, col
, nline
;
64 w
= (struct ww
*)calloc(sizeof (struct ww
), 1);
72 for (i
= 0; i
< NWW
&& wwindex
[i
] != 0; i
++)
75 wwerrno
= WWE_TOOMANY
;
84 w
->ww_w
.b
= row
+ nrow
;
86 w
->ww_w
.r
= col
+ ncol
;
91 w
->ww_b
.b
= row
+ nline
;
93 w
->ww_b
.r
= col
+ ncol
;
97 w
->ww_i
.t
= MAX(w
->ww_w
.t
, 0);
98 w
->ww_i
.b
= MIN(w
->ww_w
.b
, wwnrow
);
99 w
->ww_i
.l
= MAX(w
->ww_w
.l
, 0);
100 w
->ww_i
.r
= MIN(w
->ww_w
.r
, wwncol
);
101 w
->ww_i
.nr
= w
->ww_i
.b
- w
->ww_i
.t
;
102 w
->ww_i
.nc
= w
->ww_i
.r
- w
->ww_i
.l
;
104 w
->ww_cur
.r
= w
->ww_w
.t
;
105 w
->ww_cur
.c
= w
->ww_w
.l
;
116 if (socketpair(AF_LOCAL
, SOCK_STREAM
, PF_UNSPEC
, d
) < 0) {
120 (void) fcntl(d
[0], F_SETFD
, 1);
121 (void) fcntl(d
[1], F_SETFD
, 1);
127 if (type
!= WWT_INTERNAL
) {
128 if ((w
->ww_ob
= malloc(512)) == 0) {
132 w
->ww_obe
= w
->ww_ob
+ 512;
133 w
->ww_obp
= w
->ww_obq
= w
->ww_ob
;
134 if (w
->ww_pty
>= wwdtablesize
)
135 wwdtablesize
= w
->ww_pty
+ 1;
138 w
->ww_win
= wwalloc(w
->ww_w
.t
, w
->ww_w
.l
,
139 w
->ww_w
.nr
, w
->ww_w
.nc
, sizeof (char));
143 if (oflags
& WWO_GLASS
)
145 if (oflags
& WWO_REVERSE
) {
146 if (wwavailmodes
& WWM_REV
)
148 else oflags
&= ~WWO_REVERSE
;
150 for (i
= w
->ww_w
.t
; i
< w
->ww_w
.b
; i
++)
151 for (j
= w
->ww_w
.l
; j
< w
->ww_w
.r
; j
++)
154 if (oflags
& WWO_FRAME
) {
155 w
->ww_fmap
= wwalloc(w
->ww_w
.t
, w
->ww_w
.l
,
156 w
->ww_w
.nr
, w
->ww_w
.nc
, sizeof (char));
159 for (i
= w
->ww_w
.t
; i
< w
->ww_w
.b
; i
++)
160 for (j
= w
->ww_w
.l
; j
< w
->ww_w
.r
; j
++)
161 w
->ww_fmap
[i
][j
] = 0;
164 w
->ww_buf
= (union ww_char
**)
165 wwalloc(w
->ww_b
.t
, w
->ww_b
.l
,
166 w
->ww_b
.nr
, w
->ww_b
.nc
, sizeof (union ww_char
));
169 for (i
= w
->ww_b
.t
; i
< w
->ww_b
.b
; i
++)
170 for (j
= w
->ww_b
.l
; j
< w
->ww_b
.r
; j
++)
171 w
->ww_buf
[i
][j
].c_w
= ' ';
173 w
->ww_nvis
= (short *)malloc((unsigned) w
->ww_w
.nr
* sizeof (short));
174 if (w
->ww_nvis
== 0) {
178 w
->ww_nvis
-= w
->ww_w
.t
;
179 nvis
= m
? 0 : w
->ww_w
.nc
;
180 for (i
= w
->ww_w
.t
; i
< w
->ww_w
.b
; i
++)
181 w
->ww_nvis
[i
] = nvis
;
183 w
->ww_state
= WWS_INITIAL
;
184 CLR(w
->ww_oflags
, WWO_ALLFLAGS
);
185 SET(w
->ww_oflags
, oflags
);
186 return wwindex
[w
->ww_index
] = w
;
190 wwfree(w
->ww_win
, w
->ww_w
.t
);
192 wwfree(w
->ww_fmap
, w
->ww_w
.t
);
194 wwfree((char **)w
->ww_buf
, w
->ww_b
.t
);
196 free((char *)(w
->ww_nvis
+ w
->ww_w
.t
));
200 (void) close(w
->ww_pty
);
201 if (w
->ww_socket
>= 0)
202 (void) close(w
->ww_socket
);