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.
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.
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.
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.
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.
26 * Sun Microsystems, Inc.
28 * Mountain View, California 94043
32 * From @(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI;
34 const char main_rcsid
[] =
38 * rpc_main.c, Top level of the RPC protocol compiler.
46 #include <sys/types.h>
47 #include <sys/param.h>
50 #include "rpc_parse.h"
55 #define EXTEND 1 /* alias for TRUE */
56 #define DONT_EXTEND 0 /* alias for FALSE */
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 */
75 static const char *cmdname
;
77 #define SVR4_CPP "/usr/ccs/lib/cpp"
78 #define SUNOS_CPP "/lib/cpp"
80 static const char *svcclosetime
= "120";
81 static int cppDefined
= 0; /* explicit path for C preprocessor */
82 static const char *CPP
= SUNOS_CPP
;
83 static char CPPFLAGS
[] = "-C";
85 static const char *allv
[] =
87 "rpcgen", "-s", "udp", "-s", "tcp",
89 static int allc
= sizeof (allv
) / sizeof (allv
[0]);
90 static const char *allnv
[] =
92 "rpcgen", "-s", "netpath",
94 static int allnc
= sizeof (allnv
) / sizeof (allnv
[0]);
97 * machinations for handling expanding argument list
99 static void addarg (const char *); /* add another argument to the list */
100 static void putarg (int, const char *); /* put argument at specified location */
101 static void clear_args (void); /* clear argument list */
102 static void checkfiles (const char *, const char *);
103 /* check if out file already exists */
105 static void clear_args (void);
106 static char *extendfile (const char *file
, const char *ext
);
107 static void open_output (const char *infile
, const char *outfile
);
108 static void add_warning (void);
109 static void clear_args (void);
110 static void find_cpp (void);
111 static void open_input (const char *infile
, const char *define
);
112 static int check_nettype (const char *name
, const char *list_to_check
[]);
113 static void c_output (const char *infile
, const char *define
,
114 int extend
, const char *outfile
);
115 static void h_output (const char *infile
, const char *define
,
116 int extend
, const char *outfile
);
117 static void s_output (int argc
, const char *argv
[], const char *infile
,
118 const char *define
, int extend
,
119 const char *outfile
, int nomain
, int netflag
);
120 static void l_output (const char *infile
, const char *define
,
121 int extend
, const char *outfile
);
122 static void t_output (const char *infile
, const char *define
,
123 int extend
, const char *outfile
);
124 static void svc_output (const char *infile
, const char *define
,
125 int extend
, const char *outfile
);
126 static void clnt_output (const char *infile
, const char *define
,
127 int extend
, const char *outfile
);
128 static void mkfile_output (struct commandline
*cmd
);
129 static int do_registers (int argc
, const char *argv
[]);
130 static void addarg (const char *cp
);
131 static void putarg (int whereto
, const char *cp
);
132 static void checkfiles (const char *infile
, const char *outfile
);
133 static int parseargs (int argc
, const char *argv
[], struct commandline
*cmd
);
134 static void usage (void);
135 static void options_usage (void);
136 static void c_initialize (void);
137 static char *generate_guard (const char *pathname
);
140 #define ARGLISTLEN 20
143 static const char *arglist
[ARGLISTLEN
];
144 static int argcount
= FIXEDARGS
;
147 int nonfatalerrors
; /* errors */
148 int inetdflag
/* = 1 */ ; /* Support for inetd *//* is now the default */
149 int pmflag
; /* Support for port monitors */
150 int logflag
; /* Use syslog instead of fprintf for errors */
151 int tblflag
; /* Support for dispatch table file */
152 int mtflag
; /* Support for MT */
155 /*length at which to start doing an inline */
157 int inlineflag
= INLINE
; /* length at which to start doing an inline. 3 = default
158 if 0, no xdr_inline code */
160 int indefinitewait
; /* If started by port monitors, hang till it wants */
161 int exitnow
; /* If started by port monitors, exit after the call */
162 int timerflag
; /* TRUE if !indefinite && !exitnow */
163 int newstyle
; /* newstyle of passing arguments (by value) */
164 #ifdef __GNU_LIBRARY__
165 int Cflag
= 1; /* ANSI C syntax */
167 int Cflag
= 0; /* ANSI C/C++ syntax */
169 int CCflag
= 0; /* C++ files */
170 static int allfiles
; /* generate all files */
171 #ifdef __GNU_LIBRARY__
172 int tirpcflag
= 0; /* generating code for tirpc, by default */
174 int tirpcflag
= 1; /* generating code for tirpc, by default */
176 xdrfunc
*xdrfunc_head
= NULL
; /* xdr function list */
177 xdrfunc
*xdrfunc_tail
= NULL
; /* xdr function list */
180 main (int argc
, const char *argv
[])
182 struct commandline cmd
;
184 (void) memset ((char *) &cmd
, 0, sizeof (struct commandline
));
186 if (!parseargs (argc
, argv
, &cmd
))
189 if (cmd
.cflag
|| cmd
.hflag
|| cmd
.lflag
|| cmd
.tflag
|| cmd
.sflag
||
190 cmd
.mflag
|| cmd
.nflag
|| cmd
.Ssflag
|| cmd
.Scflag
)
192 checkfiles (cmd
.infile
, cmd
.outfile
);
195 checkfiles (cmd
.infile
, NULL
);
198 c_output (cmd
.infile
, "-DRPC_XDR", DONT_EXTEND
, cmd
.outfile
);
200 h_output (cmd
.infile
, "-DRPC_HDR", DONT_EXTEND
, cmd
.outfile
);
202 l_output (cmd
.infile
, "-DRPC_CLNT", DONT_EXTEND
, cmd
.outfile
);
203 else if (cmd
.sflag
|| cmd
.mflag
|| (cmd
.nflag
))
204 s_output (argc
, argv
, cmd
.infile
, "-DRPC_SVC", DONT_EXTEND
,
205 cmd
.outfile
, cmd
.mflag
, cmd
.nflag
);
207 t_output (cmd
.infile
, "-DRPC_TBL", DONT_EXTEND
, cmd
.outfile
);
209 svc_output (cmd
.infile
, "-DRPC_SERVER", DONT_EXTEND
, cmd
.outfile
);
211 clnt_output (cmd
.infile
, "-DRPC_CLIENT", DONT_EXTEND
, cmd
.outfile
);
212 else if (cmd
.makefileflag
)
213 mkfile_output (&cmd
);
216 /* the rescans are required, since cpp may effect input */
217 c_output (cmd
.infile
, "-DRPC_XDR", EXTEND
, "_xdr.c");
219 h_output (cmd
.infile
, "-DRPC_HDR", EXTEND
, ".h");
221 l_output (cmd
.infile
, "-DRPC_CLNT", EXTEND
, "_clnt.c");
223 if (inetdflag
|| !tirpcflag
)
224 s_output (allc
, allv
, cmd
.infile
, "-DRPC_SVC", EXTEND
,
225 "_svc.c", cmd
.mflag
, cmd
.nflag
);
227 s_output (allnc
, allnv
, cmd
.infile
, "-DRPC_SVC",
228 EXTEND
, "_svc.c", cmd
.mflag
, cmd
.nflag
);
232 t_output (cmd
.infile
, "-DRPC_TBL", EXTEND
, "_tbl.i");
237 svc_output (cmd
.infile
, "-DRPC_SERVER", EXTEND
, "_server.c");
239 clnt_output (cmd
.infile
, "-DRPC_CLIENT", EXTEND
, "_client.c");
241 if (allfiles
|| (cmd
.makefileflag
== 1))
244 mkfile_output (&cmd
);
247 exit (nonfatalerrors
);
252 * add extension to filename
255 extendfile (const char *file
, const char *ext
)
260 res
= alloc (strlen (file
) + strlen (ext
) + 1);
263 p
= strrchr (file
, '.');
265 p
= file
+ strlen (file
);
267 strcpy (res
+ (p
- file
), ext
);
272 * Open output file with given extension
275 open_output (const char *infile
, const char *outfile
)
283 if (infile
!= NULL
&& streq (outfile
, infile
))
285 fprintf (stderr
, _ ("%s: output would overwrite %s\n"), cmdname
,
289 fout
= fopen (outfile
, "w");
292 fprintf (stderr
, _ ("%s: unable to open "), cmdname
);
296 record_open (outfile
);
302 fprintf (fout
, "/*\n");
303 fprintf (fout
, " * Please do not edit this file.\n");
304 fprintf (fout
, " * It was generated using rpcgen.\n");
305 fprintf (fout
, " */\n\n");
308 /* clear list of arguments */
313 for (i
= FIXEDARGS
; i
< ARGLISTLEN
; ++i
)
315 argcount
= FIXEDARGS
;
318 /* make sure that a CPP exists */
324 if (stat (CPP
, &buf
) < 0)
325 { /* /lib/cpp or explicit cpp does not exist */
328 fprintf (stderr
, _ ("cannot find C preprocessor: %s \n"), CPP
);
332 { /* try the other one */
334 if (stat (CPP
, &buf
) < 0)
335 { /* can't find any cpp */
336 fputs (_ ("cannot find any C preprocessor (cpp)\n"), stdout
);
344 * Open input file with given define for C-preprocessor
347 open_input (const char *infile
, const char *define
)
351 infilename
= (infile
== NULL
) ? "<stdin>" : infile
;
362 putarg (1, CPPFLAGS
);
366 addarg ((char *) NULL
);
370 execv (arglist
[0], (char **) arglist
);
378 fin
= fdopen (pd
[0], "r");
381 fprintf (stderr
, "%s: ", cmdname
);
387 /* valid tirpc nettypes */
388 static const char *valid_ti_nettypes
[] =
402 /* valid inetd nettypes */
403 static const char *valid_i_nettypes
[] =
411 check_nettype (const char *name
, const char *list_to_check
[])
414 for (i
= 0; list_to_check
[i
] != NULL
; i
++)
416 if (strcmp (name
, list_to_check
[i
]) == 0)
421 fprintf (stderr
, _ ("illegal nettype :\'%s\'\n"), name
);
426 * Compile into an XDR routine output file
430 c_output (const char *infile
, const char *define
, int extend
,
435 const char *outfilename
;
439 open_input (infile
, define
);
440 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
441 open_output (infile
, outfilename
);
443 if (infile
&& (include
= extendfile (infile
, ".h")))
445 fprintf (fout
, "#include \"%s\"\n", include
);
447 /* .h file already contains rpc/rpc.h */
450 fprintf (fout
, "#include <rpc/rpc.h>\n");
452 while ((def
= get_definition ()) != NULL
)
455 if (extend
&& tell
== ftell (fout
))
456 unlink (outfilename
);
463 /* add all the starting basic types */
466 add_type (1, "long");
467 add_type (1, "short");
468 add_type (1, "bool");
470 add_type (1, "u_int");
471 add_type (1, "u_long");
472 add_type (1, "u_short");
476 char rpcgen_table_dcl
[] = "struct rpcgen_table {\n\
478 xdrproc_t xdr_arg;\n\
480 xdrproc_t xdr_res;\n\
486 generate_guard (const char *pathname
)
488 const char *filename
;
491 filename
= strrchr (pathname
, '/'); /* find last component */
492 filename
= ((filename
== NULL
) ? pathname
: filename
+ 1);
493 guard
= strdup (filename
);
494 /* convert to upper case */
499 *tmp
= toupper (*tmp
);
503 guard
= extendfile (guard
, "_H_RPCGEN");
508 * Compile into an XDR header file
513 h_output (const char *infile
, const char *define
, int extend
,
518 const char *ifilename
;
519 const char *outfilename
;
524 open_input (infile
, define
);
525 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
526 open_output (infile
, outfilename
);
528 ifilename
= (infile
== NULL
) ? "STDIN" : infile
;
529 guard
= generate_guard (outfilename
? outfilename
: ifilename
);
531 fprintf (fout
, "#ifndef _%s\n#define _%s\n\n", guard
,
534 fprintf (fout
, "#include <rpc/rpc.h>\n\n");
538 fprintf (fout
, "#include <pthread.h>\n");
541 /* put the C++ support */
542 if (Cflag
&& !CCflag
)
544 fprintf (fout
, "\n#ifdef __cplusplus\n");
545 fprintf (fout
, "extern \"C\" {\n");
546 fprintf (fout
, "#endif\n\n");
550 /* print data definitions */
551 while ((def
= get_definition ()) != NULL
)
556 /* print function declarations.
557 Do this after data definitions because they might be used as
558 arguments for functions */
559 for (l
= defined
; l
!= NULL
; l
= l
->next
)
561 print_funcdef (l
->val
);
563 /* Now print all xdr func declarations */
564 if (xdrfunc_head
!= NULL
)
566 fprintf (fout
, "\n/* the xdr functions */\n");
569 fprintf (fout
, "\n#ifdef __cplusplus\n");
570 fprintf (fout
, "extern \"C\" {\n");
571 fprintf (fout
, "#endif\n");
575 xdrfuncp
= xdrfunc_head
;
576 while (xdrfuncp
!= NULL
)
578 print_xdr_func_def (xdrfuncp
->name
,
579 xdrfuncp
->pointerp
, 2);
580 xdrfuncp
= xdrfuncp
->next
;
587 for (i
= 1; i
< 3; ++i
)
590 fprintf (fout
, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
592 fprintf (fout
, "\n#else /* K&R C */\n");
594 xdrfuncp
= xdrfunc_head
;
595 while (xdrfuncp
!= NULL
)
597 print_xdr_func_def (xdrfuncp
->name
,
598 xdrfuncp
->pointerp
, i
);
599 xdrfuncp
= xdrfuncp
->next
;
602 fprintf (fout
, "\n#endif /* K&R C */\n");
606 if (extend
&& tell
== ftell (fout
))
608 unlink (outfilename
);
612 fprintf (fout
, rpcgen_table_dcl
);
617 fprintf (fout
, "\n#ifdef __cplusplus\n");
618 fprintf (fout
, "}\n");
619 fprintf (fout
, "#endif\n");
622 fprintf (fout
, "\n#endif /* !_%s */\n", guard
);
626 * Compile into an RPC service
629 s_output (int argc
, const char *argv
[], const char *infile
, const char *define
,
630 int extend
, const char *outfile
, int nomain
, int netflag
)
634 int foundprogram
= 0;
635 const char *outfilename
;
637 open_input (infile
, define
);
638 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
639 open_output (infile
, outfilename
);
641 if (infile
&& (include
= extendfile (infile
, ".h")))
643 fprintf (fout
, "#include \"%s\"\n", include
);
647 fprintf (fout
, "#include <rpc/rpc.h>\n");
649 fprintf (fout
, "#include <stdio.h>\n");
650 fprintf (fout
, "#include <stdlib.h>\n");
653 fprintf (fout
, "#include <rpc/pmap_clnt.h>\n");
654 fprintf (fout
, "#include <string.h>\n");
656 if (strcmp (svcclosetime
, "-1") == 0)
658 else if (strcmp (svcclosetime
, "0") == 0)
660 else if (inetdflag
|| pmflag
)
662 fprintf (fout
, "#include <signal.h>\n");
666 if (!tirpcflag
&& inetdflag
)
667 #ifdef __GNU_LIBRARY__
668 fprintf (fout
, "#include <sys/ioctl.h> /* ioctl, TIOCNOTTY */\n");
670 fprintf (fout
, "#include <sys/ttycom.h>/* TIOCNOTTY */\n");
672 if (Cflag
&& (inetdflag
|| pmflag
))
674 #ifdef __GNU_LIBRARY__
675 fprintf (fout
, "#include <sys/types.h> /* open */\n");
676 fprintf (fout
, "#include <sys/stat.h> /* open */\n");
677 fprintf (fout
, "#include <fcntl.h> /* open */\n");
678 fprintf (fout
, "#include <unistd.h> /* getdtablesize */\n");
680 fprintf (fout
, "#ifdef __cplusplus\n");
681 fprintf (fout
, "#include <sysent.h> /* getdtablesize, open */\n");
682 fprintf (fout
, "#endif /* __cplusplus */\n");
684 fprintf (fout
, "#include <unistd.h> /* setsid */\n");
687 #ifdef __GNU_LIBRARY__
688 if (tirpcflag
&& !(Cflag
&& (inetdflag
|| pmflag
)))
692 fprintf (fout
, "#include <sys/types.h>\n");
694 fprintf (fout
, "#include <memory.h>\n");
695 #ifndef __GNU_LIBRARY__
696 fprintf (fout
, "#include <stropts.h>\n");
698 if (inetdflag
|| !tirpcflag
)
700 fprintf (fout
, "#include <sys/socket.h>\n");
701 fprintf (fout
, "#include <netinet/in.h>\n");
704 if ((netflag
|| pmflag
) && tirpcflag
&& !nomain
)
706 fprintf (fout
, "#include <netconfig.h>\n");
708 if ( /*timerflag && */ tirpcflag
)
709 fprintf (fout
, "#include <sys/resource.h> /* rlimit */\n");
710 if (logflag
|| inetdflag
|| pmflag
)
712 #ifdef __GNU_LIBRARY__
713 fprintf (fout
, "#include <syslog.h>\n");
715 fprintf (fout
, "#ifdef SYSLOG\n");
716 fprintf (fout
, "#include <syslog.h>\n");
717 fprintf (fout
, "#else\n");
718 fprintf (fout
, "#define LOG_ERR 1\n");
719 fprintf (fout
, "#define openlog(a, b, c)\n");
720 fprintf (fout
, "#endif\n");
726 fprintf (fout
, "\n#ifndef SIG_PF\n#define SIG_PF void(*)(int)\n#endif\n");
728 #ifndef __GNU_LIBRARY__
729 fprintf (fout
, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
732 fprintf (fout
, "\n#define _RPCSVC_CLOSEDOWN %s\n", svcclosetime
);
733 while ((def
= get_definition ()) != NULL
)
735 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
737 if (extend
&& !foundprogram
)
739 unlink (outfilename
);
742 write_most (infile
, netflag
, nomain
);
745 if (!do_registers (argc
, argv
))
748 unlink (outfilename
);
756 * generate client side stubs
759 l_output (const char *infile
, const char *define
, int extend
,
764 int foundprogram
= 0;
765 const char *outfilename
;
767 open_input (infile
, define
);
768 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
769 open_output (infile
, outfilename
);
772 fprintf (fout
, "#include <memory.h> /* for memset */\n");
773 if (infile
&& (include
= extendfile (infile
, ".h")))
775 fprintf (fout
, "#include \"%s\"\n", include
);
779 fprintf (fout
, "#include <rpc/rpc.h>\n");
780 while ((def
= get_definition ()) != NULL
)
782 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
784 if (extend
&& !foundprogram
)
786 unlink (outfilename
);
793 * generate the dispatch table
796 t_output (const char *infile
, const char *define
, int extend
,
800 int foundprogram
= 0;
801 const char *outfilename
;
803 open_input (infile
, define
);
804 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
805 open_output (infile
, outfilename
);
807 while ((def
= get_definition ()) != NULL
)
809 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
811 if (extend
&& !foundprogram
)
813 unlink (outfilename
);
819 /* sample routine for the server template */
821 svc_output (const char *infile
, const char *define
, int extend
,
826 const char *outfilename
;
829 open_input (infile
, define
);
830 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
831 checkfiles (infile
, outfilename
);
832 /*check if outfile already exists.
833 if so, print an error message and exit */
834 open_output (infile
, outfilename
);
837 if (infile
&& (include
= extendfile (infile
, ".h")))
839 fprintf (fout
, "#include \"%s\"\n", include
);
843 fprintf (fout
, "#include <rpc/rpc.h>\n");
846 while ((def
= get_definition ()) != NULL
)
848 write_sample_svc (def
);
850 if (extend
&& tell
== ftell (fout
))
852 unlink (outfilename
);
857 /* sample main routine for client */
859 clnt_output (const char *infile
, const char *define
, int extend
,
864 const char *outfilename
;
868 open_input (infile
, define
);
869 outfilename
= extend
? extendfile (infile
, outfile
) : outfile
;
870 checkfiles (infile
, outfilename
);
871 /*check if outfile already exists.
872 if so, print an error message and exit */
874 open_output (infile
, outfilename
);
876 if (infile
&& (include
= extendfile (infile
, ".h")))
878 fprintf (fout
, "#include \"%s\"\n", include
);
882 fprintf (fout
, "#include <rpc/rpc.h>\n");
884 while ((def
= get_definition ()) != NULL
)
886 has_program
+= write_sample_clnt (def
);
890 write_sample_clnt_main ();
892 if (extend
&& tell
== ftell (fout
))
894 unlink (outfilename
);
899 file_name (const char *file
, const char *ext
)
902 temp
= extendfile (file
, ext
);
904 if (access (temp
, F_OK
) != -1)
907 return ((char *) " ");
911 mkfile_output (struct commandline
*cmd
)
914 const char *clientname
, *clntname
, *xdrname
, *hdrname
;
915 const char *servername
, *svcname
, *servprogname
, *clntprogname
;
918 svcname
= file_name (cmd
->infile
, "_svc.c");
919 clntname
= file_name (cmd
->infile
, "_clnt.c");
920 xdrname
= file_name (cmd
->infile
, "_xdr.c");
921 hdrname
= file_name (cmd
->infile
, ".h");
925 servername
= extendfile (cmd
->infile
, "_server.c");
926 clientname
= extendfile (cmd
->infile
, "_client.c");
933 servprogname
= extendfile (cmd
->infile
, "_server");
934 clntprogname
= extendfile (cmd
->infile
, "_client");
938 mkfilename
= alloc (strlen ("Makefile.") +
939 strlen (cmd
->infile
) + 1);
940 temp
= (char *) rindex (cmd
->infile
, '.');
941 strcat (mkfilename
, "Makefile.");
942 strncat (mkfilename
, cmd
->infile
,
943 (temp
- cmd
->infile
));
946 mkfilename
= (char *) cmd
->outfile
;
948 checkfiles (NULL
, mkfilename
);
949 open_output (NULL
, mkfilename
);
951 fprintf (fout
, "\n# This is a template Makefile generated by rpcgen\n");
953 f_print (fout
, "\n# Parameters\n\n");
955 f_print (fout
, "CLIENT = %s\nSERVER = %s\n\n", clntprogname
, servprogname
);
956 f_print (fout
, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
957 f_print (fout
, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
958 f_print (fout
, "SOURCES.x = %s\n\n", cmd
->infile
);
959 f_print (fout
, "TARGETS_SVC.c = %s %s %s \n",
960 svcname
, servername
, xdrname
);
961 f_print (fout
, "TARGETS_CLNT.c = %s %s %s \n",
962 clntname
, clientname
, xdrname
);
963 f_print (fout
, "TARGETS = %s %s %s %s %s %s\n\n",
964 hdrname
, xdrname
, clntname
,
965 svcname
, clientname
, servername
);
967 f_print (fout
, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
968 $(TARGETS_CLNT.c:%%.c=%%.o)");
970 f_print (fout
, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
971 $(TARGETS_SVC.c:%%.c=%%.o)");
973 f_print (fout
, "\n# Compiler flags \n");
975 fprintf (fout
, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS \
976 += -lnsl -lpthread \n ");
978 f_print (fout
, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
979 f_print (fout
, "RPCGENFLAGS = \n");
981 f_print (fout
, "\n# Targets \n\n");
983 f_print (fout
, "all : $(CLIENT) $(SERVER)\n\n");
984 f_print (fout
, "$(TARGETS) : $(SOURCES.x) \n");
985 f_print (fout
, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
986 f_print (fout
, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
987 $(TARGETS_CLNT.c) \n\n");
989 f_print (fout
, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
990 $(TARGETS_SVC.c) \n\n");
991 f_print (fout
, "$(CLIENT) : $(OBJECTS_CLNT) \n");
992 f_print (fout
, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
994 f_print (fout
, "$(SERVER) : $(OBJECTS_SVC) \n");
995 f_print (fout
, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
996 f_print (fout
, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
997 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
1001 * Perform registrations for service output
1002 * Return 0 if failed; 1 otherwise.
1005 do_registers (int argc
, const char *argv
[])
1009 if (inetdflag
|| !tirpcflag
)
1011 for (i
= 1; i
< argc
; i
++)
1013 if (streq (argv
[i
], "-s"))
1015 if (!check_nettype (argv
[i
+ 1], valid_i_nettypes
))
1017 write_inetd_register (argv
[i
+ 1]);
1024 for (i
= 1; i
< argc
; i
++)
1025 if (streq (argv
[i
], "-s"))
1027 if (!check_nettype (argv
[i
+ 1], valid_ti_nettypes
))
1029 write_nettype_register (argv
[i
+ 1]);
1032 else if (streq (argv
[i
], "-n"))
1034 write_netid_register (argv
[i
+ 1]);
1042 * Add another argument to the arg list
1045 addarg (const char *cp
)
1047 if (argcount
>= ARGLISTLEN
)
1049 fprintf (stderr
, _("rpcgen: too many defines\n"));
1053 arglist
[argcount
++] = cp
;
1057 putarg (int whereto
, const char *cp
)
1059 if (whereto
>= ARGLISTLEN
)
1061 fprintf (stderr
, _("rpcgen: arglist coding error\n"));
1065 arglist
[whereto
] = cp
;
1069 * if input file is stdin and an output file is specified then complain
1070 * if the file already exists. Otherwise the file may get overwritten
1071 * If input file does not exist, exit with an error
1075 checkfiles (const char *infile
, const char *outfile
)
1079 if (infile
) /* infile ! = NULL */
1080 if (stat (infile
, &buf
) < 0)
1087 if (stat (outfile
, &buf
) < 0)
1088 return; /* file does not exist */
1092 _("file '%s' already exists and may be overwritten\n"),
1100 * Parse command line arguments
1103 parseargs (int argc
, const char *argv
[], struct commandline
*cmd
)
1108 char flag
[(1 << 8 * sizeof (char))];
1112 cmd
->infile
= cmd
->outfile
= NULL
;
1130 for (i
= 1; i
< argc
; i
++)
1132 if (argv
[i
][0] != '-')
1137 _("Cannot specify more than one input file!\n"));
1140 cmd
->infile
= argv
[i
];
1144 for (j
= 1; argv
[i
][j
] != 0; j
++)
1162 /* sample flag: Ss or Sc.
1163 Ss means set flag['S'];
1164 Sc means set flag['C'];
1165 Sm means set flag['M']; */
1166 c
= argv
[i
][++j
]; /* get next char */
1180 case 'C': /* ANSI C syntax */
1184 #ifdef __GNU_LIBRARY__
1185 case 'k': /* K&R C syntax */
1190 case 'b': /* turn TIRPC flag off for
1191 generating backward compatible
1196 #ifdef __GNU_LIBRARY__
1197 case '5': /* turn TIRPC flag on for
1198 generating SysVr4 compatible
1217 svcclosetime
= argv
[i
];
1230 inlineflag
= atoi (argv
[i
]);
1235 if (argv
[i
][j
- 1] != '-' ||
1236 argv
[i
][j
+ 1] != 0)
1247 if (!streq (argv
[i
], "udp") &&
1248 !streq (argv
[i
], "tcp"))
1255 cmd
->outfile
= argv
[i
];
1259 if (argv
[i
][j
- 1] != '-')
1267 size_t len
= strlen (argv
[i
]);
1268 pathbuf
= malloc (len
+ 5);
1269 if (pathbuf
== NULL
)
1274 stpcpy (stpcpy (pathbuf
,
1291 cmd
->cflag
= flag
['c'];
1292 cmd
->hflag
= flag
['h'];
1293 cmd
->lflag
= flag
['l'];
1294 cmd
->mflag
= flag
['m'];
1295 cmd
->nflag
= flag
['n'];
1296 cmd
->sflag
= flag
['s'];
1297 cmd
->tflag
= flag
['t'];
1298 cmd
->Ssflag
= flag
['S'];
1299 cmd
->Scflag
= flag
['C'];
1300 cmd
->makefileflag
= flag
['M'];
1304 pmflag
= inetdflag
? 0 : 1; /* pmflag or inetdflag is always TRUE */
1305 if ((inetdflag
&& cmd
->nflag
))
1306 { /* netid not allowed with inetdflag */
1307 fprintf (stderr
, _("Cannot use netid flag with inetd flag!\n"));
1313 pmflag
= 0; /* set pmflag only in tirpcmode */
1314 #ifndef __GNU_LIBRARY__
1315 inetdflag
= 1; /* inetdflag is TRUE by default */
1318 { /* netid needs TIRPC */
1319 f_print (stderr
, _("Cannot use netid flag without TIRPC!\n"));
1324 if (newstyle
&& (tblflag
|| cmd
->tflag
))
1326 f_print (stderr
, _("Cannot use table flags with newstyle!\n"));
1330 /* check no conflicts with file generation flags */
1331 nflags
= cmd
->cflag
+ cmd
->hflag
+ cmd
->lflag
+ cmd
->mflag
+
1332 cmd
->sflag
+ cmd
->nflag
+ cmd
->tflag
+ cmd
->Ssflag
+ cmd
->Scflag
;
1336 if (cmd
->outfile
!= NULL
|| cmd
->infile
== NULL
)
1341 else if (cmd
->infile
== NULL
&&
1342 (cmd
->Ssflag
|| cmd
->Scflag
|| cmd
->makefileflag
))
1345 _("\"infile\" is required for template generation flags.\n"));
1350 fprintf (stderr
, _("Cannot have more than one file generation flag!\n"));
1359 fprintf (stderr
, _("usage: %s infile\n"), cmdname
);
1360 fprintf (stderr
, _("\t%s [-abkCLNTM][-Dname[=value]] [-i size] \
1361 [-I [-K seconds]] [-Y path] infile\n"), cmdname
);
1362 fprintf (stderr
, _("\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm] \
1363 [-o outfile] [infile]\n"), cmdname
);
1364 fprintf (stderr
, _("\t%s [-s nettype]* [-o outfile] [infile]\n"), cmdname
);
1365 fprintf (stderr
, _("\t%s [-n netid]* [-o outfile] [infile]\n"), cmdname
);
1371 options_usage (void)
1373 f_print (stderr
, "options:\n");
1374 f_print (stderr
, "-a\t\tgenerate all files, including samples\n");
1375 f_print (stderr
, "-b\t\tbackward compatibility mode (generates code for SunOS 4.1)\n");
1376 f_print (stderr
, "-c\t\tgenerate XDR routines\n");
1377 f_print (stderr
, "-C\t\tANSI C mode\n");
1378 f_print (stderr
, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1379 f_print (stderr
, "-h\t\tgenerate header file\n");
1380 f_print (stderr
, "-i size\t\tsize at which to start generating inline code\n");
1381 f_print (stderr
, "-I\t\tgenerate code for inetd support in server (for SunOS 4.1)\n");
1382 f_print (stderr
, "-K seconds\tserver exits after K seconds of inactivity\n");
1383 f_print (stderr
, "-l\t\tgenerate client side stubs\n");
1384 f_print (stderr
, "-L\t\tserver errors will be printed to syslog\n");
1385 f_print (stderr
, "-m\t\tgenerate server side stubs\n");
1386 f_print (stderr
, "-M\t\tgenerate MT-safe code\n");
1387 f_print (stderr
, "-n netid\tgenerate server code that supports named netid\n");
1388 f_print (stderr
, "-N\t\tsupports multiple arguments and call-by-value\n");
1389 f_print (stderr
, "-o outfile\tname of the output file\n");
1390 f_print (stderr
, "-s nettype\tgenerate server code that supports named nettype\n");
1391 f_print (stderr
, "-Sc\t\tgenerate sample client code that uses remote procedures\n");
1392 f_print (stderr
, "-Ss\t\tgenerate sample server code that defines remote procedures\n");
1393 f_print (stderr
, "-Sm \t\tgenerate makefile template \n");
1394 f_print (stderr
, "-t\t\tgenerate RPC dispatch table\n");
1395 f_print (stderr
, "-T\t\tgenerate code to support RPC dispatch tables\n");
1396 f_print (stderr
, "-Y path\t\tdirectory name to find C preprocessor (cpp)\n");