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: vs_smap.c,v 10.28 2000/04/30 16:36:14 skimo Exp $ (Berkeley) $Date: 2000/04/30 16:36:14 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
20 #include <bitstring.h>
26 #include "../common/common.h"
29 static int vs_deleteln
__P((SCR
*, int));
30 static int vs_insertln
__P((SCR
*, int));
31 static int vs_sm_delete
__P((SCR
*, db_recno_t
));
32 static int vs_sm_down
__P((SCR
*, MARK
*, db_recno_t
, scroll_t
, SMAP
*));
33 static int vs_sm_erase
__P((SCR
*));
34 static int vs_sm_insert
__P((SCR
*, db_recno_t
));
35 static int vs_sm_reset
__P((SCR
*, db_recno_t
));
36 static int vs_sm_up
__P((SCR
*, MARK
*, db_recno_t
, scroll_t
, SMAP
*));
40 * Make a change to the screen.
42 * PUBLIC: int vs_change __P((SCR *, db_recno_t, lnop_t));
45 vs_change(sp
, lno
, op
)
52 size_t cnt
, oldy
, oldx
;
58 * Very nasty special case. The historic vi code displays a single
59 * space (or a '$' if the list option is set) for the first line in
60 * an "empty" file. If we "insert" a line, that line gets scrolled
61 * down, not repainted, so it's incorrect when we refresh the screen.
62 * The vi text input functions detect it explicitly and don't insert
65 * Check for line #2 before going to the end of the file.
67 if (((op
== LINE_APPEND
&& lno
== 0) ||
68 (op
== LINE_INSERT
&& lno
== 1)) &&
74 /* Appending is the same as inserting, if the line is incremented. */
75 if (op
== LINE_APPEND
) {
80 /* Ignore the change if the line is after the map. */
85 * If the line is before the map, and it's a decrement, decrement
86 * the map. If it's an increment, increment the map. Otherwise,
89 if (lno
< HMAP
->lno
) {
95 for (p
= HMAP
, cnt
= sp
->t_rows
; cnt
--; ++p
)
99 F_SET(vip
, VIP_N_RENUMBER
);
102 for (p
= HMAP
, cnt
= sp
->t_rows
; cnt
--; ++p
)
106 F_SET(vip
, VIP_N_RENUMBER
);
114 F_SET(vip
, VIP_N_REFRESH
);
117 * Invalidate the line size cache, and invalidate the cursor if it's
122 F_SET(vip
, VIP_CUR_INVALID
);
125 * If ex modifies the screen after ex output is already on the screen
126 * or if we've switched into ex canonical mode, don't touch it -- we'll
127 * get scrolling wrong, at best.
129 if (!F_ISSET(sp
, SC_TINPUT_INFO
) &&
130 (F_ISSET(sp
, SC_SCR_EXWROTE
) || VIP(sp
)->totalcount
> 1)) {
131 F_SET(vip
, VIP_N_EX_REDRAW
);
135 /* Save and restore the cursor for these routines. */
136 (void)sp
->gp
->scr_cursor(sp
, &oldy
, &oldx
);
140 if (vs_sm_delete(sp
, lno
))
144 F_SET(vip
, VIP_N_RENUMBER
);
147 if (vs_sm_insert(sp
, lno
))
151 F_SET(vip
, VIP_N_RENUMBER
);
154 if (vs_sm_reset(sp
, lno
))
161 (void)sp
->gp
->scr_move(sp
, oldy
, oldx
);
167 * Fill in the screen map, placing the specified line at the
168 * right position. There isn't any way to tell if an SMAP
169 * entry has been filled in, so this routine had better be
170 * called with P_FILL set before anything else is done.
173 * Unexported interface: if lno is OOBLNO, P_TOP means that the HMAP
174 * slot is already filled in, P_BOTTOM means that the TMAP slot is
175 * already filled in, and we just finish up the job.
177 * PUBLIC: int vs_sm_fill __P((SCR *, db_recno_t, pos_t));
180 vs_sm_fill(sp
, lno
, pos
)
188 /* Flush all cached information from the SMAP. */
189 for (p
= HMAP
, cnt
= sp
->t_rows
; cnt
--; ++p
)
193 * If the map is filled, the screen must be redrawn.
196 * This is a bug. We should try and figure out if the desired line
197 * is already in the map or close by -- scrolling the screen would
198 * be a lot better than redrawing.
200 F_SET(sp
, SC_SCR_REDRAW
);
208 /* See if less than half a screen from the top. */
210 &tmp
, lno
, HALFTEXT(sp
)) <= HALFTEXT(sp
)) {
215 /* See if less than half a screen from the bottom. */
216 if (db_last(sp
, &tmp
.lno
))
219 tmp
.soff
= vs_screens(sp
, tmp
.lno
, NULL
);
221 &tmp
, lno
, HALFTEXT(sp
)) <= HALFTEXT(sp
)) {
223 TMAP
->coff
= tmp
.coff
;
224 TMAP
->soff
= tmp
.soff
;
230 top
: HMAP
->lno
= lno
;
234 /* If we fail, just punt. */
235 for (p
= HMAP
, cnt
= sp
->t_rows
; --cnt
; ++p
)
236 if (vs_sm_next(sp
, p
, p
+ 1))
240 /* If we fail, guess that the file is too small. */
241 middle
: p
= HMAP
+ sp
->t_rows
/ 2;
245 for (; p
> HMAP
; --p
)
246 if (vs_sm_prev(sp
, p
, p
- 1)) {
251 /* If we fail, just punt. */
252 p
= HMAP
+ sp
->t_rows
/ 2;
253 for (; p
< TMAP
; ++p
)
254 if (vs_sm_next(sp
, p
, p
+ 1))
261 TMAP
->soff
= vs_screens(sp
, lno
, NULL
);
263 /* If we fail, guess that the file is too small. */
264 bottom
: for (p
= TMAP
; p
> HMAP
; --p
)
265 if (vs_sm_prev(sp
, p
, p
- 1)) {
276 * Try and put *something* on the screen. If this fails, we have a
277 * serious hard error.
282 for (p
= HMAP
; p
< TMAP
; ++p
)
283 if (vs_sm_next(sp
, p
, p
+ 1))
289 * For the routines vs_sm_reset, vs_sm_delete and vs_sm_insert: if the
290 * screen contains only a single line (whether because the screen is small
291 * or the line large), it gets fairly exciting. Skip the fun, set a flag
292 * so the screen map is refilled and the screen redrawn, and return. This
293 * is amazingly slow, but it's not clear that anyone will care.
295 #define HANDLE_WEIRDNESS(cnt) { \
296 if (cnt >= sp->t_rows) { \
297 F_SET(sp, SC_SCR_REFORMAT); \
304 * Delete a line out of the SMAP.
307 vs_sm_delete(sp
, lno
)
315 * Find the line in the map, and count the number of screen lines
316 * which display any part of the deleted line.
318 for (p
= HMAP
; p
->lno
!= lno
; ++p
);
319 if (O_ISSET(sp
, O_LEFTRIGHT
))
322 for (cnt_orig
= 1, t
= p
+ 1;
323 t
<= TMAP
&& t
->lno
== lno
; ++cnt_orig
, ++t
);
325 HANDLE_WEIRDNESS(cnt_orig
);
327 /* Delete that many lines from the screen. */
328 (void)sp
->gp
->scr_move(sp
, p
- HMAP
, 0);
329 if (vs_deleteln(sp
, cnt_orig
))
332 /* Shift the screen map up. */
333 memmove(p
, p
+ cnt_orig
, (((TMAP
- p
) - cnt_orig
) + 1) * sizeof(SMAP
));
335 /* Decrement the line numbers for the rest of the map. */
336 for (t
= TMAP
- cnt_orig
; p
<= t
; ++p
)
339 /* Display the new lines. */
340 for (p
= TMAP
- cnt_orig
;;) {
341 if (p
< TMAP
&& vs_sm_next(sp
, p
, p
+ 1))
343 /* vs_sm_next() flushed the cache. */
344 if (vs_line(sp
, ++p
, NULL
, NULL
))
354 * Insert a line into the SMAP.
357 vs_sm_insert(sp
, lno
)
362 size_t cnt_orig
, cnt
, coff
;
364 /* Save the offset. */
368 * Find the line in the map, find out how many screen lines
369 * needed to display the line.
371 for (p
= HMAP
; p
->lno
!= lno
; ++p
);
373 cnt_orig
= vs_screens(sp
, lno
, NULL
);
374 HANDLE_WEIRDNESS(cnt_orig
);
377 * The lines left in the screen override the number of screen
378 * lines in the inserted line.
380 cnt
= (TMAP
- p
) + 1;
384 /* Push down that many lines. */
385 (void)sp
->gp
->scr_move(sp
, p
- HMAP
, 0);
386 if (vs_insertln(sp
, cnt_orig
))
389 /* Shift the screen map down. */
390 memmove(p
+ cnt_orig
, p
, (((TMAP
- p
) - cnt_orig
) + 1) * sizeof(SMAP
));
392 /* Increment the line numbers for the rest of the map. */
393 for (t
= p
+ cnt_orig
; t
<= TMAP
; ++t
)
396 /* Fill in the SMAP for the new lines, and display. */
397 for (cnt
= 1, t
= p
; cnt
<= cnt_orig
; ++t
, ++cnt
) {
402 if (vs_line(sp
, t
, NULL
, NULL
))
410 * Reset a line in the SMAP.
418 size_t cnt_orig
, cnt_new
, cnt
, diff
;
421 * See if the number of on-screen rows taken up by the old display
422 * for the line is the same as the number needed for the new one.
423 * If so, repaint, otherwise do it the hard way.
425 for (p
= HMAP
; p
->lno
!= lno
; ++p
);
426 if (O_ISSET(sp
, O_LEFTRIGHT
)) {
428 cnt_orig
= cnt_new
= 1;
431 t
= p
; t
<= TMAP
&& t
->lno
== lno
; ++cnt_orig
, ++t
);
432 cnt_new
= vs_screens(sp
, lno
, NULL
);
435 HANDLE_WEIRDNESS(cnt_orig
);
437 if (cnt_orig
== cnt_new
) {
440 if (vs_line(sp
, p
, NULL
, NULL
))
446 if (cnt_orig
< cnt_new
) {
447 /* Get the difference. */
448 diff
= cnt_new
- cnt_orig
;
451 * The lines left in the screen override the number of screen
452 * lines in the inserted line.
454 cnt
= (TMAP
- p
) + 1;
458 /* If there are any following lines, push them down. */
460 (void)sp
->gp
->scr_move(sp
, p
- HMAP
, 0);
461 if (vs_insertln(sp
, diff
))
464 /* Shift the screen map down. */
466 (((TMAP
- p
) - diff
) + 1) * sizeof(SMAP
));
469 /* Fill in the SMAP for the replaced line, and display. */
470 for (cnt
= 1, t
= p
; cnt_new
-- && t
<= TMAP
; ++t
, ++cnt
) {
474 if (vs_line(sp
, t
, NULL
, NULL
))
478 /* Get the difference. */
479 diff
= cnt_orig
- cnt_new
;
481 /* Delete that many lines from the screen. */
482 (void)sp
->gp
->scr_move(sp
, p
- HMAP
, 0);
483 if (vs_deleteln(sp
, diff
))
486 /* Shift the screen map up. */
487 memmove(p
, p
+ diff
, (((TMAP
- p
) - diff
) + 1) * sizeof(SMAP
));
489 /* Fill in the SMAP for the replaced line, and display. */
490 for (cnt
= 1, t
= p
; cnt_new
--; ++t
, ++cnt
) {
494 if (vs_line(sp
, t
, NULL
, NULL
))
498 /* Display the new lines at the bottom of the screen. */
499 for (t
= TMAP
- diff
;;) {
500 if (t
< TMAP
&& vs_sm_next(sp
, t
, t
+ 1))
502 /* vs_sm_next() flushed the cache. */
503 if (vs_line(sp
, ++t
, NULL
, NULL
))
514 * Scroll the SMAP up/down count logical lines. Different
515 * semantics based on the vi command, *sigh*.
517 * PUBLIC: int vs_sm_scroll __P((SCR *, MARK *, db_recno_t, scroll_t));
520 vs_sm_scroll(sp
, rp
, count
, scmd
)
529 * Invalidate the cursor. The line is probably going to change,
530 * (although for ^E and ^Y it may not). In any case, the scroll
531 * routines move the cursor to draw things.
533 F_SET(VIP(sp
), VIP_CUR_INVALID
);
535 /* Find the cursor in the screen. */
536 if (vs_sm_cursor(sp
, &smp
))
544 if (vs_sm_down(sp
, rp
, count
, scmd
, smp
))
551 if (vs_sm_up(sp
, rp
, count
, scmd
, smp
))
560 * If we're at the start of a line, go for the first non-blank.
561 * This makes it look like the old vi, even though we're moving
562 * around by logical lines, not physical ones.
565 * In the presence of a long line, which has more than a screen
566 * width of leading spaces, this code can cause a cursor warp.
569 if (scmd
!= CNTRL_E
&& scmd
!= CNTRL_Y
&&
570 rp
->cno
== 0 && nonblank(sp
, rp
->lno
, &rp
->cno
))
578 * Scroll the SMAP up count logical lines.
581 vs_sm_up(sp
, rp
, count
, scmd
, smp
)
588 int cursor_set
, echanged
, zset
;
592 * Check to see if movement is possible.
594 * Get the line after the map. If that line is a new one (and if
595 * O_LEFTRIGHT option is set, this has to be true), and the next
596 * line doesn't exist, and the cursor doesn't move, or the cursor
597 * isn't even on the screen, or the cursor is already at the last
598 * line in the map, it's an error. If that test succeeded because
599 * the cursor wasn't at the end of the map, test to see if the map
602 if (vs_sm_next(sp
, TMAP
, &s1
))
604 if (s1
.lno
> TMAP
->lno
&& !db_exist(sp
, s1
.lno
)) {
605 if (scmd
== CNTRL_E
|| scmd
== Z_PLUS
|| smp
== TMAP
) {
609 if (vs_sm_next(sp
, smp
, &s1
))
611 if (s1
.lno
> smp
->lno
&& !db_exist(sp
, s1
.lno
)) {
618 * Small screens: see vs_refresh.c section 6a.
620 * If it's a small screen, and the movement isn't larger than a
621 * screen, i.e some context will remain, open up the screen and
622 * display by scrolling. In this case, the cursor moves down one
623 * line for each line displayed. Otherwise, erase/compress and
624 * repaint, and move the cursor to the first line in the screen.
625 * Note, the ^F command is always in the latter case, for historical
630 if (count
>= sp
->t_maxrows
|| scmd
== CNTRL_F
) {
634 for (; count
--; s1
= s2
) {
635 if (vs_sm_next(sp
, &s1
, &s2
))
637 if (s2
.lno
!= s1
.lno
&& !db_exist(sp
, s2
.lno
))
641 if (vs_sm_fill(sp
, OOBLNO
, P_BOTTOM
))
643 return (vs_sm_position(sp
, rp
, 0, P_TOP
));
645 cursor_set
= scmd
== CNTRL_E
|| vs_sm_cursor(sp
, &ssmp
);
647 sp
->t_rows
!= sp
->t_maxrows
; --count
, ++sp
->t_rows
) {
648 if (vs_sm_next(sp
, TMAP
, &s1
))
650 if (TMAP
->lno
!= s1
.lno
&& !db_exist(sp
, s1
.lno
))
653 /* vs_sm_next() flushed the cache. */
654 if (vs_line(sp
, TMAP
, NULL
, NULL
))
662 rp
->cno
= ssmp
->c_sboff
;
668 for (echanged
= zset
= 0; count
; --count
) {
669 /* Decide what would show up on the screen. */
670 if (vs_sm_next(sp
, TMAP
, &s1
))
673 /* If the line doesn't exist, we're done. */
674 if (TMAP
->lno
!= s1
.lno
&& !db_exist(sp
, s1
.lno
))
677 /* Scroll the screen cursor up one logical line. */
707 * On a ^E that was forced to change lines, try and keep the
708 * cursor as close as possible to the last position, but also
709 * set it up so that the next "real" movement will return the
710 * cursor to the closest position to the last real movement.
714 rp
->cno
= vs_colpos(sp
, smp
->lno
,
715 (O_ISSET(sp
, O_LEFTRIGHT
) ?
716 smp
->coff
: (smp
->soff
- 1) * sp
->cols
) +
722 * If there are more lines, the ^F command is positioned at
723 * the first line of the screen.
732 * The ^D and ^F commands move the cursor towards EOF
733 * if there are more lines to move. Check to be sure
734 * the lines actually exist. (They may not if the
735 * file is smaller than the screen.)
737 for (; count
; --count
, ++smp
)
738 if (smp
== TMAP
|| !db_exist(sp
, smp
[1].lno
))
742 /* The z+ command moves the cursor to the first new line. */
748 if (!SMAP_CACHE(smp
) && vs_line(sp
, smp
, NULL
, NULL
))
751 rp
->cno
= smp
->c_sboff
;
757 * Scroll the SMAP up one.
759 * PUBLIC: int vs_sm_1up __P((SCR *));
766 * Delete the top line of the screen. Shift the screen map
767 * up and display a new line at the bottom of the screen.
769 (void)sp
->gp
->scr_move(sp
, 0, 0);
770 if (vs_deleteln(sp
, 1))
773 /* One-line screens can fail. */
774 if (IS_ONELINE(sp
)) {
775 if (vs_sm_next(sp
, TMAP
, TMAP
))
778 memmove(HMAP
, HMAP
+ 1, (sp
->rows
- 1) * sizeof(SMAP
));
779 if (vs_sm_next(sp
, TMAP
- 1, TMAP
))
782 /* vs_sm_next() flushed the cache. */
783 return (vs_line(sp
, TMAP
, NULL
, NULL
));
788 * Delete a line a la curses, make sure to put the information
789 * line and other screens back.
801 /* If the screen is vertically split, we can't scroll it. */
803 F_SET(sp
, SC_SCR_REDRAW
);
808 (void)gp
->scr_clrtoeol(sp
);
810 (void)gp
->scr_cursor(sp
, &oldy
, &oldx
);
812 (void)gp
->scr_deleteln(sp
);
813 (void)gp
->scr_move(sp
, LASTLINE(sp
), 0);
814 (void)gp
->scr_insertln(sp
);
815 (void)gp
->scr_move(sp
, oldy
, oldx
);
823 * Scroll the SMAP down count logical lines.
826 vs_sm_down(sp
, rp
, count
, scmd
, smp
)
834 int cursor_set
, ychanged
, zset
;
836 /* Check to see if movement is possible. */
837 if (HMAP
->lno
== 1 &&
838 (O_ISSET(sp
, O_LEFTRIGHT
) || HMAP
->soff
== 1) &&
839 (scmd
== CNTRL_Y
|| scmd
== Z_CARAT
|| smp
== HMAP
)) {
845 * Small screens: see vs_refresh.c section 6a.
847 * If it's a small screen, and the movement isn't larger than a
848 * screen, i.e some context will remain, open up the screen and
849 * display by scrolling. In this case, the cursor moves up one
850 * line for each line displayed. Otherwise, erase/compress and
851 * repaint, and move the cursor to the first line in the screen.
852 * Note, the ^B command is always in the latter case, for historical
855 cursor_set
= scmd
== CNTRL_Y
;
857 if (count
>= sp
->t_maxrows
|| scmd
== CNTRL_B
) {
861 for (; count
--; s1
= s2
) {
862 if (vs_sm_prev(sp
, &s1
, &s2
))
865 (O_ISSET(sp
, O_LEFTRIGHT
) || s2
.soff
== 1))
869 if (vs_sm_fill(sp
, OOBLNO
, P_TOP
))
871 return (vs_sm_position(sp
, rp
, 0, P_BOTTOM
));
873 cursor_set
= scmd
== CNTRL_Y
|| vs_sm_cursor(sp
, &ssmp
);
875 sp
->t_rows
!= sp
->t_maxrows
; --count
, ++sp
->t_rows
) {
876 if (HMAP
->lno
== 1 &&
877 (O_ISSET(sp
, O_LEFTRIGHT
) || HMAP
->soff
== 1))
885 rp
->cno
= ssmp
->c_sboff
;
891 for (ychanged
= zset
= 0; count
; --count
) {
892 /* If the line doesn't exist, we're done. */
893 if (HMAP
->lno
== 1 &&
894 (O_ISSET(sp
, O_LEFTRIGHT
) || HMAP
->soff
== 1))
897 /* Scroll the screen and cursor down one logical line. */
921 if (scmd
!= CNTRL_Y
&& cursor_set
)
927 * If there are more lines, the ^B command is positioned at
928 * the last line of the screen. However, the line may not
932 for (smp
= TMAP
; smp
> HMAP
; --smp
)
933 if (db_exist(sp
, smp
->lno
))
940 * The ^B and ^U commands move the cursor towards SOF
941 * if there are more lines to move.
943 if (count
< smp
- HMAP
)
950 * On a ^Y that was forced to change lines, try and keep the
951 * cursor as close as possible to the last position, but also
952 * set it up so that the next "real" movement will return the
953 * cursor to the closest position to the last real movement.
957 rp
->cno
= vs_colpos(sp
, smp
->lno
,
958 (O_ISSET(sp
, O_LEFTRIGHT
) ?
959 smp
->coff
: (smp
->soff
- 1) * sp
->cols
) +
964 /* The z^ command moves the cursor to the first new line. */
970 if (!SMAP_CACHE(smp
) && vs_line(sp
, smp
, NULL
, NULL
))
973 rp
->cno
= smp
->c_sboff
;
979 * Erase the small screen area for the scrolling functions.
988 (void)gp
->scr_move(sp
, LASTLINE(sp
), 0);
989 (void)gp
->scr_clrtoeol(sp
);
990 for (; sp
->t_rows
> sp
->t_minrows
; --sp
->t_rows
, --TMAP
) {
991 (void)gp
->scr_move(sp
, TMAP
- HMAP
, 0);
992 (void)gp
->scr_clrtoeol(sp
);
999 * Scroll the SMAP down one.
1001 * PUBLIC: int vs_sm_1down __P((SCR *));
1008 * Insert a line at the top of the screen. Shift the screen map
1009 * down and display a new line at the top of the screen.
1011 (void)sp
->gp
->scr_move(sp
, 0, 0);
1012 if (vs_insertln(sp
, 1))
1015 /* One-line screens can fail. */
1016 if (IS_ONELINE(sp
)) {
1017 if (vs_sm_prev(sp
, HMAP
, HMAP
))
1020 memmove(HMAP
+ 1, HMAP
, (sp
->rows
- 1) * sizeof(SMAP
));
1021 if (vs_sm_prev(sp
, HMAP
+ 1, HMAP
))
1024 /* vs_sm_prev() flushed the cache. */
1025 return (vs_line(sp
, HMAP
, NULL
, NULL
));
1030 * Insert a line a la curses, make sure to put the information
1031 * line and other screens back.
1034 vs_insertln(sp
, cnt
)
1043 /* If the screen is vertically split, we can't scroll it. */
1044 if (IS_VSPLIT(sp
)) {
1045 F_SET(sp
, SC_SCR_REDRAW
);
1049 if (IS_ONELINE(sp
)) {
1050 (void)gp
->scr_move(sp
, LASTLINE(sp
), 0);
1051 (void)gp
->scr_clrtoeol(sp
);
1053 (void)gp
->scr_cursor(sp
, &oldy
, &oldx
);
1055 (void)gp
->scr_move(sp
, LASTLINE(sp
) - 1, 0);
1056 (void)gp
->scr_deleteln(sp
);
1057 (void)gp
->scr_move(sp
, oldy
, oldx
);
1058 (void)gp
->scr_insertln(sp
);
1066 * Fill in the next entry in the SMAP.
1068 * PUBLIC: int vs_sm_next __P((SCR *, SMAP *, SMAP *));
1071 vs_sm_next(sp
, p
, t
)
1078 if (O_ISSET(sp
, O_LEFTRIGHT
)) {
1079 t
->lno
= p
->lno
+ 1;
1082 lcnt
= vs_screens(sp
, p
->lno
, NULL
);
1083 if (lcnt
== p
->soff
) {
1084 t
->lno
= p
->lno
+ 1;
1088 t
->soff
= p
->soff
+ 1;
1096 * Fill in the previous entry in the SMAP.
1098 * PUBLIC: int vs_sm_prev __P((SCR *, SMAP *, SMAP *));
1101 vs_sm_prev(sp
, p
, t
)
1106 if (O_ISSET(sp
, O_LEFTRIGHT
)) {
1107 t
->lno
= p
->lno
- 1;
1112 t
->soff
= p
->soff
- 1;
1114 t
->lno
= p
->lno
- 1;
1115 t
->soff
= vs_screens(sp
, t
->lno
, NULL
);
1118 return (t
->lno
== 0);
1123 * Return the SMAP entry referenced by the cursor.
1125 * PUBLIC: int vs_sm_cursor __P((SCR *, SMAP **));
1128 vs_sm_cursor(sp
, smpp
)
1134 /* See if the cursor is not in the map. */
1135 if (sp
->lno
< HMAP
->lno
|| sp
->lno
> TMAP
->lno
)
1138 /* Find the first occurence of the line. */
1139 for (p
= HMAP
; p
->lno
!= sp
->lno
; ++p
);
1141 /* Fill in the map information until we find the right line. */
1142 for (; p
<= TMAP
; ++p
) {
1143 /* Short lines are common and easy to detect. */
1144 if (p
!= TMAP
&& (p
+ 1)->lno
!= p
->lno
) {
1148 if (!SMAP_CACHE(p
) && vs_line(sp
, p
, NULL
, NULL
))
1150 if (p
->c_eboff
>= sp
->cno
) {
1156 /* It was past the end of the map after all. */
1162 * Return the line/column of the top, middle or last line on the screen.
1163 * (The vi H, M and L commands.) Here because only the screen routines
1164 * know what's really out there.
1166 * PUBLIC: int vs_sm_position __P((SCR *, MARK *, u_long, pos_t));
1169 vs_sm_position(sp
, rp
, cnt
, pos
)
1182 * Historically, an invalid count to the H command failed.
1183 * We do nothing special here, just making sure that H in
1184 * an empty screen works.
1186 if (cnt
> TMAP
- HMAP
)
1189 if (cnt
&& !db_exist(sp
, smp
->lno
)) {
1190 sof
: msgq(sp
, M_BERR
, "220|Movement past the end-of-screen");
1197 * Historically, a count to the M command was ignored.
1198 * If the screen isn't filled, find the middle of what's
1199 * real and move there.
1201 if (!db_exist(sp
, TMAP
->lno
)) {
1202 if (db_last(sp
, &last
))
1204 for (smp
= TMAP
; smp
->lno
> last
&& smp
> HMAP
; --smp
);
1206 smp
-= (smp
- HMAP
) / 2;
1208 smp
= (HMAP
+ (TMAP
- HMAP
) / 2) + cnt
;
1213 * Historically, an invalid count to the L command failed.
1214 * If the screen isn't filled, find the bottom of what's
1215 * real and try to offset from there.
1217 if (cnt
> TMAP
- HMAP
)
1220 if (!db_exist(sp
, smp
->lno
)) {
1221 if (db_last(sp
, &last
))
1223 for (; smp
->lno
> last
&& smp
> HMAP
; --smp
);
1224 if (cnt
> smp
- HMAP
) {
1225 eof
: msgq(sp
, M_BERR
,
1226 "221|Movement past the beginning-of-screen");
1236 /* Make sure that the cached information is valid. */
1237 if (!SMAP_CACHE(smp
) && vs_line(sp
, smp
, NULL
, NULL
))
1240 rp
->cno
= smp
->c_sboff
;
1247 * Return the number of screen lines from an SMAP entry to the
1248 * start of some file line, less than a maximum value.
1250 * PUBLIC: db_recno_t vs_sm_nlines __P((SCR *, SMAP *, db_recno_t, size_t));
1253 vs_sm_nlines(sp
, from_sp
, to_lno
, max
)
1259 db_recno_t lno
, lcnt
;
1261 if (O_ISSET(sp
, O_LEFTRIGHT
))
1262 return (from_sp
->lno
> to_lno
?
1263 from_sp
->lno
- to_lno
: to_lno
- from_sp
->lno
);
1265 if (from_sp
->lno
== to_lno
)
1266 return (from_sp
->soff
- 1);
1268 if (from_sp
->lno
> to_lno
) {
1269 lcnt
= from_sp
->soff
- 1; /* Correct for off-by-one. */
1270 for (lno
= from_sp
->lno
; --lno
>= to_lno
&& lcnt
<= max
;)
1271 lcnt
+= vs_screens(sp
, lno
, NULL
);
1274 lcnt
= (vs_screens(sp
, lno
, NULL
) - from_sp
->soff
) + 1;
1275 for (; ++lno
< to_lno
&& lcnt
<= max
;)
1276 lcnt
+= vs_screens(sp
, lno
, NULL
);