3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_z.c,v 8.4 1993/12/02 14:02:39 bostic Exp $ (Berkeley) $Date: 1993/12/02 14:02:39 $";
12 #include <sys/types.h>
21 * ex_z -- :[line] z [^-.+=] [count] [flags]
31 recno_t cnt
, equals
, lno
;
36 * If no count specified, use either two times the size of the
37 * scrolling region, or the size of the window option. POSIX
38 * 1003.2 claims that the latter is correct, but historic ex/vi
39 * documentation and practice appear to use the scrolling region.
40 * I'm using the window size as it means that the entire screen
41 * is used instead of losing a line to roundoff. Note, we drop
42 * a line from the cnt if using the window size to leave room for
45 if (F_ISSET(cmdp
, E_COUNT
))
48 #ifdef HISTORIC_PRACTICE
49 cnt
= O_VAL(sp
, O_SCROLL
) * 2;
51 cnt
= O_VAL(sp
, O_WINDOW
) - 1;
56 lno
= cmdp
->addr1
.lno
;
59 E_F_CARAT
| E_F_DASH
| E_F_DOT
| E_F_EQUAL
| E_F_PLUS
)) {
60 case E_F_CARAT
: /* Display cnt * 2 before the line. */
63 cmdp
->addr1
.lno
= (lno
- cnt
* 2) + 1;
66 cmdp
->addr2
.lno
= (cmdp
->addr1
.lno
+ cnt
) - 1;
68 case E_F_DASH
: /* Line goes at the bottom of the screen. */
69 cmdp
->addr1
.lno
= lno
> cnt
? (lno
- cnt
) + 1 : 1;
70 cmdp
->addr2
.lno
= lno
;
72 case E_F_DOT
: /* Line goes in the middle of the screen. */
75 * Historically, the "middleness" of the line overrode the
76 * count, so that "3z.19" or "3z.20" would display the first
77 * 12 lines of the file, i.e. (N - 1) / 2 lines before and
78 * after the specified line.
82 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
83 cmdp
->addr2
.lno
= lno
+ cnt
;
85 case E_F_EQUAL
: /* Center with hyphens. */
88 * Strangeness. The '=' flag is like the '.' flag (see the
89 * above comment, it applies here as well) but with a special
90 * little hack. Print out lines of hyphens before and after
91 * the specified line. Additionally, the cursor remains set
96 cmdp
->addr1
.lno
= lno
> cnt
? lno
- cnt
: 1;
97 cmdp
->addr2
.lno
= lno
- 1;
98 if (ex_pr(sp
, ep
, cmdp
))
100 (void)ex_printf(EXCOOKIE
,
101 "%s", "----------------------------------------\n");
102 cmdp
->addr2
.lno
= cmdp
->addr1
.lno
= equals
= lno
;
103 if (ex_pr(sp
, ep
, cmdp
))
105 (void)ex_printf(EXCOOKIE
,
106 "%s", "----------------------------------------\n");
107 cmdp
->addr1
.lno
= lno
+ 1;
108 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
111 /* If no line specified, move to the next one. */
112 if (F_ISSET(cmdp
, E_ADDRDEF
))
115 case E_F_PLUS
: /* Line goes at the top of the screen. */
117 cmdp
->addr1
.lno
= lno
;
118 cmdp
->addr2
.lno
= (lno
+ cnt
) - 1;
123 if (file_lline(sp
, ep
, &lno
))
125 if (cmdp
->addr2
.lno
> lno
)
126 cmdp
->addr2
.lno
= lno
;
129 if (ex_pr(sp
, ep
, cmdp
))