/*--------------------------------------------------------------------- */
/* gettoc.c								*/
/*	Reach each input file (an mbox format) and output some header	*/
/*	lines to be used as a Table Of Contents.			*/
/*									*/
/* History:								*/
/*	6 Oct 1990	v1.0						*/
/*									*/
/* Author:								*/
/*	Eyal Lebedinsky							*/
/*	Canberra, AUSTRALIA						*/
/*--------------------------------------------------------------------- */

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

typedef unsigned char	uchar;

static uchar	line[4096];

main (argc, argv)
int	argc;
uchar	*argv[];
{
	FILE	*fin = NULL;
#ifdef	VBUF
	uchar	*p;
#endif

#ifdef	VBUF
#define	BSIZE	20480
	if ((p = (uchar *)malloc (BSIZE)) == NULL) {
		fprintf (stderr, "Out of memory\n");
		exit (1);
	}
#endif

	for (; argc-- > 1;) {
		fin = fopen (*++argv, "rt");
		if (fin == NULL)
			continue;
#ifdef	VBUF
		if (setvbuf (fin, p, _IOFBF, BSIZE)) {
			fprintf (stderr, "setvbuf failed!\n");
			exit (1);
		}
#endif
		while (fgets (line, sizeof (line), fin) != NULL) {
			if (!memcmp (line, "Keywords: ", 10) ||
			    !memcmp (line, "Subject: ", 9) ||
			    !memcmp (line, "Article ", 8) ||
			    !memcmp (line, ">From: ", 7) ||
			    !memcmp (line, "Lines: ", 7) ||
			    !memcmp (line, "From: ", 6) ||
			    !memcmp (line, "Date: ", 6))
				fputs (line, stdout);
		}
		fclose (fin);
	}
	exit (0);
}
