#include <string.h>
#include <stdio.h>
#include <intuition/screens.h>
#include "arq.h"

struct IntuitionBase *IntuitionBase = NULL;
struct Screen *WBScreen;
struct Window *WBWin;

static UBYTE *version_string = "$VER: FullBench 1.1 (13.9.92)";

long ArqReq(char *statement,UBYTE *gadtxts,UBYTE *header,USHORT Arq_id)
{
long num;
char nbs[256];
struct EasyStruct ES = {sizeof(struct EasyStruct),0,NULL,"%s",NULL};
struct ExtEasyStruct ExtArqReq = {NULL,"error_general",NULL,NULL,ARQ_MAGIC,NULL,NULL};
    nbs[0] = 0xA0;
    nbs[1] = '\0';
    strcat(nbs,header);
    ES.es_GadgetFormat = gadtxts;
    ES.es_Title = nbs;
    ExtArqReq.AnimID = Arq_id;
    ExtArqReq.Easy = ES;
    num = EasyRequest (NULL,&ExtArqReq.Easy,NULL,statement);
    return(num);
}

void main()
{

    if( !(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",36))) exit(20);

    WBScreen = (struct Screen *)LockPubScreen("Workbench");

    if ( !WBScreen) {
          ArqReq("Cant Find Worbench Screen","DEATH","Rats!",ARQ_ID_GURU);
          CloseLibrary(IntuitionBase);
          exit(20);
     }

     WBWin = WBScreen->FirstWindow;

     while (strncmp(WBWin->ScreenTitle,"Amiga Workbench",15)
               &&strncmp(WBWin->ScreenTitle,"Attempting to load program",25)
               &&strncmp(WBWin->ScreenTitle,"Copyright © 1985-1991 Commodore-Amiga, Inc. All Rights Reserved",63)
               &&strncmp(WBWin->ScreenTitle,"Cannot Quit yet",15)
               || strlen(WBWin->Title))
     {
          WBWin = WBWin->NextWindow;
          if (WBWin == NULL) {
               ArqReq("Cant Find Workbench Window\n or\nWorkbench not Backdrop","DIE","FullBench",ARQ_ID_EXCLAM);
               UnlockPubScreen(NULL,WBScreen);
               CloseLibrary(IntuitionBase);
               exit(20);
          }
     }

     ChangeWindowBox(WBWin,WBWin->LeftEdge,WBWin->TopEdge-(WBScreen->BarHeight+1),WBWin->Width,WBWin->Height+(WBScreen->BarHeight+1));

     ShowTitle(WBScreen,FALSE);

     UnlockPubScreen(NULL,WBScreen);
     CloseLibrary(IntuitionBase);
     exit(0);
}

