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

Diff for /src/usr.bin/less/ifile.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>
    */
   
   
 /*  /*
  * An IFILE represents an input file.   * An IFILE represents an input file.
  *   *
  * It is actually a pointer to an ifile structure,   * It is actually a pointer to an ifile structure,
  * but is opaque outside this module.   * but is opaque outside this module.
  * Ifile structures are kept in a linked list in the order they   * Ifile structures are kept in a linked list in the order they
  * appear on the command line.   * appear on the command line.
  * Any new file which does not already appear in the list is   * Any new file which does not already appear in the list is
  * inserted after the current file.   * inserted after the current file.
Line 38 
Line 41 
  * Convert an IFILE (external representation)   * Convert an IFILE (external representation)
  * to a struct file (internal representation), and vice versa.   * to a struct file (internal representation), and vice versa.
  */   */
 #define int_ifile(h)    ((struct ifile *)(h))  #define int_ifile(h)    ((struct ifile *)(h))
 #define ext_ifile(h)    ((IFILE)(h))  #define ext_ifile(h)    ((IFILE)(h))
   
 /*  /*
  * Anchor for linked list.   * Anchor for linked list.
  */   */
 static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0',  static struct ifile anchor = { &anchor, &anchor, NULL, NULL, 0, 0, '\0',
                                 { NULL_POSITION, 0 } };                                  { -1, 0 } };
 static int ifiles = 0;  static int ifiles = 0;
   
         static void  static void
 incr_index(p, incr)  incr_index(struct ifile *p, int incr)
         register struct ifile *p;  
         int incr;  
 {  {
         for (;  p != &anchor;  p = p->h_next)          for (; p != &anchor; p = p->h_next)
                 p->h_index += incr;                  p->h_index += incr;
 }  }
   
 /*  /*
  * Link an ifile into the ifile list.   * Link an ifile into the ifile list.
  */   */
         static void  static void
 link_ifile(p, prev)  link_ifile(struct ifile *p, struct ifile *prev)
         struct ifile *p;  
         struct ifile *prev;  
 {  {
         /*          /*
          * Link into list.           * Link into list.
Line 82 
Line 81 
         incr_index(p->h_next, 1);          incr_index(p->h_next, 1);
         ifiles++;          ifiles++;
 }  }
   
 /*  /*
  * Unlink an ifile from the ifile list.   * Unlink an ifile from the ifile list.
  */   */
         static void  static void
 unlink_ifile(p)  unlink_ifile(struct ifile *p)
         struct ifile *p;  
 {  {
         p->h_next->h_prev = p->h_prev;          p->h_next->h_prev = p->h_prev;
         p->h_prev->h_next = p->h_next;          p->h_prev->h_next = p->h_next;
Line 102 
Line 100 
  * (or at the beginning of the list if "prev" is NULL).   * (or at the beginning of the list if "prev" is NULL).
  * Return a pointer to the new ifile structure.   * Return a pointer to the new ifile structure.
  */   */
         static struct ifile *  static struct ifile *
 new_ifile(filename, prev)  new_ifile(char *filename, struct ifile *prev)
         char *filename;  
         struct ifile *prev;  
 {  {
         register struct ifile *p;          struct ifile *p;
   
         /*          /*
          * Allocate and initialize structure.           * Allocate and initialize structure.
          */           */
         p = (struct ifile *) ecalloc(1, sizeof(struct ifile));          p = ecalloc(1, sizeof (struct ifile));
         p->h_filename = save(filename);          p->h_filename = save(filename);
         p->h_scrpos.pos = NULL_POSITION;          p->h_scrpos.pos = -1;
         p->h_opened = 0;          p->h_opened = 0;
         p->h_hold = 0;          p->h_hold = 0;
         p->h_filestate = NULL;          p->h_filestate = NULL;
Line 125 
Line 121 
 /*  /*
  * Delete an existing ifile structure.   * Delete an existing ifile structure.
  */   */
         public void  void
 del_ifile(h)  del_ifile(IFILE h)
         IFILE h;  
 {  {
         register struct ifile *p;          struct ifile *p;
   
         if (h == NULL_IFILE)          if (h == NULL_IFILE)
                 return;                  return;
Line 149 
Line 144 
 /*  /*
  * Get the ifile after a given one in the list.   * Get the ifile after a given one in the list.
  */   */
         public IFILE  IFILE
 next_ifile(h)  next_ifile(IFILE h)
         IFILE h;  
 {  {
         register struct ifile *p;          struct ifile *p;
   
         p = (h == NULL_IFILE) ? &anchor : int_ifile(h);          p = (h == NULL_IFILE) ? &anchor : int_ifile(h);
         if (p->h_next == &anchor)          if (p->h_next == &anchor)
Line 164 
Line 158 
 /*  /*
  * Get the ifile before a given one in the list.   * Get the ifile before a given one in the list.
  */   */
         public IFILE  IFILE
 prev_ifile(h)  prev_ifile(IFILE h)
         IFILE h;  
 {  {
         register struct ifile *p;          struct ifile *p;
   
         p = (h == NULL_IFILE) ? &anchor : int_ifile(h);          p = (h == NULL_IFILE) ? &anchor : int_ifile(h);
         if (p->h_prev == &anchor)          if (p->h_prev == &anchor)
Line 179 
Line 172 
 /*  /*
  * Return a different ifile from the given one.   * Return a different ifile from the given one.
  */   */
         public IFILE  IFILE
 getoff_ifile(ifile)  getoff_ifile(IFILE ifile)
         IFILE ifile;  
 {  {
         IFILE newifile;          IFILE newifile;
   
         if ((newifile = prev_ifile(ifile)) != NULL_IFILE)          if ((newifile = prev_ifile(ifile)) != NULL_IFILE)
                 return (newifile);                  return (newifile);
         if ((newifile = next_ifile(ifile)) != NULL_IFILE)          if ((newifile = next_ifile(ifile)) != NULL_IFILE)
Line 195 
Line 187 
 /*  /*
  * Return the number of ifiles.   * Return the number of ifiles.
  */   */
         public int  int
 nifile()  nifile(void)
 {  {
         return (ifiles);          return (ifiles);
 }  }
Line 204 
Line 196 
 /*  /*
  * Find an ifile structure, given a filename.   * Find an ifile structure, given a filename.
  */   */
         static struct ifile *  static struct ifile *
 find_ifile(filename)  find_ifile(const char *filename)
         char *filename;  
 {  {
         register struct ifile *p;          struct ifile *p;
   
         for (p = anchor.h_next;  p != &anchor;  p = p->h_next)          for (p = anchor.h_next;  p != &anchor;  p = p->h_next)
                 if (strcmp(filename, p->h_filename) == 0)                  if (strcmp(filename, p->h_filename) == 0)
Line 221 
Line 212 
  * If the filename has not been seen before,   * If the filename has not been seen before,
  * insert the new ifile after "prev" in the list.   * insert the new ifile after "prev" in the list.
  */   */
         public IFILE  IFILE
 get_ifile(filename, prev)  get_ifile(char *filename, IFILE prev)
         char *filename;  
         IFILE prev;  
 {  {
         register struct ifile *p;          struct ifile *p;
   
         if ((p = find_ifile(filename)) == NULL)          if ((p = find_ifile(filename)) == NULL)
                 p = new_ifile(filename, int_ifile(prev));                  p = new_ifile(filename, int_ifile(prev));
Line 236 
Line 225 
 /*  /*
  * Get the filename associated with a ifile.   * Get the filename associated with a ifile.
  */   */
         public char *  char *
 get_filename(ifile)  get_filename(IFILE ifile)
         IFILE ifile;  
 {  {
         if (ifile == NULL)          if (ifile == NULL)
                 return (NULL);                  return (NULL);
Line 248 
Line 236 
 /*  /*
  * Get the index of the file associated with a ifile.   * Get the index of the file associated with a ifile.
  */   */
         public int  int
 get_index(ifile)  get_index(IFILE ifile)
         IFILE ifile;  
 {  {
         return (int_ifile(ifile)->h_index);          return (int_ifile(ifile)->h_index);
 }  }
   
 /*  /*
  * Save the file position to be associated with a given file.   * Save the file position to be associated with a given file.
  */   */
         public void  void
 store_pos(ifile, scrpos)  store_pos(IFILE ifile, struct scrpos *scrpos)
         IFILE ifile;  
         struct scrpos *scrpos;  
 {  {
         int_ifile(ifile)->h_scrpos = *scrpos;          int_ifile(ifile)->h_scrpos = *scrpos;
 }  }
   
 /*  /*
  * Recall the file position associated with a file.   * Recall the file position associated with a file.
  * If no position has been associated with the file, return NULL_POSITION.   * If no position has been associated with the file, return -1.
  */   */
         public void  void
 get_pos(ifile, scrpos)  get_pos(IFILE ifile, struct scrpos *scrpos)
         IFILE ifile;  
         struct scrpos *scrpos;  
 {  {
         *scrpos = int_ifile(ifile)->h_scrpos;          *scrpos = int_ifile(ifile)->h_scrpos;
 }  }
Line 281 
Line 264 
 /*  /*
  * Mark the ifile as "opened".   * Mark the ifile as "opened".
  */   */
         public void  void
 set_open(ifile)  set_open(IFILE ifile)
         IFILE ifile;  
 {  {
         int_ifile(ifile)->h_opened = 1;          int_ifile(ifile)->h_opened = 1;
 }  }
Line 291 
Line 273 
 /*  /*
  * Return whether the ifile has been opened previously.   * Return whether the ifile has been opened previously.
  */   */
         public int  int
 opened(ifile)  opened(IFILE ifile)
         IFILE ifile;  
 {  {
         return (int_ifile(ifile)->h_opened);          return (int_ifile(ifile)->h_opened);
 }  }
   
         public void  void
 hold_ifile(ifile, incr)  hold_ifile(IFILE ifile, int incr)
         IFILE ifile;  
         int incr;  
 {  {
         int_ifile(ifile)->h_hold += incr;          int_ifile(ifile)->h_hold += incr;
 }  }
   
 #if !SMALL  int
         public int  held_ifile(IFILE ifile)
 held_ifile(ifile)  
         IFILE ifile;  
 {  {
         return (int_ifile(ifile)->h_hold);          return (int_ifile(ifile)->h_hold);
 }  }
 #endif /* !SMALL */  
   
         public void *  void *
 get_filestate(ifile)  get_filestate(IFILE ifile)
         IFILE ifile;  
 {  {
         return (int_ifile(ifile)->h_filestate);          return (int_ifile(ifile)->h_filestate);
 }  }
   
         public void  void
 set_filestate(ifile, filestate)  set_filestate(IFILE ifile, void *filestate)
         IFILE ifile;  
         void *filestate;  
 {  {
         int_ifile(ifile)->h_filestate = filestate;          int_ifile(ifile)->h_filestate = filestate;
 }  }
   
 #if 0  
         public void  
 if_dump()  
 {  
         register struct ifile *p;  
   
         for (p = anchor.h_next;  p != &anchor;  p = p->h_next)  
         {  
                 printf("%x: %d. <%s> pos %d,%x\n",  
                         p, p->h_index, p->h_filename,  
                         p->h_scrpos.ln, p->h_scrpos.pos);  
                 ch_dump(p->h_filestate);  
         }  
 }  
 #endif  

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