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
31 #ident "@(#)rpc_main.c 1.21 94/04/25 SMI"
35 static char sccsid[] = "@(#)rpc_main.c 1.30 89/03/30 (C) 1987 SMI";
37 static const char rcsid[] =
38 "$FreeBSD: src/usr.bin/rpcgen/rpc_main.c,v 1.11 1999/08/28 01:05:16 peter Exp $";
42 * rpc_main.c, Top level of the RPC protocol compiler.
43 * Copyright (C) 1987, Sun Microsystems, Inc.
51 #include <sys/types.h>
52 #include <sys/param.h>
55 #include "rpc_parse.h"
59 extern void write_sample_svc __P(( definition * ));
60 extern int write_sample_clnt __P(( definition * ));
61 extern void write_sample_clnt_main __P(( void ));
62 extern void add_sample_msg __P(( void ));
63 static void c_output __P(( char *, char *, int, char * ));
64 static void h_output __P(( char *, char *, int, char * ));
65 static void l_output __P(( char *, char *, int, char * ));
66 static void t_output __P(( char *, char *, int, char * ));
67 static void clnt_output __P(( char *, char *, int, char * ));
69 void c_initialize __P(( void ));
71 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
75 static void usage __P(( void ));
76 static void options_usage __P (( void ));
77 static int do_registers __P(( int, char ** ));
78 static int parseargs __P(( int, char **, struct commandline * ));
79 static void svc_output __P(( char *, char *, int, char * ));
80 static void mkfile_output __P(( struct commandline * ));
81 static void s_output __P(( int, char **, char *, char *, int, char *, int, int ));
83 #define EXTEND 1 /* alias for TRUE */
84 #define DONT_EXTEND 0 /* alias for FALSE */
86 #define SVR4_CPP "/usr/ccs/lib/cpp"
88 #define SUNOS_CPP "/usr/libexec/cpp"
89 #elif defined(__NetBSD__)
90 #define SUNOS_CPP "/usr/bin/cpp"
92 #define SUNOS_CPP "/usr/lib/cpp"
95 static int cppDefined = 0; /* explicit path for C preprocessor */
97 static char *svcclosetime = "120";
98 static char *CPP = SVR4_CPP;
99 static char CPPFLAGS[] = "-C";
100 static char pathbuf[MAXPATHLEN + 1];
101 static char *allv[] = {
102 "rpcgen", "-s", "udp", "-s", "tcp",
104 static int allc = sizeof (allv)/sizeof (allv[0]);
105 static char *allnv[] = {
106 "rpcgen", "-s", "netpath",
108 static int allnc = sizeof (allnv)/sizeof (allnv[0]);
111 * machinations for handling expanding argument list
113 static void addarg(); /* add another argument to the list */
114 static void putarg(); /* put argument at specified location */
115 static void clear_args(); /* clear argument list */
116 static void checkfiles(); /* check if out file already exists */
120 #define ARGLISTLEN 20
123 static char *arglist[ARGLISTLEN];
124 static int argcount = FIXEDARGS;
127 int nonfatalerrors; /* errors */
128 #if defined(__FreeBSD__) || defined(__NetBSD__)
129 int inetdflag = 0; /* Support for inetd is now the default */
131 int inetdflag; /* Support for inetd is now the default */
133 int pmflag; /* Support for port monitors */
134 int logflag; /* Use syslog instead of fprintf for errors */
135 int tblflag; /* Support for dispatch table file */
136 int mtflag = 0; /* Support for MT */
137 #if defined(__FreeBSD__) || defined(__NetBSD__)
142 /* length at which to start doing an inline */
146 * Length at which to start doing an inline. INLINE = default
147 * if 0, no xdr_inline code
150 int indefinitewait; /* If started by port monitors, hang till it wants */
151 int exitnow; /* If started by port monitors, exit after the call */
152 int timerflag; /* TRUE if !indefinite && !exitnow */
153 int newstyle; /* newstyle of passing arguments (by value) */
154 int Cflag = 0; /* ANSI C syntax */
155 int CCflag = 0; /* C++ files */
156 static int allfiles; /* generate all files */
157 #if defined(__FreeBSD__) || defined(__NetBSD__)
158 int tirpcflag = 0; /* generating code for tirpc, by default */
160 int tirpcflag = 1; /* generating code for tirpc, by default */
162 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
163 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
172 struct commandline cmd;
174 (void) memset((char *)&cmd, 0, sizeof (struct commandline));
176 if (!parseargs(argc, argv, &cmd))
179 * Only the client and server side stubs are likely to be customized,
180 * so in that case only, check if the outfile exists, and if so,
181 * print an error message and exit.
183 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
184 checkfiles(cmd.infile, cmd.outfile);
187 checkfiles(cmd.infile, NULL);
190 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
191 } else if (cmd.hflag) {
192 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
193 } else if (cmd.lflag) {
194 l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
195 } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
196 s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
197 cmd.outfile, cmd.mflag, cmd.nflag);
198 } else if (cmd.tflag) {
199 t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
200 } else if (cmd.Ssflag) {
201 svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
203 } else if (cmd.Scflag) {
204 clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
206 } else if (cmd.makefileflag) {
209 /* the rescans are required, since cpp may effect input */
210 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
212 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
214 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
216 if (inetdflag || !tirpcflag)
217 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
218 "_svc.c", cmd.mflag, cmd.nflag);
220 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
221 EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
224 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
229 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
232 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
236 if (allfiles || (cmd.makefileflag == 1)){
242 exit(nonfatalerrors);
248 * add extension to filename
251 #if defined(__FreeBSD__) || defined(__NetBSD__)
252 extendfile(path, ext)
255 extendfile(file, ext)
262 #if defined(__FreeBSD__) || defined(__NetBSD__)
265 if ((file = rindex(path, '/')) == NULL)
270 res = alloc(strlen(file) + strlen(ext) + 1);
274 p = strrchr(file, '.');
276 p = file + strlen(file);
278 (void) strcpy(res, file);
279 (void) strcpy(res + (p - file), ext);
284 * Open output file with given extension
287 open_output(infile, outfile)
292 if (outfile == NULL) {
297 if (infile != NULL && streq(outfile, infile)) {
298 warnx("%s already exists. No output generated", infile);
301 fout = fopen(outfile, "w");
303 warn("unable to open %s", outfile);
306 record_open(outfile);
314 f_print(fout, "/*\n");
315 f_print(fout, " * Please do not edit this file.\n");
316 f_print(fout, " * It was generated using rpcgen.\n");
317 f_print(fout, " */\n\n");
320 /* clear list of arguments */
321 static void clear_args()
324 for (i = FIXEDARGS; i < ARGLISTLEN; i++)
326 argcount = FIXEDARGS;
329 /* make sure that a CPP exists */
330 static void find_cpp()
334 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
336 warnx("cannot find C preprocessor: %s", CPP);
338 } else { /* try the other one */
340 if (stat(CPP, &buf) < 0) { /* can't find any cpp */
341 warnx("cannot find any C preprocessor (cpp)");
349 * Open input file with given define for C-preprocessor
352 open_input(infile, define)
358 infilename = (infile == NULL) ? "<stdin>" : infile;
360 switch (childpid = fork()) {
368 addarg((char *)NULL);
370 (void) dup2(pd[1], 1);
372 execv(arglist[0], arglist);
380 fin = fdopen(pd[0], "r");
382 warn("%s", infilename);
387 /* valid tirpc nettypes */
388 static char* valid_ti_nettypes[] =
402 /* valid inetd nettypes */
403 static char* valid_i_nettypes[] =
410 static int check_nettype(name, list_to_check)
412 char* list_to_check[];
415 for (i = 0; list_to_check[i] != NULL; i++) {
416 if (strcmp(name, list_to_check[i]) == 0) {
420 warnx("illegal nettype :\'%s\'", name);
430 temp = extendfile(file, ext);
432 if (access(temp, F_OK) != -1)
435 return ((char *)" ");
441 c_output(infile, define, extend, outfile)
453 open_input(infile, define);
454 outfilename = extend ? extendfile(infile, outfile) : outfile;
455 open_output(infile, outfilename);
457 if (infile && (include = extendfile(infile, ".h"))) {
458 f_print(fout, "#include \"%s\"\n", include);
460 /* .h file already contains rpc/rpc.h */
462 f_print(fout, "#include <rpc/rpc.h>\n");
464 while ( (def = get_definition()) ) {
467 if (extend && tell == ftell(fout)) {
468 (void) unlink(outfilename);
477 /* add all the starting basic types */
480 add_type(1, "short");
482 add_type(1, "u_int");
483 add_type(1, "u_long");
484 add_type(1, "u_short");
488 char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
490 xdrproc_t xdr_arg; \n\
491 unsigned len_arg; \n\
492 xdrproc_t xdr_res; \n\
493 unsigned len_res; \n\
497 char *generate_guard(pathname)
500 char* filename, *guard, *tmp;
502 filename = strrchr(pathname, '/'); /* find last component */
503 filename = ((filename == 0) ? pathname : filename+1);
504 guard = strdup(filename);
505 /* convert to upper case */
509 *tmp = toupper(*tmp);
512 guard = extendfile(guard, "_H_RPCGEN");
517 * Compile into an XDR header file
522 h_output(infile, define, extend, outfile)
536 open_input(infile, define);
537 outfilename = extend ? extendfile(infile, outfile) : outfile;
538 open_output(infile, outfilename);
540 if (outfilename || infile){
541 guard = generate_guard(outfilename ? outfilename: infile);
545 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
548 f_print(fout, "#include <rpc/rpc.h>\n");
551 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
552 f_print(fout, "#include <synch.h>\n");
553 f_print(fout, "#include <thread.h>\n");
555 f_print(fout, "#include <pthread.h>\n");
559 /* put the C++ support */
560 if (Cflag && !CCflag){
561 f_print(fout, "\n#ifdef __cplusplus\n");
562 f_print(fout, "extern \"C\" {\n");
563 f_print(fout, "#endif\n\n");
566 /* put in a typedef for quadprecision. Only with Cflag */
570 /* print data definitions */
571 while ( (def = get_definition()) ) {
576 * print function declarations.
577 * Do this after data definitions because they might be used as
578 * arguments for functions
580 for (l = defined; l != NULL; l = l->next) {
581 print_funcdef(l->val);
583 /* Now print all xdr func declarations */
584 if (xdrfunc_head != NULL){
587 "\n/* the xdr functions */\n");
590 f_print(fout, "\n#ifdef __cplusplus\n");
591 f_print(fout, "extern \"C\" {\n");
592 f_print(fout, "#endif\n");
596 xdrfuncp = xdrfunc_head;
597 while (xdrfuncp != NULL){
598 print_xdr_func_def(xdrfuncp->name,
599 xdrfuncp->pointerp, 2);
600 xdrfuncp = xdrfuncp->next;
604 for (i = 1; i < 3; i++){
606 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
609 f_print(fout, "\n#else /* K&R C */\n");
611 xdrfuncp = xdrfunc_head;
612 while (xdrfuncp != NULL){
613 print_xdr_func_def(xdrfuncp->name,
614 xdrfuncp->pointerp, i);
615 xdrfuncp = xdrfuncp->next;
618 f_print(fout, "\n#endif /* K&R C */\n");
622 if (extend && tell == ftell(fout)) {
623 (void) unlink(outfilename);
624 } else if (tblflag) {
625 f_print(fout, rpcgen_table_dcl);
629 f_print(fout, "\n#ifdef __cplusplus\n");
630 f_print(fout, "}\n");
631 f_print(fout, "#endif\n");
634 f_print(fout, "\n#endif /* !_%s */\n", guard);
638 * Compile into an RPC service
641 s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
653 int foundprogram = 0;
656 open_input(infile, define);
657 outfilename = extend ? extendfile(infile, outfile) : outfile;
658 open_output(infile, outfilename);
660 if (infile && (include = extendfile(infile, ".h"))) {
661 f_print(fout, "#include \"%s\"\n", include);
664 f_print(fout, "#include <rpc/rpc.h>\n");
666 f_print(fout, "#include <stdio.h>\n");
667 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
670 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
671 f_print (fout, "#include <string.h> /* strcmp */\n");
673 if (strcmp(svcclosetime, "-1") == 0)
675 else if (strcmp(svcclosetime, "0") == 0)
677 else if (inetdflag || pmflag) {
678 f_print(fout, "#include <signal.h>\n");
682 if (!tirpcflag && inetdflag)
683 f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
684 if (Cflag && (inetdflag || pmflag)) {
685 f_print(fout, "#ifdef __cplusplus\n");
687 "#include <sysent.h> /* getdtablesize, open */\n");
688 f_print(fout, "#endif /* __cplusplus */\n");
690 f_print(fout, "#include <unistd.h> /* setsid */\n");
693 f_print(fout, "#include <sys/types.h>\n");
695 f_print(fout, "#include <memory.h>\n");
696 #if defined(__FreeBSD__) || defined(__NetBSD__)
699 f_print(fout, "#include <stropts.h>\n");
700 if (inetdflag || !tirpcflag) {
701 f_print(fout, "#include <sys/socket.h>\n");
702 f_print(fout, "#include <netinet/in.h>\n");
705 if ((netflag || pmflag) && tirpcflag && !nomain) {
706 f_print(fout, "#include <netconfig.h>\n");
709 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
710 if (logflag || inetdflag || pmflag)
711 f_print(fout, "#include <syslog.h>\n");
716 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
719 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
721 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
723 while ( (def = get_definition()) ) {
724 foundprogram |= (def->def_kind == DEF_PROGRAM);
726 if (extend && !foundprogram) {
727 (void) unlink(outfilename);
730 write_most(infile, netflag, nomain);
732 if (!do_registers(argc, argv)) {
734 (void) unlink(outfilename);
742 * generate client side stubs
745 l_output(infile, define, extend, outfile)
753 int foundprogram = 0;
756 open_input(infile, define);
757 outfilename = extend ? extendfile(infile, outfile) : outfile;
758 open_output(infile, outfilename);
761 f_print (fout, "#include <memory.h> /* for memset */\n");
762 if (infile && (include = extendfile(infile, ".h"))) {
763 f_print(fout, "#include \"%s\"\n", include);
766 f_print(fout, "#include <rpc/rpc.h>\n");
767 while ( (def = get_definition()) ) {
768 foundprogram |= (def->def_kind == DEF_PROGRAM);
770 if (extend && !foundprogram) {
771 (void) unlink(outfilename);
778 * generate the dispatch table
781 t_output(infile, define, extend, outfile)
788 int foundprogram = 0;
791 open_input(infile, define);
792 outfilename = extend ? extendfile(infile, outfile) : outfile;
793 open_output(infile, outfilename);
795 while ( (def = get_definition()) ) {
796 foundprogram |= (def->def_kind == DEF_PROGRAM);
798 if (extend && !foundprogram) {
799 (void) unlink(outfilename);
805 /* sample routine for the server template */
807 svc_output(infile, define, extend, outfile)
817 open_input(infile, define);
818 outfilename = extend ? extendfile(infile, outfile) : outfile;
819 checkfiles(infile, outfilename);
821 * Check if outfile already exists.
822 * if so, print an error message and exit
824 open_output(infile, outfilename);
827 if (infile && (include = extendfile(infile, ".h"))) {
828 f_print(fout, "#include \"%s\"\n", include);
831 f_print(fout, "#include <rpc/rpc.h>\n");
834 while ( (def = get_definition()) ) {
835 write_sample_svc(def);
837 if (extend && tell == ftell(fout)) {
838 (void) unlink(outfilename);
842 /* sample main routine for client */
844 clnt_output(infile, define, extend, outfile)
856 open_input(infile, define);
857 outfilename = extend ? extendfile(infile, outfile) : outfile;
858 checkfiles(infile, outfilename);
860 * Check if outfile already exists.
861 * if so, print an error message and exit
864 open_output(infile, outfilename);
866 if (infile && (include = extendfile(infile, ".h"))) {
867 f_print(fout, "#include \"%s\"\n", include);
870 f_print(fout, "#include <rpc/rpc.h>\n");
872 while ( (def = get_definition()) ) {
873 has_program += write_sample_clnt(def);
877 write_sample_clnt_main();
879 if (extend && tell == ftell(fout)) {
880 (void) unlink(outfilename);
885 static void mkfile_output(cmd)
886 struct commandline *cmd;
888 char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
889 char *servername, *svcname, *servprogname, *clntprogname;
892 svcname = file_name(cmd->infile, "_svc.c");
893 clntname = file_name(cmd->infile, "_clnt.c");
894 xdrname = file_name(cmd->infile, "_xdr.c");
895 hdrname = file_name(cmd->infile, ".h");
899 servername = extendfile(cmd->infile, "_server.c");
900 clientname = extendfile(cmd->infile, "_client.c");
905 servprogname = extendfile(cmd->infile, "_server");
906 clntprogname = extendfile(cmd->infile, "_client");
909 mkfilename = alloc(strlen("makefile.") +
910 strlen(cmd->infile) + 1);
911 temp = (char *)rindex(cmd->infile, '.');
912 strcat(mkfilename, "makefile.");
913 (void) strncat(mkfilename, cmd->infile,
914 (temp - cmd->infile));
916 mkfilename = cmd->outfile;
919 checkfiles(NULL, mkfilename);
920 open_output(NULL, mkfilename);
922 f_print(fout, "\n# This is a template makefile generated\
925 f_print(fout, "\n# Parameters \n\n");
927 f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
928 clntprogname, servprogname);
929 f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
930 f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
931 f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
932 f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
933 svcname, servername, xdrname);
934 f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
935 clntname, clientname, xdrname);
936 f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
937 hdrname, xdrname, clntname,
938 svcname, clientname, servername);
940 f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
941 $(TARGETS_CLNT.c:%%.c=%%.o) ");
943 f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
944 $(TARGETS_SVC.c:%%.c=%%.o) ");
947 f_print(fout, "\n# Compiler flags \n");
949 f_print(fout, "\nCPPFLAGS += -D_REENTRANT\nCFLAGS += -g \nLDLIBS += -lnsl -lthread\n");
951 #if defined(__FreeBSD__) || defined(__NetBSD__)
952 f_print(fout, "\nCFLAGS += -g \nLDLIBS +=\n");
954 f_print(fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
956 f_print(fout, "RPCGENFLAGS = \n");
958 f_print(fout, "\n# Targets \n\n");
960 f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
961 f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
962 f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
963 f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
964 $(TARGETS_CLNT.c) \n\n");
966 f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
967 $(TARGETS_SVC.c) \n\n");
968 f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
969 #if defined(__FreeBSD__) || defined(__NetBSD__)
970 f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
973 f_print(fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
976 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
977 #if defined(__FreeBSD__) || defined(__NetBSD__)
978 f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
979 f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \
980 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
982 f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
983 f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
984 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
991 * Perform registrations for service output
992 * Return 0 if failed; 1 otherwise.
995 do_registers(argc, argv)
1001 if (inetdflag || !tirpcflag) {
1002 for (i = 1; i < argc; i++) {
1003 if (streq(argv[i], "-s")) {
1004 if (!check_nettype(argv[i + 1],
1007 write_inetd_register(argv[i + 1]);
1012 for (i = 1; i < argc; i++)
1013 if (streq(argv[i], "-s")) {
1014 if (!check_nettype(argv[i + 1],
1017 write_nettype_register(argv[i + 1]);
1019 } else if (streq(argv[i], "-n")) {
1020 write_netid_register(argv[i + 1]);
1028 * Add another argument to the arg list
1034 if (argcount >= ARGLISTLEN) {
1035 warnx("too many defines");
1039 arglist[argcount++] = cp;
1048 if (where >= ARGLISTLEN) {
1049 warnx("arglist coding error");
1053 arglist[where] = cp;
1057 * if input file is stdin and an output file is specified then complain
1058 * if the file already exists. Otherwise the file may get overwritten
1059 * If input file does not exist, exit with an error
1063 checkfiles(infile, outfile)
1070 if (infile) /* infile ! = NULL */
1071 if (stat(infile, &buf) < 0)
1077 if (stat(outfile, &buf) < 0)
1078 return; /* file does not exist */
1080 warnx("file '%s' already exists and may be overwritten", outfile);
1087 * Parse command line arguments
1090 parseargs(argc, argv, cmd)
1093 struct commandline *cmd;
1098 char flag[(1 << 8 * sizeof (char))];
1101 cmd->infile = cmd->outfile = NULL;
1118 for (i = 1; i < argc; i++) {
1119 if (argv[i][0] != '-') {
1121 warnx("cannot specify more than one input file");
1124 cmd->infile = argv[i];
1126 for (j = 1; argv[i][j] != 0; j++) {
1144 * sample flag: Ss or Sc.
1145 * Ss means set flag['S'];
1146 * Sc means set flag['C'];
1147 * Sm means set flag['M'];
1149 ch = argv[i][++j]; /* get next char */
1159 if (flag[(int)ch]) {
1164 case 'C': /* ANSI C syntax */
1166 ch = argv[i][j+1]; /* get next char */
1174 * Turn TIRPC flag off for
1175 * generating backward compatible
1178 #if defined(__FreeBSD__) || defined(__NetBSD__)
1198 svcclosetime = argv[i];
1210 inline = atoi(argv[i]);
1215 if (argv[i][j - 1] != '-' ||
1216 argv[i][j + 1] != 0) {
1227 cmd->outfile = argv[i];
1231 if (argv[i][j - 1] != '-') {
1234 (void) addarg(argv[i]);
1240 (void) strcpy(pathbuf, argv[i]);
1241 (void) strcat(pathbuf, "/cpp");
1257 cmd->cflag = flag['c'];
1258 cmd->hflag = flag['h'];
1259 cmd->lflag = flag['l'];
1260 cmd->mflag = flag['m'];
1261 cmd->nflag = flag['n'];
1262 cmd->sflag = flag['s'];
1263 cmd->tflag = flag['t'];
1264 cmd->Ssflag = flag['S'];
1265 cmd->Scflag = flag['C'];
1266 cmd->makefileflag = flag['M'];
1269 pmflag = inetdflag ? 0 : 1;
1270 /* pmflag or inetdflag is always TRUE */
1271 if ((inetdflag && cmd->nflag)) {
1272 /* netid not allowed with inetdflag */
1273 warnx("cannot use netid flag with inetd flag");
1276 } else { /* 4.1 mode */
1277 pmflag = 0; /* set pmflag only in tirpcmode */
1278 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
1279 inetdflag = 1; /* inetdflag is TRUE by default */
1281 if (cmd->nflag) { /* netid needs TIRPC */
1282 warnx("cannot use netid flag without TIRPC");
1287 if (newstyle && (tblflag || cmd->tflag)) {
1288 warnx("cannot use table flags with newstyle");
1292 /* check no conflicts with file generation flags */
1293 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1294 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1295 cmd->Scflag + cmd->makefileflag;
1298 if (cmd->outfile != NULL || cmd->infile == NULL) {
1301 } else if (cmd->infile == NULL &&
1302 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1303 warnx("\"infile\" is required for template generation flags");
1306 warnx("cannot have more than one file generation flag");
1315 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1316 "usage: rpcgen infile",
1317 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1318 [-I [-K seconds]] [-Y path] infile",
1319 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1320 [-o outfile] [infile]",
1321 " rpcgen [-s nettype]* [-o outfile] [infile]",
1322 " rpcgen [-n netid]* [-o outfile] [infile]");
1330 f_print(stderr, "options:\n");
1331 f_print(stderr, "-a\t\tgenerate all files, including samples\n");
1332 f_print(stderr, "-b\t\tbackward compatibility mode (generates code\
1334 f_print(stderr, "-c\t\tgenerate XDR routines\n");
1335 f_print(stderr, "-C\t\tANSI C mode\n");
1336 f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1337 f_print(stderr, "-h\t\tgenerate header file\n");
1338 f_print(stderr, "-i size\t\tsize at which to start generating\
1340 f_print(stderr, "-I\t\tgenerate code for inetd support in server\
1341 (for SunOS 4.X)\n");
1342 f_print(stderr, "-K seconds\tserver exits after K seconds of\
1344 f_print(stderr, "-l\t\tgenerate client side stubs\n");
1345 f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
1346 f_print(stderr, "-m\t\tgenerate server side stubs\n");
1347 f_print(stderr, "-M\t\tgenerate MT-safe code\n");
1348 f_print(stderr, "-n netid\tgenerate server code that supports\
1350 f_print(stderr, "-N\t\tsupports multiple arguments and\
1352 f_print(stderr, "-o outfile\tname of the output file\n");
1353 f_print(stderr, "-s nettype\tgenerate server code that supports named\
1355 f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\
1357 f_print(stderr, "-Ss\t\tgenerate sample server code that defines\
1358 remote procedures\n");
1359 f_print(stderr, "-Sm \t\tgenerate makefile template \n");
1361 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
1362 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
1363 f_print(stderr, "-Y path\t\tpath where cpp is found\n");
1367 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
1370 register char *sp, c;