#DEFINE _EP_FLAGS_COMSPEC   0x00000001	// Run using command processor
#DEFINE _EP_FLAGS_KEYWAIT   0x00000002	// Unsupported
#DEFINE _EP_FLAGS_DONTWAIT  0x00000004	// Do not wait for program to complete
#DEFINE _EP_FLAGS_APPEND    0x00000008	// Append to end of redirection file
#DEFINE _EP_FLAGS_NOBYPASS	0x00000010	// Do not display Bypass dialog
#DEFINE _EP_FLAGS_WDPROG    0x00000020	// Use program directory as working dir
#DEFINE _EP_FLAGS_BNDASDOS  0x00000040	// Run bound program as Dos program
#DEFINE _EP_FLAGS_VMEXEC    0x00000080	// Unsupported
#DEFINE _EP_FLAGS_NOEXEC    0x00000100	// Internal use only
#define _EP_Flags_RunBkg		0x00000200	// Run program in the background
#define _EP_Flags_SkipExec	0x00000400	// Do not run DOSEXEC for Dos programs
#define _EP_Flags_NoSavFile 0x00000800	// Do not do an auto file save

#define _EP_Flags_ExeAuto		0x00000000	// Autodetect program exe type
#define _EP_Flags_ExeDos    0x00001000	// Run as a Dos program
#define _EP_Flags_ExeWin    0x00002000	// Run as a Windows program
#define _EP_Flags_ExeOs2    0x00003000	// Run as an Os/2 program
#define _EP_Flags_ExeW32C   0x00004000	// Run as a Win32 console program
#define _EP_Flags_ExeMask		0x00007000	// Mask for the Exe types flags

#DEFINE _EP_FLAGS_NORMAL		0x00000000	// Show window in normal state
#DEFINE _EP_FLAGS_HIDE			0x00010000	// Hide window
#DEFINE _EP_FLAGS_MINIMIZED 0x00020000	// Show window in minimized state
#DEFINE _EP_FLAGS_MAXIMIZED 0x00030000	// Show window in maximized state
#DEFINE _EP_FLAGS_SHOWMASK  0x00030000  // Mask for the show flags

// Exec ruturn codes.
// Returned by:  ExecProg, WinExecAndWait, DosExec

#DEFINE _EXEC_Success 0
#DEFINE _EXEC_Error   1   // See ExecErrorCode below
#DEFINE _EXEC_Abort  -1

/* PIF flags. */
#define fExcl      0x00000001 /* Exclusive mode. */
#define fpifBack   0x00000002 /* Runs in background. */
#define fpifWindow 0x00000004 /* Runs in a window. */
#define fpifAltTab 0x00000020 /* Alt-Tab reserved. */
#define fpifAltEsc 0x00000040 /* Alt-Esc reserved. */
#define fpifAltSp  0x00000080 /* Alt-Sp reserved. */
#define fpifAltEnt 0x00000100 /* Alt-Ent reserved. */
#define fpifAltPsc 0x00000200 /* Alt-PrtSc reserved. */
#define fpifPrtSc  0x00000400 /* PrtSc reserved. */
#define fpifCtlEsc 0x00000800 /* Ctl-Esc reserved. */
#define fpifIdle   0x00001000 /* Detect idle. */
#define fpifNoHMA  0x00002000 /* Don't use High Mem. */
#define fpifEmsLok 0x00008000 /* EMS memory locked. */
#define fpifXmsLok 0x00010000 /* XMS memory locked. */
#define fpifFPaste 0x00020000 /* Allow Fast Paste. */
#define fpifAppLok 0x00040000 /* Lock app. memory. */
#define fpifCloseE 0x40000000 /* Close on exit. */

/* Display flags. */
#define fdisEmText 0x00000001 /* Emulate text mode. */
#define fdisNoText 0x00000002 /* No monitor text mode. */
#define fdisNoLow  0x00000004 /* No monitor low gfx. */
#define fdisNoHigh 0x00000008 /* No monitor high gfx. */
#define fdisRetain 0x00000080 /* Retain video memory. */

// This is the struct that is passed to the DLL CALL
struct VMDEF
{
		ASCIIZ  title   [128];  // title of window if in windowed mode
		ASCIIZ  exePath [128];  /* Path of .exe to run. */
		ASCIIZ  exeArgs [128];  /* Argument list. */
		ASCIIZ  workDir [128];  /* Working drive/dir. */
		int     pifFlags;       /* PIF flags. */
		int     disFlags;       /* Display flags. */
		WORD    pageWant;       /* Desired V86 pages for VM. */
		WORD    pageMin;        /* Minimum V86 pages for VM. */
		WORD    forePriority;   /* Foreground priority. */
		WORD    backPriority;   /* Background priority. */
		WORD    kbMaxEMS;       /* Maximum EMS KB. */
		WORD    kbMinEMS;       /* Minimum EMS KB. */
		WORD    kbMaxXMS;       /* Maximum XMS KB. */
		WORD    kbMinXMS;       /* Minimum XMS KB. */
}

