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.11 2000/04/21 19:00:38 skimo Exp $ (Berkeley) $Date: 2000/04/21 19:00:38 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
25 #include "../common/common.h"
28 * ex_z -- :[line] z [^-.+=] [count] [flags]
31 * PUBLIC: int ex_z __P((SCR *, EXCMD *));
39 db_recno_t cnt
, equals
, lno
;
46 * If no count specified, use either two times the size of the
47 * scrolling region, or the size of the window option. POSIX
48 * 1003.2 claims that the latter is correct, but historic ex/vi
49 * documentation and practice appear to use the scrolling region.
50 * I'm using the window size as it means that the entire screen
51 * is used instead of losing a line to roundoff. Note, we drop
52 * a line from the cnt if using the window size to leave room for
55 if (FL_ISSET(cmdp
->iflags
, E_C_COUNT
))
58 #ifdef HISTORIC_PRACTICE
59 cnt
= O_VAL(sp
, O_SCROLL
) * 2;
61 cnt
= O_VAL(sp
, O_WINDOW
) - 1;
66 lno
= cmdp
->addr1
.lno
;
68 switch (FL_ISSET(cmdp
->iflags
,
69 E_C_CARAT
| E_C_DASH
| E_C_DOT
| E_C_EQUAL
| E_C_PLUS
)) {
70 case E_C_CARAT
: /* Display cnt * 2 before the line. */
73 cmdp
->addr1
.lno
= (lno
- cnt
* 2) + 1;
76 cmdp
->addr2
.lno
= (cmdp
->addr1
.lno
+ cnt
) - 1;
78 case E_C_DASH
: /* Line goes at the bottom of the screen. */
79 cmdp
->addr1
.lno
= lno
> cnt
? (lno
- cnt
) + 1 : 1;
80 cmdp
->addr2
.lno
= lno
;
82 case E_C_DOT
: /* Line goes in the middle of the screen. */
85 * Historically, the "middleness" of the line overrode the
86 * count, so that "3z.19" or "3z.20" would display the first
87 * 12 lines of the file, i.e. (N - 1) / 2 lines before and
88 * after the specified line.
92 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
93 cmdp
->addr2
.lno
= lno
+ cnt
;
97 * Historically, z. set the absolute cursor mark.
101 (void)mark_set(sp
, ABSMARK1
, &abs
, 1);
103 case E_C_EQUAL
: /* Center with hyphens. */
106 * Strangeness. The '=' flag is like the '.' flag (see the
107 * above comment, it applies here as well) but with a special
108 * little hack. Print out lines of hyphens before and after
109 * the specified line. Additionally, the cursor remains set
114 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
115 cmdp
->addr2
.lno
= lno
- 1;
118 (void)ex_puts(sp
, "----------------------------------------\n");
119 cmdp
->addr2
.lno
= cmdp
->addr1
.lno
= equals
= lno
;
122 (void)ex_puts(sp
, "----------------------------------------\n");
123 cmdp
->addr1
.lno
= lno
+ 1;
124 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
127 /* If no line specified, move to the next one. */
128 if (F_ISSET(cmdp
, E_ADDR_DEF
))
131 case E_C_PLUS
: /* Line goes at the top of the screen. */
133 cmdp
->addr1
.lno
= lno
;
134 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
139 if (db_last(sp
, &lno
))
141 if (cmdp
->addr2
.lno
> lno
)
142 cmdp
->addr2
.lno
= lno
;