1 /* @(#)wwwrite.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: wwwrite.c,v 1.9 2009/04/14 08:50:06 lukem Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 if (!ISSET(w->ww_wflags, WWW_NOUPDATE) && w->ww_cur.r >= 0 && \
43 w->ww_cur.r < wwnrow && wwtouched[w->ww_cur.r]) \
44 wwupdate1(w->ww_cur.r, w->ww_cur.r + 1)
47 * To support control character expansion, we save the old
48 * p and q values in r and s, and point p at the beginning
49 * of the expanded string, and q at some safe place beyond it
50 * (p + 10). At strategic points in the loops, we check
51 * for (r && !*p) and restore the saved values back into
52 * p and q. Essentially, we implement a stack of depth 2,
53 * to avoid recursion, which might be a better idea.
56 wwwrite(struct ww
*w
, const char *p
, int n
)
59 const char *savep
= p
;
60 const char *q
= p
+ n
;
65 s
= NULL
; /* define it before possible use */
67 hascursor
= ISSET(w
->ww_wflags
, WWW_HASCURSOR
);
70 while (p
< q
&& !ISSET(w
->ww_pflags
, WWP_STOPPED
) &&
71 (!wwinterrupt() || ISSET(w
->ww_wflags
, WWW_NOINTR
))) {
78 if (w
->ww_wstate
== 0 &&
80 (ISSET(w
->ww_wflags
, WWW_UNCTRL
) && isunctrl(*p
)))) {
85 if (ISSET(w
->ww_wflags
, WWW_INSERT
)) {
86 /* this is very slow */
90 ((w
->ww_cur
.c
- w
->ww_w
.l
) & 7);
99 wwinschar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
,
104 bp
= &w
->ww_buf
[w
->ww_cur
.r
][w
->ww_cur
.c
];
106 while (i
< w
->ww_w
.r
&& p
< q
)
111 } else if (*p
== '\t') {
112 int tmp
= 8 - ((i
- w
->ww_w
.l
) & 7);
116 } else if (isprt(*p
)) {
118 | w
->ww_modes
<< WWC_MSHIFT
;
120 } else if (ISSET(w
->ww_wflags
, WWW_UNCTRL
) &&
128 col
= MAX(w
->ww_cur
.c
, w
->ww_i
.l
);
129 col1
= MIN(i
, w
->ww_i
.r
);
131 if (w
->ww_cur
.r
>= w
->ww_i
.t
132 && w
->ww_cur
.r
< w
->ww_i
.b
) {
133 union ww_char
*ns
= wwns
[w
->ww_cur
.r
];
134 unsigned char *smap
=
135 &wwsmap
[w
->ww_cur
.r
][col
];
136 char *win
= w
->ww_win
[w
->ww_cur
.r
];
139 bp
= w
->ww_buf
[w
->ww_cur
.r
];
140 for (i
= col
; i
< col1
; i
++)
141 if (*smap
++ == w
->ww_index
) {
143 ns
[i
].c_w
= bp
[i
].c_w
144 ^ win
[i
] << WWC_MSHIFT
;
147 wwtouched
[w
->ww_cur
.r
] |= WWU_TOUCHED
;
150 if (w
->ww_cur
.c
>= w
->ww_w
.r
)
152 } else switch (w
->ww_wstate
) {
156 if (ISSET(w
->ww_wflags
, WWW_MAPNL
))
158 w
->ww_cur
.c
= w
->ww_w
.l
;
161 if (++w
->ww_cur
.r
>= w
->ww_w
.b
) {
162 w
->ww_cur
.r
= w
->ww_w
.b
- 1;
163 if (w
->ww_w
.b
< w
->ww_b
.b
) {
164 (void) wwscroll1(w
, w
->ww_i
.t
,
170 wwdelline(w
, w
->ww_b
.t
);
174 if (--w
->ww_cur
.c
< w
->ww_w
.l
) {
175 w
->ww_cur
.c
= w
->ww_w
.r
- 1;
180 w
->ww_cur
.c
= w
->ww_w
.l
;
194 SET(w
->ww_wflags
, WWW_INSERT
);
199 if (--w
->ww_cur
.r
< w
->ww_w
.t
) {
200 w
->ww_cur
.r
= w
->ww_w
.t
;
201 if (w
->ww_w
.t
> w
->ww_b
.t
) {
202 (void) wwscroll1(w
, w
->ww_i
.t
,
208 wwinsline(w
, w
->ww_b
.t
);
218 w
->ww_buf
-= w
->ww_w
.t
- w
->ww_b
.t
;
219 w
->ww_b
.t
= w
->ww_w
.t
;
220 w
->ww_b
.b
= w
->ww_b
.t
+ w
->ww_b
.nr
;
221 w
->ww_cur
.r
= w
->ww_w
.t
;
222 w
->ww_cur
.c
= w
->ww_w
.l
;
223 wwclreos(w
, w
->ww_w
.t
, w
->ww_w
.l
);
227 w
->ww_cur
.r
= w
->ww_w
.t
;
228 w
->ww_cur
.c
= w
->ww_w
.l
;
231 wwclreos(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
234 wwclreol(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
238 wwinsline(w
, w
->ww_cur
.r
);
241 wwdelline(w
, w
->ww_cur
.r
);
244 wwdelchar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
);
247 CLR(w
->ww_wflags
, WWW_INSERT
);
250 wwinschar(w
, w
->ww_cur
.r
, w
->ww_cur
.c
, ' ', 0);
272 w
->ww_cur
.r
= w
->ww_w
.t
+
273 (unsigned)(*p
++ - ' ') % w
->ww_w
.nr
;
277 w
->ww_cur
.c
= w
->ww_w
.l
+
278 (unsigned)(*p
++ - ' ') % w
->ww_w
.nc
;
282 w
->ww_modes
|= *p
++ & wwavailmodes
;
286 w
->ww_modes
&= ~*p
++;