2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/types.h>
13 #include <sys/queue.h>
16 #include <bitstring.h>
22 #include "../common/common.h"
25 * ex_z -- :[line] z [^-.+=] [count] [flags]
28 * PUBLIC: int ex_z(SCR *, EXCMD *);
31 ex_z(SCR *sp, EXCMD *cmdp)
34 recno_t cnt, equals, lno;
41 * If no count specified, use either two times the size of the
42 * scrolling region, or the size of the window option. POSIX
43 * 1003.2 claims that the latter is correct, but historic ex/vi
44 * documentation and practice appear to use the scrolling region.
45 * I'm using the window size as it means that the entire screen
46 * is used instead of losing a line to roundoff. Note, we drop
47 * a line from the cnt if using the window size to leave room for
50 if (FL_ISSET(cmdp->iflags, E_C_COUNT))
53 cnt = O_VAL(sp, O_WINDOW) - 1;
57 lno = cmdp->addr1.lno;
59 switch (FL_ISSET(cmdp->iflags,
60 E_C_CARAT | E_C_DASH | E_C_DOT | E_C_EQUAL | E_C_PLUS)) {
61 case E_C_CARAT: /* Display cnt * 2 before the line. */
64 cmdp->addr1.lno = (lno - cnt * 2) + 1;
67 cmdp->addr2.lno = (cmdp->addr1.lno + cnt) - 1;
69 case E_C_DASH: /* Line goes at the bottom of the screen. */
70 cmdp->addr1.lno = lno > cnt ? (lno - cnt) + 1 : 1;
71 cmdp->addr2.lno = lno;
73 case E_C_DOT: /* Line goes in the middle of the screen. */
76 * Historically, the "middleness" of the line overrode the
77 * count, so that "3z.19" or "3z.20" would display the first
78 * 12 lines of the file, i.e. (N - 1) / 2 lines before and
79 * after the specified line.
83 cmdp->addr1.lno = lno > cnt ? lno - cnt : 1;
84 cmdp->addr2.lno = lno + cnt;
88 * Historically, z. set the absolute cursor mark.
92 (void)mark_set(sp, ABSMARK1, &abs, 1);
94 case E_C_EQUAL: /* Center with hyphens. */
97 * Strangeness. The '=' flag is like the '.' flag (see the
98 * above comment, it applies here as well) but with a special
99 * little hack. Print out lines of hyphens before and after
100 * the specified line. Additionally, the cursor remains set
105 cmdp->addr1.lno = lno > cnt ? lno - cnt : 1;
106 cmdp->addr2.lno = lno - 1;
109 (void)ex_puts(sp, "----------------------------------------\n");
110 cmdp->addr2.lno = cmdp->addr1.lno = equals = lno;
113 (void)ex_puts(sp, "----------------------------------------\n");
114 cmdp->addr1.lno = lno + 1;
115 cmdp->addr2.lno = (lno + cnt) - 1;
118 /* If no line specified, move to the next one. */
119 if (F_ISSET(cmdp, E_ADDR_DEF))
122 case E_C_PLUS: /* Line goes at the top of the screen. */
124 cmdp->addr1.lno = lno;
125 cmdp->addr2.lno = (lno + cnt) - 1;
130 if (db_last(sp, &lno))
132 if (cmdp->addr2.lno > lno)
133 cmdp->addr2.lno = lno;