* Routines which jump to a new location in the file.
extern int screen_trashed
;
extern int sc_width
, sc_height
;
* Jump to the end of the file.
error("Cannot seek to end of file", NULL_PARG
);
* Position the last line in the file at the last screen line.
* Go back one line from the end of the file
* to get to the beginning of the last line.
pos
= back_line(ch_tell());
if (pos
== NULL_POSITION
)
jump_loc((POSITION
)0, sc_height
-1);
jump_loc(pos
, sc_height
-1);
* Jump to line n in the file.
* Find the position of the specified line.
* If we can seek there, just jump to it.
* If we can't seek, but we're trying to go to line number 1,
* use ch_beg_seek() to get as close as we can.
if (pos
!= NULL_POSITION
&& ch_seek(pos
) == 0)
jump_loc(pos
, jump_sline
);
} else if (n
<= 1 && ch_beg_seek() == 0)
jump_loc(ch_tell(), jump_sline
);
error("Cannot seek to beginning of file", NULL_PARG
);
error("Cannot seek to line number %d", &parg
);
* Start at the line currently at the top of the screen
* and redisplay the screen.
jump_loc(scrpos
.pos
, scrpos
.ln
);
* Jump to a specified percentage into the file.
* Determine the position in the file
* (the specified percentage of the file's length).
if ((len
= ch_length()) == NULL_POSITION
)
error("Don't know length of file", NULL_PARG
);
* {{ This calculation may overflow! }}
pos
= (percent
* len
) / 100;
jump_line_loc(pos
, jump_sline
);
* Jump to a specified position in the file.
* Like jump_loc, but the position need not be
* the first character in a line.
jump_line_loc(pos
, sline
)
* Back up to the beginning of the line.
while ((c
= ch_back_get()) != '\n' && c
!= EOI
)
* Jump to a specified position in the file.
* The position must be the first character in a line.
* Place the target line on a specified line on the screen.
if ((nline
= onscreen(pos
)) >= 0)
* The line is currently displayed.
forw(nline
, position(BOTTOM_PLUS_ONE
), 1, 0, 0);
back(-nline
, position(TOP
), 1, 0);
* Seek to the desired location.
error("Cannot seek to that file position", NULL_PARG
);
* See if the desired line is before or after
* the currently displayed screen.
bpos
= position(BOTTOM_PLUS_ONE
);
if (tpos
== NULL_POSITION
|| pos
>= tpos
)
* The desired line is after the current screen.
* Move back in the file far enough so that we can
* call forw() and put the desired line at the
* sline-th line on the screen.
for (nline
= 0; nline
< sline
; nline
++)
if (bpos
!= NULL_POSITION
&& pos
<= bpos
)
* Surprise! The desired line is
* close enough to the current screen
* that we can just scroll there after all.
forw(sc_height
-sline
+nline
-1, bpos
, 1, 0, 0);
if (pos
== NULL_POSITION
)
* Oops. Ran into the beginning of the file.
* Exit the loop here and rely on forw()
* below to draw the required number of
* blank lines at the top of the screen.
forw(sc_height
-1, pos
, 1, 0, sline
-nline
);
* The desired line is before the current screen.
* Move forward in the file far enough so that we
* can call back() and put the desired line at the
* sline-th line on the screen.
for (nline
= sline
; nline
< sc_height
- 1; nline
++)
if (pos
== NULL_POSITION
)
error("Program error: EOI in jump_loc (forw)",
* Surprise! The desired line is
* close enough to the current screen
* that we can just scroll there after all.
back(nline
+1, tpos
, 1, 0);
back(sc_height
-1, pos
, 1, 0);