diff options
Diffstat (limited to 'position.c')
-rw-r--r-- | position.c | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/position.c b/position.c index d5e949e2919c..ae3899c1e95e 100644 --- a/position.c +++ b/position.c @@ -36,21 +36,22 @@ extern int sc_width, sc_height; * the line after the bottom line on the screen */ public POSITION -position(where) - int where; +position(sindex) + int sindex; { - switch (where) + switch (sindex) { case BOTTOM: - where = sc_height - 2; + sindex = sc_height - 2; break; case BOTTOM_PLUS_ONE: - where = sc_height - 1; + sindex = sc_height - 1; break; case MIDDLE: - where = (sc_height - 1) / 2; + sindex = (sc_height - 1) / 2; + break; } - return (table[where]); + return (table[sindex]); } /* @@ -115,7 +116,7 @@ pos_init() */ if (table != NULL) { - get_scrpos(&scrpos); + get_scrpos(&scrpos, TOP); free((char*)table); } else scrpos.pos = NULL_POSITION; @@ -176,22 +177,34 @@ empty_lines(s, e) * the screen line to a number > 0. */ public void -get_scrpos(scrpos) +get_scrpos(scrpos, where) struct scrpos *scrpos; + int where; { int i; + int dir; + int last; + + switch (where) + { + case TOP: i = 0; dir = +1; last = sc_height-2; break; + default: i = sc_height-2; dir = -1; last = 0; break; + } /* * Find the first line on the screen which has something on it, * and return the screen line number and the file position. */ - for (i = 0; i < sc_height; i++) + for (;; i += dir) + { if (table[i] != NULL_POSITION) { scrpos->ln = i+1; scrpos->pos = table[i]; return; } + if (i == last) break; + } /* * The screen is empty. */ @@ -208,7 +221,7 @@ get_scrpos(scrpos) * relative to the bottom of the screen. */ public int -adjsline(sline) +sindex_from_sline(sline) int sline; { /* @@ -218,12 +231,12 @@ adjsline(sline) if (sline < 0) sline += sc_height; /* - * Can't be less than 1 or greater than sc_height-1. + * Can't be less than 1 or greater than sc_height. */ if (sline <= 0) sline = 1; - if (sline >= sc_height) - sline = sc_height - 1; + if (sline > sc_height) + sline = sc_height; /* * Return zero-based line number, not one-based. */ |