Changeset View
Changeset View
Standalone View
Standalone View
contrib/less/forwback.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
#if TAGS | #if TAGS | ||||
extern char *tagoption; | extern char *tagoption; | ||||
#endif | #endif | ||||
/* | /* | ||||
* Sound the bell to indicate user is trying to move past end of file. | * Sound the bell to indicate user is trying to move past end of file. | ||||
*/ | */ | ||||
static void | static void | ||||
eof_bell() | eof_bell(void) | ||||
{ | { | ||||
if (quiet == NOT_QUIET) | if (quiet == NOT_QUIET) | ||||
bell(); | bell(); | ||||
else | else | ||||
vbell(); | vbell(); | ||||
} | } | ||||
/* | /* | ||||
* Check to see if the end of file is currently displayed. | * Check to see if the end of file is currently displayed. | ||||
*/ | */ | ||||
public int | public int | ||||
eof_displayed() | eof_displayed(void) | ||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
if (ignore_eoi) | if (ignore_eoi) | ||||
return (0); | return (0); | ||||
if (ch_length() == NULL_POSITION) | if (ch_length() == NULL_POSITION) | ||||
/* | /* | ||||
Show All 10 Lines | eof_displayed(void) | ||||
pos = position(BOTTOM_PLUS_ONE); | pos = position(BOTTOM_PLUS_ONE); | ||||
return (pos == NULL_POSITION || pos == ch_length()); | return (pos == NULL_POSITION || pos == ch_length()); | ||||
} | } | ||||
/* | /* | ||||
* Check to see if the entire file is currently displayed. | * Check to see if the entire file is currently displayed. | ||||
*/ | */ | ||||
public int | public int | ||||
entire_file_displayed() | entire_file_displayed(void) | ||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
/* Make sure last line of file is displayed. */ | /* Make sure last line of file is displayed. */ | ||||
if (!eof_displayed()) | if (!eof_displayed()) | ||||
return (0); | return (0); | ||||
/* Make sure first line of file is displayed. */ | /* Make sure first line of file is displayed. */ | ||||
pos = position(0); | pos = position(0); | ||||
return (pos == NULL_POSITION || pos == 0); | return (pos == NULL_POSITION || pos == 0); | ||||
} | } | ||||
/* | /* | ||||
* If the screen is "squished", repaint it. | * If the screen is "squished", repaint it. | ||||
* "Squished" means the first displayed line is not at the top | * "Squished" means the first displayed line is not at the top | ||||
* of the screen; this can happen when we display a short file | * of the screen; this can happen when we display a short file | ||||
* for the first time. | * for the first time. | ||||
*/ | */ | ||||
public void | public void | ||||
squish_check() | squish_check(void) | ||||
{ | { | ||||
if (!squished) | if (!squished) | ||||
return; | return; | ||||
squished = 0; | squished = 0; | ||||
repaint(); | repaint(); | ||||
} | } | ||||
/* | /* | ||||
* Display n lines, scrolling forward, | * Display n lines, scrolling forward, | ||||
* starting at position pos in the input file. | * starting at position pos in the input file. | ||||
* "force" means display the n lines even if we hit end of file. | * "force" means display the n lines even if we hit end of file. | ||||
* "only_last" means display only the last screenful if n > screen size. | * "only_last" means display only the last screenful if n > screen size. | ||||
* "nblank" is the number of blank lines to draw before the first | * "nblank" is the number of blank lines to draw before the first | ||||
* real line. If nblank > 0, the pos must be NULL_POSITION. | * real line. If nblank > 0, the pos must be NULL_POSITION. | ||||
* The first real line after the blanks will start at ch_zero(). | * The first real line after the blanks will start at ch_zero(). | ||||
*/ | */ | ||||
public void | public void | ||||
forw(n, pos, force, only_last, nblank) | forw(int n, POSITION pos, int force, int only_last, int nblank) | ||||
register int n; | |||||
POSITION pos; | |||||
int force; | |||||
int only_last; | |||||
int nblank; | |||||
{ | { | ||||
int nlines = 0; | int nlines = 0; | ||||
int do_repaint; | int do_repaint; | ||||
static int first_time = 1; | static int first_time = 1; | ||||
squish_check(); | squish_check(); | ||||
/* | /* | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | #endif | ||||
first_time = 0; | first_time = 0; | ||||
(void) currline(BOTTOM); | (void) currline(BOTTOM); | ||||
} | } | ||||
/* | /* | ||||
* Display n lines, scrolling backward. | * Display n lines, scrolling backward. | ||||
*/ | */ | ||||
public void | public void | ||||
back(n, pos, force, only_last) | back(int n, POSITION pos, int force, int only_last) | ||||
register int n; | |||||
POSITION pos; | |||||
int force; | |||||
int only_last; | |||||
{ | { | ||||
int nlines = 0; | int nlines = 0; | ||||
int do_repaint; | int do_repaint; | ||||
squish_check(); | squish_check(); | ||||
do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1)); | do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1)); | ||||
#if HILITE_SEARCH | #if HILITE_SEARCH | ||||
if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) { | if (hilite_search == OPT_ONPLUS || is_filtering() || status_col) { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | #endif | ||||
(void) currline(BOTTOM); | (void) currline(BOTTOM); | ||||
} | } | ||||
/* | /* | ||||
* Display n more lines, forward. | * Display n more lines, forward. | ||||
* Start just after the line currently displayed at the bottom of the screen. | * Start just after the line currently displayed at the bottom of the screen. | ||||
*/ | */ | ||||
public void | public void | ||||
forward(n, force, only_last) | forward(int n, int force, int only_last) | ||||
int n; | |||||
int force; | |||||
int only_last; | |||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE)) | if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE)) | ||||
{ | { | ||||
/* | /* | ||||
* If the -e flag is set and we're trying to go | * If the -e flag is set and we're trying to go | ||||
* forward from end-of-file, go on to the next file. | * forward from end-of-file, go on to the next file. | ||||
Show All 32 Lines | forward(int n, int force, int only_last) | ||||
forw(n, pos, force, only_last, 0); | forw(n, pos, force, only_last, 0); | ||||
} | } | ||||
/* | /* | ||||
* Display n more lines, backward. | * Display n more lines, backward. | ||||
* Start just before the line currently displayed at the top of the screen. | * Start just before the line currently displayed at the top of the screen. | ||||
*/ | */ | ||||
public void | public void | ||||
backward(n, force, only_last) | backward(int n, int force, int only_last) | ||||
int n; | |||||
int force; | |||||
int only_last; | |||||
{ | { | ||||
POSITION pos; | POSITION pos; | ||||
pos = position(TOP); | pos = position(TOP); | ||||
if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0)) | if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0)) | ||||
{ | { | ||||
eof_bell(); | eof_bell(); | ||||
return; | return; | ||||
} | } | ||||
back(n, pos, force, only_last); | back(n, pos, force, only_last); | ||||
} | } | ||||
/* | /* | ||||
* Get the backwards scroll limit. | * Get the backwards scroll limit. | ||||
* Must call this function instead of just using the value of | * Must call this function instead of just using the value of | ||||
* back_scroll, because the default case depends on sc_height and | * back_scroll, because the default case depends on sc_height and | ||||
* top_scroll, as well as back_scroll. | * top_scroll, as well as back_scroll. | ||||
*/ | */ | ||||
public int | public int | ||||
get_back_scroll() | get_back_scroll(void) | ||||
{ | { | ||||
if (no_back_scroll) | if (no_back_scroll) | ||||
return (0); | return (0); | ||||
if (back_scroll >= 0) | if (back_scroll >= 0) | ||||
return (back_scroll); | return (back_scroll); | ||||
if (top_scroll) | if (top_scroll) | ||||
return (sc_height - 2); | return (sc_height - 2); | ||||
return (10000); /* infinity */ | return (10000); /* infinity */ | ||||
} | } |