rpc_main.c (9199c09a159c4e3e98c212d4eec1edc5252d9e33) rpc_main.c (4e115012be61e89caf65497654493e52630b15e4)
1/* @(#)rpc_main.c 2.2 88/08/01 4.0 RPCSRC */
1/*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
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.
8 *
9 *
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
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.
12 *
13 *
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
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.
16 *
17 *
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
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.
20 *
21 *
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
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.
24 *
25 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California 94043
28 */
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
29 */
29
30
31#if 0
32#ifndef lint
30#ifndef lint
33#ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
34static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
31/*static char sccsid[] = "from: @(#)rpc_main.c 1.7 87/06/24 (C) 1987 SMI";*/
32static char rcsid[] = "$Id: rpc_main.c,v 1.1 1993/09/13 23:20:15 jtc Exp $";
35#endif
33#endif
36#endif
37
34
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD$");
40
41/*
35/*
42 * rpc_main.c, Top level of the RPC protocol compiler.
43 * Copyright (C) 1987, Sun Microsystems, Inc.
36 * rpc_main.c, Top level of the RPC protocol compiler.
37 * Copyright (C) 1987, Sun Microsystems, Inc.
44 */
45
38 */
39
46#include <err.h>
47#include <ctype.h>
48#include <stdio.h>
40#include <stdio.h>
49#include <string.h>
50#include <unistd.h>
51#include <sys/types.h>
52#include <sys/param.h>
41#include <strings.h>
53#include <sys/file.h>
42#include <sys/file.h>
54#include <sys/stat.h>
43#include "rpc_util.h"
55#include "rpc_parse.h"
56#include "rpc_scan.h"
44#include "rpc_parse.h"
45#include "rpc_scan.h"
57#include "rpc_util.h"
58
46
59static void c_output(const char *, const char *, int, const char *);
60static void h_output(const char *, const char *, int, const char *, int);
61static void l_output(const char *, const char *, int, const char *);
62static void t_output(const char *, const char *, int, const char *);
63static void clnt_output(const char *, const char *, int, const char * );
64static char *generate_guard(const char *);
65static void c_initialize(void);
47#define EXTEND 1 /* alias for TRUE */
66
48
67#if !defined(__FreeBSD__) && !defined(__NetBSD__)
68char * rindex();
69#endif
49struct commandline {
50 int cflag;
51 int hflag;
52 int lflag;
53 int sflag;
54 int mflag;
55 char *infile;
56 char *outfile;
57};
70
58
71static void usage(void);
72static void options_usage(void);
73static int do_registers(int, const char **);
74static int parseargs(int, const char **, struct commandline *);
75static void svc_output(const char *, const char *, int, const char *);
76static void mkfile_output(struct commandline *);
77static void s_output(int, const char **, const char *, const char *, int, const char *, int, int);
78
79#define EXTEND 1 /* alias for TRUE */
80#define DONT_EXTEND 0 /* alias for FALSE */
81
82#define SVR4_CPP "/usr/ccs/lib/cpp"
83#define SUNOS_CPP "/usr/bin/cpp"
84
85static int cppDefined = 0; /* explicit path for C preprocessor */
86
87static const char *svcclosetime = "120";
88static const char *CPP = SVR4_CPP;
89static const char CPPFLAGS[] = "-C";
90static char pathbuf[MAXPATHLEN + 1];
91static const char *allv[] = {
59static char *cmdname;
60static char CPP[] = "/usr/bin/cpp";
61static char CPPFLAGS[] = "-C";
62static char *allv[] = {
92 "rpcgen", "-s", "udp", "-s", "tcp",
93};
63 "rpcgen", "-s", "udp", "-s", "tcp",
64};
94static int allc = sizeof (allv)/sizeof (allv[0]);
95static const char *allnv[] = {
96 "rpcgen", "-s", "netpath",
97};
98static int allnc = sizeof (allnv)/sizeof (allnv[0]);
65static int allc = sizeof(allv)/sizeof(allv[0]);
99
66
100/*
101 * machinations for handling expanding argument list
102 */
103static void addarg(const char *); /* add another argument to the list */
104static void putarg(int, const char *); /* put argument at specified location */
105static void clear_args(void); /* clear argument list */
106static void checkfiles(const char *, const char *);
107 /* check if out file already exists */
108
67
68static int h_output(), c_output(), s_output(), l_output(), do_registers(),
69 parseargs();
109
70
71main(argc, argv)
72 int argc;
73 char *argv[];
110
74
111#define ARGLISTLEN 20
112#define FIXEDARGS 2
113
114static char *arglist[ARGLISTLEN];
115static int argcount = FIXEDARGS;
116
117
118int nonfatalerrors; /* errors */
119int inetdflag = 0; /* Support for inetd is disabled by default, use -I */
120int pmflag = 0; /* Support for port monitors is disabled by default */
121int tirpc_socket = 1; /* TI-RPC on socket, no TLI library */
122int logflag; /* Use syslog instead of fprintf for errors */
123int tblflag; /* Support for dispatch table file */
124int mtflag = 0; /* Support for MT */
125
126#define INLINE 0
127/* length at which to start doing an inline */
128
129int inline_size = INLINE;
130/*
131 * Length at which to start doing an inline. INLINE = default
132 * if 0, no xdr_inline code
133 */
134
135int indefinitewait; /* If started by port monitors, hang till it wants */
136int exitnow; /* If started by port monitors, exit after the call */
137int timerflag; /* TRUE if !indefinite && !exitnow */
138int newstyle; /* newstyle of passing arguments (by value) */
139int CCflag = 0; /* C++ files */
140static int allfiles; /* generate all files */
141int tirpcflag = 1; /* generating code for tirpc, by default */
142xdrfunc *xdrfunc_head = NULL; /* xdr function list */
143xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
144pid_t childpid;
145
146
147int
148main(int argc, const char *argv[])
149{
150 struct commandline cmd;
151
75{
76 struct commandline cmd;
77
152 (void) memset((char *)&cmd, 0, sizeof (struct commandline));
153 clear_args();
154 if (!parseargs(argc, argv, &cmd))
155 usage();
156 /*
157 * Only the client and server side stubs are likely to be customized,
158 * so in that case only, check if the outfile exists, and if so,
159 * print an error message and exit.
160 */
161 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
162 checkfiles(cmd.infile, cmd.outfile);
78 if (!parseargs(argc, argv, &cmd)) {
79 f_print(stderr,
80 "usage: %s infile\n", cmdname);
81 f_print(stderr,
82 " %s [-c | -h | -l | -m] [-o outfile] [infile]\n",
83 cmdname);
84 f_print(stderr,
85 " %s [-s udp|tcp]* [-o outfile] [infile]\n",
86 cmdname);
87 exit(1);
163 }
88 }
164 else
165 checkfiles(cmd.infile, NULL);
166
167 if (cmd.cflag) {
89 if (cmd.cflag) {
168 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
90 c_output(cmd.infile, "-DRPC_XDR", !EXTEND, cmd.outfile);
169 } else if (cmd.hflag) {
91 } else if (cmd.hflag) {
170 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile,
171 cmd.hflag);
92 h_output(cmd.infile, "-DRPC_HDR", !EXTEND, cmd.outfile);
172 } else if (cmd.lflag) {
93 } else if (cmd.lflag) {
173 l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
174 } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
175 s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
176 cmd.outfile, cmd.mflag, cmd.nflag);
177 } else if (cmd.tflag) {
178 t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
179 } else if (cmd.Ssflag) {
180 svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
181 cmd.outfile);
182 } else if (cmd.Scflag) {
183 clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
184 cmd.outfile);
185 } else if (cmd.makefileflag) {
186 mkfile_output(&cmd);
94 l_output(cmd.infile, "-DRPC_CLNT", !EXTEND, cmd.outfile);
95 } else if (cmd.sflag || cmd.mflag) {
96 s_output(argc, argv, cmd.infile, "-DRPC_SVC", !EXTEND,
97 cmd.outfile, cmd.mflag);
187 } else {
98 } else {
188 /* the rescans are required, since cpp may effect input */
189 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
190 reinitialize();
99 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
100 reinitialize();
191 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h", cmd.hflag);
101 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
192 reinitialize();
193 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
194 reinitialize();
102 reinitialize();
103 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
104 reinitialize();
195 if (inetdflag || !tirpcflag)
196 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
197 "_svc.c", cmd.mflag, cmd.nflag);
198 else
199 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
200 EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
201 if (tblflag) {
202 reinitialize();
203 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
204 }
205
206 if (allfiles) {
207 reinitialize();
208 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
209 "_server.c");
210 reinitialize();
211 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
212 "_client.c");
213
214 }
215 if (allfiles || (cmd.makefileflag == 1)){
216 reinitialize();
217 mkfile_output(&cmd);
218 }
219
105 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
106 "_svc.c", cmd.mflag);
220 }
107 }
221 exit(nonfatalerrors);
222 /* NOTREACHED */
108 exit(0);
223}
224
109}
110
225
226/*
111/*
227 * add extension to filename
112 * add extension to filename
228 */
229static char *
113 */
114static char *
230extendfile(const char *path, const char *ext)
115extendfile(file, ext)
116 char *file;
117 char *ext;
231{
232 char *res;
118{
119 char *res;
233 const char *p;
234 const char *file;
120 char *p;
235
121
236 if ((file = rindex(path, '/')) == NULL)
237 file = path;
238 else
239 file++;
240 res = xmalloc(strlen(file) + strlen(ext) + 1);
241 p = strrchr(file, '.');
122 res = alloc(strlen(file) + strlen(ext) + 1);
123 if (res == NULL) {
124 abort();
125 }
126 p = rindex(file, '.');
242 if (p == NULL) {
243 p = file + strlen(file);
244 }
245 (void) strcpy(res, file);
246 (void) strcpy(res + (p - file), ext);
247 return (res);
248}
249
250/*
127 if (p == NULL) {
128 p = file + strlen(file);
129 }
130 (void) strcpy(res, file);
131 (void) strcpy(res + (p - file), ext);
132 return (res);
133}
134
135/*
251 * Open output file with given extension
136 * Open output file with given extension
252 */
137 */
253static void
254open_output(const char *infile, const char *outfile)
138static
139open_output(infile, outfile)
140 char *infile;
141 char *outfile;
255{
142{
256
257 if (outfile == NULL) {
258 fout = stdout;
259 return;
260 }
143 if (outfile == NULL) {
144 fout = stdout;
145 return;
146 }
261
262 if (infile != NULL && streq(outfile, infile)) {
147 if (infile != NULL && streq(outfile, infile)) {
263 warnx("%s already exists. No output generated", infile);
148 f_print(stderr, "%s: output would overwrite %s\n", cmdname,
149 infile);
264 crash();
265 }
266 fout = fopen(outfile, "w");
267 if (fout == NULL) {
150 crash();
151 }
152 fout = fopen(outfile, "w");
153 if (fout == NULL) {
268 warn("unable to open %s", outfile);
154 f_print(stderr, "%s: unable to open ", cmdname);
155 perror(outfile);
269 crash();
270 }
271 record_open(outfile);
156 crash();
157 }
158 record_open(outfile);
272
273 return;
274}
275
159}
160
276static void
277add_warning(void)
278{
279 f_print(fout, "/*\n");
280 f_print(fout, " * Please do not edit this file.\n");
281 f_print(fout, " * It was generated using rpcgen.\n");
282 f_print(fout, " */\n\n");
283}
284
285/* clear list of arguments */
286static void
287clear_args(void)
288{
289 int i;
290 for (i = FIXEDARGS; i < ARGLISTLEN; i++)
291 arglist[i] = NULL;
292 argcount = FIXEDARGS;
293}
294
295/* make sure that a CPP exists */
296static void
297find_cpp(void)
298{
299 struct stat buf;
300
301 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
302 if (cppDefined) {
303 warnx("cannot find C preprocessor: %s", CPP);
304 crash();
305 } else { /* try the other one */
306 CPP = SUNOS_CPP;
307 if (stat(CPP, &buf) < 0) { /* can't find any cpp */
308 warnx("cannot find C preprocessor: %s", CPP);
309 crash();
310 }
311 }
312 }
313}
314
315/*
161/*
316 * Open input file with given define for C-preprocessor
162 * Open input file with given define for C-preprocessor
317 */
163 */
318static void
319open_input(const char *infile, const char *define)
164static
165open_input(infile, define)
166 char *infile;
167 char *define;
320{
321 int pd[2];
322
323 infilename = (infile == NULL) ? "<stdin>" : infile;
324 (void) pipe(pd);
168{
169 int pd[2];
170
171 infilename = (infile == NULL) ? "<stdin>" : infile;
172 (void) pipe(pd);
325 switch (childpid = fork()) {
173 switch (fork()) {
326 case 0:
174 case 0:
327 find_cpp();
328 putarg(0, CPP);
329 putarg(1, CPPFLAGS);
330 addarg(define);
331 if (infile)
332 addarg(infile);
333 addarg((char *)NULL);
334 (void) close(1);
335 (void) dup2(pd[1], 1);
336 (void) close(pd[0]);
175 (void) close(1);
176 (void) dup2(pd[1], 1);
177 (void) close(pd[0]);
337 execv(arglist[0], arglist);
338 err(1, "execv");
178 execl(CPP, CPP, CPPFLAGS, define, infile, NULL);
179 perror("execl");
180 exit(1);
339 case -1:
181 case -1:
340 err(1, "fork");
182 perror("fork");
183 exit(1);
341 }
342 (void) close(pd[1]);
343 fin = fdopen(pd[0], "r");
344 if (fin == NULL) {
184 }
185 (void) close(pd[1]);
186 fin = fdopen(pd[0], "r");
187 if (fin == NULL) {
345 warn("%s", infilename);
188 f_print(stderr, "%s: ", cmdname);
189 perror(infilename);
346 crash();
347 }
348}
349
190 crash();
191 }
192}
193
350/* valid tirpc nettypes */
351static const char *valid_ti_nettypes[] =
194/*
195 * Compile into an XDR routine output file
196 */
197static
198c_output(infile, define, extend, outfile)
199 char *infile;
200 char *define;
201 int extend;
202 char *outfile;
352{
203{
353 "netpath",
354 "visible",
355 "circuit_v",
356 "datagram_v",
357 "circuit_n",
358 "datagram_n",
359 "udp",
360 "tcp",
361 "raw",
362 NULL
363 };
364
365/* valid inetd nettypes */
366static const char *valid_i_nettypes[] =
367{
368 "udp",
369 "tcp",
370 NULL
371 };
372
373static int
374check_nettype(const char *name, const char *list_to_check[])
375{
376 int i;
377 for (i = 0; list_to_check[i] != NULL; i++) {
378 if (strcmp(name, list_to_check[i]) == 0) {
379 return (1);
380 }
381 }
382 warnx("illegal nettype :\'%s\'", name);
383 return (0);
384}
385
386static const char *
387file_name(const char *file, const char *ext)
388{
389 char *temp;
390 temp = extendfile(file, ext);
391
392 if (access(temp, F_OK) != -1)
393 return (temp);
394 else
395 return (" ");
396
397}
398
399
400static void
401c_output(const char *infile, const char *define, int extend, const char *outfile)
402{
403 definition *def;
404 char *include;
204 definition *def;
205 char *include;
405 const char *outfilename;
206 char *outfilename;
406 long tell;
407
207 long tell;
208
408 c_initialize();
409 open_input(infile, define);
209 open_input(infile, define);
410 outfilename = extend ? extendfile(infile, outfile) : outfile;
411 open_output(infile, outfilename);
210 outfilename = extend ? extendfile(infile, outfile) : outfile;
211 open_output(infile, outfilename);
412 add_warning();
212 f_print(fout, "#include <rpc/rpc.h>\n");
413 if (infile && (include = extendfile(infile, ".h"))) {
414 f_print(fout, "#include \"%s\"\n", include);
415 free(include);
213 if (infile && (include = extendfile(infile, ".h"))) {
214 f_print(fout, "#include \"%s\"\n", include);
215 free(include);
416 /* .h file already contains rpc/rpc.h */
417 } else
418 f_print(fout, "#include <rpc/rpc.h>\n");
216 }
419 tell = ftell(fout);
217 tell = ftell(fout);
420 while ( (def = get_definition()) ) {
218 while (def = get_definition()) {
421 emit(def);
422 }
423 if (extend && tell == ftell(fout)) {
424 (void) unlink(outfilename);
425 }
426}
427
219 emit(def);
220 }
221 if (extend && tell == ftell(fout)) {
222 (void) unlink(outfilename);
223 }
224}
225
428
429void
430c_initialize(void)
431{
432
433 /* add all the starting basic types */
434 add_type(1, "int");
435 add_type(1, "long");
436 add_type(1, "short");
437 add_type(1, "bool");
438 add_type(1, "u_int");
439 add_type(1, "u_long");
440 add_type(1, "u_short");
441
442}
443
444const char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
445 char *(*proc)(); \n\
446 xdrproc_t xdr_arg; \n\
447 unsigned len_arg; \n\
448 xdrproc_t xdr_res; \n\
449 unsigned len_res; \n\
450}; \n";
451
452
453char *
454generate_guard(const char *pathname)
455{
456 const char *filename;
457 char *guard, *tmp, *stopat;
458
459 filename = strrchr(pathname, '/'); /* find last component */
460 filename = ((filename == 0) ? pathname : filename+1);
461 guard = xstrdup(filename);
462 stopat = strrchr(guard, '.');
463
464 /*
465 * Convert to a valid C macro name and make it upper case.
466 * Map macro unfriendly characterss to '_'.
467 */
468 for (tmp = guard; *tmp != '\000'; ++tmp) {
469 if (islower(*tmp))
470 *tmp = toupper(*tmp);
471 else if (isupper(*tmp) || *tmp == '_')
472 /* OK for C */;
473 else if (tmp == guard)
474 *tmp = '_';
475 else if (isdigit(*tmp))
476 /* OK for all but first character */;
477 else if (tmp == stopat) {
478 *tmp = '\0';
479 break;
480 } else
481 *tmp = '_';
482 }
483 /*
484 * Can't have a '_' in front, because it'll end up being "__".
485 * "__" macros shoudln't be used. So, remove all of the
486 * '_' characters from the front.
487 */
488 if (*guard == '_') {
489 for (tmp = guard; *tmp == '_'; ++tmp)
490 ;
491 strcpy(guard, tmp);
492 }
493 guard = extendfile(guard, "_H_RPCGEN");
494 return (guard);
495}
496
497/*
498 * Compile into an XDR header file
499 */
226/*
227 * Compile into an XDR header file
228 */
500
501
502static void
503h_output(const char *infile, const char *define, int extend, const char *outfile, int headeronly)
229static
230h_output(infile, define, extend, outfile)
231 char *infile;
232 char *define;
233 int extend;
234 char *outfile;
504{
505 definition *def;
235{
236 definition *def;
506 const char *outfilename;
237 char *outfilename;
507 long tell;
238 long tell;
508 const char *guard;
509 list *l;
510 xdrfunc *xdrfuncp;
511
512 open_input(infile, define);
513 outfilename = extend ? extendfile(infile, outfile) : outfile;
514 open_output(infile, outfilename);
239
240 open_input(infile, define);
241 outfilename = extend ? extendfile(infile, outfile) : outfile;
242 open_output(infile, outfilename);
515 add_warning();
516 if (outfilename || infile){
517 guard = generate_guard(outfilename ? outfilename: infile);
518 } else
519 guard = "STDIN_";
520
521 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
522 guard);
523
524 f_print(fout, "#include <rpc/rpc.h>\n");
525
526 if (mtflag)
527 f_print(fout, "#include <pthread.h>\n");
528
529 /* put the C++ support */
530 if (!CCflag) {
531 f_print(fout, "\n#ifdef __cplusplus\n");
532 f_print(fout, "extern \"C\" {\n");
533 f_print(fout, "#endif\n\n");
534 }
535
536 /* put in a typedef for quadprecision. Only with Cflag */
537
538 tell = ftell(fout);
243 tell = ftell(fout);
539
540 /* print data definitions */
541 while ( (def = get_definition()) ) {
542 print_datadef(def, headeronly);
244 while (def = get_definition()) {
245 print_datadef(def);
543 }
246 }
544
545 /*
546 * print function declarations.
547 * Do this after data definitions because they might be used as
548 * arguments for functions
549 */
550 for (l = defined; l != NULL; l = l->next) {
551 print_funcdef(l->val, headeronly);
552 }
553 /* Now print all xdr func declarations */
554 if (xdrfunc_head != NULL){
555
556 f_print(fout,
557 "\n/* the xdr functions */\n");
558
559 if (CCflag){
560 f_print(fout, "\n#ifdef __cplusplus\n");
561 f_print(fout, "extern \"C\" {\n");
562 f_print(fout, "#endif\n");
563 }
564
565 xdrfuncp = xdrfunc_head;
566 while (xdrfuncp != NULL){
567 print_xdr_func_def(xdrfuncp->name, xdrfuncp->pointerp);
568 xdrfuncp = xdrfuncp->next;
569 }
570 }
571
572 if (extend && tell == ftell(fout)) {
573 (void) unlink(outfilename);
247 if (extend && tell == ftell(fout)) {
248 (void) unlink(outfilename);
574 } else if (tblflag) {
575 f_print(fout, rpcgen_table_dcl);
576 }
249 }
577
578 f_print(fout, "\n#ifdef __cplusplus\n");
579 f_print(fout, "}\n");
580 f_print(fout, "#endif\n");
581
582 f_print(fout, "\n#endif /* !_%s */\n", guard);
583}
584
585/*
586 * Compile into an RPC service
587 */
250}
251
252/*
253 * Compile into an RPC service
254 */
588static void
589s_output(int argc, const char *argv[], const char *infile, const char *define,
590 int extend, const char *outfile, int nomain, int netflag)
255static
256s_output(argc, argv, infile, define, extend, outfile, nomain)
257 int argc;
258 char *argv[];
259 char *infile;
260 char *define;
261 int extend;
262 char *outfile;
263 int nomain;
591{
592 char *include;
593 definition *def;
264{
265 char *include;
266 definition *def;
594 int foundprogram = 0;
595 const char *outfilename;
267 int foundprogram;
268 char *outfilename;
596
597 open_input(infile, define);
598 outfilename = extend ? extendfile(infile, outfile) : outfile;
599 open_output(infile, outfilename);
269
270 open_input(infile, define);
271 outfilename = extend ? extendfile(infile, outfile) : outfile;
272 open_output(infile, outfilename);
600 add_warning();
273 f_print(fout, "#include <stdio.h>\n");
274 f_print(fout, "#include <rpc/rpc.h>\n");
601 if (infile && (include = extendfile(infile, ".h"))) {
602 f_print(fout, "#include \"%s\"\n", include);
603 free(include);
275 if (infile && (include = extendfile(infile, ".h"))) {
276 f_print(fout, "#include \"%s\"\n", include);
277 free(include);
604 } else
605 f_print(fout, "#include <rpc/rpc.h>\n");
606
607 f_print(fout, "#include <stdio.h>\n");
608 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
609 f_print (fout, "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
610 f_print (fout, "#include <string.h> /* strcmp */\n");
611 if (tirpcflag)
612 f_print(fout, "#include <rpc/rpc_com.h>\n");
613 if (strcmp(svcclosetime, "-1") == 0)
614 indefinitewait = 1;
615 else if (strcmp(svcclosetime, "0") == 0)
616 exitnow = 1;
617 else if (inetdflag || pmflag) {
618 f_print(fout, "#include <signal.h>\n");
619 timerflag = 1;
620 }
278 }
621
622 if (!tirpcflag && inetdflag)
623 f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
624 if (inetdflag || pmflag) {
625 f_print(fout, "#ifdef __cplusplus\n");
626 f_print(fout,
627 "#include <sys/sysent.h> /* getdtablesize, open */\n");
628 f_print(fout, "#endif /* __cplusplus */\n");
629 }
630 if (tirpcflag) {
631 f_print(fout, "#include <fcntl.h> /* open */\n");
632 f_print(fout, "#include <unistd.h> /* fork / setsid */\n");
633 f_print(fout, "#include <sys/types.h>\n");
634 }
635
636 f_print(fout, "#include <string.h>\n");
637 if (inetdflag || !tirpcflag) {
638 f_print(fout, "#include <sys/socket.h>\n");
639 f_print(fout, "#include <netinet/in.h>\n");
640 }
641
642 if ((netflag || pmflag) && tirpcflag && !nomain) {
643 f_print(fout, "#include <netconfig.h>\n");
644 }
645 if (tirpcflag)
646 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
647 if (logflag || inetdflag || pmflag || tirpcflag)
648 f_print(fout, "#include <syslog.h>\n");
649
650 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
651 if (timerflag)
652 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
653 svcclosetime);
654 while ( (def = get_definition()) ) {
279 foundprogram = 0;
280 while (def = get_definition()) {
655 foundprogram |= (def->def_kind == DEF_PROGRAM);
656 }
657 if (extend && !foundprogram) {
658 (void) unlink(outfilename);
659 return;
660 }
281 foundprogram |= (def->def_kind == DEF_PROGRAM);
282 }
283 if (extend && !foundprogram) {
284 (void) unlink(outfilename);
285 return;
286 }
661 write_most(infile, netflag, nomain);
662 if (!nomain) {
663 if (!do_registers(argc, argv)) {
664 if (outfilename)
665 (void) unlink(outfilename);
666 usage();
667 }
287 if (nomain) {
288 write_programs((char *)NULL);
289 } else {
290 write_most();
291 do_registers(argc, argv);
668 write_rest();
292 write_rest();
293 write_programs("static");
669 }
670}
671
294 }
295}
296
672/*
673 * generate client side stubs
674 */
675static void
676l_output(const char *infile, const char *define, int extend, const char *outfile)
297static
298l_output(infile, define, extend, outfile)
299 char *infile;
300 char *define;
301 int extend;
302 char *outfile;
677{
678 char *include;
679 definition *def;
303{
304 char *include;
305 definition *def;
680 int foundprogram = 0;
681 const char *outfilename;
306 int foundprogram;
307 char *outfilename;
682
683 open_input(infile, define);
684 outfilename = extend ? extendfile(infile, outfile) : outfile;
685 open_output(infile, outfilename);
308
309 open_input(infile, define);
310 outfilename = extend ? extendfile(infile, outfile) : outfile;
311 open_output(infile, outfilename);
686 add_warning();
687 f_print (fout, "#include <string.h> /* for memset */\n");
312 f_print(fout, "#include <rpc/rpc.h>\n");
688 if (infile && (include = extendfile(infile, ".h"))) {
689 f_print(fout, "#include \"%s\"\n", include);
690 free(include);
313 if (infile && (include = extendfile(infile, ".h"))) {
314 f_print(fout, "#include \"%s\"\n", include);
315 free(include);
691 } else
692 f_print(fout, "#include <rpc/rpc.h>\n");
693 while ( (def = get_definition()) ) {
316 }
317 foundprogram = 0;
318 while (def = get_definition()) {
694 foundprogram |= (def->def_kind == DEF_PROGRAM);
695 }
696 if (extend && !foundprogram) {
697 (void) unlink(outfilename);
698 return;
699 }
700 write_stubs();
701}
702
703/*
319 foundprogram |= (def->def_kind == DEF_PROGRAM);
320 }
321 if (extend && !foundprogram) {
322 (void) unlink(outfilename);
323 return;
324 }
325 write_stubs();
326}
327
328/*
704 * generate the dispatch table
329 * Perform registrations for service output
705 */
330 */
706static void
707t_output(const char *infile, const char *define, int extend, const char *outfile)
708{
709 definition *def;
710 int foundprogram = 0;
711 const char *outfilename;
331static
332do_registers(argc, argv)
333 int argc;
334 char *argv[];
712
335
713 open_input(infile, define);
714 outfilename = extend ? extendfile(infile, outfile) : outfile;
715 open_output(infile, outfilename);
716 add_warning();
717 while ( (def = get_definition()) ) {
718 foundprogram |= (def->def_kind == DEF_PROGRAM);
719 }
720 if (extend && !foundprogram) {
721 (void) unlink(outfilename);
722 return;
723 }
724 write_tables();
725}
726
727/* sample routine for the server template */
728static void
729svc_output(const char *infile, const char *define, int extend, const char *outfile)
730{
336{
731 definition *def;
732 char *include;
733 const char *outfilename;
734 long tell;
735 open_input(infile, define);
736 outfilename = extend ? extendfile(infile, outfile) : outfile;
737 checkfiles(infile, outfilename);
738 /*
739 * Check if outfile already exists.
740 * if so, print an error message and exit
741 */
742 open_output(infile, outfilename);
743 add_sample_msg();
744
745 if (infile && (include = extendfile(infile, ".h"))) {
746 f_print(fout, "#include \"%s\"\n", include);
747 free(include);
748 } else
749 f_print(fout, "#include <rpc/rpc.h>\n");
750
751 tell = ftell(fout);
752 while ( (def = get_definition()) ) {
753 write_sample_svc(def);
754 }
755 if (extend && tell == ftell(fout)) {
756 (void) unlink(outfilename);
757 }
758}
759
760/* sample main routine for client */
761static void
762clnt_output(const char *infile, const char *define, int extend, const char *outfile)
763{
764 definition *def;
765 char *include;
766 const char *outfilename;
767 long tell;
768 int has_program = 0;
769
770 open_input(infile, define);
771 outfilename = extend ? extendfile(infile, outfile) : outfile;
772 checkfiles(infile, outfilename);
773 /*
774 * Check if outfile already exists.
775 * if so, print an error message and exit
776 */
777
778 open_output(infile, outfilename);
779 add_sample_msg();
780 if (infile && (include = extendfile(infile, ".h"))) {
781 f_print(fout, "#include \"%s\"\n", include);
782 free(include);
783 } else
784 f_print(fout, "#include <rpc/rpc.h>\n");
785 tell = ftell(fout);
786 while ( (def = get_definition()) ) {
787 has_program += write_sample_clnt(def);
788 }
789
790 if (has_program)
791 write_sample_clnt_main();
792
793 if (extend && tell == ftell(fout)) {
794 (void) unlink(outfilename);
795 }
796}
797
798
799static void mkfile_output(struct commandline *cmd)
800{
801 const char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
802 const char *servername, *svcname, *servprogname, *clntprogname;
803 char *temp, *mkftemp;
804
805 svcname = file_name(cmd->infile, "_svc.c");
806 clntname = file_name(cmd->infile, "_clnt.c");
807 xdrname = file_name(cmd->infile, "_xdr.c");
808 hdrname = file_name(cmd->infile, ".h");
809
810
811 if (allfiles){
812 servername = extendfile(cmd->infile, "_server.c");
813 clientname = extendfile(cmd->infile, "_client.c");
814 }else{
815 servername = " ";
816 clientname = " ";
817 }
818 servprogname = extendfile(cmd->infile, "_server");
819 clntprogname = extendfile(cmd->infile, "_client");
820
821 if (allfiles){
822 mkftemp = xmalloc(strlen("makefile.") +
823 strlen(cmd->infile) + 1);
824 temp = (char *)rindex(cmd->infile, '.');
825 strcpy(mkftemp, "makefile.");
826 (void) strncat(mkftemp, cmd->infile,
827 (temp - cmd->infile));
828 mkfilename = mkftemp;
829 } else
830 mkfilename = cmd->outfile;
831
832
833 checkfiles(NULL, mkfilename);
834 open_output(NULL, mkfilename);
835
836 f_print(fout, "\n# This is a template makefile generated\
837 by rpcgen \n");
838
839 f_print(fout, "\n# Parameters \n\n");
840
841 f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
842 clntprogname, servprogname);
843 f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
844 f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
845 f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
846 f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
847 svcname, servername, xdrname);
848 f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
849 clntname, clientname, xdrname);
850 f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
851 hdrname, xdrname, clntname,
852 svcname, clientname, servername);
853
854 f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
855$(TARGETS_CLNT.c:%%.c=%%.o) ");
856
857 f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
858$(TARGETS_SVC.c:%%.c=%%.o) ");
859
860
861 f_print(fout, "\n# Compiler flags \n");
862 if (mtflag)
863 f_print(fout, "\nCFLAGS += -D_REENTRANT -D_THEAD_SAFE \nLDLIBS += -pthread\n");
864
865 f_print(fout, "RPCGENFLAGS = \n");
866
867 f_print(fout, "\n# Targets \n\n");
868
869 f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
870 f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
871 f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
872 f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
873$(TARGETS_CLNT.c) \n\n");
874
875 f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
876$(TARGETS_SVC.c) \n\n");
877 f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
878 f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
879$(LDLIBS) \n\n");
880 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
881 f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
882 f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \
883$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
884}
885
886
887
888/*
889 * Perform registrations for service output
890 * Return 0 if failed; 1 otherwise.
891 */
892static int
893do_registers(int argc, const char *argv[])
894{
895 int i;
896
337 int i;
338
897 if (inetdflag || !tirpcflag) {
898 for (i = 1; i < argc; i++) {
899 if (streq(argv[i], "-s")) {
900 if (!check_nettype(argv[i + 1],
901 valid_i_nettypes))
902 return (0);
903 write_inetd_register(argv[i + 1]);
904 i++;
905 }
339 for (i = 1; i < argc; i++) {
340 if (streq(argv[i], "-s")) {
341 write_register(argv[i + 1]);
342 i++;
906 }
343 }
907 } else {
908 for (i = 1; i < argc; i++)
909 if (streq(argv[i], "-s")) {
910 if (!check_nettype(argv[i + 1],
911 valid_ti_nettypes))
912 return (0);
913 write_nettype_register(argv[i + 1]);
914 i++;
915 } else if (streq(argv[i], "-n")) {
916 write_netid_register(argv[i + 1]);
917 i++;
918 }
919 }
344 }
920 return (1);
921}
922
923/*
345}
346
347/*
924 * Add another argument to the arg list
348 * Parse command line arguments
925 */
349 */
926static void
927addarg(const char *cp)
928{
929 if (argcount >= ARGLISTLEN) {
930 warnx("too many defines");
931 crash();
932 /*NOTREACHED*/
933 }
934 if (cp != NULL)
935 arglist[argcount++] = xstrdup(cp);
936 else
937 arglist[argcount++] = NULL;
350static
351parseargs(argc, argv, cmd)
352 int argc;
353 char *argv[];
354 struct commandline *cmd;
938
355
939}
940
941static void
942putarg(int place, const char *cp)
943{
356{
944 if (place >= ARGLISTLEN) {
945 warnx("arglist coding error");
946 crash();
947 /*NOTREACHED*/
948 }
949 if (cp != NULL)
950 arglist[place] = xstrdup(cp);
951 else
952 arglist[place] = NULL;
953}
954
955/*
956 * if input file is stdin and an output file is specified then complain
957 * if the file already exists. Otherwise the file may get overwritten
958 * If input file does not exist, exit with an error
959 */
960
961static void
962checkfiles(const char *infile, const char *outfile)
963{
964
965 struct stat buf;
966
967 if (infile) /* infile ! = NULL */
968 if (stat(infile, &buf) < 0)
969 {
970 warn("%s", infile);
971 crash();
972 };
973 if (outfile) {
974 if (stat(outfile, &buf) < 0)
975 return; /* file does not exist */
976 else {
977 warnx("file '%s' already exists and may be overwritten", outfile);
978 crash();
979 }
980 }
981}
982
983/*
984 * Parse command line arguments
985 */
986static int
987parseargs(int argc, const char *argv[], struct commandline *cmd)
988{
989 int i;
990 int j;
357 int i;
358 int j;
991 char c, ch;
992 char flag[(1 << 8 * sizeof (char))];
359 char c;
360 char flag[(1 << 8 * sizeof(char))];
993 int nflags;
994
361 int nflags;
362
363 cmdname = argv[0];
995 cmd->infile = cmd->outfile = NULL;
996 if (argc < 2) {
997 return (0);
998 }
364 cmd->infile = cmd->outfile = NULL;
365 if (argc < 2) {
366 return (0);
367 }
999 allfiles = 0;
1000 flag['c'] = 0;
1001 flag['h'] = 0;
368 flag['c'] = 0;
369 flag['h'] = 0;
370 flag['s'] = 0;
371 flag['o'] = 0;
1002 flag['l'] = 0;
1003 flag['m'] = 0;
372 flag['l'] = 0;
373 flag['m'] = 0;
1004 flag['o'] = 0;
1005 flag['s'] = 0;
1006 flag['n'] = 0;
1007 flag['t'] = 0;
1008 flag['S'] = 0;
1009 flag['C'] = 0;
1010 flag['M'] = 0;
1011
1012 for (i = 1; i < argc; i++) {
1013 if (argv[i][0] != '-') {
1014 if (cmd->infile) {
374 for (i = 1; i < argc; i++) {
375 if (argv[i][0] != '-') {
376 if (cmd->infile) {
1015 warnx("cannot specify more than one input file");
1016 return (0);
1017 }
1018 cmd->infile = argv[i];
1019 } else {
1020 for (j = 1; argv[i][j] != 0; j++) {
1021 c = argv[i][j];
1022 switch (c) {
377 return (0);
378 }
379 cmd->infile = argv[i];
380 } else {
381 for (j = 1; argv[i][j] != 0; j++) {
382 c = argv[i][j];
383 switch (c) {
1023 case 'a':
1024 allfiles = 1;
1025 break;
1026 case 'c':
1027 case 'h':
1028 case 'l':
1029 case 'm':
384 case 'c':
385 case 'h':
386 case 'l':
387 case 'm':
1030 case 't':
1031 if (flag[(int)c]) {
388 if (flag[c]) {
1032 return (0);
1033 }
389 return (0);
390 }
1034 flag[(int)c] = 1;
391 flag[c] = 1;
1035 break;
392 break;
1036 case 'S':
1037 /*
1038 * sample flag: Ss or Sc.
1039 * Ss means set flag['S'];
1040 * Sc means set flag['C'];
1041 * Sm means set flag['M'];
1042 */
1043 ch = argv[i][++j]; /* get next char */
1044 if (ch == 's')
1045 ch = 'S';
1046 else if (ch == 'c')
1047 ch = 'C';
1048 else if (ch == 'm')
1049 ch = 'M';
1050 else
1051 return (0);
1052
1053 if (flag[(int)ch]) {
1054 return (0);
1055 }
1056 flag[(int)ch] = 1;
1057 break;
1058 case 'C': /* ANSI C syntax */
1059 ch = argv[i][j+1]; /* get next char */
1060
1061 if (ch != 'C')
1062 break;
1063 CCflag = 1;
1064 break;
1065 case 'b':
1066 /*
1067 * Turn TIRPC flag off for
1068 * generating backward compatible
1069 * code
1070 */
1071 tirpcflag = 0;
1072 break;
1073
1074 case 'I':
1075 inetdflag = 1;
1076 break;
1077 case 'N':
1078 newstyle = 1;
1079 break;
1080 case 'L':
1081 logflag = 1;
1082 break;
1083 case 'P':
1084 pmflag = 1;
1085 break;
1086 case 'K':
1087 if (++i == argc) {
1088 return (0);
1089 }
1090 svcclosetime = argv[i];
1091 goto nextarg;
1092 case 'T':
1093 tblflag = 1;
1094 break;
1095 case 'M':
1096 mtflag = 1;
1097 break;
1098 case 'i' :
1099 if (++i == argc) {
1100 return (0);
1101 }
1102 inline_size = atoi(argv[i]);
1103 goto nextarg;
1104 case 'n':
1105 case 'o':
1106 case 's':
393 case 'o':
394 case 's':
1107 if (argv[i][j - 1] != '-' ||
395 if (argv[i][j - 1] != '-' ||
1108 argv[i][j + 1] != 0) {
1109 return (0);
1110 }
396 argv[i][j + 1] != 0) {
397 return (0);
398 }
1111 flag[(int)c] = 1;
399 flag[c] = 1;
1112 if (++i == argc) {
1113 return (0);
1114 }
400 if (++i == argc) {
401 return (0);
402 }
1115 if (c == 'o') {
403 if (c == 's') {
404 if (!streq(argv[i], "udp") &&
405 !streq(argv[i], "tcp")) {
406 return (0);
407 }
408 } else if (c == 'o') {
1116 if (cmd->outfile) {
1117 return (0);
1118 }
1119 cmd->outfile = argv[i];
1120 }
1121 goto nextarg;
409 if (cmd->outfile) {
410 return (0);
411 }
412 cmd->outfile = argv[i];
413 }
414 goto nextarg;
1122 case 'D':
1123 if (argv[i][j - 1] != '-') {
1124 return (0);
1125 }
1126 (void) addarg(argv[i]);
1127 goto nextarg;
1128 case 'Y':
1129 if (++i == argc) {
1130 return (0);
1131 }
1132 (void) strlcpy(pathbuf, argv[i], sizeof(pathbuf));
1133 if (strlcat(pathbuf, "/cpp", sizeof(pathbuf))
1134 >= sizeof(pathbuf)) {
1135 warnx("argument too long");
1136 return (0);
1137 }
1138 CPP = pathbuf;
1139 cppDefined = 1;
1140 goto nextarg;
1141
415
1142
1143
1144 default:
1145 return (0);
1146 }
1147 }
416 default:
417 return (0);
418 }
419 }
1148 nextarg:
420 nextarg:
1149 ;
1150 }
1151 }
421 ;
422 }
423 }
1152
1153 cmd->cflag = flag['c'];
1154 cmd->hflag = flag['h'];
424 cmd->cflag = flag['c'];
425 cmd->hflag = flag['h'];
426 cmd->sflag = flag['s'];
1155 cmd->lflag = flag['l'];
1156 cmd->mflag = flag['m'];
427 cmd->lflag = flag['l'];
428 cmd->mflag = flag['m'];
1157 cmd->nflag = flag['n'];
1158 cmd->sflag = flag['s'];
1159 cmd->tflag = flag['t'];
1160 cmd->Ssflag = flag['S'];
1161 cmd->Scflag = flag['C'];
1162 cmd->makefileflag = flag['M'];
1163
1164 if (tirpcflag) {
1165 if (inetdflag)
1166 pmflag = 0;
1167 if ((inetdflag && cmd->nflag)) {
1168 /* netid not allowed with inetdflag */
1169 warnx("cannot use netid flag with inetd flag");
1170 return (0);
1171 }
1172 } else { /* 4.1 mode */
1173 pmflag = 0; /* set pmflag only in tirpcmode */
1174 if (cmd->nflag) { /* netid needs TIRPC */
1175 warnx("cannot use netid flag without TIRPC");
1176 return (0);
1177 }
1178 }
1179
1180 if (newstyle && (tblflag || cmd->tflag)) {
1181 warnx("cannot use table flags with newstyle");
1182 return (0);
1183 }
1184
1185 /* check no conflicts with file generation flags */
1186 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1187 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1188 cmd->Scflag + cmd->makefileflag;
1189
429 nflags = cmd->cflag + cmd->hflag + cmd->sflag + cmd->lflag + cmd->mflag;
1190 if (nflags == 0) {
1191 if (cmd->outfile != NULL || cmd->infile == NULL) {
1192 return (0);
1193 }
430 if (nflags == 0) {
431 if (cmd->outfile != NULL || cmd->infile == NULL) {
432 return (0);
433 }
1194 } else if (cmd->infile == NULL &&
1195 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1196 warnx("\"infile\" is required for template generation flags");
434 } else if (nflags > 1) {
1197 return (0);
435 return (0);
1198 } if (nflags > 1) {
1199 warnx("cannot have more than one file generation flag");
1200 return (0);
1201 }
1202 return (1);
1203}
436 }
437 return (1);
438}
1204
1205static void
1206usage(void)
1207{
1208 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1209 "usage: rpcgen infile",
1210 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1211[-I -P [-K seconds]] [-Y path] infile",
1212 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1213[-o outfile] [infile]",
1214 " rpcgen [-s nettype]* [-o outfile] [infile]",
1215 " rpcgen [-n netid]* [-o outfile] [infile]");
1216 options_usage();
1217 exit(1);
1218}
1219
1220static void
1221options_usage(void)
1222{
1223 f_print(stderr, "options:\n");
1224 f_print(stderr, "-a\t\tgenerate all files, including samples\n");
1225 f_print(stderr, "-b\t\tbackward compatibility mode (generates code \
1226for FreeBSD 4.X)\n");
1227 f_print(stderr, "-c\t\tgenerate XDR routines\n");
1228 f_print(stderr, "-C\t\tANSI C mode\n");
1229 f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1230 f_print(stderr, "-h\t\tgenerate header file\n");
1231 f_print(stderr, "-i size\t\tsize at which to start generating\
1232inline code\n");
1233 f_print(stderr, "-I\t\tgenerate code for inetd support in server\n");
1234 f_print(stderr, "-K seconds\tserver exits after K seconds of\
1235inactivity\n");
1236 f_print(stderr, "-l\t\tgenerate client side stubs\n");
1237 f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
1238 f_print(stderr, "-m\t\tgenerate server side stubs\n");
1239 f_print(stderr, "-M\t\tgenerate MT-safe code\n");
1240 f_print(stderr, "-n netid\tgenerate server code that supports\
1241named netid\n");
1242 f_print(stderr, "-N\t\tsupports multiple arguments and\
1243call-by-value\n");
1244 f_print(stderr, "-o outfile\tname of the output file\n");
1245 f_print(stderr, "-P\t\tgenerate code for port monitoring support in server\n");
1246 f_print(stderr, "-s nettype\tgenerate server code that supports named\
1247nettype\n");
1248 f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\
1249procedures\n");
1250 f_print(stderr, "-Ss\t\tgenerate sample server code that defines\
1251remote procedures\n");
1252 f_print(stderr, "-Sm \t\tgenerate makefile template \n");
1253
1254 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
1255 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
1256 f_print(stderr, "-Y path\t\tpath where cpp is found\n");
1257 exit(1);
1258}