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