#ifndef __cvariables__
#define __cvariables__

#include "stdarg.h"
#include <stdio.h>


#define MAX_CGI_VAR_LEN	50

typedef struct _L_Variables
{
	char name[MAX_CGI_VAR_LEN+1];
	char * value;
	int	opts;		// options? used by some decendants
	struct _L_Variables * next;

} L_Variables;



class CVariables
{
public:
	friend	class CGIList;

	CVariables(  );

	~CVariables( );

	void 	RenameVariable( const char * name, const char * newname );
	void	LetInt16( char * var, const int value );  // Set the variable to an integer value
	void	LetStr( const char * var, const char * value );	// Set the variable to a string value
	void	LetStrf( char * var, const char * format, ... );
	void	vLetStrf( char * var, const char * format, va_list ap );
	void	LetStr( char * var, const char * value, int len );
					// Set the variable to a string value and truncate to len

	void	StrCat( char * var, const char * format, ... );
	void	StrCatf( char * var, const char * format, ... );

	char 	* GetVariable( const char * var );	// Obtain the variable value and return its temp location
	char 	* GetVariable( const char * var, char * result, int size );
					// Obtain the variable value and return it in 'result'
	char 	* GetVariable( const char * var, bool test, char * section = "" );
	long	GetVariableLong( char * name, bool *valid = NULL );
	long	GetVariableLong( char * name, bool test, char * section = "" );
	bool	GetBool( char * var, bool test = false, char * section = "" );

	void	PrintVars( FILE * f = stdout );	// Print out all variables to file pointed to by 'f'

	void	Cleanup();

	L_Variables * var, * var_top;
	
	L_Variables * FindVariable( const char * var, bool create=false );
		// Obtains the next variable during the template parsing process

};


#endif
