Commit | Line | Data |
---|---|---|
60de5df9 | 1 | /* |
46e9ea25 KB |
2 | * Copyright (c) 1983 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
5e8b0e60 KB |
6 | * provided that the above copyright notice and this paragraph are |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
60de5df9 EW |
16 | */ |
17 | ||
46e9ea25 | 18 | #ifndef lint |
d9375810 | 19 | static char sccsid[] = "@(#)wwinschar.c 3.18 (Berkeley) %G%"; |
46e9ea25 KB |
20 | #endif /* not lint */ |
21 | ||
bc28423e | 22 | #include "ww.h" |
e908bfac | 23 | #include "tt.h" |
bc28423e | 24 | |
f2a77fe1 | 25 | wwinschar(w, row, col, c) |
bc28423e | 26 | register struct ww *w; |
14f251df | 27 | short c; |
bc28423e | 28 | { |
14f251df | 29 | register i; |
14f251df | 30 | int nvis; |
bc28423e | 31 | |
19f9784c EW |
32 | /* |
33 | * First, shift the line. | |
34 | */ | |
14f251df EW |
35 | { |
36 | register union ww_char *p, *q; | |
37 | ||
f2a77fe1 | 38 | p = &w->ww_buf[row][w->ww_b.r]; |
14f251df | 39 | q = p - 1; |
f2a77fe1 | 40 | for (i = w->ww_b.r - col; --i > 0;) |
14f251df EW |
41 | *--p = *--q; |
42 | q->c_w = c; | |
43 | } | |
19f9784c EW |
44 | |
45 | /* | |
46 | * If can't see it, just return. | |
47 | */ | |
f2a77fe1 EW |
48 | if (row < w->ww_i.t || row >= w->ww_i.b |
49 | || w->ww_i.r <= 0 || w->ww_i.r <= col) | |
14f251df | 50 | return; |
19f9784c | 51 | |
f2a77fe1 EW |
52 | if (col < w->ww_i.l) |
53 | col = w->ww_i.l; | |
19f9784c EW |
54 | |
55 | /* | |
56 | * Now find out how much is actually changed, and fix wwns. | |
57 | */ | |
14f251df EW |
58 | { |
59 | register union ww_char *buf; | |
60 | register char *win; | |
61 | register union ww_char *ns; | |
62 | register char *smap; | |
d069a508 | 63 | char touched; |
14f251df EW |
64 | |
65 | nvis = 0; | |
f2a77fe1 | 66 | smap = &wwsmap[row][col]; |
d069a508 EW |
67 | for (i = col; i < w->ww_i.r && *smap++ != w->ww_index; i++) |
68 | ; | |
69 | if (i >= w->ww_i.r) | |
14f251df | 70 | return; |
d069a508 EW |
71 | col = i; |
72 | buf = w->ww_buf[row]; | |
73 | win = w->ww_win[row]; | |
74 | ns = wwns[row]; | |
75 | smap = &wwsmap[row][i]; | |
76 | touched = wwtouched[row]; | |
77 | for (; i < w->ww_i.r; i++) { | |
78 | if (*smap++ != w->ww_index) | |
79 | continue; | |
04d70db4 | 80 | touched |= WWU_TOUCHED; |
d069a508 EW |
81 | if (win[i]) |
82 | ns[i].c_w = | |
83 | buf[i].c_w ^ win[i] << WWC_MSHIFT; | |
84 | else { | |
14f251df | 85 | nvis++; |
d069a508 | 86 | ns[i] = buf[i]; |
bc28423e | 87 | } |
d069a508 EW |
88 | } |
89 | wwtouched[row] = touched; | |
bc28423e | 90 | } |
19f9784c EW |
91 | |
92 | /* | |
93 | * Can/Should we use delete character? | |
94 | */ | |
2d152f42 | 95 | if ((tt.tt_inschar || tt.tt_setinsert) && nvis > (wwncol - col) / 2) { |
14f251df EW |
96 | register union ww_char *p, *q; |
97 | ||
2d152f42 | 98 | xxinschar(row, col, c & wwavailmodes << WWC_MSHIFT); |
f2a77fe1 | 99 | p = &wwos[row][wwncol]; |
14f251df | 100 | q = p - 1; |
f2a77fe1 | 101 | for (i = wwncol - col; --i > 0;) |
14f251df | 102 | *--p = *--q; |
2d152f42 | 103 | q->c_w = tt.tt_setinsert ? c : ' '; |
14f251df | 104 | } |
bc28423e | 105 | } |