* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
*
- * This code is derived from software contributed to Berkeley by
- * Mark Nudleman.
- *
- * 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 the University of California, Berkeley. The name of 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.
+ * %sccs.include.redist.c%
*/
#ifndef lint
-static char sccsid[] = "@(#)position.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)position.c 5.7 (Berkeley) %G%";
#endif /* not lint */
/*
* and just change a couple of pointers. }}
*/
-#include "less.h"
-#include "position.h"
+#include <sys/types.h>
+#include <less.h>
-#define NPOS 100 /* {{ sc_height must be less than NPOS }} */
-static POSITION table[NPOS]; /* The position table */
+static off_t *table; /* The position table */
+static int tablesize;
-extern int sc_width, sc_height;
+extern int sc_height;
/*
* Return the starting file position of a line displayed on the screen.
* the bottom line on the screen
* the line after the bottom line on the screen
*/
- public POSITION
+off_t
position(where)
int where;
{
/*
* Add a new file position to the bottom of the position table.
*/
- public void
add_forw_pos(pos)
- POSITION pos;
+ off_t pos;
{
register int i;
/*
* Add a new file position to the top of the position table.
*/
- public void
add_back_pos(pos)
- POSITION pos;
+ off_t pos;
{
register int i;
table[0] = pos;
}
+copytable()
+{
+ register int a, b;
+
+ for (a = 0; a < sc_height && table[a] == NULL_POSITION; a++);
+ for (b = 0; a < sc_height; a++, b++) {
+ table[b] = table[a];
+ table[a] = NULL_POSITION;
+ }
+}
+
/*
* Initialize the position table, done whenever we clear the screen.
*/
- public void
pos_clear()
{
register int i;
+ extern char *malloc(), *realloc();
+
+ if (table == 0) {
+ tablesize = sc_height > 25 ? sc_height : 25;
+ table = (off_t *)malloc(tablesize * sizeof *table);
+ } else if (sc_height >= tablesize) {
+ tablesize = sc_height;
+ table = (off_t *)realloc(table, tablesize * sizeof *table);
+ }
for (i = 0; i < sc_height; i++)
table[i] = NULL_POSITION;
* Check the position table to see if the position falls within its range.
* Return the position table entry if found, -1 if not.
*/
- public int
onscreen(pos)
- POSITION pos;
+ off_t pos;
{
register int i;