
#define DECSIZE 	16
#define DECUNKNOWN	-2

struct decimal
    {
    short dec_exp;		/* exponent base 100		*/
    short dec_pos;		/* sign of number 1=pos, 0=neg	*/
    short dec_ndgts;		/* number of significant digits	*/
    char  dec_dgts[DECSIZE];	/* actual digits base 100	*/
    };
typedef struct decimal dec_t;


 /* C language types */

#define CCHARTYPE	100
#define CSHORTTYPE	101
#define CINTTYPE	102
#define CLONGTYPE	103
#define CFLOATTYPE	104
#define CDOUBLETYPE	105
#define CBYTETYPE	106
#define CDECIMALTYPE	107
#define CFIXCHARTYPE	108
#define CSTRINGTYPE	109
#define CDATETYPE	110
#define CMONEYTYPE	111


#define USERCOLL(x)	((x))


/*
 * Define all possible database types
 *   include C-ISAM types here as well as in isam.h
 */

#define SQLCHAR		0
#define SQLSMINT	1
#define SQLINT		2
#define SQLFLOAT	3
#define SQLSMFLOAT	4
#define SQLDECIMAL	5
#define SQLSERIAL	6
#define SQLDATE		7
#define SQLMONEY	8
#define SQLNULL		9
#define SQLTYPE		0xF	/* type mask		*/
#define SQLNONULL	0400	/* disallow nulls	*/

/* this is not a real type but a flag to show that the
 * value is from a host variable
 */
#define SQLHOST		01000


#define DATENULL	0x80000000L


struct value
    {
    short v_type;		/* type of value, determines	*/
    short v_ind;		/* null indicator		*/
    short v_prec;		/* decimal precision		*/
    union			/* which of following is valid	*/
	{
	struct			/* char value (not null terminated) */
	    {
	    char *vcp;		/* ptr to char string value	*/
	    short vidx;		/* unused			*/
	    short vlen;		/* len of char string value	*/
	    } vchar;
	int vint;		/* integer value		*/
	long vlng;		/* long value (also dates)	*/
	float vflo;		/* float value			*/
	double vdub;		/* double value             	*/
	dec_t vdec;		/* decimal value (also money)	*/
	} v_val;
    };
#define v_charp		v_val.vchar.vcp
#define v_index		v_val.vchar.vidx
#define v_len		v_val.vchar.vlen
#define v_int		v_val.vint
#define v_long		v_val.vlng
#define v_float		v_val.vflo
#define v_double	v_val.vdub
#define v_decimal	v_val.vdec


typedef struct value * valueptr;
typedef struct value * acevalue;
typedef struct value * perfvalue;


extern struct value retstack;

#define intreturn(i)	{retstack.v_type=SQLSMINT;\
			retstack.v_int=(i);\
			return(&retstack);}

#define lngreturn(i)	{retstack.v_type=SQLINT;\
			retstack.v_long=(i);\
			return(&retstack);}

#define floreturn(d)	{retstack.v_type=SQLSMFLOAT;\
			retstack.v_float=(d);\
			return(&retstack);}

#define dubreturn(d)	{retstack.v_type=SQLFLOAT;\
			retstack.v_double=(d);\
			return(&retstack);}

#define strreturn(s,c)	{retstack.v_type=SQLCHAR;\
			retstack.v_charp=(s);\
			retstack.v_len=(c);\
			return(&retstack);}


#define decreturn(d)	{retstack.v_type=SQLDECIMAL;\
			deccopy(&d, &retstack.v_decimal);\
			return(&retstack);}

extern int toint();	/* toint() takes a pointer to value structure 
			 *          as an argument.
			 *          Returns the value (converted to integer)
			 *          of the value structure (v_int).
			 */
extern long tolong();	/* tolong() takes a pointer to value structure 
			 *          as an argument.
			 *          Returns the value (converted to long)
			 *          of the value structure (v_long).
			 */
extern double todouble();/* todouble() takes a pointer to value structure
			 *          as an argument.
			 *          Returns the value (converted to double)
			 *          of the value structure (v_double).
			 */
extern long todate();	/* todate() takes a pointer to value structure
			 *	    Returns the value (converted to long)
			 *	    of the value structure (v_long).
			 */
extern double tofloat();/* tofloat() takes a pointer to value structure
			 *	    as an argument.
			 *	    Returns the value (converted to double)
			 *	    of the value structure (v_double).
			 */
extern int todecimal(); /* todecimal() takes a pointer to a value structure
			 *	    as the first argument, and a pointer to
			 *	    a dec_t structure as a second argument.
			 */

#define intcon	toint
#define longcon	tolong
#define dubcon	todouble


struct ufunc
	  {
	  char *uf_id;
	  struct value *(*uf_func)();
	  };

/*
 * The structure declaration for "userfuncs" must be put in the 
 * user's data area. A hypothetical case using the user C functions
 * called "userfunc1" and "userfunc2" is shown below.
 *
 *  valueptr userfunc1();  These routines must be externed before
 *  valueptr userfunc2();  the userfuncs structure is initialized
 *
 *  struct ufunc userfuncs[] =
 *       {
 *	 "userfunc1", userfunc1,
 *	 "userfunc2", userfunc2,
 *        ^           ^__________Pointer to the user function.
 *	  |______________________The name of the user function
 *	                         as defined in the DEFINE statement of ACE.
 *	 0,0 <-------------------Note that this array must be terminated
 *				       by two zeros.
 *	 };
 *
 * These structures are required so that ACE can call the user subroutines
 * at run time.
 */

