foaddfuncs - Add functions

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

fo
The math unit to add to.
ff
Array of function descriptions to be added.
n
The number of functions being added.


EXAMPLE

int
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.


Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.