The cstubs.c module is the source code module that contains the external subroutines that are called with a LINK statement from logic.  The source code module must be compiled or assembled before linking in PROIV. The arguments to the subroutines are passed by reference in the order and number specified by the corresponding LINK statement. All parameters are passed to external subroutines, as ā€˜C’ strings for example, are Null terminated. The following is an example of a cstubs.c module written in 'C'.

Example

This is an example of cstubs written in 'C'

/*********************************************************************
*                                                                    *
* cstubs.c - external subroutines                                    *
*                                                                    *
**********************************************************************
* External Subroutines 0 - 9                                         *
* Each argument is passed by reference in the order and number       *
* specified by the corresponding LINK statement in PROIV logic       *
*********************************************************************/
sub0(num1,num2)
char *num1, *num2;
/*********************************************************************
* Local Data storage area                                            *
*********************************************************************/
 {
          bytmov (num1,num2,7);
 }


sub1(name1,name2)
/*********************************************************************
* Local data storage area                                            *
*********************************************************************/
char *name1,*name2;
{
            puts ("\nSubroutine 1");
            printf("First argument is %8.4s\n", name1);
            printf("Second argument is %8.5s\n",name2;
            puts ("\nPress <RET> to continue");
            getchar ( );
}

sub2(name1,name2)
/*********************************************************************
* Local data storage area                                            *
*********************************************************************/
char *name1,*name2;

{
            puts ("nSubroutine 2");
            strncpy (name1,"derf",4);
            printf("First argument is %8.4s\n", name1);
            strncpy (name2, "cakes",5);
            printf("Second argument is %8.5s\n", name2);
            puts ("\nPress <RET> to continue");
            getchar ( );
}

sub3(name1,name2)
/*********************************************************************
* Local data storage area                                            *
*********************************************************************/
char *name1,*name2;
{
            puts ("\nSubroutine 3");
            name1[5] - '\0';
            name2[6] - '\0';
            printf("First argument is %s\n", name1);
            printf("Second argument is %s\n", name2);
            puts ("\nPress <RET> to continue");
            getchar ( );
}

/*********************************************************************
* Unused entries should be defined to avoid Link warning messages    *
* but will not actually be invoked                                   *
*********************************************************************/
sub4( )
{
}
sub5( )
{
}
sub6( )
{
}
sub7( )
{
}
sub8( )
{
}
sub9( )
{
}

sub0(param)
char *param

The length can be accessed using:

len = *(param-1);

Comment on this topic

Topic ID: 720279