head	1.2;
access;
symbols
	version39-41:1.1;
locks;
comment	@ *  @;


1.2
date	92.08.09.20.42.46;	author amiga;	state Exp;
branches;
next	1.1;

1.1
date	92.05.14.19.55.40;	author mwild;	state Exp;
branches;
next	;


desc
@provide WB specific startup to ixemul programs
@


1.2
log
@get rid of some warnings
@
text
@/*
 *  This file is part of ixemul.library for the Amiga.
 *  Copyright (C) 1991, 1992  Markus M. Wild
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  $Id: _wb_parse.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
 *
 *  $Log: _wb_parse.c,v $
 *  Revision 1.1  1992/05/14  19:55:40  mwild
 *  Initial revision
 *
 */

/*
 * Originally written by Olaf "Olsen" Barthel. Thanks Olsen!
 * I left his indentation style...
 */

#define KERNEL
#include "ixemul.h"

#include <workbench/workbench.h>
#include <workbench/startup.h>

#define BASE_EXT_DECL
#define BASE_PAR_DECL  void *iconbase, 
#define BASE_PAR_DECL0 void *iconbase
#define BASE_NAME      iconbase
#include <inline/icon.h>

	/* wb_parse():
	 *
	 *	A more or less decent rewrite of Manx' original
	 *	wb_parse() routine which will do the following:
	 *
	 *	- if open_wb_window is zero no console window
	 *	  will be opened.
	 *
	 *	- if default_wb_window points to a valid string
	 *	  it will be used to open the window.
	 *
	 *	- if everything fails, read the icon file,
	 *	  scan it for a "WINDOW" tool type and take
	 *	  the corresponding tool type entry string
	 *	  (somewhat primitive if compared to the Macintosh
	 *	  way of doing it...).
	 *
	 *	This routine will return TRUE if it was able to
	 *	open an output file, FALSE otherwise.
	 */

int
_wb_parse(struct Process *ThisProcess,struct WBStartup *WBenchMsg,
	  char *default_wb_window)
{
  void  *iconbase;
  char	*WindowName	= NULL;
  int	fd = -1;

		/* Are we to open a console window? */

	if(default_wb_window != (char *)-1)
	{

			/* Any special name preference? */

		if(default_wb_window)
			WindowName = default_wb_window;
		else
		{
				/* Do we have a valid tool window? */

			if(WBenchMsg -> sm_ToolWindow)
				WindowName = WBenchMsg -> sm_ToolWindow;
			else
			{
					/* Open icon.library. */

				if(iconbase = OpenLibrary("icon.library",0))
				{
					struct DiskObject *Icon;

						/* Try to load the icon file. */

					if(Icon = GetDiskObject(iconbase, WBenchMsg -> sm_ArgList[0] . wa_Name))
					{
							/* Look for a "WINDOW" tool type. */

						WindowName = (u_char *) FindToolType(iconbase, (u_char **) Icon -> do_ToolTypes, "WINDOW");
						if (WindowName)
							WindowName = strdup (WindowName);

						FreeDiskObject(iconbase, Icon);
					}

					CloseLibrary(iconbase);
				}
			}
		}

			/* Are we to open a file? */

		if (WindowName)
		  fd = syscall (SYS_open, WindowName, 2);
		if (fd != -1)
		  {
		    /* this fd "should" be 0, since we didn't open any files
		     * till now when running under workbench */
		    if (fd != 0)
		    	ix_panic ("_wb_parse: first opened fd != 0!");

		    ThisProcess -> pr_ConsoleTask	= u.u_ofile[fd]->f_fh->fh_Type;
		    syscall (SYS_dup2, fd, 2); 
		    /* now dup() the descriptor to cover an additional descriptor, 
		     * so that by closing 0-2 pr_ConsoleTask doesn't vanish yet */
		    syscall (SYS_dup2, fd, NOFILE-1);
    		    syscall (SYS_close, fd);

		    
		    fd = syscall (SYS_open, "*", 0);
		    if (fd != -1)
		      ThisProcess -> pr_CIS		= CTOBPTR (u.u_ofile[fd]->f_fh);

		    fd = syscall (SYS_open, "*", 1);
		      ThisProcess -> pr_COS		= CTOBPTR (u.u_ofile[fd]->f_fh);

		    return 1;
		  }
	}

	return(FALSE);
}
@


1.1
log
@Initial revision
@
text
@d19 1
a19 1
 *  $Id$
d21 4
a24 1
 *  $Log$
d28 1
a28 1
 * Originally written by Olaf Barthel. Thanks Olaf!
d102 1
a102 1
						WindowName = FindToolType(iconbase, Icon -> do_ToolTypes,"WINDOW");
@
