Dec 092017
Write UDF's in C for Quick SIlver.
File UDF_IN_C.ZIP from The Programmer’s Corner in
Category Dbase Source Code
Write UDF’s in C for Quick SIlver.
File Name File Size Zip Size Zip Type
MYFUNC.C 275 166 deflated
MYPROG.PRG 23 23 stored
QSUDF.H 968 359 deflated
READ.ME 3638 1535 deflated

Download File UDF_IN_C.ZIP Here

Contents of the READ.ME file

The contents of this ARCed file are:
READ.ME (This file)

Following is an extract from the QS 1.2 READ_ME.QS file, explaining how to
have UDFs in C.

== UDFs in C ==

User Defined Functions (UDFs) allow the programmer to add new
functions to the dBASE language. Release 1.1 of Quicksilver
allowed only UDFs written in dBASE, but allowed one to call C
programs using the CCALL command. Returning values to your program
was needlessly difficult, and making the C function act as a UDF
required embedding CCALL in a Quicksilver function file. Now you
can call your C functions directly and have them return values in
a way similar to standard C conventions. This makes programming
easier and results in faster execution speed.

The only C compiler directly supported for UDFs at this time is
the Lattice C Compiler, preferably version 3.0 or higher.

UDFs in C are called from your dBASE program like any of the
standard functions. For example, a C function calculating the sine
of an angle can be called with the following line:

x = sin(45)

Your C source file must include the C header file QSUDF.H with the
line :

#include "QSUDF.H"

The file QSUDF.H, which is distributed with Quicksilver, must be
accessible to your C compiler, so you will have to either copy it
into your include file directory or set your C compiler's include
path to search your Quicksilver directory. This file sets up some
external function definitions, as well as several macros that you
will need to use in your C function.

On entry to your C function you should test the parameter list
passed from your program using the following macros and return an
error if the parameters passed do not match those required by your
C function.

PCOUNT - returns the number of parameters passed
ISCHAR(n) - returns a zero if parameter number n is a C; a non-
zero number if it is not
ISNUM(n) - same as above, except checks for numerics
ISLOG(n) - same as above, except checks for logicals
ISDATE(n) - same as above, except checks for date types
ISMEMO(n) - same as above, except checks for memo fields

To actually obtain the parameter values, you must use one of the
functions below :

_parc(n) - returns a character pointer to parameter n
_parni(n) - returns an integer value for parameter n
_parnl(n) - returns a long value for parameter n
_parnd(n) - returns a double for parameter n
_parl(n) - returns a logical value 0 or 1 for n
_pards(n) - returns a character pointer to a date string for
parameter n in the form YYYYMMDD

To set the value to be returned to by your UDF you must use one of
the functions below :

_retc(char *) - returns a character string
_retni(int) - returns an integer
_retnl(long) - returns a long
_retnd(double) - returns a double
_retl(int) - returns a logical
_retds(char *) - returns a date

Note that you MUST use one of these functions to maintain the
integrity of Quicksilver's internal stack.

See the sample programs MYFUNC.C, and MRPROG.PRG, which may be
found on the UTILS directory, for a better idea of how to
implement a UDF in C

Putting Everything Together

1) Compile your C program with the Lattice C compiler using the -
ml option. Example:

lc -ml myfunc

2) Compile your Quicksilver program using the normal DB3C, DB3L -q
sequence. Example:

db3c myprog
db3l -q myprog

3) Run the Quicksilver optimizer with the -C!objectfile option.

QS -C!myfunc myprog

4) Execute the program, and check to make sure the function
returns values properly.

 December 9, 2017  Add comments

Leave a Reply