2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * generator.c -- phase 2 of the generator.
13 * takes a file, which has a list of signature as input,
14 * and outputs the client, server, .xg, and makefiles
15 * This file is normally created by running tableGen.c,
16 * but theoretically could be generated by a human.
18 * Format of the signatures : no_of_args list_of_arg_signs
19 * arg_sign : (dir type)
22 * This program is used to generate client/server pairs that
23 * make and verify random rpcs. It can be used to generate
24 * both pthread and lwp versions of the client and server.
25 * It was designed to verify that the new pthread rx library
26 * was functioning correctly.
28 * The key to understanding how this program works is to realize
29 * that all the data necessary to generate the client/server
30 * code is generated first, in char string format.
31 * For example, if you are generating 10 rpc's, the input and
32 * output values of all the parameters are generated - and
33 * stored as strings. This allows you to write out the values
34 * as the client and server are created without having to worry
35 * about data type conversion.
37 * In addition, these strings (along with other information) are
38 * stored in a structure that is iterated over many times during
39 * the construction of the client and server.
41 * Often this iteration takes the form of:
42 * for (i=0; i < argsP->argCount; i++)
44 * It may be possible to eliminate some of these iterations for
45 * efficiency sake, but this was not done - allowing an easier
48 * The bulk of this code was lifted from the delight project.
52 #include <afsconfig.h>
53 #include <afs/param.h>
65 #include "generator.h"
67 static char *unix_symbols[] = {
69 "include ../../../config/Makefile.$(SYS_NAME)\n",
72 "#include <netdb.h>\n",
76 "LIBS = $(DESTDIR)lib/libafsrpc.so \\\n"
77 "\t$(DESTDIR)lib/afs/libcmd.a \\\n"
78 "\t$(DESTDIR)lib/afs/libcom_err.a \\\n"
79 "\t$(DESTDIR)lib/afs/util.a \n",
82 "LIBS = $(DESTDIR)lib/librxkad.a \\\n" "\t$(DESTDIR)lib/libdes.a \\\n"
83 "\t$(DESTDIR)lib/librx.a \\\n" "\t$(DESTDIR)lib/liblwp.a \\\n"
84 "\t$(DESTDIR)lib/afs/libcmd.a \\\n"
85 "\t$(DESTDIR)lib/afs/libcom_err.a \\\n"
86 "\t$(DESTDIR)lib/afs/util.a \\\n" "\t/usr/ucblib/libucb.a \n",
89 "\t@if [ ! -r DEST ] ; \\\n" "\tthen \\\n"
90 "\t\techo \"Must create DEST link by hand before building tests\"; \\\n"
91 "\t\texit 1; \\\n" "\tfi\n"
94 static char *nt_symbols[] = {
96 "!INCLUDE ../../../config/NTMakefile.$(SYS_NAME)\n",
99 "#include <windows.h>\n",
103 "LIBS = $(DESTDIR)/lib/afsrpc.lib \\\n"
104 "\t$(DESTDIR)/lib/afs/afscmd.lib \\\n"
105 "\t$(DESTDIR)/lib/afs/afscom_err.lib \\\n"
106 "\t$(DESTDIR)/lib/afs/afsutil.lib \\\n"
107 "\t$(DESTDIR)/lib/pthread.lib \\\n" "\t$(DESTDIR)/lib/afsreg.lib \\\n"
111 "LIBS = $(DESTDIR)/lib/afsrxkad.lib \\\n"
112 "\t$(DESTDIR)/lib/afsdes.lib \\\n" "\t$(DESTDIR)/lib/afsrx.lib \\\n"
113 "\t$(DESTDIR)/lib/afslwp.lib \\\n"
114 "\t$(DESTDIR)/lib/afs/afscmd.lib \\\n"
115 "\t$(DESTDIR)/lib/afs/afscom_err.lib \\\n"
116 "\t$(DESTDIR)/lib/afs/afsutil.lib \\\n"
117 "\t$(DESTDIR)/lib/afsreg.lib \n",
120 "!\tIF (!EXIST(DEST))\n"
121 "!\t\tERROR Must create DEST link by hand before building tests\n"
125 static char **platform = nt_symbols;
128 #define strdup(x) _strdup(x)
132 * 31 bit random number generator, we don't really care how random
133 * these numbers are, it is more important that identical rx files
134 * are generated no matter what platform the generator runs on
136 static unsigned long randVal = 0x330E16;
143 static threadModel_t threadModel = PTHREADS;
148 randVal = ((randVal * 0xEECE66D) + 0xB) & 0xFFFFFFFF;
149 return ((double)(randVal) / 4294967296.0);
153 * GetDescription writes a one line comment describing the parameters
154 * used in an rpc in the client program
157 GetDescription(rpcArgs * argsP)
163 (char *)calloc((MAX_TYP_STR + MAX_DIR_STR + ATTRIB_LEN * ATTRIB_NO)
164 * argsP->argCount + 3, sizeof(char));
165 MEM_CHK(bufP2, "GetDescription: out of mem bufP2\n");
167 for (i = 0; i < argsP->argCount; i++) {
168 strcat(bufP2, argsP->argDescr[i].direction);
169 strcat(bufP2, argsP->argDescr[i].type);
175 * GetName -- get the name of the current server/instance
178 GetName(char *serverName, int sign_no)
180 /* itl file name 8.3 format */
183 bufP = (char *)malloc(32 * sizeof(char));
184 MEM_CHK(bufP, "GetName: bufP out of mem\n");
186 sprintf(bufP, "%s%d", serverName, sign_no);
191 * OpenOutFile -- open a file in the output directory
194 OpenOutFile(char *outDir, char *fileName, char *tailStr)
201 (char *)malloc(sizeof(char) *
202 (strlen(fileName) + strlen(tailStr) +
203 strlen(outDir) + 2));
204 MEM_CHK(bufP, "OpenOutFile : Out of mem -- bufP\n");
205 sprintf(bufP, "%s/%s%s", outDir, fileName, tailStr);
208 (char *)malloc(sizeof(char) *
209 (strlen(fileName) + strlen(tailStr) + 1));
210 MEM_CHK(bufP, "OpenOutFile : Out of mem -- bufP\n");
211 sprintf(bufP, "%s%s", fileName, tailStr);
213 fP = fopen(bufP, "w");
214 MEM_CHK(fP, "main: Unable to open output file\n");
220 * WriteXGDecl -- write the declaration for a parameter
223 WriteXGDecl(arg_tuple * arg, FILE * xg_h, int i, int structFlag, int lastFlag)
226 if (!strcmp(arg->type, "varString")) {
227 fprintf(xg_h, "\tchar a%d[STR_MAX];\n", i);
229 fprintf(xg_h, "\tdrpc_%s_t a%d;\n", arg->type, i);
232 if (!strncmp(arg->type, "ar_", 2)) {
233 fprintf(xg_h, "\t%s drpc_out_%s_t *a%d", arg->direction,
235 } else if (!strcmp(arg->type, "varString")) {
236 fprintf(xg_h, "\t%s string a%d<STR_MAX>", arg->direction, i);
237 } else if (!strcmp(arg->direction, "IN")) {
238 fprintf(xg_h, "\t%s drpc_%s_t a%d", arg->direction, arg->type, i);
240 fprintf(xg_h, "\t%s drpc_%s_t *a%d", arg->direction, arg->type,
252 * WriteXG -- write the body of the xg interface
255 WriteXG(rpcArgs * argsP, FILE * xg_h, char *serverName, int sign_no)
258 char *name = GetName(serverName, sign_no);
261 * CASE 1: all arguments passed as parameters
264 fprintf(xg_h, "\nproc %s(\n", name);
266 /* declare each arg */
267 for (i = 0; i < argsP->argCount; i++) {
268 WriteXGDecl(&argsP->argDescr[i], xg_h, i, FALSE,
269 (i == argsP->argCount - 1));
272 /* Now pass the paramaters inside a structure */
273 fprintf(xg_h, "\nstruct %s_t {\n", name);
274 for (i = 0; i < argsP->argCount; i++) {
275 WriteXGDecl(&argsP->argDescr[i], xg_h, i, TRUE,
276 (i == argsP->argCount - 1));
278 fprintf(xg_h, "} ;\n");
279 fprintf(xg_h, "\nproc %s_s(\n", name);
280 fprintf(xg_h, "\tINOUT struct %s_t *s);\n", name);
286 * GetRandStr -- get a random string
289 GetRandStr(int strLen, char **ret, int *rP)
297 randI = 'A' + ('Z' - 'A') * drand32();
298 sprintf(buf, "%c", randI);
307 * GetRandP -- sets a string to a random value of the data type
308 * inthe case of a char type, ret holds "%c" and ret2 holds '%c'
311 GetRandP(char *typ, char **ret, char **ret2)
318 *ret = (char *)calloc(MAX_RAND_LENGTH + 1, sizeof(char));
319 *ret2 = (char *)calloc(MAX_RAND_LENGTH + 1, sizeof(char));
321 if (strstr(typ, "char")) {
322 GetRandStr(1, ret2, &randI);
324 strcpy(*ret2, "'\\\\'");
325 else if (randI == '\'')
326 strcpy(*ret2, "'\\''");
328 sprintf(*ret, "'%c'", randI);
330 } else if (strstr(typ, "short")) {
331 shI = SHRT_MIN + (SHRT_MAX - SHRT_MIN) * drand32();
332 sprintf(*ret, "%d", shI);
334 } else if (strstr(typ, "afs_int32")) {
335 randI = INT_MIN + UINT_MAX * drand32();
336 if (randI < INT_MIN || randI > INT_MAX) {
337 fprintf(stderr, "GetRandP: afs_int32 %d out of bounds\n", randI);
340 sprintf(*ret, "%d", randI);
342 } else if (strstr(typ, "float")) {
345 sprintf(*ret, "%2.8e", f);
348 } else if (strstr(typ, "double")) {
350 sprintf(*ret, "%2.16e", d1);
353 } else if (strstr(typ, "String")) {
354 strLen = (MAX_RAND_LENGTH - 2) * drand32();
355 GetRandStr(strLen, ret, &randI);
362 * GenParamValues -- generate the parameter values for an rpc
365 GenParamValues(rpcArgs * argsP)
370 /* generate random values for each argument */
371 for (i = 0; i < argsP->argCount; i++) {
373 argsP->argDescr[i].vc_low = 0;
374 argsP->argDescr[i].vc_max = IDL_FIX_ARRAY_SIZE - 1;
375 argsP->argDescr[i].vc_high = IDL_FIX_ARRAY_SIZE - 1;
376 argsP->argDescr[i].ovc_low = 0;
377 argsP->argDescr[i].ovc_high = IDL_FIX_ARRAY_SIZE - 1;
379 if (!strncmp(argsP->argDescr[i].type, "ar_", 3)) {
380 typ = argsP->argDescr[i].type + 3;
381 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++) {
382 GetRandP(typ, &argsP->argDescr[i].inValue[j],
383 &argsP->argDescr[i].inValue2[j]);
384 GetRandP(typ, &argsP->argDescr[i].outValue[j],
385 &argsP->argDescr[i].outValue2[j]);
388 GetRandP(argsP->argDescr[i].type, &argsP->argDescr[i].inValue[0],
389 &argsP->argDescr[i].inValue2[0]);
390 GetRandP(argsP->argDescr[i].type, &argsP->argDescr[i].outValue[0],
391 &argsP->argDescr[i].outValue2[0]);
397 * WriteServC -- write the rpcs in the server file
400 WriteServC(rpcArgs * argsP, FILE * srv_h, char *serverName, int sign_no)
405 name = GetName(serverName, sign_no);
406 fprintf(srv_h, "\nint A%s(struct rx_call *c,\n", name);
408 /* declare each arg */
409 for (i = 0; i < argsP->argCount; i++) {
411 if (!strcmp(argsP->argDescr[i].type, "varString")) {
412 if (!strcmp(argsP->argDescr[i].direction, "IN")) {
413 fprintf(srv_h, "\tchar *a%d", i);
415 fprintf(srv_h, "\tchar **a%d", i);
417 } else if (strncmp(argsP->argDescr[i].type, "ar_", 3)
418 && (!strcmp(argsP->argDescr[i].direction, "IN"))) {
419 fprintf(srv_h, "\tdrpc_%s_t a%d", argsP->argDescr[i].type, i);
421 if (!strncmp(argsP->argDescr[i].type, "ar_", 3)) {
422 fprintf(srv_h, "\tdrpc_out_%s_t *a%d",
423 argsP->argDescr[i].type, i);
425 fprintf(srv_h, "\tdrpc_%s_t *a%d", argsP->argDescr[i].type,
429 if (i < (argsP->argCount - 1)) {
430 fprintf(srv_h, ",\n");
433 fputs(")\n{\n", srv_h); /* balance the } */
434 fputs("\tint errFlag = 0;", srv_h);
437 * check the in and inout parameters
439 for (i = 0; i < argsP->argCount; i++) {
441 if (!strcmp(argsP->argDescr[i].direction, "IN")
442 || (!strcmp(argsP->argDescr[i].direction, "INOUT")
443 && !strcmp(argsP->argDescr[i].type, "varString"))) {
445 typ = argsP->argDescr[i].type;
447 if (strstr(typ, "String")) {
448 if (!strcmp(argsP->argDescr[i].direction, "INOUT")) {
449 fprintf(srv_h, "\n\tCHECK%s((char *)*a%d, %s, \"%s\");",
450 typ, i, argsP->argDescr[i].inValue[0], name);
452 fprintf(srv_h, "\n\tCHECK%s((char *)a%d, %s, \"%s\");",
453 typ, i, argsP->argDescr[i].inValue[0], name);
455 } else if (!strcmp(typ, "afs_int32")) {
456 fprintf(srv_h, "\n\tCHECK%s(a%d, %sL, \"%s\");", typ, i,
457 argsP->argDescr[i].inValue[0], name);
459 if (!strncmp(typ, "ar_", 3)) {
460 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
462 "\n\tCHECK%s(a%d->drpc_out_%s_t_val[%d], %s, \"%s\");",
463 (typ + 3), i, typ, j,
464 argsP->argDescr[i].inValue[j], name);
466 fprintf(srv_h, "\n\tCHECK%s(a%d, %s, \"%s\");", typ, i,
467 argsP->argDescr[i].inValue[0], name);
470 } else if (!strcmp(argsP->argDescr[i].direction, "INOUT")) {
472 typ = argsP->argDescr[i].type;
474 if (strstr(typ, "String")) {
475 fprintf(srv_h, "\n\tCHECK%s((char *)*a%d, %s, \"%s\");", typ,
476 i, argsP->argDescr[i].inValue[0], name);
477 } else if (!strcmp(typ, "afs_int32")) {
478 fprintf(srv_h, "\n\tCHECK%s(*a%d, %sL, \"%s\");", typ, i,
479 argsP->argDescr[i].inValue[0], name);
481 if (!strncmp(typ, "ar_", 3)) {
482 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
484 "\n\tCHECK%s(a%d->drpc_out_%s_t_val[%d], %s, \"%s\");",
485 (typ + 3), i, typ, j,
486 argsP->argDescr[i].inValue[j], name);
488 fprintf(srv_h, "\n\tCHECK%s(*a%d, %s, \"%s\");", typ, i,
489 argsP->argDescr[i].inValue[0], name);
496 * free up memory for dynamic input args
498 for (i = 0; i < argsP->argCount; i++) {
499 if (!strncmp(argsP->argDescr[i].type, "ar_", 3)) {
500 typ = argsP->argDescr[i].type;
501 if (!strcmp(argsP->argDescr[i].direction, "INOUT")) {
503 "\n\tif (a%d->drpc_out_%s_t_val) "
504 "free(a%d->drpc_out_%s_t_val);", i, typ, i, typ);
506 if (!strcmp(argsP->argDescr[i].direction, "INOUT")
507 || !strcmp(argsP->argDescr[i].direction, "OUT")) {
509 "\n\ta%d->drpc_out_%s_t_val = (%s *) "
510 "malloc(FIX_ARRAY_SIZE * sizeof(%s));", i, typ,
511 (typ + 3), (typ + 3));
512 fprintf(srv_h, "\n\ta%d->drpc_out_%s_t_len = FIX_ARRAY_SIZE;",
519 * set the inout and out parameters
521 for (i = 0; i < argsP->argCount; i++) {
523 if (!strcmp(argsP->argDescr[i].direction, "INOUT")
524 || !strcmp(argsP->argDescr[i].direction, "OUT")) {
526 typ = argsP->argDescr[i].type;
528 if (!strncmp(typ, "ar_", 3)) {
529 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
530 fprintf(srv_h, "\n\ta%d->drpc_out_%s_t_val[%d] = %s;", i,
531 typ, j, argsP->argDescr[i].outValue[j]);
532 } else if (!strcmp(typ, "afs_int32")) {
533 fprintf(srv_h, "\n\t*a%d = %sL;", i,
534 argsP->argDescr[i].outValue[0]);
535 } else if (!strcmp(typ, "varString")) {
536 if (!strcmp(argsP->argDescr[i].direction, "OUT")) {
537 fprintf(srv_h, "\n\t*a%d = (char *) malloc(STR_MAX);", i);
539 fprintf(srv_h, "\n\tstrcpy((char *)*a%d, %s);", i,
540 argsP->argDescr[i].outValue[0]);
541 } else if (strstr(typ, "String")) {
542 fprintf(srv_h, "\n\t*a%d = (drpc_%s_t)rpc_ss_allocate(%d);",
543 i, typ, strlen(argsP->argDescr[i].outValue[0]) - 1);
544 fprintf(srv_h, "\n\tstrcpy((char *)*a%d, %s);", i,
545 argsP->argDescr[i].outValue[0]);
547 fprintf(srv_h, "\n\t*a%d = %s;", i,
548 argsP->argDescr[i].outValue[0]);
554 "\n\tif (errFlag) {" "\n\t\tprintf(\"%s: failed\\n\");"
555 "\n\t\tfflush(stdout);" "\n\t}" "\n\treturn errFlag;\n}\n", name);
558 * second routine with arguments inside a structure
561 "\nint A%s_s(struct rx_call *c,\n\t%s_t *s)\n{"
562 "\n\tint errFlag = 0;", name, name);
565 * check the in and inout parameters
567 for (i = 0; i < argsP->argCount; i++) {
569 if (!strcmp(argsP->argDescr[i].direction, "IN")
570 || (!strstr(argsP->argDescr[i].type, "String")
571 && !strcmp(argsP->argDescr[i].direction, "INOUT"))) {
573 typ = argsP->argDescr[i].type;
575 if (!strncmp(typ, "ar_", 3)) {
576 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
577 fprintf(srv_h, "\n\tCHECK%s(s->a%d[%d], %s, \"%s_s\");",
578 (typ + 3), i, j, argsP->argDescr[i].inValue[j],
580 } else if (strstr(typ, "String")) {
581 fprintf(srv_h, "\n\tCHECK%s((char *)s->a%d, %s, \"%s_s\");",
582 typ, i, argsP->argDescr[i].inValue[0], name);
583 } else if (!strcmp(typ, "afs_int32")) {
584 fprintf(srv_h, "\n\tCHECK%s(s->a%d, %sL, \"%s_s\");", typ, i,
585 argsP->argDescr[i].inValue[0], name);
587 fprintf(srv_h, "\n\tCHECK%s(s->a%d, %s, \"%s_s\");", typ, i,
588 argsP->argDescr[i].inValue[0], name);
594 * set the inout and out parameters
596 for (i = 0; i < argsP->argCount; i++) {
598 if (!strcmp(argsP->argDescr[i].direction, "INOUT")
599 || !strcmp(argsP->argDescr[i].direction, "OUT")) {
601 typ = argsP->argDescr[i].type;
603 if (!strncmp(typ, "ar_", 3)) {
604 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
605 fprintf(srv_h, "\n\ts->a%d[%d]= %s;", i, j,
606 argsP->argDescr[i].outValue[j]);
607 } else if (!strcmp(typ, "afs_int32")) {
608 fprintf(srv_h, "\n\ts->a%d = %sL;", i,
609 argsP->argDescr[i].outValue[0]);
610 } else if (!strcmp(typ, "varString")) {
611 fprintf(srv_h, "\n\tstrcpy((char *)s->a%d, %s);", i,
612 argsP->argDescr[i].outValue[0]);
613 } else if (strstr(typ, "String")) {
614 fprintf(srv_h, "\n\ts->a%d = rpc_ss_allocate(%d);", i,
615 strlen(argsP->argDescr[i].outValue[0]) - 1);
616 fprintf(srv_h, "\n\tstrcpy((char *)s->a%d, %s);", i,
617 argsP->argDescr[i].outValue[0]);
619 fprintf(srv_h, "\n\ts->a%d = %s;", i,
620 argsP->argDescr[i].outValue[0]);
626 "\n\tif (errFlag) {" "\n\t\tprintf(\"%s_s: failed\\n\");" "\n\t}"
627 "\n\tfflush(stdout);" "\n\treturn errFlag;\n}\n", name);
634 * WriteMake - write the makefile for a particular client/server pair
637 WriteMake(char *serverName, int srv_no, FILE * mak_h)
640 char *obj = platform[2];
642 sprintf(p, "%s%d", serverName, srv_no);
643 fprintf(mak_h, "%s", platform[1]);
644 if (threadModel == PTHREADS) {
645 fprintf(mak_h, "CFLAGS = -KPIC -g -mt -I$(DESTDIR)include\n" "%s",
649 fprintf(mak_h, "CFLAGS = -g -I$(DESTDIR)include\n" "%s", platform[7]
653 "\n\ntest: all\ntests: all\nall: %sClt %sSrv\n\n"
654 "%sClt: %s.cs.%s %s.xdr.%s %sClt.%s $(LIBS)\n", p, p, p, p, obj,
656 if (platform == nt_symbols) {
657 fprintf(mak_h, "\t$(EXECONLINK)\n\n");
660 "\t$(CC) $(CFLAGS) -o $@ %sClt.%s %s.cs.%s %s.xdr.%s "
661 "$(LIBS) $(XLIBS)\n\n", p, obj, p, obj, p, obj);
664 "%s.xdr.c: %s.xg\n\n" "%s.h %s.cs.c %s.ss.c: %s.xg\n"
665 "\t$(RXGEN) %s.xg\n" "\t%s %s.cs.c\n" "\t%s %s.ss.c\n\n", p, p, p,
666 p, p, p, p, platform[3], p, platform[3], p);
667 fprintf(mak_h, "%sSrv: %s.ss.%s %s.xdr.%s %sSrv.%s $(LIBS)\n", p, p, obj,
670 if (platform == nt_symbols) {
671 fprintf(mak_h, "\t$(EXECONLINK)\n\n");
674 "\t$(CC) $(CFLAGS) -o $@ %sSrv.o %s.ss.o %s.xdr.o "
675 "$(LIBS) $(XLIBS)\n\n", p, p, p);
678 if (platform == unix_symbols) {
680 "clean:\n" "\t/bin/rm -f %sClt %s.h %s.cs.c %s.ss.c core "
682 "\t%sClt.o %s.cs.o %s.ss.o %s.xdr.c %s.xdr.o\n", p, p, p, p,
683 p, p, p, p, p, p, p);
689 * WriteCltTrailer - finish writing client source
692 WriteCltTrailer(char *serverName, int first, int last, FILE * itl_h)
697 * Write out 1 function that calls all the manager functions
699 if (threadModel == PTHREADS) {
700 fprintf(itl_h, "\n\nvoid *threadFunc(void *arg) {\n");
702 fprintf(itl_h, "\n\nint threadFunc(int *arg) {\n");
706 "\tstruct rx_connection *conn;\n" "\tint error=0;\n\n"
707 "\tint i = (int) arg;\n\n");
710 "\tconn = rx_GetCachedConnection(serverAddr,serverPort,4,secClass,secIndex);\n");
712 fprintf(itl_h, "\twhile(i--) {\n");
716 for (i = first; i < last; i++) {
717 fprintf(itl_h, "\t\tC_%s%d(conn);\n", serverName, i);
718 fprintf(itl_h, "\t\tC_%s%d_s(conn);\n", serverName, i);
720 fprintf(itl_h, "\t}\n");
722 fprintf(itl_h, "\trx_ReleaseCachedConnection(conn);\n");
724 if (threadModel == PTHREADS) {
725 fprintf(itl_h, "\treturn (void *) 0;\n");
728 "\tLWP_CALL(LWP_SignalProcess,(&done));\n" "\treturn 0;\n");
731 fprintf(itl_h, "}\n");
734 "\n\nstatic void DoRun(struct cmd_syndesc *as, char *arock) {\n");
736 if (threadModel == PTHREADS) {
737 fprintf(itl_h, "\tpthread_t *tid;\n");
739 fprintf(itl_h, "\tPROCESS *tid;\n");
743 "\tint i,j;\n" "\tunsigned int numThreads=0,numIterations=0;\n"
744 "\tint errflg=0;\n" "\tstruct hostent *host=NULL;\n\n"
745 "\tnumThreads = atoi(as->parms[0].items->data);\n"
746 "\tnumIterations = atoi(as->parms[1].items->data);\n"
747 "\tsecType = atoi(as->parms[2].items->data);\n"
748 "\tencLevel = atoi(as->parms[3].items->data);\n"
749 "\tserverPort = htons(atoi(as->parms[4].items->data));\n"
750 "\tif ((host = hostutil_GetHostByName(as->parms[5].items->data))==0) {\n"
751 "\t\terrflg++;\n" "\t}\n" "\telse {\n"
752 "\t\tmemcpy((void *) &serverAddr, (const void *)host->h_addr, sizeof(serverAddr));\n"
753 "\t}\n" "\tif ((secType<1) || (secType>2)) errflg++;\n"
754 "\tif ((encLevel<0) || (encLevel>2)) errflg++;\n"
755 "\tif ((serverPort == 0) ||(numThreads == 0) ||(numIterations == 0)) errflg++;\n"
756 "\tif (errflg) {\n" "\t\tprintf(\"invalid argument\\n\");\n"
757 "\t\texit(1);\n" "\t}\n\n" "\tif(rx_Init(htons(0)) < 0) {\n"
758 "\t\texit(1);\n" "\t}\n\n" "\tswitch(secType) {\n" "\t\tcase 1:\n"
759 "\t\t\tsecIndex = 0;\n"
760 "\t\t\tsecClass = rxnull_NewClientSecurityObject();\n"
761 "\t\t\tbreak;\n" "\t\tcase 2:\n"
762 "\t\t\tif (GetTicket (&kvno, &Ksession, &ticketLen, ticket) == 0) {\n"
763 "\t\t\t\tsecIndex = 2;\n"
764 "\t\t\t\tsecClass = rxkad_NewClientSecurityObject(encLevel,\n"
765 "\t\t\t\t&Ksession, kvno, ticketLen, ticket);\n" "\t\t\t}\n"
766 "\t\t\tbreak;\n" "\t\tdefault:\n" "\t\t\tbreak;\n" "\t}\n"
767 "\tassert(secClass);\n\n");
768 if (threadModel == PTHREADS) {
770 "#if defined sun\n" "\tthr_setconcurrency(numThreads);\n"
771 "#endif\n" "\ttid = (pthread_t *) "
772 "malloc(numThreads*(sizeof(pthread_t)));\n");
775 "\ttid = (PROCESS *) malloc(numThreads*(sizeof(PROCESS *)));\n");
778 fprintf(itl_h, "\tassert(tid);\n" "\tfor(j=0;j<numThreads;j++) {\n");
779 if (threadModel == PTHREADS) {
781 "\t\ti = pthread_create(&tid[j], (const pthread_attr_t *) 0,\n"
782 "\t\tthreadFunc, (void *) numIterations);\n"
783 "\t\tassert(i==0);\n");
786 "\t\tLWP_CALL(LWP_CreateProcess,(threadFunc, 10*4096, LWP_NORMAL_PRIORITY, numIterations, \"foo\", &tid[j]));\n");
789 fprintf(itl_h, "\t}\n" "\tfor(j=0;j<numThreads;j++) {\n");
790 if (threadModel == PTHREADS) {
792 "\t\ti = pthread_join(tid[j], (void **) 0);\n"
793 "\t\tassert(i==0);\n");
795 fprintf(itl_h, "\t\tLWP_CALL(LWP_WaitProcess,(&done));\n");
797 fprintf(itl_h, "\t}\n" "\trx_Finalize();\n" "\tfree(tid);\n" "}\n");
800 * Write command syntax function
804 "static void SetupRunCmd(void) {\n" "\tstruct cmd_syndesc *ts;\n"
805 "\tts = cmd_CreateSyntax(NULL,DoRun, 0, \"run the test client program\");\n"
806 "\tcmd_AddParm(ts, \"-threadCount\", CMD_SINGLE, CMD_REQUIRED, \"number of threads to spawn\");\n"
807 "\tcmd_AddParm(ts, \"-iterationCount\", CMD_SINGLE, CMD_REQUIRED, \"number of iterations to make over entire interface for each thread\");\n"
808 "\tcmd_AddParm(ts, \"-secType\", CMD_SINGLE, CMD_REQUIRED, \"security level to use (1 -> unauthenticated, 2 -> authenticated)\");\n"
809 "\tcmd_AddParm(ts, \"-encLevel\", CMD_SINGLE, CMD_REQUIRED, \"encryption level to use, (0-> rxkad_clear, 1 -> rxkad_auth, 2 -> rxkad_crypt)\");\n"
810 "\tcmd_AddParm(ts, \"-serverPort\", CMD_SINGLE, CMD_REQUIRED, \"port that server is using\");\n"
811 "\tcmd_AddParm(ts, \"-serverHost\", CMD_SINGLE, CMD_REQUIRED, \"host where server is running\");\n"
819 "int main (int argc, char *argv[]) {\n" "\tint code;\n\n"
820 "\tinitialize_CMD_error_table();\n" "\tSetupRunCmd();\n"
821 "\tcode = cmd_Dispatch(argc, argv);\n\n" "\treturn(code);\n"
827 * Create macros useful for checking input/output parameters
831 WriteTestMacros(FILE * f)
834 "\n#define CHECKchar(x,y,z) if ((x)!=(y)) { printf(\"%%s: Got '%%c',"
835 "expected '%%c'\\n\", z, (char)x, (char)(y)); fflush(stdout); "
836 "errFlag = 1; } " "\n#define CHECKshort(x,y,z) if ((x)!=(y)) "
837 "{ printf(\"%%s: Got 0x%%04x, "
838 "expected 0x%%04x\\n\", z, x, y); fflush(stdout); "
839 "errFlag = 1; } " "\n#define CHECKint32(x,y,z) if ((x)!=(y)) "
840 "{ printf(\"%%s: Got 0x%%08x, "
841 "expected 0x%%08x\\n\", z, x, y); fflush(stdout); "
843 "\n#define CHECKfloat(x,y,z) if (((x)/(y)<.999999) "
844 "|| ((x)/(y)>1.000001)) "
845 "{ printf(\"%%s: Got %%2.8e, expected %%2.8e\\n\", z, x, y); "
846 "fflush(stdout); " "errFlag = 1; } "
847 "\n#define CHECKdouble(x,y,z) if (((x)/(y)<.999999999999999) || "
848 "((x)/(y)>1.000000000000001)) { printf(\"%%s: Got %%2.16e, "
849 "expected %%2.16e\\n\", z, x, y); fflush(stdout); errFlag = 1; }"
850 "\n#define CHECKvarString(x,y,z) if (strcmp((x),(y))) { printf(\"%%s: "
851 "Got \\\"%%s\\\", expected \\\"%%s\\\"\\n\", z, x, y); fflush(stdout); "
852 "errFlag = 1; } \n");
856 * WriteCltHeader - write the begining of the client code.
859 WriteCltHeader(char *serverName, int srv_no, FILE * itl_h)
861 fprintf(itl_h, "#include <stdio.h>\n");
862 if (threadModel == PTHREADS) {
863 fprintf(itl_h, "#include <pthread.h>\n");
866 "%s" "#include <assert.h>\n" "#include <rx/rx.h>\n"
867 "#include <rx/rx_null.h>\n" "#include <rx/rxkad.h>\n"
868 "#include <afs/cmd.h>\n" "#include \"%s%d.h\"\n", platform[4],
870 if (threadModel == LWPS) {
872 "\n\n#define LWP_CALL(fnName, params) \\\n" "{ \\\n"
873 "\tint rc; \\\n" "\trc = fnName params; \\\n"
874 "\tif (rc != LWP_SUCCESS) { \\\n"
875 "\t\tprintf(\"call to %%s failed with %%d\\n\", # fnName, rc); \\\n"
876 "\t\texit(1); \\\n" "\t} \\\n" "};\n\n" "char done;\n\n");
880 "struct ktc_encryptionKey serviceKey =\n"
881 "\t{0x45, 0xe3, 0x3d, 0x16, 0x29, 0x64, 0x8a, 0x8f};\n"
882 "long serviceKeyVersion = 7;\n"
883 "\nextern struct hostent *hostutil_GetHostByName();\n\n"
884 "static long GetTicket (long *versionP,\n"
885 "\tstruct ktc_encryptionKey *session,\n"
886 "\tint * ticketLenP, char *ticket)\n" "{\n" "\tlong code;\n"
887 "\tdes_init_random_number_generator (&serviceKey);\n"
888 "\tcode = des_random_key (session);\n"
889 "\tif (code) return code;\n" "\t*ticketLenP = 0;\n"
890 "\tcode = tkt_MakeTicket(ticket, ticketLenP, &serviceKey,\n"
891 "\t\t\"tclnt\", \"\", \"\",\n" "\t\t0, 0xffffffff, session, 0,\n"
892 "\t\t\"tsrvr\", \"\");\n" "\tif (code) return code;\n"
893 "\t*versionP = serviceKeyVersion;\n" "\treturn 0;\n" "}\n\n"
894 "static int secType,encLevel,serverPort,serverAddr;\n"
895 "struct rx_securityClass *secClass;\n" "int secIndex;\n"
896 "long kvno;\n" "char ticket[MAXKTCTICKETLEN];\n"
897 "int ticketLen;\n" "struct ktc_encryptionKey Ksession;\n\n");
898 WriteTestMacros(itl_h);
903 * WriteCltInit -- write the initialization for each param
906 WriteCltInit(arg_tuple * arg, FILE * itl_h, int i, int structFlag)
909 char *s = (structFlag) ? "s." : "";
911 if ((!strncmp(arg->direction, "IN", 2) || structFlag)) {
912 if (!strncmp(arg->type, "varString", 9)) {
913 fprintf(itl_h, "\tstrcpy(%sa%d, %s);\n", s, i, arg->inValue[0]);
914 } else if (!strncmp(arg->type, "ar_", 3)) {
917 "\t%sa%d.drpc_out_%s_t_len = FIX_ARRAY_SIZE;\n", s, i,
920 "\t%sa%d.drpc_out_%s_t_val = "
921 "(%s *) malloc(FIX_ARRAY_SIZE * sizeof(%s));\n", s, i,
922 arg->type, (arg->type + 3), (arg->type + 3));
924 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++) {
926 fprintf(itl_h, "\t%sa%d[%d] = %s;\n", s, i, j,
929 fprintf(itl_h, "\t%sa%d.drpc_out_%s_t_val[%d] = %s;\n", s,
930 i, arg->type, j, arg->inValue[j]);
934 fprintf(itl_h, "\t%sa%d = %s;\n", s, i, arg->inValue[0]);
940 * WriteCltCall -- write each parameter for a call
943 WriteCltCall(arg_tuple * arg, FILE * itl_h, int i)
946 if (!strncmp(arg->type, "varString", 9)) {
947 if ((!strncmp(arg->direction, "OUT", 3))
948 || (!strncmp(arg->direction, "INOUT", 5))) {
949 fprintf(itl_h, "&a%d_p", i);
951 fprintf(itl_h, "a%d_p", i);
954 if ((!strncmp(arg->direction, "OUT", 3))
955 || (!strncmp(arg->direction, "INOUT", 5))
956 || (!strncmp(arg->type, "ar_", 3))) {
957 fprintf(itl_h, "&a%d", i);
959 fprintf(itl_h, "a%d", i);
965 * WriteCltDecl -- write the declaration for a parameter
968 WriteCltDecl(arg_tuple * arg, FILE * itl_h, int i)
971 if (!strncmp(arg->type, "ar_", 3)) {
972 if (!strncmp(arg->direction, "OUT", 3)) {
973 fprintf(itl_h, "\tdrpc_out_%s_t a%d = {0,0};\n", arg->type, i);
975 fprintf(itl_h, "\tdrpc_out_%s_t a%d;\n", arg->type, i);
977 } else if (!strncmp(arg->type, "varString", 9)) {
978 fprintf(itl_h, "\tchar a%d[STR_MAX];\n", i);
979 fprintf(itl_h, "\tchar *a%d_p = a%d;\n", i, i);
981 fprintf(itl_h, "\t%s a%d;\n", arg->type, i);
987 * WriteClt -- write the rpcs in the client
990 WriteClt(rpcArgs * argsP, char *serverName, int sign_no, FILE * itl_h)
992 char *name, *name2, *typ;
995 name = GetName(serverName, sign_no);
996 name2 = GetDescription(argsP);
998 fprintf(itl_h, "\n/* %s */\n\n", name2);
1000 fprintf(itl_h, "\nvoid C_%s(struct rx_connection *conn) {\n", name);
1002 /* declare each arg */
1003 for (i = 0; i < argsP->argCount; i++) {
1004 WriteCltDecl(&argsP->argDescr[i], itl_h, i);
1006 fprintf(itl_h, "\tint error;\n\tint errFlag;\n\n");
1008 /* initialize IN/INOUT args */
1009 for (i = 0; i < argsP->argCount; i++) {
1010 WriteCltInit(&argsP->argDescr[i], itl_h, i, FALSE);
1013 /* call the server */
1014 fprintf(itl_h, "\terror = A%s(conn, ", name);
1017 for (i = 0; i < argsP->argCount; i++) {
1018 WriteCltCall(&argsP->argDescr[i], itl_h, i);
1019 fprintf(itl_h, ((i < (argsP->argCount - 1))) ? "," : ");\n");
1023 "\tif (error != 0) {\n"
1024 "\t\tprintf(\"C_%s failed %%d\\n\", error);\n"
1025 "\t\tfflush(stdout);\n" "\t\treturn;\n" "\t}\n", name);
1028 * check the in and inout parameters
1030 for (i = 0; i < argsP->argCount; i++) {
1032 if ((!strcmp(argsP->argDescr[i].direction, "OUT"))
1033 || (!strcmp(argsP->argDescr[i].direction, "INOUT"))) {
1035 typ = argsP->argDescr[i].type;
1037 if (!strncmp(typ, "ar_", 3)) {
1038 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
1040 "\n\tCHECK%s(a%d.drpc_out_%s_t_val[%d], %s, \"C_%s_s\");",
1041 (typ + 3), i, typ, j,
1042 argsP->argDescr[i].outValue[j], name);
1043 } else if (strstr(typ, "String")) {
1044 fprintf(itl_h, "\n\tCHECK%s((char *)a%d, %s, \"C_%s_s\");",
1045 typ, i, argsP->argDescr[i].outValue[0], name);
1046 } else if (!strcmp(typ, "afs_int32")) {
1047 fprintf(itl_h, "\n\tCHECK%s(a%d, %sL, \"C_%s_s\");", typ, i,
1048 argsP->argDescr[i].outValue[0], name);
1050 fprintf(itl_h, "\n\tCHECK%s(a%d, %s, \"C_%s_s\");", typ, i,
1051 argsP->argDescr[i].outValue[0], name);
1057 * free up memory for dynamic input args
1059 for (i = 0; i < argsP->argCount; i++) {
1060 if (!strncmp(argsP->argDescr[i].type, "ar_", 3)) {
1061 typ = argsP->argDescr[i].type;
1063 "\n\tif (a%d.drpc_out_%s_t_val) "
1064 "free(a%d.drpc_out_%s_t_val);", i, typ, i, typ);
1069 fprintf(itl_h, "\n}\n");
1072 * Call the structure oriented rpc interface
1075 fprintf(itl_h, "\nvoid C_%s_s(struct rx_connection *conn) {\n", name);
1076 fprintf(itl_h, "\tstruct %s_t s;\n", name);
1077 fprintf(itl_h, "\tint error;\n\tint errFlag;\n\n");
1079 /* initialize IN/INOUT args */
1080 for (i = 0; i < argsP->argCount; i++) {
1081 WriteCltInit(&argsP->argDescr[i], itl_h, i, TRUE);
1084 /* call the server */
1085 fprintf(itl_h, "\terror = A%s_s(conn, &s);\n", name);
1088 "\tif (error != 0) {\n"
1089 "\t\tprintf(\"C_%s_s failed %%d\\n\", error);\n"
1090 "\t\tfflush(stdout);\n" "\t\treturn;\n" "\t}\n", name);
1093 * check the in and inout parameters
1095 for (i = 0; i < argsP->argCount; i++) {
1097 if ((!strcmp(argsP->argDescr[i].direction, "OUT"))
1098 || (!strcmp(argsP->argDescr[i].direction, "INOUT"))) {
1100 typ = argsP->argDescr[i].type;
1102 if (!strncmp(typ, "ar_", 3)) {
1103 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++)
1104 fprintf(itl_h, "\n\tCHECK%s(s.a%d[%d], %s, \"C_%s_s\");",
1105 (typ + 3), i, j, argsP->argDescr[i].outValue[j],
1107 } else if (strstr(typ, "String")) {
1108 fprintf(itl_h, "\n\tCHECK%s((char *)s.a%d, %s, \"C_%s_s\");",
1109 typ, i, argsP->argDescr[i].outValue[0], name);
1110 } else if (!strcmp(typ, "afs_int32")) {
1111 fprintf(itl_h, "\n\tCHECK%s(s.a%d, %sL, \"C_%s_s\");", typ, i,
1112 argsP->argDescr[i].outValue[0], name);
1114 fprintf(itl_h, "\n\tCHECK%s(s.a%d, %s, \"C_%s_s\");", typ, i,
1115 argsP->argDescr[i].outValue[0], name);
1121 fprintf(itl_h, "\n}\n");
1128 * WriteXGHeader -- fill in Header info in the xg file
1131 WriteXGHeader(char *serverName, FILE * xg_h, int srv_no)
1134 /* create the interface header */
1137 "\n/* Do not edit this file -- it was created by a generator */\n"
1138 "\npackage A\n\n" "const STR_MAX = %d; \n"
1139 "const FIX_ARRAY_SIZE = %d; \n" "typedef char drpc_char_t; \n"
1140 "typedef short drpc_short_t; \n" "typedef long drpc_int32_t; \n"
1141 "typedef string drpc_varString_t<STR_MAX>; \n"
1142 "typedef drpc_char_t drpc_ar_char_t[FIX_ARRAY_SIZE]; \n"
1143 "typedef drpc_char_t drpc_out_ar_char_t<FIX_ARRAY_SIZE>; \n"
1144 "typedef drpc_short_t drpc_ar_short_t[FIX_ARRAY_SIZE]; \n"
1145 "typedef drpc_short_t drpc_out_ar_short_t<FIX_ARRAY_SIZE>; \n"
1146 "typedef drpc_int32_t drpc_ar_int32_t[FIX_ARRAY_SIZE]; \n"
1147 "typedef drpc_int32_t drpc_out_ar_int32_t<FIX_ARRAY_SIZE>; \n",
1148 IDL_STR_MAX, IDL_FIX_ARRAY_SIZE);
1152 * WriteServHeader -- fill in the Header info in the server file
1155 WriteServHeader(FILE * srv_h, char *serverName, int srv_no)
1159 name = GetName(serverName, srv_no);
1162 "\n/* Do not edit this file -- it's been created by a generator */\n\n"
1163 "%s\n" "#include <stdio.h>\n" "#include <string.h>\n"
1164 "#include <stdlib.h>\n" "#include <rx/rx.h>\n"
1165 "#include <rx/rx_null.h>\n" "#include <rx/rxkad.h>\n"
1166 "#include <afs/cmd.h>\n" "#include \"%s.h\"\n\n"
1167 "struct ktc_encryptionKey serviceKey =\n"
1168 "\t{0x45, 0xe3, 0x3d, 0x16, 0x29, 0x64, 0x8a, 0x8f};\n"
1169 "long serviceKeyVersion = 7;\n\n"
1170 "extern int AExecuteRequest();\n" "extern char *optarg;\n"
1171 "extern int optind, opterr, optopt;\n\n"
1172 "#define VERIFY(x,y) if (!(x)) { printf y ; exit(1); }\n"
1173 "#define CHECK(x) ASSERT(x)\n", platform[4], name);
1175 WriteTestMacros(srv_h);
1180 * WriteServTrailer -- finish up the server file
1183 WriteServTrailer(FILE * srv_h)
1187 "\nstatic long GetKey (char *rock, long kvno, struct ktc_encryptionKey *key) {\n"
1188 "\tmemcpy ((void *) key, (void *) &serviceKey, sizeof(*key));\n"
1189 "\treturn 0;\n" "}\n\n"
1190 "static void DoRun(struct cmd_syndesc *as, char *arock) {\n"
1191 "\tstruct rx_service *serv;\n"
1192 "\tstruct rx_securityClass *sc[3];\n\n"
1193 "\tint port=0, errflg=0;\n" "\tint lowThreads=4, highThreads=8;\n"
1194 "\tlowThreads = atoi(as->parms[0].items->data);\n"
1195 "\thighThreads = atoi(as->parms[1].items->data);\n"
1196 "\tport = atoi(as->parms[2].items->data);\n"
1197 "\tif (port == 0) errflg++;\n" "\tif (errflg) {\n"
1198 "\t\tprintf(\"invalid argument\\n\");\n" "\t\texit(1);\n" "\t}\n"
1199 "\trx_Init(htons(port));\n"
1200 "\tsc[0] = rxnull_NewServerSecurityObject();\n" "\tsc[1] = 0;\n"
1201 "\tsc[2] = rxkad_NewServerSecurityObject (rxkad_clear, 0, GetKey, 0);\n"
1202 "\tif (serv = rx_NewService(0,4,\"foo\",sc,3,AExecuteRequest)) {\n"
1203 "\t\trx_SetMinProcs(serv,lowThreads);\n"
1204 "\t\trx_SetMaxProcs(serv,highThreads);\n"
1205 "\t\trx_StartServer(1);\n" "\t}\n" "\texit(0);\n" "}\n\n"
1206 "static void SetupRunCmd(void) {\n" "\tstruct cmd_syndesc *ts;\n"
1207 "\tts = cmd_CreateSyntax(NULL,DoRun, 0, \"run the test server program\");\n"
1208 "\tcmd_AddParm(ts, \"-lowThreadCount\", CMD_SINGLE, CMD_REQUIRED, \"minimum number of threads to spawn\");\n"
1209 "\tcmd_AddParm(ts, \"-highThreadCount\", CMD_SINGLE, CMD_REQUIRED, \"maximum number of threads to spawn\");\n"
1210 "\tcmd_AddParm(ts, \"-serverPort\", CMD_SINGLE, CMD_REQUIRED, \"port that server is using\");\n"
1211 "}\n" "int main(int argc, char **argv) {\n" "\tint code;\n"
1212 "\tinitialize_CMD_error_table();\n" "\tSetupRunCmd();\n"
1213 "\tcode = cmd_Dispatch(argc, argv);\n" "\treturn(code);\n" "}\n");
1217 * ProcessCmdLine -- processes the command line args
1220 ProcessCmdLine(int argc, char **argv, char **serverName, char **ipFileName,
1227 /* command line processing */
1228 while (--argc > 0) {
1229 if ((*++argv)[0] == '-') {
1230 switch ((*argv)[1]) {
1233 case 'F': /* input table file */
1234 *ipFileName = *++argv;
1237 case 'h': /* display help */
1243 case 'L': /* use LWP threads */
1247 case 'S': /* serverName */
1248 *serverName = *++argv;
1249 /* need 8 char file name, and so truncate the server name */
1250 if ((int)strlen(*serverName) > MAX_SERV_NAME)
1251 *(*serverName + MAX_SERV_NAME) = '\0';
1256 *outputDir = *++argv;
1261 if (strcmp(*++argv, "NT"))
1262 platform = unix_symbols;
1276 FATAL("Please set server name using -s switch\n");
1281 main(int argc, char **argv)
1283 FILE *table_h, *srv_h, *xg_h, *clt_h, *mak_h;
1286 char *name, *ifName;
1287 char *serverName = NULL;
1288 char *ipFileName = NULL;
1289 char *outputDir = NULL;
1290 int sign_no = 0, start_no, srv_no;
1292 ProcessCmdLine(argc, argv, &serverName, &ipFileName, &outputDir);
1294 /* open input file */
1295 table_h = fopen(ipFileName, "r");
1296 MEM_CHK(table_h, "main: Unable to open input file\n");
1302 * open the first set of output files
1305 name = GetName(serverName, srv_no);
1307 srv_h = OpenOutFile(outputDir, name, "Srv.c");
1308 xg_h = OpenOutFile(outputDir, name, ".xg");
1309 clt_h = OpenOutFile(outputDir, name, "Clt.c");
1310 mak_h = OpenOutFile(outputDir, name, ".mak");
1312 WriteXGHeader(serverName, xg_h, srv_no);
1313 WriteServHeader(srv_h, serverName, srv_no);
1314 WriteCltHeader(serverName, srv_no, clt_h);
1315 WriteMake(serverName, srv_no, mak_h);
1319 /* read the table */
1320 while (fscanf(table_h, "%d", &(args.argCount)) != EOF) {
1322 /* increment signature number 8.3 format-- only 10^7 dif sign */
1324 if (sign_no > 1.0e+7)
1325 FATAL("Max no: of signatures overflow\n");
1327 /* allocate for the arg struct */
1329 (arg_tuple *) calloc(args.argCount, sizeof(arg_tuple));
1330 MEM_CHK(args.argDescr, "main: Out of memory -- args.argDescr\n");
1332 /* pick out the dirs and the types */
1333 for (i = 0; i < args.argCount; i++) {
1335 (table_h, " ( %s %s )", args.argDescr[i].direction,
1336 args.argDescr[i].type)) {
1337 FATAL("main: Incorrect input file format\n");
1342 * switch files when we hit TESTS_PER_FILE
1344 if (sign_no - start_no >= TESTS_PER_FILE) {
1346 * Finish up the current files
1348 WriteServTrailer(srv_h);
1349 WriteCltTrailer(serverName, start_no, sign_no, clt_h);
1356 * Open the next set of output files
1361 name = GetName(serverName, srv_no);
1363 srv_h = OpenOutFile(outputDir, name, "Srv.c");
1364 xg_h = OpenOutFile(outputDir, name, ".xg");
1365 clt_h = OpenOutFile(outputDir, name, "Clt.c");
1366 mak_h = OpenOutFile(outputDir, name, ".mak");
1367 WriteXGHeader(serverName, xg_h, srv_no);
1368 WriteServHeader(srv_h, serverName, srv_no);
1369 WriteCltHeader(serverName, srv_no, clt_h);
1370 WriteMake(serverName, srv_no, mak_h);
1376 /* initialize parameter values */
1377 for (i = 0; i < args.argCount; i++) {
1378 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++) {
1379 args.argDescr[i].inValue[j] = NULL;
1380 args.argDescr[i].inValue2[j] = NULL;
1381 args.argDescr[i].outValue[j] = NULL;
1382 args.argDescr[i].outValue2[j] = NULL;
1385 GenParamValues(&args);
1387 /* write rpc desc into body of the interface */
1388 WriteXG(&args, xg_h, serverName, sign_no);
1390 /* write the rpc into the manager file */
1391 WriteServC(&args, srv_h, serverName, sign_no);
1393 /* write out ITL test */
1394 WriteClt(&args, serverName, sign_no, clt_h);
1396 /* free saved values */
1397 for (i = 0; i < args.argCount; i++) {
1398 for (j = 0; j < IDL_FIX_ARRAY_SIZE; j++) {
1399 if (args.argDescr[i].inValue[j])
1400 free(args.argDescr[i].inValue[j]);
1401 if (args.argDescr[i].inValue2[j])
1402 free(args.argDescr[i].inValue2[j]);
1403 if (args.argDescr[i].outValue[j])
1404 free(args.argDescr[i].outValue[j]);
1405 if (args.argDescr[i].outValue2[j])
1406 free(args.argDescr[i].outValue2[j]);
1409 free(args.argDescr);
1412 WriteServTrailer(srv_h);
1413 WriteCltTrailer(serverName, start_no, (sign_no + 1), clt_h);
1423 * create 1 makefile that drives all the rest
1426 mak_h = OpenOutFile(outputDir, "Makefile", "");
1427 fprintf(mak_h, "\ntest:all\ntests:all\nall:\n");
1428 fprintf(mak_h, "%s", platform[8]);
1429 for (i = 1; i <= srv_no; i++)
1430 fprintf(mak_h, "\t%s %s%d.mak %s\n", platform[0], serverName, i,
1432 fprintf(mak_h, "\nclean:\n");
1433 for (i = 1; i <= srv_no; i++)
1434 fprintf(mak_h, "\t%s %s%d.mak clean\n", platform[0], serverName, i);