home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rexx / rexxfunc / ezrxfunc / c / func1.c next >
C/C++ Source or Header  |  1993-07-28  |  2KB  |  70 lines

  1. /*
  2.  * func1.c -- Example of a simple REXX function.
  3.  */
  4.  
  5. #include "standard.h"
  6.  
  7. #define INCL_DOS
  8. #include <os2.h>
  9.  
  10. #include "rxsutils.h"
  11.  
  12. /*
  13.  * Declare our exported function.  Don't forget to export it!
  14.  */
  15.  
  16. RexxFunctionHandler EZFunc1;
  17.  
  18. /*
  19.  * EZFunc1 -- Bumps a counter and returns a string.  Arguments are as
  20.  *            follows:
  21.  *
  22.  *              name -- Name of function being called.
  23.  *              numargs -- Number of argument strings passed from REXX.
  24.  *              args -- Array of argument strings passed from REXX.
  25.  *              queuename -- Name of currently active queue.
  26.  *              retstr -- Pointer to buffer for result string.
  27.  *
  28.  *            The only one you may modify is the retstr.
  29.  */
  30.  
  31. ULONG EZFunc1( CHAR *name, ULONG numargs, RXSTRING args[],
  32.                CHAR *queuename, RXSTRING *retstr )
  33.   {
  34.     static ULONG count = 0;
  35.     char         buf[ 100 ];
  36.  
  37.     place_holder( name );
  38.     place_holder( queuename );
  39.     place_holder( args );
  40.  
  41.     /* Check # of arguments.  We don't want any.  Exit with error
  42.        (which halts the REXX program) if some are given. */
  43.  
  44.     if( numargs > 0 ) goto error;
  45.  
  46.     /* Enter a critical section.  Because the counter is static, it
  47.        will be shared across threads, so we need to update it atomically. */
  48.  
  49.     DosEnterCritSec();
  50.  
  51.     sprintf( buf, "You called EZFunc1 %d times.", ++count );
  52.  
  53.     DosExitCritSec();
  54.  
  55.     /* Set the retstr to the new string. */
  56.  
  57.     CopyResult( buf, strlen( buf ), retstr );
  58.  
  59.     /* Return 0 if no error occurred */
  60.  
  61.     return( VALID_ROUTINE );
  62.  
  63.     /* If a syntax error of some kind occurs (too few/many args, bad args)
  64.        then return an errorcode of 40 */
  65.  
  66.   error:
  67.     return( INVALID_ROUTINE );
  68. }
  69.  
  70.