Chapter Contents |
Previous |
Next |
cmsrxfn |
Portability: | SAS/C extension |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
CAUTIONS | |
IMPLEMENTATION | |
EXAMPLE |
SYNOPSIS |
#include <cmsexec.h> int cmsrxfn(int argc, const char *argv[], int fncc, REXX_FNC fncv[]);
DESCRIPTION |
cmsrxfn
defines a set of C functions that can be called directly from
the System Product Interpreter (REXX).
fncc
specifies the number of functions that can be called in this manner,
and
fncv
is a pointer to
an array of function pointers. Each function pointer in the array points
to a function of type REXX_FNC that can be called by REXX. The
argc
and
argv
parameters are the command-line parameters passed to the
main
function in the C function
package. These parameters should not be altered before passing them to
cmsrxfn
.
RETURN VALUE |
The nature of
cmsrxfn
is such that it does not return under usual circumstances.
Therefore,
cmsrxfn
does
not return the normal successful return code of
0
. If
cmsrxfn
cannot
allocate enough storage for control blocks or cannot install the module as
a nucleus extension, it returns
-1
. If the module is terminated by an ABEND under CMS,
cmsrxfn
returns
1
. If the module is terminated by a NUCXDROP
command,
cmsrxfn
returns
2
.
CAUTIONS |
REXX typically calls a function package with a parameter list of the following form:
RXLOCFN LOAD FUNC1
This parameter list is passed to the
main
function via
argc
and
argv
. These
parameters should be passed directly to
cmsrxfn
without modification.
REXX calls a function in a function package with a parameter
list in the form of an array of pairs of character pointers and integers,
each pair describing a parameter. (Refer to The SAS/C Library Interface and the REXX Extended Plist). All parameters, including numbers, are in
character format. The array is terminated with a
char *
,
int
pair
where the value of the
char *
is REXX_LAST_AD (defined in
<cmsexec.h>
), and the value of the
int
is REXX_LAST_LEN.
The result value, assigned to the REXX variable RESULT, also should be in character format.
If a C function called as a REXX function (identified
as such in the array pointed to by
fncv
) returns a nonzero value via the RETURN statement, REXX ignores
any RESULT value returned by the function. To set the REXX variable RC, use
cmsshv
. To assign a value to
the REXX variable RESULT or to return a value from a C function called as
a REXX function, use
rxresult
or
rxeval
.
IMPLEMENTATION |
cmsrxfn
causes the program to be installed as a REXX function package.
EXAMPLE |
#include <cmsexec.h> #include <stdlib.h> #include <string.h> #include <stdio.h> static int list(); /* Declare REXX external function.*/ REXX_FNC rxfncs[] = {& list}; void main(int argc, char *argv[] ) { int rc; /* Call cmsrxfn, passing the argc, argv parameters, the number */ /* of functions to define (1), and an array of pointers to the */ /* function(s). */ rc = cmsrxfn(argc, argv, 1, rxfncs); printf("cmsrxfn completed with return code %d\n",rc); } /* This REXX function types a note indicating whether it was */ /* called as a function or as a subroutine (via a REXX call */ /* statement ). It then lists the arguments it was called with */ /* and sets the value of the REXX variable RESULT to the number */ /* of arguments. */ static list(args, subflag) struct REXX_PLIST args[]; int subflag; { int n; /* number of arguments passed */ char result_buffer[3]; /* buffer for REXX RESULT string */ if (subflag) /* Were we called as a subroutine or a function? */ puts("Called as a subroutine."); else puts("Called as a function."); /* Count arguments and print. REXX will provide up to ten */ /* argument strings. */ for (n = 0; args[n].len != REXX_LAST_LEN; n++) if (args[n].ad != NULL) printf("Argument %d: "%.*s"\n", n, args[n].len, args[n].ad); else printf("Argument %d: (Omitted)\n", n); if (n == 0) puts("No arguments passed."); /* Convert 'n' to string and set REXX RESULT variable. */ sprintf(result_buffer, "%d", n); rxresult(result_buffer); return 0; }
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.