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