[net.news.b] How to expire different groups at different ages

rees@apollo.uucp (Jim Rees) (08/26/85)

A while back I hacked "expire" to read in a list of newsgroup patterns
and expiration times, to apply different times to different newsgroups.
I have a file called "expdays" in LIBDIR that looks like this:

apollo		120
fa.apollo	60
net.abortion	1
net.bizarre	1
net.jokes	1
net.origins	1
net.philosophy	1
net.politics	1
net.religion	1
net.religion.christian	1
net.sf-lovers	1
net.singles	1
net.women	1
all

Expire reads this in then applies the given expiration time to the
corresponding groups.  If no time is given, the default is used.
The first pattern in expdays that matches the article under consideration
is the one that gets applied.

I have been reluctant to publish this because

  1.  Our expire is greatly hacked, and the patches may not go into
      your expire, or may not work for you, and
  2.  It uses a fixed length array and dispenses with bounds checking.
      This is not my normal style but I was in a hurry.

Anyway, if you think this might be useful, here are the diffs.

***************
*** 64,69
  	int dsize;
  } datum;
  
  long	expincr;
  long	atol();
  time_t	cgtdate(), time();

--- 64,76 -----
  	int dsize;
  } datum;
  
+ struct {
+ 	char *pat;
+ 	long incr;
+ } nga[100];
+ 
  long	expincr;
  long	atol();
  time_t	cgtdate(), time();
***************
*** 171,177
  		argv++;
  	}
  	if (ngpat[0] == 0)
! 		strcpy(ngpat, "all,");
  	now = time(0);
  	if (chdir(SPOOL))
  		xerror("Cannot chdir %s", SPOOL);

--- 173,184 -----
  		argv++;
  	}
  	if (ngpat[0] == 0)
! 		readexpdays();
! 	else {
! 		nga[0].pat = ngpat;
! 		nga[0].incr = expincr;
! 		nga[1].pat = NULL;
! 	}
  	now = time(0);
  	if (chdir(SPOOL))
  		xerror("Cannot chdir %s", SPOOL);
***************
*** 231,237
  					if (p1 != NULL)
  						*p1 = NULL;
  					ngcat(groupdir);
! 					if (!ngmatch(groupdir, ngpat))
  						continue;
  					ngdel(groupdir);
  

--- 238,244 -----
  					if (p1 != NULL)
  						*p1 = NULL;
  					ngcat(groupdir);
! 					if ((expincr = getincr(groupdir)) < 0)
  						continue;
  					ngdel(groupdir);
  
***************
*** 285,291
  				goto checkdate;
  			}
  			ngcat(groupdir);
! 			if (!ngmatch(groupdir, ngpat)) {
  				fputs(afline, nhfd);
  				continue;
  			}

--- 292,298 -----
  				goto checkdate;
  			}
  			ngcat(groupdir);
! 			if ((expincr = getincr(groupdir)) < 0) {
  				fputs(afline, nhfd);
  				continue;
  			}
***************
*** 473,478
+ 
+ readexpdays()
+ {
+ 	char buf[BUFLEN], ngbuf[BUFLEN];
+ 	FILE *f;
+ 	int i, n;
+ 	long incr;
+ 
+ 	sprintf(buf, "%s/%s", LIB, "expdays");
+ 	f = xfopen(buf, "r");
+ 	i = 0;
+ 	while (fgets(buf, sizeof buf, f) != NULL) {
+ 		n = sscanf(buf, "%s %d", ngbuf, &incr);
+ 		if (n < 1)
+ 			continue;
+ 		if (n == 1)
+ 			nga[i].incr = expincr;
+ 		else
+ 			nga[i].incr = incr * DAYS;
+ 		ngcat(ngbuf);
+ 		nga[i].pat = malloc(strlen(ngbuf) + 1);
+ 		strcpy(nga[i].pat, ngbuf);
+ 		i++;
+ 	}
+ 	nga[i].pat = NULL;
+ 	fclose(f);
+ }
+ 
+ getincr(group)
+ char *group;
+ {
+ 	int i;
+ 
+ 	for (i = 0; nga[i].pat != NULL; i++)
+ 		if (ngmatch(group, nga[i].pat)) {
+ 			if (verbose > 2)
+ 				printf("pattern %s incr %d days\n", nga[i].pat, nga[i].incr / DAYS);
+ 			return (nga[i].incr);
+ 		}
+ 	return -1;
+ }