You map routine identifiers to C functions in the PRODSP() dispatch routine. ABL provides a prototype PRODSP() in the C source file, hlprodsp.c.
Note: The $DLC/oebuild/hlc directory on UNIX and the %DLC%\oebuild\hlc directory in Windows contain a prototype hlprodsp.c file. Do not modify this file. To make changes, copy it to a working directory and modify the copy.
Because ABL calls the PRODSP() dispatch routine, it must have the following declaration:
PRODSP(pfunnam, argc, argv)
char *pfunnam, /* Name of function to call */
int *argc, /* CALL statement argument count */
char *argv[], /* CALL statement argument list */
The hlprodsp.c file shows routine-identifier hlcroutine being mapped to the C function hlcfunc() in PRODSP():
/* PROGRAM: PRODSP
*
* This is the interface to all C routines that
* ABL has associated 'CALL' statements to.
*/
long
PRODSP(pfunnam, argc, argv)
char *pfunnam; /* Name of function to call */
int argc; /* CALL statement argument count */
char *argv[]; /* CALL statement argument list */
{
FUNCTEST("HLCROUTINE", hlcfunc);
return 1; /* Non-zero return code causes OpenEdge error */
} /* condition if CALLed routine not found. */
For each routine you add, you must include a call to the FUNCTEST macro. For example, to map two routine names, such as HLCROUTINE1 and HLCROUTINE2, to two corresponding C functions, such as hlcfunc1() and hlcfunc2(), you must include the following lines in PRODSP():
This is the syntax for the FUNCTEST macro in hlprodsp.c:
The routine-identifier is the name referenced by a CALL statement that identifies your C function. Enter the routine identifier as a character string surrounded by quotes. Since FUNCTEST does not convert case for the routine identifier, the case is significant.
The function-name is the name of the C function that the routine-identifier references.
The routine identifier and the function name can have the same name, for example:
FUNCTEST("hlcfunc", hlcfunc);
When you compile hlprodsp.c, the C compiler translates the FUNCTEST macro references to C code, for example:
FUNCTEST("HLCROUTINE", hlcfunc);
Translates to:
if (strcmp("HLCROUTINE", pfunnam) == 0)
return hlcfunc(argc,argv);
Therefore, when ABL invokes PRODSP() with the argument HLCROUTINE, it runs hlcfunc.