Changeset View
Changeset View
Standalone View
Standalone View
contrib/less/jump.c
Show All 20 Lines | |||||
extern int sc_width, sc_height; | extern int sc_width, sc_height; | ||||
extern int show_attn; | extern int show_attn; | ||||
extern int top_scroll; | extern int top_scroll; | ||||
/* | /* | ||||
* Jump to the end of the file. | * Jump to the end of the file. | ||||
*/ | */ | ||||
public void | public void | ||||
jump_forw() | jump_forw(void) | ||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
POSITION end_pos; | POSITION end_pos; | ||||
if (ch_end_seek()) | if (ch_end_seek()) | ||||
{ | { | ||||
error("Cannot seek to end of file", NULL_PARG); | error("Cannot seek to end of file", NULL_PARG); | ||||
return; | return; | ||||
Show All 21 Lines | if (position(sc_height-1) != end_pos) | ||||
repaint(); | repaint(); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Jump to the last buffered line in the file. | * Jump to the last buffered line in the file. | ||||
*/ | */ | ||||
public void | public void | ||||
jump_forw_buffered() | jump_forw_buffered(void) | ||||
{ | { | ||||
POSITION end; | POSITION end; | ||||
if (ch_end_buffer_seek()) | if (ch_end_buffer_seek()) | ||||
{ | { | ||||
error("Cannot seek to end of buffers", NULL_PARG); | error("Cannot seek to end of buffers", NULL_PARG); | ||||
return; | return; | ||||
} | } | ||||
end = ch_tell(); | end = ch_tell(); | ||||
if (end != NULL_POSITION && end > 0) | if (end != NULL_POSITION && end > 0) | ||||
jump_line_loc(end-1, sc_height-1); | jump_line_loc(end-1, sc_height-1); | ||||
} | } | ||||
/* | /* | ||||
* Jump to line n in the file. | * Jump to line n in the file. | ||||
*/ | */ | ||||
public void | public void | ||||
jump_back(linenum) | jump_back(LINENUM linenum) | ||||
LINENUM linenum; | |||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
PARG parg; | PARG parg; | ||||
/* | /* | ||||
* Find the position of the specified line. | * Find the position of the specified line. | ||||
* If we can seek there, just jump to it. | * If we can seek there, just jump to it. | ||||
* If we can't seek, but we're trying to go to line number 1, | * If we can't seek, but we're trying to go to line number 1, | ||||
Show All 15 Lines | if (pos != NULL_POSITION && ch_seek(pos) == 0) | ||||
error("Cannot seek to line number %n", &parg); | error("Cannot seek to line number %n", &parg); | ||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Repaint the screen. | * Repaint the screen. | ||||
*/ | */ | ||||
public void | public void | ||||
repaint() | repaint(void) | ||||
{ | { | ||||
struct scrpos scrpos; | struct scrpos scrpos; | ||||
/* | /* | ||||
* Start at the line currently at the top of the screen | * Start at the line currently at the top of the screen | ||||
* and redisplay the screen. | * and redisplay the screen. | ||||
*/ | */ | ||||
get_scrpos(&scrpos); | get_scrpos(&scrpos); | ||||
pos_clear(); | pos_clear(); | ||||
jump_loc(scrpos.pos, scrpos.ln); | jump_loc(scrpos.pos, scrpos.ln); | ||||
} | } | ||||
/* | /* | ||||
* Jump to a specified percentage into the file. | * Jump to a specified percentage into the file. | ||||
*/ | */ | ||||
public void | public void | ||||
jump_percent(percent, fraction) | jump_percent(int percent, long fraction) | ||||
int percent; | |||||
long fraction; | |||||
{ | { | ||||
POSITION pos, len; | POSITION pos, len; | ||||
/* | /* | ||||
* Determine the position in the file | * Determine the position in the file | ||||
* (the specified percentage of the file's length). | * (the specified percentage of the file's length). | ||||
*/ | */ | ||||
if ((len = ch_length()) == NULL_POSITION) | if ((len = ch_length()) == NULL_POSITION) | ||||
Show All 14 Lines | |||||
} | } | ||||
/* | /* | ||||
* Jump to a specified position in the file. | * Jump to a specified position in the file. | ||||
* Like jump_loc, but the position need not be | * Like jump_loc, but the position need not be | ||||
* the first character in a line. | * the first character in a line. | ||||
*/ | */ | ||||
public void | public void | ||||
jump_line_loc(pos, sline) | jump_line_loc(POSITION pos, int sline) | ||||
POSITION pos; | |||||
int sline; | |||||
{ | { | ||||
int c; | int c; | ||||
if (ch_seek(pos) == 0) | if (ch_seek(pos) == 0) | ||||
{ | { | ||||
/* | /* | ||||
* Back up to the beginning of the line. | * Back up to the beginning of the line. | ||||
*/ | */ | ||||
Show All 9 Lines | |||||
} | } | ||||
/* | /* | ||||
* Jump to a specified position in the file. | * Jump to a specified position in the file. | ||||
* The position must be the first character in a line. | * The position must be the first character in a line. | ||||
* Place the target line on a specified line on the screen. | * Place the target line on a specified line on the screen. | ||||
*/ | */ | ||||
public void | public void | ||||
jump_loc(pos, sline) | jump_loc(POSITION pos, int sline) | ||||
POSITION pos; | |||||
int sline; | |||||
{ | { | ||||
register int nline; | register int nline; | ||||
POSITION tpos; | POSITION tpos; | ||||
POSITION bpos; | POSITION bpos; | ||||
/* | /* | ||||
* Normalize sline. | * Normalize sline. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |