home *** CD-ROM | disk | FTP | other *** search
/ Beijing Paradise BBS Backup / PARADISE.ISO / software / BBSDOORW / UUPC11XS.ZIP / LIB / READNEXT.C < prev    next >
C/C++ Source or Header  |  1992-11-27  |  4KB  |  107 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    r e a d n e x t . c                                             */
  3. /*                                                                    */
  4. /*    Reads a spooling directory with optional pattern matching       */
  5. /*                                                                    */
  6. /*    Copyright 1991 (C), Andrew H. Derbyshire                        */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *    $Id: READNEXT.C 1.3 1992/11/22 20:58:55 ahd Exp $
  11.  *
  12.  *    $Log: READNEXT.C $
  13.  * Revision 1.3  1992/11/22  20:58:55  ahd
  14.  * Use strpool to allocate const strings
  15.  *
  16.  */
  17.  
  18. /*--------------------------------------------------------------------*/
  19. /*                        System include files                        */
  20. /*--------------------------------------------------------------------*/
  21.  
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include <time.h>
  26.  
  27. /*--------------------------------------------------------------------*/
  28. /*                    UUPC/extended include files                     */
  29. /*--------------------------------------------------------------------*/
  30.  
  31. #include "lib.h"
  32. #include "readnext.h"
  33. #include "ndir.h"
  34. #include "hostable.h"
  35. #include "security.h"
  36.  
  37. currentfile();
  38.  
  39. /*--------------------------------------------------------------------*/
  40. /*    r e a d n e x t                                                 */
  41. /*                                                                    */
  42. /*    Read a directory into a linked list                             */
  43. /*--------------------------------------------------------------------*/
  44.  
  45. char     *readnext(char *xname,
  46.           const char *remote,
  47.           const char *subdir,
  48.           char *pattern )
  49. {
  50.    static DIR *dirp;
  51.    static char *SaveRemote = NULL;
  52.    static char remotedir[FILENAME_MAX];
  53.  
  54.    struct direct *dp;
  55.  
  56. /*--------------------------------------------------------------------*/
  57. /*          Determine if we must restart the directory scan           */
  58. /*--------------------------------------------------------------------*/
  59.  
  60.    if ( (remote == NULL) || ( SaveRemote == NULL ) ||
  61.         !equal(remote, SaveRemote ) )
  62.    {
  63.       if ( SaveRemote != NULL )   /* Clean up old directory? */
  64.       {                           /* Yes --> Do so           */
  65.          closedir(dirp);
  66.          SaveRemote = NULL;
  67.       } /* if */
  68.  
  69.       if ( remote == NULL )      /* Clean up only, no new search? */
  70.          return NULL;            /* Yes --> Return to caller      */
  71.  
  72.       if ( pattern == NULL )
  73.          pattern = "*.*";
  74.  
  75.       sprintf(remotedir,"%s/%.8s/%s",E_spooldir,remote, subdir);
  76.       if ((dirp = opendirx(remotedir,pattern)) == nil(DIR))
  77.       {
  78.          printmsg(5, "readnext: couldn't opendir() %s", remotedir);
  79.          return NULL;
  80.       } /* if */
  81.  
  82.       SaveRemote = newstr( remote );
  83.                               /* Flag we have an active search    */
  84.    } /* if */
  85.  
  86. /*--------------------------------------------------------------------*/
  87. /*              Look for the next file in the directory               */
  88. /*--------------------------------------------------------------------*/
  89.  
  90.    if ((dp = readdir(dirp)) != nil(struct direct))
  91.    {
  92.       sprintf(xname, "%s/%s", remotedir, dp->d_name);
  93.       printmsg(5, "readnext: matched \"%s\"",xname);
  94.       return xname;
  95.    }
  96.  
  97. /*--------------------------------------------------------------------*/
  98. /*     No hit; clean up after ourselves and return to the caller      */
  99. /*--------------------------------------------------------------------*/
  100.  
  101.    printmsg(5, "readnext: \"%s\" not matched", remotedir);
  102.    closedir(dirp);
  103.    SaveRemote = NULL;
  104.    return NULL;
  105.  
  106. } /*readnext*/
  107.