.newsrc update program

utzoo!utcsrgv!donald utzoo!utcsrgv!donald
Thu Apr 7 10:44:30 AEST 1983


For those of you that don't keep up with netnews regularly and are
deluged with a flood of net.misc articles full of a 5-week old
discussion on Vegemite, here's the solution.  This program can be
used to update your .newsrc so that it indicates that you have
read everything to date.  Individual newsgroups can be conveniently
updated by using the ! operator while editing .newsrc with vi.

/*
 *  PROGRAM: newsrc
 *  AUTHOR:  Don Chan (...utcsrgv!donald) April 4, 1983
 *
 *  Filter to update lines in a .newsrc to indicate that all articles
 *  to date have been read (useful after a long absence from netnews).
 *
 *  USAGE:
 *  May be called from the shell:
 *     newsrc <.newsrc >new ; mv new .newsrc
 *  or from vi (by editing .newsrc) by using the ! operator on lines.
 *
 *  Lines on the standard input of the form 'X:...' and 'X!...'
 *  (where X is a newsgroup) are transformed to lines 'X: 1-N' and
 *  'X! 1-N', respectively, and placed on the standard output.
 *  (N is the last numbered article in newsgroup X)
 *  Lines not of that form are copied unmolested.
 *
 *  The number of articles in newsgroup X is found by determining
 *  the size of the stat file '/usr/spool/news/.X' (where '.X' might
 *  have to be truncated to 14 chars because it's a filename).
 *  If N can't be determined (e.g. stat file doesn't exist), N=1 is
 *  assumed.
 *
 */

#define MAX 80
#define PREFIX "/usr/spool/news/."

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

main()
{
    char sizefile[MAX], line[MAX], delim, *endPtr, *index();
    int endPrefix;
    struct stat stbuf;

    sizefile[0] = '\0';
    strcat(sizefile,PREFIX);
    endPrefix = strlen(sizefile);

    while ( fgets(line,MAX+1,stdin) != NULL ) {

	/* find ':' or '!' delimiter, if any */
	endPtr = index(line,':');
	if (endPtr == 0) endPtr = index(line,'!');

	if (endPtr == 0) /* no delimiter on line; leave line alone */
	    fputs(line,stdout);
	else {
	    delim = *endPtr; *endPtr = '\0'; /* chop at delimiter */
	    printf("%s%c 1",line,delim);
	    line[13] = '\0'; /* chop at 14th char */
	    strcat(sizefile,line);
	    if (stat(sizefile,&stbuf) == 0 && stbuf.st_size != 1)
		printf("-%d\n",stbuf.st_size);
	    else
		putchar('\n');
	    sizefile[endPrefix] = '\0';
	}

    }
}



More information about the Comp.sources.unix mailing list