[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[leafnode-list] Enhancements to applyfilter



The following patch allows you to specify multiple groups to
applyfilter.  If you don't specify any groups at all, it applies the
filter to every existing group.

--- ../leafnode-1.9.17.orig/applyfilter.c	Mon Sep  4 15:26:20 2000
+++ ./applyfilter.c	Thu Nov  9 00:07:22 2000
@@ -22,33 +22,22 @@
 
 int debug = 0;
 int verbose;
-int first, last;
+int needwrite = 0;
+
+static void filtergroup( struct newsgroup * g, int quiet );
 
 int main( int argc, char * argv[] ) {
-    char c[4] = "-\\|/" ; 
-    int i, n, score, option, deleted, kept;
-    char *k, *l, *msgid;
-    const char *msgidpath = "";
-    FILE *f;
-    DIR * d;
-    struct dirent * de;
-    struct stat st;
-    struct utimbuf u;
+    int option;
     struct newsgroup * g;
 
     if ( !initvars( argv[0] ) )
 	exit(1);
 
-    if ( ( argc < 2 ) || ( argc > 3 ) ) {
-	printf("Usage: %s newsgroups\n", argv[0] );
-	exit(1);
-    }
-
     while ( ( option = getopt( argc, argv, "v" ) ) != -1 ) {
 	if ( option == 'v' )
 	    verbose++;
 	else {
-	    printf("Usage: %s newsgroups\n", argv[0] );
+	    printf("Usage: %s [-v] [newsgroup...]\n", argv[0] );
 	    exit( 1 );
 	}
     }
@@ -74,26 +63,56 @@
 	exit( 1 );
     readactive();
 
-    g = findgroup( argv[optind] );
-    if ( !g ) {
-	printf("Newsgroups %s not found in active file.\n", argv[optind] );
-	unlink( lockfile );
-	exit(1);
+    if (optind == argc) {
+	for ( g = active; g->name; g++ )
+	    filtergroup( g, 1 );
+    } else {
+	for ( ; optind < argc; optind++ ) {
+	    g = findgroup( argv[optind] );
+	    if ( !g )
+		printf("Newsgroup %s not found in active file.\n", argv[optind] );
+	    else
+		filtergroup( g, 0 );
+	}
     }
 
+    if ( needwrite )
+	writeactive();
+    unlink( lockfile );
+
+#ifdef NOTYET
+    if ( verbose )
+	printf( "Updating .overview file\n" );
+    fixxovergrp( g->name );
+#endif
+    exit(0);
+}
+
+
+static void filtergroup( struct newsgroup * g, int quiet ) {
+    char c[4] = "-\\|/" ; 
+    int i, n, score, deleted, kept;
+    char *k, *l, *msgid;
+    const char *msgidpath = "";
+    FILE *f;
+    DIR * d;
+    struct dirent * de;
+    struct stat st;
+    struct utimbuf u;
+
     g->first = INT_MAX;
     g->last = 0;
     if ( !chdirgroup( g->name, FALSE )) {
-	printf("No such newsgroup: %s\n", g->name );
-	unlink( lockfile );
-	exit(1);
+	if ( !quiet )
+	    printf("No such newsgroup: %s\n", g->name );
+	return;
     }
     if ( !(d = opendir( "." ) )) {
 	printf("Unable to open directory for newsgroup %s\n", g->name );
-	unlink( lockfile );
-	exit(1);
+	return;
     }
 
+    printf( "%s:\n", g->name );
     i = 0;
     deleted = 0;
     kept = 0;
@@ -163,14 +182,6 @@
     closedir( d );
     free( l );
     if ( g->first <= g->last )
-	writeactive();
-    unlink( lockfile );
+	needwrite = 1;
     printf( "%d articles deleted, %d kept.\n", deleted, kept );
-
-#ifdef NOTYET
-    if ( verbose )
-	printf( "Updating .overview file\n" );
-    fixxovergrp( g->name );
-#endif
-    exit(0);
 }

-Larry Jones

Ever notice how tense grown-ups get when they're recreating? -- Calvin

-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list