#include #include "countchar.h" /* Generated by countchar.x */ /* CpSc 824 Desc: rpc server for countchar. This routine is passed a character string and a character via a pointer parameter to the enclosing structure -- and this routine counts and returns the number of occurrences of the character in the string. */ int countchar_1_svc(stringdata *parm, int *count) { char *p; /* Start at the begining of the string and scan through counting occurences */ *count = 0; p = parm -> buf; while (*p) if (*p++ == parm-> findch) (*count)++; printf("Just a test\n"); /* Return count */ return(1); } /* CpSc 824 Desc: rpc server countallchars. Scan the input parameter string and construct a linked list of each character found in the string and an occurence count. Return the linked list. */ int countallchars_1_svc(buftype *bufptr, nextcount *start) { nextcount cur, last; char *ch; ch = *bufptr; /* Allocate first node */ *start = (nextcount) malloc(sizeof(struct countdata)); (*start)->character = *ch; (*start)->count = 1; (*start)->next = NULL; /* Now process rest of string */ ch++; while (*ch) { /* Search for previous occurence */ cur = *start; while (cur) { if (cur->character == *ch) { cur->count++; break; } last = cur; cur = last->next; } /* If not found, allocate a new node */ if (cur == NULL) { last->next = cur = (nextcount) malloc(sizeof(struct countdata)); cur -> character = *ch; cur ->count=1; cur -> next = NULL; } ch++; } /* Return list */ return(1); } /* Procedure to free return parameters that may have been dynamically allocated in previous call. In this example this is particularly important for "countallchars" so that the linked list is freed. */ int countcharprog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result, caddr_t result) { (void) xdr_free(xdr_result , result); return(1); }