bug, wrong value to getcount for 'z' command
[nvi.git] / vi / v_z.c
blob3f6b2e9c98598f37b78dbe1547ff50850fb879b7
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.6 1993/11/29 14:15:30 bostic Exp $ (Berkeley) $Date: 1993/11/29 14:15:30 $";
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;
29 u_int value;
32 * The first count is the line to use. If the value doesn't
33 * exist, use the last line.
35 if (F_ISSET(vp, VC_C1SET)) {
36 lno = vp->count;
37 if (file_lline(sp, ep, &last))
38 return (1);
39 if (lno > last)
40 lno = last;
41 } else
42 lno = fm->lno;
44 /* The second count is the window size. */
45 if (F_ISSET(vp, VC_C2SET) && set_window_size(sp, vp->count2, 0))
46 return (1);
48 /* Set default cursor values. */
49 rp->lno = lno;
50 rp->cno = fm->cno;
52 switch (vp->character) {
53 case '-': /* Put the line at the bottom. */
54 if (sp->s_fill(sp, ep, lno, P_BOTTOM))
55 return (1);
56 break;
57 case '.': /* Put the line in the middle. */
58 if (sp->s_fill(sp, ep, lno, P_MIDDLE))
59 return (1);
60 break;
61 default: /* Put the line at the top for <cr>. */
62 value = term_key_val(sp, vp->character);
63 if (value != K_CR && value != K_NL) {
64 msgq(sp, M_ERR, "usage: %s.", vp->kp->usage);
65 return (1);
67 /* FALLTHROUGH */
68 case '+': /* Put the line at the top. */
69 if (sp->s_fill(sp, ep, lno, P_TOP))
70 return (1);
71 break;
72 case '^': /* Print the screen before the z- screen. */
74 * !!!
75 * Historic practice isn't real clear on this one. It seems
76 * that the command "70z^" is the same as ":70<cr>z-z^" with
77 * an off-by-one difference. So, until I find documentation
78 * to the contrary, the z^ command in this implementation
79 * displays the screen immediately before the current one.
80 * Fill the screen with the selected line at the bottom, then,
81 * scroll the screen down a page, and move to the middle line
82 * of the screen. Historic vi moved the cursor to some random
83 * place in the screen, as far as I can tell.
85 if (sp->s_fill(sp, ep, lno, P_BOTTOM))
86 return (1);
87 if (sp->s_down(sp, ep, rp, sp->t_maxrows - 1, 1))
88 return (1);
89 if (sp->s_position(sp, ep, rp, 0, P_MIDDLE))
90 return (1);
91 break;
94 /* If the map changes, have to redraw the entire screen. */
95 F_SET(sp, S_REDRAW);
97 return (0);