home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / util / trimnews.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  2.0 KB  |  105 lines

  1.  
  2. /*
  3.  *  TRIMNEWS.C
  4.  *
  5.  *  TRIMNEWS
  6.  *
  7.  *  This program scans UULIB:NewsGroups then chdir's into each news group's
  8.  *  directory.    The second field specifies the number of days old any numerical
  9.  *  file (ifilename beginning with 0-9) is allowed to be before it is deleted.
  10.  *
  11.  *  If the second field does not exist for a given line in the NewsGroups file,
  12.  *  7 days is automatically assumed.  The number of days is referenced from
  13.  *  when the file was created, NOT the Date: field in the article.
  14.  *
  15.  *  The program is meant to be run daily from a DCron entry to clear out old
  16.  *  news.
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include "config.h"
  22. #include "version.h"
  23. #include <libraries/dos.h>
  24.  
  25. typedef struct FileInfoBlock    FIB;
  26.  
  27. IDENT(".01");
  28.  
  29. static char TmpBuf[256];
  30.  
  31. void ScanDirectoryDeleteFiles();
  32.  
  33. int
  34. brk()
  35. {
  36.     return(0);
  37. }
  38.  
  39. main(ac, av)
  40. char *av[];
  41. {
  42.     FILE *fi;
  43.     char *path;
  44.     char newsgrp[64];
  45.     int days;
  46.  
  47.     onbreak(brk);
  48.     fi = openlib("NewsGroups");
  49.     if (fi == NULL) {
  50.     puts("Unable to open NewsGroups file");
  51.     exit(1);
  52.     }
  53.     while (fgets(TmpBuf, sizeof(TmpBuf), fi)) {
  54.     switch (sscanf(TmpBuf, "%s %d", newsgrp, &days)) {
  55.     case 1:
  56.         days = 7;
  57.     case 2:
  58.         path = MakeConfigPath(UUNEWS, newsgrp);
  59.         if (days)
  60.         ScanDirectoryDeleteFiles(path, days);
  61.     }
  62.     }
  63.     fclose(fi);
  64.     return(0);
  65. }
  66.  
  67. void
  68. ScanDirectoryDeleteFiles(path, days)
  69. char *path;
  70. int days;
  71. {
  72.     BPTR lock;
  73.     BPTR oldlock;
  74.     FIB *fib;
  75.     long ds[3];
  76.     long tnow;
  77.  
  78.     DateStamp(ds);
  79.     tnow = dstot(ds) - days * 1440*60;
  80.  
  81.     if (lock = Lock(path, ACCESS_READ)) {
  82.     oldlock = CurrentDir(lock);
  83.     if (fib = malloc(sizeof(FIB))) {
  84.         if (Examine(lock, fib)) {
  85.         while (ExNext(lock, fib)) {
  86.             if (isdigit((unsigned char)fib->fib_FileName[0])) {
  87.             if (tnow > dstot(&fib->fib_Date))
  88.                 DeleteFile(fib->fib_FileName);
  89.             }
  90.         }
  91.         }
  92.         free(fib);
  93.     }
  94.     UnLock(CurrentDir(oldlock));
  95.     }
  96. }
  97.  
  98. long
  99. dstot(date)
  100. long *date;    /*  days, mins, ticks    */
  101. {
  102.     return(date[0] * 1440 * 60 + date[1] * 60 + date[2] / 50);
  103. }
  104.  
  105.