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