* 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
[] = "@(#)position.c 5.5 (Berkeley) %G%";
* Routines dealing with the "position" table.
* This is a table which tells the position (in the input file) of the
* first char on each currently displayed line.
* {{ The position table is scrolled by moving all the entries.
* Would be better to have a circular table
* and just change a couple of pointers. }}
static off_t
*table
; /* The position table */
* Return the starting file position of a line displayed on the screen.
* The line may be specified as a line number relative to the top
* of the screen, but is usually one of these special cases:
* the top (first) line on the screen
* the second line on the screen
* the bottom line on the screen
* the line after the bottom line on the screen
* Add a new file position to the bottom of the position table.
* Scroll the position table up.
for (i
= 1; i
< sc_height
; i
++)
table
[sc_height
- 1] = pos
;
* Add a new file position to the top of the position table.
* Scroll the position table down.
for (i
= sc_height
- 1; i
> 0; i
--)
for (a
= 0; a
< sc_height
&& table
[a
] == NULL_POSITION
; a
++);
for (b
= 0; a
< sc_height
; a
++, b
++) {
table
[a
] = NULL_POSITION
;
* Initialize the position table, done whenever we clear the screen.
extern char *malloc(), *realloc();
tablesize
= sc_height
> 25 ? sc_height
: 25;
table
= malloc(tablesize
* sizeof *table
);
} else if (sc_height
>= tablesize
) {
table
= realloc(table
, tablesize
* sizeof *table
);
for (i
= 0; i
< sc_height
; i
++)
table
[i
] = NULL_POSITION
;
* See if the byte at a specified position is currently on the screen.
* Check the position table to see if the position falls within its range.
* Return the position table entry if found, -1 if not.
for (i
= 1; i
< sc_height
; i
++)