diff options
Diffstat (limited to 'contrib/nvi/vi/vs_smap.c')
-rw-r--r-- | contrib/nvi/vi/vs_smap.c | 116 |
1 files changed, 49 insertions, 67 deletions
diff --git a/contrib/nvi/vi/vs_smap.c b/contrib/nvi/vi/vs_smap.c index 18d7942..0ab2df9 100644 --- a/contrib/nvi/vi/vs_smap.c +++ b/contrib/nvi/vi/vs_smap.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "@(#)vs_smap.c 10.25 (Berkeley) 7/12/96"; +static const char sccsid[] = "$Id: vs_smap.c,v 10.31 2011/02/26 13:56:21 skimo Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -42,10 +42,7 @@ static int vs_sm_up __P((SCR *, MARK *, recno_t, scroll_t, SMAP *)); * PUBLIC: int vs_change __P((SCR *, recno_t, lnop_t)); */ int -vs_change(sp, lno, op) - SCR *sp; - recno_t lno; - lnop_t op; +vs_change(SCR *sp, recno_t lno, lnop_t op) { VI_PRIVATE *vip; SMAP *p; @@ -64,7 +61,8 @@ vs_change(sp, lno, op) * * Check for line #2 before going to the end of the file. */ - if ((op == LINE_APPEND && lno == 0 || op == LINE_INSERT && lno == 1) && + if (((op == LINE_APPEND && lno == 0) || + (op == LINE_INSERT && lno == 1)) && !db_exist(sp, 2)) { lno = 1; op = LINE_RESET; @@ -138,11 +136,15 @@ vs_change(sp, lno, op) case LINE_DELETE: if (vs_sm_delete(sp, lno)) return (1); + if (sp->lno > lno) + --sp->lno; F_SET(vip, VIP_N_RENUMBER); break; case LINE_INSERT: if (vs_sm_insert(sp, lno)) return (1); + if (sp->lno > lno) + ++sp->lno; F_SET(vip, VIP_N_RENUMBER); break; case LINE_RESET: @@ -172,10 +174,7 @@ vs_change(sp, lno, op) * PUBLIC: int vs_sm_fill __P((SCR *, recno_t, pos_t)); */ int -vs_sm_fill(sp, lno, pos) - SCR *sp; - recno_t lno; - pos_t pos; +vs_sm_fill(SCR *sp, recno_t lno, pos_t pos) { SMAP *p, tmp; size_t cnt; @@ -225,6 +224,16 @@ vs_sm_fill(sp, lno, pos) top: HMAP->lno = lno; HMAP->coff = 0; HMAP->soff = 1; + } else { + /* + * If number of lines HMAP->lno (top line) spans + * changed due to, say reformatting, and now is + * fewer than HMAP->soff, reset so the line is + * redrawn at the top of the screen. + */ + cnt = vs_screens(sp, HMAP->lno, NULL); + if (cnt < HMAP->soff) + HMAP->soff = 1; } /* If we fail, just punt. */ for (p = HMAP, cnt = sp->t_rows; --cnt; ++p) @@ -299,9 +308,7 @@ err: HMAP->lno = 1; * Delete a line out of the SMAP. */ static int -vs_sm_delete(sp, lno) - SCR *sp; - recno_t lno; +vs_sm_delete(SCR *sp, recno_t lno) { SMAP *p, *t; size_t cnt_orig; @@ -349,9 +356,7 @@ vs_sm_delete(sp, lno) * Insert a line into the SMAP. */ static int -vs_sm_insert(sp, lno) - SCR *sp; - recno_t lno; +vs_sm_insert(SCR *sp, recno_t lno) { SMAP *p, *t; size_t cnt_orig, cnt, coff; @@ -405,9 +410,7 @@ vs_sm_insert(sp, lno) * Reset a line in the SMAP. */ static int -vs_sm_reset(sp, lno) - SCR *sp; - recno_t lno; +vs_sm_reset(SCR *sp, recno_t lno) { SMAP *p, *t; size_t cnt_orig, cnt_new, cnt, diff; @@ -512,11 +515,7 @@ vs_sm_reset(sp, lno) * PUBLIC: int vs_sm_scroll __P((SCR *, MARK *, recno_t, scroll_t)); */ int -vs_sm_scroll(sp, rp, count, scmd) - SCR *sp; - MARK *rp; - recno_t count; - scroll_t scmd; +vs_sm_scroll(SCR *sp, MARK *rp, recno_t count, scroll_t scmd) { SMAP *smp; @@ -573,12 +572,7 @@ vs_sm_scroll(sp, rp, count, scmd) * Scroll the SMAP up count logical lines. */ static int -vs_sm_up(sp, rp, count, scmd, smp) - SCR *sp; - MARK *rp; - scroll_t scmd; - recno_t count; - SMAP *smp; +vs_sm_up(SCR *sp, MARK *rp, recno_t count, scroll_t scmd, SMAP *smp) { int cursor_set, echanged, zset; SMAP *ssmp, s1, s2; @@ -754,8 +748,7 @@ vs_sm_up(sp, rp, count, scmd, smp) * PUBLIC: int vs_sm_1up __P((SCR *)); */ int -vs_sm_1up(sp) - SCR *sp; +vs_sm_1up(SCR *sp) { /* * Delete the top line of the screen. Shift the screen map @@ -784,14 +777,19 @@ vs_sm_1up(sp) * line and other screens back. */ static int -vs_deleteln(sp, cnt) - SCR *sp; - int cnt; +vs_deleteln(SCR *sp, int cnt) { GS *gp; size_t oldy, oldx; gp = sp->gp; + + /* If the screen is vertically split, we can't scroll it. */ + if (IS_VSPLIT(sp)) { + F_SET(sp, SC_SCR_REDRAW); + return (0); + } + if (IS_ONELINE(sp)) (void)gp->scr_clrtoeol(sp); else { @@ -811,12 +809,7 @@ vs_deleteln(sp, cnt) * Scroll the SMAP down count logical lines. */ static int -vs_sm_down(sp, rp, count, scmd, smp) - SCR *sp; - MARK *rp; - recno_t count; - SMAP *smp; - scroll_t scmd; +vs_sm_down(SCR *sp, MARK *rp, recno_t count, scroll_t scmd, SMAP *smp) { SMAP *ssmp, s1, s2; int cursor_set, ychanged, zset; @@ -967,8 +960,7 @@ vs_sm_down(sp, rp, count, scmd, smp) * Erase the small screen area for the scrolling functions. */ static int -vs_sm_erase(sp) - SCR *sp; +vs_sm_erase(SCR *sp) { GS *gp; @@ -989,8 +981,7 @@ vs_sm_erase(sp) * PUBLIC: int vs_sm_1down __P((SCR *)); */ int -vs_sm_1down(sp) - SCR *sp; +vs_sm_1down(SCR *sp) { /* * Insert a line at the top of the screen. Shift the screen map @@ -1019,14 +1010,19 @@ vs_sm_1down(sp) * line and other screens back. */ static int -vs_insertln(sp, cnt) - SCR *sp; - int cnt; +vs_insertln(SCR *sp, int cnt) { GS *gp; size_t oldy, oldx; gp = sp->gp; + + /* If the screen is vertically split, we can't scroll it. */ + if (IS_VSPLIT(sp)) { + F_SET(sp, SC_SCR_REDRAW); + return (0); + } + if (IS_ONELINE(sp)) { (void)gp->scr_move(sp, LASTLINE(sp), 0); (void)gp->scr_clrtoeol(sp); @@ -1049,9 +1045,7 @@ vs_insertln(sp, cnt) * PUBLIC: int vs_sm_next __P((SCR *, SMAP *, SMAP *)); */ int -vs_sm_next(sp, p, t) - SCR *sp; - SMAP *p, *t; +vs_sm_next(SCR *sp, SMAP *p, SMAP *t) { size_t lcnt; @@ -1079,9 +1073,7 @@ vs_sm_next(sp, p, t) * PUBLIC: int vs_sm_prev __P((SCR *, SMAP *, SMAP *)); */ int -vs_sm_prev(sp, p, t) - SCR *sp; - SMAP *p, *t; +vs_sm_prev(SCR *sp, SMAP *p, SMAP *t) { SMAP_FLUSH(t); if (O_ISSET(sp, O_LEFTRIGHT)) { @@ -1106,9 +1098,7 @@ vs_sm_prev(sp, p, t) * PUBLIC: int vs_sm_cursor __P((SCR *, SMAP **)); */ int -vs_sm_cursor(sp, smpp) - SCR *sp; - SMAP **smpp; +vs_sm_cursor(SCR *sp, SMAP **smpp) { SMAP *p; @@ -1147,11 +1137,7 @@ vs_sm_cursor(sp, smpp) * PUBLIC: int vs_sm_position __P((SCR *, MARK *, u_long, pos_t)); */ int -vs_sm_position(sp, rp, cnt, pos) - SCR *sp; - MARK *rp; - u_long cnt; - pos_t pos; +vs_sm_position(SCR *sp, MARK *rp, u_long cnt, pos_t pos) { SMAP *smp; recno_t last; @@ -1231,11 +1217,7 @@ eof: msgq(sp, M_BERR, * PUBLIC: recno_t vs_sm_nlines __P((SCR *, SMAP *, recno_t, size_t)); */ recno_t -vs_sm_nlines(sp, from_sp, to_lno, max) - SCR *sp; - SMAP *from_sp; - recno_t to_lno; - size_t max; +vs_sm_nlines(SCR *sp, SMAP *from_sp, recno_t to_lno, size_t max) { recno_t lno, lcnt; |