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 * The program will create a file that contains descriptions
12 * of a set of rx rpc's. The output of this program is used
13 * as input to generator.c.
15 * Changing the output format of this program will necessitate
16 * a change in generator.c
19 #include <afsconfig.h>
20 #include <afs/param.h>
27 #define PRIVATE static
29 #define MACRO_BEGIN do {
30 #define MACRO_END } while (0)
34 #define close(x) _close(x)
38 #define MAX_NO_OF_ARGUMENTS 2
39 #define MAX_TYPE_NAME_LEN 10
40 #define MAX_DIRECTION_NAME_LEN 6
41 #define MAX_ATTR_NAME_LEN 7
42 #define MAX_SIGNATURE_LEN 100000
44 #define NEXT_SEQ(S,M) (((S) >= ((M)-1)) ? 0 : (S)+1)
46 #define MEM_CHK(x, y) if(!x) {fprintf(stderr, y); exit(1);}
47 #define FATAL( y ) {fprintf(stderr, y); exit(1);}
48 #define PrintShortUsage \
51 "Usage: tableGen [-h] [-a] <appendFileName> -d <list of dirs> \
52 [-o] <outputFile> -t <list of types>\n"); \
54 #define PrintLongUsage \
58 "\nCommand line options(case insensitive):\
59 \n\t-h = help message \
60 \n\t-a = set the file to append\
61 \n\t-d = set the list of directions (IN OUT INOUT)\
62 \n\t-o = set output file (mandatory)\
63 \n\t-t = set the list of types (char int8 short afs_int32 \
64 \n\t\tfloat double string ar_char ar_int8 ar_short \
65 \n\t\tar_int32 ar_float ar_double \
69 /* macro which sets if attributes for var/conf found */
70 #define SET_ATTR_FLAGS( x ) \
72 if (!strcmp(attrib[x], "size")) SIZE = TRUE;\
73 else if (!strcmp(attrib[x], "max")) MAX = TRUE; \
74 else if (!strcmp(attrib[x], "length")) LENGTH = TRUE;\
75 else if (!strcmp(attrib[x], "last")) LAST = TRUE;\
84 PRIVATE
char *init_dir
[] = { "IN", "OUT", "INOUT" };
86 PRIVATE
char *init_typ
[] = {
95 PRIVATE
char *attrib
[] = {
110 "3 max first length",
112 "3 size first length"
116 * 31 bit random number generator, we don't really care how random
117 * these numbers are, it is more important that identical IDL files
118 * are generated no matter what platform the generator runs on
120 static unsigned long randVal
= 0x330E16;
125 randVal
= ((randVal
* 0xEECE66D) + 0xB) & 0xFFFFFFFF;
126 return ((double)(randVal
) / 4294967296.0);
130 * BunchArg -- prints signature for lots of arguments
135 BunchArg(FILE * O_FP
)
137 int num_args
= ((int)((double)MAX_ARGS
* drand32()));
139 int dir_index
, typ_index
;
143 fprintf(O_FP
, "%d ", num_args
);
145 for (i
= 0; i
< num_args
; i
++) {
146 typ_index
= ((int)((double)typ_size
* drand32()));
148 dir_index
= ((int)((double)dir_size
* drand32()));
149 } while (!strcmp(dir
[dir_index
], "INOUT")
150 && (!strcmp(typ
[typ_index
], "varString")));
152 fprintf(O_FP
, "( %s %s ) ", dir
[dir_index
], typ
[typ_index
]);
158 * SingleArg -- prints signature for single argument of given type
161 SingleArg(O_FP
, typ_index
)
168 * choose random argument direction, cannot use ref string
169 * pointers for output parameters
172 dir_index
= ((int)((double)dir_size
* drand32()));
173 } while (!strcmp(dir
[dir_index
], "INOUT")
174 && (!strcmp(typ
[typ_index
], "varString")));
176 fprintf(O_FP
, "1 ( %s %s )\n", dir
[dir_index
], typ
[typ_index
]);
180 * DoubleArg -- prints signature for two arguments of given types
183 DoubleArg(O_FP
, typ_index1
, typ_index2
)
192 * choose random argument direction, cannot use ref string
193 * pointers for output parameters
196 dir_index1
= ((int)((double)dir_size
* drand32()));
197 } while (!strcmp(dir
[dir_index1
], "INOUT")
198 && (!strcmp(typ
[typ_index1
], "varString")));
200 dir_index2
= ((int)((double)dir_size
* drand32()));
201 } while (!strcmp(dir
[dir_index2
], "INOUT")
202 && (!strcmp(typ
[typ_index2
], "varString")));
204 fprintf(O_FP
, "2 ( %s %s ) ", dir
[dir_index1
], typ
[typ_index1
]);
205 fprintf(O_FP
, "( %s %s )\n", dir
[dir_index2
], typ
[typ_index2
]);
209 * ProcessCmdLine -- processes the command line args
212 ProcessCmdLine(argc
, argv
, apFileNamePP
, outputFileP
)
228 /* command line processing */
230 if ((*++argv
)[0] == '-') {
231 switch ((*argv
)[1]) {
234 case 'A': /* input table file */
235 *apFileNamePP
= *++argv
;
242 while (argc
> 1 && (*++p
)[0] != '-') {
247 FATAL("ProcessCmdLine: must give dir with -d\n");
249 dir
= malloc(sizeof(char *) * n
);
250 MEM_CHK(dir
, "ProcessCmdLine: out of mem dir\n");
251 for (i
= 0; i
< n
; i
++)
252 *(dir
+ i
) = *++argv
;
254 case 'h': /* display help */
261 *outputFileP
= *(++argv
);
268 while (argc
> 1 && (*++p
)[0] != '-') {
273 FATAL("ProcessCmdLine: must give typ with -t\n");
275 typ
= malloc(sizeof(char *) * n
);
276 MEM_CHK(typ
, "ProcessCmdLine: out of mem typ\n");
277 for (i
= 0; i
< n
; i
++)
278 *(typ
+ i
) = *++argv
;
290 if (*outputFileP
== 0)
291 FATAL("Please set output filename(s) using -o switch\n");
294 dir_size
= sizeof(init_dir
) / sizeof(init_dir
[0]);
299 typ_size
= sizeof(init_typ
) / sizeof(init_typ
[0]);
303 attr_size
= sizeof(attrib
) / sizeof(attrib
[0]);
312 char *apFileName
= NULL
;
316 char max_buf
[MAX_SIGNATURE_LEN
];
318 ProcessCmdLine(argc
, argv
, &apFileName
, &outputFile
);
321 O_FP
= fopen(outputFile
, "w");
322 MEM_CHK(O_FP
, "main: Unable to open output file\n");
324 A_FP
= fopen(apFileName
, "r");
325 MEM_CHK(A_FP
, "main: Unable to open append file\n");
326 while (fgets(max_buf
, MAX_SIGNATURE_LEN
, A_FP
)) {
327 fputs(max_buf
, O_FP
);
332 for (i
= 0; i
< typ_size
; i
++) {
334 for (j
= 0; j
< typ_size
; j
++) {
335 DoubleArg(O_FP
, i
, j
);
338 for (i
= 0; i
< 100; i
++) {