=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/forwback.c,v retrieving revision 1.9 retrieving revision 1.10 diff -c -r1.9 -r1.10 *** src/usr.bin/less/forwback.c 2014/04/25 13:38:21 1.9 --- src/usr.bin/less/forwback.c 2015/11/05 22:08:44 1.10 *************** *** 6,13 **** * * For more information, see the README file. */ - /* * Primitives for displaying the file on the screen, * scrolling either forward or backward. --- 6,16 ---- * * For more information, see the README file. */ + /* + * Modified for use with illumos. + * Copyright 2014 Garrett D'Amore + */ /* * Primitives for displaying the file on the screen, * scrolling either forward or backward. *************** *** 16,25 **** #include "less.h" #include "position.h" ! public int screen_trashed; ! public int squished; ! public int no_back_scroll = 0; ! public int forw_prompt; extern volatile sig_atomic_t sigs; extern int top_scroll; --- 19,28 ---- #include "less.h" #include "position.h" ! int screen_trashed; ! int squished; ! int no_back_scroll = 0; ! int forw_prompt; extern volatile sig_atomic_t sigs; extern int top_scroll; *************** *** 32,49 **** extern int clear_bg; extern int final_attr; extern int oldbot; - #if TAGS extern char *tagoption; - #endif /* * Sound the bell to indicate user is trying to move past end of file. */ ! static void ! eof_bell() { if (quiet == NOT_QUIET) ! bell(); else vbell(); } --- 35,50 ---- extern int clear_bg; extern int final_attr; extern int oldbot; extern char *tagoption; /* * Sound the bell to indicate user is trying to move past end of file. */ ! static void ! eof_bell(void) { if (quiet == NOT_QUIET) ! ring_bell(); else vbell(); } *************** *** 51,65 **** /* * Check to see if the end of file is currently displayed. */ ! public int ! eof_displayed() { ! POSITION pos; if (ignore_eoi) return (0); ! if (ch_length() == NULL_POSITION) /* * If the file length is not known, * we can't possibly be displaying EOF. --- 52,66 ---- /* * Check to see if the end of file is currently displayed. */ ! int ! eof_displayed(void) { ! off_t pos; if (ignore_eoi) return (0); ! if (ch_length() == -1) /* * If the file length is not known, * we can't possibly be displaying EOF. *************** *** 72,87 **** * we must be just at EOF. */ pos = position(BOTTOM_PLUS_ONE); ! return (pos == NULL_POSITION || pos == ch_length()); } /* * 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()) --- 73,88 ---- * we must be just at EOF. */ pos = position(BOTTOM_PLUS_ONE); ! return (pos == -1 || pos == ch_length()); } /* * Check to see if the entire file is currently displayed. */ ! int ! entire_file_displayed(void) { ! off_t pos; /* Make sure last line of file is displayed. */ if (!eof_displayed()) *************** *** 89,95 **** /* Make sure first line of file is displayed. */ pos = position(0); ! return (pos == NULL_POSITION || pos == 0); } /* --- 90,96 ---- /* Make sure first line of file is displayed. */ pos = position(0); ! return (pos == -1 || pos == 0); } /* *************** *** 98,105 **** * of the screen; this can happen when we display a short file * for the first time. */ ! public void ! squish_check() { if (!squished) return; --- 99,106 ---- * of the screen; this can happen when we display a short file * for the first time. */ ! void ! squish_check(void) { if (!squished) return; *************** *** 108,130 **** } /* ! * Display n lines, scrolling forward, * starting at position pos in the input 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. * "nblank" is the number of blank lines to draw before the first ! * real line. If nblank > 0, the pos must be NULL_POSITION. * The first real line after the blanks will start at ch_zero(). */ ! public void ! forw(n, pos, force, only_last, nblank) ! register int n; ! POSITION pos; ! int force; ! int only_last; ! int nblank; { - int eof = 0; int nlines = 0; int do_repaint; static int first_time = 1; --- 109,125 ---- } /* ! * Display n lines, scrolling forward, * starting at position pos in the input 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. * "nblank" is the number of blank lines to draw before the first ! * real line. If nblank > 0, the pos must be -1. * The first real line after the blanks will start at ch_zero(). */ ! void ! forw(int n, off_t pos, int force, int only_last, int nblank) { int nlines = 0; int do_repaint; static int first_time = 1; *************** *** 132,152 **** squish_check(); /* ! * do_repaint tells us not to display anything till the end, * then just repaint the entire screen. ! * We repaint if we are supposed to display only the last * screenful and the request is for more than a screenful. * Also if the request exceeds the forward scroll limit * (but not if the request is for exactly a screenful, since * repainting itself involves scrolling forward a screenful). */ ! do_repaint = (only_last && n > sc_height-1) || ! (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1); ! if (!do_repaint) ! { ! if (top_scroll && n >= sc_height - 1 && pos != ch_length()) ! { /* * Start a new screen. * {{ This is not really desirable if we happen --- 127,145 ---- squish_check(); /* ! * do_repaint tells us not to display anything till the end, * then just repaint the entire screen. ! * We repaint if we are supposed to display only the last * screenful and the request is for more than a screenful. * Also if the request exceeds the forward scroll limit * (but not if the request is for exactly a screenful, since * repainting itself involves scrolling forward a screenful). */ ! do_repaint = (only_last && n > sc_height-1) || ! (forw_scroll >= 0 && n > forw_scroll && n != sc_height-1); ! if (!do_repaint) { ! if (top_scroll && n >= sc_height - 1 && pos != ch_length()) { /* * Start a new screen. * {{ This is not really desirable if we happen *************** *** 156,221 **** pos_clear(); add_forw_pos(pos); force = 1; ! clear(); home(); } ! if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) ! { /* * This is not contiguous with what is ! * currently displayed. Clear the screen image * (position table) and start a new screen. */ pos_clear(); add_forw_pos(pos); force = 1; ! if (top_scroll) ! { ! clear(); home(); ! } else if (!first_time) ! { putstr("...skipping...\n"); } } } ! while (--n >= 0) ! { /* * Read the next line of input. */ ! if (nblank > 0) ! { /* ! * Still drawing blanks; don't get a line * from the file yet. * If this is the last blank line, get ready to * read a line starting at ch_zero() next time. */ if (--nblank == 0) pos = ch_zero(); ! } else ! { ! /* * Get the next line from the file. */ pos = forw_line(pos); ! if (pos == NULL_POSITION) ! { /* ! * End of file: stop here unless the top line * is still empty, or "force" is true. * Even if force is true, stop when the last * line in the file reaches the top of screen. */ ! eof = 1; ! if (!force && position(TOP) != NULL_POSITION) break; ! if (!empty_lines(0, 0) && !empty_lines(1, 1) && ! empty_lines(2, sc_height-1)) break; } } --- 149,206 ---- pos_clear(); add_forw_pos(pos); force = 1; ! do_clear(); home(); } ! if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) { /* * This is not contiguous with what is ! * currently displayed. Clear the screen image * (position table) and start a new screen. */ pos_clear(); add_forw_pos(pos); force = 1; ! if (top_scroll) { ! do_clear(); home(); ! } else if (!first_time) { putstr("...skipping...\n"); } } } ! while (--n >= 0) { /* * Read the next line of input. */ ! if (nblank > 0) { /* ! * Still drawing blanks; don't get a line * from the file yet. * If this is the last blank line, get ready to * read a line starting at ch_zero() next time. */ if (--nblank == 0) pos = ch_zero(); ! } else { ! /* * Get the next line from the file. */ pos = forw_line(pos); ! if (pos == -1) { /* ! * End of file: stop here unless the top line * is still empty, or "force" is true. * Even if force is true, stop when the last * line in the file reaches the top of screen. */ ! if (!force && position(TOP) != -1) break; ! if (!empty_lines(0, 0) && !empty_lines(1, 1) && ! empty_lines(2, sc_height-1)) break; } } *************** *** 237,273 **** * start the display after the beginning of the file, * and it is not appropriate to squish in that case. */ ! if (first_time && pos == NULL_POSITION && !top_scroll && ! #if TAGS ! tagoption == NULL && ! #endif ! !plusoption) ! { squished = 1; continue; } put_line(); - #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 - * of the display may have scrolled the screen. - * If we were in standout mode, clear_bg terminals - * will fill the new line with the standout color. - * Now we're in normal mode again, so clear the line. - */ - clear_eol(); - } - #endif forw_prompt = 1; } --- 222,233 ---- * start the display after the beginning of the file, * and it is not appropriate to squish in that case. */ ! if (first_time && pos == -1 && !top_scroll && ! tagoption == NULL && !plusoption) { squished = 1; continue; } put_line(); forw_prompt = 1; } *************** *** 282,307 **** /* * Display n lines, scrolling backward. */ ! public void ! back(n, pos, force, only_last) ! register int n; ! POSITION pos; ! int force; ! int only_last; { int nlines = 0; int do_repaint; squish_check(); do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1)); ! while (--n >= 0) ! { /* * Get the previous line of input. */ pos = back_line(pos); ! if (pos == NULL_POSITION) ! { /* * Beginning of file: stop here unless "force" is true. */ --- 242,261 ---- /* * Display n lines, scrolling backward. */ ! void ! back(int n, off_t pos, int force, int only_last) { int nlines = 0; int do_repaint; squish_check(); do_repaint = (n > get_back_scroll() || (only_last && n > sc_height-1)); ! while (--n >= 0) { /* * Get the previous line of input. */ pos = back_line(pos); ! if (pos == -1) { /* * Beginning of file: stop here unless "force" is true. */ *************** *** 314,321 **** */ add_back_pos(pos); nlines++; ! if (!do_repaint) ! { home(); add_line(); put_line(); --- 268,274 ---- */ add_back_pos(pos); nlines++; ! if (!do_repaint) { home(); add_line(); put_line(); *************** *** 335,350 **** * Display n more lines, forward. * Start just after the line currently displayed at the bottom of the screen. */ ! public void ! forward(n, force, only_last) ! int n; ! int force; ! int only_last; { ! POSITION pos; ! if (get_quit_at_eof() && eof_displayed() && !(ch_getflags() & CH_HELPFILE)) ! { /* * If the -e flag is set and we're trying to go * forward from end-of-file, go on to the next file. --- 288,300 ---- * Display n more lines, forward. * Start just after the line currently displayed at the bottom of the screen. */ ! void ! forward(int n, int force, int only_last) { ! off_t pos; ! if (get_quit_at_eof() && eof_displayed() && ! !(ch_getflags() & CH_HELPFILE)) { /* * If the -e flag is set and we're trying to go * forward from end-of-file, go on to the next file. *************** *** 355,381 **** } pos = position(BOTTOM_PLUS_ONE); ! if (pos == NULL_POSITION && (!force || empty_lines(2, sc_height-1))) ! { ! if (ignore_eoi) ! { /* * ignore_eoi is to support A_F_FOREVER. * Back up until there is a line at the bottom * of the screen. */ ! if (empty_screen()) pos = ch_zero(); ! else ! { ! do ! { back(1, position(TOP), 1, 0); pos = position(BOTTOM_PLUS_ONE); ! } while (pos == NULL_POSITION); } ! } else ! { eof_bell(); return; } --- 305,326 ---- } pos = position(BOTTOM_PLUS_ONE); ! if (pos == -1 && (!force || empty_lines(2, sc_height-1))) { ! if (ignore_eoi) { /* * ignore_eoi is to support A_F_FOREVER. * Back up until there is a line at the bottom * of the screen. */ ! if (empty_screen()) { pos = ch_zero(); ! } else { ! do { back(1, position(TOP), 1, 0); pos = position(BOTTOM_PLUS_ONE); ! } while (pos == -1); } ! } else { eof_bell(); return; } *************** *** 387,405 **** * Display n more lines, backward. * Start just before the line currently displayed at the top of the screen. */ ! public void ! backward(n, force, only_last) ! int n; ! int force; ! int only_last; { ! POSITION pos; pos = position(TOP); ! if (pos == NULL_POSITION && (!force || position(BOTTOM) == 0)) ! { eof_bell(); ! return; } back(n, pos, force, only_last); } --- 332,346 ---- * Display n more lines, backward. * Start just before the line currently displayed at the top of the screen. */ ! void ! backward(int n, int force, int only_last) { ! off_t pos; pos = position(TOP); ! if (pos == -1 && (!force || position(BOTTOM) == 0)) { eof_bell(); ! return; } back(n, pos, force, only_last); } *************** *** 410,417 **** * back_scroll, because the default case depends on sc_height and * top_scroll, as well as back_scroll. */ ! public int ! get_back_scroll() { if (no_back_scroll) return (0); --- 351,358 ---- * back_scroll, because the default case depends on sc_height and * top_scroll, as well as back_scroll. */ ! int ! get_back_scroll(void) { if (no_back_scroll) return (0);