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