Commit | Line | Data |
---|---|---|
bc28423e | 1 | #ifndef lint |
84ad208b | 2 | static char *sccsid = "@(#)wwinschar.c 3.10 83/11/23"; |
bc28423e EW |
3 | #endif |
4 | ||
5 | #include "ww.h" | |
e908bfac | 6 | #include "tt.h" |
bc28423e | 7 | |
f2a77fe1 | 8 | wwinschar(w, row, col, c) |
bc28423e | 9 | register struct ww *w; |
14f251df | 10 | short c; |
bc28423e | 11 | { |
14f251df | 12 | register i; |
14f251df | 13 | int nvis; |
bc28423e | 14 | |
19f9784c EW |
15 | /* |
16 | * First, shift the line. | |
17 | */ | |
14f251df EW |
18 | { |
19 | register union ww_char *p, *q; | |
20 | ||
f2a77fe1 | 21 | p = &w->ww_buf[row][w->ww_b.r]; |
14f251df | 22 | q = p - 1; |
f2a77fe1 | 23 | for (i = w->ww_b.r - col; --i > 0;) |
14f251df EW |
24 | *--p = *--q; |
25 | q->c_w = c; | |
26 | } | |
19f9784c EW |
27 | |
28 | /* | |
29 | * If can't see it, just return. | |
30 | */ | |
f2a77fe1 EW |
31 | if (row < w->ww_i.t || row >= w->ww_i.b |
32 | || w->ww_i.r <= 0 || w->ww_i.r <= col) | |
14f251df | 33 | return; |
19f9784c | 34 | |
f2a77fe1 EW |
35 | if (col < w->ww_i.l) |
36 | col = w->ww_i.l; | |
19f9784c EW |
37 | |
38 | /* | |
39 | * Now find out how much is actually changed, and fix wwns. | |
40 | */ | |
14f251df EW |
41 | { |
42 | register union ww_char *buf; | |
43 | register char *win; | |
44 | register union ww_char *ns; | |
45 | register char *smap; | |
861cd1ed | 46 | char *touched; |
14f251df EW |
47 | |
48 | nvis = 0; | |
f2a77fe1 EW |
49 | smap = &wwsmap[row][col]; |
50 | for (i = w->ww_i.r - col; i > 0 && *smap++ != w->ww_index; i--) | |
51 | col++; | |
14f251df EW |
52 | if (i <= 0) |
53 | return; | |
f2a77fe1 | 54 | buf = &w->ww_buf[row][col]; |
14f251df | 55 | win = &w->ww_win[row][col]; |
f2a77fe1 | 56 | ns = &wwns[row][col]; |
84ad208b | 57 | smap = &wwsmap[row][col]; |
f2a77fe1 | 58 | touched = &wwtouched[row]; |
14f251df | 59 | c = buf->c_w ^ *win << WWC_MSHIFT; |
84ad208b EW |
60 | for (; --i >= 0;) |
61 | if (*smap++ != w->ww_index) { | |
62 | ns++; | |
63 | buf++; | |
64 | win++; | |
65 | } else if (*win) { | |
66 | ns++->c_w = buf++->c_w ^ *win++ << WWC_MSHIFT; | |
861cd1ed | 67 | *touched = 1; |
84ad208b | 68 | } else { |
14f251df EW |
69 | *ns++ = *buf++; |
70 | win++; | |
71 | nvis++; | |
84ad208b | 72 | *touched = 1; |
bc28423e | 73 | } |
bc28423e | 74 | } |
19f9784c EW |
75 | |
76 | /* | |
77 | * Can/Should we use delete character? | |
78 | */ | |
3130283e | 79 | if (tt.tt_hasinsert && nvis > (wwncol - col) / 2) { |
14f251df EW |
80 | register union ww_char *p, *q; |
81 | ||
3130283e EW |
82 | tt.tt_ninsert = 1; |
83 | tt.tt_nmodes = c >> WWC_MSHIFT & tt.tt_availmodes; | |
f2a77fe1 | 84 | (*tt.tt_move)(row, col); |
14f251df | 85 | (*tt.tt_putc)(c & WWC_CMASK); |
3130283e | 86 | tt.tt_ninsert = 0; |
14f251df | 87 | |
f2a77fe1 | 88 | p = &wwos[row][wwncol]; |
14f251df | 89 | q = p - 1; |
f2a77fe1 | 90 | for (i = wwncol - col; --i > 0;) |
14f251df EW |
91 | *--p = *--q; |
92 | q->c_w = c; | |
93 | } | |
bc28423e | 94 | } |