home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d9xx
/
d902
/
less.lha
/
Less
/
Source
/
source.lha
/
position.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-21
|
3KB
|
129 lines
/*
* 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. }}
*/
#include "less.h"
#include "position.h"
#define NPOS 100 /* {{ sc_height must be less than NPOS }} */
static POSITION table[NPOS]; /* The position table */
extern int sc_width, sc_height;
/*
* 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
*/
#ifdef __STDC__
POSITION position (int where)
#else
public POSITION
position(where)
int where;
#endif
{
switch (where)
{
case BOTTOM:
where = sc_height - 2;
break;
case BOTTOM_PLUS_ONE:
where = sc_height - 1;
break;
}
return (table[where]);
}
/*
* Add a new file position to the bottom of the position table.
*/
#ifdef __STDC__
void add_forw_pos (POSITION pos)
#else
public void
add_forw_pos(pos)
POSITION pos;
#endif
{
register int i;
/*
* Scroll the position table up.
*/
for (i = 1; i < sc_height; i++)
table[i-1] = table[i];
table[sc_height - 1] = pos;
}
/*
* Add a new file position to the top of the position table.
*/
#ifdef __STDC__
void add_back_pos (POSITION pos)
#else
public void
add_back_pos(pos)
POSITION pos;
#endif
{
register int i;
/*
* Scroll the position table down.
*/
for (i = sc_height - 1; i > 0; i--)
table[i] = table[i-1];
table[0] = pos;
}
/*
* Initialize the position table, done whenever we clear the screen.
*/
#ifdef __STDC__
void pos_clear (void)
#else
public void
pos_clear()
#endif
{
register int i;
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.
*/
#ifdef __STDC__
int onscreen (POSITION pos)
#else
public int
onscreen(pos)
POSITION pos;
#endif
{
register int i;
if (pos < table[0])
return (-1);
for (i = 1; i < sc_height; i++)
if (pos < table[i])
return (i-1);
return (-1);
}