SYNOPSIS#include <sys/types.h>
#include "dbquery.h"
int foaddfuncs(fo, ff, n)
FLDOP *fo;
FLDFUNC *ff;
int n;
DESCRIPTION
Foaddfuncs adds a function to the math unit of Texis. The function
can take up to five arguments, and returns a single argument. The function
will be called with pointers to FLD structures. The return values
should be stuffed into the pointer to the first argument.
The math unit takes care of all the required stack manipulation, so no stack manipulation is required in the function. The math unit will always pass the maximum number of arguments to the function.
Foaddfuncs takes an array of function descriptions as one of its
arguments. The functions description function looks like
struct {
char *name; /* name of function */
int (*func)(); /* handler */
int minargs; /* minimum # of arguments allowed */
int maxargs; /* maximum # of arguments allowed */
int rettype; /* return type */
int types[MAXFLDARGS]; /* argument types, 0 means don't care */
} FLDFUNC;
Parameters
EXAMPLEint
fsqr(f)
FLD *f;
{
int x;
size_t sz;
x = *(ft_int *)getfld(f, &sz); /* Get the number */
x = x * x ; /* Square it */
putfld(f, x, 1); /* Put the result */
return 0;
}
static FLDFUNC dbfldfuncs[]=
{
{"sqr", fsqr, 1, 1, FTN_INT, FTN_INT, 0, 0, 0, 0 },
};
#define NFLDFUNCS (sizeof(dbfldfuncs)/sizeof(dbfldfuncs[0]))
foaddfuncs(fo, dbfldfuncs, NFLDFUNCS);
This will add a function to square an integer.