/****************************************************************
 * This software is Copyright (C) 1986-1998 by                  *
 *                                                              *
 * F6FBB - Jean-Paul ROUBELAT,  jpr@f6fbb.org                   *
 * 6, rue George Sand                                           *
 * 31120 - Roquettes - France                                   *
 *                                                              *
 * License to copy and use this software is granted for         *
 * non-commercial use provided that it is identified as         *
 *                                                              *
 * "FBB packet-radio BBS software by Jean-Paul ROUBELAT, F6FBB" *
 *                                                              *
 * in all material mentioning or referencing this software      *
 * or this function.                                            *
 *                                                              *
 * These notices must be retained in any copies of any part of  *
 * this documentation and/or software.                          *
 *                                                              *
 * Parts of code have been taken from many other softwares.     *
 * Thanks for the help.                                         *
 ****************************************************************/


#include <stdio.h>
#include <ctype.h>
#include <time.h>
#include "version.h"

#define FALSE 0
#define TRUE  1

#ifdef __LINUX__

#define __a2__ __attribute__ ((packed, aligned(2)))

#else

#define __a2__

#endif


typedef struct typindic
{
	char call[7];
	char num;
}
indicat;

typedef struct {

	indicat indic     ;	/* 8  Callsign */
	indicat relai[8]  ;	/* 64 Digis path */
	long	lastmes __a2__  ;	/* 4  Last L number */
	long	nbcon   __a2__  ;	/* 4  Number of connexions */
	long	hcon    __a2__  ;	/* 4  Last connexion date */
	long	lastyap __a2__  ;	/* 4  Last YN date */
	unsigned short	flags    ;	/* 2  Flags */
	unsigned short	on_base  ;	/* 2  ON Base number */

	unsigned char	nbl       ;	/* 1  Lines paging */
	unsigned char	lang      ;	/* 1  Language */

	long	newbanner __a2__;	/* 4  Last Banner date */
	unsigned short 	download  ;	/* 2  download size (KB) = 100 */
	char	free[20]  ;	/* 20 Reserved */
	char	theme     ;	/* 1  Current topic */

	char	nom[18]   ;	/* 18 1st Name */
	char	prenom[13];	/* 13 Christian name */
	char	adres[61] ;	/* 61 Address */
	char	ville[31] ;	/* 31 City */
	char	teld[13]  ;	/* 13 home phone */
	char	telp[13]  ;	/* 13 modem phone */
	char	home[41]  ;	/* 41 home BBS */
	char	qra[7]    ;	/* 7  Qth Locator */
	char	priv[13]  ;	/* 13 PRIV directory */
	char	filtre[7] ;	/* 7  LC choice filter */
	char	pass[13]  ;	/* 13 Password */
	char	zip[9]    ;	/* 9  Zipcode */

} info ;                /* Total : 360 bytes */



FILE *ouvre_nomenc (void);

int main (int ac, char **av)
{
	info buf;
	FILE *fichi;

	long rinfo = 0L;
	long tot_dw = 0L;
	long nb_users = 0L;
	long temps = time (NULL);
	struct tm *tm = localtime (&temps);

	fprintf (stderr, "CLR_USER V %d.%d%c\n\n", MAJEUR, MINEUR, LETTRE);

	/* if (tm->tm_wday != 0)
	   return(0);
	 */

	putchar ('\n');
	puts (asctime (tm));

	fichi = ouvre_nomenc ();

	while (fread ((char *) &buf, (int) sizeof (buf), 1, fichi))
	{
		tot_dw += (long) buf.download;
		if (buf.download)
		{
			printf ("%6s : %dKB\n", buf.indic.call, buf.download);
			buf.download = 0;
			fseek (fichi, rinfo, 0);
			fwrite ((char *) &buf, (int) sizeof (buf), 1, fichi);
		}
		rinfo += sizeof (buf);
		fseek (fichi, rinfo, 0);
		++nb_users;
	}

	fclose (fichi);

#ifdef ENGLISH
	printf ("%ld callsigns ok      \n", nb_users);
	printf ("%ld KB downloaded     \n", tot_dw);
#else
	printf ("%ld indicatifs        \n", nb_users);
	printf ("%ld KB envoy‚s        \n", tot_dw);
#endif
	return (0);
}


FILE *ouvre_nomenc (void)
{
	FILE *fichi;

	if ((fichi = fopen ("inf.sys", "r+b")) == NULL)
	{
#ifdef ENGLISH
		fprintf (stderr, "Cannot find inf.sys !!     \n");
#else
		fprintf (stderr, "Erreur ouverture inf.sys !!\n");
#endif
		exit (1);
	}

	return (fichi);
}
