add S_RENUMBER support so when a new line is entered all the line
[nvi.git] / vi / v_z.c
blob96bec3e8d3247b3442a72c93cd830d988b5b1867
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: v_z.c,v 8.5 1993/10/03 13:01:44 bostic Exp $ (Berkeley) $Date: 1993/10/03 13:01:44 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "vcmd.h"
18 * v_z -- [count]z[count][-.+^<CR>]
19 * Move the screen.
21 int
22 v_z(sp, ep, vp, fm, tm, rp)
23 SCR *sp;
24 EXF *ep;
25 VICMDARG *vp;
26 MARK *fm, *tm, *rp;
28 recno_t last, lno;
31 * The first count is the line to use. If the value doesn't
32 * exist, use the last line.
34 if (F_ISSET(vp, VC_C1SET)) {
35 lno = vp->count;
36 if (file_lline(sp, ep, &last))
37 return (1);
38 if (lno > last)
39 lno = last;
40 } else
41 lno = fm->lno;
43 /* The second count is the window size. */
44 if (F_ISSET(vp, VC_C2SET) && set_window_size(sp, vp->count2, 0))
45 return (1);
47 /* Set default cursor values. */
48 rp->lno = lno;
49 rp->cno = fm->cno;
51 switch (vp->character) {
52 case '-': /* Put the line at the bottom. */
53 if (sp->s_fill(sp, ep, lno, P_BOTTOM))
54 return (1);
55 break;
56 case '.': /* Put the line in the middle. */
57 if (sp->s_fill(sp, ep, lno, P_MIDDLE))
58 return (1);
59 break;
60 default: /* Put the line at the top for <cr>. */
61 if (sp->special[vp->character] != K_CR &&
62 sp->special[vp->character] != K_NL) {
63 msgq(sp, M_ERR, "usage: %s.", vp->kp->usage);
64 return (1);
66 /* FALLTHROUGH */
67 case '+': /* Put the line at the top. */
68 if (sp->s_fill(sp, ep, lno, P_TOP))
69 return (1);
70 break;
71 case '^': /* Print the screen before the z- screen. */
73 * !!!
74 * Historic practice isn't real clear on this one. It seems
75 * that the command "70z^" is the same as ":70<cr>z-z^" with
76 * an off-by-one difference. So, until I find documentation
77 * to the contrary, the z^ command in this implementation
78 * displays the screen immediately before the current one.
79 * Fill the screen with the selected line at the bottom, then,
80 * scroll the screen down a page, and move to the middle line
81 * of the screen. Historic vi moved the cursor to some random
82 * place in the screen, as far as I can tell.
84 if (sp->s_fill(sp, ep, lno, P_BOTTOM))
85 return (1);
86 if (sp->s_down(sp, ep, rp, sp->t_maxrows - 1, 1))
87 return (1);
88 if (sp->s_position(sp, ep, rp, 0, P_MIDDLE))
89 return (1);
90 break;
93 /* If the map changes, have to redraw the entire screen. */
94 F_SET(sp, S_REDRAW);
96 return (0);