/* Copyright (C) 1986,1987 by Manx Software Systems, Inc. */

/*
 *	This routine is called from the _main() routine and is used to
 *	open a window for standard I/O to use. The window is actually
 *	defined by setting the ToolType, "WINDOW", to the desired window
 *	specification. If this is not required, this routine may be
 *	replaced by a stub in the users main program. Note that even if
 *	this code is called by _main(), if the WINDOW tool type is not
 *	defined, there will be no window.
 *
 *	EXAMPLE:	WINDOW=CON:0/0/640/200/Test Window
 */

/* tweeked to handle v1.4 wbench startup */

void *IconBase;

_wb_parse(struct Process *pp,struct WBStartup *wbm)
{
	if(IconBase = OpenLibrary("icon.library",0))
	{
		struct DiskObject *dop;

		if(dop = GetDiskObject(wbm -> sm_ArgList -> wa_Name))
		{
			char *cp;

			if(cp = FindToolType(dop -> do_ToolTypes,"WINDOW"))
			{
				BPTR wind;

				if(wind = Open(cp, MODE_OLDFILE))
				{
					struct FileHandle *fhp;

					fhp = (struct FileHandle *)BADDR(wind);

					pp -> pr_ConsoleTask	= (APTR)fhp -> fh_Type;
					pp -> pr_CIS		= (BPTR)wind;
					pp -> pr_COS		= (BPTR)Open("*", MODE_OLDFILE);

					/* !!! 1.4 tweek */

					_devtab[0] . mode &= ~O_STDIO;	/* setup for exit to close these if we succeeded */
					_devtab[1] . mode &= ~O_STDIO;
				}
			}

			FreeDiskObject(dop);
		}

		CloseLibrary(IconBase);

		IconBase = NULL;
	}
}
