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.21 94/04/25 SMI; 1.30 89/03/30 (C) 1987 SMI
30 * $FreeBSD: src/usr.bin/rpcgen/rpc_main.c,v 1.33 2007/08/23 09:38:26 delphij Exp $
31 * $DragonFly: src/usr.bin/rpcgen/rpc_main.c,v 1.12 2008/10/16 01:52:33 swildner Exp $
36 * rpc_main.c, Top level of the RPC protocol compiler.
37 * Copyright (C) 1987, Sun Microsystems, Inc.
45 #include <sys/types.h>
46 #include <sys/param.h>
49 #include "rpc_parse.h"
53 static void c_output(const char *, const char *, int, const char *);
54 static void h_output(const char *, const char *, int, const char *, int);
55 static void l_output(const char *, const char *, int, const char *);
56 static void t_output(const char *, const char *, int, const char *);
57 static void clnt_output(const char *, const char *, int, const char *);
58 static char *generate_guard(const char *);
59 static void c_initialize(void);
61 static void usage(void);
62 static void options_usage(void);
63 static int do_registers(int, const char **);
64 static int parseargs(int, const char **, struct commandline *);
65 static void svc_output(const char *, const char *, int, const char *);
66 static void mkfile_output(struct commandline *);
67 static void s_output(int, const char **, const char *, const char *, int,
68 const char *, int, int);
70 #define EXTEND 1 /* alias for TRUE */
71 #define DONT_EXTEND 0 /* alias for FALSE */
73 static int cppDefined = 0; /* explicit path for C preprocessor */
75 static const char *svcclosetime = "120";
76 static const char *CPP = NULL;
77 static const char CPPFLAGS[] = "-C";
78 static char pathbuf[MAXPATHLEN + 1];
79 static const char *allv[] = {
80 "rpcgen", "-s", "udp", "-s", "tcp",
82 static int allc = sizeof (allv)/sizeof (allv[0]);
83 static const char *allnv[] = {
84 "rpcgen", "-s", "netpath",
86 static int allnc = sizeof (allnv)/sizeof (allnv[0]);
89 * machinations for handling expanding argument list
91 static void addarg(const char *); /* add another argument to the list */
92 static void putarg(int, const char *); /* put argument at specified location */
93 static void clear_args(void); /* clear argument list */
94 static void checkfiles(const char *, const char *);
95 /* check if out file already exists */
102 static char *arglist[ARGLISTLEN];
103 static int argcount = FIXEDARGS;
106 int nonfatalerrors; /* errors */
107 int inetdflag = 0; /* Support for inetd is disabled by default, use -I */
108 int pmflag = 0; /* Support for port monitors is disabled by default */
109 int tirpc_socket = 1; /* TI-RPC on socket, no TLI library */
110 int logflag; /* Use syslog instead of fprintf for errors */
111 int tblflag; /* Support for dispatch table file */
112 int mtflag = 0; /* Support for MT */
115 /* length at which to start doing an inline */
117 int inline_size = INLINE;
119 * Length at which to start doing an inline. INLINE = default
120 * if 0, no xdr_inline code
123 int indefinitewait; /* If started by port monitors, hang till it wants */
124 int exitnow; /* If started by port monitors, exit after the call */
125 int timerflag; /* TRUE if !indefinite && !exitnow */
126 int newstyle; /* newstyle of passing arguments (by value) */
127 int CCflag = 0; /* C++ files */
128 static int allfiles; /* generate all files */
129 int tirpcflag = 1; /* generating code for tirpc, by default */
130 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
131 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
136 main(int argc, const char **argv)
138 struct commandline cmd;
140 memset(&cmd, 0, sizeof (struct commandline));
142 if (!parseargs(argc, argv, &cmd))
145 * Only the client and server side stubs are likely to be customized,
146 * so in that case only, check if the outfile exists, and if so,
147 * print an error message and exit.
149 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag)
150 checkfiles(cmd.infile, cmd.outfile);
152 checkfiles(cmd.infile, NULL);
155 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
156 } else if (cmd.hflag) {
157 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile,
159 } else if (cmd.lflag) {
160 l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
161 } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
162 s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
163 cmd.outfile, cmd.mflag, cmd.nflag);
164 } else if (cmd.tflag) {
165 t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
166 } else if (cmd.Ssflag) {
167 svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
169 } else if (cmd.Scflag) {
170 clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
172 } else if (cmd.makefileflag) {
175 /* the rescans are required, since cpp may effect input */
176 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
178 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h", cmd.hflag);
180 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
182 if (inetdflag || !tirpcflag)
183 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
184 "_svc.c", cmd.mflag, cmd.nflag);
186 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
187 EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
190 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
195 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
198 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
202 if (allfiles || (cmd.makefileflag == 1)){
208 exit(nonfatalerrors);
214 * add extension to filename
217 extendfile(const char *path, const char *ext)
223 if ((file = strrchr(path, '/')) == NULL)
227 res = xmalloc(strlen(file) + strlen(ext) + 1);
228 p = strrchr(file, '.');
230 p = file + strlen(file);
232 strcpy(res + (p - file), ext);
237 * Open output file with given extension
240 open_output(const char *infile, const char *outfile)
242 if (outfile == NULL) {
247 if (infile != NULL && streq(outfile, infile)) {
248 warnx("%s already exists. No output generated", infile);
251 fout = fopen(outfile, "w");
253 warn("unable to open %s", outfile);
256 record_open(outfile);
262 f_print(fout, "/*\n");
263 f_print(fout, " * Please do not edit this file.\n");
264 f_print(fout, " * It was generated using rpcgen.\n");
265 f_print(fout, " */\n\n");
268 /* clear list of arguments */
274 for (i = FIXEDARGS; i < ARGLISTLEN; i++)
276 argcount = FIXEDARGS;
279 /* make sure that a CPP exists */
290 * Open input file with given define for C-preprocessor
293 open_input(const char *infile, const char *define)
298 infilename = (infile == NULL) ? "<stdin>" : infile;
300 switch (childpid = fork()) {
313 execvp(arglist[0], arglist);
315 execv(arglist[0], arglist);
316 err(1, "execv(%s)", arglist[0]);
321 fin = fdopen(pd[0], "r");
323 warn("%s", infilename);
328 /* valid tirpc nettypes */
329 static const char *valid_ti_nettypes[] =
343 /* valid inetd nettypes */
344 static const char *valid_i_nettypes[] =
352 check_nettype(const char *name, const char *list_to_check[])
355 for (i = 0; list_to_check[i] != NULL; i++) {
356 if (strcmp(name, list_to_check[i]) == 0)
359 warnx("illegal nettype :\'%s\'", name);
364 file_name(const char *file, const char *ext)
367 temp = extendfile(file, ext);
369 if (access(temp, F_OK) != -1)
377 c_output(const char *infile, const char *define, int extend, const char *outfile)
381 const char *outfilename;
385 open_input(infile, define);
386 outfilename = extend ? extendfile(infile, outfile) : outfile;
387 open_output(infile, outfilename);
389 if (infile && (include = extendfile(infile, ".h"))) {
390 f_print(fout, "#include \"%s\"\n", include);
392 /* .h file already contains rpc/rpc.h */
394 f_print(fout, "#include <rpc/rpc.h>\n");
396 while ( (def = get_definition()) )
398 if (extend && tell == ftell(fout))
405 /* add all the starting basic types */
408 add_type(1, "short");
410 add_type(1, "u_int");
411 add_type(1, "u_long");
412 add_type(1, "u_short");
415 const char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
417 xdrproc_t xdr_arg; \n\
418 unsigned len_arg; \n\
419 xdrproc_t xdr_res; \n\
420 unsigned len_res; \n\
424 generate_guard(const char *pathname)
426 const char *filename;
427 char *guard, *tmp, *stopat;
429 filename = strrchr(pathname, '/'); /* find last component */
430 filename = ((filename == 0) ? pathname : filename+1);
431 guard = xstrdup(filename);
432 stopat = strrchr(guard, '.');
435 * Convert to a valid C macro name and make it upper case.
436 * Map macro unfriendly characterss to '_'.
438 for (tmp = guard; *tmp != '\000'; ++tmp) {
440 *tmp = toupper(*tmp);
441 else if (isupper(*tmp) || *tmp == '_')
443 else if (tmp == guard)
445 else if (isdigit(*tmp))
446 /* OK for all but first character */;
447 else if (tmp == stopat) {
454 * Can't have a '_' in front, because it'll end up being "__".
455 * "__" macros shoudln't be used. So, remove all of the
456 * '_' characters from the front.
459 for (tmp = guard; *tmp == '_'; ++tmp)
463 guard = extendfile(guard, "_H_RPCGEN");
468 * Compile into an XDR header file
472 h_output(const char *infile, const char *define, int extend, const char *outfile, int headeronly)
475 const char *outfilename;
481 open_input(infile, define);
482 outfilename = extend ? extendfile(infile, outfile) : outfile;
483 open_output(infile, outfilename);
485 if (outfilename || infile){
486 guard = generate_guard(outfilename ? outfilename: infile);
490 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
493 f_print(fout, "#include <rpc/rpc.h>\n");
496 f_print(fout, "#include <pthread.h>\n");
498 /* put the C++ support */
500 f_print(fout, "\n#ifdef __cplusplus\n");
501 f_print(fout, "extern \"C\" {\n");
502 f_print(fout, "#endif\n\n");
505 /* put in a typedef for quadprecision. Only with Cflag */
509 /* print data definitions */
510 while ((def = get_definition()) != 0)
511 print_datadef(def, headeronly);
514 * print function declarations.
515 * Do this after data definitions because they might be used as
516 * arguments for functions
518 for (l = defined; l != NULL; l = l->next)
519 print_funcdef(l->val, headeronly);
520 /* Now print all xdr func declarations */
521 if (xdrfunc_head != NULL) {
522 f_print(fout, "\n/* the xdr functions */\n");
525 f_print(fout, "\n#ifdef __cplusplus\n");
526 f_print(fout, "extern \"C\" {\n");
527 f_print(fout, "#endif\n");
530 xdrfuncp = xdrfunc_head;
531 while (xdrfuncp != NULL) {
532 print_xdr_func_def(xdrfuncp->name, xdrfuncp->pointerp);
533 xdrfuncp = xdrfuncp->next;
537 if (extend && tell == ftell(fout))
540 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");
546 f_print(fout, "\n#endif /* !_%s */\n", guard);
550 * Compile into an RPC service
553 s_output(int argc, const char **argv, const char *infile, const char *define,
554 int extend, const char *outfile, int nomain, int netflag)
558 int foundprogram = 0;
559 const char *outfilename;
561 open_input(infile, define);
562 outfilename = extend ? extendfile(infile, outfile) : outfile;
563 open_output(infile, outfilename);
565 if (infile && (include = extendfile(infile, ".h"))) {
566 f_print(fout, "#include \"%s\"\n", include);
569 f_print(fout, "#include <rpc/rpc.h>\n");
571 f_print(fout, "#include <stdio.h>\n");
572 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
573 f_print(fout, "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
574 f_print(fout, "#include <string.h> /* strcmp */\n");
576 f_print(fout, "#include <rpc/rpc_com.h>\n");
577 if (strcmp(svcclosetime, "-1") == 0)
579 else if (strcmp(svcclosetime, "0") == 0)
581 else if (inetdflag || pmflag) {
582 f_print(fout, "#include <signal.h>\n");
586 if (!tirpcflag && inetdflag)
587 f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
588 if (inetdflag || pmflag) {
589 f_print(fout, "#ifdef __cplusplus\n");
591 "#include <sys/sysent.h> /* getdtablesize, open */\n");
592 f_print(fout, "#endif /* __cplusplus */\n");
595 f_print(fout, "#include <fcntl.h> /* open */\n");
596 f_print(fout, "#include <unistd.h> /* fork / setsid */\n");
597 f_print(fout, "#include <sys/types.h>\n");
600 f_print(fout, "#include <string.h>\n");
601 if (inetdflag || !tirpcflag) {
602 f_print(fout, "#include <sys/socket.h>\n");
603 f_print(fout, "#include <netinet/in.h>\n");
606 if ((netflag || pmflag) && tirpcflag && !nomain)
607 f_print(fout, "#include <netconfig.h>\n");
609 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
610 if (logflag || inetdflag || pmflag || tirpcflag)
611 f_print(fout, "#include <syslog.h>\n");
613 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
615 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
617 while ((def = get_definition()) != 0)
618 foundprogram |= (def->def_kind == DEF_PROGRAM);
619 if (extend && !foundprogram) {
623 write_most(infile, netflag, nomain);
625 if (!do_registers(argc, argv)) {
635 * generate client side stubs
638 l_output(const char *infile, const char *define, int extend, const char *outfile)
642 int foundprogram = 0;
643 const char *outfilename;
645 open_input(infile, define);
646 outfilename = extend ? extendfile(infile, outfile) : outfile;
647 open_output(infile, outfilename);
649 f_print(fout, "#include <string.h> /* for memset */\n");
650 if (infile && (include = extendfile(infile, ".h"))) {
651 f_print(fout, "#include \"%s\"\n", include);
654 f_print(fout, "#include <rpc/rpc.h>\n");
655 while ((def = get_definition()) != 0)
656 foundprogram |= (def->def_kind == DEF_PROGRAM);
657 if (extend && !foundprogram)
664 * generate the dispatch table
667 t_output(const char *infile, const char *define, int extend, const char *outfile)
670 int foundprogram = 0;
671 const char *outfilename;
673 open_input(infile, define);
674 outfilename = extend ? extendfile(infile, outfile) : outfile;
675 open_output(infile, outfilename);
677 while ((def = get_definition()) != 0)
678 foundprogram |= (def->def_kind == DEF_PROGRAM);
679 if (extend && !foundprogram)
685 /* sample routine for the server template */
687 svc_output(const char *infile, const char *define, int extend, const char *outfile)
691 const char *outfilename;
693 open_input(infile, define);
694 outfilename = extend ? extendfile(infile, outfile) : outfile;
695 checkfiles(infile, outfilename);
697 * Check if outfile already exists.
698 * if so, print an error message and exit
700 open_output(infile, outfilename);
703 if (infile && (include = extendfile(infile, ".h"))) {
704 f_print(fout, "#include \"%s\"\n", include);
707 f_print(fout, "#include <rpc/rpc.h>\n");
710 while ((def = get_definition()) != 0)
711 write_sample_svc(def);
712 if (extend && tell == ftell(fout))
716 /* sample main routine for client */
718 clnt_output(const char *infile, const char *define, int extend, const char *outfile)
722 const char *outfilename;
726 open_input(infile, define);
727 outfilename = extend ? extendfile(infile, outfile) : outfile;
728 checkfiles(infile, outfilename);
730 * Check if outfile already exists.
731 * if so, print an error message and exit
734 open_output(infile, outfilename);
736 if (infile && (include = extendfile(infile, ".h"))) {
737 f_print(fout, "#include \"%s\"\n", include);
740 f_print(fout, "#include <rpc/rpc.h>\n");
742 while ((def = get_definition()) != 0)
743 has_program += write_sample_clnt(def);
746 write_sample_clnt_main();
748 if (extend && tell == ftell(fout))
754 mkfile_output(struct commandline *cmd)
756 const char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
757 const char *servername, *svcname, *servprogname, *clntprogname;
758 char *temp, *mkftemp;
760 svcname = file_name(cmd->infile, "_svc.c");
761 clntname = file_name(cmd->infile, "_clnt.c");
762 xdrname = file_name(cmd->infile, "_xdr.c");
763 hdrname = file_name(cmd->infile, ".h");
766 servername = extendfile(cmd->infile, "_server.c");
767 clientname = extendfile(cmd->infile, "_client.c");
772 servprogname = extendfile(cmd->infile, "_server");
773 clntprogname = extendfile(cmd->infile, "_client");
776 mkftemp = xmalloc(strlen("makefile.") +
777 strlen(cmd->infile) + 1);
778 temp = strrchr(cmd->infile, '.');
779 strcpy(mkftemp, "makefile.");
780 strncat(mkftemp, cmd->infile, (temp - cmd->infile));
781 mkfilename = mkftemp;
783 mkfilename = cmd->outfile;
785 checkfiles(NULL, mkfilename);
786 open_output(NULL, mkfilename);
788 f_print(fout, "\n# This is a template makefile generated "
791 f_print(fout, "\n# Parameters \n\n");
793 f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
794 clntprogname, servprogname);
795 f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
796 f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
797 f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
798 f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
799 svcname, servername, xdrname);
800 f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
801 clntname, clientname, xdrname);
802 f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
803 hdrname, xdrname, clntname,
804 svcname, clientname, servername);
806 f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) "
807 "$(TARGETS_CLNT.c:%%.c=%%.o) ");
809 f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) "
810 "$(TARGETS_SVC.c:%%.c=%%.o) ");
813 f_print(fout, "\n# Compiler flags \n");
815 f_print(fout, "\nCFLAGS += -D_REENTRANT -D_THEAD_SAFE \nLDLIBS += -pthread\n");
817 f_print(fout, "RPCGENFLAGS = \n");
819 f_print(fout, "\n# Targets \n\n");
821 f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
822 f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
823 f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
824 f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) "
825 "$(TARGETS_CLNT.c) \n\n");
827 f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) "
828 "$(TARGETS_SVC.c) \n\n");
829 f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
830 f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS) \n\n");
831 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
832 f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
833 f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) "
834 "$(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
840 * Perform registrations for service output
841 * Return 0 if failed; 1 otherwise.
844 do_registers(int argc, const char **argv)
848 if (inetdflag || !tirpcflag) {
849 for (i = 1; i < argc; i++) {
850 if (streq(argv[i], "-s")) {
851 if (!check_nettype(argv[i + 1],
854 write_inetd_register(argv[i + 1]);
859 for (i = 1; i < argc; i++)
860 if (streq(argv[i], "-s")) {
861 if (!check_nettype(argv[i + 1],
864 write_nettype_register(argv[i + 1]);
866 } else if (streq(argv[i], "-n")) {
867 write_netid_register(argv[i + 1]);
875 * Add another argument to the arg list
878 addarg(const char *cp)
880 if (argcount >= ARGLISTLEN) {
881 warnx("too many defines");
886 arglist[argcount++] = xstrdup(cp);
888 arglist[argcount++] = NULL;
893 putarg(int place, const char *cp)
895 if (place >= ARGLISTLEN) {
896 warnx("arglist coding error");
901 arglist[place] = xstrdup(cp);
903 arglist[place] = NULL;
907 * if input file is stdin and an output file is specified then complain
908 * if the file already exists. Otherwise the file may get overwritten
909 * If input file does not exist, exit with an error
913 checkfiles(const char *infile, const char *outfile)
917 if (infile != NULL && stat(infile, &buf) < 0) {
922 if (stat(outfile, &buf) < 0)
923 return; /* file does not exist */
925 warnx("file '%s' already exists and may be overwritten", outfile);
932 * Parse command line arguments
935 parseargs(int argc, const char **argv, struct commandline *cmd)
940 char flag[(1 << 8 * sizeof (char))];
943 cmd->infile = cmd->outfile = NULL;
960 for (i = 1; i < argc; i++) {
961 if (argv[i][0] != '-') {
963 warnx("cannot specify more than one input file");
966 cmd->infile = argv[i];
968 for (j = 1; argv[i][j] != 0; j++) {
985 * sample flag: Ss or Sc.
986 * Ss means set flag['S'];
987 * Sc means set flag['C'];
988 * Sm means set flag['M'];
990 ch = argv[i][++j]; /* get next char */
1004 case 'C': /* ANSI C syntax */
1005 ch = argv[i][j+1]; /* get next char */
1013 * Turn TIRPC flag off for
1014 * generating backward compatible
1035 svcclosetime = argv[i];
1046 inline_size = atoi(argv[i]);
1051 if (argv[i][j - 1] != '-' ||
1052 argv[i][j + 1] != 0)
1060 cmd->outfile = argv[i];
1064 if (argv[i][j - 1] != '-')
1071 strlcpy(pathbuf, argv[i], sizeof(pathbuf));
1072 if (strlcat(pathbuf, "/cpp", sizeof(pathbuf))
1073 >= sizeof(pathbuf)) {
1074 warnx("argument too long");
1090 cmd->cflag = flag['c'];
1091 cmd->hflag = flag['h'];
1092 cmd->lflag = flag['l'];
1093 cmd->mflag = flag['m'];
1094 cmd->nflag = flag['n'];
1095 cmd->sflag = flag['s'];
1096 cmd->tflag = flag['t'];
1097 cmd->Ssflag = flag['S'];
1098 cmd->Scflag = flag['C'];
1099 cmd->makefileflag = flag['M'];
1104 if ((inetdflag && cmd->nflag)) {
1105 /* netid not allowed with inetdflag */
1106 warnx("cannot use netid flag with inetd flag");
1109 } else { /* 4.1 mode */
1110 pmflag = 0; /* set pmflag only in tirpcmode */
1111 if (cmd->nflag) { /* netid needs TIRPC */
1112 warnx("cannot use netid flag without TIRPC");
1117 if (newstyle && (tblflag || cmd->tflag)) {
1118 warnx("cannot use table flags with newstyle");
1122 /* check no conflicts with file generation flags */
1123 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1124 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1125 cmd->Scflag + cmd->makefileflag;
1128 if (cmd->outfile != NULL || cmd->infile == NULL)
1130 } else if (cmd->infile == NULL &&
1131 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1132 warnx("\"infile\" is required for template generation flags");
1135 warnx("cannot have more than one file generation flag");
1144 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1145 "usage: rpcgen infile",
1146 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]"
1147 "[-I -P [-K seconds]] [-Y path] infile",
1148 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]"
1149 "[-o outfile] [infile]",
1150 " rpcgen [-s nettype]* [-o outfile] [infile]",
1151 " rpcgen [-n netid]* [-o outfile] [infile]");
1159 f_print(stderr, "options:\n");
1160 f_print(stderr, "-a\t\tgenerate all files, including samples\n");
1161 f_print(stderr, "-b\t\tbackward compatibility mode (generates code"
1162 "for SunOS 4.X)\n");
1163 f_print(stderr, "-c\t\tgenerate XDR routines\n");
1164 f_print(stderr, "-C\t\tANSI C mode\n");
1165 f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1166 f_print(stderr, "-h\t\tgenerate header file\n");
1167 f_print(stderr, "-i size\t\tsize at which to start generating"
1169 f_print(stderr, "-I\t\tgenerate code for inetd support in server\n");
1170 f_print(stderr, "-K seconds\tserver exits after K seconds of"
1172 f_print(stderr, "-l\t\tgenerate client side stubs\n");
1173 f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
1174 f_print(stderr, "-m\t\tgenerate server side stubs\n");
1175 f_print(stderr, "-M\t\tgenerate MT-safe code\n");
1176 f_print(stderr, "-n netid\tgenerate server code that supports"
1178 f_print(stderr, "-N\t\tsupports multiple arguments and"
1180 f_print(stderr, "-o outfile\tname of the output file\n");
1181 f_print(stderr, "-P\t\tgenerate code for port monitoring support in server\n");
1182 f_print(stderr, "-s nettype\tgenerate server code that supports named"
1184 f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote"
1186 f_print(stderr, "-Ss\t\tgenerate sample server code that defines"
1187 "remote procedures\n");
1188 f_print(stderr, "-Sm \t\tgenerate makefile template \n");
1190 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
1191 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
1192 f_print(stderr, "-Y path\t\tpath where cpp is found\n");