/*
**	SetWB - force the WB backdrop window with several arguments
**
**	Copyright (C) 1995,96 by Daniel Balster
*/

#include <exec/exec.h>
#include <dos/dos.h>
#include <intuition/intuition.h>
#include <graphics/layers.h>
#include <utility/hooks.h>

/*#include <clib/macros.h>*/

#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>

#include <string.h>
#include <stdlib.h>

/****************************************************/
//#define DEBUG

#ifdef DEBUG
void kprintf(UBYTE *fmt,...);
#define bug kprintf
#define D(X) X
#else
#define D(X)
#endif

#define AllocStruct(X)	AllocVec(sizeof(struct X),MEMF_CLEAR|MEMF_PUBLIC)
#define FreeStruct(X)	if (X) FreeVec(X)

#define ifnot(expr)	if(!(expr))

typedef enum { false=0, true=~(false) } bool;
/****************************************************/

/* OpenWindowTagList */
#define VEC -0x25e
#define LIB (struct Library*) IntuitionBase

extern APTR NewVector;
extern APTR OldVector;

extern long __oslibversion = 37L;

static char vers[] = "$VER: SetWB 1.3 (29.1.96) Copyright ©1995,1996 by Daniel Balster";

#define TEMPL	"LEFT/N/K,TOP/N/K,WIDTH/N/K,HEIGHT/N/K,BORDER/S,TITLE/S,DELTA/S,QUIET/S,BORL/N,BORR/N,BORB/N,BORT/N"

struct {
	ULONG	*left,*top,*width,*height;
	ULONG	border,title,delta, quiet;
	ULONG	*borl,*borr,*borb,*bort;
} args;

int main ()
{
	struct RDArgs *rda;
	
	if (rda = ReadArgs(TEMPL,(LONG*)&args,NULL))
	{
		if (!args.quiet) PutStr(
"*** SetWB 1.3 ***\n"
"Copyright © 1995,1996 by Daniel Balster\n"
"All Rights Reserved.\n"
		);
	
		Disable();
		OldVector = SetFunction (LIB,VEC,(ULONG(*)())&(NewVector));
		CacheClearU();
		Enable();

		if (args.borr || args.borl || args.borb || args.bort)
		{
			struct Screen *scr = LockPubScreen("Workbench");
			
			if (scr)
			{
				if (args.borr) scr->WBorRight	= *args.borr;
				if (args.borl) scr->WBorLeft	= *args.borl;
				if (args.bort) scr->WBorTop	= *args.bort;
				if (args.borb) scr->WBorBottom= *args.borb;

				UnlockPubScreen(0,scr);
			}
		}

		Wait (SIGBREAKF_CTRL_C);
		
		if (FindPort("SetMan"))
		{
			Disable();
			SetFunction (LIB,VEC,(ULONG(*)())(OldVector));
			CacheClearU();
			Enable();
		}
		else Wait(0);

		FreeArgs(rda);
	}
	else PrintFault(IoErr(),0);

	return 0;
}
