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[] = "@(#)vs_smap.c 10.25 (Berkeley) 7/12/96";
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 *, recno_t));
32 static int vs_sm_down __P((SCR *, MARK *, recno_t, scroll_t, SMAP *));
33 static int vs_sm_erase __P((SCR *));
34 static int vs_sm_insert __P((SCR *, recno_t));
35 static int vs_sm_reset __P((SCR *, recno_t));
36 static int vs_sm_up __P((SCR *, MARK *, recno_t, scroll_t, SMAP *));
40 * Make a change to the screen.
42 * PUBLIC: int vs_change __P((SCR *, 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 || op == LINE_INSERT && lno == 1) &&
73 /* Appending is the same as inserting, if the line is incremented. */
74 if (op == LINE_APPEND) {
79 /* Ignore the change if the line is after the map. */
84 * If the line is before the map, and it's a decrement, decrement
85 * the map. If it's an increment, increment the map. Otherwise,
88 if (lno < HMAP->lno) {
94 for (p = HMAP, cnt = sp->t_rows; cnt--; ++p)
98 F_SET(vip, VIP_N_RENUMBER);
101 for (p = HMAP, cnt = sp->t_rows; cnt--; ++p)
105 F_SET(vip, VIP_N_RENUMBER);
113 F_SET(vip, VIP_N_REFRESH);
116 * Invalidate the line size cache, and invalidate the cursor if it's
121 F_SET(vip, VIP_CUR_INVALID);
124 * If ex modifies the screen after ex output is already on the screen
125 * or if we've switched into ex canonical mode, don't touch it -- we'll
126 * get scrolling wrong, at best.
128 if (!F_ISSET(sp, SC_TINPUT_INFO) &&
129 (F_ISSET(sp, SC_SCR_EXWROTE) || VIP(sp)->totalcount > 1)) {
130 F_SET(vip, VIP_N_EX_REDRAW);
134 /* Save and restore the cursor for these routines. */
135 (void)sp->gp->scr_cursor(sp, &oldy, &oldx);
139 if (vs_sm_delete(sp, lno))
141 F_SET(vip, VIP_N_RENUMBER);
144 if (vs_sm_insert(sp, lno))
146 F_SET(vip, VIP_N_RENUMBER);
149 if (vs_sm_reset(sp, lno))
156 (void)sp->gp->scr_move(sp, oldy, oldx);
162 * Fill in the screen map, placing the specified line at the
163 * right position. There isn't any way to tell if an SMAP
164 * entry has been filled in, so this routine had better be
165 * called with P_FILL set before anything else is done.
168 * Unexported interface: if lno is OOBLNO, P_TOP means that the HMAP
169 * slot is already filled in, P_BOTTOM means that the TMAP slot is
170 * already filled in, and we just finish up the job.
172 * PUBLIC: int vs_sm_fill __P((SCR *, recno_t, pos_t));
175 vs_sm_fill(sp, lno, pos)
183 /* Flush all cached information from the SMAP. */
184 for (p = HMAP, cnt = sp->t_rows; cnt--; ++p)
188 * If the map is filled, the screen must be redrawn.
191 * This is a bug. We should try and figure out if the desired line
192 * is already in the map or close by -- scrolling the screen would
193 * be a lot better than redrawing.
195 F_SET(sp, SC_SCR_REDRAW);
203 /* See if less than half a screen from the top. */
205 &tmp, lno, HALFTEXT(sp)) <= HALFTEXT(sp)) {
210 /* See if less than half a screen from the bottom. */
211 if (db_last(sp, &tmp.lno))
214 tmp.soff = vs_screens(sp, tmp.lno, NULL);
216 &tmp, lno, HALFTEXT(sp)) <= HALFTEXT(sp)) {
218 TMAP->coff = tmp.coff;
219 TMAP->soff = tmp.soff;
225 top: HMAP->lno = lno;
229 /* If we fail, just punt. */
230 for (p = HMAP, cnt = sp->t_rows; --cnt; ++p)
231 if (vs_sm_next(sp, p, p + 1))
235 /* If we fail, guess that the file is too small. */
236 middle: p = HMAP + sp->t_rows / 2;
240 for (; p > HMAP; --p)
241 if (vs_sm_prev(sp, p, p - 1)) {
246 /* If we fail, just punt. */
247 p = HMAP + sp->t_rows / 2;
248 for (; p < TMAP; ++p)
249 if (vs_sm_next(sp, p, p + 1))
256 TMAP->soff = vs_screens(sp, lno, NULL);
258 /* If we fail, guess that the file is too small. */
259 bottom: for (p = TMAP; p > HMAP; --p)
260 if (vs_sm_prev(sp, p, p - 1)) {
271 * Try and put *something* on the screen. If this fails, we have a
272 * serious hard error.
277 for (p = HMAP; p < TMAP; ++p)
278 if (vs_sm_next(sp, p, p + 1))
284 * For the routines vs_sm_reset, vs_sm_delete and vs_sm_insert: if the
285 * screen contains only a single line (whether because the screen is small
286 * or the line large), it gets fairly exciting. Skip the fun, set a flag
287 * so the screen map is refilled and the screen redrawn, and return. This
288 * is amazingly slow, but it's not clear that anyone will care.
290 #define HANDLE_WEIRDNESS(cnt) { \
291 if (cnt >= sp->t_rows) { \
292 F_SET(sp, SC_SCR_REFORMAT); \
299 * Delete a line out of the SMAP.
302 vs_sm_delete(sp, lno)
310 * Find the line in the map, and count the number of screen lines
311 * which display any part of the deleted line.
313 for (p = HMAP; p->lno != lno; ++p);
314 if (O_ISSET(sp, O_LEFTRIGHT))
317 for (cnt_orig = 1, t = p + 1;
318 t <= TMAP && t->lno == lno; ++cnt_orig, ++t);
320 HANDLE_WEIRDNESS(cnt_orig);
322 /* Delete that many lines from the screen. */
323 (void)sp->gp->scr_move(sp, p - HMAP, 0);
324 if (vs_deleteln(sp, cnt_orig))
327 /* Shift the screen map up. */
328 memmove(p, p + cnt_orig, (((TMAP - p) - cnt_orig) + 1) * sizeof(SMAP));
330 /* Decrement the line numbers for the rest of the map. */
331 for (t = TMAP - cnt_orig; p <= t; ++p)
334 /* Display the new lines. */
335 for (p = TMAP - cnt_orig;;) {
336 if (p < TMAP && vs_sm_next(sp, p, p + 1))
338 /* vs_sm_next() flushed the cache. */
339 if (vs_line(sp, ++p, NULL, NULL))
349 * Insert a line into the SMAP.
352 vs_sm_insert(sp, lno)
357 size_t cnt_orig, cnt, coff;
359 /* Save the offset. */
363 * Find the line in the map, find out how many screen lines
364 * needed to display the line.
366 for (p = HMAP; p->lno != lno; ++p);
368 cnt_orig = vs_screens(sp, lno, NULL);
369 HANDLE_WEIRDNESS(cnt_orig);
372 * The lines left in the screen override the number of screen
373 * lines in the inserted line.
375 cnt = (TMAP - p) + 1;
379 /* Push down that many lines. */
380 (void)sp->gp->scr_move(sp, p - HMAP, 0);
381 if (vs_insertln(sp, cnt_orig))
384 /* Shift the screen map down. */
385 memmove(p + cnt_orig, p, (((TMAP - p) - cnt_orig) + 1) * sizeof(SMAP));
387 /* Increment the line numbers for the rest of the map. */
388 for (t = p + cnt_orig; t <= TMAP; ++t)
391 /* Fill in the SMAP for the new lines, and display. */
392 for (cnt = 1, t = p; cnt <= cnt_orig; ++t, ++cnt) {
397 if (vs_line(sp, t, NULL, NULL))
405 * Reset a line in the SMAP.
413 size_t cnt_orig, cnt_new, cnt, diff;
416 * See if the number of on-screen rows taken up by the old display
417 * for the line is the same as the number needed for the new one.
418 * If so, repaint, otherwise do it the hard way.
420 for (p = HMAP; p->lno != lno; ++p);
421 if (O_ISSET(sp, O_LEFTRIGHT)) {
423 cnt_orig = cnt_new = 1;
426 t = p; t <= TMAP && t->lno == lno; ++cnt_orig, ++t);
427 cnt_new = vs_screens(sp, lno, NULL);
430 HANDLE_WEIRDNESS(cnt_orig);
432 if (cnt_orig == cnt_new) {
435 if (vs_line(sp, p, NULL, NULL))
441 if (cnt_orig < cnt_new) {
442 /* Get the difference. */
443 diff = cnt_new - cnt_orig;
446 * The lines left in the screen override the number of screen
447 * lines in the inserted line.
449 cnt = (TMAP - p) + 1;
453 /* If there are any following lines, push them down. */
455 (void)sp->gp->scr_move(sp, p - HMAP, 0);
456 if (vs_insertln(sp, diff))
459 /* Shift the screen map down. */
461 (((TMAP - p) - diff) + 1) * sizeof(SMAP));
464 /* Fill in the SMAP for the replaced line, and display. */
465 for (cnt = 1, t = p; cnt_new-- && t <= TMAP; ++t, ++cnt) {
469 if (vs_line(sp, t, NULL, NULL))
473 /* Get the difference. */
474 diff = cnt_orig - cnt_new;
476 /* Delete that many lines from the screen. */
477 (void)sp->gp->scr_move(sp, p - HMAP, 0);
478 if (vs_deleteln(sp, diff))
481 /* Shift the screen map up. */
482 memmove(p, p + diff, (((TMAP - p) - diff) + 1) * sizeof(SMAP));
484 /* Fill in the SMAP for the replaced line, and display. */
485 for (cnt = 1, t = p; cnt_new--; ++t, ++cnt) {
489 if (vs_line(sp, t, NULL, NULL))
493 /* Display the new lines at the bottom of the screen. */
494 for (t = TMAP - diff;;) {
495 if (t < TMAP && vs_sm_next(sp, t, t + 1))
497 /* vs_sm_next() flushed the cache. */
498 if (vs_line(sp, ++t, NULL, NULL))
509 * Scroll the SMAP up/down count logical lines. Different
510 * semantics based on the vi command, *sigh*.
512 * PUBLIC: int vs_sm_scroll __P((SCR *, MARK *, recno_t, scroll_t));
515 vs_sm_scroll(sp, rp, count, scmd)
524 * Invalidate the cursor. The line is probably going to change,
525 * (although for ^E and ^Y it may not). In any case, the scroll
526 * routines move the cursor to draw things.
528 F_SET(VIP(sp), VIP_CUR_INVALID);
530 /* Find the cursor in the screen. */
531 if (vs_sm_cursor(sp, &smp))
539 if (vs_sm_down(sp, rp, count, scmd, smp))
546 if (vs_sm_up(sp, rp, count, scmd, smp))
555 * If we're at the start of a line, go for the first non-blank.
556 * This makes it look like the old vi, even though we're moving
557 * around by logical lines, not physical ones.
560 * In the presence of a long line, which has more than a screen
561 * width of leading spaces, this code can cause a cursor warp.
564 if (scmd != CNTRL_E && scmd != CNTRL_Y &&
565 rp->cno == 0 && nonblank(sp, rp->lno, &rp->cno))
573 * Scroll the SMAP up count logical lines.
576 vs_sm_up(sp, rp, count, scmd, smp)
583 int cursor_set, echanged, zset;
587 * Check to see if movement is possible.
589 * Get the line after the map. If that line is a new one (and if
590 * O_LEFTRIGHT option is set, this has to be true), and the next
591 * line doesn't exist, and the cursor doesn't move, or the cursor
592 * isn't even on the screen, or the cursor is already at the last
593 * line in the map, it's an error. If that test succeeded because
594 * the cursor wasn't at the end of the map, test to see if the map
597 if (vs_sm_next(sp, TMAP, &s1))
599 if (s1.lno > TMAP->lno && !db_exist(sp, s1.lno)) {
600 if (scmd == CNTRL_E || scmd == Z_PLUS || smp == TMAP) {
604 if (vs_sm_next(sp, smp, &s1))
606 if (s1.lno > smp->lno && !db_exist(sp, s1.lno)) {
613 * Small screens: see vs_refresh.c section 6a.
615 * If it's a small screen, and the movement isn't larger than a
616 * screen, i.e some context will remain, open up the screen and
617 * display by scrolling. In this case, the cursor moves down one
618 * line for each line displayed. Otherwise, erase/compress and
619 * repaint, and move the cursor to the first line in the screen.
620 * Note, the ^F command is always in the latter case, for historical
625 if (count >= sp->t_maxrows || scmd == CNTRL_F) {
629 for (; count--; s1 = s2) {
630 if (vs_sm_next(sp, &s1, &s2))
632 if (s2.lno != s1.lno && !db_exist(sp, s2.lno))
636 if (vs_sm_fill(sp, OOBLNO, P_BOTTOM))
638 return (vs_sm_position(sp, rp, 0, P_TOP));
640 cursor_set = scmd == CNTRL_E || vs_sm_cursor(sp, &ssmp);
642 sp->t_rows != sp->t_maxrows; --count, ++sp->t_rows) {
643 if (vs_sm_next(sp, TMAP, &s1))
645 if (TMAP->lno != s1.lno && !db_exist(sp, s1.lno))
648 /* vs_sm_next() flushed the cache. */
649 if (vs_line(sp, TMAP, NULL, NULL))
657 rp->cno = ssmp->c_sboff;
663 for (echanged = zset = 0; count; --count) {
664 /* Decide what would show up on the screen. */
665 if (vs_sm_next(sp, TMAP, &s1))
668 /* If the line doesn't exist, we're done. */
669 if (TMAP->lno != s1.lno && !db_exist(sp, s1.lno))
672 /* Scroll the screen cursor up one logical line. */
702 * On a ^E that was forced to change lines, try and keep the
703 * cursor as close as possible to the last position, but also
704 * set it up so that the next "real" movement will return the
705 * cursor to the closest position to the last real movement.
709 rp->cno = vs_colpos(sp, smp->lno,
710 (O_ISSET(sp, O_LEFTRIGHT) ?
711 smp->coff : (smp->soff - 1) * sp->cols) +
717 * If there are more lines, the ^F command is positioned at
718 * the first line of the screen.
727 * The ^D and ^F commands move the cursor towards EOF
728 * if there are more lines to move. Check to be sure
729 * the lines actually exist. (They may not if the
730 * file is smaller than the screen.)
732 for (; count; --count, ++smp)
733 if (smp == TMAP || !db_exist(sp, smp[1].lno))
737 /* The z+ command moves the cursor to the first new line. */
743 if (!SMAP_CACHE(smp) && vs_line(sp, smp, NULL, NULL))
746 rp->cno = smp->c_scoff == 255 ? 0 : smp->c_sboff;
752 * Scroll the SMAP up one.
754 * PUBLIC: int vs_sm_1up __P((SCR *));
761 * Delete the top line of the screen. Shift the screen map
762 * up and display a new line at the bottom of the screen.
764 (void)sp->gp->scr_move(sp, 0, 0);
765 if (vs_deleteln(sp, 1))
768 /* One-line screens can fail. */
769 if (IS_ONELINE(sp)) {
770 if (vs_sm_next(sp, TMAP, TMAP))
773 memmove(HMAP, HMAP + 1, (sp->rows - 1) * sizeof(SMAP));
774 if (vs_sm_next(sp, TMAP - 1, TMAP))
777 /* vs_sm_next() flushed the cache. */
778 return (vs_line(sp, TMAP, NULL, NULL));
783 * Delete a line a la curses, make sure to put the information
784 * line and other screens back.
796 (void)gp->scr_clrtoeol(sp);
798 (void)gp->scr_cursor(sp, &oldy, &oldx);
800 (void)gp->scr_deleteln(sp);
801 (void)gp->scr_move(sp, LASTLINE(sp), 0);
802 (void)gp->scr_insertln(sp);
803 (void)gp->scr_move(sp, oldy, oldx);
811 * Scroll the SMAP down count logical lines.
814 vs_sm_down(sp, rp, count, scmd, smp)
822 int cursor_set, ychanged, zset;
824 /* Check to see if movement is possible. */
825 if (HMAP->lno == 1 &&
826 (O_ISSET(sp, O_LEFTRIGHT) || HMAP->soff == 1) &&
827 (scmd == CNTRL_Y || scmd == Z_CARAT || smp == HMAP)) {
833 * Small screens: see vs_refresh.c section 6a.
835 * If it's a small screen, and the movement isn't larger than a
836 * screen, i.e some context will remain, open up the screen and
837 * display by scrolling. In this case, the cursor moves up one
838 * line for each line displayed. Otherwise, erase/compress and
839 * repaint, and move the cursor to the first line in the screen.
840 * Note, the ^B command is always in the latter case, for historical
843 cursor_set = scmd == CNTRL_Y;
845 if (count >= sp->t_maxrows || scmd == CNTRL_B) {
849 for (; count--; s1 = s2) {
850 if (vs_sm_prev(sp, &s1, &s2))
853 (O_ISSET(sp, O_LEFTRIGHT) || s2.soff == 1))
857 if (vs_sm_fill(sp, OOBLNO, P_TOP))
859 return (vs_sm_position(sp, rp, 0, P_BOTTOM));
861 cursor_set = scmd == CNTRL_Y || vs_sm_cursor(sp, &ssmp);
863 sp->t_rows != sp->t_maxrows; --count, ++sp->t_rows) {
864 if (HMAP->lno == 1 &&
865 (O_ISSET(sp, O_LEFTRIGHT) || HMAP->soff == 1))
873 rp->cno = ssmp->c_sboff;
879 for (ychanged = zset = 0; count; --count) {
880 /* If the line doesn't exist, we're done. */
881 if (HMAP->lno == 1 &&
882 (O_ISSET(sp, O_LEFTRIGHT) || HMAP->soff == 1))
885 /* Scroll the screen and cursor down one logical line. */
909 if (scmd != CNTRL_Y && cursor_set)
915 * If there are more lines, the ^B command is positioned at
916 * the last line of the screen. However, the line may not
920 for (smp = TMAP; smp > HMAP; --smp)
921 if (db_exist(sp, smp->lno))
928 * The ^B and ^U commands move the cursor towards SOF
929 * if there are more lines to move.
931 if (count < smp - HMAP)
938 * On a ^Y that was forced to change lines, try and keep the
939 * cursor as close as possible to the last position, but also
940 * set it up so that the next "real" movement will return the
941 * cursor to the closest position to the last real movement.
945 rp->cno = vs_colpos(sp, smp->lno,
946 (O_ISSET(sp, O_LEFTRIGHT) ?
947 smp->coff : (smp->soff - 1) * sp->cols) +
952 /* The z^ command moves the cursor to the first new line. */
958 if (!SMAP_CACHE(smp) && vs_line(sp, smp, NULL, NULL))
961 rp->cno = smp->c_scoff == 255 ? 0 : smp->c_sboff;
967 * Erase the small screen area for the scrolling functions.
976 (void)gp->scr_move(sp, LASTLINE(sp), 0);
977 (void)gp->scr_clrtoeol(sp);
978 for (; sp->t_rows > sp->t_minrows; --sp->t_rows, --TMAP) {
979 (void)gp->scr_move(sp, TMAP - HMAP, 0);
980 (void)gp->scr_clrtoeol(sp);
987 * Scroll the SMAP down one.
989 * PUBLIC: int vs_sm_1down __P((SCR *));
996 * Insert a line at the top of the screen. Shift the screen map
997 * down and display a new line at the top of the screen.
999 (void)sp->gp->scr_move(sp, 0, 0);
1000 if (vs_insertln(sp, 1))
1003 /* One-line screens can fail. */
1004 if (IS_ONELINE(sp)) {
1005 if (vs_sm_prev(sp, HMAP, HMAP))
1008 memmove(HMAP + 1, HMAP, (sp->rows - 1) * sizeof(SMAP));
1009 if (vs_sm_prev(sp, HMAP + 1, HMAP))
1012 /* vs_sm_prev() flushed the cache. */
1013 return (vs_line(sp, HMAP, NULL, NULL));
1018 * Insert a line a la curses, make sure to put the information
1019 * line and other screens back.
1022 vs_insertln(sp, cnt)
1030 if (IS_ONELINE(sp)) {
1031 (void)gp->scr_move(sp, LASTLINE(sp), 0);
1032 (void)gp->scr_clrtoeol(sp);
1034 (void)gp->scr_cursor(sp, &oldy, &oldx);
1036 (void)gp->scr_move(sp, LASTLINE(sp) - 1, 0);
1037 (void)gp->scr_deleteln(sp);
1038 (void)gp->scr_move(sp, oldy, oldx);
1039 (void)gp->scr_insertln(sp);
1047 * Fill in the next entry in the SMAP.
1049 * PUBLIC: int vs_sm_next __P((SCR *, SMAP *, SMAP *));
1052 vs_sm_next(sp, p, t)
1059 if (O_ISSET(sp, O_LEFTRIGHT)) {
1060 t->lno = p->lno + 1;
1063 lcnt = vs_screens(sp, p->lno, NULL);
1064 if (lcnt == p->soff) {
1065 t->lno = p->lno + 1;
1069 t->soff = p->soff + 1;
1077 * Fill in the previous entry in the SMAP.
1079 * PUBLIC: int vs_sm_prev __P((SCR *, SMAP *, SMAP *));
1082 vs_sm_prev(sp, p, t)
1087 if (O_ISSET(sp, O_LEFTRIGHT)) {
1088 t->lno = p->lno - 1;
1093 t->soff = p->soff - 1;
1095 t->lno = p->lno - 1;
1096 t->soff = vs_screens(sp, t->lno, NULL);
1099 return (t->lno == 0);
1104 * Return the SMAP entry referenced by the cursor.
1106 * PUBLIC: int vs_sm_cursor __P((SCR *, SMAP **));
1109 vs_sm_cursor(sp, smpp)
1115 /* See if the cursor is not in the map. */
1116 if (sp->lno < HMAP->lno || sp->lno > TMAP->lno)
1119 /* Find the first occurence of the line. */
1120 for (p = HMAP; p->lno != sp->lno; ++p);
1122 /* Fill in the map information until we find the right line. */
1123 for (; p <= TMAP; ++p) {
1124 /* Short lines are common and easy to detect. */
1125 if (p != TMAP && (p + 1)->lno != p->lno) {
1129 if (!SMAP_CACHE(p) && vs_line(sp, p, NULL, NULL))
1131 if (p->c_eboff >= sp->cno) {
1137 /* It was past the end of the map after all. */
1143 * Return the line/column of the top, middle or last line on the screen.
1144 * (The vi H, M and L commands.) Here because only the screen routines
1145 * know what's really out there.
1147 * PUBLIC: int vs_sm_position __P((SCR *, MARK *, u_long, pos_t));
1150 vs_sm_position(sp, rp, cnt, pos)
1163 * Historically, an invalid count to the H command failed.
1164 * We do nothing special here, just making sure that H in
1165 * an empty screen works.
1167 if (cnt > TMAP - HMAP)
1170 if (cnt && !db_exist(sp, smp->lno)) {
1171 sof: msgq(sp, M_BERR, "220|Movement past the end-of-screen");
1178 * Historically, a count to the M command was ignored.
1179 * If the screen isn't filled, find the middle of what's
1180 * real and move there.
1182 if (!db_exist(sp, TMAP->lno)) {
1183 if (db_last(sp, &last))
1185 for (smp = TMAP; smp->lno > last && smp > HMAP; --smp);
1187 smp -= (smp - HMAP) / 2;
1189 smp = (HMAP + (TMAP - HMAP) / 2) + cnt;
1194 * Historically, an invalid count to the L command failed.
1195 * If the screen isn't filled, find the bottom of what's
1196 * real and try to offset from there.
1198 if (cnt > TMAP - HMAP)
1201 if (!db_exist(sp, smp->lno)) {
1202 if (db_last(sp, &last))
1204 for (; smp->lno > last && smp > HMAP; --smp);
1205 if (cnt > smp - HMAP) {
1206 eof: msgq(sp, M_BERR,
1207 "221|Movement past the beginning-of-screen");
1217 /* Make sure that the cached information is valid. */
1218 if (!SMAP_CACHE(smp) && vs_line(sp, smp, NULL, NULL))
1221 rp->cno = smp->c_sboff;
1228 * Return the number of screen lines from an SMAP entry to the
1229 * start of some file line, less than a maximum value.
1231 * PUBLIC: recno_t vs_sm_nlines __P((SCR *, SMAP *, recno_t, size_t));
1234 vs_sm_nlines(sp, from_sp, to_lno, max)
1242 if (O_ISSET(sp, O_LEFTRIGHT))
1243 return (from_sp->lno > to_lno ?
1244 from_sp->lno - to_lno : to_lno - from_sp->lno);
1246 if (from_sp->lno == to_lno)
1247 return (from_sp->soff - 1);
1249 if (from_sp->lno > to_lno) {
1250 lcnt = from_sp->soff - 1; /* Correct for off-by-one. */
1251 for (lno = from_sp->lno; --lno >= to_lno && lcnt <= max;)
1252 lcnt += vs_screens(sp, lno, NULL);
1255 lcnt = (vs_screens(sp, lno, NULL) - from_sp->soff) + 1;
1256 for (; ++lno < to_lno && lcnt <= max;)
1257 lcnt += vs_screens(sp, lno, NULL);