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