1 /* $NetBSD: wwwrite.c,v 1.8 2003/08/07 11:17:46 agc 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. 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
[] = "@(#)wwwrite.c 8.1 (Berkeley) 6/6/93";
40 __RCSID("$NetBSD: wwwrite.c,v 1.8 2003/08/07 11:17:46 agc Exp $");
50 if (!ISSET(w->ww_wflags, WWW_NOUPDATE) && w->ww_cur.r >= 0 && \
51 w->ww_cur.r < wwnrow && wwtouched[w->ww_cur.r]) \
52 wwupdate1(w->ww_cur.r, w->ww_cur.r + 1)
55 * To support control character expansion, we save the old
56 * p and q values in r and s, and point p at the beginning
57 * of the expanded string, and q at some safe place beyond it
58 * (p + 10). At strategic points in the loops, we check
59 * for (r && !*p) and restore the saved values back into
60 * p and q. Essentially, we implement a stack of depth 2,
61 * to avoid recursion, which might be a better idea.
64 wwwrite(struct ww
*w
, const char *p
, int n
)
67 const char *savep
= p
;
68 const char *q
= p
+ n
;
73 s
= 0; /* define it before possible use */
75 hascursor
= ISSET(w
->ww_wflags
, WWW_HASCURSOR
);
78 while (p
< q
&& !ISSET(w
->ww_pflags
, WWP_STOPPED
) &&
79 (!wwinterrupt() || ISSET(w
->ww_wflags
, WWW_NOINTR
))) {
86 if (w
->ww_wstate
== 0 &&
88 (ISSET(w
->ww_wflags
, WWW_UNCTRL
) && isunctrl(*p
)))) {
93 if (ISSET(w
->ww_wflags
, WWW_INSERT
)) {
94 /* this is very slow */
98 ((w
->ww_cur
.c
- w
->ww_w
.l
) & 7);
107 wwinschar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
,
112 bp
= &w
->ww_buf
[w
->ww_cur
.r
][w
->ww_cur
.c
];
114 while (i
< w
->ww_w
.r
&& p
< q
)
119 } else if (*p
== '\t') {
120 int tmp
= 8 - ((i
- w
->ww_w
.l
) & 7);
124 } else if (isprt(*p
)) {
126 | w
->ww_modes
<< WWC_MSHIFT
;
128 } else if (ISSET(w
->ww_wflags
, WWW_UNCTRL
) &&
136 col
= MAX(w
->ww_cur
.c
, w
->ww_i
.l
);
137 col1
= MIN(i
, w
->ww_i
.r
);
139 if (w
->ww_cur
.r
>= w
->ww_i
.t
140 && w
->ww_cur
.r
< w
->ww_i
.b
) {
141 union ww_char
*ns
= wwns
[w
->ww_cur
.r
];
142 unsigned char *smap
=
143 &wwsmap
[w
->ww_cur
.r
][col
];
144 char *win
= w
->ww_win
[w
->ww_cur
.r
];
147 bp
= w
->ww_buf
[w
->ww_cur
.r
];
148 for (i
= col
; i
< col1
; i
++)
149 if (*smap
++ == w
->ww_index
) {
151 ns
[i
].c_w
= bp
[i
].c_w
152 ^ win
[i
] << WWC_MSHIFT
;
155 wwtouched
[w
->ww_cur
.r
] |= WWU_TOUCHED
;
158 if (w
->ww_cur
.c
>= w
->ww_w
.r
)
160 } else switch (w
->ww_wstate
) {
164 if (ISSET(w
->ww_wflags
, WWW_MAPNL
))
166 w
->ww_cur
.c
= w
->ww_w
.l
;
169 if (++w
->ww_cur
.r
>= w
->ww_w
.b
) {
170 w
->ww_cur
.r
= w
->ww_w
.b
- 1;
171 if (w
->ww_w
.b
< w
->ww_b
.b
) {
172 (void) wwscroll1(w
, w
->ww_i
.t
,
178 wwdelline(w
, w
->ww_b
.t
);
182 if (--w
->ww_cur
.c
< w
->ww_w
.l
) {
183 w
->ww_cur
.c
= w
->ww_w
.r
- 1;
188 w
->ww_cur
.c
= w
->ww_w
.l
;
202 SET(w
->ww_wflags
, WWW_INSERT
);
207 if (--w
->ww_cur
.r
< w
->ww_w
.t
) {
208 w
->ww_cur
.r
= w
->ww_w
.t
;
209 if (w
->ww_w
.t
> w
->ww_b
.t
) {
210 (void) wwscroll1(w
, w
->ww_i
.t
,
216 wwinsline(w
, w
->ww_b
.t
);
226 w
->ww_buf
-= w
->ww_w
.t
- w
->ww_b
.t
;
227 w
->ww_b
.t
= w
->ww_w
.t
;
228 w
->ww_b
.b
= w
->ww_b
.t
+ w
->ww_b
.nr
;
229 w
->ww_cur
.r
= w
->ww_w
.t
;
230 w
->ww_cur
.c
= w
->ww_w
.l
;
231 wwclreos(w
, w
->ww_w
.t
, w
->ww_w
.l
);
235 w
->ww_cur
.r
= w
->ww_w
.t
;
236 w
->ww_cur
.c
= w
->ww_w
.l
;
239 wwclreos(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
242 wwclreol(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
246 wwinsline(w
, w
->ww_cur
.r
);
249 wwdelline(w
, w
->ww_cur
.r
);
252 wwdelchar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
255 CLR(w
->ww_wflags
, WWW_INSERT
);
258 wwinschar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
, ' ', 0);
280 w
->ww_cur
.r
= w
->ww_w
.t
+
281 (unsigned)(*p
++ - ' ') % w
->ww_w
.nr
;
285 w
->ww_cur
.c
= w
->ww_w
.l
+
286 (unsigned)(*p
++ - ' ') % w
->ww_w
.nc
;
290 w
->ww_modes
|= *p
++ & wwavailmodes
;
294 w
->ww_modes
&= ~*p
++;