From sources-request@genrad.UUCP Sun Apr 14 18:01:45 1985 Relay-Version: version B 2.10.3 alpha 4/3/85; site seismo.UUCP Posting-Version: version B 2.10.2 9/3/84; site genrad.UUCP Path: seismo!harvard!talcott!panda!genrad!sources-request From: sources-request@genrad.UUCP Newsgroups: mod.sources Subject: Sun RPC part 6 of 10 Message-ID: <755@genrad.UUCP> Date: 14 Apr 85 23:01:45 GMT Date-Received: 15 Apr 85 06:04:10 GMT Sender: john@genrad.UUCP Lines: 146 Approved: john@genrad.UUCP From: blyon@sun (Bob Lyon) ----------------- cut here -------------------- # run this script through "sh" to extract files mkdir toys; cd toys echo x - Makefile sed 's/^X//' >Makefile <<'!Funky!Stuff!' CFLAGS= -O all: sortit sort_service sortit: sortit.o sort_prot.o ${CC} ${CFLAGS} sortit.o sort_prot.o -o sortit sort_service: sort_service.o sort_prot.o ${CC} ${CFLAGS} sort_service.o sort_prot.o -o sort_service X.c.o: ${CC} ${CFLAGS} -c $*.c !Funky!Stuff! echo x - sort_prot.c sed 's/^X//' >sort_prot.c <<'!Funky!Stuff!' /* * sort_prot.c * Implements the protcol filter for the toy sort service. */ #include #include "sort_prot.h" int xdr_sortstrings(xdrs, ssp) XDR *xdrs; struct sortstrings *ssp; { return (xdr_array(xdrs, &ssp->s, &ssp->ns, MAXSORTSIZE, sizeof (char *), xdr_wrapstring)); } !Funky!Stuff! echo x - sort_prot.h sed 's/^X//' >sort_prot.h <<'!Funky!Stuff!' /* * Protocol for a sorting service. */ #define SORTPROG ((long) 22855) #define SORTVERS ((long) 1) #define SORT ((long) 1) /* * The sort procedure receives an array of strings and returns an array * of strings. This toy service handles a maximum of 64 strings. */ #define MAXSORTSIZE ((long) 64) struct sortstrings { long ns; /* number of strings in the array */ char **s; /* pointer to the array of strings */ }; int xdr_sortstrings(); !Funky!Stuff! echo x - sort_service.c sed 's/^X//' >sort_service.c <<'!Funky!Stuff!' /* * sort_service.c * Implements the server side of the sort_service. */ #include #include "sort_prot.h" static int comparestrings(sp1, sp2) char **sp1, **sp2; { return (strcmp(*sp1, *sp2)); } static struct sortstrings * sort(ssp) struct sortstrings *ssp; { qsort(ssp->s, ssp->ns, sizeof (char *), comparestrings); return(ssp); } main() { /* register the serive */ registerrpc(SORTPROG, SORTVERS, SORT, sort, xdr_sortstrings, xdr_sortstrings); /* run the service forever */ svc_run(); /* never returns */ exit(1); } !Funky!Stuff! echo x - sortit.c sed 's/^X//' >sortit.c <<'!Funky!Stuff!' /* * sortit.c * Client side application which sorts argc, argv. */ #include #include #include "sort_prot.h" main(argc, argv) int argc; char **argv; { char *machinename; struct sortstrings args, res; int i; if (argc < 2) { fprintf(stderr, "usage: %s machinename [s1 ...]\n", argv[0]); exit(1); } machinename = argv[1]; args.ns = argc; args.s = argv; res.s = (char **)NULL; callrpc(machinename, SORTPROG, SORTVERS, SORT, xdr_sortstrings, &args, xdr_sortstrings, &res); for (i = 0; i < res.ns; i++) { printf("%s\n", res.s[i]); } /* should free res here */ exit(0); } !Funky!Stuff! exit