2 * Routines which jump to a new location in the file.
11 extern int screen_trashed;
12 extern int sc_width, sc_height;
15 * Jump to the end of the file.
24 error("Cannot seek to end of file", NULL_PARG);
28 * Position the last line in the file at the last screen line.
29 * Go back one line from the end of the file
30 * to get to the beginning of the last line.
32 pos = back_line(ch_tell());
33 if (pos == NULL_POSITION)
34 jump_loc((POSITION)0, sc_height-1);
36 jump_loc(pos, sc_height-1);
40 * Jump to line n in the file.
50 * Find the position of the specified line.
51 * If we can seek there, just jump to it.
52 * If we can't seek, but we're trying to go to line number 1,
53 * use ch_beg_seek() to get as close as we can.
56 if (pos != NULL_POSITION && ch_seek(pos) == 0)
58 jump_loc(pos, jump_sline);
59 } else if (n <= 1 && ch_beg_seek() == 0)
61 jump_loc(ch_tell(), jump_sline);
62 error("Cannot seek to beginning of file", NULL_PARG);
66 error("Cannot seek to line number %d", &parg);
78 * Start at the line currently at the top of the screen
79 * and redisplay the screen.
83 jump_loc(scrpos.pos, scrpos.ln);
87 * Jump to a specified percentage into the file.
96 * Determine the position in the file
97 * (the specified percentage of the file's length).
99 if ((len = ch_length()) == NULL_POSITION)
101 error("Don't know length of file", NULL_PARG);
105 * {{ This calculation may overflow! }}
107 pos = (percent * len) / 100;
111 jump_line_loc(pos, jump_sline);
115 * Jump to a specified position in the file.
116 * Like jump_loc, but the position need not be
117 * the first character in a line.
120 jump_line_loc(pos, sline)
126 if (ch_seek(pos) == 0)
129 * Back up to the beginning of the line.
131 while ((c = ch_back_get()) != '\n' && c != EOI)
134 (void) ch_forw_get();
137 jump_loc(pos, sline);
141 * Jump to a specified position in the file.
142 * The position must be the first character in a line.
143 * Place the target line on a specified line on the screen.
157 sline = adjsline(sline);
159 if ((nline = onscreen(pos)) >= 0)
162 * The line is currently displayed.
167 forw(nline, position(BOTTOM_PLUS_ONE), 1, 0, 0);
169 back(-nline, position(TOP), 1, 0);
174 * Line is not on screen.
175 * Seek to the desired location.
179 error("Cannot seek to that file position", NULL_PARG);
184 * See if the desired line is before or after
185 * the currently displayed screen.
187 tpos = position(TOP);
188 bpos = position(BOTTOM_PLUS_ONE);
189 if (tpos == NULL_POSITION || pos >= tpos)
192 * The desired line is after the current screen.
193 * Move back in the file far enough so that we can
194 * call forw() and put the desired line at the
195 * sline-th line on the screen.
197 for (nline = 0; nline < sline; nline++)
199 if (bpos != NULL_POSITION && pos <= bpos)
202 * Surprise! The desired line is
203 * close enough to the current screen
204 * that we can just scroll there after all.
206 forw(sc_height-sline+nline-1, bpos, 1, 0, 0);
209 pos = back_line(pos);
210 if (pos == NULL_POSITION)
213 * Oops. Ran into the beginning of the file.
214 * Exit the loop here and rely on forw()
215 * below to draw the required number of
216 * blank lines at the top of the screen.
225 forw(sc_height-1, pos, 1, 0, sline-nline);
229 * The desired line is before the current screen.
230 * Move forward in the file far enough so that we
231 * can call back() and put the desired line at the
232 * sline-th line on the screen.
234 for (nline = sline; nline < sc_height - 1; nline++)
236 pos = forw_line(pos);
237 if (pos == NULL_POSITION)
240 error("Program error: EOI in jump_loc (forw)",
247 * Surprise! The desired line is
248 * close enough to the current screen
249 * that we can just scroll there after all.
251 back(nline+1, tpos, 1, 0);
259 back(sc_height-1, pos, 1, 0);