/*  Citadel Verify Database */
#include <stdio.h>
#include <string.h>
#include "ctdl.h"
char netDebug      = '\0';
char logNetResults = '\0';
FILE  *netLog = stdout;

extern CONFIG      cfg;            /* A buncha variables           */
extern FILE            *netfl, *roomfl;
extern MessageBuffer  msgBuf; /* The -sole- message buffer      */
extern FILE *msgfl, *msgfl2;

void Process_Msg(MessageBuffer  *msg);
void Do_Room_Stats(long total);
void Print_Counts(struct counts *ptr );
void Do_Message(MessageBuffer  *);
void Verify_Messages(void);
int MsgLen(MessageBuffer  *);
void Verify_Room(void);
void crashout(char *);

int  mPrintf(char *format, ...) {return 0; }  /* stub to quiet the linker */


void crashout(str)
char *str;
  {
  printf(str);
  exit(10);

  }
int  main(int,char **);
int  main(argc,argv)
int  argc;
char **argv;
  {
  /* Process CONFIG  */
  cfg.weAre = UTILITY;
  printf("Citadel Vortex Unit Test Version %s\n", VERSION_NAME);
  if (!readSysTab(FALSE, TRUE)) exit(100);
  VortexInit();
  InitVortexing();
  Verify_Messages();    /* process the messages */
  FinVortexing();
  printf(msgBuf.mbtext);
  return 0;
  }

void Verify_Messages()
  {
  MSG_NUMBER msg, firstMessage;
  int total=1;     /* For stat keeping. */
  int bad=0;
  extern struct mBuf mFile1;
  fprintf(stderr, "Mulching...\n");
  InitMsgBase();
  startAt(msgfl, &mFile1, 0, 0);
  getMessage(getMsgChar, FALSE, TRUE, TRUE);
  firstMessage = atol(msgBuf.mbId);
  if( !NotVortex() )
    {
    printf(" Author:%s from %s rejected.\n", msgBuf.mbauth,  msgBuf.mboname);
    printf(" Id: %s  Date: %s  Time: %s  Room: %s\n",
    msgBuf.mbId, msgBuf.mbdate, msgBuf.mbtime, msgBuf.mbroom);
    bad++;
    };
  msg = firstMessage -1;
  while (msg != firstMessage)
    {
    total++;
    getMessage(getMsgChar, FALSE, TRUE, TRUE);
    if( !NotVortex() )
      {
      printf(" Author:%s from %s rejected.\n", msgBuf.mbauth,  msgBuf.mboname);
      printf(" Id: %s  Date: %s  Time: %s  Room: %s\n",
      msgBuf.mbId, msgBuf.mbdate, msgBuf.mbtime, msgBuf.mbroom);
      bad++;
      };
    msg = atol(msgBuf.mbId);
    printf(" %d out of %d messagges are duplicates\r", bad, total);
    fflush(stdout);
    };
  printf(" %d out of %d messagges are duplicates\n", bad, total);

  }
