/*	Comprehensive RPC system test:	Called subroutines - C	    BIG_SUB_C
	============================= 

	21 Apr 87	Bug out: test sequence was not initialised.
	31 Aug 87	C version derived - Nici.
	 5 Aug 88	BIG_SUB_C made from BIG_PROG_C - Tim.

This module passes simple variables by ADDRESS, not by value. It is compatible
with stubs produced WITHOUT the /BYVALUE option.

*/

#include <stdio.h>
#include <rpcrts.h>

#define	byte_type   rpc_byte
#define	char_type   rpc_char
#define	short_type  rpc_short
#define	long_type   rpc_long
#define	real_type   rpc_real32

typedef rpc_char    str_type[81];
typedef rpc_char    substr_type[80];
typedef rpc_char    array_type[11][8];
typedef	rpc_integer seq_type[80];

byte_type  my_byte,  his_byte;
char_type  my_char,  his_char;
short_type my_short, his_short;
long_type  my_long,  his_long;
real_type  my_real,  his_real;
str_type   my_str,   his_str;
array_type my_array, his_array;

substr_type a_my_substr, a_his_substr;
rpc_integer s_my_substr, s_his_substr,
	    l_my_substr, l_his_substr;

seq_type    a_my_seq, a_his_seq;
rpc_integer l_my_seq, l_his_seq;


/*	    Small subroutine for testing mixed directions
*/

int bigsub1(x,y,z)
int *x, *y, *z;
{
    	*y = *x + *y;		/* Modify this parameter */
	*z = *x * 3;		/* Return this parameter */
	return((*x) * (*x));

} /* end bigsub1 */
/*
______________________________________________________________________________

	Dummy with no parameters
*/
void no_parameters()
{

	/* Does nothing */
}

/*
______________________________________________________________________________

	Pass parameters in only

*/
only_in(x_byte, x_char, x_short, x_long, x_real, x_str,
		a_x_substr, s_x_substr, l_x_substr, x_array,
		a_x_seq, l_x_seq)
    
byte_type  *x_byte;
char_type  *x_char;
short_type *x_short;
long_type  *x_long;
real_type  *x_real;
str_type   x_str;
array_type x_array;

substr_type a_x_substr;
rpc_integer *s_x_substr,
	    *l_x_substr;

seq_type    a_x_seq;
rpc_integer *l_x_seq;

{
    int i,j;

    my_byte = *x_byte;
    my_char = *x_char;
    my_short = *x_short;
    my_long = *x_long;
    my_real = *x_real;
    strcpy(my_str, x_str);
    s_my_substr = *s_x_substr;
    l_my_substr = *l_x_substr;
    for (i=(*s_x_substr); i<(*s_x_substr+*l_x_substr); i++)
	a_my_substr[i-1]=a_x_substr[i-1];
    for (i=0; i<11; i++) for (j=0; j<8; j++) my_array[i][j]=x_array[i][j];
    l_my_seq = *l_x_seq;
    for (i=0; i<*l_x_seq; i++) a_my_seq[i]=a_x_seq[i];

} /* end only_in */


/*
______________________________________________________________________________

	Pass parameters out only

*/
only_out(x_byte, x_char, x_short, x_long, x_real, x_str,
		a_x_substr, s_x_substr, l_x_substr, x_array,
		a_x_seq, l_x_seq)
    
byte_type  *x_byte;
char_type  *x_char;
short_type *x_short;
long_type  *x_long;
real_type  *x_real;
str_type   x_str;
array_type x_array;

substr_type a_x_substr;
rpc_integer *s_x_substr,
	    *l_x_substr;

seq_type    a_x_seq;
rpc_integer *l_x_seq;

{
    int i,j;

    *x_byte = my_byte;
    *x_char = my_char;
    *x_short = my_short;
    *x_long = my_long;
    *x_real = my_real;
    strcpy(x_str, my_str);
    *s_x_substr = s_my_substr;
    *l_x_substr = l_my_substr;
    for (i=s_my_substr; i<s_my_substr+l_my_substr; i++)
	a_x_substr[i-1]=a_my_substr[i-1];
    for (i=0; i<11; i++) for (j=0; j<8; j++) x_array[i][j]=my_array[i][j];
    *l_x_seq = l_my_seq;
    for (i=0; i<l_my_seq; i++) a_x_seq[i]=a_my_seq[i];

} /* end only_out */



/*
______________________________________________________________________________

	Pass parameters in and out

*/
in_out(x_byte, x_char, x_short, x_long, x_real, x_str,
		a_x_substr, s_x_substr, l_x_substr, x_array,
		a_x_seq, l_x_seq)
    
byte_type  *x_byte;
char_type  *x_char;
short_type *x_short;
long_type  *x_long;
real_type  *x_real;
str_type   x_str;
array_type x_array;

substr_type a_x_substr;
rpc_integer *s_x_substr,
	    *l_x_substr;

seq_type    a_x_seq;
rpc_integer *l_x_seq;
{
	int i,j;

	*x_byte = 255 - *x_byte;
	*x_char = '*';
/* was	*x_char = (char)(127 - (int)*x_char); */
	*x_short = *x_short + 4321;
	*x_long = *x_long * (-13);
	*x_real = *x_real * (-123.456);

	for (i = 0; x_str[i] != '\0'; i++) x_str[i] = '%';

	for (i = *s_x_substr; i < *s_x_substr + *l_x_substr; i++)
		    a_x_substr[i-1] = '&';

	for (i = 0; i < 11; i++)
	    for (j = 0; j < 8; j++) 
		x_array[i][j] = '!';
	/* was: (char)( ((int)x_array[i][j] + i*(j + 5)) % 128); */


	for (i = 0; i < *l_x_seq; i++)
	    a_x_seq[i] += i + 1;

} /* end in_out */