position.c (7e1b7636c894be9d1130c284089ce1ea0786ecec) position.c (b2ea244070ff84eab79e04befb7aa30c982fc84d)
1/*
2 * Copyright (C) 1984-2017 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information, see the README file.
8 */

--- 22 unchanged lines hidden (view full) ---

31 * The line may be specified as a line number relative to the top
32 * of the screen, but is usually one of these special cases:
33 * the top (first) line on the screen
34 * the second line on the screen
35 * the bottom line on the screen
36 * the line after the bottom line on the screen
37 */
38 public POSITION
1/*
2 * Copyright (C) 1984-2017 Mark Nudelman
3 *
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
6 *
7 * For more information, see the README file.
8 */

--- 22 unchanged lines hidden (view full) ---

31 * The line may be specified as a line number relative to the top
32 * of the screen, but is usually one of these special cases:
33 * the top (first) line on the screen
34 * the second line on the screen
35 * the bottom line on the screen
36 * the line after the bottom line on the screen
37 */
38 public POSITION
39position(where)
40 int where;
39position(sindex)
40 int sindex;
41{
41{
42 switch (where)
42 switch (sindex)
43 {
44 case BOTTOM:
43 {
44 case BOTTOM:
45 where = sc_height - 2;
45 sindex = sc_height - 2;
46 break;
47 case BOTTOM_PLUS_ONE:
46 break;
47 case BOTTOM_PLUS_ONE:
48 where = sc_height - 1;
48 sindex = sc_height - 1;
49 break;
50 case MIDDLE:
49 break;
50 case MIDDLE:
51 where = (sc_height - 1) / 2;
51 sindex = (sc_height - 1) / 2;
52 break;
52 }
53 }
53 return (table[where]);
54 return (table[sindex]);
54}
55
56/*
57 * Add a new file position to the bottom of the position table.
58 */
59 public void
60add_forw_pos(pos)
61 POSITION pos;

--- 48 unchanged lines hidden (view full) ---

110 if (sc_height <= table_size)
111 return;
112 /*
113 * If we already have a table, remember the first line in it
114 * before we free it, so we can copy that line to the new table.
115 */
116 if (table != NULL)
117 {
55}
56
57/*
58 * Add a new file position to the bottom of the position table.
59 */
60 public void
61add_forw_pos(pos)
62 POSITION pos;

--- 48 unchanged lines hidden (view full) ---

111 if (sc_height <= table_size)
112 return;
113 /*
114 * If we already have a table, remember the first line in it
115 * before we free it, so we can copy that line to the new table.
116 */
117 if (table != NULL)
118 {
118 get_scrpos(&scrpos);
119 get_scrpos(&scrpos, TOP);
119 free((char*)table);
120 } else
121 scrpos.pos = NULL_POSITION;
122 table = (POSITION *) ecalloc(sc_height, sizeof(POSITION));
123 table_size = sc_height;
124 pos_clear();
125 if (scrpos.pos != NULL_POSITION)
126 table[scrpos.ln-1] = scrpos.pos;

--- 44 unchanged lines hidden (view full) ---

171 * Get the current screen position.
172 * The screen position consists of both a file position and
173 * a screen line number where the file position is placed on the screen.
174 * Normally the screen line number is 0, but if we are positioned
175 * such that the top few lines are empty, we may have to set
176 * the screen line to a number > 0.
177 */
178 public void
120 free((char*)table);
121 } else
122 scrpos.pos = NULL_POSITION;
123 table = (POSITION *) ecalloc(sc_height, sizeof(POSITION));
124 table_size = sc_height;
125 pos_clear();
126 if (scrpos.pos != NULL_POSITION)
127 table[scrpos.ln-1] = scrpos.pos;

--- 44 unchanged lines hidden (view full) ---

172 * Get the current screen position.
173 * The screen position consists of both a file position and
174 * a screen line number where the file position is placed on the screen.
175 * Normally the screen line number is 0, but if we are positioned
176 * such that the top few lines are empty, we may have to set
177 * the screen line to a number > 0.
178 */
179 public void
179get_scrpos(scrpos)
180get_scrpos(scrpos, where)
180 struct scrpos *scrpos;
181 struct scrpos *scrpos;
182 int where;
181{
182 int i;
183{
184 int i;
185 int dir;
186 int last;
183
187
188 switch (where)
189 {
190 case TOP: i = 0; dir = +1; last = sc_height-2; break;
191 default: i = sc_height-2; dir = -1; last = 0; break;
192 }
193
184 /*
185 * Find the first line on the screen which has something on it,
186 * and return the screen line number and the file position.
187 */
194 /*
195 * Find the first line on the screen which has something on it,
196 * and return the screen line number and the file position.
197 */
188 for (i = 0; i < sc_height; i++)
198 for (;; i += dir)
199 {
189 if (table[i] != NULL_POSITION)
190 {
191 scrpos->ln = i+1;
192 scrpos->pos = table[i];
193 return;
194 }
200 if (table[i] != NULL_POSITION)
201 {
202 scrpos->ln = i+1;
203 scrpos->pos = table[i];
204 return;
205 }
206 if (i == last) break;
207 }
195 /*
196 * The screen is empty.
197 */
198 scrpos->pos = NULL_POSITION;
199}
200
201/*
202 * Adjust a screen line number to be a simple positive integer
203 * in the range { 0 .. sc_height-2 }.
204 * (The bottom line, sc_height-1, is reserved for prompts, etc.)
205 * The given "sline" may be in the range { 1 .. sc_height-1 }
206 * to refer to lines relative to the top of the screen (starting from 1),
207 * or it may be in { -1 .. -(sc_height-1) } to refer to lines
208 * relative to the bottom of the screen.
209 */
210 public int
208 /*
209 * The screen is empty.
210 */
211 scrpos->pos = NULL_POSITION;
212}
213
214/*
215 * Adjust a screen line number to be a simple positive integer
216 * in the range { 0 .. sc_height-2 }.
217 * (The bottom line, sc_height-1, is reserved for prompts, etc.)
218 * The given "sline" may be in the range { 1 .. sc_height-1 }
219 * to refer to lines relative to the top of the screen (starting from 1),
220 * or it may be in { -1 .. -(sc_height-1) } to refer to lines
221 * relative to the bottom of the screen.
222 */
223 public int
211adjsline(sline)
224sindex_from_sline(sline)
212 int sline;
213{
214 /*
215 * Negative screen line number means
216 * relative to the bottom of the screen.
217 */
218 if (sline < 0)
219 sline += sc_height;
220 /*
225 int sline;
226{
227 /*
228 * Negative screen line number means
229 * relative to the bottom of the screen.
230 */
231 if (sline < 0)
232 sline += sc_height;
233 /*
221 * Can't be less than 1 or greater than sc_height-1.
234 * Can't be less than 1 or greater than sc_height.
222 */
223 if (sline <= 0)
224 sline = 1;
235 */
236 if (sline <= 0)
237 sline = 1;
225 if (sline >= sc_height)
226 sline = sc_height - 1;
238 if (sline > sc_height)
239 sline = sc_height;
227 /*
228 * Return zero-based line number, not one-based.
229 */
230 return (sline-1);
231}
240 /*
241 * Return zero-based line number, not one-based.
242 */
243 return (sline-1);
244}