#ifndef	EVAL_H
#define	EVAL_H

#include <v_lib.h>
#include "framebuf.h"

#define	MAX_ID	256

#define	STR_COMP			strcasecmp
#define	STR_EQ(str1,str2)	(!STR_COMP((str1),(str2)))

extern vhandle_t random_gen;

/*
 * Note:
 * If this is changed, the state.c:state_key_table must be changed also.
 */
typedef struct eval_state_s
{
	u32_t		custom_width, custom_height; /* valid if > 0 */
	vboolean	input_powers2;
	vboolean	input_square;
} eval_state_t, *eval_state_p;

/* -------------------------------------------------------------------- */

/*
 * Implemented in state.c
 */
void stateDefault(eval_state_p state);

vboolean stateChange(eval_state_p state,vhandle_t script);

void stateHelp(void);

/* -------------------------------------------------------------------- */

/*
 * Implemented in eval.c
 */

typedef struct arg_s
{
	char	id[MAX_ID];
	int		type; /* matrix, vector, (output ?) */
    eval_state_t state;
	vboolean evaluated;
	union	operand
	{
		void_p data;
		matrix_p matrix;
		vector_p vector;
		/* framebuf_p framebuf; ? */
	} op;
}	arg_t, *arg_p;

void evalHelp();

void matZeroRows(matrix_p m,u32_t row_start,u32_t row_end);

void matZeroCols(matrix_p m,u32_t col_start,u32_t col_end);

void vecRunningSum(vector_p dest,vector_p src);

void vecLinSpaced(vector_p dest,vec_t min,vec_t max);

void matScaleAdd(matrix_p dest,matrix_p src,vec_t scale,vec_t offset);

vboolean scriptEvalMatrix(arg_p arg,vhandle_t script);

vboolean scriptEvalVector(arg_p arg,vhandle_t script);

void evalFreeAllArgs(void);

void evalDestroyAllFourierTransformers(void);

vboolean evalAll(vhandle_t script);

vboolean evalOutput(char *file_name,vhandle_t script);

vboolean evalRealFunction(vhandle_t script,vec_t *result);

vboolean evalIntFunction(vhandle_t script,s32_t *result);

vboolean evalUIntFunction(vhandle_t script,u32_t *result);

#endif /* EVAL_H */
