🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #8195

Re: How do I remove stuff expire missed?

#8195
From: Paul Southworth
Date: Sun, 02 Jun 1996 11:26
233 lines
5966 bytes
In article <4opca7$frd@odin.funcom.no>,
Torbjorn Lindgren <tl@odin.funcom.no> wrote:
>Daryl E. Kottek <dkotte2@ednet1.osl.or.gov> wrote:
>>Anyone know how I can remove those old articles that history doesn't 
>>know about?  I know that I could use "find", finding all files that
>>were older than 5/14, but that doesn't seem like the right thing to 
>>do.
>
>Some people will of course recommend findmissing.pl, but while it does
>work I can't understand why they use a program that easily runs for
>*hours* when there are *much* faster programs available.

I couldn't agree more.

Here's another one we've been using for a couple years.  Written by
Bryan Beecher <bryan@ans.net> while he was still at the University of
Michigan.  Utility is called "missart".

/*
 * Copyright (c) 1994 Regents of the University of Michigan.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of Michigan at Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */

#include <stdio.h>
#include <string.h>
#include <dirent.h>

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

static char *article_path = "/var/spool/news";
static char *history_file = "/usr/local/news/history";

static char *newsgroups[BUFSIZ * 16];
static int number_of_groups = 0;

char *dbggrp = NULL;

main(argc, argv)
int argc;
char *argv[];
{
	FILE *fp;
	char line[BUFSIZ];
	register char *s;
	int c;
	extern char *optarg;
	void usage(), check_group();

	while ((c = getopt(argc, argv, "a:d:h:")) != EOF)
		switch(c) {
		case 'a' :
			article_path = optarg;
			break;
		case 'd' :
			dbggrp = optarg;
			break;
		case 'h' :
			history_file = optarg;
			break;
		default :
			usage(argv[0]);
			/*NOTREACHED*/
		}

	if ((fp = fopen(history_file, "r")) == NULL) {
		perror("fopen");
		exit(-1);
	}
	if (chdir(article_path) < 0) {
		perror("chdir");
		exit(-1);
	}
	for (;;) {
		if (fgets(line, sizeof(line), fp) == NULL)
			break;
		line[strlen(line) - 1] = '\0';	/* kill newline */

		/* message-id */
		if ((s = strtok(line, " \t")) == NULL)
			break;

		/* time(s) */
		if ((s = strtok(NULL, " \t")) == NULL)
			break;

		/* path(s), if not already expired */
		if ((s = strtok(NULL, " \t")) == NULL)
			continue;

		for (;;) {
			check_group(s);

			/* additional paths */
			if ((s = strtok(NULL, " \t")) == NULL)
				break;
		}
	}
	fclose(fp);
}

void check_group(group)
char *group;
{
	void to_path(), add_to_list();
	int need_to_do(), debug = 0, number, article;
	int found_letter = FALSE;
	char *cp;
	DIR *dirp;
	struct dirent *dp;

	/* get group name */
	cp = strchr(group, '/');
	if (cp == NULL)
		return;
	*cp = '\0';

	/* do we need to do this group, or have we done it already? */
	if (!need_to_do(group))
		return;
	add_to_list(group);
	if (dbggrp != NULL && !strcmp(group, dbggrp)) {
		debug = 1;
		printf("Group '%s' has been added to the list\n", group);
	}

	/* change the dots in the group name to slashes */
	to_path(group);

	/* get article number */
	number = atoi (cp + 1);
	if (debug > 0)
		printf("First article listed in history db is %d\n", number);

	if ((dirp = opendir(group)) == NULL) {
		printf("Could not open directory %s\n", group);
		perror("opendir");
		return;
	}
	for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
		if (!strcmp(dp->d_name, "."))
			continue;
		if (!strcmp(dp->d_name, ".."))
			continue;
		if ((article = atoi(dp->d_name)) == 0)	/* subdirectory */
			continue;
		/*
		 *  atoi() can be fooled by some subdirectories, like alt/3d
		 */
		for (cp = dp->d_name; *cp != '\0'; cp++)
			if (!isdigit(*cp)) {
				found_letter = TRUE;
				break;
			}
		if (found_letter)
			continue;
		if (debug > 0) {
			printf("%d  ", article);
			fflush(stdout);
		}
		if (article < number)
			printf("%s/%s/%s\n", article_path, group, dp->d_name);
	}
	if (debug > 0)
		printf("\n");
	fflush(stdout);
	closedir(dirp);
	return;
}

void to_path(s)
char *s;
{
	register char *rcp;

	for (rcp = strchr(s, '.'); rcp != NULL; rcp = strchr(s, '.'))
		*rcp = '/';
	return;
}

void add_to_list(group)
char *group;
{
	int qsortcmp();

	newsgroups[number_of_groups] = strdup(group);
	number_of_groups++;
	qsort(newsgroups, number_of_groups, sizeof(char *), qsortcmp);
	return;
}

need_to_do(group)
char *group;
{
	int bsearchcmp();

	if (bsearch(group, newsgroups, number_of_groups, sizeof(char *), bsearchcmp) == NULL)
		return(TRUE);
	return(FALSE);
}

bsearchcmp(s1, s2)
char *s1, **s2;
{
	return(strcmp(s1, *s2));
}

qsortcmp(s1, s2)
char **s1, **s2;
{
	return(strcmp(*s1, *s2));
}

void usage(program)
char *program;
{
	fprintf(stderr, "%s [-a article-directory] [-h history-file]\n",
		program);
	fprintf(stderr, "Defaults are %s and %s, respectively.\n",
		article_path, history_file);
	exit(0);
}
Technical Details
Message-ID: <4ortp6$e20@news.cic.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!news.csc.fi!news.funet.fi!newsfeed.sunet.se!news00.sunet.se!sunic!nntp.coast.net!chi-news.cic.net!news.cic.net!pauls
References: <4nfvss$h86@ednet1.orednet.org> <4opca7$frd@odin.funcom.no>

Show Full Headers
Complete Article Headers
Message-ID: <4ortp6$e20@news.cic.net>
Subject: Re: How do I remove stuff expire missed?
Date: Sun, 02 Jun 1996 11:26:30 +0000
From: pauls@cic.net (Paul Southworth)
References: <4nfvss$h86@ednet1.orednet.org> <4opca7$frd@odin.funcom.no>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp!news.csc.fi!news.funet.fi!newsfeed.sunet.se!news00.sunet.se!sunic!nntp.coast.net!chi-news.cic.net!news.cic.net!pauls
Newsgroups: news.software.nntp,alt.sources
Followup-To: news.software.nntp
Organization: CICNet, Inc.
Lines: 232
NNTP-Posting-Host: locust.cic.net