Example C User-Written Function

The following illustrates a C user-written function that reverses an input string. The example below is for a User Function to be run on a UNIX system.
/*********************************************************************/
/* File   : normc.c                                                  */
/* System : Enrichment                                */
/* Version: 6.6.2                                                    */
/* Copyright (c)1993-2013 Precisely                  */
/* all rights reserved.  Unauthorized use or duplication prohibited. */
/*-------------------------------------------------------------------*/
/* Purpose:                                                          */
/*-------------------------------------------------------------------*/
/* History:                                                          */
/* static char SccsID[] = @(#)normc.c    1.1 08/18/97                */
/* 07/09/98 rolson Initial 50                                        */
/* 08/18/97 tcampbel Userfunction for testcases                      */
/* ----------------------------------------------------------------- */
/*
 * normc.c - Example Normal C User Function
 * Reverse characters.
 */
/* ----------------------------------------------------------------- */
#include <stdio.h>
                             /* --- UFAPI Input Call Area ---------- */
typedef struct {
   char   pSig[4];                /* Signature 'PDRI'                */
   char   cCallType;              /* Type - Init, Norm, or Term      */
   char   cCallFrom;              /* Called from - R/P rule/pagerule */
   char   pSave1[2];              /* (future)                        */
   int    iInRC;                  /* Initial RC                      */
   int    iInRV;                  /* Initial RV                      */
   char   pSave2[20];             /* (future)                        */
   int    iInSize;                /* Size of Input data              */
   char   pInData[2];             /* Input data (blank padded)       */
} UFIN, *PUFIN;

                             /* --- UFAPI Output Call Area --------- */
typedef struct {
   char   pSig[4];                /* Signature 'PDRO'                */
   int    iOutRC;                 /* Return RC                       */
   int    iOutRV;                 /* Return RV                       */
   char   pSave1[24];             /* (future)                        */
   int    iOutSize;               /* Size of Output data             */
   char   pOutData[2];            /* Output data (blank padded)      */
} UFOUT, *PUFOUT;

                      /* -- User Function subroutine to be called -- */
long int normc(PUFIN pUFIN, PUFOUT pUFOUT) {

  long int i;
                            /* Error exit if signatures not found    */
  if (memcmp(pUFIN->pSig, "PDRI",4)) return(3);
  if (memcmp(pUFOUT->pSig,"PDRO",4)) return(3);

  pUFOUT->iOutRC = pUFOUT->iOutRV = 0;, /* Clear -99s from RC & RV  */
for (pUFOUT->iOutSize=0,i=pUFIN->iInSize-1;
       pUFOUT->iOutSize<pUFIN->iInSize;
       pUFOUT->iOutSize++) {
    pUFOUT->pOutData[pUFOUT->iOutSize] = pUFIN->pInData[i--];
  }
  return (0);                             /* RC=0 -> all ok   */
} /* NORMC */