/*  This is a Door Coder's debugging tool */


#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dos.h>
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_protos.h>

#include <dos/dosextens.h>
#include <intuition/screens.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <diskfont/diskfont.h>
#include <utility/utility.h>
#include <graphics/gfxbase.h>
#include <workbench/workbench.h>
#include <graphics/scale.h>
#include <clib/wb_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <string.h>
#include <clib/diskfont_protos.h>

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

#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#endif

#include <HBBS/ANSI_Codes.h>
#include <HBBS/Defines.h>
#include <HBBS/types.h>
#include <HBBS/structures.h>
#include <HBBS/hbbscommon_protos.h>

#ifdef __SASC
#include <HBBS/hbbscommon_pragmas_sas.h>
#else
#include <HBBS/hbbscommon_pragmas.h>
#endif

#include <HBBS/Hbbsnode_protos.h>

#ifdef __SASC
#include <HBBS/Hbbsnode_pragmas_sas.h>
#else
#include <HBBS/Hbbsnode_pragmas.h>
#endif

struct Library *HBBSCommonBase=NULL;
struct Library *HBBSNodeBase=NULL;

struct BBSGlobalData *BBSGlobal=NULL;
struct NodeData *N_ND=NULL;
int N_NodeNum=-1;

static VOID cleanup(ULONG num)
{
  if (HBBSCommonBase)
  {
    HBBS_CleanUpCommon();
    CloseLibrary (HBBSCommonBase);
  }

  if (num) printf("Door Error = %d\n",num);

  exit(0);
}

static VOID init(char *name)
{
  if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  {
    cleanup(1);
  }

  if (!(HBBS_InitCommon()))
  {
    cleanup(2);
  }

  SetProgramName(name);
}


void DoorMain(int argc,char *argv[])
{

  /* you can now access any HBBS data structure you like, for instance... */

  printf("Config Log is %s, filename of log is: %s\n", BBSGlobal->LogConfig ? "ON" : "OFF",BBSGlobal->ConfigLogFile);


  /* if node 1 is started, then display some message */

  if (N_ND=HBBS_NodeDataPtr(1))
  {
    if (N_ND->User->Valid)
    {
      printf("Currently logged on user has written %ld message(s)\n",N_ND->User->MsgsWritten);
    }
    else
    {
      printf("No-one logged on.\n");
    }
    if (N_ND->SerOK) puts("SerOK"); else puts("Ser NOT OK!");
    if (N_ND->SerWaiting) puts("Serial waiting"); else puts("Serial not waiting!");
    if (N_ND->NodeFlags & NFLG_BLOCKSERIAL) puts("Serial input blocked!"); else puts("Serial input not blocked");
  }
}

int main(int argc,char *argv[])
{
  init("PrintData");

  if (BBSGlobal=HBBS_GimmeBBS())
  {
    DoorMain(argc,argv);
  }
  else
  {
    puts("Could not interface to HBBS!");
  }
  cleanup(0);
}
