Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rxgen / rpc_main.c
1 /* @(#)rpc_main.c 1.4 87/11/30 3.9 RPCSRC */
2 /*
3 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4 * unrestricted use provided that this legend is included on all tape
5 * media and as a part of the software program in whole or part. Users
6 * may copy or modify Sun RPC without charge, but are not authorized
7 * to license or distribute it to anyone else except as part of a product or
8 * program developed by the user.
9 *
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 *
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
17 *
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
21 *
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
25 *
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
29 */
30
31 /*
32 * rpc_main.c, Top level of the RPC protocol compiler.
33 * Copyright (C) 1987, Sun Microsystems, Inc.
34 */
35
36 #include <afsconfig.h>
37 #include <afs/param.h>
38
39 #include <roken.h>
40
41 #include <limits.h>
42 #include <ctype.h>
43
44 #include "rpc_scan.h"
45 #include "rpc_parse.h"
46 #include "rpc_util.h"
47
48 #define EXTEND 1 /* alias for TRUE */
49
50 struct commandline {
51 int ansic_flag;
52 int brief_flag;
53 int cflag;
54 int hflag;
55 int Cflag;
56 int Sflag;
57 int rflag;
58 int kflag;
59 int pflag;
60 int dflag;
61 int xflag;
62 int yflag;
63 int uflag;
64 char *infile;
65 char *outfile;
66 };
67
68 #define MAXCPPARGS 256 /* maximum number of arguments to cpp */
69
70 char *prefix = "";
71 static char *IncludeDir[MAXCPPARGS];
72 int nincludes = 0;
73 char *OutFileFlag = "";
74 char OutFile[256];
75 char Sflag = 0, Cflag = 0, hflag = 0, cflag = 0, kflag = 0, uflag = 0;
76 char ansic_flag = 0; /* If set, build ANSI C style prototypes */
77 char brief_flag = 0; /* If set, shorten names */
78 char zflag = 0; /* If set, abort server stub if rpc call returns non-zero */
79 char xflag = 0; /* if set, add stats code to stubs */
80 char yflag = 0; /* if set, only emit function name arrays to xdr file */
81 int debug = 0;
82 static int pclose_fin = 0;
83 static char *cmdname;
84 #ifdef PATH_CPP
85 static char *CPP = PATH_CPP;
86 #else
87 #ifdef AFS_NT40_ENV
88 static char *CPP = "cl /EP /C /nologo";
89 #else
90 static char *CPP = "/lib/cpp";
91 #endif
92 #endif
93
94 /*
95 * Running "cpp" directly on DEC OSF/1 does not define anything; the "cc"
96 * driver is responsible. To compensate (and allow for other definitions
97 * which should always be passed to "cpp"), place definitions which whould
98 * always be passed to "rxgen" in this string.
99 */
100 static char *CPPFLAGS = "-C"
101 #ifdef AFS_ALPHA_ENV
102 #ifdef __alpha
103 " -D__alpha"
104 #endif /* __alpha */
105 #ifdef OSF
106 " -DOSF"
107 #endif /* OSF */
108 #endif
109 ;
110
111 #include "AFS_component_version_number.c"
112
113 /* static prototypes */
114 static char *extendfile(char *file, char *ext);
115 static void open_output(char *infile, char *outfile);
116 static void open_input(char *infile, char *define);
117 static void c_output(char *infile, char *define, int extend, char *outfile,
118 int append);
119 static void h_output(char *infile, char *define, int extend, char *outfile,
120 int append);
121 static int parseargs(int argc, char *argv[], struct commandline *cmd);
122 static void C_output(char *infile, char *define, int extend, char *outfile,
123 int append);
124 static void S_output(char *infile, char *define, int extend, char *outfile,
125 int append);
126 static char *uppercase(char *str);
127
128 int
129 main(int argc, char *argv[])
130 {
131 struct commandline cmd;
132 char *ep;
133
134 ep = getenv("RXGEN_CPPCMD");
135 if (ep)
136 CPP = ep;
137 #ifdef AFS_AIX32_ENV
138 /*
139 * The following signal action for AIX is necessary so that in case of a
140 * crash (i.e. core is generated) we can include the user's data section
141 * in the core dump. Unfortunately, by default, only a partial core is
142 * generated which, in many cases, isn't too useful.
143 */
144 struct sigaction nsa;
145
146 sigemptyset(&nsa.sa_mask);
147 nsa.sa_handler = SIG_DFL;
148 nsa.sa_flags = SA_FULLDUMP;
149 sigaction(SIGSEGV, &nsa, NULL);
150 #endif
151 reinitialize();
152 if (!parseargs(argc, argv, &cmd)) {
153 f_print(stderr, "usage: %s infile\n", cmdname);
154 f_print(stderr,
155 " %s [-c | -h | -C | -S | -r | -b | -k | -p | -d | -z | -u] [-Pprefix] [-Idir] [-o outfile] [infile]\n",
156 cmdname);
157 f_print(stderr, " %s [-o outfile] [infile]\n",
158 cmdname);
159 exit(1);
160 }
161 OutFileFlag = cmd.outfile;
162 if (OutFileFlag)
163 strcpy(OutFile, cmd.outfile);
164 if (cmd.cflag) {
165 OutFileFlag = NULL;
166 c_output(cmd.infile, "-DRPC_XDR", !EXTEND, cmd.outfile, 0);
167 } else if (cmd.hflag) {
168 h_output(cmd.infile, "-DRPC_HDR", !EXTEND, cmd.outfile, 0);
169 } else if (cmd.Cflag) {
170 OutFileFlag = NULL;
171 C_output(cmd.infile, "-DRPC_CLIENT", !EXTEND, cmd.outfile, 1);
172 } else if (cmd.Sflag) {
173 OutFileFlag = NULL;
174 S_output(cmd.infile, "-DRPC_SERVER", !EXTEND, cmd.outfile, 1);
175 } else {
176 if (OutFileFlag && (strrchr(OutFile, '.') == NULL))
177 strcat(OutFile, ".");
178 if (cmd.rflag) {
179 C_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_CLIENT",
180 EXTEND, ".cs.c", 1);
181 reinitialize();
182 S_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_SERVER",
183 EXTEND, ".ss.c", 1);
184 reinitialize();
185 } else {
186 reinitialize();
187 c_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_XDR",
188 EXTEND, ".xdr.c", 0);
189 reinitialize();
190 h_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_HDR",
191 EXTEND, ".h", 0);
192 reinitialize();
193 C_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_CLIENT",
194 EXTEND, ".cs.c", 1);
195 reinitialize();
196 S_output((OutFileFlag ? OutFile : cmd.infile), "-DRPC_SERVER",
197 EXTEND, ".ss.c", 1);
198 reinitialize();
199 }
200 }
201 if (fin && pclose_fin) {
202 /* the cpp command we called returned a non-zero exit status */
203 if (pclose(fin)) {
204 crash();
205 }
206 }
207 exit(0);
208 }
209
210 /*
211 * add extension to filename
212 */
213 static char *
214 extendfile(char *file, char *ext)
215 {
216 char *res;
217 char *p;
218 char *sname;
219
220 res = alloc(strlen(file) + strlen(ext) + 1);
221 if (res == NULL) {
222 abort();
223 }
224 p = (char *)strrchr(file, '.');
225 if (p == NULL) {
226 p = file + strlen(file);
227 }
228 sname = (char *)strrchr(file, '/');
229 if (sname == NULL)
230 sname = file;
231 else
232 sname++;
233 strcpy(res, sname);
234 strcpy(res + (p - sname), ext);
235 return (res);
236 }
237
238 /*
239 * Open output file with given extension
240 */
241 static void
242 open_output(char *infile, char *outfile)
243 {
244 if (outfile == NULL) {
245 fout = stdout;
246 return;
247 }
248 if (infile != NULL && streq(outfile, infile)) {
249 f_print(stderr, "%s: output would overwrite %s\n", cmdname, infile);
250 crash();
251 }
252 fout = fopen(outfile, "w");
253 if (fout == NULL) {
254 f_print(stderr, "%s: unable to open ", cmdname);
255 perror(outfile);
256 crash();
257 }
258 record_open(outfile);
259 }
260
261 /*
262 * Open input file with given define for C-preprocessor
263 */
264 static void
265 open_input(char *infile, char *define)
266 {
267 char *cpp_cmdline;
268 int i, l = 0;
269
270 if (debug == 0) {
271 infilename = (infile == NULL) ? "<stdin>" : infile;
272 l = strlen(CPP) + strlen(CPPFLAGS) + strlen(define) + 3;
273 for (i = 0; i < nincludes; i++)
274 l += strlen(IncludeDir[i]) + 1;
275 l += strlen(infile) + 1;
276 cpp_cmdline = malloc(l);
277 if (!cpp_cmdline) {
278 perror("Unable to allocate space for cpp command line");
279 crash();
280 }
281
282 sprintf(cpp_cmdline, "%s %s %s", CPP, CPPFLAGS, define);
283 l = strlen(cpp_cmdline);
284 for (i = 0; i < nincludes; i++) {
285 cpp_cmdline[l++] = ' ';
286 strcpy(cpp_cmdline + l, IncludeDir[i]);
287 l += strlen(IncludeDir[i]);
288 }
289 cpp_cmdline[l++] = ' ';
290 strcpy(cpp_cmdline + l, infile);
291
292 fin = popen(cpp_cmdline, "r");
293 if (fin == NULL)
294 perror("popen");
295 pclose_fin = 1;
296
297 } else {
298 if (infile == NULL) {
299 fin = stdin;
300 return;
301 }
302 fin = fopen(infile, "r");
303 }
304 if (fin == NULL) {
305 f_print(stderr, "%s: ", cmdname);
306 perror(infilename);
307 crash();
308 }
309 }
310
311 /*
312 * Compile into an XDR routine output file
313 */
314 static void
315 c_output(char *infile, char *define, int extend, char *outfile, int append)
316 {
317 definition *def;
318 char *include;
319 char *outfilename;
320 long tell;
321 char fullname[1024];
322 char *currfile = (OutFileFlag ? OutFile : infile);
323 int i, j;
324
325 open_input(infile, define);
326 cflag = 1;
327 memset(fullname, 0, sizeof(fullname));
328 if (append) {
329 strcpy(fullname, prefix);
330 strcat(fullname, infile);
331 } else
332 strcpy(fullname, infile);
333 outfilename = extend ? extendfile(fullname, outfile) : outfile;
334 open_output(infile, outfilename);
335 f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
336 if (xflag) {
337 if (kflag) {
338 f_print(fout, "#include \"afsconfig.h\"\n");
339 f_print(fout, "#include \"afs/param.h\"\n");
340 } else {
341 f_print(fout, "#include <afsconfig.h>\n");
342 f_print(fout, "#include <afs/param.h>\n");
343 f_print(fout, "#include <roken.h>\n");
344 }
345 f_print(fout, "#ifdef AFS_NT40_ENV\n");
346 f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllexport)\n");
347 f_print(fout, "#endif /* AFS_NT40_ENV */\n");
348 }
349 if (currfile && (include = extendfile(currfile, ".h"))) {
350 if (kflag) {
351 f_print(fout, "#include \"%s\"\n\n", include);
352 } else
353 f_print(fout, "#include \"%s\"\n\n", include);
354 free(include);
355 } else {
356 /* In case we can't include the interface's own header file... */
357 if (kflag) {
358 f_print(fout, "#include \"h/types.h\"\n");
359 f_print(fout, "#include \"h/socket.h\"\n");
360 f_print(fout, "#include \"h/file.h\"\n");
361 f_print(fout, "#include \"h/stat.h\"\n");
362 f_print(fout, "#include \"netinet/in.h\"\n");
363 f_print(fout, "#include \"h/time.h\"\n");
364 f_print(fout, "#include \"rx/xdr.h\"\n");
365 f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
366 } else {
367 f_print(fout, "#include <rx/xdr.h>\n");
368 }
369 }
370
371 tell = ftell(fout);
372 while ((def = get_definition())) {
373 if (!yflag) {
374 if ((!IsRxgenDefinition(def)) && def->def_kind != DEF_CUSTOMIZED)
375 emit(def);
376 }
377 }
378
379 /*
380 * Print out array containing list of all functions in the interface
381 * in order
382 */
383
384 if (xflag) {
385 for (j = 0; j <= PackageIndex; j++) {
386 f_print(fout, "AFS_RXGEN_EXPORT\n");
387 f_print(fout, "const char *%sfunction_names[] = {\n",
388 PackagePrefix[j]);
389
390 for (i = 0; i < no_of_stat_funcs_header[j]; i++) {
391 if (i == 0) {
392 f_print(fout, "\t\"%s\"", function_list[j][i]);
393 } else {
394 f_print(fout, ",\n\t\"%s\"", function_list[j][i]);
395 }
396 }
397
398
399 f_print(fout, "\n};\n");
400 }
401 er_Proc_CodeGeneration();
402 }
403
404 if (extend && tell == ftell(fout)) {
405 (void)unlink(outfilename);
406 }
407 cflag = 0;
408 }
409
410 /*
411 * Compile into an XDR header file
412 */
413 static void
414 h_output(char *infile, char *define, int extend, char *outfile, int append)
415 {
416 definition *def;
417 char *outfilename;
418 long tell;
419 char fullname[1024], *p;
420
421 open_input(infile, define);
422 hflag = 1;
423 memset(fullname, 0, sizeof(fullname));
424 if (append) {
425 strcpy(fullname, prefix);
426 strcat(fullname, infile);
427 } else
428 strcpy(fullname, infile);
429 outfilename = extend ? extendfile(fullname, outfile) : outfile;
430 open_output(infile, outfilename);
431 strcpy(fullname, outfilename);
432 if ((p = strchr(fullname, '.')))
433 *p = '\0';
434 f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
435 f_print(fout, "#ifndef _RXGEN_%s_\n", uppercase(fullname));
436 f_print(fout, "#define _RXGEN_%s_\n\n", uppercase(fullname));
437 f_print(fout, "#ifdef KERNEL\n");
438 f_print(fout,
439 "/* The following 'ifndefs' are not a good solution to the vendor's omission of surrounding all system includes with 'ifndef's since it requires that this file is included after the system includes...*/\n");
440 f_print(fout, "#include <afsconfig.h>\n");
441 f_print(fout, "#include \"afs/param.h\"\n");
442 f_print(fout, "#ifdef UKERNEL\n");
443 f_print(fout, "#include \"afs/sysincludes.h\"\n");
444 f_print(fout, "#include \"rx/xdr.h\"\n");
445 f_print(fout, "#include \"rx/rx.h\"\n");
446 if (xflag) {
447 f_print(fout, "#include \"rx/rx_globals.h\"\n");
448 }
449 if (brief_flag) {
450 f_print(fout, "#include \"rx/rx_opaque.h\"\n");
451 }
452 f_print(fout, "#else /* UKERNEL */\n");
453 f_print(fout, "#include \"h/types.h\"\n");
454 f_print(fout, "#ifndef SOCK_DGRAM /* XXXXX */\n");
455 f_print(fout, "#include \"h/socket.h\"\n");
456 f_print(fout, "#endif\n");
457 f_print(fout, "#ifndef DTYPE_SOCKET /* XXXXX */\n");
458 f_print(fout, "#ifndef AFS_LINUX22_ENV\n");
459 f_print(fout, "#include \"h/file.h\"\n");
460 f_print(fout, "#endif\n");
461 f_print(fout, "#endif\n");
462 f_print(fout, "#ifndef S_IFMT /* XXXXX */\n");
463 f_print(fout, "#include \"h/stat.h\"\n");
464 f_print(fout, "#endif\n");
465 f_print(fout, "#if defined (AFS_OBSD_ENV) && !defined (MLEN)\n");
466 f_print(fout, "#include \"sys/mbuf.h\"\n");
467 f_print(fout, "#endif\n");
468 f_print(fout, "#ifndef IPPROTO_UDP /* XXXXX */\n");
469 f_print(fout, "#include \"netinet/in.h\"\n");
470 f_print(fout, "#endif\n");
471 f_print(fout, "#ifndef DST_USA /* XXXXX */\n");
472 f_print(fout, "#include \"h/time.h\"\n");
473 f_print(fout, "#endif\n");
474 f_print(fout, "#ifndef XDR_GETLONG /* XXXXX */\n");
475 f_print(fout, "#ifdef AFS_LINUX22_ENV\n");
476 f_print(fout, "#ifndef quad_t\n");
477 f_print(fout, "#define quad_t __quad_t\n");
478 f_print(fout, "#define u_quad_t __u_quad_t\n");
479 f_print(fout, "#endif\n");
480 f_print(fout, "#endif\n");
481 f_print(fout, "#include \"rx/xdr.h\"\n");
482 f_print(fout, "#endif /* XDR_GETLONG */\n");
483 f_print(fout, "#endif /* UKERNEL */\n");
484 f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
485 f_print(fout, "#include \"afs_osi.h\"\n");
486 f_print(fout, "#include \"rx/rx.h\"\n");
487 if (xflag) {
488 f_print(fout, "#include \"rx/rx_globals.h\"\n");
489 }
490 if (brief_flag) {
491 f_print(fout, "#include \"rx/rx_opaque.h\"\n");
492 }
493 f_print(fout, "#else /* KERNEL */\n");
494 f_print(fout, "#include <afs/param.h>\n");
495 f_print(fout, "#include <afs/stds.h>\n");
496 f_print(fout, "#include <sys/types.h>\n");
497 f_print(fout, "#include <rx/xdr.h>\n");
498 f_print(fout, "#include <rx/rx.h>\n");
499 if (xflag) {
500 f_print(fout, "#include <rx/rx_globals.h>\n");
501 }
502 if (brief_flag) {
503 f_print(fout, "#include <rx/rx_opaque.h>\n");
504 }
505 f_print(fout, "#include <afs/rxgen_consts.h>\n");
506 if (uflag)
507 f_print(fout, "#include <ubik.h>\n");
508 f_print(fout, "#endif /* KERNEL */\n\n");
509 f_print(fout, "#ifdef AFS_NT40_ENV\n");
510 f_print(fout, "#ifndef AFS_RXGEN_EXPORT\n");
511 f_print(fout, "#define AFS_RXGEN_EXPORT __declspec(dllimport)\n");
512 f_print(fout, "#endif /* AFS_RXGEN_EXPORT */\n");
513 f_print(fout, "#else /* AFS_NT40_ENV */\n");
514 f_print(fout, "#define AFS_RXGEN_EXPORT\n");
515 f_print(fout, "#endif /* AFS_NT40_ENV */\n\n");
516 tell = ftell(fout);
517 while ((def = get_definition())) {
518 print_datadef(def);
519 }
520 h_Proc_CodeGeneration();
521 h_opcode_stats();
522 hflag = 0;
523 f_print(fout, "#endif /* _RXGEN_%s_ */\n", uppercase(fullname));
524 if (extend && tell == ftell(fout)) {
525 (void)unlink(outfilename);
526 }
527 }
528
529 static void
530 C_output(char *infile, char *define, int extend, char *outfile, int append)
531 {
532 char *include;
533 char *outfilename;
534 char fullname[1024];
535 long tell;
536 char *currfile = (OutFileFlag ? OutFile : infile);
537
538 Cflag = 1;
539 open_input(infile, define);
540 memset(fullname, 0, sizeof(fullname));
541 if (append) {
542 strcpy(fullname, prefix);
543 strcat(fullname, infile);
544 } else
545 strcpy(fullname, infile);
546 outfilename = extend ? extendfile(fullname, outfile) : outfile;
547 open_output(infile, outfilename);
548 f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
549 if (currfile && (include = extendfile(currfile, ".h"))) {
550 if (kflag) {
551 f_print(fout, "#include \"%s\"\n\n", include);
552 } else {
553 f_print(fout, "#include <afsconfig.h>\n");
554 f_print(fout, "#include <afs/param.h>\n");
555 f_print(fout, "#include <roken.h>\n");
556 f_print(fout, "#include <afs/opr.h>\n");
557 f_print(fout, "#ifdef AFS_PTHREAD_ENV\n");
558 f_print(fout, "# include <opr/lock.h>\n");
559 f_print(fout, "#endif\n");
560 f_print(fout, "#include \"%s\"\n\n", include);
561 }
562 free(include);
563 } else {
564 if (kflag) {
565 f_print(fout, "#include \"h/types.h\"\n");
566 f_print(fout, "#include \"h/socket.h\"\n");
567 f_print(fout, "#include \"h/file.h\"\n");
568 f_print(fout, "#include \"h/stat.h\"\n");
569 f_print(fout, "#include \"netinet/in.h\"\n");
570 f_print(fout, "#include \"h/time.h\"\n");
571 f_print(fout, "#include \"rx/xdr.h\"\n");
572 f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
573 f_print(fout, "#include \"afs/afs_osi.h\"\n");
574 f_print(fout, "#include \"rx/rx.h\"\n");
575 if (xflag) {
576 f_print(fout, "#include \"rx/rx_globals.h\"\n");
577 }
578 if (brief_flag) {
579 f_print(fout, "#include \"rx/rx_opaque.h\"\n");
580 }
581 } else {
582 f_print(fout, "#include <sys/types.h>\n");
583 f_print(fout, "#include <rx/xdr.h>\n");
584 f_print(fout, "#include <rx/rx.h>\n");
585 if (xflag) {
586 f_print(fout, "#include <rx/rx_globals.h>\n");
587 }
588 if (brief_flag) {
589 f_print(fout, "#include <rx/rx_opaque.h\"\n");
590 }
591 f_print(fout, "#include <afs/rxgen_consts.h>\n");
592 }
593 }
594
595 tell = ftell(fout);
596 while (get_definition())
597 continue;
598 if (extend && tell == ftell(fout)) {
599 (void)unlink(outfilename);
600 }
601
602 Cflag = 0;
603 }
604
605 static void
606 S_output(char *infile, char *define, int extend, char *outfile, int append)
607 {
608 char *include;
609 char *outfilename;
610 char fullname[1024];
611 definition *def;
612 long tell;
613 char *currfile = (OutFileFlag ? OutFile : infile);
614
615 Sflag = 1;
616 open_input(infile, define);
617 memset(fullname, 0, sizeof(fullname));
618 if (append) {
619 strcpy(fullname, prefix);
620 strcat(fullname, infile);
621 } else
622 strcpy(fullname, infile);
623 outfilename = extend ? extendfile(fullname, outfile) : outfile;
624 open_output(infile, outfilename);
625 f_print(fout, "/* Machine generated file -- Do NOT edit */\n\n");
626 if (currfile && (include = extendfile(currfile, ".h"))) {
627 if (kflag) {
628 f_print(fout, "#include \"%s\"\n", include);
629 } else {
630 f_print(fout, "#include <afsconfig.h>\n");
631 f_print(fout, "#include <afs/param.h>\n");
632 f_print(fout, "#include <roken.h>\n");
633 f_print(fout, "#include \"%s\"\n\n", include);
634 }
635 free(include);
636 } else {
637 if (kflag) {
638 f_print(fout, "#include \"h/types.h\"\n");
639 f_print(fout, "#include \"h/socket.h\"\n");
640 f_print(fout, "#include \"h/file.h\"\n");
641 f_print(fout, "#include \"h/stat.h\"\n");
642 f_print(fout, "#include \"netinet/in.h\"\n");
643 f_print(fout, "#include \"h/time.h\"\n");
644 f_print(fout, "#include \"rx/xdr.h\"\n");
645 f_print(fout, "#include \"afs/rxgen_consts.h\"\n");
646 f_print(fout, "#include \"afs/afs_osi.h\"\n");
647 f_print(fout, "#include \"rx/rx.h\"\n");
648 if (xflag) {
649 f_print(fout, "#include \"rx/rx_globals.h\"\n");
650 }
651 if (brief_flag) {
652 f_print(fout, "#include \"rx/rx_opaque.h\"\n");
653 }
654 } else {
655 f_print(fout, "#include <sys/types.h>\n");
656 f_print(fout, "#include <rx/xdr.h>\n");
657 f_print(fout, "#include <rx/rx.h>\n");
658 if (xflag) {
659 f_print(fout, "#include <rx/rx_globals.h>\n");
660 }
661 if (brief_flag) {
662 f_print(fout, "#include <rx/rx_opaque.h>\n");
663 }
664 f_print(fout, "#include <afs/rxgen_consts.h>\n");
665 }
666 }
667
668 tell = ftell(fout);
669 fflush(fout);
670 while ((def = get_definition())) {
671 fflush(fout);
672 print_datadef(def);
673 }
674
675 er_Proc_CodeGeneration();
676
677 if (extend && tell == ftell(fout)) {
678 (void)unlink(outfilename);
679 }
680 Sflag = 0;
681 }
682
683 static char *
684 uppercase(char *str)
685 {
686 static char max_size[100];
687 char *pnt;
688 int len = (int)strlen(str);
689
690 for (pnt = max_size; len > 0; len--, str++) {
691 *pnt++ = (islower(*str) ? toupper(*str) : *str);
692 }
693 *pnt = '\0';
694 return max_size;
695 }
696
697 /*
698 * Parse command line arguments
699 */
700 static int
701 parseargs(int argc, char *argv[], struct commandline *cmd)
702 {
703 int i;
704 int j;
705 char c;
706 char flag[(1 << (8 * sizeof(char)))];
707 int nflags;
708
709 cmdname = argv[0];
710 cmd->infile = cmd->outfile = NULL;
711 if (argc < 2) {
712 return (0);
713 }
714 memset(flag, 0, sizeof(flag));
715 cmd->outfile = NULL;
716 for (i = 1; i < argc; i++) {
717 if (argv[i][0] != '-') {
718 if (cmd->infile) {
719 return (0);
720 }
721 cmd->infile = argv[i];
722 } else {
723 for (j = 1; argv[i][j] != 0; j++) {
724 c = argv[i][j];
725 switch (c) {
726 case 'A':
727 case 'c':
728 case 'h':
729 case 'C':
730 case 'S':
731 case 'b':
732 case 'r':
733 case 'k':
734 case 'p':
735 case 'd':
736 case 'u':
737 case 'x':
738 case 'y':
739 case 'z':
740 if (flag[(int)c]) {
741 return (0);
742 }
743 flag[(int)c] = 1;
744 break;
745 case 'o':
746 if (argv[i][j - 1] != '-' || argv[i][j + 1] != 0) {
747 return (0);
748 }
749 flag[(int)c] = 1;
750 if (++i == argc) {
751 return (0);
752 }
753 if (cmd->outfile) {
754 return (0);
755 }
756 cmd->outfile = argv[i];
757 goto nextarg;
758 case 'P':
759 if (argv[i][j - 1] != '-')
760 return (0);
761 prefix = &argv[i][j + 1];
762 goto nextarg;
763 case 'I':
764 if (nincludes >= MAXCPPARGS) {
765 f_print(stderr, "Too many -I arguments\n");
766 return (0);
767 }
768 if (argv[i][j - 1] != '-')
769 return (0);
770 IncludeDir[nincludes++] = &argv[i][j - 1];
771 goto nextarg;
772 default:
773 return (0);
774 }
775 }
776 nextarg:
777 ;
778 }
779 }
780 cmd->ansic_flag = ansic_flag = flag['A'];
781 cmd->brief_flag = brief_flag = flag['b'];
782 cmd->cflag = cflag = flag['c'];
783 cmd->hflag = hflag = flag['h'];
784 cmd->xflag = xflag = flag['x'];
785 cmd->yflag = yflag = flag['y'];
786 cmd->Cflag = Cflag = flag['C'];
787 cmd->Sflag = Sflag = flag['S'];
788 cmd->rflag = flag['r'];
789 cmd->uflag = uflag = flag['u'];
790 cmd->kflag = kflag = flag['k'];
791 cmd->pflag = flag['p'];
792 cmd->dflag = debug = flag['d'];
793 zflag = flag['z'];
794 if (cmd->pflag)
795 combinepackages = 1;
796 nflags =
797 cmd->cflag + cmd->hflag + cmd->Cflag + cmd->Sflag + cmd->rflag;
798 if (nflags == 0) {
799 if (cmd->outfile != NULL || cmd->infile == NULL) {
800 return (0);
801 }
802 } else if (nflags > 1) {
803 return (0);
804 }
805 return (1);
806 }