global
{
	int ExecReturnCode  "!ExecReturnCode";    // Return code from DOS programs
	int ExecErrorCode   "!ExecErrorCode";     // Error code when _EXEC_ERROR is returned
	int ExecId          "!ExecId";            // The type of program last executed
																						// see IDEXEC.SH for values

	int DosExecMethod   "!DosExecMethod";
	int ExecKeep				"@ExecKeep";
	int ExecNoDisplay		"@ExecNoDisplay";
	int ExecShutdown 		"!ExecShutdown";
	int g_DosExecInUse	"~DosExecInUse";
	int g_Os2ExecInUse	"~Os2ExecInUse";
	int g_W32ExecInUse	"~W32ExecInUse";
	int g_BeepTaskDone	"!BeepTaskDone";	// True to beep on background task done
	int g_UseW32Exec		"!UseW32Exec";

	str BkgTaskMac			"@BkgTaskMac";    // Background task process macro
}
#DEFINE _DosExec_Direct   1
#DEFINE _DosExec_PIF      0
#DEFINE _DosExec_ExecVM   2

#define _ExecExit_Doit		0
#define _ExecExit_Prompt	1
#define _ExecExit_Keep		2

#define _QExecDos					0
#define _QExecOs2					1
#define _QExecW32					2

// Errors returned in ExecErrorCode
#define _ExecEC_ExecInUse	-1

prototype winexec
{


	int ExecProg( str prog,      // = parse_str("/PROG=", mparm_str),
															 //  The command line

								str working_dir, // parse_str("/WD=",mparm_str),
								str stdout_file, // = parse_str("/RED=", mparm_str),
																 // The filename to output STDOUT to
																 // (Dos .EXE files only)

								str stderr_file, // = parse_str("/REDERR=", mparm_str),
																 // The filename to output STDERR to
																 // (Dos .EXE files only)

								int flags        // = parse_int("/FLAGS=", mparm_str )
																 // Flags.  See #DEFINE _EP_FLAGS_xxxx above
						 );

	INT WinExecAndWait( STR Path,
											STR working_dir,
											INT flags,
											STR title,
											STR semiphore_file
										);

	int DosExec( STR path,
							 STR working_dir,
							 INT Visibility,
							 STR stdio_file,
							 STR stderr_file,
							 INT flags
							);

	int Os2Exec( str Path,
							 str Working_Dir,
							 int Visibility,
							 str Stdio_File,
							 str Stderr_File,
							 int Flags
						 );

	int QueryExec( int Exit, int TypeExec );
/******************************************************************************
	Function: Check for currently running EXEC program and shut it down when Exit
						is True.

	Entry   : int Exit   		- Set to cause currently running DOSEXEC to exit.
												 		Note: use /EXIT=1 when calling from command line.

						int TypeExec	- The type of EXEC to check for.  Possible values are
														_QExecDos for DOSEXEC
														_QExecOs2 for OS2EXEC
														_QExecW32C for W32EXEC
	Exit    : int
							True 		- EXEC is currently running
							False   - EXEC is NOT running
********************************************************************( ldh )***/

	void ExecShutdown( );
/******************************************************************************
  Function: Prompt for and shutdown the running DosExec and Os2Exec programs.
********************************************************************( ldh )***/

	str ExecSearchPath( str Program, str Path );
/******************************************************************************
  Function: Searches for a filename in a given path TranslateCmdLine is called
						to parse out any metacommands BEFORE the search takes place.  When
						extension is blank will try to find an executable file .COM .EXE
						.BAT .CMD

  Entry   : str Program	- The executable file name to search for
						str FPath		- The path to search

  Exit    : str					-	Complete path and filename, or a NUL string if the
													search was not successful.
********************************************************************( ldh )***/

	int ExecChkTask( int TaskNo );
/******************************************************************************
	Function: Return the number of background task running ( TaskNo == 0 ) or
 						the handle number of the running task TaskNo.

	Entry   : int TaskNo	- The number of the task to check the status on.
													Use 0 to return the number of running tasks.

	Exit    : int
										( TaskNo == 0 )
							#   - Number of running background tasks

										( TaskNo != 0 )
							0		- TimerEvent for TaskNo not running
							#		- Handle of the TimerEvent for the running task TaskNo
********************************************************************( ldh )***/

	int ExecProcessTask( int TaskNo, str TaskStr, int Prompt );
/******************************************************************************
  Function: Run the process macro for TaskNo and remove the task from the
						running task list.

  Entry   :	int TaskNo  - The Task number to process
						str TaskStr	- The task string. "" will get the string for the
													globals.
						int Prompt	- True will show a prompt before removing a running task
													from the list
  Exit    : int
							True		- Task processed
							False		- Task not finished running
********************************************************************( ldh )***/

	void ExecTaskDlg( int SwitchFocus );
/******************************************************************************
  Function: Show and update the running tasks list modeless dialog.
  Entry   : int SwitchFocus	- When True will cause the focus to be changed
															to the task list dialog. ( "/S=1" )
********************************************************************( ldh )***/

	int ExecQueryNoTasks( );
/******************************************************************************
  Function: Check to see if there are no tasks defined.
  Exit    : int
							True		- Tasks defined
							False		- No tasks defined
********************************************************************( ldh )***/

	int QueryRunTasks( int Prompt );
/******************************************************************************
  Function: Checks to see if any background tasks are running. A remove task
						prompt is shown when Prompt is True

  Entry   : int Prompt	- True will show a remove task prompt.
  Exit    : int
							True			- Running tasks found.
							False			- No tasks running.
********************************************************************( ldh )***/
}

IMPORT DWORD VMExec (POINTER pVMdefRecord) MEWTOOLS 501;
