version 1.6, 2003/04/14 14:33:57 |
version 1.7, 2011/09/16 18:12:09 |
|
|
/* |
/* |
* Copyright (C) 1984-2002 Mark Nudelman |
* Copyright (C) 1984-2011 Mark Nudelman |
* |
* |
* You may distribute under the terms of either the GNU General Public |
* You may distribute under the terms of either the GNU General Public |
* License or the Less License, as specified in the README file. |
* License or the Less License, as specified in the README file. |
|
|
#include "less.h" |
#include "less.h" |
#include "position.h" |
#include "position.h" |
|
|
public int hit_eof; /* Keeps track of how many times we hit end of file */ |
|
public int screen_trashed; |
public int screen_trashed; |
public int squished; |
public int squished; |
public int no_back_scroll = 0; |
public int no_back_scroll = 0; |
|
public int forw_prompt; |
|
|
extern int sigs; |
extern int sigs; |
extern int top_scroll; |
extern int top_scroll; |
extern int quiet; |
extern int quiet; |
extern int sc_width, sc_height; |
extern int sc_width, sc_height; |
extern int quit_at_eof; |
|
extern int plusoption; |
extern int plusoption; |
extern int forw_scroll; |
extern int forw_scroll; |
extern int back_scroll; |
extern int back_scroll; |
extern int ignore_eoi; |
extern int ignore_eoi; |
extern int clear_bg; |
extern int clear_bg; |
extern int final_attr; |
extern int final_attr; |
|
extern int oldbot; |
#if TAGS |
#if TAGS |
extern char *tagoption; |
extern char *tagoption; |
#endif |
#endif |
|
|
} |
} |
|
|
/* |
/* |
* Check to see if the end of file is currently "displayed". |
* Check to see if the end of file is currently displayed. |
*/ |
*/ |
static void |
public int |
eof_check() |
eof_displayed() |
{ |
{ |
POSITION pos; |
POSITION pos; |
|
|
if (ignore_eoi) |
if (ignore_eoi) |
return; |
return (0); |
if (ABORT_SIGS()) |
|
return; |
if (ch_length() == NULL_POSITION) |
|
/* |
|
* If the file length is not known, |
|
* we can't possibly be displaying EOF. |
|
*/ |
|
return (0); |
|
|
/* |
/* |
* If the bottom line is empty, we are at EOF. |
* If the bottom line is empty, we are at EOF. |
* If the bottom line ends at the file length, |
* If the bottom line ends at the file length, |
* we must be just at EOF. |
* we must be just at EOF. |
*/ |
*/ |
pos = position(BOTTOM_PLUS_ONE); |
pos = position(BOTTOM_PLUS_ONE); |
if (pos == NULL_POSITION || pos == ch_length()) |
return (pos == NULL_POSITION || pos == ch_length()); |
hit_eof++; |
|
} |
} |
|
|
/* |
/* |
|
* Check to see if the entire file is currently displayed. |
|
*/ |
|
public int |
|
entire_file_displayed() |
|
{ |
|
POSITION pos; |
|
|
|
/* Make sure last line of file is displayed. */ |
|
if (!eof_displayed()) |
|
return (0); |
|
|
|
/* Make sure first line of file is displayed. */ |
|
pos = position(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. |
*/ |
*/ |
static void |
public void |
squish_check() |
squish_check() |
{ |
{ |
if (!squished) |
if (!squished) |
|
|
|
|
if (!do_repaint) |
if (!do_repaint) |
{ |
{ |
/* |
|
* Forget any current line shift we might have |
|
* (from the last line of the previous screenful). |
|
*/ |
|
extern int cshift; |
|
cshift = 0; |
|
|
|
if (top_scroll && n >= sc_height - 1 && pos != ch_length()) |
if (top_scroll && n >= sc_height - 1 && pos != ch_length()) |
{ |
{ |
/* |
/* |
|
|
pos_clear(); |
pos_clear(); |
add_forw_pos(pos); |
add_forw_pos(pos); |
force = 1; |
force = 1; |
if (top_scroll == OPT_ONPLUS || first_time) |
clear(); |
clear(); |
|
home(); |
home(); |
} else |
|
{ |
|
clear_bot(); |
|
} |
} |
|
|
if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) |
if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) |
|
|
force = 1; |
force = 1; |
if (top_scroll) |
if (top_scroll) |
{ |
{ |
if (top_scroll == OPT_ONPLUS) |
clear(); |
clear(); |
|
home(); |
home(); |
} else if (!first_time) |
} else if (!first_time) |
{ |
{ |
|
|
squished = 1; |
squished = 1; |
continue; |
continue; |
} |
} |
if (top_scroll == OPT_ON) |
|
clear_eol(); |
|
put_line(); |
put_line(); |
if (clear_bg && final_attr != AT_NORMAL) |
#if 0 |
|
/* {{ |
|
* Can't call clear_eol here. The cursor might be at end of line |
|
* on an ignaw terminal, so clear_eol would clear the last char |
|
* of the current line instead of all of the next line. |
|
* If we really need to do this on clear_bg terminals, we need |
|
* to find a better way. |
|
* }} |
|
*/ |
|
if (clear_bg && apply_at_specials(final_attr) != AT_NORMAL) |
{ |
{ |
/* |
/* |
* Writing the last character on the last line |
* Writing the last character on the last line |
|
|
*/ |
*/ |
clear_eol(); |
clear_eol(); |
} |
} |
|
#endif |
|
forw_prompt = 1; |
} |
} |
|
|
if (ignore_eoi) |
|
hit_eof = 0; |
|
else if (eof && !ABORT_SIGS()) |
|
hit_eof++; |
|
else |
|
eof_check(); |
|
if (nlines == 0) |
if (nlines == 0) |
eof_bell(); |
eof_bell(); |
else if (do_repaint) |
else if (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)); |
hit_eof = 0; |
|
while (--n >= 0) |
while (--n >= 0) |
{ |
{ |
/* |
/* |
|
|
} |
} |
} |
} |
|
|
eof_check(); |
|
if (nlines == 0) |
if (nlines == 0) |
eof_bell(); |
eof_bell(); |
else if (do_repaint) |
else if (do_repaint) |
repaint(); |
repaint(); |
|
else if (!oldbot) |
|
lower_left(); |
(void) currline(BOTTOM); |
(void) currline(BOTTOM); |
} |
} |
|
|
|
|
{ |
{ |
POSITION pos; |
POSITION pos; |
|
|
if (quit_at_eof && hit_eof) |
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 |
|
|
} else |
} else |
{ |
{ |
eof_bell(); |
eof_bell(); |
hit_eof++; |
|
return; |
return; |
} |
} |
} |
} |