=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/input.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/less/input.c 2001/11/19 19:02:14 1.3 +++ src/usr.bin/less/input.c 2003/04/13 18:26:25 1.4 @@ -1,29 +1,11 @@ -/* $OpenBSD: input.c,v 1.3 2001/11/19 19:02:14 mpech Exp $ */ - /* - * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman - * All rights reserved. + * Copyright (C) 1984-2002 Mark Nudelman * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice in the documentation and/or other materials provided with - * the distribution. + * You may distribute under the terms of either the GNU General Public + * License or the Less License, as specified in the README file. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * For more information about less, or for information on how to + * contact the author, see the README file. */ @@ -41,7 +23,12 @@ extern int squeeze; extern int chopline; +extern int hshift; +extern int quit_if_one_screen; extern int sigs; +extern int ignore_eoi; +extern POSITION start_attnpos; +extern POSITION end_attnpos; #if HILITE_SEARCH extern int hilite_search; extern int size_linebuf; @@ -59,7 +46,7 @@ POSITION curr_pos; { POSITION new_pos; - int c; + register int c; int blankline; int endline; @@ -70,7 +57,15 @@ } #if HILITE_SEARCH if (hilite_search == OPT_ONPLUS) - prep_hilite(curr_pos, curr_pos + 3*size_linebuf); + /* + * If we are ignoring EOI (command F), only prepare + * one line ahead, to avoid getting stuck waiting for + * slow data without displaying the data we already have. + * If we're not ignoring EOI, we *could* do the same, but + * for efficiency we prepare several lines ahead at once. + */ + prep_hilite(curr_pos, curr_pos + 3*size_linebuf, + ignore_eoi ? 1 : -1); #endif if (ch_seek(curr_pos)) { @@ -103,7 +98,7 @@ * End of the line. */ new_pos = ch_tell(); - endline = 1; + endline = TRUE; break; } @@ -117,18 +112,19 @@ * is too long to print in the screen width. * End the line here. */ - if (chopline) + if (chopline || hshift > 0) { do { c = ch_forw_get(); } while (c != '\n' && c != EOI); new_pos = ch_tell(); - endline = 1; + endline = TRUE; + quit_if_one_screen = FALSE; } else { new_pos = ch_tell() - 1; - endline = 0; + endline = FALSE; } break; } @@ -180,7 +176,7 @@ #if HILITE_SEARCH if (hilite_search == OPT_ONPLUS) prep_hilite((curr_pos < 3*size_linebuf) ? - 0 : curr_pos - 3*size_linebuf, curr_pos); + 0 : curr_pos - 3*size_linebuf, curr_pos, -1); #endif if (ch_seek(curr_pos-1)) { @@ -266,7 +262,7 @@ null_line(); return (NULL_POSITION); } - endline = 0; + endline = FALSE; loop: begin_new_pos = new_pos; prewind(); @@ -284,7 +280,7 @@ new_pos++; if (c == '\n') { - endline = 1; + endline = TRUE; break; } if (pappend(c, ch_tell()-1)) @@ -294,9 +290,10 @@ * reached our curr_pos yet. Discard the line * and start a new one. */ - if (chopline) + if (chopline || hshift > 0) { - endline = 1; + endline = TRUE; + quit_if_one_screen = FALSE; break; } pdone(0); @@ -309,4 +306,38 @@ pdone(endline); return (begin_new_pos); +} + +/* + * Set attnpos. + */ + public void +set_attnpos(pos) + POSITION pos; +{ + int c; + + if (pos != NULL_POSITION) + { + if (ch_seek(pos)) + return; + for (;;) + { + c = ch_forw_get(); + if (c == EOI) + return; + if (c != '\n' && c != '\r') + break; + pos++; + } + } + start_attnpos = pos; + for (;;) + { + c = ch_forw_get(); + pos++; + if (c == EOI || c == '\n' || c == '\r') + break; + } + end_attnpos = pos; }