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.8 2004/02/02 05:43:16 dillon 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 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
71 static void usage( void );
72 static void options_usage( void );
73 static int do_registers( int, char ** );
74 static int parseargs( int, char **, struct commandline * );
75 static void svc_output( char *, char *, int, char * );
76 static void mkfile_output( struct commandline * );
77 static void s_output( int, char **, char *, char *, int, char *, int, int );
79 #define EXTEND 1 /* alias for TRUE */
80 #define DONT_EXTEND 0 /* alias for FALSE */
82 static int cppDefined = 0; /* explicit path for C preprocessor */
84 static char *svcclosetime = "120";
85 static char *CPP = NULL;
86 static char CPPFLAGS[] = "-C";
87 static char pathbuf[MAXPATHLEN + 1];
88 static char *allv[] = {
89 "rpcgen", "-s", "udp", "-s", "tcp",
91 static int allc = sizeof (allv)/sizeof (allv[0]);
92 static char *allnv[] = {
93 "rpcgen", "-s", "netpath",
95 static int allnc = sizeof (allnv)/sizeof (allnv[0]);
98 * machinations for handling expanding argument list
100 static void addarg(); /* add another argument to the list */
101 static void putarg(); /* put argument at specified location */
102 static void clear_args(); /* clear argument list */
103 static void checkfiles(); /* check if out file already exists */
107 #define ARGLISTLEN 20
110 static char *arglist[ARGLISTLEN];
111 static int argcount = FIXEDARGS;
114 int nonfatalerrors; /* errors */
115 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__DragonFly__)
116 int inetdflag = 0; /* Support for inetd is now the default */
118 int inetdflag; /* Support for inetd is now the default */
120 int pmflag; /* Support for port monitors */
121 int logflag; /* Use syslog instead of fprintf for errors */
122 int tblflag; /* Support for dispatch table file */
123 int mtflag = 0; /* Support for MT */
124 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__DragonFly__)
129 /* length at which to start doing an inline */
133 * Length at which to start doing an inline. INLINE = default
134 * if 0, no xdr_inline code
137 int indefinitewait; /* If started by port monitors, hang till it wants */
138 int exitnow; /* If started by port monitors, exit after the call */
139 int timerflag; /* TRUE if !indefinite && !exitnow */
140 int newstyle; /* newstyle of passing arguments (by value) */
141 int Cflag = 0; /* ANSI C syntax */
142 int CCflag = 0; /* C++ files */
143 static int allfiles; /* generate all files */
144 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__DragonFly__)
145 int tirpcflag = 0; /* generating code for tirpc, by default */
147 int tirpcflag = 1; /* generating code for tirpc, by default */
149 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
150 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
159 struct commandline cmd;
161 (void) memset((char *)&cmd, 0, sizeof (struct commandline));
163 if (!parseargs(argc, argv, &cmd))
166 * Only the client and server side stubs are likely to be customized,
167 * so in that case only, check if the outfile exists, and if so,
168 * print an error message and exit.
170 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
171 checkfiles(cmd.infile, cmd.outfile);
174 checkfiles(cmd.infile, NULL);
177 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
178 } else if (cmd.hflag) {
179 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
180 } else if (cmd.lflag) {
181 l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
182 } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
183 s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
184 cmd.outfile, cmd.mflag, cmd.nflag);
185 } else if (cmd.tflag) {
186 t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
187 } else if (cmd.Ssflag) {
188 svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
190 } else if (cmd.Scflag) {
191 clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
193 } else if (cmd.makefileflag) {
196 /* the rescans are required, since cpp may effect input */
197 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
199 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
201 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
203 if (inetdflag || !tirpcflag)
204 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
205 "_svc.c", cmd.mflag, cmd.nflag);
207 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
208 EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
211 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
216 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
219 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
223 if (allfiles || (cmd.makefileflag == 1)){
229 exit(nonfatalerrors);
235 * add extension to filename
238 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__DragonFly__)
239 extendfile(path, ext)
242 extendfile(file, ext)
249 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__DragonFly__)
252 if ((file = rindex(path, '/')) == NULL)
257 res = alloc(strlen(file) + strlen(ext) + 1);
261 p = strrchr(file, '.');
263 p = file + strlen(file);
265 (void) strcpy(res, file);
266 (void) strcpy(res + (p - file), ext);
271 * Open output file with given extension
274 open_output(infile, outfile)
279 if (outfile == NULL) {
284 if (infile != NULL && streq(outfile, infile)) {
285 warnx("%s already exists. No output generated", infile);
288 fout = fopen(outfile, "w");
290 warn("unable to open %s", outfile);
293 record_open(outfile);
301 f_print(fout, "/*\n");
302 f_print(fout, " * Please do not edit this file.\n");
303 f_print(fout, " * It was generated using rpcgen.\n");
304 f_print(fout, " */\n\n");
307 /* clear list of arguments */
308 static void clear_args()
311 for (i = FIXEDARGS; i < ARGLISTLEN; i++)
313 argcount = FIXEDARGS;
316 /* make sure that a CPP exists */
317 static int find_cpp()
326 * Open input file with given define for C-preprocessor
329 open_input(infile, define)
336 infilename = (infile == NULL) ? "<stdin>" : infile;
338 switch (childpid = fork()) {
346 addarg((char *)NULL);
348 (void) dup2(pd[1], 1);
351 execvp(arglist[0], arglist);
353 execv(arglist[0], arglist);
361 fin = fdopen(pd[0], "r");
363 warn("%s", infilename);
368 /* valid tirpc nettypes */
369 static char* valid_ti_nettypes[] =
383 /* valid inetd nettypes */
384 static char* valid_i_nettypes[] =
391 static int check_nettype(name, list_to_check)
393 char* list_to_check[];
396 for (i = 0; list_to_check[i] != NULL; i++) {
397 if (strcmp(name, list_to_check[i]) == 0) {
401 warnx("illegal nettype :\'%s\'", name);
411 temp = extendfile(file, ext);
413 if (access(temp, F_OK) != -1)
416 return ((char *)" ");
422 c_output(infile, define, extend, outfile)
434 open_input(infile, define);
435 outfilename = extend ? extendfile(infile, outfile) : outfile;
436 open_output(infile, outfilename);
438 if (infile && (include = extendfile(infile, ".h"))) {
439 f_print(fout, "#include \"%s\"\n", include);
441 /* .h file already contains rpc/rpc.h */
443 f_print(fout, "#include <rpc/rpc.h>\n");
445 while ( (def = get_definition()) ) {
448 if (extend && tell == ftell(fout)) {
449 (void) unlink(outfilename);
458 /* add all the starting basic types */
461 add_type(1, "short");
463 add_type(1, "u_int");
464 add_type(1, "u_long");
465 add_type(1, "u_short");
469 char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
471 xdrproc_t xdr_arg; \n\
472 unsigned len_arg; \n\
473 xdrproc_t xdr_res; \n\
474 unsigned len_res; \n\
478 char *generate_guard(pathname)
481 char* filename, *guard, *tmp;
483 filename = strrchr(pathname, '/'); /* find last component */
484 filename = ((filename == 0) ? pathname : filename+1);
485 guard = strdup(filename);
486 /* convert to upper case */
490 *tmp = toupper(*tmp);
493 guard = extendfile(guard, "_H_RPCGEN");
498 * Compile into an XDR header file
503 h_output(infile, define, extend, outfile)
517 open_input(infile, define);
518 outfilename = extend ? extendfile(infile, outfile) : outfile;
519 open_output(infile, outfilename);
521 if (outfilename || infile){
522 guard = generate_guard(outfilename ? outfilename: infile);
526 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
529 f_print(fout, "#include <rpc/rpc.h>\n");
532 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
533 f_print(fout, "#include <synch.h>\n");
534 f_print(fout, "#include <thread.h>\n");
536 f_print(fout, "#include <pthread.h>\n");
540 /* put the C++ support */
541 if (Cflag && !CCflag){
542 f_print(fout, "\n#ifdef __cplusplus\n");
543 f_print(fout, "extern \"C\" {\n");
544 f_print(fout, "#endif\n\n");
547 /* put in a typedef for quadprecision. Only with Cflag */
551 /* print data definitions */
552 while ( (def = get_definition()) ) {
557 * print function declarations.
558 * Do this after data definitions because they might be used as
559 * arguments for functions
561 for (l = defined; l != NULL; l = l->next) {
562 print_funcdef(l->val);
564 /* Now print all xdr func declarations */
565 if (xdrfunc_head != NULL){
568 "\n/* the xdr functions */\n");
571 f_print(fout, "\n#ifdef __cplusplus\n");
572 f_print(fout, "extern \"C\" {\n");
573 f_print(fout, "#endif\n");
577 xdrfuncp = xdrfunc_head;
578 while (xdrfuncp != NULL){
579 print_xdr_func_def(xdrfuncp->name,
580 xdrfuncp->pointerp, 2);
581 xdrfuncp = xdrfuncp->next;
585 for (i = 1; i < 3; i++){
587 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
590 f_print(fout, "\n#else /* K&R C */\n");
592 xdrfuncp = xdrfunc_head;
593 while (xdrfuncp != NULL){
594 print_xdr_func_def(xdrfuncp->name,
595 xdrfuncp->pointerp, i);
596 xdrfuncp = xdrfuncp->next;
599 f_print(fout, "\n#endif /* K&R C */\n");
603 if (extend && tell == ftell(fout)) {
604 (void) unlink(outfilename);
605 } else if (tblflag) {
606 f_print(fout, rpcgen_table_dcl);
610 f_print(fout, "\n#ifdef __cplusplus\n");
611 f_print(fout, "}\n");
612 f_print(fout, "#endif\n");
615 f_print(fout, "\n#endif /* !_%s */\n", guard);
619 * Compile into an RPC service
622 s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
634 int foundprogram = 0;
637 open_input(infile, define);
638 outfilename = extend ? extendfile(infile, outfile) : outfile;
639 open_output(infile, outfilename);
641 if (infile && (include = extendfile(infile, ".h"))) {
642 f_print(fout, "#include \"%s\"\n", include);
645 f_print(fout, "#include <rpc/rpc.h>\n");
647 f_print(fout, "#include <stdio.h>\n");
648 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
651 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
652 f_print (fout, "#include <string.h> /* strcmp */\n");
654 if (strcmp(svcclosetime, "-1") == 0)
656 else if (strcmp(svcclosetime, "0") == 0)
658 else if (inetdflag || pmflag) {
659 f_print(fout, "#include <signal.h>\n");
663 if (!tirpcflag && inetdflag)
664 f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
665 if (Cflag && (inetdflag || pmflag)) {
666 f_print(fout, "#ifdef __cplusplus\n");
668 "#include <sysent.h> /* getdtablesize, open */\n");
669 f_print(fout, "#endif /* __cplusplus */\n");
671 f_print(fout, "#include <unistd.h> /* setsid */\n");
674 f_print(fout, "#include <sys/types.h>\n");
676 f_print(fout, "#include <memory.h>\n");
677 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
680 f_print(fout, "#include <stropts.h>\n");
681 if (inetdflag || !tirpcflag) {
682 f_print(fout, "#include <sys/socket.h>\n");
683 f_print(fout, "#include <netinet/in.h>\n");
686 if ((netflag || pmflag) && tirpcflag && !nomain) {
687 f_print(fout, "#include <netconfig.h>\n");
690 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
691 if (logflag || inetdflag || pmflag)
692 f_print(fout, "#include <syslog.h>\n");
697 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
700 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
702 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
704 while ( (def = get_definition()) ) {
705 foundprogram |= (def->def_kind == DEF_PROGRAM);
707 if (extend && !foundprogram) {
708 (void) unlink(outfilename);
711 write_most(infile, netflag, nomain);
713 if (!do_registers(argc, argv)) {
715 (void) unlink(outfilename);
723 * generate client side stubs
726 l_output(infile, define, extend, outfile)
734 int foundprogram = 0;
737 open_input(infile, define);
738 outfilename = extend ? extendfile(infile, outfile) : outfile;
739 open_output(infile, outfilename);
742 f_print (fout, "#include <memory.h> /* for memset */\n");
743 if (infile && (include = extendfile(infile, ".h"))) {
744 f_print(fout, "#include \"%s\"\n", include);
747 f_print(fout, "#include <rpc/rpc.h>\n");
748 while ( (def = get_definition()) ) {
749 foundprogram |= (def->def_kind == DEF_PROGRAM);
751 if (extend && !foundprogram) {
752 (void) unlink(outfilename);
759 * generate the dispatch table
762 t_output(infile, define, extend, outfile)
769 int foundprogram = 0;
772 open_input(infile, define);
773 outfilename = extend ? extendfile(infile, outfile) : outfile;
774 open_output(infile, outfilename);
776 while ( (def = get_definition()) ) {
777 foundprogram |= (def->def_kind == DEF_PROGRAM);
779 if (extend && !foundprogram) {
780 (void) unlink(outfilename);
786 /* sample routine for the server template */
788 svc_output(infile, define, extend, outfile)
798 open_input(infile, define);
799 outfilename = extend ? extendfile(infile, outfile) : outfile;
800 checkfiles(infile, outfilename);
802 * Check if outfile already exists.
803 * if so, print an error message and exit
805 open_output(infile, outfilename);
808 if (infile && (include = extendfile(infile, ".h"))) {
809 f_print(fout, "#include \"%s\"\n", include);
812 f_print(fout, "#include <rpc/rpc.h>\n");
815 while ( (def = get_definition()) ) {
816 write_sample_svc(def);
818 if (extend && tell == ftell(fout)) {
819 (void) unlink(outfilename);
823 /* sample main routine for client */
825 clnt_output(infile, define, extend, outfile)
837 open_input(infile, define);
838 outfilename = extend ? extendfile(infile, outfile) : outfile;
839 checkfiles(infile, outfilename);
841 * Check if outfile already exists.
842 * if so, print an error message and exit
845 open_output(infile, outfilename);
847 if (infile && (include = extendfile(infile, ".h"))) {
848 f_print(fout, "#include \"%s\"\n", include);
851 f_print(fout, "#include <rpc/rpc.h>\n");
853 while ( (def = get_definition()) ) {
854 has_program += write_sample_clnt(def);
858 write_sample_clnt_main();
860 if (extend && tell == ftell(fout)) {
861 (void) unlink(outfilename);
866 static void mkfile_output(cmd)
867 struct commandline *cmd;
869 char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
870 char *servername, *svcname, *servprogname, *clntprogname;
873 svcname = file_name(cmd->infile, "_svc.c");
874 clntname = file_name(cmd->infile, "_clnt.c");
875 xdrname = file_name(cmd->infile, "_xdr.c");
876 hdrname = file_name(cmd->infile, ".h");
880 servername = extendfile(cmd->infile, "_server.c");
881 clientname = extendfile(cmd->infile, "_client.c");
886 servprogname = extendfile(cmd->infile, "_server");
887 clntprogname = extendfile(cmd->infile, "_client");
890 mkfilename = alloc(strlen("makefile.") +
891 strlen(cmd->infile) + 1);
892 temp = (char *)rindex(cmd->infile, '.');
893 strcat(mkfilename, "makefile.");
894 (void) strncat(mkfilename, cmd->infile,
895 (temp - cmd->infile));
897 mkfilename = cmd->outfile;
900 checkfiles(NULL, mkfilename);
901 open_output(NULL, mkfilename);
903 f_print(fout, "\n# This is a template makefile generated\
906 f_print(fout, "\n# Parameters \n\n");
908 f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
909 clntprogname, servprogname);
910 f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
911 f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
912 f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
913 f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
914 svcname, servername, xdrname);
915 f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
916 clntname, clientname, xdrname);
917 f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
918 hdrname, xdrname, clntname,
919 svcname, clientname, servername);
921 f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
922 $(TARGETS_CLNT.c:%%.c=%%.o) ");
924 f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
925 $(TARGETS_SVC.c:%%.c=%%.o) ");
928 f_print(fout, "\n# Compiler flags \n");
930 f_print(fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS += -lnsl -lthread\n");
932 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
933 f_print(fout, "\nCFLAGS += -g \nLDLIBS +=\n");
935 f_print(fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
937 f_print(fout, "RPCGENFLAGS = \n");
939 f_print(fout, "\n# Targets \n\n");
941 f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
942 f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
943 f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
944 f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
945 $(TARGETS_CLNT.c) \n\n");
947 f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
948 $(TARGETS_SVC.c) \n\n");
949 f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
950 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
951 f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
954 f_print(fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
957 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
958 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
959 f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
960 f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \
961 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
963 f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
964 f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
965 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
972 * Perform registrations for service output
973 * Return 0 if failed; 1 otherwise.
976 do_registers(argc, argv)
982 if (inetdflag || !tirpcflag) {
983 for (i = 1; i < argc; i++) {
984 if (streq(argv[i], "-s")) {
985 if (!check_nettype(argv[i + 1],
988 write_inetd_register(argv[i + 1]);
993 for (i = 1; i < argc; i++)
994 if (streq(argv[i], "-s")) {
995 if (!check_nettype(argv[i + 1],
998 write_nettype_register(argv[i + 1]);
1000 } else if (streq(argv[i], "-n")) {
1001 write_netid_register(argv[i + 1]);
1009 * Add another argument to the arg list
1015 if (argcount >= ARGLISTLEN) {
1016 warnx("too many defines");
1020 arglist[argcount++] = cp;
1029 if (where >= ARGLISTLEN) {
1030 warnx("arglist coding error");
1034 arglist[where] = cp;
1038 * if input file is stdin and an output file is specified then complain
1039 * if the file already exists. Otherwise the file may get overwritten
1040 * If input file does not exist, exit with an error
1044 checkfiles(infile, outfile)
1051 if (infile) /* infile ! = NULL */
1052 if (stat(infile, &buf) < 0)
1058 if (stat(outfile, &buf) < 0)
1059 return; /* file does not exist */
1061 warnx("file '%s' already exists and may be overwritten", outfile);
1068 * Parse command line arguments
1071 parseargs(argc, argv, cmd)
1074 struct commandline *cmd;
1079 char flag[(1 << 8 * sizeof (char))];
1082 cmd->infile = cmd->outfile = NULL;
1099 for (i = 1; i < argc; i++) {
1100 if (argv[i][0] != '-') {
1102 warnx("cannot specify more than one input file");
1105 cmd->infile = argv[i];
1107 for (j = 1; argv[i][j] != 0; j++) {
1125 * sample flag: Ss or Sc.
1126 * Ss means set flag['S'];
1127 * Sc means set flag['C'];
1128 * Sm means set flag['M'];
1130 ch = argv[i][++j]; /* get next char */
1140 if (flag[(int)ch]) {
1145 case 'C': /* ANSI C syntax */
1147 ch = argv[i][j+1]; /* get next char */
1155 * Turn TIRPC flag off for
1156 * generating backward compatible
1159 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
1179 svcclosetime = argv[i];
1191 inline = atoi(argv[i]);
1196 if (argv[i][j - 1] != '-' ||
1197 argv[i][j + 1] != 0) {
1208 cmd->outfile = argv[i];
1212 if (argv[i][j - 1] != '-') {
1215 (void) addarg(argv[i]);
1221 (void) strcpy(pathbuf, argv[i]);
1222 (void) strcat(pathbuf, "/cpp");
1238 cmd->cflag = flag['c'];
1239 cmd->hflag = flag['h'];
1240 cmd->lflag = flag['l'];
1241 cmd->mflag = flag['m'];
1242 cmd->nflag = flag['n'];
1243 cmd->sflag = flag['s'];
1244 cmd->tflag = flag['t'];
1245 cmd->Ssflag = flag['S'];
1246 cmd->Scflag = flag['C'];
1247 cmd->makefileflag = flag['M'];
1250 pmflag = inetdflag ? 0 : 1;
1251 /* pmflag or inetdflag is always TRUE */
1252 if ((inetdflag && cmd->nflag)) {
1253 /* netid not allowed with inetdflag */
1254 warnx("cannot use netid flag with inetd flag");
1257 } else { /* 4.1 mode */
1258 pmflag = 0; /* set pmflag only in tirpcmode */
1259 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
1260 inetdflag = 1; /* inetdflag is TRUE by default */
1262 if (cmd->nflag) { /* netid needs TIRPC */
1263 warnx("cannot use netid flag without TIRPC");
1268 if (newstyle && (tblflag || cmd->tflag)) {
1269 warnx("cannot use table flags with newstyle");
1273 /* check no conflicts with file generation flags */
1274 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1275 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1276 cmd->Scflag + cmd->makefileflag;
1279 if (cmd->outfile != NULL || cmd->infile == NULL) {
1282 } else if (cmd->infile == NULL &&
1283 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1284 warnx("\"infile\" is required for template generation flags");
1287 warnx("cannot have more than one file generation flag");
1296 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1297 "usage: rpcgen infile",
1298 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1299 [-I [-K seconds]] [-Y path] infile",
1300 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1301 [-o outfile] [infile]",
1302 " rpcgen [-s nettype]* [-o outfile] [infile]",
1303 " rpcgen [-n netid]* [-o outfile] [infile]");
1311 f_print(stderr, "options:\n");
1312 f_print(stderr, "-a\t\tgenerate all files, including samples\n");
1313 f_print(stderr, "-b\t\tbackward compatibility mode (generates code\
1315 f_print(stderr, "-c\t\tgenerate XDR routines\n");
1316 f_print(stderr, "-C\t\tANSI C mode\n");
1317 f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1318 f_print(stderr, "-h\t\tgenerate header file\n");
1319 f_print(stderr, "-i size\t\tsize at which to start generating\
1321 f_print(stderr, "-I\t\tgenerate code for inetd support in server\
1322 (for SunOS 4.X)\n");
1323 f_print(stderr, "-K seconds\tserver exits after K seconds of\
1325 f_print(stderr, "-l\t\tgenerate client side stubs\n");
1326 f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
1327 f_print(stderr, "-m\t\tgenerate server side stubs\n");
1328 f_print(stderr, "-M\t\tgenerate MT-safe code\n");
1329 f_print(stderr, "-n netid\tgenerate server code that supports\
1331 f_print(stderr, "-N\t\tsupports multiple arguments and\
1333 f_print(stderr, "-o outfile\tname of the output file\n");
1334 f_print(stderr, "-s nettype\tgenerate server code that supports named\
1336 f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\
1338 f_print(stderr, "-Ss\t\tgenerate sample server code that defines\
1339 remote procedures\n");
1340 f_print(stderr, "-Sm \t\tgenerate makefile template \n");
1342 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
1343 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
1344 f_print(stderr, "-Y path\t\tpath where cpp is found\n");
1348 #if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__Dragonfly__)
1351 register char *sp, c;