* Copyright (c) 1988 Mark Nudleman
* Copyright (c) 1988 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by Mark Nudleman and the University of California, Berkeley. The
* name of Mark Nudleman or the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
static char sccsid
[] = "@(#)input.c 5.2 (Berkeley) %G%";
* High level routines dealing with getting lines of input
* from the file being viewed.
* When we speak of "lines" here, we mean PRINTABLE lines;
* lines processed with respect to the screen width.
* We use the term "raw line" to refer to lines simply
* delimited by newlines; not processed with respect to screen width.
* A "current" position is passed and a "new" position is returned.
* The current position is the position of the first character of
* a line. The new position is the position of the first character
* of the NEXT line. The line obtained is the line starting at curr_pos.
if (curr_pos
== NULL_POSITION
|| ch_seek(curr_pos
))
if (c
== '\n' || c
== EOI
)
* Append the char to the line and get the next char.
* The char won't fit in the line; the line
* is too long to print in the screen width.
if (squeeze
&& *line
== '\0')
* Skip down to the last contiguous blank line
* and pretend it is the one which we are returning.
while ((c
= ch_forw_get()) == '\n')
* A "current" position is passed and a "new" position is returned.
* The current position is the position of the first character of
* a line. The new position is the position of the first character
* of the PREVIOUS line. The line obtained is the one starting at new_pos.
POSITION new_pos
, begin_new_pos
;
if (curr_pos
== NULL_POSITION
|| curr_pos
<= (POSITION
)0 ||
* Find out if the "current" line was blank.
(void) ch_forw_get(); /* Skip the newline */
c
= ch_forw_get(); /* First char of "current" line */
(void) ch_back_get(); /* Restore our position */
* The "current" line was blank.
* Skip over any preceeding blank lines,
* since we skipped them in forw_line().
while ((c
= ch_back_get()) == '\n')
* Scan backwards until we hit the beginning of the line.
* This is the newline ending the previous line.
* We have hit the beginning of the line.
* We have hit the beginning of the file.
* This must be the first line in the file.
* This must, of course, be the beginning of the line.
* Now scan forwards from the beginning of this line.
* We keep discarding "printable lines" (based on screen width)
* until we reach the curr_pos.
* {{ This algorithm is pretty inefficient if the lines
* are much longer than the screen width,
* but I don't know of any better way. }}
* Got a full printable line, but we haven't
* reached our curr_pos yet. Discard the line
} while (new_pos
< curr_pos
);