home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / readnext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  5.0 KB  |  138 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    r e a d n e x t . c                                             */
  3. /*                                                                    */
  4. /*    Reads a spooling directory with optional pattern matching       */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: readnext.c 1.5 1993/08/26 05:00:25 ahd Exp $
  21.  *
  22.  *    $Log: readnext.c $
  23.  *     Revision 1.5  1993/08/26  05:00:25  ahd
  24.  *     Debugging code for odd failures on J. McBride's network
  25.  *
  26.  *     Revision 1.5  1993/08/26  05:00:25  ahd
  27.  *     Debugging code for odd failures on J. McBride's network
  28.  *
  29.  *     Revision 1.4  1993/04/05  04:32:19  ahd
  30.  *     Add timestamp, size to information returned by directory searches
  31.  *
  32.  *     Revision 1.3  1992/11/22  20:58:55  ahd
  33.  *     Use strpool to allocate const strings
  34.  *
  35.  */
  36.  
  37. /*--------------------------------------------------------------------*/
  38. /*                        System include files                        */
  39. /*--------------------------------------------------------------------*/
  40.  
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <stdlib.h>
  44. #include <time.h>
  45.  
  46. /*--------------------------------------------------------------------*/
  47. /*                    UUPC/extended include files                     */
  48. /*--------------------------------------------------------------------*/
  49.  
  50. #include "lib.h"
  51. #include "readnext.h"
  52. #include "uundir.h"
  53. #include "hostable.h"
  54. #include "security.h"
  55.  
  56. currentfile();
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*    r e a d n e x t                                                 */
  60. /*                                                                    */
  61. /*    Read a directory into a linked list                             */
  62. /*--------------------------------------------------------------------*/
  63.  
  64. char     *readnext(char *xname,
  65.                    const char *remote,
  66.                    const char *subdir,
  67.                    char *pattern,
  68.                    time_t *modified,
  69.                    long   *size )
  70. {
  71.    static DIR *dirp = NULL;
  72.    static char *SaveRemote = NULL;
  73.    static char remotedir[FILENAME_MAX];
  74.  
  75.    struct direct *dp;
  76.  
  77. /*--------------------------------------------------------------------*/
  78. /*          Determine if we must restart the directory scan           */
  79. /*--------------------------------------------------------------------*/
  80.  
  81.    if ( (remote == NULL) || ( SaveRemote == NULL ) ||
  82.         !equal(remote, SaveRemote ) )
  83.    {
  84.       if ( SaveRemote != NULL )   /* Clean up old directory? */
  85.       {                           /* Yes --> Do so           */
  86.          closedir(dirp);
  87.          dirp = NULL;
  88.          SaveRemote = NULL;
  89.       } /* if */
  90.  
  91.       if ( remote == NULL )      /* Clean up only, no new search? */
  92.          return NULL;            /* Yes --> Return to caller      */
  93.  
  94.       if ( pattern == NULL )
  95.          pattern = "*.*";
  96.  
  97.       sprintf(remotedir,"%s/%.8s/%s",E_spooldir,remote, subdir);
  98.       if ((dirp = opendirx(remotedir,pattern)) == nil(DIR))
  99.       {
  100.          printmsg(5, "readnext: couldn't opendir() %s", remotedir);
  101.          dirp = NULL;
  102.          return NULL;
  103.       } /* if */
  104.  
  105.       SaveRemote = newstr( remote );
  106.                               /* Flag we have an active search    */
  107.    } /* if */
  108.  
  109. /*--------------------------------------------------------------------*/
  110. /*              Look for the next file in the directory               */
  111. /*--------------------------------------------------------------------*/
  112.  
  113.    if ((dp = readdir(dirp)) != nil(struct direct))
  114.    {
  115.       sprintf(xname, "%s/%s", remotedir, dp->d_name);
  116.       printmsg(5, "readnext: matched \"%s\"",xname);
  117.  
  118.       if ( modified != NULL )
  119.          *modified = dp->d_modified;
  120.  
  121.       if ( size != NULL )
  122.          *size = dp->d_size;
  123.  
  124.       return xname;
  125.    }
  126.  
  127. /*--------------------------------------------------------------------*/
  128. /*     No hit; clean up after ourselves and return to the caller      */
  129. /*--------------------------------------------------------------------*/
  130.  
  131.    printmsg(5, "readnext: \"%s\" not matched", remotedir);
  132.    closedir(dirp);
  133.    SaveRemote = NULL;
  134.    dirp = NULL;
  135.    return NULL;
  136.  
  137. } /*readnext*/
  138.