]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/miscellany/less-177/position.c
2 * Routines dealing with the "position" table.
3 * This is a table which tells the position (in the input file) of the
4 * first char on each currently displayed line.
6 * {{ The position table is scrolled by moving all the entries.
7 * Would be better to have a circular table
8 * and just change a couple of pointers. }}
14 static POSITION
*table
= NULL
; /* The position table */
15 static int table_size
;
17 extern int sc_width
, sc_height
;
20 * Return the starting file position of a line displayed on the screen.
21 * The line may be specified as a line number relative to the top
22 * of the screen, but is usually one of these special cases:
23 * the top (first) line on the screen
24 * the second line on the screen
25 * the bottom line on the screen
26 * the line after the bottom line on the screen
35 where
= sc_height
- 2;
38 where
= sc_height
- 1;
41 where
= sc_height
/ 2;
43 return (table
[where
]);
47 * Add a new file position to the bottom of the position table.
56 * Scroll the position table up.
58 for (i
= 1; i
< sc_height
; i
++)
59 table
[i
-1] = table
[i
];
60 table
[sc_height
- 1] = pos
;
64 * Add a new file position to the top of the position table.
73 * Scroll the position table down.
75 for (i
= sc_height
- 1; i
> 0; i
--)
76 table
[i
] = table
[i
-1];
81 * Initialize the position table, done whenever we clear the screen.
88 for (i
= 0; i
< sc_height
; i
++)
89 table
[i
] = NULL_POSITION
;
93 * Allocate the position table.
98 if (sc_height
<= table_size
)
102 table
= (POSITION
*) ecalloc(sc_height
, sizeof(POSITION
));
103 table_size
= sc_height
;
107 * See if the byte at a specified position is currently on the screen.
108 * Check the position table to see if the position falls within its range.
109 * Return the position table entry if found, -1 if not.
119 for (i
= 1; i
< sc_height
; i
++)
126 * See if the entire screen is empty.
131 return (empty_lines(0, sc_height
-1));
141 for (i
= s
; i
<= e
; i
++)
142 if (table
[i
] != NULL_POSITION
)
148 * Get the current screen position.
149 * The screen position consists of both a file position and
150 * a screen line number where the file position is placed on the screen.
151 * Normally the screen line number is 0, but if we are positioned
152 * such that the top few lines are empty, we may have to set
153 * the screen line to a number > 0.
157 struct scrpos
*scrpos
;
162 * Find the first line on the screen which has something on it,
163 * and return the screen line number and the file position.
165 for (i
= 0; i
< sc_height
; i
++)
166 if (table
[i
] != NULL_POSITION
)
169 scrpos
->pos
= table
[i
];
173 * The screen is empty.
175 scrpos
->pos
= NULL_POSITION
;
179 * Adjust a screen line number to be a simple positive integer
180 * in the range { 0 .. sc_height-2 }.
181 * (The bottom line, sc_height-1, is reserved for prompts, etc.)
182 * The given "sline" may be in the range { 1 .. sc_height-1 }
183 * to refer to lines relative to the top of the screen (starting from 1),
184 * or it may be in { -1 .. -(sc_height-1) } to refer to lines
185 * relative to the bottom of the screen.
192 * Negative screen line number means
193 * relative to the bottom of the screen.
198 * Can't be less than 1 or greater than sc_height-1.
202 if (sline
>= sc_height
)
203 sline
= sc_height
- 1;
205 * Return zero-based line number, not one-based.