3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: vs_relative.c,v 8.7 1993/12/29 16:27:20 bostic Exp $ (Berkeley) $Date: 1993/12/29 16:27:20 $";
12 #include <sys/types.h>
17 #include "svi_screen.h"
21 * Return the logical column of the cursor.
24 svi_column(sp
, ep
, cp
)
31 col
= SVP(sp
)->sc_col
;
32 if (O_ISSET(sp
, O_NUMBER
))
33 col
-= O_NUMBER_LENGTH
;
40 * Return the physical column from the line that will display a
41 * character closest to the currently most attractive character
42 * position. If it's not easy, uses the underlying routine that
43 * really figures it out. It's broken into two parts because the
44 * svi_lrelative routine handles "logical" offsets, which nobody
45 * but the screen routines understand.
48 svi_relative(sp
, ep
, lno
)
55 /* First non-blank character. */
56 if (sp
->rcmflags
== RCM_FNB
) {
58 (void)nonblank(sp
, ep
, lno
, &cno
);
62 /* First character is easy, and common. */
63 if (sp
->rcmflags
!= RCM_LAST
&& sp
->rcm
== 0)
66 return (svi_lrelative(sp
, ep
, lno
, 1));
71 * Return the physical column from the line that will display a
72 * character closest to the currently most attractive character
73 * position. The offset is for the commands that move logical
74 * distances, i.e. if it's a logical scroll the closest physical
75 * distance is based on the logical line, not the physical line.
78 svi_lrelative(sp
, ep
, lno
, off
)
85 size_t len
, llen
, scno
;
89 /* Need the line to go any further. */
90 if ((lp
= file_gline(sp
, ep
, lno
, &len
)) == NULL
)
93 /* Empty lines are easy. */
97 /* Last character is easy, and common. */
98 if (sp
->rcmflags
== RCM_LAST
)
101 /* Discard logical lines. */
102 cname
= sp
->gp
->cname
;
103 listset
= O_ISSET(sp
, O_LIST
);
104 for (scno
= 0, p
= lp
, llen
= len
; --off
;) {
105 for (; len
&& scno
< sp
->cols
; --len
)
112 /* Step through the line until reach the right character. */
115 if (scno
>= sp
->rcm
) {
116 /* Get the offset of this character. */
120 * May be the next character, not this one,
121 * so check to see if we've gone too far.
124 return (len
< llen
- 1 ? len
: llen
- 1);
125 /* It's this character. */
129 /* No such character; return start of last character. */
135 * Return the physical column from the line that will display a
136 * character closest to the specified column.
139 svi_chposition(sp
, ep
, lno
, cno
)
146 size_t len
, llen
, scno
;
150 /* Need the line to go any further. */
151 if ((lp
= file_gline(sp
, ep
, lno
, &llen
)) == NULL
)
154 /* Empty lines are easy. */
158 /* Step through the line until reach the right character. */
159 cname
= sp
->gp
->cname
;
160 listset
= O_ISSET(sp
, O_LIST
);
161 for (scno
= 0, len
= llen
, p
= lp
; len
--;) {
164 /* Get the offset of this character. */
168 * May be the next character, not this one,
169 * so check to see if we've gone too far.
172 return (len
< llen
- 1 ? len
: llen
- 1);
173 /* It's this character. */
177 /* No such character; return start of last character. */