/*
 * This is sample code generated by rpcgen.
 * These are only templates and you can use them
 * as a guideline for developing your own functions.
 */

#include "mc.h"


void
mcprog_1(char *host)
{
	CLIENT *clnt;
	int  *result_1;
	mypair  add_1_arg;
	int  *result_2;
	mypair  subtract_1_arg;

#ifndef	DEBUG
	clnt = clnt_create (host, MCPROG, MCVERS, "tcp");
	if (clnt == NULL) {
		clnt_pcreateerror (host);
		exit (1);
	}
#endif	/* DEBUG */
	/* Start of inserted code */
	 while (1) {
	    char choice[256];
	    struct timeval before, after;
	    long dure;
	    printf("\n\n");
	    printf("\n\t1. Add\n");
	    printf("\t2. Subtract\n");
	    printf("\tEnter your choice: ");
	    scanf("%0255s", choice);
	    if (strcmp(choice, "1") == 0) {
	      printf("\nEnter the two integers to add: ");
	      scanf("%d %d", &(add_1_arg.arg1), &(add_1_arg.arg2));
	      /* Start of code generated by rpcgen */
	      gettimeofday(&before, NULL);
	      result_1 = add_1(&add_1_arg, clnt);
	      gettimeofday(&after, NULL);
	      if (result_1 == (int *) NULL) {
		clnt_perror (clnt, "call failed");
	      }
	      /* End of code generated by rpcgen */
	      printf("The sum is %d\n", *result_1);
	    }else if (strcmp(choice, "2") == 0) {
	      printf("\nEnter the two integers to subtract: ");
	      scanf("%d %d", &(subtract_1_arg.arg1), &(subtract_1_arg.arg2));
	      /* Start of code generated by rpcgen */
	      gettimeofday(&before, NULL);
	      result_2 = subtract_1(&subtract_1_arg, clnt);
	      gettimeofday(&after, NULL);
	      if (result_2 == (int *) NULL) {
		  clnt_perror (clnt, "call failed");
	      }
	      printf("The difference is %d\n", *result_2);
	      /* End of code generated by rpcgen */
	    } else
	      break;
	    dure = (after.tv_sec - before.tv_sec)*1000000 +
		  	(after.tv_usec -before.tv_usec);
	    printf("Duration: %ld microseconds\n", dure);
	}
	/* End of inserted code */
#ifndef	DEBUG
	clnt_destroy (clnt);
#endif  /* DEBUG */
}


int
main (int argc, char *argv[])
{
	char *host;

	if (argc < 2) {
		printf ("usage: %s server_host\n", argv[0]);
		exit (1);
	}
	host = argv[1];
	mcprog_1 (host);
exit (0);
}

