tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / vi / v_z.c
blobcd402f3c82c8016aed867569890a158f4b8ed474
1 /* $NetBSD: v_z.c,v 1.2 2013/11/22 15:52:06 christos Exp $ */
2 /*-
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
9 */
11 #include "config.h"
13 #ifndef lint
14 static const char sccsid[] = "Id: v_z.c,v 10.12 2001/06/25 15:19:36 skimo Exp (Berkeley) Date: 2001/06/25 15:19:36 ";
15 #endif /* not lint */
17 #include <sys/types.h>
18 #include <sys/queue.h>
19 #include <sys/time.h>
21 #include <bitstring.h>
22 #include <limits.h>
23 #include <stdio.h>
25 #include "../common/common.h"
26 #include "vi.h"
29 * v_z -- [count]z[count][-.+^<CR>]
30 * Move the screen.
32 * PUBLIC: int v_z __P((SCR *, VICMD *));
34 int
35 v_z(SCR *sp, VICMD *vp)
37 db_recno_t lno;
38 e_key_t value;
41 * The first count is the line to use. If the value doesn't
42 * exist, use the last line.
44 if (F_ISSET(vp, VC_C1SET)) {
45 lno = vp->count;
46 if (!db_exist(sp, lno) && db_last(sp, &lno))
47 return (1);
48 } else
49 lno = vp->m_start.lno;
51 /* Set default return cursor line. */
52 vp->m_final.lno = lno;
53 vp->m_final.cno = vp->m_start.cno;
56 * The second count is the displayed window size, i.e. the 'z' command
57 * is another way to get artificially small windows. Note, you can't
58 * grow beyond the size of the window.
60 * !!!
61 * A window size of 0 was historically allowed, and simply ignored.
62 * This could be much more simply done by modifying the value of the
63 * O_WINDOW option, but that's not how it worked historically.
65 if (F_ISSET(vp, VC_C2SET) && vp->count2 != 0) {
66 if (vp->count2 > O_VAL(sp, O_WINDOW))
67 vp->count2 = O_VAL(sp, O_WINDOW);
68 if (vs_crel(sp, vp->count2))
69 return (1);
72 switch (vp->character) {
73 case '-': /* Put the line at the bottom. */
74 if (vs_sm_fill(sp, lno, P_BOTTOM))
75 return (1);
76 break;
77 case '.': /* Put the line in the middle. */
78 if (vs_sm_fill(sp, lno, P_MIDDLE))
79 return (1);
80 break;
81 case '+':
83 * If the user specified a line number, put that line at the
84 * top and move the cursor to it. Otherwise, scroll forward
85 * a screen from the current screen.
87 if (F_ISSET(vp, VC_C1SET)) {
88 if (vs_sm_fill(sp, lno, P_TOP))
89 return (1);
90 if (vs_sm_position(sp, &vp->m_final, 0, P_TOP))
91 return (1);
92 } else
93 if (vs_sm_scroll(sp, &vp->m_final, sp->t_rows, Z_PLUS))
94 return (1);
95 break;
96 case '^':
98 * If the user specified a line number, put that line at the
99 * bottom, move the cursor to it, and then display the screen
100 * before that one. Otherwise, scroll backward a screen from
101 * the current screen.
103 * !!!
104 * Note, we match the off-by-one characteristics of historic
105 * vi, here.
107 if (F_ISSET(vp, VC_C1SET)) {
108 if (vs_sm_fill(sp, lno, P_BOTTOM))
109 return (1);
110 if (vs_sm_position(sp, &vp->m_final, 0, P_TOP))
111 return (1);
112 if (vs_sm_fill(sp, vp->m_final.lno, P_BOTTOM))
113 return (1);
114 } else
115 if (vs_sm_scroll(sp, &vp->m_final, sp->t_rows, Z_CARAT))
116 return (1);
117 break;
118 default: /* Put the line at the top for <cr>. */
119 value = KEY_VAL(sp, vp->character);
120 if (value != K_CR && value != K_NL) {
121 v_emsg(sp, vp->kp->usage, VIM_USAGE);
122 return (1);
124 if (vs_sm_fill(sp, lno, P_TOP))
125 return (1);
126 break;
128 return (0);
132 * vs_crel --
133 * Change the relative size of the current screen.
135 * PUBLIC: int vs_crel __P((SCR *, long));
138 vs_crel(SCR *sp, long int count)
140 sp->t_minrows = sp->t_rows = count;
141 if (sp->t_rows > sp->rows - 1)
142 sp->t_minrows = sp->t_rows = sp->rows - 1;
143 TMAP = HMAP + (sp->t_rows - 1);
144 F_SET(sp, SC_SCR_REDRAW);
145 return (0);