version 1.3, 2001/11/19 19:02:14 |
version 1.4, 2003/04/13 18:26:25 |
|
|
/* $OpenBSD$ */ |
|
|
|
/* |
/* |
* Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman |
* Copyright (C) 1984-2002 Mark Nudelman |
* All rights reserved. |
|
* |
* |
* Redistribution and use in source and binary forms, with or without |
* You may distribute under the terms of either the GNU General Public |
* modification, are permitted provided that the following conditions |
* License or the Less License, as specified in the README file. |
* 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. |
|
* |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY |
* For more information about less, or for information on how to |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* contact the author, see the README file. |
* 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. |
|
*/ |
*/ |
|
|
|
|
|
|
|
|
extern int squeeze; |
extern int squeeze; |
extern int chopline; |
extern int chopline; |
|
extern int hshift; |
|
extern int quit_if_one_screen; |
extern int sigs; |
extern int sigs; |
|
extern int ignore_eoi; |
|
extern POSITION start_attnpos; |
|
extern POSITION end_attnpos; |
#if HILITE_SEARCH |
#if HILITE_SEARCH |
extern int hilite_search; |
extern int hilite_search; |
extern int size_linebuf; |
extern int size_linebuf; |
|
|
POSITION curr_pos; |
POSITION curr_pos; |
{ |
{ |
POSITION new_pos; |
POSITION new_pos; |
int c; |
register int c; |
int blankline; |
int blankline; |
int endline; |
int endline; |
|
|
|
|
} |
} |
#if HILITE_SEARCH |
#if HILITE_SEARCH |
if (hilite_search == OPT_ONPLUS) |
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 |
#endif |
if (ch_seek(curr_pos)) |
if (ch_seek(curr_pos)) |
{ |
{ |
|
|
* End of the line. |
* End of the line. |
*/ |
*/ |
new_pos = ch_tell(); |
new_pos = ch_tell(); |
endline = 1; |
endline = TRUE; |
break; |
break; |
} |
} |
|
|
|
|
* is too long to print in the screen width. |
* is too long to print in the screen width. |
* End the line here. |
* End the line here. |
*/ |
*/ |
if (chopline) |
if (chopline || hshift > 0) |
{ |
{ |
do |
do |
{ |
{ |
c = ch_forw_get(); |
c = ch_forw_get(); |
} while (c != '\n' && c != EOI); |
} while (c != '\n' && c != EOI); |
new_pos = ch_tell(); |
new_pos = ch_tell(); |
endline = 1; |
endline = TRUE; |
|
quit_if_one_screen = FALSE; |
} else |
} else |
{ |
{ |
new_pos = ch_tell() - 1; |
new_pos = ch_tell() - 1; |
endline = 0; |
endline = FALSE; |
} |
} |
break; |
break; |
} |
} |
|
|
#if HILITE_SEARCH |
#if HILITE_SEARCH |
if (hilite_search == OPT_ONPLUS) |
if (hilite_search == OPT_ONPLUS) |
prep_hilite((curr_pos < 3*size_linebuf) ? |
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 |
#endif |
if (ch_seek(curr_pos-1)) |
if (ch_seek(curr_pos-1)) |
{ |
{ |
|
|
null_line(); |
null_line(); |
return (NULL_POSITION); |
return (NULL_POSITION); |
} |
} |
endline = 0; |
endline = FALSE; |
loop: |
loop: |
begin_new_pos = new_pos; |
begin_new_pos = new_pos; |
prewind(); |
prewind(); |
|
|
new_pos++; |
new_pos++; |
if (c == '\n') |
if (c == '\n') |
{ |
{ |
endline = 1; |
endline = TRUE; |
break; |
break; |
} |
} |
if (pappend(c, ch_tell()-1)) |
if (pappend(c, ch_tell()-1)) |
|
|
* reached our curr_pos yet. Discard the line |
* reached our curr_pos yet. Discard the line |
* and start a new one. |
* and start a new one. |
*/ |
*/ |
if (chopline) |
if (chopline || hshift > 0) |
{ |
{ |
endline = 1; |
endline = TRUE; |
|
quit_if_one_screen = FALSE; |
break; |
break; |
} |
} |
pdone(0); |
pdone(0); |
|
|
pdone(endline); |
pdone(endline); |
|
|
return (begin_new_pos); |
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; |
} |
} |