.Xr botch fix
[unix-history] / usr / src / usr.bin / window / wwinschar.c
CommitLineData
60de5df9 1/*
46e9ea25
KB
2 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved.
4 *
3dd3a9e5
KB
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
7 *
87f529ec 8 * %sccs.include.redist.c%
60de5df9
EW
9 */
10
46e9ea25 11#ifndef lint
3dd3a9e5 12static char sccsid[] = "@(#)wwinschar.c 3.20 (Berkeley) %G%";
46e9ea25
KB
13#endif /* not lint */
14
bc28423e 15#include "ww.h"
e908bfac 16#include "tt.h"
bc28423e 17
365131ac 18wwinschar(w, row, col, c, m)
bc28423e 19register struct ww *w;
365131ac 20char c, m;
bc28423e 21{
14f251df 22 register i;
14f251df 23 int nvis;
365131ac 24 short x = c | m << WWC_MSHIFT;
bc28423e 25
19f9784c
EW
26 /*
27 * First, shift the line.
28 */
14f251df
EW
29 {
30 register union ww_char *p, *q;
31
f2a77fe1 32 p = &w->ww_buf[row][w->ww_b.r];
14f251df 33 q = p - 1;
f2a77fe1 34 for (i = w->ww_b.r - col; --i > 0;)
14f251df 35 *--p = *--q;
365131ac 36 q->c_w = x;
14f251df 37 }
19f9784c
EW
38
39 /*
40 * If can't see it, just return.
41 */
f2a77fe1
EW
42 if (row < w->ww_i.t || row >= w->ww_i.b
43 || w->ww_i.r <= 0 || w->ww_i.r <= col)
14f251df 44 return;
19f9784c 45
f2a77fe1
EW
46 if (col < w->ww_i.l)
47 col = w->ww_i.l;
19f9784c
EW
48
49 /*
50 * Now find out how much is actually changed, and fix wwns.
51 */
14f251df
EW
52 {
53 register union ww_char *buf;
54 register char *win;
55 register union ww_char *ns;
56 register char *smap;
d069a508 57 char touched;
14f251df
EW
58
59 nvis = 0;
f2a77fe1 60 smap = &wwsmap[row][col];
d069a508
EW
61 for (i = col; i < w->ww_i.r && *smap++ != w->ww_index; i++)
62 ;
63 if (i >= w->ww_i.r)
14f251df 64 return;
d069a508
EW
65 col = i;
66 buf = w->ww_buf[row];
67 win = w->ww_win[row];
68 ns = wwns[row];
69 smap = &wwsmap[row][i];
70 touched = wwtouched[row];
71 for (; i < w->ww_i.r; i++) {
72 if (*smap++ != w->ww_index)
73 continue;
04d70db4 74 touched |= WWU_TOUCHED;
d069a508
EW
75 if (win[i])
76 ns[i].c_w =
77 buf[i].c_w ^ win[i] << WWC_MSHIFT;
78 else {
14f251df 79 nvis++;
d069a508 80 ns[i] = buf[i];
bc28423e 81 }
d069a508
EW
82 }
83 wwtouched[row] = touched;
bc28423e 84 }
19f9784c
EW
85
86 /*
87 * Can/Should we use delete character?
88 */
365131ac 89 if ((tt.tt_inschar || tt.tt_insspace) && nvis > (wwncol - col) / 2) {
14f251df
EW
90 register union ww_char *p, *q;
91
365131ac
EW
92 if (tt.tt_inschar)
93 xxinschar(row, col, c, m);
94 else {
95 xxinsspace(row, col);
96 x = ' ';
97 }
f2a77fe1 98 p = &wwos[row][wwncol];
14f251df 99 q = p - 1;
f2a77fe1 100 for (i = wwncol - col; --i > 0;)
14f251df 101 *--p = *--q;
365131ac 102 q->c_w = x;
14f251df 103 }
bc28423e 104}