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.2 2003/06/17 04:29:31 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 __P(( definition * ));
56 extern int write_sample_clnt __P(( definition * ));
57 extern void write_sample_clnt_main __P(( void ));
58 extern void add_sample_msg __P(( void ));
59 static void c_output __P(( char *, char *, int, char * ));
60 static void h_output __P(( char *, char *, int, char * ));
61 static void l_output __P(( char *, char *, int, char * ));
62 static void t_output __P(( char *, char *, int, char * ));
63 static void clnt_output __P(( char *, char *, int, char * ));
65 void c_initialize __P(( void ));
67 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
71 static void usage __P(( void ));
72 static void options_usage __P (( void ));
73 static int do_registers __P(( int, char ** ));
74 static int parseargs __P(( int, char **, struct commandline * ));
75 static void svc_output __P(( char *, char *, int, char * ));
76 static void mkfile_output __P(( struct commandline * ));
77 static void s_output __P(( int, char **, char *, char *, int, 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"
84 #define SUNOS_CPP "/usr/libexec/cpp"
85 #elif defined(__NetBSD__)
86 #define SUNOS_CPP "/usr/bin/cpp"
88 #define SUNOS_CPP "/usr/lib/cpp"
91 static int cppDefined = 0; /* explicit path for C preprocessor */
93 static char *svcclosetime = "120";
94 static char *CPP = SVR4_CPP;
95 static char CPPFLAGS[] = "-C";
96 static char pathbuf[MAXPATHLEN + 1];
97 static char *allv[] = {
98 "rpcgen", "-s", "udp", "-s", "tcp",
100 static int allc = sizeof (allv)/sizeof (allv[0]);
101 static char *allnv[] = {
102 "rpcgen", "-s", "netpath",
104 static int allnc = sizeof (allnv)/sizeof (allnv[0]);
107 * machinations for handling expanding argument list
109 static void addarg(); /* add another argument to the list */
110 static void putarg(); /* put argument at specified location */
111 static void clear_args(); /* clear argument list */
112 static void checkfiles(); /* check if out file already exists */
116 #define ARGLISTLEN 20
119 static char *arglist[ARGLISTLEN];
120 static int argcount = FIXEDARGS;
123 int nonfatalerrors; /* errors */
124 #if defined(__FreeBSD__) || defined(__NetBSD__)
125 int inetdflag = 0; /* Support for inetd is now the default */
127 int inetdflag; /* Support for inetd is now the default */
129 int pmflag; /* Support for port monitors */
130 int logflag; /* Use syslog instead of fprintf for errors */
131 int tblflag; /* Support for dispatch table file */
132 int mtflag = 0; /* Support for MT */
133 #if defined(__FreeBSD__) || defined(__NetBSD__)
138 /* length at which to start doing an inline */
142 * Length at which to start doing an inline. INLINE = default
143 * if 0, no xdr_inline code
146 int indefinitewait; /* If started by port monitors, hang till it wants */
147 int exitnow; /* If started by port monitors, exit after the call */
148 int timerflag; /* TRUE if !indefinite && !exitnow */
149 int newstyle; /* newstyle of passing arguments (by value) */
150 int Cflag = 0; /* ANSI C syntax */
151 int CCflag = 0; /* C++ files */
152 static int allfiles; /* generate all files */
153 #if defined(__FreeBSD__) || defined(__NetBSD__)
154 int tirpcflag = 0; /* generating code for tirpc, by default */
156 int tirpcflag = 1; /* generating code for tirpc, by default */
158 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
159 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
168 struct commandline cmd;
170 (void) memset((char *)&cmd, 0, sizeof (struct commandline));
172 if (!parseargs(argc, argv, &cmd))
175 * Only the client and server side stubs are likely to be customized,
176 * so in that case only, check if the outfile exists, and if so,
177 * print an error message and exit.
179 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
180 checkfiles(cmd.infile, cmd.outfile);
183 checkfiles(cmd.infile, NULL);
186 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
187 } else if (cmd.hflag) {
188 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
189 } else if (cmd.lflag) {
190 l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
191 } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
192 s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
193 cmd.outfile, cmd.mflag, cmd.nflag);
194 } else if (cmd.tflag) {
195 t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
196 } else if (cmd.Ssflag) {
197 svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
199 } else if (cmd.Scflag) {
200 clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
202 } else if (cmd.makefileflag) {
205 /* the rescans are required, since cpp may effect input */
206 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
208 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
210 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
212 if (inetdflag || !tirpcflag)
213 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
214 "_svc.c", cmd.mflag, cmd.nflag);
216 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
217 EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
220 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
225 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
228 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
232 if (allfiles || (cmd.makefileflag == 1)){
238 exit(nonfatalerrors);
244 * add extension to filename
247 #if defined(__FreeBSD__) || defined(__NetBSD__)
248 extendfile(path, ext)
251 extendfile(file, ext)
258 #if defined(__FreeBSD__) || defined(__NetBSD__)
261 if ((file = rindex(path, '/')) == NULL)
266 res = alloc(strlen(file) + strlen(ext) + 1);
270 p = strrchr(file, '.');
272 p = file + strlen(file);
274 (void) strcpy(res, file);
275 (void) strcpy(res + (p - file), ext);
280 * Open output file with given extension
283 open_output(infile, outfile)
288 if (outfile == NULL) {
293 if (infile != NULL && streq(outfile, infile)) {
294 warnx("%s already exists. No output generated", infile);
297 fout = fopen(outfile, "w");
299 warn("unable to open %s", outfile);
302 record_open(outfile);
310 f_print(fout, "/*\n");
311 f_print(fout, " * Please do not edit this file.\n");
312 f_print(fout, " * It was generated using rpcgen.\n");
313 f_print(fout, " */\n\n");
316 /* clear list of arguments */
317 static void clear_args()
320 for (i = FIXEDARGS; i < ARGLISTLEN; i++)
322 argcount = FIXEDARGS;
325 /* make sure that a CPP exists */
326 static void find_cpp()
330 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
332 warnx("cannot find C preprocessor: %s", CPP);
334 } else { /* try the other one */
336 if (stat(CPP, &buf) < 0) { /* can't find any cpp */
337 warnx("cannot find any C preprocessor (cpp)");
345 * Open input file with given define for C-preprocessor
348 open_input(infile, define)
354 infilename = (infile == NULL) ? "<stdin>" : infile;
356 switch (childpid = fork()) {
364 addarg((char *)NULL);
366 (void) dup2(pd[1], 1);
368 execv(arglist[0], arglist);
376 fin = fdopen(pd[0], "r");
378 warn("%s", infilename);
383 /* valid tirpc nettypes */
384 static char* valid_ti_nettypes[] =
398 /* valid inetd nettypes */
399 static char* valid_i_nettypes[] =
406 static int check_nettype(name, list_to_check)
408 char* list_to_check[];
411 for (i = 0; list_to_check[i] != NULL; i++) {
412 if (strcmp(name, list_to_check[i]) == 0) {
416 warnx("illegal nettype :\'%s\'", name);
426 temp = extendfile(file, ext);
428 if (access(temp, F_OK) != -1)
431 return ((char *)" ");
437 c_output(infile, define, extend, outfile)
449 open_input(infile, define);
450 outfilename = extend ? extendfile(infile, outfile) : outfile;
451 open_output(infile, outfilename);
453 if (infile && (include = extendfile(infile, ".h"))) {
454 f_print(fout, "#include \"%s\"\n", include);
456 /* .h file already contains rpc/rpc.h */
458 f_print(fout, "#include <rpc/rpc.h>\n");
460 while ( (def = get_definition()) ) {
463 if (extend && tell == ftell(fout)) {
464 (void) unlink(outfilename);
473 /* add all the starting basic types */
476 add_type(1, "short");
478 add_type(1, "u_int");
479 add_type(1, "u_long");
480 add_type(1, "u_short");
484 char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
486 xdrproc_t xdr_arg; \n\
487 unsigned len_arg; \n\
488 xdrproc_t xdr_res; \n\
489 unsigned len_res; \n\
493 char *generate_guard(pathname)
496 char* filename, *guard, *tmp;
498 filename = strrchr(pathname, '/'); /* find last component */
499 filename = ((filename == 0) ? pathname : filename+1);
500 guard = strdup(filename);
501 /* convert to upper case */
505 *tmp = toupper(*tmp);
508 guard = extendfile(guard, "_H_RPCGEN");
513 * Compile into an XDR header file
518 h_output(infile, define, extend, outfile)
532 open_input(infile, define);
533 outfilename = extend ? extendfile(infile, outfile) : outfile;
534 open_output(infile, outfilename);
536 if (outfilename || infile){
537 guard = generate_guard(outfilename ? outfilename: infile);
541 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
544 f_print(fout, "#include <rpc/rpc.h>\n");
547 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
548 f_print(fout, "#include <synch.h>\n");
549 f_print(fout, "#include <thread.h>\n");
551 f_print(fout, "#include <pthread.h>\n");
555 /* put the C++ support */
556 if (Cflag && !CCflag){
557 f_print(fout, "\n#ifdef __cplusplus\n");
558 f_print(fout, "extern \"C\" {\n");
559 f_print(fout, "#endif\n\n");
562 /* put in a typedef for quadprecision. Only with Cflag */
566 /* print data definitions */
567 while ( (def = get_definition()) ) {
572 * print function declarations.
573 * Do this after data definitions because they might be used as
574 * arguments for functions
576 for (l = defined; l != NULL; l = l->next) {
577 print_funcdef(l->val);
579 /* Now print all xdr func declarations */
580 if (xdrfunc_head != NULL){
583 "\n/* the xdr functions */\n");
586 f_print(fout, "\n#ifdef __cplusplus\n");
587 f_print(fout, "extern \"C\" {\n");
588 f_print(fout, "#endif\n");
592 xdrfuncp = xdrfunc_head;
593 while (xdrfuncp != NULL){
594 print_xdr_func_def(xdrfuncp->name,
595 xdrfuncp->pointerp, 2);
596 xdrfuncp = xdrfuncp->next;
600 for (i = 1; i < 3; i++){
602 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
605 f_print(fout, "\n#else /* K&R C */\n");
607 xdrfuncp = xdrfunc_head;
608 while (xdrfuncp != NULL){
609 print_xdr_func_def(xdrfuncp->name,
610 xdrfuncp->pointerp, i);
611 xdrfuncp = xdrfuncp->next;
614 f_print(fout, "\n#endif /* K&R C */\n");
618 if (extend && tell == ftell(fout)) {
619 (void) unlink(outfilename);
620 } else if (tblflag) {
621 f_print(fout, rpcgen_table_dcl);
625 f_print(fout, "\n#ifdef __cplusplus\n");
626 f_print(fout, "}\n");
627 f_print(fout, "#endif\n");
630 f_print(fout, "\n#endif /* !_%s */\n", guard);
634 * Compile into an RPC service
637 s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
649 int foundprogram = 0;
652 open_input(infile, define);
653 outfilename = extend ? extendfile(infile, outfile) : outfile;
654 open_output(infile, outfilename);
656 if (infile && (include = extendfile(infile, ".h"))) {
657 f_print(fout, "#include \"%s\"\n", include);
660 f_print(fout, "#include <rpc/rpc.h>\n");
662 f_print(fout, "#include <stdio.h>\n");
663 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
666 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
667 f_print (fout, "#include <string.h> /* strcmp */\n");
669 if (strcmp(svcclosetime, "-1") == 0)
671 else if (strcmp(svcclosetime, "0") == 0)
673 else if (inetdflag || pmflag) {
674 f_print(fout, "#include <signal.h>\n");
678 if (!tirpcflag && inetdflag)
679 f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
680 if (Cflag && (inetdflag || pmflag)) {
681 f_print(fout, "#ifdef __cplusplus\n");
683 "#include <sysent.h> /* getdtablesize, open */\n");
684 f_print(fout, "#endif /* __cplusplus */\n");
686 f_print(fout, "#include <unistd.h> /* setsid */\n");
689 f_print(fout, "#include <sys/types.h>\n");
691 f_print(fout, "#include <memory.h>\n");
692 #if defined(__FreeBSD__) || defined(__NetBSD__)
695 f_print(fout, "#include <stropts.h>\n");
696 if (inetdflag || !tirpcflag) {
697 f_print(fout, "#include <sys/socket.h>\n");
698 f_print(fout, "#include <netinet/in.h>\n");
701 if ((netflag || pmflag) && tirpcflag && !nomain) {
702 f_print(fout, "#include <netconfig.h>\n");
705 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
706 if (logflag || inetdflag || pmflag)
707 f_print(fout, "#include <syslog.h>\n");
712 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
715 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
717 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
719 while ( (def = get_definition()) ) {
720 foundprogram |= (def->def_kind == DEF_PROGRAM);
722 if (extend && !foundprogram) {
723 (void) unlink(outfilename);
726 write_most(infile, netflag, nomain);
728 if (!do_registers(argc, argv)) {
730 (void) unlink(outfilename);
738 * generate client side stubs
741 l_output(infile, define, extend, outfile)
749 int foundprogram = 0;
752 open_input(infile, define);
753 outfilename = extend ? extendfile(infile, outfile) : outfile;
754 open_output(infile, outfilename);
757 f_print (fout, "#include <memory.h> /* for memset */\n");
758 if (infile && (include = extendfile(infile, ".h"))) {
759 f_print(fout, "#include \"%s\"\n", include);
762 f_print(fout, "#include <rpc/rpc.h>\n");
763 while ( (def = get_definition()) ) {
764 foundprogram |= (def->def_kind == DEF_PROGRAM);
766 if (extend && !foundprogram) {
767 (void) unlink(outfilename);
774 * generate the dispatch table
777 t_output(infile, define, extend, outfile)
784 int foundprogram = 0;
787 open_input(infile, define);
788 outfilename = extend ? extendfile(infile, outfile) : outfile;
789 open_output(infile, outfilename);
791 while ( (def = get_definition()) ) {
792 foundprogram |= (def->def_kind == DEF_PROGRAM);
794 if (extend && !foundprogram) {
795 (void) unlink(outfilename);
801 /* sample routine for the server template */
803 svc_output(infile, define, extend, outfile)
813 open_input(infile, define);
814 outfilename = extend ? extendfile(infile, outfile) : outfile;
815 checkfiles(infile, outfilename);
817 * Check if outfile already exists.
818 * if so, print an error message and exit
820 open_output(infile, outfilename);
823 if (infile && (include = extendfile(infile, ".h"))) {
824 f_print(fout, "#include \"%s\"\n", include);
827 f_print(fout, "#include <rpc/rpc.h>\n");
830 while ( (def = get_definition()) ) {
831 write_sample_svc(def);
833 if (extend && tell == ftell(fout)) {
834 (void) unlink(outfilename);
838 /* sample main routine for client */
840 clnt_output(infile, define, extend, outfile)
852 open_input(infile, define);
853 outfilename = extend ? extendfile(infile, outfile) : outfile;
854 checkfiles(infile, outfilename);
856 * Check if outfile already exists.
857 * if so, print an error message and exit
860 open_output(infile, outfilename);
862 if (infile && (include = extendfile(infile, ".h"))) {
863 f_print(fout, "#include \"%s\"\n", include);
866 f_print(fout, "#include <rpc/rpc.h>\n");
868 while ( (def = get_definition()) ) {
869 has_program += write_sample_clnt(def);
873 write_sample_clnt_main();
875 if (extend && tell == ftell(fout)) {
876 (void) unlink(outfilename);
881 static void mkfile_output(cmd)
882 struct commandline *cmd;
884 char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
885 char *servername, *svcname, *servprogname, *clntprogname;
888 svcname = file_name(cmd->infile, "_svc.c");
889 clntname = file_name(cmd->infile, "_clnt.c");
890 xdrname = file_name(cmd->infile, "_xdr.c");
891 hdrname = file_name(cmd->infile, ".h");
895 servername = extendfile(cmd->infile, "_server.c");
896 clientname = extendfile(cmd->infile, "_client.c");
901 servprogname = extendfile(cmd->infile, "_server");
902 clntprogname = extendfile(cmd->infile, "_client");
905 mkfilename = alloc(strlen("makefile.") +
906 strlen(cmd->infile) + 1);
907 temp = (char *)rindex(cmd->infile, '.');
908 strcat(mkfilename, "makefile.");
909 (void) strncat(mkfilename, cmd->infile,
910 (temp - cmd->infile));
912 mkfilename = cmd->outfile;
915 checkfiles(NULL, mkfilename);
916 open_output(NULL, mkfilename);
918 f_print(fout, "\n# This is a template makefile generated\
921 f_print(fout, "\n# Parameters \n\n");
923 f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
924 clntprogname, servprogname);
925 f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
926 f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
927 f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
928 f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
929 svcname, servername, xdrname);
930 f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
931 clntname, clientname, xdrname);
932 f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
933 hdrname, xdrname, clntname,
934 svcname, clientname, servername);
936 f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
937 $(TARGETS_CLNT.c:%%.c=%%.o) ");
939 f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
940 $(TARGETS_SVC.c:%%.c=%%.o) ");
943 f_print(fout, "\n# Compiler flags \n");
945 f_print(fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS += -lnsl -lthread\n");
947 #if defined(__FreeBSD__) || defined(__NetBSD__)
948 f_print(fout, "\nCFLAGS += -g \nLDLIBS +=\n");
950 f_print(fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
952 f_print(fout, "RPCGENFLAGS = \n");
954 f_print(fout, "\n# Targets \n\n");
956 f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
957 f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
958 f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
959 f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
960 $(TARGETS_CLNT.c) \n\n");
962 f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
963 $(TARGETS_SVC.c) \n\n");
964 f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
965 #if defined(__FreeBSD__) || defined(__NetBSD__)
966 f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
969 f_print(fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
972 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
973 #if defined(__FreeBSD__) || defined(__NetBSD__)
974 f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
975 f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \
976 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
978 f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
979 f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
980 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
987 * Perform registrations for service output
988 * Return 0 if failed; 1 otherwise.
991 do_registers(argc, argv)
997 if (inetdflag || !tirpcflag) {
998 for (i = 1; i < argc; i++) {
999 if (streq(argv[i], "-s")) {
1000 if (!check_nettype(argv[i + 1],
1003 write_inetd_register(argv[i + 1]);
1008 for (i = 1; i < argc; i++)
1009 if (streq(argv[i], "-s")) {
1010 if (!check_nettype(argv[i + 1],
1013 write_nettype_register(argv[i + 1]);
1015 } else if (streq(argv[i], "-n")) {
1016 write_netid_register(argv[i + 1]);
1024 * Add another argument to the arg list
1030 if (argcount >= ARGLISTLEN) {
1031 warnx("too many defines");
1035 arglist[argcount++] = cp;
1044 if (where >= ARGLISTLEN) {
1045 warnx("arglist coding error");
1049 arglist[where] = cp;
1053 * if input file is stdin and an output file is specified then complain
1054 * if the file already exists. Otherwise the file may get overwritten
1055 * If input file does not exist, exit with an error
1059 checkfiles(infile, outfile)
1066 if (infile) /* infile ! = NULL */
1067 if (stat(infile, &buf) < 0)
1073 if (stat(outfile, &buf) < 0)
1074 return; /* file does not exist */
1076 warnx("file '%s' already exists and may be overwritten", outfile);
1083 * Parse command line arguments
1086 parseargs(argc, argv, cmd)
1089 struct commandline *cmd;
1094 char flag[(1 << 8 * sizeof (char))];
1097 cmd->infile = cmd->outfile = NULL;
1114 for (i = 1; i < argc; i++) {
1115 if (argv[i][0] != '-') {
1117 warnx("cannot specify more than one input file");
1120 cmd->infile = argv[i];
1122 for (j = 1; argv[i][j] != 0; j++) {
1140 * sample flag: Ss or Sc.
1141 * Ss means set flag['S'];
1142 * Sc means set flag['C'];
1143 * Sm means set flag['M'];
1145 ch = argv[i][++j]; /* get next char */
1155 if (flag[(int)ch]) {
1160 case 'C': /* ANSI C syntax */
1162 ch = argv[i][j+1]; /* get next char */
1170 * Turn TIRPC flag off for
1171 * generating backward compatible
1174 #if defined(__FreeBSD__) || defined(__NetBSD__)
1194 svcclosetime = argv[i];
1206 inline = atoi(argv[i]);
1211 if (argv[i][j - 1] != '-' ||
1212 argv[i][j + 1] != 0) {
1223 cmd->outfile = argv[i];
1227 if (argv[i][j - 1] != '-') {
1230 (void) addarg(argv[i]);
1236 (void) strcpy(pathbuf, argv[i]);
1237 (void) strcat(pathbuf, "/cpp");
1253 cmd->cflag = flag['c'];
1254 cmd->hflag = flag['h'];
1255 cmd->lflag = flag['l'];
1256 cmd->mflag = flag['m'];
1257 cmd->nflag = flag['n'];
1258 cmd->sflag = flag['s'];
1259 cmd->tflag = flag['t'];
1260 cmd->Ssflag = flag['S'];
1261 cmd->Scflag = flag['C'];
1262 cmd->makefileflag = flag['M'];
1265 pmflag = inetdflag ? 0 : 1;
1266 /* pmflag or inetdflag is always TRUE */
1267 if ((inetdflag && cmd->nflag)) {
1268 /* netid not allowed with inetdflag */
1269 warnx("cannot use netid flag with inetd flag");
1272 } else { /* 4.1 mode */
1273 pmflag = 0; /* set pmflag only in tirpcmode */
1274 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
1275 inetdflag = 1; /* inetdflag is TRUE by default */
1277 if (cmd->nflag) { /* netid needs TIRPC */
1278 warnx("cannot use netid flag without TIRPC");
1283 if (newstyle && (tblflag || cmd->tflag)) {
1284 warnx("cannot use table flags with newstyle");
1288 /* check no conflicts with file generation flags */
1289 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1290 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1291 cmd->Scflag + cmd->makefileflag;
1294 if (cmd->outfile != NULL || cmd->infile == NULL) {
1297 } else if (cmd->infile == NULL &&
1298 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1299 warnx("\"infile\" is required for template generation flags");
1302 warnx("cannot have more than one file generation flag");
1311 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1312 "usage: rpcgen infile",
1313 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1314 [-I [-K seconds]] [-Y path] infile",
1315 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1316 [-o outfile] [infile]",
1317 " rpcgen [-s nettype]* [-o outfile] [infile]",
1318 " rpcgen [-n netid]* [-o outfile] [infile]");
1326 f_print(stderr, "options:\n");
1327 f_print(stderr, "-a\t\tgenerate all files, including samples\n");
1328 f_print(stderr, "-b\t\tbackward compatibility mode (generates code\
1330 f_print(stderr, "-c\t\tgenerate XDR routines\n");
1331 f_print(stderr, "-C\t\tANSI C mode\n");
1332 f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1333 f_print(stderr, "-h\t\tgenerate header file\n");
1334 f_print(stderr, "-i size\t\tsize at which to start generating\
1336 f_print(stderr, "-I\t\tgenerate code for inetd support in server\
1337 (for SunOS 4.X)\n");
1338 f_print(stderr, "-K seconds\tserver exits after K seconds of\
1340 f_print(stderr, "-l\t\tgenerate client side stubs\n");
1341 f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
1342 f_print(stderr, "-m\t\tgenerate server side stubs\n");
1343 f_print(stderr, "-M\t\tgenerate MT-safe code\n");
1344 f_print(stderr, "-n netid\tgenerate server code that supports\
1346 f_print(stderr, "-N\t\tsupports multiple arguments and\
1348 f_print(stderr, "-o outfile\tname of the output file\n");
1349 f_print(stderr, "-s nettype\tgenerate server code that supports named\
1351 f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\
1353 f_print(stderr, "-Ss\t\tgenerate sample server code that defines\
1354 remote procedures\n");
1355 f_print(stderr, "-Sm \t\tgenerate makefile template \n");
1357 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
1358 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
1359 f_print(stderr, "-Y path\t\tpath where cpp is found\n");
1363 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
1366 register char *sp, c;