Figure 14 for An Introduction to Extending the Rexx Language
The Rexx API - An Introduction to Extending the Rexx Language
Figure 14
/* ===================================================================
*
* Module: myfuncs.c
* Type: C
* Description: this is a sample external function definition for
* Personal Rexx for Microsoft Windows NT.
*
* Usage: the following describes the sample functions within
* this package and how they are used by a calling EXEC:
*
* ++++ f2c( n ): convert fahrenheit to celsius.
*
* RxFuncAdd( 'f2c', 'myfuncs', 'f2c' )
* c_temp = f2c( f_temp )
*
* ++++ c2f( n ): convert celsius to fahrenheit.
*
* RxFuncAdd( 'c2f', 'myfuncs', 'c2f' )
* f_temp = c2f( c_temp )
*
* ++++ Load(): this function registers all of the functions
* in the myfuncs package with the interpreter
*
* RxFuncAdd( 'Load', 'myfuncs', 'Load' )
* ret_code = Load()
*
* example:
* rc = Load()
*
* ++++ UnLoad(): this function de-registers all of the functions
* in the myfuncs package with the interpreter
*
* RxFuncAdd( 'UnLoad', 'myfuncs', 'UnLoad' )
* ret_code = UnLoad()
*
* example:
* rc = UnLoad()
*
*/
#include
#include
#define INCL_RXFUNC
#include
#define RX_OK 0
#define RX_ERROR 1
typedef struct _tagEXTFUNCTIONS {
char *szFName;
char *szDll;
char *szPName;
} EXTFUNCTIONS;
EXTFUNCTIONS func[] = {
{ "f2c", "myfuncs", "c2f" },
{ "c2f", "myfuncs", "c2f" },
{ "Load", "myfuncs", "Load" },
{ "UnLoad", "myfuncs", "UnLoad" },
};
#define MAX_FUNCS sizeof( func ) / sizeof( EXTFUNCTIONS )
/*
* function prototypes, f2c and the others use the provided
* typedef, while c2f does not, for comparison.
*/
RexxFunctionHandler f2c;
DWORD c2f( LPCSTR, DWORD, PRXSTRING, LPCSTR, PRXSTRING );
RexxFunctionHandler Load;
RexxFunctionHandler UnLoad;
/* --------------------------------------------------------------------
* f2c
*
* This function converts the value passed to degrees celsius.
*
* Usage:
* RxFuncAdd( 'f2c', 'myfuncs', 'f2c' )
* c_temp = f2c( f_temp )
*/
DWORD
f2c( LPCSTR szFunctionName,
DWORD ArgCount,
PRXSTRING Arg,
LPCSTR szQueueName,
PRXSTRING lprxsReturn )
{
float n;
if( (int)ArgCount == 1 )
sscanf( Arg->strptr, "%f", &n );
else
return RX_ERROR;
n = 5*(n-32)/9;
lprxsReturn->strlength =
sprintf( lprxsReturn->strptr, "%f", n );
return RX_OK;
}
/* --------------------------------------------------------------------
* c2f
*
* This function converts the value passed to degrees fahrenheit
*
* Usage:
* RxFuncAdd( 'c2f', 'myfuncs', 'c2f' )
* f_temp = c2f( c_temp )
*/
DWORD
c2f( LPCSTR szFunctionName, /* function name */
DWORD Argc, /* argc */
PRXSTRING Argv, /* argv */
LPCSTR szQueueName, /* ext. data queue */
PRXSTRING lprxsReturn ) /* return string */
{
float n; /* var for the user's arg */
if( (int)Argc == 1 )
sscanf( Argv->strptr, "%f", &n );
else
return RX_ERROR;
n = 9*(n+32)/5;
lprxsReturn->strlength =
sprintf( lprxsReturn->strptr, "%f", n );
return RX_OK;
}
/* --------------------------------------------------------------------
* Load
*
* This function registers all of the external functions defined in
* the myfuncs dll.
*
* Usage:
* RxFuncAdd( 'Load', 'myfuncs', 'Load' )
* ret_code = Load()
*
*/
DWORD
Load( LPCSTR szFunctionName,
DWORD Argc,
PRXSTRING Argv,
LPCSTR szQueueName,
PRXSTRING lprxsReturn )
{
DWORD dwRC;
int i;
for( i=0; istrlength =
wsprintf( lprxsReturn->strptr, (LPSTR)"ERROR" );
return RXFUNC_OK;
break;
}
}
}
lprxsReturn->strlength =
wsprintf( lprxsReturn->strptr, (LPSTR)"OK" );
return RXFUNC_OK;
}
/* --------------------------------------------------------------------
* UnLoad
*
* This function de-registers all of the external functions defined in
* the myfuncs dll.
*
* Usage:
* RxFuncAdd( 'UnLoad', 'myfuncs', 'UnLoad' )
* ret_code = UnLoad()
*
*/
DWORD
UnLoad( LPCSTR szFunctionName,
DWORD ArgCount,
PRXSTRING Arg,
LPCSTR szQueueName,
PRXSTRING lprxsReturn )
{
DWORD dwRC;
int i;
for( i=0; istrlength =
wsprintf( lprxsReturn->strptr, (LPSTR)"ERROR" );
return RXFUNC_OK;
break;
}
}
}
lprxsReturn->strlength =
wsprintf( lprxsReturn->strptr, (LPSTR)"OK" );
return RXFUNC_OK;
}
/*
* eof myfuncs.c
*/
Return to Contents
Bill Potvin
bill.potvin@network.com