/************************************************************************/
/* Copyright 2010 MBARI													*/
/************************************************************************/
/* Summary	: Definitions for application scripting						*/
/* Filename : script.h													*/
/* Author	: Robert Herlien (rah)										*/
/* Project	: Respirometers												*/
/* Revision : 1.0														*/
/* Created	: 10/05/2010												*/
/*																			*/
/* MBARI provides this documentation and code "as is", with no warranty,	*/
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium	*/
/* Research Institute to assist in its use, correction, modification, or	*/
/* enhancement. This information should not be published or distributed to	*/
/* third parties without specific written permission from MBARI.			*/
/*																			*/
/************************************************************************/
/* Modification History:												*/
/* 05oct2010 rah - created												*/
/* $Log $
*/
/************************************************************************/

#ifndef INCscripth
#define INCscripth		1

#include <list.h>
#include <time.h>

#define NEST_DEPTH		4
#define MAX_ARGS		15
#define NAMELEN			32
#define LINELEN			256
#define SCRIPT_DONE		(-20)


#define FLG_FOREVER		1
#define FLG_INTERVAL	2

typedef struct					/****************************************/
{								/* Structure to hold loop cnt and return*/
	Int32		loopCnt;		/* Current loop counter					*/
	Int32		loopEnd;		/* Loop end test						*/
	Nat32		flags;			/* Flags (forever, interval)			*/
	Nat32		startTime;		/* Time started current loop			*/
	Nat32		period;			/* For repeat_interval (seconds)		*/
	long		returnPos;		/* Where in file to loop to				*/
	long		returnLine;		/* Line number for loop return			*/
} ScriptLoop;					/****************************************/

typedef struct					/****************************************/
{								/* Struct to hold script variables		*/
	Node		sNode;			/* Node for linked list					*/
	char		fname[NAMELEN]; /* Name of file we're executing			*/
	Tid			td;				/* Thread running script				*/
	long		fpos;			/* Current position in file				*/
	long		lineno;			/* Current line number					*/
	Nat32		lineTime;		/* Time started on current line			*/
	Int32		nestLevel;		/* Current nest level of loops			*/
	ScriptLoop	loop[NEST_DEPTH]; /* Variables for nested loops			*/
	char		*argv[MAX_ARGS];  /* argv ptr							*/		
	char		linebuf[LINELEN]; /* Buffer for current line			*/
} ScriptDesc;					/****************************************/

typedef ScriptDesc		*SDPtr;

typedef struct					/****************************************/
{								/* Script function pointers				*/
	char		*funcName;		/* Name to match						*/
	Errno		(*func)();		/* Function ptr							*/
} ScriptFunc;					/****************************************/


/****************************************/
/* Function Declarations				*/
/****************************************/

Void	initScript();
Int16	showScript(Void);
Errno	readScriptLine(ScriptDesc *sd);
Errno	runScriptLine(ScriptDesc *sd, MBool syntaxOnly);
Void	runScript(ScriptDesc *sd);
Errno	syntaxCheckScript(ScriptDesc *sd);
Errno	parseScript(char *s);
ScriptDesc *findScript(char *fname);
Int16	startScript(Nat16 pmask, char *fname);
Int16	stopScript(Nat16 pmask, char *fname);
Int16	restartScript(Nat16 pmask, char *fname);

#endif	/* INCscripth */
