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";
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
43 * rpc_main.c, Top level of the RPC protocol compiler.
44 * Copyright (C) 1987, Sun Microsystems, Inc.
52 #include <sys/types.h>
53 #include <sys/param.h>
56 #include "rpc_parse.h"
60 extern void write_sample_svc( definition * );
61 extern int write_sample_clnt( definition * );
62 extern void write_sample_clnt_main( void );
63 extern void add_sample_msg( void );
64 static void c_output( char *, char *, int, char * );
65 static void h_output( char *, char *, int, char * );
66 static void l_output( char *, char *, int, char * );
67 static void t_output( char *, char *, int, char * );
68 static void clnt_output( char *, char *, int, char * );
69 void c_initialize( void );
71 #if !defined(__FreeBSD__) && !defined(__NetBSD__)
75 static void usage(void);
76 static void options_usage(void);
77 static int do_registers(int, char **);
78 static int parseargs(int, char **, struct commandline *);
79 static void svc_output(char *, char *, int, char *);
80 static void mkfile_output(struct commandline *);
81 static void s_output(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"
87 #define SUNOS_CPP "/usr/bin/cpp"
89 static int cppDefined = 0; /* explicit path for C preprocessor */
91 static char *svcclosetime = "120";
92 static char *CPP = SVR4_CPP;
93 static char CPPFLAGS[] = "-C";
94 static char pathbuf[MAXPATHLEN + 1];
95 static char *allv[] = {
96 "rpcgen", "-s", "udp", "-s", "tcp",
98 static int allc = sizeof (allv)/sizeof (allv[0]);
99 static char *allnv[] = {
100 "rpcgen", "-s", "netpath",
102 static int allnc = sizeof (allnv)/sizeof (allnv[0]);
105 * machinations for handling expanding argument list
107 static void addarg(); /* add another argument to the list */
108 static void putarg(); /* put argument at specified location */
109 static void clear_args(); /* clear argument list */
110 static void checkfiles(); /* check if out file already exists */
114 #define ARGLISTLEN 20
117 static char *arglist[ARGLISTLEN];
118 static int argcount = FIXEDARGS;
121 int nonfatalerrors; /* errors */
122 int inetdflag = 0; /* Support for inetd is disabled by default, use -I */
123 int pmflag = 0; /* Support for port monitors is disabled by default */
124 int tirpc_socket = 1; /* TI-RPC on socket, no TLI library */
125 int logflag; /* Use syslog instead of fprintf for errors */
126 int tblflag; /* Support for dispatch table file */
127 int mtflag = 0; /* Support for MT */
130 /* length at which to start doing an inline */
134 * Length at which to start doing an inline. INLINE = default
135 * if 0, no xdr_inline code
138 int indefinitewait; /* If started by port monitors, hang till it wants */
139 int exitnow; /* If started by port monitors, exit after the call */
140 int timerflag; /* TRUE if !indefinite && !exitnow */
141 int newstyle; /* newstyle of passing arguments (by value) */
142 int Cflag = 0; /* ANSI C syntax */
143 int CCflag = 0; /* C++ files */
144 static int allfiles; /* generate all files */
145 int tirpcflag = 1; /* generating code for tirpc, by default */
146 xdrfunc *xdrfunc_head = NULL; /* xdr function list */
147 xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
156 struct commandline cmd;
158 (void) memset((char *)&cmd, 0, sizeof (struct commandline));
160 if (!parseargs(argc, argv, &cmd))
163 * Only the client and server side stubs are likely to be customized,
164 * so in that case only, check if the outfile exists, and if so,
165 * print an error message and exit.
167 if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag) {
168 checkfiles(cmd.infile, cmd.outfile);
171 checkfiles(cmd.infile, NULL);
174 c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
175 } else if (cmd.hflag) {
176 h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
177 } else if (cmd.lflag) {
178 l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
179 } else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
180 s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
181 cmd.outfile, cmd.mflag, cmd.nflag);
182 } else if (cmd.tflag) {
183 t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
184 } else if (cmd.Ssflag) {
185 svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
187 } else if (cmd.Scflag) {
188 clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
190 } else if (cmd.makefileflag) {
193 /* the rescans are required, since cpp may effect input */
194 c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
196 h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
198 l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
200 if (inetdflag || !tirpcflag)
201 s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
202 "_svc.c", cmd.mflag, cmd.nflag);
204 s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
205 EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
208 t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
213 svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
216 clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
220 if (allfiles || (cmd.makefileflag == 1)){
226 exit(nonfatalerrors);
232 * add extension to filename
235 extendfile(path, ext)
243 if ((file = rindex(path, '/')) == NULL)
247 res = xmalloc(strlen(file) + strlen(ext) + 1);
248 p = strrchr(file, '.');
250 p = file + strlen(file);
252 (void) strcpy(res, file);
253 (void) strcpy(res + (p - file), ext);
258 * Open output file with given extension
261 open_output(infile, outfile)
266 if (outfile == NULL) {
271 if (infile != NULL && streq(outfile, infile)) {
272 warnx("%s already exists. No output generated", infile);
275 fout = fopen(outfile, "w");
277 warn("unable to open %s", outfile);
280 record_open(outfile);
288 f_print(fout, "/*\n");
289 f_print(fout, " * Please do not edit this file.\n");
290 f_print(fout, " * It was generated using rpcgen.\n");
291 f_print(fout, " */\n\n");
294 /* clear list of arguments */
295 static void clear_args()
298 for (i = FIXEDARGS; i < ARGLISTLEN; i++)
300 argcount = FIXEDARGS;
303 /* make sure that a CPP exists */
304 static void find_cpp()
308 if (stat(CPP, &buf) < 0) { /* SVR4 or explicit cpp does not exist */
310 warnx("cannot find C preprocessor: %s", CPP);
312 } else { /* try the other one */
314 if (stat(CPP, &buf) < 0) { /* can't find any cpp */
315 warnx("cannot find C preprocessor: %s", CPP);
323 * Open input file with given define for C-preprocessor
326 open_input(infile, define)
332 infilename = (infile == NULL) ? "<stdin>" : infile;
334 switch (childpid = fork()) {
342 addarg((char *)NULL);
344 (void) dup2(pd[1], 1);
346 execv(arglist[0], arglist);
352 fin = fdopen(pd[0], "r");
354 warn("%s", infilename);
359 /* valid tirpc nettypes */
360 static char* valid_ti_nettypes[] =
374 /* valid inetd nettypes */
375 static char* valid_i_nettypes[] =
382 static int check_nettype(name, list_to_check)
384 char* list_to_check[];
387 for (i = 0; list_to_check[i] != NULL; i++) {
388 if (strcmp(name, list_to_check[i]) == 0) {
392 warnx("illegal nettype :\'%s\'", name);
402 temp = extendfile(file, ext);
404 if (access(temp, F_OK) != -1)
407 return ((char *)" ");
413 c_output(infile, define, extend, outfile)
425 open_input(infile, define);
426 outfilename = extend ? extendfile(infile, outfile) : outfile;
427 open_output(infile, outfilename);
429 if (infile && (include = extendfile(infile, ".h"))) {
430 f_print(fout, "#include \"%s\"\n", include);
432 /* .h file already contains rpc/rpc.h */
434 f_print(fout, "#include <rpc/rpc.h>\n");
436 while ( (def = get_definition()) ) {
439 if (extend && tell == ftell(fout)) {
440 (void) unlink(outfilename);
449 /* add all the starting basic types */
452 add_type(1, "short");
454 add_type(1, "u_int");
455 add_type(1, "u_long");
456 add_type(1, "u_short");
460 char rpcgen_table_dcl[] = "struct rpcgen_table {\n\
462 xdrproc_t xdr_arg; \n\
463 unsigned len_arg; \n\
464 xdrproc_t xdr_res; \n\
465 unsigned len_res; \n\
469 char *generate_guard(pathname)
472 char* filename, *guard, *tmp;
474 filename = strrchr(pathname, '/'); /* find last component */
475 filename = ((filename == 0) ? pathname : filename+1);
476 guard = xstrdup(filename);
477 /* convert to a valid C macro name, and upper case
478 * =~ m,[A-Za-z_][A-Za-z_0-9]*, else map other chars to '_'.
480 for (tmp = guard; '\000' != *tmp; ++tmp) {
482 *tmp = toupper(*tmp);
483 else if (isupper(*tmp) || '_' == *tmp)
485 else if (tmp == guard)
487 else if (isdigit(*tmp))
488 /* OK for all but first character */;
489 else if ('.' == *tmp) {
495 /* When the filename started with "." (wow, the is Poor Form)
496 * lets put in the word "DOT" so we don't violate ANSI's reservation
497 * of macros that start with "_" -- rpc at ksb.npcguild.org
499 if ('\000' == *guard) {
502 guard = extendfile(guard, "_H_RPCGEN");
507 * Compile into an XDR header file
512 h_output(infile, define, extend, outfile)
526 open_input(infile, define);
527 outfilename = extend ? extendfile(infile, outfile) : outfile;
528 open_output(infile, outfilename);
530 if (outfilename || infile){
531 guard = generate_guard(outfilename ? outfilename: infile);
535 f_print(fout, "#ifndef _%s\n#define _%s\n\n", guard,
538 f_print(fout, "#include <rpc/rpc.h>\n");
541 f_print(fout, "#include <pthread.h>\n");
543 /* put the C++ support */
544 if (Cflag && !CCflag){
545 f_print(fout, "\n#ifdef __cplusplus\n");
546 f_print(fout, "extern \"C\" {\n");
547 f_print(fout, "#endif\n\n");
550 /* put in a typedef for quadprecision. Only with Cflag */
554 /* print data definitions */
555 while ( (def = get_definition()) ) {
560 * print function declarations.
561 * Do this after data definitions because they might be used as
562 * arguments for functions
564 for (l = defined; l != NULL; l = l->next) {
565 print_funcdef(l->val);
567 /* Now print all xdr func declarations */
568 if (xdrfunc_head != NULL){
571 "\n/* the xdr functions */\n");
574 f_print(fout, "\n#ifdef __cplusplus\n");
575 f_print(fout, "extern \"C\" {\n");
576 f_print(fout, "#endif\n");
580 xdrfuncp = xdrfunc_head;
581 while (xdrfuncp != NULL){
582 print_xdr_func_def(xdrfuncp->name,
583 xdrfuncp->pointerp, 2);
584 xdrfuncp = xdrfuncp->next;
588 for (i = 1; i < 3; i++){
590 f_print(fout, "\n#if defined(__STDC__) || defined(__cplusplus)\n");
593 f_print(fout, "\n#else /* K&R C */\n");
595 xdrfuncp = xdrfunc_head;
596 while (xdrfuncp != NULL){
597 print_xdr_func_def(xdrfuncp->name,
598 xdrfuncp->pointerp, i);
599 xdrfuncp = xdrfuncp->next;
602 f_print(fout, "\n#endif /* K&R C */\n");
606 if (extend && tell == ftell(fout)) {
607 (void) unlink(outfilename);
608 } else if (tblflag) {
609 f_print(fout, rpcgen_table_dcl);
613 f_print(fout, "\n#ifdef __cplusplus\n");
614 f_print(fout, "}\n");
615 f_print(fout, "#endif\n");
618 f_print(fout, "\n#endif /* !_%s */\n", guard);
622 * Compile into an RPC service
625 s_output(argc, argv, infile, define, extend, outfile, nomain, netflag)
637 int foundprogram = 0;
640 open_input(infile, define);
641 outfilename = extend ? extendfile(infile, outfile) : outfile;
642 open_output(infile, outfilename);
644 if (infile && (include = extendfile(infile, ".h"))) {
645 f_print(fout, "#include \"%s\"\n", include);
648 f_print(fout, "#include <rpc/rpc.h>\n");
650 f_print(fout, "#include <stdio.h>\n");
651 f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
654 "#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
655 f_print (fout, "#include <string.h> /* strcmp */\n");
658 f_print(fout, "#include <rpc/rpc_com.h>\n");
659 if (strcmp(svcclosetime, "-1") == 0)
661 else if (strcmp(svcclosetime, "0") == 0)
663 else if (inetdflag || pmflag) {
664 f_print(fout, "#include <signal.h>\n");
668 if (!tirpcflag && inetdflag)
669 f_print(fout, "#include <sys/ttycom.h> /* TIOCNOTTY */\n");
670 if (Cflag && (inetdflag || pmflag)) {
671 f_print(fout, "#ifdef __cplusplus\n");
673 "#include <sysent.h> /* getdtablesize, open */\n");
674 f_print(fout, "#endif /* __cplusplus */\n");
677 f_print(fout, "#include <fcntl.h> /* open */\n");
678 f_print(fout, "#include <unistd.h> /* fork / setsid */\n");
679 f_print(fout, "#include <sys/types.h>\n");
682 f_print(fout, "#include <memory.h>\n");
683 if (inetdflag || !tirpcflag) {
684 f_print(fout, "#include <sys/socket.h>\n");
685 f_print(fout, "#include <netinet/in.h>\n");
688 if ((netflag || pmflag) && tirpcflag && !nomain) {
689 f_print(fout, "#include <netconfig.h>\n");
692 f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
693 if (logflag || inetdflag || pmflag || tirpcflag)
694 f_print(fout, "#include <syslog.h>\n");
699 "\n#ifndef SIG_PF\n#define SIG_PF void(*)\
702 f_print(fout, "\n#ifdef DEBUG\n#define RPC_SVC_FG\n#endif\n");
704 f_print(fout, "\n#define _RPCSVC_CLOSEDOWN %s\n",
706 while ( (def = get_definition()) ) {
707 foundprogram |= (def->def_kind == DEF_PROGRAM);
709 if (extend && !foundprogram) {
710 (void) unlink(outfilename);
713 write_most(infile, netflag, nomain);
715 if (!do_registers(argc, argv)) {
717 (void) unlink(outfilename);
725 * generate client side stubs
728 l_output(infile, define, extend, outfile)
736 int foundprogram = 0;
739 open_input(infile, define);
740 outfilename = extend ? extendfile(infile, outfile) : outfile;
741 open_output(infile, outfilename);
744 f_print (fout, "#include <memory.h> /* for memset */\n");
745 if (infile && (include = extendfile(infile, ".h"))) {
746 f_print(fout, "#include \"%s\"\n", include);
749 f_print(fout, "#include <rpc/rpc.h>\n");
750 while ( (def = get_definition()) ) {
751 foundprogram |= (def->def_kind == DEF_PROGRAM);
753 if (extend && !foundprogram) {
754 (void) unlink(outfilename);
761 * generate the dispatch table
764 t_output(infile, define, extend, outfile)
771 int foundprogram = 0;
774 open_input(infile, define);
775 outfilename = extend ? extendfile(infile, outfile) : outfile;
776 open_output(infile, outfilename);
778 while ( (def = get_definition()) ) {
779 foundprogram |= (def->def_kind == DEF_PROGRAM);
781 if (extend && !foundprogram) {
782 (void) unlink(outfilename);
788 /* sample routine for the server template */
790 svc_output(infile, define, extend, outfile)
800 open_input(infile, define);
801 outfilename = extend ? extendfile(infile, outfile) : outfile;
802 checkfiles(infile, outfilename);
804 * Check if outfile already exists.
805 * if so, print an error message and exit
807 open_output(infile, outfilename);
810 if (infile && (include = extendfile(infile, ".h"))) {
811 f_print(fout, "#include \"%s\"\n", include);
814 f_print(fout, "#include <rpc/rpc.h>\n");
817 while ( (def = get_definition()) ) {
818 write_sample_svc(def);
820 if (extend && tell == ftell(fout)) {
821 (void) unlink(outfilename);
825 /* sample main routine for client */
827 clnt_output(infile, define, extend, outfile)
839 open_input(infile, define);
840 outfilename = extend ? extendfile(infile, outfile) : outfile;
841 checkfiles(infile, outfilename);
843 * Check if outfile already exists.
844 * if so, print an error message and exit
847 open_output(infile, outfilename);
849 if (infile && (include = extendfile(infile, ".h"))) {
850 f_print(fout, "#include \"%s\"\n", include);
853 f_print(fout, "#include <rpc/rpc.h>\n");
855 while ( (def = get_definition()) ) {
856 has_program += write_sample_clnt(def);
860 write_sample_clnt_main();
862 if (extend && tell == ftell(fout)) {
863 (void) unlink(outfilename);
868 static void mkfile_output(cmd)
869 struct commandline *cmd;
871 char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
872 char *servername, *svcname, *servprogname, *clntprogname;
875 svcname = file_name(cmd->infile, "_svc.c");
876 clntname = file_name(cmd->infile, "_clnt.c");
877 xdrname = file_name(cmd->infile, "_xdr.c");
878 hdrname = file_name(cmd->infile, ".h");
882 servername = extendfile(cmd->infile, "_server.c");
883 clientname = extendfile(cmd->infile, "_client.c");
888 servprogname = extendfile(cmd->infile, "_server");
889 clntprogname = extendfile(cmd->infile, "_client");
892 mkfilename = xmalloc(strlen("makefile.") +
893 strlen(cmd->infile) + 1);
894 temp = (char *)rindex(cmd->infile, '.');
895 strcpy(mkfilename, "makefile.");
896 (void) strncat(mkfilename, cmd->infile,
897 (temp - cmd->infile));
899 mkfilename = cmd->outfile;
902 checkfiles(NULL, mkfilename);
903 open_output(NULL, mkfilename);
905 f_print(fout, "\n# This is a template makefile generated\
908 f_print(fout, "\n# Parameters \n\n");
910 f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
911 clntprogname, servprogname);
912 f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
913 f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
914 f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
915 f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
916 svcname, servername, xdrname);
917 f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
918 clntname, clientname, xdrname);
919 f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
920 hdrname, xdrname, clntname,
921 svcname, clientname, servername);
923 f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) \
924 $(TARGETS_CLNT.c:%%.c=%%.o) ");
926 f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) \
927 $(TARGETS_SVC.c:%%.c=%%.o) ");
930 f_print(fout, "\n# Compiler flags \n");
932 f_print(fout, "\nCFLAGS += -D_REENTRANT -D_THEAD_SAFE \nLDLIBS += -pthread\n");
934 f_print(fout, "RPCGENFLAGS = \n");
936 f_print(fout, "\n# Targets \n\n");
938 f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
939 f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
940 f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
941 f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
942 $(TARGETS_CLNT.c) \n\n");
944 f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
945 $(TARGETS_SVC.c) \n\n");
946 f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
947 f_print(fout, "\t$(CC) -o $(CLIENT) $(OBJECTS_CLNT) \
949 f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
950 f_print(fout, "\t$(CC) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
951 f_print(fout, "clean:\n\t $(RM) -f core $(TARGETS) $(OBJECTS_CLNT) \
952 $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
958 * Perform registrations for service output
959 * Return 0 if failed; 1 otherwise.
962 do_registers(argc, argv)
968 if (inetdflag || !tirpcflag) {
969 for (i = 1; i < argc; i++) {
970 if (streq(argv[i], "-s")) {
971 if (!check_nettype(argv[i + 1],
974 write_inetd_register(argv[i + 1]);
979 for (i = 1; i < argc; i++)
980 if (streq(argv[i], "-s")) {
981 if (!check_nettype(argv[i + 1],
984 write_nettype_register(argv[i + 1]);
986 } else if (streq(argv[i], "-n")) {
987 write_netid_register(argv[i + 1]);
995 * Add another argument to the arg list
1001 if (argcount >= ARGLISTLEN) {
1002 warnx("too many defines");
1006 arglist[argcount++] = cp;
1015 if (where >= ARGLISTLEN) {
1016 warnx("arglist coding error");
1020 arglist[where] = cp;
1024 * if input file is stdin and an output file is specified then complain
1025 * if the file already exists. Otherwise the file may get overwritten
1026 * If input file does not exist, exit with an error
1030 checkfiles(infile, outfile)
1037 if (infile) /* infile ! = NULL */
1038 if (stat(infile, &buf) < 0)
1044 if (stat(outfile, &buf) < 0)
1045 return; /* file does not exist */
1047 warnx("file '%s' already exists and may be overwritten", outfile);
1054 * Parse command line arguments
1057 parseargs(argc, argv, cmd)
1060 struct commandline *cmd;
1065 char flag[(1 << 8 * sizeof (char))];
1068 cmd->infile = cmd->outfile = NULL;
1085 for (i = 1; i < argc; i++) {
1086 if (argv[i][0] != '-') {
1088 warnx("cannot specify more than one input file");
1091 cmd->infile = argv[i];
1093 for (j = 1; argv[i][j] != 0; j++) {
1111 * sample flag: Ss or Sc.
1112 * Ss means set flag['S'];
1113 * Sc means set flag['C'];
1114 * Sm means set flag['M'];
1116 ch = argv[i][++j]; /* get next char */
1126 if (flag[(int)ch]) {
1131 case 'C': /* ANSI C syntax */
1133 ch = argv[i][j+1]; /* get next char */
1141 * Turn TIRPC flag off for
1142 * generating backward compatible
1164 svcclosetime = argv[i];
1176 inline = atoi(argv[i]);
1181 if (argv[i][j - 1] != '-' ||
1182 argv[i][j + 1] != 0) {
1193 cmd->outfile = argv[i];
1197 if (argv[i][j - 1] != '-') {
1200 (void) addarg(argv[i]);
1206 (void) strlcpy(pathbuf, argv[i], sizeof(pathbuf));
1207 if (strlcat(pathbuf, "/cpp", sizeof(pathbuf))
1208 >= sizeof(pathbuf)) {
1209 warnx("argument too long");
1227 cmd->cflag = flag['c'];
1228 cmd->hflag = flag['h'];
1229 cmd->lflag = flag['l'];
1230 cmd->mflag = flag['m'];
1231 cmd->nflag = flag['n'];
1232 cmd->sflag = flag['s'];
1233 cmd->tflag = flag['t'];
1234 cmd->Ssflag = flag['S'];
1235 cmd->Scflag = flag['C'];
1236 cmd->makefileflag = flag['M'];
1241 if ((inetdflag && cmd->nflag)) {
1242 /* netid not allowed with inetdflag */
1243 warnx("cannot use netid flag with inetd flag");
1246 } else { /* 4.1 mode */
1247 pmflag = 0; /* set pmflag only in tirpcmode */
1248 if (cmd->nflag) { /* netid needs TIRPC */
1249 warnx("cannot use netid flag without TIRPC");
1254 if (newstyle && (tblflag || cmd->tflag)) {
1255 warnx("cannot use table flags with newstyle");
1259 /* check no conflicts with file generation flags */
1260 nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
1261 cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
1262 cmd->Scflag + cmd->makefileflag;
1265 if (cmd->outfile != NULL || cmd->infile == NULL) {
1268 } else if (cmd->infile == NULL &&
1269 (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
1270 warnx("\"infile\" is required for template generation flags");
1273 warnx("cannot have more than one file generation flag");
1282 f_print(stderr, "%s\n%s\n%s\n%s\n%s\n",
1283 "usage: rpcgen infile",
1284 " rpcgen [-abCLNTM] [-Dname[=value]] [-i size]\
1285 [-I -P [-K seconds]] [-Y path] infile",
1286 " rpcgen [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]\
1287 [-o outfile] [infile]",
1288 " rpcgen [-s nettype]* [-o outfile] [infile]",
1289 " rpcgen [-n netid]* [-o outfile] [infile]");
1297 f_print(stderr, "options:\n");
1298 f_print(stderr, "-a\t\tgenerate all files, including samples\n");
1299 f_print(stderr, "-b\t\tbackward compatibility mode (generates code \
1300 for FreeBSD 4.X)\n");
1301 f_print(stderr, "-c\t\tgenerate XDR routines\n");
1302 f_print(stderr, "-C\t\tANSI C mode\n");
1303 f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
1304 f_print(stderr, "-h\t\tgenerate header file\n");
1305 f_print(stderr, "-i size\t\tsize at which to start generating\
1307 f_print(stderr, "-I\t\tgenerate code for inetd support in server\n");
1308 f_print(stderr, "-K seconds\tserver exits after K seconds of\
1310 f_print(stderr, "-l\t\tgenerate client side stubs\n");
1311 f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
1312 f_print(stderr, "-m\t\tgenerate server side stubs\n");
1313 f_print(stderr, "-M\t\tgenerate MT-safe code\n");
1314 f_print(stderr, "-n netid\tgenerate server code that supports\
1316 f_print(stderr, "-N\t\tsupports multiple arguments and\
1318 f_print(stderr, "-o outfile\tname of the output file\n");
1319 f_print(stderr, "-P\t\tgenerate code for port monitoring support in server\n");
1320 f_print(stderr, "-s nettype\tgenerate server code that supports named\
1322 f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote\
1324 f_print(stderr, "-Ss\t\tgenerate sample server code that defines\
1325 remote procedures\n");
1326 f_print(stderr, "-Sm \t\tgenerate makefile template \n");
1328 f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
1329 f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
1330 f_print(stderr, "-Y path\t\tpath where cpp is found\n");