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.
13 static const char sccsid[] = "$Id: ex_z.c,v 10.12 2001/06/25 15:19:22 skimo Exp $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
26 #include "../common/common.h"
29 * ex_z -- :[line] z [^-.+=] [count] [flags]
32 * PUBLIC: int ex_z __P((SCR *, EXCMD *));
35 ex_z(SCR *sp, EXCMD *cmdp)
38 recno_t cnt, equals, lno;
45 * If no count specified, use either two times the size of the
46 * scrolling region, or the size of the window option. POSIX
47 * 1003.2 claims that the latter is correct, but historic ex/vi
48 * documentation and practice appear to use the scrolling region.
49 * I'm using the window size as it means that the entire screen
50 * is used instead of losing a line to roundoff. Note, we drop
51 * a line from the cnt if using the window size to leave room for
54 if (FL_ISSET(cmdp->iflags, E_C_COUNT))
57 #ifdef HISTORICAL_PRACTICE
58 cnt = O_VAL(sp, O_SCROLL) * 2;
60 cnt = O_VAL(sp, O_WINDOW) - 1;
65 lno = cmdp->addr1.lno;
67 switch (FL_ISSET(cmdp->iflags,
68 E_C_CARAT | E_C_DASH | E_C_DOT | E_C_EQUAL | E_C_PLUS)) {
69 case E_C_CARAT: /* Display cnt * 2 before the line. */
72 cmdp->addr1.lno = (lno - cnt * 2) + 1;
75 cmdp->addr2.lno = (cmdp->addr1.lno + cnt) - 1;
77 case E_C_DASH: /* Line goes at the bottom of the screen. */
78 cmdp->addr1.lno = lno > cnt ? (lno - cnt) + 1 : 1;
79 cmdp->addr2.lno = lno;
81 case E_C_DOT: /* Line goes in the middle of the screen. */
84 * Historically, the "middleness" of the line overrode the
85 * count, so that "3z.19" or "3z.20" would display the first
86 * 12 lines of the file, i.e. (N - 1) / 2 lines before and
87 * after the specified line.
91 cmdp->addr1.lno = lno > cnt ? lno - cnt : 1;
92 cmdp->addr2.lno = lno + cnt;
96 * Historically, z. set the absolute cursor mark.
100 (void)mark_set(sp, ABSMARK1, &abs, 1);
102 case E_C_EQUAL: /* Center with hyphens. */
105 * Strangeness. The '=' flag is like the '.' flag (see the
106 * above comment, it applies here as well) but with a special
107 * little hack. Print out lines of hyphens before and after
108 * the specified line. Additionally, the cursor remains set
113 cmdp->addr1.lno = lno > cnt ? lno - cnt : 1;
114 cmdp->addr2.lno = lno - 1;
117 (void)ex_puts(sp, "----------------------------------------\n");
118 cmdp->addr2.lno = cmdp->addr1.lno = equals = lno;
121 (void)ex_puts(sp, "----------------------------------------\n");
122 cmdp->addr1.lno = lno + 1;
123 cmdp->addr2.lno = (lno + cnt) - 1;
126 /* If no line specified, move to the next one. */
127 if (F_ISSET(cmdp, E_ADDR_DEF))
130 case E_C_PLUS: /* Line goes at the top of the screen. */
132 cmdp->addr1.lno = lno;
133 cmdp->addr2.lno = (lno + cnt) - 1;
138 if (db_last(sp, &lno))
140 if (cmdp->addr2.lno > lno)
141 cmdp->addr2.lno = lno;