home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 287.lha / TY_v1.3 / src / position.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  2.5 KB  |  66 lines

  1. /*************************************************************************
  2.  ***                        position.c                   (JJB TEMPLAR) ***
  3.  *** Date modifications begun: 7/8/89.                                 ***
  4.  *** Last modified: 7/8/89.                                            ***
  5.  *************************************************************************/
  6. /*** Routines dealing with the "position" table. This is a table that  ***
  7.  *** tells the pos in the input file of the first char on each         ***
  8.  *** currently displayed line.                                         ***
  9.  *************************************************************************/
  10.  
  11. #include "less.h"
  12. #include "position.h"
  13.  
  14. #define NPOS    100             /* Must be greater than sc_height. */
  15. static LONG     table[NPOS];    /* The position table. */
  16.  
  17. extern int sc_width, sc_height;
  18.  
  19. LONG    position(where) /*===============================================*/
  20. int where;
  21. {
  22.     switch (where) {
  23.         case BOTTOM:          where = sc_height - 2;     break;
  24.         case BOTTOM_PLUS_ONE: where = sc_height - 1;     break;
  25.     }
  26.     return (table[where]);
  27. }
  28.  
  29. void    add_forw_pos(pos) /*=============================================*/
  30. LONG    pos;              /* Add a new pos to end of table.              */
  31. {
  32. register int    i;
  33.     for (i = 1;  i < sc_height;  i++) table[i-1] = table[i];
  34.     table[sc_height - 1] = pos;   /* Table moved up one. */
  35. }
  36.  
  37. void    add_back_pos(pos) /*=============================================*/
  38. LONG    pos;              /* Add a new pos to top of table.              */
  39. {
  40. register int    i;
  41.     for (i = sc_height - 1;  i > 0;  i--) table[i] = table[i-1];
  42.     table[0] = pos;               /* Table moved down one */
  43. }
  44.  
  45. void    pos_clear() /*===================================================*/
  46. {                   /* Clear table.                                      */
  47. register int    i;
  48.     for (i = 0;  i < sc_height;  i++) table[i] = NULL_POSITION;
  49. }
  50.  
  51. int     onscreen(pos) /*=================================================*/
  52. LONG    pos;    /* Is pos on screen? If so, return table line #, else -1 */
  53. {
  54. register int    i;
  55.     if (pos < table[0]) return (-1);        /* Before top line */
  56.     for (i = 1;  i < sc_height;  i++)
  57.         if (pos < table[i]) return (i-1);   /* Found line! */
  58.     return (-1);                            /* Not found :-( */
  59. }
  60.  
  61. void    set_top_pos(pos) /*==============================================*/
  62. LONG    pos;
  63. {
  64.     table[0] = pos;
  65. }
  66.