1 /* $NetBSD: ex_z.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
3 * Copyright (c) 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
13 #include <sys/cdefs.h>
16 static const char sccsid
[] = "Id: ex_z.c,v 10.12 2001/06/25 15:19:22 skimo Exp (Berkeley) Date: 2001/06/25 15:19:22 ";
19 __RCSID("$NetBSD: ex_z.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
22 #include <sys/types.h>
23 #include <sys/queue.h>
25 #include <bitstring.h>
31 #include "../common/common.h"
34 * ex_z -- :[line] z [^-.+=] [count] [flags]
37 * PUBLIC: int ex_z __P((SCR *, EXCMD *));
40 ex_z(SCR
*sp
, EXCMD
*cmdp
)
43 db_recno_t cnt
, equals
, lno
;
50 * If no count specified, use either two times the size of the
51 * scrolling region, or the size of the window option. POSIX
52 * 1003.2 claims that the latter is correct, but historic ex/vi
53 * documentation and practice appear to use the scrolling region.
54 * I'm using the window size as it means that the entire screen
55 * is used instead of losing a line to roundoff. Note, we drop
56 * a line from the cnt if using the window size to leave room for
59 if (FL_ISSET(cmdp
->iflags
, E_C_COUNT
))
62 #ifdef HISTORIC_PRACTICE
63 cnt
= O_VAL(sp
, O_SCROLL
) * 2;
65 cnt
= O_VAL(sp
, O_WINDOW
) - 1;
70 lno
= cmdp
->addr1
.lno
;
72 switch (FL_ISSET(cmdp
->iflags
,
73 E_C_CARAT
| E_C_DASH
| E_C_DOT
| E_C_EQUAL
| E_C_PLUS
)) {
74 case E_C_CARAT
: /* Display cnt * 2 before the line. */
77 cmdp
->addr1
.lno
= (lno
- cnt
* 2) + 1;
80 cmdp
->addr2
.lno
= (cmdp
->addr1
.lno
+ cnt
) - 1;
82 case E_C_DASH
: /* Line goes at the bottom of the screen. */
83 cmdp
->addr1
.lno
= lno
> cnt
? (lno
- cnt
) + 1 : 1;
84 cmdp
->addr2
.lno
= lno
;
86 case E_C_DOT
: /* Line goes in the middle of the screen. */
89 * Historically, the "middleness" of the line overrode the
90 * count, so that "3z.19" or "3z.20" would display the first
91 * 12 lines of the file, i.e. (N - 1) / 2 lines before and
92 * after the specified line.
96 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
97 cmdp
->addr2
.lno
= lno
+ cnt
;
101 * Historically, z. set the absolute cursor mark.
105 (void)mark_set(sp
, ABSMARK1
, &abm
, 1);
107 case E_C_EQUAL
: /* Center with hyphens. */
110 * Strangeness. The '=' flag is like the '.' flag (see the
111 * above comment, it applies here as well) but with a special
112 * little hack. Print out lines of hyphens before and after
113 * the specified line. Additionally, the cursor remains set
118 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
119 cmdp
->addr2
.lno
= lno
- 1;
122 (void)ex_puts(sp
, "----------------------------------------\n");
123 cmdp
->addr2
.lno
= cmdp
->addr1
.lno
= equals
= lno
;
126 (void)ex_puts(sp
, "----------------------------------------\n");
127 cmdp
->addr1
.lno
= lno
+ 1;
128 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
131 /* If no line specified, move to the next one. */
132 if (F_ISSET(cmdp
, E_ADDR_DEF
))
135 case E_C_PLUS
: /* Line goes at the top of the screen. */
137 cmdp
->addr1
.lno
= lno
;
138 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
143 if (db_last(sp
, &lno
))
145 if (cmdp
->addr2
.lno
> lno
)
146 cmdp
->addr2
.lno
= lno
;