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(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 cnt
= O_VAL(sp
, O_WINDOW
) - 1;
61 lno
= cmdp
->addr1
.lno
;
63 switch (FL_ISSET(cmdp
->iflags
,
64 E_C_CARAT
| E_C_DASH
| E_C_DOT
| E_C_EQUAL
| E_C_PLUS
)) {
65 case E_C_CARAT
: /* Display cnt * 2 before the line. */
68 cmdp
->addr1
.lno
= (lno
- cnt
* 2) + 1;
71 cmdp
->addr2
.lno
= (cmdp
->addr1
.lno
+ cnt
) - 1;
73 case E_C_DASH
: /* Line goes at the bottom of the screen. */
74 cmdp
->addr1
.lno
= lno
> cnt
? (lno
- cnt
) + 1 : 1;
75 cmdp
->addr2
.lno
= lno
;
77 case E_C_DOT
: /* Line goes in the middle of the screen. */
80 * Historically, the "middleness" of the line overrode the
81 * count, so that "3z.19" or "3z.20" would display the first
82 * 12 lines of the file, i.e. (N - 1) / 2 lines before and
83 * after the specified line.
87 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
88 cmdp
->addr2
.lno
= lno
+ cnt
;
92 * Historically, z. set the absolute cursor mark.
96 (void)mark_set(sp
, ABSMARK1
, &abs
, 1);
98 case E_C_EQUAL
: /* Center with hyphens. */
101 * Strangeness. The '=' flag is like the '.' flag (see the
102 * above comment, it applies here as well) but with a special
103 * little hack. Print out lines of hyphens before and after
104 * the specified line. Additionally, the cursor remains set
109 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
110 cmdp
->addr2
.lno
= lno
- 1;
113 (void)ex_puts(sp
, "----------------------------------------\n");
114 cmdp
->addr2
.lno
= cmdp
->addr1
.lno
= equals
= lno
;
117 (void)ex_puts(sp
, "----------------------------------------\n");
118 cmdp
->addr1
.lno
= lno
+ 1;
119 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
122 /* If no line specified, move to the next one. */
123 if (F_ISSET(cmdp
, E_ADDR_DEF
))
126 case E_C_PLUS
: /* Line goes at the top of the screen. */
128 cmdp
->addr1
.lno
= lno
;
129 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
134 if (db_last(sp
, &lno
))
136 if (cmdp
->addr2
.lno
> lno
)
137 cmdp
->addr2
.lno
= lno
;