1: /*
   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.
   5:  *
   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. }}
   9:  */
  10: 
  11: #include "less.h"
  12: #include "position.h"
  13: 
  14: #define NPOS    100     /* {{ sc_height must be less than NPOS }} */
  15: static POSITION table[NPOS];    /* The position table */
  16: 
  17: extern int sc_width, sc_height;
  18: 
  19: /*
  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
  27:  */
  28:     public POSITION
  29: position(where)
  30:     int where;
  31: {
  32:     switch (where)
  33:     {
  34:     case BOTTOM:
  35:         where = sc_height - 2;
  36:         break;
  37:     case BOTTOM_PLUS_ONE:
  38:         where = sc_height - 1;
  39:         break;
  40:     }
  41:     return (table[where]);
  42: }
  43: 
  44: /*
  45:  * Add a new file position to the bottom of the position table.
  46:  */
  47:     public void
  48: add_forw_pos(pos)
  49:     POSITION pos;
  50: {
  51:     register int i;
  52: 
  53:     /*
  54: 	 * Scroll the position table up.
  55: 	 */
  56:     for (i = 1;  i < sc_height;  i++)
  57:         table[i-1] = table[i];
  58:     table[sc_height - 1] = pos;
  59: }
  60: 
  61: /*
  62:  * Add a new file position to the top of the position table.
  63:  */
  64:     public void
  65: add_back_pos(pos)
  66:     POSITION pos;
  67: {
  68:     register int i;
  69: 
  70:     /*
  71: 	 * Scroll the position table down.
  72: 	 */
  73:     for (i = sc_height - 1;  i > 0;  i--)
  74:         table[i] = table[i-1];
  75:     table[0] = pos;
  76: }
  77: 
  78: /*
  79:  * Initialize the position table, done whenever we clear the screen.
  80:  */
  81:     public void
  82: pos_clear()
  83: {
  84:     register int i;
  85: 
  86:     for (i = 0;  i < sc_height;  i++)
  87:         table[i] = NULL_POSITION;
  88: }
  89: 
  90: /*
  91:  * See if the byte at a specified position is currently on the screen.
  92:  * Check the position table to see if the position falls within its range.
  93:  * Return the position table entry if found, -1 if not.
  94:  */
  95:     public int
  96: onscreen(pos)
  97:     POSITION pos;
  98: {
  99:     register int i;
 100: 
 101:     if (pos < table[0])
 102:         return (-1);
 103:     for (i = 1;  i < sc_height;  i++)
 104:         if (pos < table[i])
 105:             return (i-1);
 106:     return (-1);
 107: }

Defined functions

add_back_pos defined in line 64; used 3 times
add_forw_pos defined in line 47; used 3 times
onscreen defined in line 95; used 2 times

Defined variables

public defined in line 95; never used
table defined in line 15; used 10 times

Defined macros

NPOS defined in line 14; used 1 times
  • in line 15
Last modified: 1990-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 559
Valid CSS Valid XHTML 1.0 Strict