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