/* 
 *   Copyright (c) 1990 Rodney Volz
 *   ALL RIGHTS RESERVED 
 * 
 *   THIS SOFTWARE PRODUCT CONTAINS THE
 *   UNPUBLISHED SOURCE CODE OF RODNEY VOLZ
 *
 *   The copyright notices above do not evidence
 *   intended publication of such source code.
 *
 */

/*
 * MERCURY UUCP SOURCECODE [statnews.c]
 */

static char sccsid[] = "@(#) MERCURY CORP. [uucp: statnews]";

#ifndef MWC
#include "uulib.c"
overlay "main"
#else
#include "define.h"
#endif


main()
{
	static char s[LLEN],s2[LLEN],s3[LLEN];
	char *ngtab[NEWSANZ];

	int anz,work,news,keep;
	int k,n,i,c,f,inh,outh,atr;
	unsigned long len,all,artics;
	char save;
	char single;
	unsigned long loc,ll,wr,tml;
	char sys_newsdir[LLEN];

	send("Statnews - ");
	send(VERSION);
	cr(1);

	artics = 0;
	/*
	i = 0;
	while (i < NEWSANZ)
	{
		ngtab[i++] = (char *)malloc((long)LLEN);
	}
	*/
	
	curs();
	getconf(18,sys_newsdir);
	sys_impdirn(sys_newsdir);

	save = FALSE;
	
	strcpy(sys_newsdir,s2);
	stradd("news.def",s2);
	
	if (exist(s2) == FALSE)
	{
		send("Active file does not exist.");
		cr(1);
		return(0);		
	}
		
	inh = open(s2,2);	/* Open for input */
		
	n = 0;
	while (0 == 0)
	{
		if (uu_getline(inh,s) == -1)
			break;
		
		
		/* Get some room in our machine's brain */
			
		ngtab[n] = (char *)malloc((long)LLEN);
		
		strcpys(s,(char *)ngtab[n],0,linstr(s,'|') - 1);
		strcpys(s,s2,rinstr(s,'|') + 1,strlen(s));
		++n;
	}
	close(inh);
	anz = n;
	
	/* <anz> zeigt jetzt auf den ersten noch freien Platz */
	/* in der Newsgroup-Table *ngtab[] */

	cr(1);
	
	sd(s);
	send(s);
	
	cr(2);
	
	n = 0;
	all = 0l;	
	while (n < anz)
	{
		strcpy(ngtab[n],s);
		
		send(s);
		send(" ");

		strmul('.',30 - strlen(s),s2);
		send(s2);

#if OLDFS
		strcpy(sys_newsdir,s);
		stradd("ng",s);
		str(n + 1,s2);
		stradd(s2,s);
		stradd("\\*",s);
#else
		munge(sys_newsdir,ngtab[n],s);
		stradd("*",s);
#endif
		i = 0;
		len = 0l;
		k = sfirst(s);
		while (k >= 0)
		{
			dtaxtr(s2,&ll,&save);
			
			if (save != 16)
			{
				len = len + ll;
				++i;
			}
			
			k = snext();
		}
		all = all + len;
		strl(len,s2);
		strmul('.',8 - strlen(s2),s3);
		send(s3);
		send(" ");
		send(s2);
		send(" Bytes");
		str(i,s);
		artics += i;
		strmul(' ',8 - strlen(s),s2);
		send(s2);
		send(s);
		send(". articles");
		cr(1);

		++n;
	}
	strmul('=',70,s);
	send(s);
	cr(1);
	
	send("Total:                      ");
	str((int)(all / 1024),s2);
	strmul(' ',12 - strlen(s2),s);
	send(s);
	send(s2);
	send(" KByte in ");
	sendl(artics);
	send(" articles");
	cr(1);

}
