new copyright notice
[unix-history] / usr / src / usr.bin / more / position.c
index 998c61c..ac60fe1 100644 (file)
@@ -3,24 +3,11 @@
  * Copyright (c) 1988 Regents of the University of California.
  * All rights reserved.
  *
  * 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
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)position.c 5.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)position.c 5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -33,13 +20,13 @@ static char sccsid[] = "@(#)position.c      5.1 (Berkeley) %G%";
  *    and just change a couple of pointers. }}
  */
 
  *    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.
 
 /*
  * Return the starting file position of a line displayed on the screen.
@@ -50,7 +37,7 @@ extern int sc_width, sc_height;
  *     the bottom line on the screen
  *     the line after the bottom line 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;
 {
 position(where)
        int where;
 {
@@ -71,9 +58,8 @@ position(where)
 /*
  * Add a new file position to the bottom of the position table.
  */
 /*
  * Add a new file position to the bottom of the position table.
  */
-       public void
 add_forw_pos(pos)
 add_forw_pos(pos)
-       POSITION pos;
+       off_t pos;
 {
        register int i;
 
 {
        register int i;
 
@@ -88,9 +74,8 @@ add_forw_pos(pos)
 /*
  * Add a new file position to the top of the position table.
  */
 /*
  * Add a new file position to the top of the position table.
  */
-       public void
 add_back_pos(pos)
 add_back_pos(pos)
-       POSITION pos;
+       off_t pos;
 {
        register int i;
 
 {
        register int i;
 
@@ -102,13 +87,32 @@ add_back_pos(pos)
        table[0] = pos;
 }
 
        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.
  */
 /*
  * Initialize the position table, done whenever we clear the screen.
  */
-       public void
 pos_clear()
 {
        register int i;
 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;
 
        for (i = 0;  i < sc_height;  i++)
                table[i] = NULL_POSITION;
@@ -119,9 +123,8 @@ pos_clear()
  * Check the position table to see if the position falls within its range.
  * Return the position table entry if found, -1 if not.
  */
  * 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)
 onscreen(pos)
-       POSITION pos;
+       off_t pos;
 {
        register int i;
 
 {
        register int i;