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.10 2004/08/30 18:06:50 eirikn 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
);
327 fin
= fdopen(pd
[0], "r");
329 warn("%s", infilename
);
334 /* valid tirpc nettypes */
335 static char* valid_ti_nettypes
[] =
349 /* valid inetd nettypes */
350 static char* valid_i_nettypes
[] =
357 static int check_nettype(name
, list_to_check
)
359 char* list_to_check
[];
362 for (i
= 0; list_to_check
[i
] != NULL
; i
++) {
363 if (strcmp(name
, list_to_check
[i
]) == 0)
366 warnx("illegal nettype :\'%s\'", name
);
371 file_name(char *file
, char *ext
)
374 temp
= extendfile(file
, ext
);
376 if (access(temp
, F_OK
) != -1)
384 c_output(char *infile
, char *define
, int extend
, char *outfile
)
392 open_input(infile
, define
);
393 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
394 open_output(infile
, outfilename
);
396 if (infile
&& (include
= extendfile(infile
, ".h"))) {
397 f_print(fout
, "#include \"%s\"\n", include
);
399 /* .h file already contains rpc/rpc.h */
401 f_print(fout
, "#include <rpc/rpc.h>\n");
403 while ( (def
= get_definition()) )
405 if (extend
&& tell
== ftell(fout
))
412 /* add all the starting basic types */
415 add_type(1, "short");
417 add_type(1, "u_int");
418 add_type(1, "u_long");
419 add_type(1, "u_short");
422 char rpcgen_table_dcl
[] = "struct rpcgen_table {\n\
424 xdrproc_t xdr_arg; \n\
425 unsigned len_arg; \n\
426 xdrproc_t xdr_res; \n\
427 unsigned len_res; \n\
430 char *generate_guard(char *pathname
)
432 char* filename
, *guard
, *tmp
;
434 filename
= strrchr(pathname
, '/'); /* find last component */
435 filename
= ((filename
== 0) ? pathname
: filename
+1);
436 guard
= strdup(filename
);
437 /* convert to upper case */
441 *tmp
= toupper(*tmp
);
444 guard
= extendfile(guard
, "_H_RPCGEN");
449 * Compile into an XDR header file
453 h_output(char *infile
, char *define
, int extend
, char *outfile
)
463 open_input(infile
, define
);
464 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
465 open_output(infile
, outfilename
);
467 if (outfilename
|| infile
){
468 guard
= generate_guard(outfilename
? outfilename
: infile
);
472 f_print(fout
, "#ifndef _%s\n#define _%s\n\n", guard
,
475 f_print(fout
, "#include <rpc/rpc.h>\n");
478 f_print(fout
, "#include <pthread.h>\n");
480 /* put the C++ support */
481 if (Cflag
&& !CCflag
){
482 f_print(fout
, "\n#ifdef __cplusplus\n");
483 f_print(fout
, "extern \"C\" {\n");
484 f_print(fout
, "#endif\n\n");
487 /* put in a typedef for quadprecision. Only with Cflag */
491 /* print data definitions */
492 while ((def
= get_definition()) != 0)
496 * print function declarations.
497 * Do this after data definitions because they might be used as
498 * arguments for functions
500 for (l
= defined
; l
!= NULL
; l
= l
->next
)
501 print_funcdef(l
->val
);
503 /* Now print all xdr func declarations */
504 if (xdrfunc_head
!= NULL
) {
505 f_print(fout
, "\n/* the xdr functions */\n");
508 f_print(fout
, "\n#ifdef __cplusplus\n");
509 f_print(fout
, "extern \"C\" {\n");
510 f_print(fout
, "#endif\n");
514 xdrfuncp
= xdrfunc_head
;
515 while (xdrfuncp
!= NULL
) {
516 print_xdr_func_def(xdrfuncp
->name
,
517 xdrfuncp
->pointerp
, 2);
518 xdrfuncp
= xdrfuncp
->next
;
521 for (i
= 1; i
< 3; i
++) {
523 f_print(fout
, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
525 f_print(fout
, "\n#else /* K&R C */\n");
527 xdrfuncp
= xdrfunc_head
;
528 while (xdrfuncp
!= NULL
) {
529 print_xdr_func_def(xdrfuncp
->name
,
530 xdrfuncp
->pointerp
, i
);
531 xdrfuncp
= xdrfuncp
->next
;
534 f_print(fout
, "\n#endif /* K&R C */\n");
538 if (extend
&& tell
== ftell(fout
))
541 f_print(fout
, rpcgen_table_dcl
);
544 f_print(fout
, "\n#ifdef __cplusplus\n");
545 f_print(fout
, "}\n");
546 f_print(fout
, "#endif\n");
549 f_print(fout
, "\n#endif /* !_%s */\n", guard
);
553 * Compile into an RPC service
556 s_output(int argc
, char **argv
, char *infile
, char *define
, int extend
,
557 char *outfile
, int nomain
, int netflag
)
561 int foundprogram
= 0;
564 open_input(infile
, define
);
565 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
566 open_output(infile
, outfilename
);
568 if (infile
&& (include
= extendfile(infile
, ".h"))) {
569 f_print(fout
, "#include \"%s\"\n", include
);
572 f_print(fout
, "#include <rpc/rpc.h>\n");
574 f_print(fout
, "#include <stdio.h>\n");
575 f_print(fout
, "#include <stdlib.h> /* getenv, exit */\n");
578 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
579 f_print(fout
, "#include <string.h> /* strcmp */\n");
581 if (strcmp(svcclosetime
, "-1") == 0)
583 else if (strcmp(svcclosetime
, "0") == 0)
585 else if (inetdflag
|| pmflag
) {
586 f_print(fout
, "#include <signal.h>\n");
590 if (!tirpcflag
&& inetdflag
)
591 f_print(fout
, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
592 if (Cflag
&& (inetdflag
|| pmflag
)) {
593 f_print(fout
, "#ifdef __cplusplus\n");
595 "#include <sysent.h> /* getdtablesize, open */\n");
596 f_print(fout
, "#endif /* __cplusplus */\n");
598 f_print(fout
, "#include <unistd.h> /* setsid */\n");
601 f_print(fout
, "#include <sys/types.h>\n");
603 f_print(fout
, "#include <memory.h>\n");
605 f_print(fout
, "#include <stropts.h>\n");
606 if (inetdflag
|| !tirpcflag
) {
607 f_print(fout
, "#include <sys/socket.h>\n");
608 f_print(fout
, "#include <netinet/in.h>\n");
611 if ((netflag
|| pmflag
) && tirpcflag
&& !nomain
)
612 f_print(fout
, "#include <netconfig.h>\n");
614 f_print(fout
, "#include <sys/resource.h> /* rlimit */\n");
615 if (logflag
|| inetdflag
|| pmflag
)
616 f_print(fout
, "#include <syslog.h>\n");
621 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
624 f_print(fout
, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
626 f_print(fout
, "\n#define _RPCSVC_CLOSEDOWN %s\n",
628 while ((def
= get_definition()) != 0)
629 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
630 if (extend
&& !foundprogram
) {
634 write_most(infile
, netflag
, nomain
);
636 if (!do_registers(argc
, argv
)) {
646 * generate client side stubs
649 l_output(char *infile
, char *define
, int extend
, char *outfile
)
653 int foundprogram
= 0;
656 open_input(infile
, define
);
657 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
658 open_output(infile
, outfilename
);
661 f_print (fout
, "#include <memory.h> /* for memset */\n");
662 if (infile
&& (include
= extendfile(infile
, ".h"))) {
663 f_print(fout
, "#include \"%s\"\n", include
);
666 f_print(fout
, "#include <rpc/rpc.h>\n");
667 while ((def
= get_definition()) != 0)
668 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
669 if (extend
&& !foundprogram
)
676 * generate the dispatch table
679 t_output(char *infile
, char *define
, int extend
, char *outfile
)
682 int foundprogram
= 0;
685 open_input(infile
, define
);
686 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
687 open_output(infile
, outfilename
);
689 while ((def
= get_definition()) != 0)
690 foundprogram
|= (def
->def_kind
== DEF_PROGRAM
);
691 if (extend
&& !foundprogram
)
697 /* sample routine for the server template */
699 svc_output(char *infile
, char *define
, int extend
, char *outfile
)
705 open_input(infile
, define
);
706 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
707 checkfiles(infile
, outfilename
);
709 * Check if outfile already exists.
710 * if so, print an error message and exit
712 open_output(infile
, outfilename
);
715 if (infile
&& (include
= extendfile(infile
, ".h"))) {
716 f_print(fout
, "#include \"%s\"\n", include
);
719 f_print(fout
, "#include <rpc/rpc.h>\n");
722 while ((def
= get_definition()) != 0)
723 write_sample_svc(def
);
724 if (extend
&& tell
== ftell(fout
))
728 /* sample main routine for client */
730 clnt_output(char *infile
, char *define
, int extend
, char *outfile
)
738 open_input(infile
, define
);
739 outfilename
= extend
? extendfile(infile
, outfile
) : outfile
;
740 checkfiles(infile
, outfilename
);
742 * Check if outfile already exists.
743 * if so, print an error message and exit
746 open_output(infile
, outfilename
);
748 if (infile
&& (include
= extendfile(infile
, ".h"))) {
749 f_print(fout
, "#include \"%s\"\n", include
);
752 f_print(fout
, "#include <rpc/rpc.h>\n");
754 while ((def
= get_definition()) != 0)
755 has_program
+= write_sample_clnt(def
);
758 write_sample_clnt_main();
760 if (extend
&& tell
== ftell(fout
))
765 static void mkfile_output(cmd
)
766 struct commandline
*cmd
;
768 char *mkfilename
, *clientname
, *clntname
, *xdrname
, *hdrname
;
769 char *servername
, *svcname
, *servprogname
, *clntprogname
;
772 svcname
= file_name(cmd
->infile
, "_svc.c");
773 clntname
= file_name(cmd
->infile
, "_clnt.c");
774 xdrname
= file_name(cmd
->infile
, "_xdr.c");
775 hdrname
= file_name(cmd
->infile
, ".h");
778 servername
= extendfile(cmd
->infile
, "_server.c");
779 clientname
= extendfile(cmd
->infile
, "_client.c");
784 servprogname
= extendfile(cmd
->infile
, "_server");
785 clntprogname
= extendfile(cmd
->infile
, "_client");
788 mkfilename
= alloc(strlen("makefile.") +
789 strlen(cmd
->infile
) + 1);
790 temp
= strrchr(cmd
->infile
, '.');
791 strcat(mkfilename
, "makefile.");
792 strncat(mkfilename
, cmd
->infile
, (temp
- cmd
->infile
));
794 mkfilename
= cmd
->outfile
;
796 checkfiles(NULL
, mkfilename
);
797 open_output(NULL
, mkfilename
);
799 f_print(fout
, "\n# This is a template makefile generated "
802 f_print(fout
, "\n# Parameters \n\n");
804 f_print(fout
, "CLIENT = %s\nSERVER = %s\n\n",
805 clntprogname
, servprogname
);
806 f_print(fout
, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
807 f_print(fout
, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
808 f_print(fout
, "SOURCES.x = %s\n\n", cmd
->infile
);
809 f_print(fout
, "TARGETS_SVC.c = %s %s %s \n",
810 svcname
, servername
, xdrname
);
811 f_print(fout
, "TARGETS_CLNT.c = %s %s %s \n",
812 clntname
, clientname
, xdrname
);
813 f_print(fout
, "TARGETS = %s %s %s %s %s %s\n\n",
814 hdrname
, xdrname
, clntname
,
815 svcname
, clientname
, servername
);
817 f_print(fout
, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) "
818 "$(TARGETS_CLNT.c:%%.c=%%.o) ");
820 f_print(fout
, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) "
821 "$(TARGETS_SVC.c:%%.c=%%.o) ");
824 f_print(fout
, "\n# Compiler flags \n");
826 f_print(fout
, "\nCPPFLAGS += -D_REENTRANT\n"
827 "CFLAGS += -g \nLDLIBS += -lnsl -lthread\n");
829 f_print(fout
, "\nCFLAGS += -g \nLDLIBS +=\n");
830 f_print(fout
, "RPCGENFLAGS = \n");
832 f_print(fout
, "\n# Targets \n\n");
834 f_print(fout
, "all : $(CLIENT) $(SERVER)\n\n");
835 f_print(fout
, "$(TARGETS) : $(SOURCES.x) \n");
836 f_print(fout
, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
837 f_print(fout
, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) "
838 "$(TARGETS_CLNT.c) \n\n");
840 f_print(fout
, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) "
841 "$(TARGETS_SVC.c) \n\n");
842 f_print(fout
, "$(CLIENT) : $(OBJECTS_CLNT) \n");
843 f_print(fout
, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS) \n\n");
844 f_print(fout
, "$(SERVER) : $(OBJECTS_SVC) \n");
845 f_print(fout
, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
846 f_print(fout
, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) "
847 "$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
853 * Perform registrations for service output
854 * Return 0 if failed; 1 otherwise.
857 do_registers(int argc
, char **argv
)
861 if (inetdflag
|| !tirpcflag
) {
862 for (i
= 1; i
< argc
; i
++) {
863 if (streq(argv
[i
], "-s")) {
864 if (!check_nettype(argv
[i
+ 1],
867 write_inetd_register(argv
[i
+ 1]);
872 for (i
= 1; i
< argc
; i
++)
873 if (streq(argv
[i
], "-s")) {
874 if (!check_nettype(argv
[i
+ 1],
877 write_nettype_register(argv
[i
+ 1]);
879 } else if (streq(argv
[i
], "-n")) {
880 write_netid_register(argv
[i
+ 1]);
888 * Add another argument to the arg list
893 if (argcount
>= ARGLISTLEN
) {
894 warnx("too many defines");
898 arglist
[argcount
++] = cp
;
907 if (where
>= ARGLISTLEN
) {
908 warnx("arglist coding error");
916 * if input file is stdin and an output file is specified then complain
917 * if the file already exists. Otherwise the file may get overwritten
918 * If input file does not exist, exit with an error
922 checkfiles(char *infile
, char *outfile
)
926 if (infile
!= NULL
&& stat(infile
, &buf
) < 0) {
931 if (stat(outfile
, &buf
) < 0)
932 return; /* file does not exist */
934 warnx("file '%s' already exists and may be overwritten", outfile
);
941 * Parse command line arguments
944 parseargs(int argc
, char **argv
,struct commandline
*cmd
)
949 char flag
[(1 << 8 * sizeof (char))];
952 cmd
->infile
= cmd
->outfile
= NULL
;
969 for (i
= 1; i
< argc
; i
++) {
970 if (argv
[i
][0] != '-') {
972 warnx("cannot specify more than one input file");
975 cmd
->infile
= argv
[i
];
977 for (j
= 1; argv
[i
][j
] != 0; j
++) {
994 * sample flag: Ss or Sc.
995 * Ss means set flag['S'];
996 * Sc means set flag['C'];
997 * Sm means set flag['M'];
999 ch
= argv
[i
][++j
]; /* get next char */
1013 case 'C': /* ANSI C syntax */
1015 ch
= argv
[i
][j
+1]; /* get next char */
1037 svcclosetime
= argv
[i
];
1048 rpcgen_inline
= atoi(argv
[i
]);
1053 if (argv
[i
][j
- 1] != '-' ||
1054 argv
[i
][j
+ 1] != 0)
1062 cmd
->outfile
= argv
[i
];
1066 if (argv
[i
][j
- 1] != '-')
1073 strcpy(pathbuf
, argv
[i
]);
1074 strcat(pathbuf
, "/cpp");
1088 cmd
->cflag
= flag
['c'];
1089 cmd
->hflag
= flag
['h'];
1090 cmd
->lflag
= flag
['l'];
1091 cmd
->mflag
= flag
['m'];
1092 cmd
->nflag
= flag
['n'];
1093 cmd
->sflag
= flag
['s'];
1094 cmd
->tflag
= flag
['t'];
1095 cmd
->Ssflag
= flag
['S'];
1096 cmd
->Scflag
= flag
['C'];
1097 cmd
->makefileflag
= flag
['M'];
1100 pmflag
= inetdflag
? 0 : 1;
1101 /* pmflag or inetdflag is always TRUE */
1102 if ((inetdflag
&& cmd
->nflag
)) {
1103 /* netid not allowed with inetdflag */
1104 warnx("cannot use netid flag with inetd flag");
1107 } else { /* 4.1 mode */
1108 pmflag
= 0; /* set pmflag only in tirpcmode */
1109 if (cmd
->nflag
) { /* netid needs TIRPC */
1110 warnx("cannot use netid flag without TIRPC");
1115 if (newstyle
&& (tblflag
|| cmd
->tflag
)) {
1116 warnx("cannot use table flags with newstyle");
1120 /* check no conflicts with file generation flags */
1121 nflags
= cmd
->cflag
+ cmd
->hflag
+ cmd
->lflag
+ cmd
->mflag
+
1122 cmd
->sflag
+ cmd
->nflag
+ cmd
->tflag
+ cmd
->Ssflag
+
1123 cmd
->Scflag
+ cmd
->makefileflag
;
1126 if (cmd
->outfile
!= NULL
|| cmd
->infile
== NULL
)
1128 } else if (cmd
->infile
== NULL
&&
1129 (cmd
->Ssflag
|| cmd
->Scflag
|| cmd
->makefileflag
)) {
1130 warnx("\"infile\" is required for template generation flags");
1133 warnx("cannot have more than one file generation flag");
1142 f_print(stderr
, "%s\n%s\n%s\n%s\n%s\n",
1143 "usage: rpcgen infile",
1144 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]"
1145 "[-I [-K seconds]] [-Y path] infile",
1146 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]"
1147 "[-o outfile] [infile]",
1148 " rpcgen [-s nettype]* [-o outfile] [infile]",
1149 " rpcgen [-n netid]* [-o outfile] [infile]");
1157 f_print(stderr
, "options:\n");
1158 f_print(stderr
, "-a\t\tgenerate all files, including samples\n");
1159 f_print(stderr
, "-b\t\tbackward compatibility mode (generates code"
1160 "for SunOS 4.X)\n");
1161 f_print(stderr
, "-c\t\tgenerate XDR routines\n");
1162 f_print(stderr
, "-C\t\tANSI C mode\n");
1163 f_print(stderr
, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1164 f_print(stderr
, "-h\t\tgenerate header file\n");
1165 f_print(stderr
, "-i size\t\tsize at which to start generating"
1167 f_print(stderr
, "-I\t\tgenerate code for inetd support in server"
1168 "(for SunOS 4.X)\n");
1169 f_print(stderr
, "-K seconds\tserver exits after K seconds of"
1171 f_print(stderr
, "-l\t\tgenerate client side stubs\n");
1172 f_print(stderr
, "-L\t\tserver errors will be printed to syslog\n");
1173 f_print(stderr
, "-m\t\tgenerate server side stubs\n");
1174 f_print(stderr
, "-M\t\tgenerate MT-safe code\n");
1175 f_print(stderr
, "-n netid\tgenerate server code that supports"
1177 f_print(stderr
, "-N\t\tsupports multiple arguments and"
1179 f_print(stderr
, "-o outfile\tname of the output file\n");
1180 f_print(stderr
, "-s nettype\tgenerate server code that supports named"
1182 f_print(stderr
, "-Sc\t\tgenerate sample client code that uses remote"
1184 f_print(stderr
, "-Ss\t\tgenerate sample server code that defines"
1185 "remote procedures\n");
1186 f_print(stderr
, "-Sm \t\tgenerate makefile template \n");
1188 f_print(stderr
, "-t\t\tgenerate RPC dispatch table\n");
1189 f_print(stderr
, "-T\t\tgenerate code to support RPC dispatch tables\n");
1190 f_print(stderr
, "-Y path\t\tpath where cpp is found\n");