]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/wwwrite.c
1 /* $NetBSD: wwwrite.c,v 1.6 1997/11/21 08:38:00 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
[] = "@(#)wwwrite.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: wwwrite.c,v 1.6 1997/11/21 08:38:00 lukem Exp $");
54 if (!ISSET(w->ww_wflags, WWW_NOUPDATE) && w->ww_cur.r >= 0 && \
55 w->ww_cur.r < wwnrow && wwtouched[w->ww_cur.r]) \
56 wwupdate1(w->ww_cur.r, w->ww_cur.r + 1)
59 * To support control character expansion, we save the old
60 * p and q values in r and s, and point p at the beginning
61 * of the expanded string, and q at some safe place beyond it
62 * (p + 10). At strategic points in the loops, we check
63 * for (r && !*p) and restore the saved values back into
64 * p and q. Essentially, we implement a stack of depth 2,
65 * to avoid recursion, which might be a better idea.
80 s
= 0; /* define it before possible use */
82 hascursor
= ISSET(w
->ww_wflags
, WWW_HASCURSOR
);
85 while (p
< q
&& !ISSET(w
->ww_pflags
, WWP_STOPPED
) &&
86 (!wwinterrupt() || ISSET(w
->ww_wflags
, WWW_NOINTR
))) {
93 if (w
->ww_wstate
== 0 &&
95 (ISSET(w
->ww_wflags
, WWW_UNCTRL
) && isunctrl(*p
)))) {
100 if (ISSET(w
->ww_wflags
, WWW_INSERT
)) {
101 /* this is very slow */
105 ((w
->ww_cur
.c
- w
->ww_w
.l
) & 7);
114 wwinschar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
,
119 bp
= &w
->ww_buf
[w
->ww_cur
.r
][w
->ww_cur
.c
];
121 while (i
< w
->ww_w
.r
&& p
< q
)
126 } else if (*p
== '\t') {
127 int tmp
= 8 - ((i
- w
->ww_w
.l
) & 7);
131 } else if (isprt(*p
)) {
133 | w
->ww_modes
<< WWC_MSHIFT
;
135 } else if (ISSET(w
->ww_wflags
, WWW_UNCTRL
) &&
143 col
= MAX(w
->ww_cur
.c
, w
->ww_i
.l
);
144 col1
= MIN(i
, w
->ww_i
.r
);
146 if (w
->ww_cur
.r
>= w
->ww_i
.t
147 && w
->ww_cur
.r
< w
->ww_i
.b
) {
148 union ww_char
*ns
= wwns
[w
->ww_cur
.r
];
149 unsigned char *smap
=
150 &wwsmap
[w
->ww_cur
.r
][col
];
151 char *win
= w
->ww_win
[w
->ww_cur
.r
];
154 bp
= w
->ww_buf
[w
->ww_cur
.r
];
155 for (i
= col
; i
< col1
; i
++)
156 if (*smap
++ == w
->ww_index
) {
158 ns
[i
].c_w
= bp
[i
].c_w
159 ^ win
[i
] << WWC_MSHIFT
;
162 wwtouched
[w
->ww_cur
.r
] |= WWU_TOUCHED
;
165 if (w
->ww_cur
.c
>= w
->ww_w
.r
)
167 } else switch (w
->ww_wstate
) {
171 if (ISSET(w
->ww_wflags
, WWW_MAPNL
))
173 w
->ww_cur
.c
= w
->ww_w
.l
;
176 if (++w
->ww_cur
.r
>= w
->ww_w
.b
) {
177 w
->ww_cur
.r
= w
->ww_w
.b
- 1;
178 if (w
->ww_w
.b
< w
->ww_b
.b
) {
179 (void) wwscroll1(w
, w
->ww_i
.t
,
185 wwdelline(w
, w
->ww_b
.t
);
189 if (--w
->ww_cur
.c
< w
->ww_w
.l
) {
190 w
->ww_cur
.c
= w
->ww_w
.r
- 1;
195 w
->ww_cur
.c
= w
->ww_w
.l
;
209 SET(w
->ww_wflags
, WWW_INSERT
);
214 if (--w
->ww_cur
.r
< w
->ww_w
.t
) {
215 w
->ww_cur
.r
= w
->ww_w
.t
;
216 if (w
->ww_w
.t
> w
->ww_b
.t
) {
217 (void) wwscroll1(w
, w
->ww_i
.t
,
223 wwinsline(w
, w
->ww_b
.t
);
233 w
->ww_buf
-= w
->ww_w
.t
- w
->ww_b
.t
;
234 w
->ww_b
.t
= w
->ww_w
.t
;
235 w
->ww_b
.b
= w
->ww_b
.t
+ w
->ww_b
.nr
;
236 w
->ww_cur
.r
= w
->ww_w
.t
;
237 w
->ww_cur
.c
= w
->ww_w
.l
;
238 wwclreos(w
, w
->ww_w
.t
, w
->ww_w
.l
);
242 w
->ww_cur
.r
= w
->ww_w
.t
;
243 w
->ww_cur
.c
= w
->ww_w
.l
;
246 wwclreos(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
249 wwclreol(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
253 wwinsline(w
, w
->ww_cur
.r
);
256 wwdelline(w
, w
->ww_cur
.r
);
259 wwdelchar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
262 CLR(w
->ww_wflags
, WWW_INSERT
);
265 wwinschar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
, ' ', 0);
287 w
->ww_cur
.r
= w
->ww_w
.t
+
288 (unsigned)(*p
++ - ' ') % w
->ww_w
.nr
;
292 w
->ww_cur
.c
= w
->ww_w
.l
+
293 (unsigned)(*p
++ - ' ') % w
->ww_w
.nc
;
297 w
->ww_modes
|= *p
++ & wwavailmodes
;
301 w
->ww_modes
&= ~*p
++;