/*
 *	File:					execute().h
 *	Description:	Executes a command, pops up a shell-window if needed.
 *								All calles will use the same window.
 *
 *	(C) 1993-1994, Ketil Hunn
 *
 */

#ifndef	EXECUTE_H
#define	EXECUTE_H

BOOL shellopen;	// If TRUE, execute() will use the active shell-window

#define SHELLTITLE "CON:0/18/640/100/Recall Window/AUTO/CLOSE/WAIT"
static ULONG systemtags[]={	SYS_Input, NULL,
														SYS_Output, NULL,
														SYS_UserShell,	TRUE,
														TAG_DONE
													};

void execute(char *line)
{
	if(systemtags[1]==NULL & shellopen==FALSE)
	{
		register BPTR fp;
		register char *t;
		register int inquote=FALSE, usecon=TRUE;

		for(t=line; *t; t++)
		{
			if(*t=='\"')
				if(t<=line || t[-1]!='*')
					inquote^=1;
			if(!inquote)
				if(*t=='>')
				{
					usecon=FALSE;
					break;
				}
		}
		if(usecon==TRUE)
		{
			shellopen=TRUE;
			if(fp=Open(SHELLTITLE, MODE_OLDFILE))
				systemtags[1]=(ULONG)fp;
		}
	}
	SystemTagList(line, (struct TagItem *)systemtags);
}
#endif
