fosetop - Add an operator

SYNOPSIS

#include <sys/types.h>
#include "dbquery.h"

int fosetop(fo, type1, type2, func, ofunc)
FLDOP *fo;
int type1;
int type2;
fop_type func;
fop_type *ofunc;


DESCRIPTION
Fosetop changes a binary operator in the math unit of Texis. The function func will be called for all operations on (type1, type2). If the function does not know how to handle the specific operation, and ofunc is not NULL, ofunc can be called to hande the operation.

The function being called should look like

int
func(f1, f2, f3, op)
FLD *f1;
FLD *f2;
FLD *f3;
int op;
{
}

Parameters

fo
The math unit to change.
type1
The type of the first operand.
type2
The type of the second operand.
func
Pointer to the function to perform the operation.
ofunc
Pointer to pointer to function. The pointer to function will be stuffed with the old function to perform the operation. This can be used to add some cases, and keep the old functionality in others. The return value should be 0 for success. The result of the operation should be put in f3.


EXAMPLE

#include <sys/types.h>
#include "dbquery.h"

fop_type o_ftich;          /* the pointer to the previous handler */

int
n_ftich(f1, f2, f3, op)
FLD     *f1;
FLD     *f2;
FLD     *f2;
int     op;
{
        TIMESTAMP       *ts;
        double          d;
        int             n;

        if (op != FOP_ASN)      /* We only know about assignment. */
                if (o_ftich)
                        return ((*o_ftich)(f1, f2, f3, op));
                else
                        return FOP_EINVAL;

        /* Set up the return field. */
        f3->type = FTN_TIMESTAMP;
        f3->elsz = sizeof(TIMESTAMP);
        f3->size = sizeof(TIMESTAMP);
        f3->n = 1;
        if(sizeof(TIMESTAMP) > f3->alloced)
        {
                void *v;

                v = malloc(sizeof(TIMESTAMP));
                setfld(f2, v, sizeof(TIMESTAMP));
                f3->alloced = sizeof(TIMESTAMP);
        }

/* First 0 out all the elements */
        ts = getfld(f1, NULL);
        ts->year = 0;
        ts->month = 0;
        ts->day = 0;
        ts->hour = 0;
        ts->minute = 0;
        ts->second = 0;
        ts->fraction = 0;

/* Now read in the values */
        n = sscanf(getfld(f2, NULL), "%hu/%hu/%hd %hu:%hu:%hu%lf",
                &ts->month, &ts->day, &ts->year,
                &ts->hour, &ts->minute, &ts->second, &d);

/* Convert any fractional seconds into the appropriate number
   of billionths of a second.
*/
        if (n == 7)
                ts->fraction = d * 1000000000 ;
}

 .
 .
 .
        fosetop(fo, FTN_TIMESTAMP, FTN_CHAR, n_ftich, &o_ftich);
 .
 .
 .

This example adds an operator to allow the assignment of a TIMESTAMP field from a character string. See dbaddtype for the definition of TIMESTAMP.


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.