2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)wwwrite.c 8.1 (Berkeley) 6/6/93";
48 if (!w->ww_noupdate && w->ww_cur.r >= 0 && w->ww_cur.r < wwnrow && \
49 wwtouched[w->ww_cur.r]) \
50 wwupdate1(w->ww_cur.r, w->ww_cur.r + 1)
53 * To support control character expansion, we save the old
54 * p and q values in r and s, and point p at the beginning
55 * of the expanded string, and q at some safe place beyond it
56 * (p + 10). At strategic points in the loops, we check
57 * for (r && !*p) and restore the saved values back into
58 * p and q. Essentially, we implement a stack of depth 2,
59 * to avoid recursion, which might be a better idea.
62 register struct ww *w;
63 register unsigned char *p;
67 unsigned char *savep = p;
68 unsigned char *q = p + n;
73 s = 0; /* define it before possible use */
75 if (hascursor = w->ww_hascursor)
77 while (p < q && !w->ww_stopped && (!wwinterrupt() || w->ww_nointr)) {
84 if (w->ww_wstate == 0 &&
85 (isprt(*p) || w->ww_unctrl && isunctrl(*p))) {
87 register union ww_char *bp;
90 if (w->ww_insert) { /* this is very slow */
94 (w->ww_cur.c - w->ww_w.l & 7);
103 wwinschar(w, w->ww_cur.r, w->ww_cur.c,
108 bp = &w->ww_buf[w->ww_cur.r][w->ww_cur.c];
110 while (i < w->ww_w.r && p < q)
115 } else if (*p == '\t') {
116 register tmp = 8 - (i - w->ww_w.l & 7);
120 } else if (isprt(*p)) {
122 | w->ww_modes << WWC_MSHIFT;
124 } else if (w->ww_unctrl && isunctrl(*p)) {
131 col = MAX(w->ww_cur.c, w->ww_i.l);
132 col1 = MIN(i, w->ww_i.r);
134 if (w->ww_cur.r >= w->ww_i.t
135 && w->ww_cur.r < w->ww_i.b) {
136 register union ww_char *ns = wwns[w->ww_cur.r];
137 register char *smap = &wwsmap[w->ww_cur.r][col];
138 register char *win = w->ww_win[w->ww_cur.r];
141 bp = w->ww_buf[w->ww_cur.r];
142 for (i = col; i < col1; i++)
143 if (*smap++ == w->ww_index) {
145 ns[i].c_w = bp[i].c_w
146 ^ win[i] << WWC_MSHIFT;
149 wwtouched[w->ww_cur.r] |= WWU_TOUCHED;
152 if (w->ww_cur.c >= w->ww_w.r)
154 } else switch (w->ww_wstate) {
160 w->ww_cur.c = w->ww_w.l;
163 if (++w->ww_cur.r >= w->ww_w.b) {
164 w->ww_cur.r = w->ww_w.b - 1;
165 if (w->ww_w.b < w->ww_b.b) {
166 (void) wwscroll1(w, w->ww_i.t,
172 wwdelline(w, w->ww_b.t);
176 if (--w->ww_cur.c < w->ww_w.l) {
177 w->ww_cur.c = w->ww_w.r - 1;
182 w->ww_cur.c = w->ww_w.l;
201 if (--w->ww_cur.r < w->ww_w.t) {
202 w->ww_cur.r = w->ww_w.t;
203 if (w->ww_w.t > w->ww_b.t) {
204 (void) wwscroll1(w, w->ww_i.t,
210 wwinsline(w, w->ww_b.t);
220 w->ww_buf -= w->ww_w.t - w->ww_b.t;
221 w->ww_b.t = w->ww_w.t;
222 w->ww_b.b = w->ww_b.t + w->ww_b.nr;
223 w->ww_cur.r = w->ww_w.t;
224 w->ww_cur.c = w->ww_w.l;
225 wwclreos(w, w->ww_w.t, w->ww_w.l);
229 w->ww_cur.r = w->ww_w.t;
230 w->ww_cur.c = w->ww_w.l;
233 wwclreos(w, w->ww_cur.r, w->ww_cur.c);
236 wwclreol(w, w->ww_cur.r, w->ww_cur.c);
240 wwinsline(w, w->ww_cur.r);
243 wwdelline(w, w->ww_cur.r);
246 wwdelchar(w, w->ww_cur.r, w->ww_cur.c);
252 wwinschar(w, w->ww_cur.r, w->ww_cur.c, ' ', 0);
274 w->ww_cur.r = w->ww_w.t +
275 (unsigned)(*p++ - ' ') % w->ww_w.nr;
279 w->ww_cur.c = w->ww_w.l +
280 (unsigned)(*p++ - ' ') % w->ww_w.nc;
284 w->ww_modes |= *p++ & wwavailmodes;
288 w->ww_modes &= ~*p++;