/* 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)
{
	char *cp;
	struct DiskObject *dop;
	struct FileHandle *fhp;
	BPTR wind;

	if (IconBase = OpenLibrary("icon.library", 0L))
	{
		if (dop = GetDiskObject(wbm->sm_ArgList->wa_Name))
		{
			if (cp = FindToolType(dop->do_ToolTypes, "WINDOW"))
			{
				if (wind = Open(cp, MODE_OLDFILE))
				{
					fhp = (struct FileHandle *) (wind << 2);

					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;

					/* !!! 1.4 tweek */
				}
			}

			FreeDiskObject(dop);
		}

		CloseLibrary(IconBase);

		IconBase = 0;
	}
}
