1 /* $NetBSD: position.c,v 1.4 2003/08/07 09:28:01 agc Exp $ */
4 * Copyright (c) 1988 Mark Nudelman
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
36 static char sccsid
[] = "@(#)position.c 8.1 (Berkeley) 6/6/93";
38 __RCSID("$NetBSD: position.c,v 1.4 2003/08/07 09:28:01 agc Exp $");
43 * Routines dealing with the "position" table.
44 * This is a table which tells the position (in the input file) of the
45 * first char on each currently displayed line.
47 * {{ The position table is scrolled by moving all the entries.
48 * Would be better to have a circular table
49 * and just change a couple of pointers. }}
52 #include <sys/types.h>
58 static off_t
*table
; /* The position table */
62 * Return the starting file position of a line displayed on the screen.
63 * The line may be specified as a line number relative to the top
64 * of the screen, but is usually one of these special cases:
65 * the top (first) line on the screen
66 * the second line on the screen
67 * the bottom line on the screen
68 * the line after the bottom line on the screen
77 where
= sc_height
- 2;
80 where
= sc_height
- 1;
83 where
= sc_height
/ 2;
85 return (table
[where
]);
89 * Add a new file position to the bottom of the position table.
98 * Scroll the position table up.
100 for (i
= 1; i
< sc_height
; i
++)
101 table
[i
-1] = table
[i
];
102 table
[sc_height
- 1] = pos
;
106 * Add a new file position to the top of the position table.
115 * Scroll the position table down.
117 for (i
= sc_height
- 1; i
> 0; i
--)
118 table
[i
] = table
[i
-1];
127 for (a
= 0; a
< sc_height
&& table
[a
] == NULL_POSITION
; a
++);
128 for (b
= 0; a
< sc_height
; a
++, b
++) {
130 table
[a
] = NULL_POSITION
;
135 * Initialize the position table, done whenever we clear the screen.
143 tablesize
= sc_height
> 25 ? sc_height
: 25;
144 table
= (off_t
*)malloc(tablesize
* sizeof *table
);
145 } else if (sc_height
>= tablesize
) {
146 tablesize
= sc_height
;
147 table
= (off_t
*)realloc(table
, tablesize
* sizeof *table
);
150 for (i
= 0; i
< sc_height
; i
++)
151 table
[i
] = NULL_POSITION
;
155 * See if the byte at a specified position is currently on the screen.
156 * Check the position table to see if the position falls within its range.
157 * Return the position table entry if found, -1 if not.
167 for (i
= 1; i
< sc_height
; i
++)