1 /* $NetBSD: xx.c,v 1.6 2002/06/14 01:07:03 wiz Exp $ */
4 * Copyright (c) 1989, 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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)xx.c 8.1 (Berkeley) 6/6/93";
40 __RCSID("$NetBSD: xx.c,v 1.6 2002/06/14 01:07:03 wiz Exp $");
57 xxbufsize
= tt
.tt_nrow
* tt
.tt_ncol
* 2;
58 /* ccinit may choose to change xxbufsize */
59 if (tt
.tt_ntoken
> 0 && ccinit() < 0)
61 xxbuf
= malloc((unsigned) xxbufsize
* sizeof *xxbuf
);
67 xxbufe
= xxbuf
+ xxbufsize
;
77 xxreset1(); /* might be a restart */
94 for (xp
= xx_head
; xp
!= 0; xp
= xq
) {
98 xx_tail
= xx_head
= 0;
105 if (tt
.tt_scroll_top
!= 0 || tt
.tt_scroll_bot
!= tt
.tt_nrow
- 1)
106 /* tt.tt_setscroll is known to be defined */
107 (*tt
.tt_setscroll
)(0, tt
.tt_nrow
- 1);
109 (*tt
.tt_setmodes
)(0);
110 if (tt
.tt_scroll_down
)
111 (*tt
.tt_scroll_down
)(1);
112 (*tt
.tt_move
)(tt
.tt_nrow
- 1, 0);
113 if (tt
.tt_ntoken
> 0)
126 if ((xp
= xx_freelist
) == 0)
127 /* XXX can't deal with failure */
128 xp
= (struct xx
*) malloc((unsigned) sizeof *xp
);
130 xx_freelist
= xp
->link
;
141 xxfree(struct xx
*xp
)
143 xp
->link
= xx_freelist
;
148 xxmove(int row
, int col
)
150 struct xx
*xp
= xx_tail
;
152 if (xp
== 0 || xp
->cmd
!= xc_move
) {
161 xxscroll(int dir
, int top
, int bot
)
163 struct xx
*xp
= xx_tail
;
165 if (xp
!= 0 && xp
->cmd
== xc_scroll
&&
166 xp
->arg1
== top
&& xp
->arg2
== bot
&&
167 ((xp
->arg0
< 0 && dir
< 0) || (xp
->arg0
> 0 && dir
> 0))) {
179 xxinschar(int row
, int col
, int c
, int m
)
184 xp
->cmd
= xc_inschar
;
192 xxinsspace(int row
, int col
)
194 struct xx
*xp
= xx_tail
;
196 if (xp
!= 0 && xp
->cmd
== xc_insspace
&& xp
->arg0
== row
&&
197 col
>= xp
->arg1
&& col
<= xp
->arg1
+ xp
->arg2
) {
202 xp
->cmd
= xc_insspace
;
209 xxdelchar(int row
, int col
)
211 struct xx
*xp
= xx_tail
;
213 if (xp
!= 0 && xp
->cmd
== xc_delchar
&&
214 xp
->arg0
== row
&& xp
->arg1
== col
) {
219 xp
->cmd
= xc_delchar
;
236 xxclreos(int row
, int col
)
238 struct xx
*xp
= xxalloc();
246 xxclreol(int row
, int col
)
248 struct xx
*xp
= xxalloc();
256 xxwrite(int row
, int col
, char *p
, int n
, int m
)
260 if (xxbufp
+ n
+ 1 > xxbufe
)
269 memmove(xxbufp
, p
, n
);
271 *xxbufp
++ = char_sep
;