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