home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / dirread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-05  |  3.6 KB  |  159 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: dirread.c,v 1.5 1995/06/04 23:11:58 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    dirread.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    31 Jan 1985
  9.  * Last update:
  10.  *        19 Feb 1995, prototyped
  11.  *        15 Jun 1985, typed 'realloc', 'calloc'.
  12.  *        05 Feb 1985, added 'dirread_path' entry.
  13.  *        01 Feb 1985
  14.  *
  15.  * Function:    This module updates the read-list for FLIST.  Each time a
  16.  *        directory search is performed (i.e., by the initial invocation,
  17.  *        or by the READ command), FLIST calls this module to unite
  18.  *        the data with the read-list.  We do pruning here, because we
  19.  *        want to make the full re-READ of the display list fast.
  20.  *        By eliminating redundant search-patterns, we can keep the
  21.  *        read-list from growing faster than the display list.
  22.  *
  23.  *        We perform both directions of pruning:
  24.  *
  25.  *            a)    A pattern which is a proper subset of at least one
  26.  *            pattern already in the read-list is ignored.
  27.  *            b)    A pattern which is a proper superset of one or more
  28.  *            patterns already in the read-list causes those patterns
  29.  *            to be replaced by the new pattern.
  30.  */
  31.  
  32. #include    <string.h>
  33.  
  34. #include    <stdlib.h>
  35. #include    <rms.h>
  36.  
  37. #include    "flist.h"
  38. #include    "dirent.h"
  39. #include    "dirfind.h"
  40. #include    "dirread.h"
  41.  
  42. import(readlist);    import(readllen);
  43.  
  44. /* <init>:
  45.  * Initialize this module for a new directory-level:
  46.  */
  47. void
  48. dirread_init (void)
  49. {
  50.     readllen = 0;
  51. }
  52.  
  53. /* <put>:
  54.  * Put a new entry into the read-list:
  55.  */
  56. void
  57. dirread_put (struct FAB *fab_)
  58. {
  59.     struct    NAM    *nam_    = fab_->fab$l_nam;    /* patch: should pass NAM */
  60.     FILENT    fz;
  61.     register int    j, k;
  62.  
  63.     dirent_chop (&fz, nullC, nam_);
  64.  
  65.     if (readllen)
  66.     {
  67.         /*
  68.          * First, see if the new pattern is a subset of anything already
  69.          * in the list:
  70.          */
  71.         for (j = 0; j < readllen; j++)
  72.         {
  73.         if (dirfind_tst (&fz, &readlist[j], FALSE))    return;
  74.         }
  75.         /*
  76.          * If we get this far, then the new pattern is not a proper subset
  77.          * of any already there.  However, it may absorb others:
  78.          */
  79.         for (j = 0; j < readllen; j++)
  80.         {
  81.         if (dirfind_tst (&readlist[j], &fz, FALSE))
  82.         {
  83.             for (k = j; k < readllen; k++)
  84.             readlist[k] = readlist[k+1];    /* compress list */
  85.             readllen--;
  86.             j--;        /* ...and restart comparison */
  87.         }
  88.         }
  89.     }
  90.     j = (readllen + 2) * sizeof(FILENT);
  91.     if (readllen)
  92.         readlist = realloc (readlist, j);
  93.     else
  94.         readlist = calloc (1, j);
  95.     readlist[readllen++] = fz;
  96. }
  97.  
  98. /* <get>:
  99.  * Return a string pointer to the inx'th item in the read-list.  If no
  100.  * more items remain, return null.
  101.  */
  102. char    *dirread_get (char *filespec, int inx)
  103. {
  104.     return ((inx < readllen) ? dirent_glue (filespec, &readlist[inx]) : nullC);
  105. }
  106.  
  107. /* <free>:
  108.  * Release the structure on exit to a higher directory level:
  109.  */
  110. void    dirread_free (void)
  111. {
  112.     cfree (readlist);
  113. }
  114.  
  115. #ifdef    DEBUG
  116. void    dirread_show (void)
  117. {
  118.     int    j;
  119.     char    filespec[MAX_PATH];
  120.  
  121.     trace ("READ-LIST:\n");
  122.     for (j = 0; j < readllen; j++)
  123.         trace ("%d: '%s'\n", j, dirent_glue(filespec, &readlist[j]));
  124. }
  125. #endif
  126.  
  127. /* <path>:
  128.  * Given a (potential) index into the read-list, return a pointer to the
  129.  * pathname portion.  If the index lies beyond the end of the list, return
  130.  * null.  If the pathname is not unique (i.e., is a repeat of previous
  131.  * entries in the list), skip to the next entry.
  132.  *
  133.  * To permit the skip, we pass the address of the index.
  134.  */
  135. char    *dirread_path (int *inx_)
  136. {
  137.     FILENT    *z;
  138.     int    j;
  139.     char    *c_;
  140.  
  141.     if (*inx_ >= readllen || *inx_ < 0)
  142.         return (nullC);
  143.     else
  144.     {
  145.         z  = &readlist[*inx_];
  146.         c_ = zPATHOF(z);
  147.         for (j = 0; j < *inx_; j++)
  148.         {
  149.             z = &readlist[j];
  150.             if (strcmp(c_, zPATHOF(z)) == 0)
  151.             {
  152.                 *inx_ = *inx_ + 1;
  153.                 return (dirread_path(inx_));
  154.             }
  155.         }
  156.         return (c_);
  157.     }
  158. }
  159.