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.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
33 #ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
34 static char sccsid
[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
42 * rpc_main.c, Top level of the RPC protocol compiler.
43 * Copyright (C) 1987, Sun Microsystems, Inc.
51 #include <sys/types.h>
52 #include <sys/param.h>
55 #include "rpc_parse.h"
59 static void c_output(const char *, const char *, int, const char *);
60 static void h_output(const char *, const char *, int, const char *, int);
61 static void l_output(const char *, const char *, int, const char *);
62 static void t_output(const char *, const char *, int, const char *);
63 static void clnt_output(const char *, const char *, int, const char * );
64 static char *generate_guard(const char *);
65 static void c_initialize(void);
67 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
71 static void usage(void);
72 static void options_usage(void);
73 static int do_registers(int, const char **);
74 static int parseargs(int, const char **, struct commandline
*);
75 static void svc_output(const char *, const char *, int, const char *);
76 static void mkfile_output(struct commandline
*);
77 static void s_output(int, const char **, const char *, const char *, int, const char *, int, int);
79 #define EXTEND 1 /* alias for TRUE */
80 #define DONT_EXTEND 0 /* alias for FALSE */
82 #define SVR4_CPP "/usr/ccs/lib/cpp"
83 #define SUNOS_CPP "/usr/bin/cpp"
85 static int cppDefined
= 0; /* explicit path for C preprocessor */
87 static const char *svcclosetime
= "120";
88 static const char *CPP
= SVR4_CPP
;
89 static const char CPPFLAGS
[] = "-C";
90 static char pathbuf
[MAXPATHLEN
+ 1];
91 static const char *allv
[] = {
92 "rpcgen", "-s", "udp", "-s", "tcp",
94 static int allc
= sizeof (allv
)/sizeof (allv
[0]);
95 static const char *allnv
[] = {
96 "rpcgen", "-s", "netpath",
98 static int allnc
= sizeof (allnv
)/sizeof (allnv
[0]);
101 * machinations for handling expanding argument list
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 */
111 #define ARGLISTLEN 20
114 static char *arglist
[ARGLISTLEN
];
115 static int argcount
= FIXEDARGS
;
118 int nonfatalerrors
; /* errors */
119 int inetdflag
= 0; /* Support for inetd is disabled by default, use -I */
120 int pmflag
= 0; /* Support for port monitors is disabled by default */
121 int tirpc_socket
= 1; /* TI-RPC on socket, no TLI library */
122 int logflag
; /* Use syslog instead of fprintf for errors */
123 int tblflag
; /* Support for dispatch table file */
124 int mtflag
= 0; /* Support for MT */
127 /* length at which to start doing an inline */
129 int inline_size
= INLINE
;
131 * Length at which to start doing an inline. INLINE = default
132 * if 0, no xdr_inline code
135 int indefinitewait
; /* If started by port monitors, hang till it wants */
136 int exitnow
; /* If started by port monitors, exit after the call */
137 int timerflag
; /* TRUE if !indefinite && !exitnow */
138 int newstyle
; /* newstyle of passing arguments (by value) */
139 int CCflag
= 0; /* C++ files */
140 static int allfiles
; /* generate all files */
141 int tirpcflag
= 1; /* generating code for tirpc, by default */
142 xdrfunc
*xdrfunc_head
= NULL
; /* xdr function list */
143 xdrfunc
*xdrfunc_tail
= NULL
; /* xdr function list */
148 main(int argc
, const char *argv
[])
150 struct commandline cmd
;
152 (void) memset((char *)&cmd
, 0, sizeof (struct commandline
));
154 if (!parseargs(argc
, argv
, &cmd
))
157 * Only the client and server side stubs are likely to be customized,
158 * so in that case only, check if the outfile exists, and if so,
159 * print an error message and exit.
161 if (cmd
.Ssflag
|| cmd
.Scflag
|| cmd
.makefileflag
) {
162 checkfiles(cmd
.infile
, cmd
.outfile
);
165 checkfiles(cmd
.infile
, NULL
);
168 c_output(cmd
.infile
, "-DRPC_XDR", DONT_EXTEND
, cmd
.outfile
);
169 } else if (cmd
.hflag
) {
170 h_output(cmd
.infile
, "-DRPC_HDR", DONT_EXTEND
, cmd
.outfile
,
172 } else if (cmd
.lflag
) {
173 l_output(cmd
.infile
, "-DRPC_CLNT", DONT_EXTEND
, cmd
.outfile
);
174 } else if (cmd
.sflag
|| cmd
.mflag
|| (cmd
.nflag
)) {
175 s_output(argc
, argv
, cmd
.infile
, "-DRPC_SVC", DONT_EXTEND
,
176 cmd
.outfile
, cmd
.mflag
, cmd
.nflag
);
177 } else if (cmd
.tflag
) {
178 t_output(cmd
.infile
, "-DRPC_TBL", DONT_EXTEND
, cmd
.outfile
);
179 } else if (cmd
.Ssflag
) {
180 svc_output(cmd
.infile
, "-DRPC_SERVER", DONT_EXTEND
,
182 } else if (cmd
.Scflag
) {
183 clnt_output(cmd
.infile
, "-DRPC_CLIENT", DONT_EXTEND
,
185 } else if (cmd
.makefileflag
) {
188 /* the rescans are required, since cpp may effect input */
189 c_output(cmd
.infile
, "-DRPC_XDR", EXTEND
, "_xdr.c");
191 h_output(cmd
.infile
, "-DRPC_HDR", EXTEND
, ".h", cmd
.hflag
);
193 l_output(cmd
.infile
, "-DRPC_CLNT", EXTEND
, "_clnt.c");
195 if (inetdflag
|| !tirpcflag
)
196 s_output(allc
, allv
, cmd
.infile
, "-DRPC_SVC", EXTEND
,
197 "_svc.c", cmd
.mflag
, cmd
.nflag
);
199 s_output(allnc
, allnv
, cmd
.infile
, "-DRPC_SVC",
200 EXTEND
, "_svc.c", cmd
.mflag
, cmd
.nflag
);
203 t_output(cmd
.infile
, "-DRPC_TBL", EXTEND
, "_tbl.i");
208 svc_output(cmd
.infile
, "-DRPC_SERVER", EXTEND
,
211 clnt_output(cmd
.infile
, "-DRPC_CLIENT", EXTEND
,
215 if (allfiles
|| (cmd
.makefileflag
== 1)){
221 exit(nonfatalerrors
);
227 * add extension to filename
230 extendfile(const char *path
, const char *ext
)
236 if ((file
= rindex(path
, '/')) == NULL
)
240 res
= xmalloc(strlen(file
) + strlen(ext
) + 1);
241 p
= strrchr(file
, '.');
243 p
= file
+ strlen(file
);
245 (void) strcpy(res
, file
);
246 (void) strcpy(res
+ (p
- file
), ext
);
251 * Open output file with given extension
254 open_output(const char *infile
, const char *outfile
)
257 if (outfile
== NULL
) {
262 if (infile
!= NULL
&& streq(outfile
, infile
)) {
263 warnx("%s already exists. No output generated", infile
);
266 fout
= fopen(outfile
, "w");
268 warn("unable to open %s", outfile
);
271 record_open(outfile
);
279 f_print(fout
, "/*\n");
280 f_print(fout
, " * Please do not edit this file.\n");
281 f_print(fout
, " * It was generated using rpcgen.\n");
282 f_print(fout
, " */\n\n");
285 /* clear list of arguments */
290 for (i
= FIXEDARGS
; i
< ARGLISTLEN
; i
++)
292 argcount
= FIXEDARGS
;
295 /* make sure that a CPP exists */
301 if (stat(CPP
, &buf
) < 0) { /* SVR4 or explicit cpp does not exist */
303 warnx("cannot find C preprocessor: %s", CPP
);
305 } else { /* try the other one */
307 if (stat(CPP
, &buf
) < 0) { /* can't find any cpp */
308 warnx("cannot find C preprocessor: %s", CPP
);
316 * Open input file with given define for C-preprocessor
319 open_input(const char *infile
, const char *define
)
323 infilename
= (infile
== NULL
) ? "<stdin>" : infile
;
325 switch (childpid
= fork()) {
333 addarg((char *)NULL
);
335 (void) dup2(pd
[1], 1);
337 execv(arglist
[0], arglist
);
343 fin
= fdopen(pd
[0], "r");
345 warn("%s", infilename
);
350 /* valid tirpc nettypes */
351 static const char *valid_ti_nettypes
[] =
365 /* valid inetd nettypes */
366 static const char *valid_i_nettypes
[] =
374 check_nettype(const char *name
, const char *list_to_check
[])
377 for (i
= 0; list_to_check
[i
] != NULL
; i
++) {
378 if (strcmp(name
, list_to_check
[i
]) == 0) {
382 warnx("illegal nettype :\'%s\'", name
);
387 file_name(const char *file
, const char *ext
)
390 temp
= extendfile(file
, ext
);
392 if (access(temp
, F_OK
) != -1)
401 c_output(const char *infile
, const char *define
, int extend
, const char *outfile
)
405 const char *outfilename
;
409 open_input(infile
, define
);
410 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
411 open_output(infile
, outfilename
);
413 if (infile
&& (include
= extendfile(infile
, ".h"))) {
414 f_print(fout
, "#include \"%s\"\n", include
);
416 /* .h file already contains rpc/rpc.h */
418 f_print(fout
, "#include <rpc/rpc.h>\n");
420 while ( (def
= get_definition()) ) {
423 if (extend
&& tell
== ftell(fout
)) {
424 (void) unlink(outfilename
);
433 /* add all the starting basic types */
436 add_type(1, "short");
438 add_type(1, "u_int");
439 add_type(1, "u_long");
440 add_type(1, "u_short");
444 const char rpcgen_table_dcl
[] = "struct rpcgen_table {\n\
446 xdrproc_t xdr_arg; \n\
447 unsigned len_arg; \n\
448 xdrproc_t xdr_res; \n\
449 unsigned len_res; \n\
454 generate_guard(const char *pathname
)
456 const char *filename
;
457 char *guard
, *tmp
, *stopat
;
459 filename
= strrchr(pathname
, '/'); /* find last component */
460 filename
= ((filename
== 0) ? pathname
: filename
+1);
461 guard
= xstrdup(filename
);
462 stopat
= strrchr(guard
, '.');
465 * Convert to a valid C macro name and make it upper case.
466 * Map macro unfriendly characterss to '_'.
468 for (tmp
= guard
; *tmp
!= '\000'; ++tmp
) {
470 *tmp
= toupper(*tmp
);
471 else if (isupper(*tmp
) || *tmp
== '_')
473 else if (tmp
== guard
)
475 else if (isdigit(*tmp
))
476 /* OK for all but first character */;
477 else if (tmp
== stopat
) {
484 * Can't have a '_' in front, because it'll end up being "__".
485 * "__" macros shoudln't be used. So, remove all of the
486 * '_' characters from the front.
489 for (tmp
= guard
; *tmp
== '_'; ++tmp
)
493 guard
= extendfile(guard
, "_H_RPCGEN");
498 * Compile into an XDR header file
503 h_output(const char *infile
, const char *define
, int extend
, const char *outfile
, int headeronly
)
506 const char *outfilename
;
512 open_input(infile
, define
);
513 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
514 open_output(infile
, outfilename
);
516 if (outfilename
|| infile
){
517 guard
= generate_guard(outfilename
? outfilename
: infile
);
521 f_print(fout
, "#ifndef _%s\n#define _%s\n\n", guard
,
524 f_print(fout
, "#include <rpc/rpc.h>\n");
527 f_print(fout
, "#include <pthread.h>\n");
529 /* put the C++ support */
531 f_print(fout
, "\n#ifdef __cplusplus\n");
532 f_print(fout
, "extern \"C\" {\n");
533 f_print(fout
, "#endif\n\n");
536 /* put in a typedef for quadprecision. Only with Cflag */
540 /* print data definitions */
541 while ( (def
= get_definition()) ) {
542 print_datadef(def
, headeronly
);
546 * print function declarations.
547 * Do this after data definitions because they might be used as
548 * arguments for functions
550 for (l
= defined
; l
!= NULL
; l
= l
->next
) {
551 print_funcdef(l
->val
, headeronly
);
553 /* Now print all xdr func declarations */
554 if (xdrfunc_head
!= NULL
){
557 "\n/* the xdr functions */\n");
560 f_print(fout
, "\n#ifdef __cplusplus\n");
561 f_print(fout
, "extern \"C\" {\n");
562 f_print(fout
, "#endif\n");
565 xdrfuncp
= xdrfunc_head
;
566 while (xdrfuncp
!= NULL
){
567 print_xdr_func_def(xdrfuncp
->name
, xdrfuncp
->pointerp
);
568 xdrfuncp
= xdrfuncp
->next
;
572 if (extend
&& tell
== ftell(fout
)) {
573 (void) unlink(outfilename
);
574 } else if (tblflag
) {
575 f_print(fout
, rpcgen_table_dcl
);
578 f_print(fout
, "\n#ifdef __cplusplus\n");
579 f_print(fout
, "}\n");
580 f_print(fout
, "#endif\n");
582 f_print(fout
, "\n#endif /* !_%s */\n", guard
);
586 * Compile into an RPC service
589 s_output(int argc
, const char *argv
[], const char *infile
, const char *define
,
590 int extend
, const char *outfile
, int nomain
, int netflag
)
594 int foundprogram
= 0;
595 const char *outfilename
;
597 open_input(infile
, define
);
598 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
599 open_output(infile
, outfilename
);
601 if (infile
&& (include
= extendfile(infile
, ".h"))) {
602 f_print(fout
, "#include \"%s\"\n", include
);
605 f_print(fout
, "#include <rpc/rpc.h>\n");
607 f_print(fout
, "#include <stdio.h>\n");
608 f_print(fout
, "#include <stdlib.h> /* getenv, exit */\n");
609 f_print (fout
, "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
610 f_print (fout
, "#include <string.h> /* strcmp */\n");
612 f_print(fout
, "#include <rpc/rpc_com.h>\n");
613 if (strcmp(svcclosetime
, "-1") == 0)
615 else if (strcmp(svcclosetime
, "0") == 0)
617 else if (inetdflag
|| pmflag
) {
618 f_print(fout
, "#include <signal.h>\n");
622 if (!tirpcflag
&& inetdflag
)
623 f_print(fout
, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
624 if (inetdflag
|| pmflag
) {
625 f_print(fout
, "#ifdef __cplusplus\n");
627 "#include <sys/sysent.h> /* getdtablesize, open */\n");
628 f_print(fout
, "#endif /* __cplusplus */\n");
631 f_print(fout
, "#include <fcntl.h> /* open */\n");
632 f_print(fout
, "#include <unistd.h> /* fork / setsid */\n");
633 f_print(fout
, "#include <sys/types.h>\n");
636 f_print(fout
, "#include <string.h>\n");
637 if (inetdflag
|| !tirpcflag
) {
638 f_print(fout
, "#include <sys/socket.h>\n");
639 f_print(fout
, "#include <netinet/in.h>\n");
642 if ((netflag
|| pmflag
) && tirpcflag
&& !nomain
) {
643 f_print(fout
, "#include <netconfig.h>\n");
646 f_print(fout
, "#include <sys/resource.h> /* rlimit */\n");
647 if (logflag
|| inetdflag
|| pmflag
|| tirpcflag
)
648 f_print(fout
, "#include <syslog.h>\n");
650 f_print(fout
, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
652 f_print(fout
, "\n#define _RPCSVC_CLOSEDOWN %s\n",
654 while ( (def
= get_definition()) ) {
655 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
657 if (extend
&& !foundprogram
) {
658 (void) unlink(outfilename
);
661 write_most(infile
, netflag
, nomain
);
663 if (!do_registers(argc
, argv
)) {
665 (void) unlink(outfilename
);
673 * generate client side stubs
676 l_output(const char *infile
, const char *define
, int extend
, const char *outfile
)
680 int foundprogram
= 0;
681 const char *outfilename
;
683 open_input(infile
, define
);
684 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
685 open_output(infile
, outfilename
);
687 f_print (fout
, "#include <string.h> /* for memset */\n");
688 if (infile
&& (include
= extendfile(infile
, ".h"))) {
689 f_print(fout
, "#include \"%s\"\n", include
);
692 f_print(fout
, "#include <rpc/rpc.h>\n");
693 while ( (def
= get_definition()) ) {
694 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
696 if (extend
&& !foundprogram
) {
697 (void) unlink(outfilename
);
704 * generate the dispatch table
707 t_output(const char *infile
, const char *define
, int extend
, const char *outfile
)
710 int foundprogram
= 0;
711 const char *outfilename
;
713 open_input(infile
, define
);
714 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
715 open_output(infile
, outfilename
);
717 while ( (def
= get_definition()) ) {
718 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
720 if (extend
&& !foundprogram
) {
721 (void) unlink(outfilename
);
727 /* sample routine for the server template */
729 svc_output(const char *infile
, const char *define
, int extend
, const char *outfile
)
733 const char *outfilename
;
735 open_input(infile
, define
);
736 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
737 checkfiles(infile
, outfilename
);
739 * Check if outfile already exists.
740 * if so, print an error message and exit
742 open_output(infile
, outfilename
);
745 if (infile
&& (include
= extendfile(infile
, ".h"))) {
746 f_print(fout
, "#include \"%s\"\n", include
);
749 f_print(fout
, "#include <rpc/rpc.h>\n");
752 while ( (def
= get_definition()) ) {
753 write_sample_svc(def
);
755 if (extend
&& tell
== ftell(fout
)) {
756 (void) unlink(outfilename
);
760 /* sample main routine for client */
762 clnt_output(const char *infile
, const char *define
, int extend
, const char *outfile
)
766 const char *outfilename
;
770 open_input(infile
, define
);
771 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
772 checkfiles(infile
, outfilename
);
774 * Check if outfile already exists.
775 * if so, print an error message and exit
778 open_output(infile
, outfilename
);
780 if (infile
&& (include
= extendfile(infile
, ".h"))) {
781 f_print(fout
, "#include \"%s\"\n", include
);
784 f_print(fout
, "#include <rpc/rpc.h>\n");
786 while ( (def
= get_definition()) ) {
787 has_program
+= write_sample_clnt(def
);
791 write_sample_clnt_main();
793 if (extend
&& tell
== ftell(fout
)) {
794 (void) unlink(outfilename
);
799 static void mkfile_output(struct commandline
*cmd
)
801 const char *mkfilename
, *clientname
, *clntname
, *xdrname
, *hdrname
;
802 const char *servername
, *svcname
, *servprogname
, *clntprogname
;
803 char *temp
, *mkftemp
;
805 svcname
= file_name(cmd
->infile
, "_svc.c");
806 clntname
= file_name(cmd
->infile
, "_clnt.c");
807 xdrname
= file_name(cmd
->infile
, "_xdr.c");
808 hdrname
= file_name(cmd
->infile
, ".h");
812 servername
= extendfile(cmd
->infile
, "_server.c");
813 clientname
= extendfile(cmd
->infile
, "_client.c");
818 servprogname
= extendfile(cmd
->infile
, "_server");
819 clntprogname
= extendfile(cmd
->infile
, "_client");
822 mkftemp
= xmalloc(strlen("makefile.") +
823 strlen(cmd
->infile
) + 1);
824 temp
= (char *)rindex(cmd
->infile
, '.');
825 strcpy(mkftemp
, "makefile.");
826 (void) strncat(mkftemp
, cmd
->infile
,
827 (temp
- cmd
->infile
));
828 mkfilename
= mkftemp
;
830 mkfilename
= cmd
->outfile
;
833 checkfiles(NULL
, mkfilename
);
834 open_output(NULL
, mkfilename
);
836 f_print(fout
, "\n# This is a template makefile generated\
839 f_print(fout
, "\n# Parameters \n\n");
841 f_print(fout
, "CLIENT = %s\nSERVER = %s\n\n",
842 clntprogname
, servprogname
);
843 f_print(fout
, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
844 f_print(fout
, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
845 f_print(fout
, "SOURCES.x = %s\n\n", cmd
->infile
);
846 f_print(fout
, "TARGETS_SVC.c = %s %s %s \n",
847 svcname
, servername
, xdrname
);
848 f_print(fout
, "TARGETS_CLNT.c = %s %s %s \n",
849 clntname
, clientname
, xdrname
);
850 f_print(fout
, "TARGETS = %s %s %s %s %s %s\n\n",
851 hdrname
, xdrname
, clntname
,
852 svcname
, clientname
, servername
);
854 f_print(fout
, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
855 $(TARGETS_CLNT.c:%%.c=%%.o) ");
857 f_print(fout
, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
858 $(TARGETS_SVC.c:%%.c=%%.o) ");
861 f_print(fout
, "\n# Compiler flags \n");
863 f_print(fout
, "\nCFLAGS += -D_REENTRANT -D_THEAD_SAFE \nLDLIBS += -pthread\n");
865 f_print(fout
, "RPCGENFLAGS = \n");
867 f_print(fout
, "\n# Targets \n\n");
869 f_print(fout
, "all : $(CLIENT) $(SERVER)\n\n");
870 f_print(fout
, "$(TARGETS) : $(SOURCES.x) \n");
871 f_print(fout
, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
872 f_print(fout
, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
873 $(TARGETS_CLNT.c) \n\n");
875 f_print(fout
, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
876 $(TARGETS_SVC.c) \n\n");
877 f_print(fout
, "$(CLIENT) : $(OBJECTS_CLNT) \n");
878 f_print(fout
, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
880 f_print(fout
, "$(SERVER) : $(OBJECTS_SVC) \n");
881 f_print(fout
, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
882 f_print(fout
, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \
883 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
889 * Perform registrations for service output
890 * Return 0 if failed; 1 otherwise.
893 do_registers(int argc
, const char *argv
[])
897 if (inetdflag
|| !tirpcflag
) {
898 for (i
= 1; i
< argc
; i
++) {
899 if (streq(argv
[i
], "-s")) {
900 if (!check_nettype(argv
[i
+ 1],
903 write_inetd_register(argv
[i
+ 1]);
908 for (i
= 1; i
< argc
; i
++)
909 if (streq(argv
[i
], "-s")) {
910 if (!check_nettype(argv
[i
+ 1],
913 write_nettype_register(argv
[i
+ 1]);
915 } else if (streq(argv
[i
], "-n")) {
916 write_netid_register(argv
[i
+ 1]);
924 * Add another argument to the arg list
927 addarg(const char *cp
)
929 if (argcount
>= ARGLISTLEN
) {
930 warnx("too many defines");
935 arglist
[argcount
++] = xstrdup(cp
);
937 arglist
[argcount
++] = NULL
;
942 putarg(int place
, const char *cp
)
944 if (place
>= ARGLISTLEN
) {
945 warnx("arglist coding error");
950 arglist
[place
] = xstrdup(cp
);
952 arglist
[place
] = NULL
;
956 * if input file is stdin and an output file is specified then complain
957 * if the file already exists. Otherwise the file may get overwritten
958 * If input file does not exist, exit with an error
962 checkfiles(const char *infile
, const char *outfile
)
967 if (infile
) /* infile ! = NULL */
968 if (stat(infile
, &buf
) < 0)
974 if (stat(outfile
, &buf
) < 0)
975 return; /* file does not exist */
977 warnx("file '%s' already exists and may be overwritten", outfile
);
984 * Parse command line arguments
987 parseargs(int argc
, const char *argv
[], struct commandline
*cmd
)
992 char flag
[(1 << 8 * sizeof (char))];
995 cmd
->infile
= cmd
->outfile
= NULL
;
1012 for (i
= 1; i
< argc
; i
++) {
1013 if (argv
[i
][0] != '-') {
1015 warnx("cannot specify more than one input file");
1018 cmd
->infile
= argv
[i
];
1020 for (j
= 1; argv
[i
][j
] != 0; j
++) {
1038 * sample flag: Ss or Sc.
1039 * Ss means set flag['S'];
1040 * Sc means set flag['C'];
1041 * Sm means set flag['M'];
1043 ch
= argv
[i
][++j
]; /* get next char */
1053 if (flag
[(int)ch
]) {
1058 case 'C': /* ANSI C syntax */
1059 ch
= argv
[i
][j
+1]; /* get next char */
1067 * Turn TIRPC flag off for
1068 * generating backward compatible
1090 svcclosetime
= argv
[i
];
1102 inline_size
= atoi(argv
[i
]);
1107 if (argv
[i
][j
- 1] != '-' ||
1108 argv
[i
][j
+ 1] != 0) {
1119 cmd
->outfile
= argv
[i
];
1123 if (argv
[i
][j
- 1] != '-') {
1126 (void) addarg(argv
[i
]);
1132 (void) strlcpy(pathbuf
, argv
[i
], sizeof(pathbuf
));
1133 if (strlcat(pathbuf
, "/cpp", sizeof(pathbuf
))
1134 >= sizeof(pathbuf
)) {
1135 warnx("argument too long");
1153 cmd
->cflag
= flag
['c'];
1154 cmd
->hflag
= flag
['h'];
1155 cmd
->lflag
= flag
['l'];
1156 cmd
->mflag
= flag
['m'];
1157 cmd
->nflag
= flag
['n'];
1158 cmd
->sflag
= flag
['s'];
1159 cmd
->tflag
= flag
['t'];
1160 cmd
->Ssflag
= flag
['S'];
1161 cmd
->Scflag
= flag
['C'];
1162 cmd
->makefileflag
= flag
['M'];
1167 if ((inetdflag
&& cmd
->nflag
)) {
1168 /* netid not allowed with inetdflag */
1169 warnx("cannot use netid flag with inetd flag");
1172 } else { /* 4.1 mode */
1173 pmflag
= 0; /* set pmflag only in tirpcmode */
1174 if (cmd
->nflag
) { /* netid needs TIRPC */
1175 warnx("cannot use netid flag without TIRPC");
1180 if (newstyle
&& (tblflag
|| cmd
->tflag
)) {
1181 warnx("cannot use table flags with newstyle");
1185 /* check no conflicts with file generation flags */
1186 nflags
= cmd
->cflag
+ cmd
->hflag
+ cmd
->lflag
+ cmd
->mflag
+
1187 cmd
->sflag
+ cmd
->nflag
+ cmd
->tflag
+ cmd
->Ssflag
+
1188 cmd
->Scflag
+ cmd
->makefileflag
;
1191 if (cmd
->outfile
!= NULL
|| cmd
->infile
== NULL
) {
1194 } else if (cmd
->infile
== NULL
&&
1195 (cmd
->Ssflag
|| cmd
->Scflag
|| cmd
->makefileflag
)) {
1196 warnx("\"infile\" is required for template generation flags");
1199 warnx("cannot have more than one file generation flag");
1208 f_print(stderr
, "%s\n%s\n%s\n%s\n%s\n",
1209 "usage: rpcgen infile",
1210 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1211 [-I -P [-K seconds]] [-Y path] infile",
1212 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1213 [-o outfile] [infile]",
1214 " rpcgen [-s nettype]* [-o outfile] [infile]",
1215 " rpcgen [-n netid]* [-o outfile] [infile]");
1223 f_print(stderr
, "options:\n");
1224 f_print(stderr
, "-a\t\tgenerate all files, including samples\n");
1225 f_print(stderr
, "-b\t\tbackward compatibility mode (generates code \
1226 for FreeBSD 4.X)\n");
1227 f_print(stderr
, "-c\t\tgenerate XDR routines\n");
1228 f_print(stderr
, "-C\t\tANSI C mode\n");
1229 f_print(stderr
, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1230 f_print(stderr
, "-h\t\tgenerate header file\n");
1231 f_print(stderr
, "-i size\t\tsize at which to start generating\
1233 f_print(stderr
, "-I\t\tgenerate code for inetd support in server\n");
1234 f_print(stderr
, "-K seconds\tserver exits after K seconds of\
1236 f_print(stderr
, "-l\t\tgenerate client side stubs\n");
1237 f_print(stderr
, "-L\t\tserver errors will be printed to syslog\n");
1238 f_print(stderr
, "-m\t\tgenerate server side stubs\n");
1239 f_print(stderr
, "-M\t\tgenerate MT-safe code\n");
1240 f_print(stderr
, "-n netid\tgenerate server code that supports\
1242 f_print(stderr
, "-N\t\tsupports multiple arguments and\
1244 f_print(stderr
, "-o outfile\tname of the output file\n");
1245 f_print(stderr
, "-P\t\tgenerate code for port monitoring support in server\n");
1246 f_print(stderr
, "-s nettype\tgenerate server code that supports named\
1248 f_print(stderr
, "-Sc\t\tgenerate sample client code that uses remote\
1250 f_print(stderr
, "-Ss\t\tgenerate sample server code that defines\
1251 remote procedures\n");
1252 f_print(stderr
, "-Sm \t\tgenerate makefile template \n");
1254 f_print(stderr
, "-t\t\tgenerate RPC dispatch table\n");
1255 f_print(stderr
, "-T\t\tgenerate code to support RPC dispatch tables\n");
1256 f_print(stderr
, "-Y path\t\tpath where cpp is found\n");