[BACK]Return to position.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/position.c between version 1.7 and 1.8

version 1.7, 2014/04/25 13:38:21 version 1.8, 2015/11/05 22:08:44
Line 6 
Line 6 
  *   *
  * For more information, see the README file.   * For more information, see the README file.
  */   */
   /*
    * Modified for use with illumos.
    * Copyright 2014 Garrett D'Amore <garrett@damore.org>
    */
   
   
 /*  /*
  * Routines dealing with the "position" table.   * Routines dealing with the "position" table.
  * This is a table which tells the position (in the input file) of the   * This is a table which tells the position (in the input file) of the
  * first char on each currently displayed line.   * first char on each currently displayed line.
  *   *
  * {{ The position table is scrolled by moving all the entries.   * {{ The position table is scrolled by moving all the entries.
  *    Would be better to have a circular table   * Would be better to have a circular table
  *    and just change a couple of pointers. }}   * and just change a couple of pointers. }}
  */   */
   
 #include "less.h"  #include "less.h"
 #include "position.h"  #include "position.h"
   
 static POSITION *table = NULL;  /* The position table */  static off_t *table = NULL;     /* The position table */
 static int table_size;  static int table_size;
   
 extern int sc_width, sc_height;  extern int sc_width, sc_height;
Line 35 
Line 38 
  *      the bottom line on the screen   *      the bottom line on the screen
  *      the line after the bottom line on the screen   *      the line after the bottom line on the screen
  */   */
         public POSITION  off_t
 position(where)  position(int where)
         int where;  
 {  {
         switch (where)          switch (where) {
         {  
         case BOTTOM:          case BOTTOM:
                 where = sc_height - 2;                  where = sc_height - 2;
                 break;                  break;
Line 56 
Line 57 
 /*  /*
  * Add a new file position to the bottom of the position table.   * Add a new file position to the bottom of the position table.
  */   */
         public void  void
 add_forw_pos(pos)  add_forw_pos(off_t pos)
         POSITION pos;  
 {  {
         register int i;          int i;
   
         /*          /*
          * Scroll the position table up.           * Scroll the position table up.
Line 73 
Line 73 
 /*  /*
  * Add a new file position to the top of the position table.   * Add a new file position to the top of the position table.
  */   */
         public void  void
 add_back_pos(pos)  add_back_pos(off_t pos)
         POSITION pos;  
 {  {
         register int i;          int i;
   
         /*          /*
          * Scroll the position table down.           * Scroll the position table down.
Line 90 
Line 89 
 /*  /*
  * Initialize the position table, done whenever we clear the screen.   * Initialize the position table, done whenever we clear the screen.
  */   */
         public void  void
 pos_clear()  pos_clear(void)
 {  {
         register int i;          int i;
   
         for (i = 0;  i < sc_height;  i++)          for (i = 0;  i < sc_height;  i++)
                 table[i] = NULL_POSITION;                  table[i] = -1;
 }  }
   
 /*  /*
  * Allocate or reallocate the position table.   * Allocate or reallocate the position table.
  */   */
         public void  void
 pos_init()  pos_init(void)
 {  {
         struct scrpos scrpos;          struct scrpos scrpos;
   
Line 113 
Line 112 
          * If we already have a table, remember the first line in it           * If we already have a table, remember the first line in it
          * before we free it, so we can copy that line to the new table.           * before we free it, so we can copy that line to the new table.
          */           */
         if (table != NULL)          if (table != NULL) {
         {  
                 get_scrpos(&scrpos);                  get_scrpos(&scrpos);
                 free((char*)table);                  free(table);
         } else          } else {
                 scrpos.pos = NULL_POSITION;                  scrpos.pos = -1;
         table = (POSITION *) ecalloc(sc_height, sizeof(POSITION));          }
           table = ecalloc(sc_height, sizeof (off_t));
         table_size = sc_height;          table_size = sc_height;
         pos_clear();          pos_clear();
         if (scrpos.pos != NULL_POSITION)          if (scrpos.pos != -1)
                 table[scrpos.ln-1] = scrpos.pos;                  table[scrpos.ln-1] = scrpos.pos;
 }  }
   
Line 131 
Line 130 
  * Check the position table to see if the position falls within its range.   * Check the position table to see if the position falls within its range.
  * Return the position table entry if found, -1 if not.   * Return the position table entry if found, -1 if not.
  */   */
         public int  int
 onscreen(pos)  onscreen(off_t pos)
         POSITION pos;  
 {  {
         register int i;          register int i;
   
Line 148 
Line 146 
 /*  /*
  * See if the entire screen is empty.   * See if the entire screen is empty.
  */   */
         public int  int
 empty_screen()  empty_screen(void)
 {  {
         return (empty_lines(0, sc_height-1));          return (empty_lines(0, sc_height-1));
 }  }
   
         public int  int
 empty_lines(s, e)  empty_lines(int s, int e)
         int s;  
         int e;  
 {  {
         register int i;          int i;
   
         for (i = s;  i <= e;  i++)          for (i = s;  i <= e;  i++)
                 if (table[i] != NULL_POSITION && table[i] != 0)                  if (table[i] != -1 && table[i] != 0)
                         return (0);                          return (0);
         return (1);          return (1);
 }  }
Line 175 
Line 171 
  * such that the top few lines are empty, we may have to set   * such that the top few lines are empty, we may have to set
  * the screen line to a number > 0.   * the screen line to a number > 0.
  */   */
         public void  void
 get_scrpos(scrpos)  get_scrpos(struct scrpos *scrpos)
         struct scrpos *scrpos;  
 {  {
         register int i;          int i;
   
         /*          /*
          * Find the first line on the screen which has something on it,           * Find the first line on the screen which has something on it,
          * and return the screen line number and the file position.           * and return the screen line number and the file position.
          */           */
         for (i = 0; i < sc_height;  i++)          for (i = 0; i < sc_height;  i++)
                 if (table[i] != NULL_POSITION)                  if (table[i] != -1) {
                 {  
                         scrpos->ln = i+1;                          scrpos->ln = i+1;
                         scrpos->pos = table[i];                          scrpos->pos = table[i];
                         return;                          return;
Line 195 
Line 189 
         /*          /*
          * The screen is empty.           * The screen is empty.
          */           */
         scrpos->pos = NULL_POSITION;          scrpos->pos = -1;
 }  }
   
 /*  /*
Line 207 
Line 201 
  * or it may be in { -1 .. -(sc_height-1) } to refer to lines   * or it may be in { -1 .. -(sc_height-1) } to refer to lines
  * relative to the bottom of the screen.   * relative to the bottom of the screen.
  */   */
         public int  int
 adjsline(sline)  adjsline(int sline)
         int sline;  
 {  {
         /*          /*
          * Negative screen line number means           * Negative screen line number means

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8