    
#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>

#include "SysopListView.h"

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

#include <HBBS/release.h>
char *versionstr="$VER: SysopListView "RELEASE_STR;

#ifdef __SASC
int CXBRK(void) { return(0); }
int _CXBRK(void) { return(0); }
void chkabort(void) {}
#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 UpdateLV2(UWORD Code)
{
  struct Node *node;

  node=(struct Node*)GetNode( (struct List*) &LV1List,Code);

  if (!stricmp(node->ln_Name,"Protocols"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->ProtocolList,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Nodes"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->NodeList,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Conferences"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->ConfList,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Access Levels"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->AcsLevelList,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Access Names"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->AcsLevelNames,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Drives"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->Drive,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Language Name"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->LanguageName,GTLV_Top,0,TAG_DONE);
  }
  if (!stricmp(node->ln_Name,"Language Extn"))
  {
    GT_SetGadgetAttrs(SLVGadgets[LV2],SLV,NULL,GTLV_Labels,BBSGlobal->LanguageExtn,GTLV_Top,0,TAG_DONE);
  }

}

int ProcessWindowSLV( LONG Class, UWORD Code, APTR IAddress )
{
struct Gadget *gad;
switch ( Class )
  {
  case IDCMP_GADGETUP :
    /* Gadget message, gadget = gad. */
    gad = (struct Gadget *)IAddress;
    switch ( gad->GadgetID )
      {
      case LV1 :
        /* ListView pressed, Text of gadget :  */

        UpdateLV2(Code);

        break;
      case LV2 :
        /* ListView pressed, Text of gadget :  */
        break;
      }
    break;
  case IDCMP_CLOSEWINDOW :
    /* CloseWindow Now */
    return(1);
    break;
  case IDCMP_REFRESHWINDOW :
    GT_BeginRefresh( SLV);
    /* Refresh window. */
    GT_EndRefresh( SLV, TRUE);
  GT_RefreshWindow( SLV, NULL);
  RefreshGList( SLVGList, SLV, NULL, ~0);
    break;
  }
  return(0);
}


void DoorMain(int argc,char *argv[])
{
  int done=0;
  ULONG class;
  UWORD code;
  struct Gadget *pgsel;
  struct IntuiMessage *imsg;
  ULONG ReturnedSig;
  struct Screen *CtrlScr;

  if (CtrlScr=LockPubScreen(BBSGlobal->ScreenInfo->PubScreenName))
  {
    ScreenToFront(CtrlScr);
    if (OpenWindowSLV(CtrlScr)==0)
    {
      UnlockPubScreen(NULL,CtrlScr);
      while(done==0)
      {
        ReturnedSig=Wait(1L << SLV->UserPort->mp_SigBit);

        if (ReturnedSig & 1L << SLV->UserPort->mp_SigBit)
        {
          while (imsg=GT_GetIMsg(SLV->UserPort))
          {
            class=imsg->Class;
            code=imsg->Code;
            pgsel=(struct Gadget *)imsg->IAddress;

            GT_ReplyIMsg(imsg);

            done=ProcessWindowSLV(class, code, pgsel);
          }
        }
      }
      CloseWindowSLV();
    } else UnlockPubScreen(NULL,CtrlScr);
  }
  else puts("Error Opening Window!");
}

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

  if (BBSGlobal=HBBS_GimmeBBS())
  {
      DoorMain(argc,argv);
  }
  cleanup(0);
}
