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
29 * @(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI
30 * $FreeBSD: src/usr.bin/rpcgen/rpc_main.c,v 1.11 1999/08/28 01:05:16 peter Exp $
31 * $DragonFly: src/usr.bin/rpcgen/rpc_main.c,v 1.11 2007/08/25 08:55:26 corecode Exp $
35 #ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
38 * rpc_main.c, Top level of the RPC protocol compiler.
39 * Copyright (C) 1987, Sun Microsystems, Inc.
47 #include <sys/types.h>
48 #include <sys/param.h>
51 #include "rpc_parse.h"
55 extern void write_sample_svc(definition
*);
56 extern int write_sample_clnt(definition
*);
57 extern void write_sample_clnt_main(void);
58 extern void add_sample_msg(void);
59 static void c_output(char *, char *, int, char *);
60 static void h_output(char *, char *, int, char *);
61 static void l_output(char *, char *, int, char *);
62 static void t_output(char *, char *, int, char *);
63 static void clnt_output(char *, char *, int, char *);
65 void c_initialize(void);
67 static void usage(void);
68 static void options_usage(void);
69 static int do_registers(int, char **);
70 static int parseargs(int, char **, struct commandline
*);
71 static void svc_output(char *, char *, int, char *);
72 static void mkfile_output(struct commandline
*);
73 static void s_output(int, char **, char *, char *, int, char *, int, int);
75 #define EXTEND 1 /* alias for TRUE */
76 #define DONT_EXTEND 0 /* alias for FALSE */
78 static int cppDefined
= 0; /* explicit path for C preprocessor */
80 static char *svcclosetime
= "120";
81 static char *CPP
= NULL
;
82 static char CPPFLAGS
[] = "-C";
83 static char pathbuf
[MAXPATHLEN
+ 1];
84 static char *allv
[] = {
85 "rpcgen", "-s", "udp", "-s", "tcp",
87 static int allc
= sizeof (allv
)/sizeof (allv
[0]);
88 static char *allnv
[] = {
89 "rpcgen", "-s", "netpath",
91 static int allnc
= sizeof (allnv
)/sizeof (allnv
[0]);
94 * machinations for handling expanding argument list
96 static void addarg(); /* add another argument to the list */
97 static void putarg(); /* put argument at specified location */
98 static void clear_args(); /* clear argument list */
99 static void checkfiles(); /* check if out file already exists */
103 #define ARGLISTLEN 20
106 static char *arglist
[ARGLISTLEN
];
107 static int argcount
= FIXEDARGS
;
110 int nonfatalerrors
; /* errors */
111 int inetdflag
= 0; /* Support for inetd is now the default */
112 int pmflag
; /* Support for port monitors */
113 int logflag
; /* Use syslog instead of fprintf for errors */
114 int tblflag
; /* Support for dispatch table file */
115 int mtflag
= 0; /* Support for MT */
117 /* length at which to start doing an inline */
119 int rpcgen_inline
= INLINE
;
121 * Length at which to start doing an inline. INLINE = default
122 * if 0, no xdr_inline code
125 int indefinitewait
; /* If started by port monitors, hang till it wants */
126 int exitnow
; /* If started by port monitors, exit after the call */
127 int timerflag
; /* TRUE if !indefinite && !exitnow */
128 int newstyle
; /* newstyle of passing arguments (by value) */
129 int Cflag
= 0; /* ANSI C syntax */
130 int CCflag
= 0; /* C++ files */
131 static int allfiles
; /* generate all files */
132 int tirpcflag
= 0; /* generating code for tirpc, by default */
133 xdrfunc
*xdrfunc_head
= NULL
; /* xdr function list */
134 xdrfunc
*xdrfunc_tail
= NULL
; /* xdr function list */
139 main(int argc
, char **argv
)
141 struct commandline cmd
;
143 memset(&cmd
, 0, sizeof (struct commandline
));
145 if (!parseargs(argc
, argv
, &cmd
))
148 * Only the client and server side stubs are likely to be customized,
149 * so in that case only, check if the outfile exists, and if so,
150 * print an error message and exit.
152 if (cmd
.Ssflag
|| cmd
.Scflag
|| cmd
.makefileflag
)
153 checkfiles(cmd
.infile
, cmd
.outfile
);
155 checkfiles(cmd
.infile
, NULL
);
158 c_output(cmd
.infile
, "-DRPC_XDR", DONT_EXTEND
, cmd
.outfile
);
159 } else if (cmd
.hflag
) {
160 h_output(cmd
.infile
, "-DRPC_HDR", DONT_EXTEND
, cmd
.outfile
);
161 } else if (cmd
.lflag
) {
162 l_output(cmd
.infile
, "-DRPC_CLNT", DONT_EXTEND
, cmd
.outfile
);
163 } else if (cmd
.sflag
|| cmd
.mflag
|| (cmd
.nflag
)) {
164 s_output(argc
, argv
, cmd
.infile
, "-DRPC_SVC", DONT_EXTEND
,
165 cmd
.outfile
, cmd
.mflag
, cmd
.nflag
);
166 } else if (cmd
.tflag
) {
167 t_output(cmd
.infile
, "-DRPC_TBL", DONT_EXTEND
, cmd
.outfile
);
168 } else if (cmd
.Ssflag
) {
169 svc_output(cmd
.infile
, "-DRPC_SERVER", DONT_EXTEND
,
171 } else if (cmd
.Scflag
) {
172 clnt_output(cmd
.infile
, "-DRPC_CLIENT", DONT_EXTEND
,
174 } else if (cmd
.makefileflag
) {
177 /* the rescans are required, since cpp may effect input */
178 c_output(cmd
.infile
, "-DRPC_XDR", EXTEND
, "_xdr.c");
180 h_output(cmd
.infile
, "-DRPC_HDR", EXTEND
, ".h");
182 l_output(cmd
.infile
, "-DRPC_CLNT", EXTEND
, "_clnt.c");
184 if (inetdflag
|| !tirpcflag
)
185 s_output(allc
, allv
, cmd
.infile
, "-DRPC_SVC", EXTEND
,
186 "_svc.c", cmd
.mflag
, cmd
.nflag
);
188 s_output(allnc
, allnv
, cmd
.infile
, "-DRPC_SVC",
189 EXTEND
, "_svc.c", cmd
.mflag
, cmd
.nflag
);
192 t_output(cmd
.infile
, "-DRPC_TBL", EXTEND
, "_tbl.i");
197 svc_output(cmd
.infile
, "-DRPC_SERVER", EXTEND
,
200 clnt_output(cmd
.infile
, "-DRPC_CLIENT", EXTEND
,
204 if (allfiles
|| (cmd
.makefileflag
== 1)){
210 exit(nonfatalerrors
);
216 * add extension to filename
219 extendfile(char *path
, char *ext
)
225 if ((file
= strrchr(path
, '/')) == NULL
)
229 res
= alloc(strlen(file
) + strlen(ext
) + 1);
232 p
= strrchr(file
, '.');
234 p
= file
+ strlen(file
);
236 strcpy(res
+ (p
- file
), ext
);
241 * Open output file with given extension
244 open_output(char *infile
, char *outfile
)
246 if (outfile
== NULL
) {
251 if (infile
!= NULL
&& streq(outfile
, infile
)) {
252 warnx("%s already exists. No output generated", infile
);
255 fout
= fopen(outfile
, "w");
257 warn("unable to open %s", outfile
);
260 record_open(outfile
);
266 f_print(fout
, "/*\n");
267 f_print(fout
, " * Please do not edit this file.\n");
268 f_print(fout
, " * It was generated using rpcgen.\n");
269 f_print(fout
, " */\n\n");
272 /* clear list of arguments */
278 for (i
= FIXEDARGS
; i
< ARGLISTLEN
; i
++)
280 argcount
= FIXEDARGS
;
283 /* make sure that a CPP exists */
294 * Open input file with given define for C-preprocessor
297 open_input(char *infile
, char *define
)
302 infilename
= (infile
== NULL
) ? "<stdin>" : infile
;
304 switch (childpid
= fork()) {
312 addarg((char *)NULL
);
317 execvp(arglist
[0], arglist
);
319 execv(arglist
[0], arglist
);
320 err(1, "execv(%s)", arglist
[0]);
325 fin
= fdopen(pd
[0], "r");
327 warn("%s", infilename
);
332 /* valid tirpc nettypes */
333 static char* valid_ti_nettypes
[] =
347 /* valid inetd nettypes */
348 static char* valid_i_nettypes
[] =
355 static int check_nettype(name
, list_to_check
)
357 char* list_to_check
[];
360 for (i
= 0; list_to_check
[i
] != NULL
; i
++) {
361 if (strcmp(name
, list_to_check
[i
]) == 0)
364 warnx("illegal nettype :\'%s\'", name
);
369 file_name(char *file
, char *ext
)
372 temp
= extendfile(file
, ext
);
374 if (access(temp
, F_OK
) != -1)
382 c_output(char *infile
, char *define
, int extend
, char *outfile
)
390 open_input(infile
, define
);
391 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
392 open_output(infile
, outfilename
);
394 if (infile
&& (include
= extendfile(infile
, ".h"))) {
395 f_print(fout
, "#include \"%s\"\n", include
);
397 /* .h file already contains rpc/rpc.h */
399 f_print(fout
, "#include <rpc/rpc.h>\n");
401 while ( (def
= get_definition()) )
403 if (extend
&& tell
== ftell(fout
))
410 /* add all the starting basic types */
413 add_type(1, "short");
415 add_type(1, "u_int");
416 add_type(1, "u_long");
417 add_type(1, "u_short");
420 char rpcgen_table_dcl
[] = "struct rpcgen_table {\n\
422 xdrproc_t xdr_arg; \n\
423 unsigned len_arg; \n\
424 xdrproc_t xdr_res; \n\
425 unsigned len_res; \n\
428 char *generate_guard(char *pathname
)
430 char* filename
, *guard
, *tmp
;
432 filename
= strrchr(pathname
, '/'); /* find last component */
433 filename
= ((filename
== 0) ? pathname
: filename
+1);
434 guard
= strdup(filename
);
435 /* convert to upper case */
439 *tmp
= toupper(*tmp
);
442 guard
= extendfile(guard
, "_H_RPCGEN");
447 * Compile into an XDR header file
451 h_output(char *infile
, char *define
, int extend
, char *outfile
)
461 open_input(infile
, define
);
462 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
463 open_output(infile
, outfilename
);
465 if (outfilename
|| infile
){
466 guard
= generate_guard(outfilename
? outfilename
: infile
);
470 f_print(fout
, "#ifndef _%s\n#define _%s\n\n", guard
,
473 f_print(fout
, "#include <rpc/rpc.h>\n");
476 f_print(fout
, "#include <pthread.h>\n");
478 /* put the C++ support */
479 if (Cflag
&& !CCflag
){
480 f_print(fout
, "\n#ifdef __cplusplus\n");
481 f_print(fout
, "extern \"C\" {\n");
482 f_print(fout
, "#endif\n\n");
485 /* put in a typedef for quadprecision. Only with Cflag */
489 /* print data definitions */
490 while ((def
= get_definition()) != 0)
494 * print function declarations.
495 * Do this after data definitions because they might be used as
496 * arguments for functions
498 for (l
= defined
; l
!= NULL
; l
= l
->next
)
499 print_funcdef(l
->val
);
501 /* Now print all xdr func declarations */
502 if (xdrfunc_head
!= NULL
) {
503 f_print(fout
, "\n/* the xdr functions */\n");
506 f_print(fout
, "\n#ifdef __cplusplus\n");
507 f_print(fout
, "extern \"C\" {\n");
508 f_print(fout
, "#endif\n");
512 xdrfuncp
= xdrfunc_head
;
513 while (xdrfuncp
!= NULL
) {
514 print_xdr_func_def(xdrfuncp
->name
,
515 xdrfuncp
->pointerp
, 2);
516 xdrfuncp
= xdrfuncp
->next
;
519 for (i
= 1; i
< 3; i
++) {
521 f_print(fout
, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
523 f_print(fout
, "\n#else /* K&R C */\n");
525 xdrfuncp
= xdrfunc_head
;
526 while (xdrfuncp
!= NULL
) {
527 print_xdr_func_def(xdrfuncp
->name
,
528 xdrfuncp
->pointerp
, i
);
529 xdrfuncp
= xdrfuncp
->next
;
532 f_print(fout
, "\n#endif /* K&R C */\n");
536 if (extend
&& tell
== ftell(fout
))
539 f_print(fout
, rpcgen_table_dcl
);
542 f_print(fout
, "\n#ifdef __cplusplus\n");
543 f_print(fout
, "}\n");
544 f_print(fout
, "#endif\n");
547 f_print(fout
, "\n#endif /* !_%s */\n", guard
);
551 * Compile into an RPC service
554 s_output(int argc
, char **argv
, char *infile
, char *define
, int extend
,
555 char *outfile
, int nomain
, int netflag
)
559 int foundprogram
= 0;
562 open_input(infile
, define
);
563 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
564 open_output(infile
, outfilename
);
566 if (infile
&& (include
= extendfile(infile
, ".h"))) {
567 f_print(fout
, "#include \"%s\"\n", include
);
570 f_print(fout
, "#include <rpc/rpc.h>\n");
572 f_print(fout
, "#include <stdio.h>\n");
573 f_print(fout
, "#include <stdlib.h> /* getenv, exit */\n");
576 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
577 f_print(fout
, "#include <string.h> /* strcmp */\n");
579 if (strcmp(svcclosetime
, "-1") == 0)
581 else if (strcmp(svcclosetime
, "0") == 0)
583 else if (inetdflag
|| pmflag
) {
584 f_print(fout
, "#include <signal.h>\n");
588 if (!tirpcflag
&& inetdflag
)
589 f_print(fout
, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
590 if (Cflag
&& (inetdflag
|| pmflag
)) {
591 f_print(fout
, "#ifdef __cplusplus\n");
593 "#include <sysent.h> /* getdtablesize, open */\n");
594 f_print(fout
, "#endif /* __cplusplus */\n");
596 f_print(fout
, "#include <unistd.h> /* setsid */\n");
599 f_print(fout
, "#include <sys/types.h>\n");
601 f_print(fout
, "#include <memory.h>\n");
603 f_print(fout
, "#include <stropts.h>\n");
604 if (inetdflag
|| !tirpcflag
) {
605 f_print(fout
, "#include <sys/socket.h>\n");
606 f_print(fout
, "#include <netinet/in.h>\n");
609 if ((netflag
|| pmflag
) && tirpcflag
&& !nomain
)
610 f_print(fout
, "#include <netconfig.h>\n");
612 f_print(fout
, "#include <sys/resource.h> /* rlimit */\n");
613 if (logflag
|| inetdflag
|| pmflag
)
614 f_print(fout
, "#include <syslog.h>\n");
619 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
622 f_print(fout
, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
624 f_print(fout
, "\n#define _RPCSVC_CLOSEDOWN %s\n",
626 while ((def
= get_definition()) != 0)
627 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
628 if (extend
&& !foundprogram
) {
632 write_most(infile
, netflag
, nomain
);
634 if (!do_registers(argc
, argv
)) {
644 * generate client side stubs
647 l_output(char *infile
, char *define
, int extend
, char *outfile
)
651 int foundprogram
= 0;
654 open_input(infile
, define
);
655 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
656 open_output(infile
, outfilename
);
659 f_print (fout
, "#include <memory.h> /* for memset */\n");
660 if (infile
&& (include
= extendfile(infile
, ".h"))) {
661 f_print(fout
, "#include \"%s\"\n", include
);
664 f_print(fout
, "#include <rpc/rpc.h>\n");
665 while ((def
= get_definition()) != 0)
666 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
667 if (extend
&& !foundprogram
)
674 * generate the dispatch table
677 t_output(char *infile
, char *define
, int extend
, char *outfile
)
680 int foundprogram
= 0;
683 open_input(infile
, define
);
684 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
685 open_output(infile
, outfilename
);
687 while ((def
= get_definition()) != 0)
688 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
689 if (extend
&& !foundprogram
)
695 /* sample routine for the server template */
697 svc_output(char *infile
, char *define
, int extend
, char *outfile
)
703 open_input(infile
, define
);
704 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
705 checkfiles(infile
, outfilename
);
707 * Check if outfile already exists.
708 * if so, print an error message and exit
710 open_output(infile
, outfilename
);
713 if (infile
&& (include
= extendfile(infile
, ".h"))) {
714 f_print(fout
, "#include \"%s\"\n", include
);
717 f_print(fout
, "#include <rpc/rpc.h>\n");
720 while ((def
= get_definition()) != 0)
721 write_sample_svc(def
);
722 if (extend
&& tell
== ftell(fout
))
726 /* sample main routine for client */
728 clnt_output(char *infile
, char *define
, int extend
, char *outfile
)
736 open_input(infile
, define
);
737 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
738 checkfiles(infile
, outfilename
);
740 * Check if outfile already exists.
741 * if so, print an error message and exit
744 open_output(infile
, outfilename
);
746 if (infile
&& (include
= extendfile(infile
, ".h"))) {
747 f_print(fout
, "#include \"%s\"\n", include
);
750 f_print(fout
, "#include <rpc/rpc.h>\n");
752 while ((def
= get_definition()) != 0)
753 has_program
+= write_sample_clnt(def
);
756 write_sample_clnt_main();
758 if (extend
&& tell
== ftell(fout
))
763 static void mkfile_output(cmd
)
764 struct commandline
*cmd
;
766 char *mkfilename
, *clientname
, *clntname
, *xdrname
, *hdrname
;
767 char *servername
, *svcname
, *servprogname
, *clntprogname
;
770 svcname
= file_name(cmd
->infile
, "_svc.c");
771 clntname
= file_name(cmd
->infile
, "_clnt.c");
772 xdrname
= file_name(cmd
->infile
, "_xdr.c");
773 hdrname
= file_name(cmd
->infile
, ".h");
776 servername
= extendfile(cmd
->infile
, "_server.c");
777 clientname
= extendfile(cmd
->infile
, "_client.c");
782 servprogname
= extendfile(cmd
->infile
, "_server");
783 clntprogname
= extendfile(cmd
->infile
, "_client");
786 mkfilename
= alloc(strlen("makefile.") +
787 strlen(cmd
->infile
) + 1);
788 temp
= strrchr(cmd
->infile
, '.');
789 strcat(mkfilename
, "makefile.");
790 strncat(mkfilename
, cmd
->infile
, (temp
- cmd
->infile
));
792 mkfilename
= cmd
->outfile
;
794 checkfiles(NULL
, mkfilename
);
795 open_output(NULL
, mkfilename
);
797 f_print(fout
, "\n# This is a template makefile generated "
800 f_print(fout
, "\n# Parameters \n\n");
802 f_print(fout
, "CLIENT = %s\nSERVER = %s\n\n",
803 clntprogname
, servprogname
);
804 f_print(fout
, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
805 f_print(fout
, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
806 f_print(fout
, "SOURCES.x = %s\n\n", cmd
->infile
);
807 f_print(fout
, "TARGETS_SVC.c = %s %s %s \n",
808 svcname
, servername
, xdrname
);
809 f_print(fout
, "TARGETS_CLNT.c = %s %s %s \n",
810 clntname
, clientname
, xdrname
);
811 f_print(fout
, "TARGETS = %s %s %s %s %s %s\n\n",
812 hdrname
, xdrname
, clntname
,
813 svcname
, clientname
, servername
);
815 f_print(fout
, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) "
816 "$(TARGETS_CLNT.c:%%.c=%%.o) ");
818 f_print(fout
, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) "
819 "$(TARGETS_SVC.c:%%.c=%%.o) ");
822 f_print(fout
, "\n# Compiler flags \n");
824 f_print(fout
, "\nCPPFLAGS += -D_REENTRANT\n"
825 "CFLAGS += -g \nLDLIBS += -lnsl -lthread\n");
827 f_print(fout
, "\nCFLAGS += -g \nLDLIBS +=\n");
828 f_print(fout
, "RPCGENFLAGS = \n");
830 f_print(fout
, "\n# Targets \n\n");
832 f_print(fout
, "all : $(CLIENT) $(SERVER)\n\n");
833 f_print(fout
, "$(TARGETS) : $(SOURCES.x) \n");
834 f_print(fout
, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
835 f_print(fout
, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) "
836 "$(TARGETS_CLNT.c) \n\n");
838 f_print(fout
, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) "
839 "$(TARGETS_SVC.c) \n\n");
840 f_print(fout
, "$(CLIENT) : $(OBJECTS_CLNT) \n");
841 f_print(fout
, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS) \n\n");
842 f_print(fout
, "$(SERVER) : $(OBJECTS_SVC) \n");
843 f_print(fout
, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
844 f_print(fout
, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) "
845 "$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
851 * Perform registrations for service output
852 * Return 0 if failed; 1 otherwise.
855 do_registers(int argc
, char **argv
)
859 if (inetdflag
|| !tirpcflag
) {
860 for (i
= 1; i
< argc
; i
++) {
861 if (streq(argv
[i
], "-s")) {
862 if (!check_nettype(argv
[i
+ 1],
865 write_inetd_register(argv
[i
+ 1]);
870 for (i
= 1; i
< argc
; i
++)
871 if (streq(argv
[i
], "-s")) {
872 if (!check_nettype(argv
[i
+ 1],
875 write_nettype_register(argv
[i
+ 1]);
877 } else if (streq(argv
[i
], "-n")) {
878 write_netid_register(argv
[i
+ 1]);
886 * Add another argument to the arg list
891 if (argcount
>= ARGLISTLEN
) {
892 warnx("too many defines");
896 arglist
[argcount
++] = cp
;
905 if (where
>= ARGLISTLEN
) {
906 warnx("arglist coding error");
914 * if input file is stdin and an output file is specified then complain
915 * if the file already exists. Otherwise the file may get overwritten
916 * If input file does not exist, exit with an error
920 checkfiles(char *infile
, char *outfile
)
924 if (infile
!= NULL
&& stat(infile
, &buf
) < 0) {
929 if (stat(outfile
, &buf
) < 0)
930 return; /* file does not exist */
932 warnx("file '%s' already exists and may be overwritten", outfile
);
939 * Parse command line arguments
942 parseargs(int argc
, char **argv
,struct commandline
*cmd
)
947 char flag
[(1 << 8 * sizeof (char))];
950 cmd
->infile
= cmd
->outfile
= NULL
;
967 for (i
= 1; i
< argc
; i
++) {
968 if (argv
[i
][0] != '-') {
970 warnx("cannot specify more than one input file");
973 cmd
->infile
= argv
[i
];
975 for (j
= 1; argv
[i
][j
] != 0; j
++) {
992 * sample flag: Ss or Sc.
993 * Ss means set flag['S'];
994 * Sc means set flag['C'];
995 * Sm means set flag['M'];
997 ch
= argv
[i
][++j
]; /* get next char */
1011 case 'C': /* ANSI C syntax */
1013 ch
= argv
[i
][j
+1]; /* get next char */
1035 svcclosetime
= argv
[i
];
1046 rpcgen_inline
= atoi(argv
[i
]);
1051 if (argv
[i
][j
- 1] != '-' ||
1052 argv
[i
][j
+ 1] != 0)
1060 cmd
->outfile
= argv
[i
];
1064 if (argv
[i
][j
- 1] != '-')
1071 strcpy(pathbuf
, argv
[i
]);
1072 strcat(pathbuf
, "/cpp");
1086 cmd
->cflag
= flag
['c'];
1087 cmd
->hflag
= flag
['h'];
1088 cmd
->lflag
= flag
['l'];
1089 cmd
->mflag
= flag
['m'];
1090 cmd
->nflag
= flag
['n'];
1091 cmd
->sflag
= flag
['s'];
1092 cmd
->tflag
= flag
['t'];
1093 cmd
->Ssflag
= flag
['S'];
1094 cmd
->Scflag
= flag
['C'];
1095 cmd
->makefileflag
= flag
['M'];
1098 pmflag
= inetdflag
? 0 : 1;
1099 /* pmflag or inetdflag is always TRUE */
1100 if ((inetdflag
&& cmd
->nflag
)) {
1101 /* netid not allowed with inetdflag */
1102 warnx("cannot use netid flag with inetd flag");
1105 } else { /* 4.1 mode */
1106 pmflag
= 0; /* set pmflag only in tirpcmode */
1107 if (cmd
->nflag
) { /* netid needs TIRPC */
1108 warnx("cannot use netid flag without TIRPC");
1113 if (newstyle
&& (tblflag
|| cmd
->tflag
)) {
1114 warnx("cannot use table flags with newstyle");
1118 /* check no conflicts with file generation flags */
1119 nflags
= cmd
->cflag
+ cmd
->hflag
+ cmd
->lflag
+ cmd
->mflag
+
1120 cmd
->sflag
+ cmd
->nflag
+ cmd
->tflag
+ cmd
->Ssflag
+
1121 cmd
->Scflag
+ cmd
->makefileflag
;
1124 if (cmd
->outfile
!= NULL
|| cmd
->infile
== NULL
)
1126 } else if (cmd
->infile
== NULL
&&
1127 (cmd
->Ssflag
|| cmd
->Scflag
|| cmd
->makefileflag
)) {
1128 warnx("\"infile\" is required for template generation flags");
1131 warnx("cannot have more than one file generation flag");
1140 f_print(stderr
, "%s\n%s\n%s\n%s\n%s\n",
1141 "usage: rpcgen infile",
1142 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]"
1143 "[-I [-K seconds]] [-Y path] infile",
1144 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]"
1145 "[-o outfile] [infile]",
1146 " rpcgen [-s nettype]* [-o outfile] [infile]",
1147 " rpcgen [-n netid]* [-o outfile] [infile]");
1155 f_print(stderr
, "options:\n");
1156 f_print(stderr
, "-a\t\tgenerate all files, including samples\n");
1157 f_print(stderr
, "-b\t\tbackward compatibility mode (generates code"
1158 "for SunOS 4.X)\n");
1159 f_print(stderr
, "-c\t\tgenerate XDR routines\n");
1160 f_print(stderr
, "-C\t\tANSI C mode\n");
1161 f_print(stderr
, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1162 f_print(stderr
, "-h\t\tgenerate header file\n");
1163 f_print(stderr
, "-i size\t\tsize at which to start generating"
1165 f_print(stderr
, "-I\t\tgenerate code for inetd support in server"
1166 "(for SunOS 4.X)\n");
1167 f_print(stderr
, "-K seconds\tserver exits after K seconds of"
1169 f_print(stderr
, "-l\t\tgenerate client side stubs\n");
1170 f_print(stderr
, "-L\t\tserver errors will be printed to syslog\n");
1171 f_print(stderr
, "-m\t\tgenerate server side stubs\n");
1172 f_print(stderr
, "-M\t\tgenerate MT-safe code\n");
1173 f_print(stderr
, "-n netid\tgenerate server code that supports"
1175 f_print(stderr
, "-N\t\tsupports multiple arguments and"
1177 f_print(stderr
, "-o outfile\tname of the output file\n");
1178 f_print(stderr
, "-s nettype\tgenerate server code that supports named"
1180 f_print(stderr
, "-Sc\t\tgenerate sample client code that uses remote"
1182 f_print(stderr
, "-Ss\t\tgenerate sample server code that defines"
1183 "remote procedures\n");
1184 f_print(stderr
, "-Sm \t\tgenerate makefile template \n");
1186 f_print(stderr
, "-t\t\tgenerate RPC dispatch table\n");
1187 f_print(stderr
, "-T\t\tgenerate code to support RPC dispatch tables\n");
1188 f_print(stderr
, "-Y path\t\tpath where cpp is found\n");