xref: /illumos-gate/usr/src/cmd/rpcgen/rpc_main.c (revision 61961e0f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
22*61961e0fSrobinson 
237c478bd9Sstevel@tonic-gate /*
247c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
287c478bd9Sstevel@tonic-gate /* All Rights Reserved */
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * rpc_main.c, Top level of the RPC protocol compiler.
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #include <stdio.h>
46*61961e0fSrobinson #include <stdlib.h>
477c478bd9Sstevel@tonic-gate #include <string.h>
48*61961e0fSrobinson #include <strings.h>
497c478bd9Sstevel@tonic-gate #include <unistd.h>
50*61961e0fSrobinson #include <ctype.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate #include <sys/param.h>
537c478bd9Sstevel@tonic-gate #include <sys/file.h>
547c478bd9Sstevel@tonic-gate #include <sys/stat.h>
557c478bd9Sstevel@tonic-gate #include "rpc_parse.h"
567c478bd9Sstevel@tonic-gate #include "rpc_util.h"
577c478bd9Sstevel@tonic-gate #include "rpc_scan.h"
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate 
60*61961e0fSrobinson extern void write_sample_svc(definition *);
61*61961e0fSrobinson extern int write_sample_clnt(definition *);
62*61961e0fSrobinson extern void write_sample_clnt_main(void);
63*61961e0fSrobinson extern void reinitialize(void);
64*61961e0fSrobinson extern void crash(void);
65*61961e0fSrobinson extern void add_type(int, char *);
66*61961e0fSrobinson extern void add_sample_msg(void);
67*61961e0fSrobinson 
68*61961e0fSrobinson static void svc_output(char *, char *, int, char *);
69*61961e0fSrobinson static void clnt_output(char *, char *, int, char *);
70*61961e0fSrobinson static void c_output(char *, char *, int, char *);
71*61961e0fSrobinson static void mkfile_output(struct commandline *);
72*61961e0fSrobinson static void c_initialize(void);
73*61961e0fSrobinson static void h_output(char *, char *, int, char *);
74*61961e0fSrobinson static void s_output(int, char *[], char *, char *, int, char *, int, int);
75*61961e0fSrobinson static void l_output(char *, char *, int, char *);
76*61961e0fSrobinson static void t_output(char *, char *, int, char *);
77*61961e0fSrobinson static int do_registers(int, char *[]);
78*61961e0fSrobinson static uint_t parseargs(int, char *[], struct commandline *);
79*61961e0fSrobinson static void usage(void);
80*61961e0fSrobinson static void version_info(void);
81*61961e0fSrobinson static void options_usage(void);
82*61961e0fSrobinson 
83*61961e0fSrobinson #define	EXTEND		1		/* alias for TRUE */
847c478bd9Sstevel@tonic-gate #define	DONT_EXTEND	0		/* alias for FALSE */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #define	SUNOS_CPP "/usr/lib/cpp"
877c478bd9Sstevel@tonic-gate static int cppDefined = 0;	/* explicit path for C preprocessor */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate static char *cmdname;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate static char *svcclosetime = "120";
937c478bd9Sstevel@tonic-gate static char *CPP = SUNOS_CPP;
947c478bd9Sstevel@tonic-gate static char CPPFLAGS[] = "-C";
957c478bd9Sstevel@tonic-gate static char pathbuf[MAXPATHLEN + 1];
967c478bd9Sstevel@tonic-gate static char *allv[] = {
977c478bd9Sstevel@tonic-gate 	"rpcgen", "-s", "udp", "-s", "tcp",
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate static int allc = sizeof (allv)/sizeof (allv[0]);
1007c478bd9Sstevel@tonic-gate static char *allnv[] = {
1017c478bd9Sstevel@tonic-gate 	"rpcgen", "-s", "netpath",
1027c478bd9Sstevel@tonic-gate };
1037c478bd9Sstevel@tonic-gate static int allnc = sizeof (allnv)/sizeof (allnv[0]);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * machinations for handling expanding argument list
1077c478bd9Sstevel@tonic-gate  */
108*61961e0fSrobinson static void addarg(char *);	/* add another argument to the list */
109*61961e0fSrobinson static void putarg(int, char *); /* put argument at specified location  */
110*61961e0fSrobinson static void clear_args(void);	/* clear argument list */
111*61961e0fSrobinson static void checkfiles(char *, char *);	/* check if out file already exists */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #define	ARGLISTLEN	20
1157c478bd9Sstevel@tonic-gate #define	FIXEDARGS	2
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate static char *arglist[ARGLISTLEN];
1187c478bd9Sstevel@tonic-gate static int argcount = FIXEDARGS;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate int nonfatalerrors;	/* errors */
1227c478bd9Sstevel@tonic-gate int inetdflag;	/* Support for inetd  is now the default */
1237c478bd9Sstevel@tonic-gate int pmflag;		/* Support for port monitors */
1247c478bd9Sstevel@tonic-gate int logflag;		/* Use syslog instead of fprintf for errors */
1257c478bd9Sstevel@tonic-gate int tblflag;		/* Support for dispatch table file */
1267c478bd9Sstevel@tonic-gate int mtflag = 0;		/* Support for MT */
1277c478bd9Sstevel@tonic-gate int mtauto = 0;		/* Enable automatic mode */
1287c478bd9Sstevel@tonic-gate int rflag = 1;		/* Eliminate tail recursion from structures */
1297c478bd9Sstevel@tonic-gate #define	INLINE 5
1307c478bd9Sstevel@tonic-gate /* length at which to start doing an inline */
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate int inlinelen = INLINE;
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Length at which to start doing an inline. INLINE = default
1357c478bd9Sstevel@tonic-gate  * if 0, no xdr_inline code
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate int indefinitewait;	/* If started by port monitors, hang till it wants */
1397c478bd9Sstevel@tonic-gate int exitnow;		/* If started by port monitors, exit after the call */
1407c478bd9Sstevel@tonic-gate int timerflag;		/* TRUE if !indefinite && !exitnow */
1417c478bd9Sstevel@tonic-gate int newstyle;		/* newstyle of passing arguments (by value) */
1427c478bd9Sstevel@tonic-gate int Cflag = 0;		/* ANSI C syntax */
1437c478bd9Sstevel@tonic-gate int CCflag = 0;		/* C++ files */
1447c478bd9Sstevel@tonic-gate static int allfiles;   /* generate all files */
1457c478bd9Sstevel@tonic-gate int tirpcflag = 1;    /* generating code for tirpc, by default */
1467c478bd9Sstevel@tonic-gate xdrfunc *xdrfunc_head = NULL; /* xdr function list */
1477c478bd9Sstevel@tonic-gate xdrfunc *xdrfunc_tail = NULL; /* xdr function list */
1487c478bd9Sstevel@tonic-gate pid_t childpid;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 
151*61961e0fSrobinson int
152*61961e0fSrobinson main(int argc, char *argv[])
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate 	struct commandline cmd;
1557c478bd9Sstevel@tonic-gate 
156*61961e0fSrobinson 	(void) memset(&cmd, 0, sizeof (struct commandline));
1577c478bd9Sstevel@tonic-gate 	clear_args();
1587c478bd9Sstevel@tonic-gate 	if (!parseargs(argc, argv, &cmd))
1597c478bd9Sstevel@tonic-gate 		usage();
1607c478bd9Sstevel@tonic-gate 	/*
1617c478bd9Sstevel@tonic-gate 	 * Only the client and server side stubs are likely to be customized,
1627c478bd9Sstevel@tonic-gate 	 *  so in that case only, check if the outfile exists, and if so,
1637c478bd9Sstevel@tonic-gate 	 *  print an error message and exit.
1647c478bd9Sstevel@tonic-gate 	 */
165*61961e0fSrobinson 	if (cmd.Ssflag || cmd.Scflag || cmd.makefileflag)
1667c478bd9Sstevel@tonic-gate 		checkfiles(cmd.infile, cmd.outfile);
1677c478bd9Sstevel@tonic-gate 	else
1687c478bd9Sstevel@tonic-gate 		checkfiles(cmd.infile, NULL);
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 	if (cmd.cflag) {
1717c478bd9Sstevel@tonic-gate 		c_output(cmd.infile, "-DRPC_XDR", DONT_EXTEND, cmd.outfile);
1727c478bd9Sstevel@tonic-gate 	} else if (cmd.hflag) {
1737c478bd9Sstevel@tonic-gate 		h_output(cmd.infile, "-DRPC_HDR", DONT_EXTEND, cmd.outfile);
1747c478bd9Sstevel@tonic-gate 	} else if (cmd.lflag) {
1757c478bd9Sstevel@tonic-gate 		l_output(cmd.infile, "-DRPC_CLNT", DONT_EXTEND, cmd.outfile);
1767c478bd9Sstevel@tonic-gate 	} else if (cmd.sflag || cmd.mflag || (cmd.nflag)) {
1777c478bd9Sstevel@tonic-gate 		s_output(argc, argv, cmd.infile, "-DRPC_SVC", DONT_EXTEND,
1787c478bd9Sstevel@tonic-gate 			cmd.outfile, cmd.mflag, cmd.nflag);
1797c478bd9Sstevel@tonic-gate 	} else if (cmd.tflag) {
1807c478bd9Sstevel@tonic-gate 		t_output(cmd.infile, "-DRPC_TBL", DONT_EXTEND, cmd.outfile);
1817c478bd9Sstevel@tonic-gate 	} else if (cmd.Ssflag) {
1827c478bd9Sstevel@tonic-gate 		svc_output(cmd.infile, "-DRPC_SERVER", DONT_EXTEND,
1837c478bd9Sstevel@tonic-gate 			cmd.outfile);
1847c478bd9Sstevel@tonic-gate 	} else if (cmd.Scflag) {
1857c478bd9Sstevel@tonic-gate 		clnt_output(cmd.infile, "-DRPC_CLIENT", DONT_EXTEND,
1867c478bd9Sstevel@tonic-gate 			    cmd.outfile);
1877c478bd9Sstevel@tonic-gate 	} else if (cmd.makefileflag) {
1887c478bd9Sstevel@tonic-gate 		mkfile_output(&cmd);
1897c478bd9Sstevel@tonic-gate 	} else {
1907c478bd9Sstevel@tonic-gate 		/* the rescans are required, since cpp may effect input */
1917c478bd9Sstevel@tonic-gate 		c_output(cmd.infile, "-DRPC_XDR", EXTEND, "_xdr.c");
1927c478bd9Sstevel@tonic-gate 		reinitialize();
1937c478bd9Sstevel@tonic-gate 		h_output(cmd.infile, "-DRPC_HDR", EXTEND, ".h");
1947c478bd9Sstevel@tonic-gate 		reinitialize();
1957c478bd9Sstevel@tonic-gate 		l_output(cmd.infile, "-DRPC_CLNT", EXTEND, "_clnt.c");
1967c478bd9Sstevel@tonic-gate 		reinitialize();
1977c478bd9Sstevel@tonic-gate 		if (inetdflag || !tirpcflag)
1987c478bd9Sstevel@tonic-gate 			s_output(allc, allv, cmd.infile, "-DRPC_SVC", EXTEND,
1997c478bd9Sstevel@tonic-gate 			"_svc.c", cmd.mflag, cmd.nflag);
2007c478bd9Sstevel@tonic-gate 		else
2017c478bd9Sstevel@tonic-gate 			s_output(allnc, allnv, cmd.infile, "-DRPC_SVC",
2027c478bd9Sstevel@tonic-gate 				EXTEND, "_svc.c", cmd.mflag, cmd.nflag);
2037c478bd9Sstevel@tonic-gate 		if (tblflag) {
2047c478bd9Sstevel@tonic-gate 			reinitialize();
205*61961e0fSrobinson 			t_output(cmd.infile, "-DRPC_TBL", EXTEND, "_tbl.i");
2067c478bd9Sstevel@tonic-gate 		}
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 		if (allfiles) {
2097c478bd9Sstevel@tonic-gate 			reinitialize();
2107c478bd9Sstevel@tonic-gate 			svc_output(cmd.infile, "-DRPC_SERVER", EXTEND,
2117c478bd9Sstevel@tonic-gate 				"_server.c");
2127c478bd9Sstevel@tonic-gate 			reinitialize();
2137c478bd9Sstevel@tonic-gate 			clnt_output(cmd.infile, "-DRPC_CLIENT", EXTEND,
2147c478bd9Sstevel@tonic-gate 				"_client.c");
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 		}
2177c478bd9Sstevel@tonic-gate 		if (allfiles || (cmd.makefileflag == 1)) {
2187c478bd9Sstevel@tonic-gate 			reinitialize();
2197c478bd9Sstevel@tonic-gate 			mkfile_output(&cmd);
2207c478bd9Sstevel@tonic-gate 		}
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	}
223*61961e0fSrobinson 	return (nonfatalerrors);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate  * add extension to filename
2297c478bd9Sstevel@tonic-gate  */
2307c478bd9Sstevel@tonic-gate static char *
231*61961e0fSrobinson extendfile(char *file, char *ext)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate 	char *res;
2347c478bd9Sstevel@tonic-gate 	char *p;
2357c478bd9Sstevel@tonic-gate 
236*61961e0fSrobinson 	res = malloc(strlen(file) + strlen(ext) + 1);
237*61961e0fSrobinson 	if (res == NULL)
2387c478bd9Sstevel@tonic-gate 		abort();
2397c478bd9Sstevel@tonic-gate 	p = strrchr(file, '.');
240*61961e0fSrobinson 	if (p == NULL)
2417c478bd9Sstevel@tonic-gate 		p = file + strlen(file);
2427c478bd9Sstevel@tonic-gate 	(void) strcpy(res, file);
2437c478bd9Sstevel@tonic-gate 	(void) strcpy(res + (p - file), ext);
2447c478bd9Sstevel@tonic-gate 	return (res);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate /*
2487c478bd9Sstevel@tonic-gate  * Open output file with given extension
2497c478bd9Sstevel@tonic-gate  */
250*61961e0fSrobinson static void
251*61961e0fSrobinson open_output(char *infile, char *outfile)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	if (outfile == NULL) {
2557c478bd9Sstevel@tonic-gate 		fout = stdout;
2567c478bd9Sstevel@tonic-gate 		return;
2577c478bd9Sstevel@tonic-gate 	}
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if (infile != NULL && streq(outfile, infile)) {
2607c478bd9Sstevel@tonic-gate 	f_print(stderr, "%s: %s already exists.  No output generated.\n",
2617c478bd9Sstevel@tonic-gate 		cmdname, infile);
2627c478bd9Sstevel@tonic-gate 		crash();
2637c478bd9Sstevel@tonic-gate 	}
2647c478bd9Sstevel@tonic-gate 	fout = fopen(outfile, "w");
2657c478bd9Sstevel@tonic-gate 	if (fout == NULL) {
2667c478bd9Sstevel@tonic-gate 		f_print(stderr, "%s: unable to open ", cmdname);
2677c478bd9Sstevel@tonic-gate 		perror(outfile);
2687c478bd9Sstevel@tonic-gate 		crash();
2697c478bd9Sstevel@tonic-gate 	}
2707c478bd9Sstevel@tonic-gate 	record_open(outfile);
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate }
2737c478bd9Sstevel@tonic-gate 
274*61961e0fSrobinson static void
275*61961e0fSrobinson add_warning(void)
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate 	f_print(fout, "/*\n");
2787c478bd9Sstevel@tonic-gate 	f_print(fout, " * Please do not edit this file.\n");
2797c478bd9Sstevel@tonic-gate 	f_print(fout, " * It was generated using rpcgen.\n");
2807c478bd9Sstevel@tonic-gate 	f_print(fout, " */\n\n");
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate /* clear list of arguments */
284*61961e0fSrobinson static void
285*61961e0fSrobinson clear_args(void)
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate 	int i;
288*61961e0fSrobinson 
2897c478bd9Sstevel@tonic-gate 	for (i = FIXEDARGS; i < ARGLISTLEN; i++)
2907c478bd9Sstevel@tonic-gate 		arglist[i] = NULL;
2917c478bd9Sstevel@tonic-gate 	argcount = FIXEDARGS;
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /* make sure that a CPP exists */
295*61961e0fSrobinson static void
296*61961e0fSrobinson find_cpp(void)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	struct stat buf;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	if (stat(CPP, &buf) < 0)  { /* SVR4 or explicit cpp does not exist */
3017c478bd9Sstevel@tonic-gate 		if (cppDefined) {
302*61961e0fSrobinson 			(void) fprintf(stderr,
3037c478bd9Sstevel@tonic-gate 				"cannot find C preprocessor: %s \n", CPP);
3047c478bd9Sstevel@tonic-gate 			crash();
3057c478bd9Sstevel@tonic-gate 		} else {	/* try the other one */
3067c478bd9Sstevel@tonic-gate 			CPP = SUNOS_CPP;
3077c478bd9Sstevel@tonic-gate 			if (stat(CPP, &buf) < 0) { /* can't find any cpp */
308*61961e0fSrobinson 				(void) fprintf(stderr,
3097c478bd9Sstevel@tonic-gate 		"cannot find any C preprocessor (cpp)\n");
3107c478bd9Sstevel@tonic-gate 				crash();
3117c478bd9Sstevel@tonic-gate 			}
3127c478bd9Sstevel@tonic-gate 		}
3137c478bd9Sstevel@tonic-gate 	}
3147c478bd9Sstevel@tonic-gate }
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate /*
3177c478bd9Sstevel@tonic-gate  * Open input file with given define for C-preprocessor
3187c478bd9Sstevel@tonic-gate  */
319*61961e0fSrobinson static void
320*61961e0fSrobinson open_input(char *infile, char *define)
3217c478bd9Sstevel@tonic-gate {
3227c478bd9Sstevel@tonic-gate 	int pd[2];
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	infilename = (infile == NULL) ? "<stdin>" : infile;
3257c478bd9Sstevel@tonic-gate 	(void) pipe(pd);
3267c478bd9Sstevel@tonic-gate 	switch (childpid = fork()) {
3277c478bd9Sstevel@tonic-gate 	case 0:
3287c478bd9Sstevel@tonic-gate 		find_cpp();
3297c478bd9Sstevel@tonic-gate 		putarg(0, CPP);
3307c478bd9Sstevel@tonic-gate 		putarg(1, CPPFLAGS);
3317c478bd9Sstevel@tonic-gate 		addarg(define);
3327c478bd9Sstevel@tonic-gate 		if (infile)
3337c478bd9Sstevel@tonic-gate 			addarg(infile);
3347c478bd9Sstevel@tonic-gate 		addarg((char *)NULL);
3357c478bd9Sstevel@tonic-gate 		(void) close(1);
3367c478bd9Sstevel@tonic-gate 		(void) dup2(pd[1], 1);
3377c478bd9Sstevel@tonic-gate 		(void) close(pd[0]);
338*61961e0fSrobinson 		(void) execv(arglist[0], arglist);
3397c478bd9Sstevel@tonic-gate 		perror("execv");
3407c478bd9Sstevel@tonic-gate 		exit(1);
341*61961e0fSrobinson 		/* NOTREACHED */
3427c478bd9Sstevel@tonic-gate 	case -1:
3437c478bd9Sstevel@tonic-gate 		perror("fork");
3447c478bd9Sstevel@tonic-gate 		exit(1);
3457c478bd9Sstevel@tonic-gate 	}
3467c478bd9Sstevel@tonic-gate 	(void) close(pd[1]);
3477c478bd9Sstevel@tonic-gate 	fin = fdopen(pd[0], "r");
3487c478bd9Sstevel@tonic-gate 	if (fin == NULL) {
3497c478bd9Sstevel@tonic-gate 		f_print(stderr, "%s: ", cmdname);
3507c478bd9Sstevel@tonic-gate 		perror(infilename);
3517c478bd9Sstevel@tonic-gate 		crash();
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate }
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate /* valid tirpc nettypes */
356*61961e0fSrobinson static char *valid_ti_nettypes[] = {
3577c478bd9Sstevel@tonic-gate 	"netpath",
3587c478bd9Sstevel@tonic-gate 	"visible",
3597c478bd9Sstevel@tonic-gate 	"circuit_v",
3607c478bd9Sstevel@tonic-gate 	"datagram_v",
3617c478bd9Sstevel@tonic-gate 	"circuit_n",
3627c478bd9Sstevel@tonic-gate 	"datagram_n",
3637c478bd9Sstevel@tonic-gate 	"udp",
3647c478bd9Sstevel@tonic-gate 	"tcp",
3657c478bd9Sstevel@tonic-gate 	"raw",
3667c478bd9Sstevel@tonic-gate 	NULL
367*61961e0fSrobinson };
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /* valid inetd nettypes */
370*61961e0fSrobinson static char *valid_i_nettypes[] = {
3717c478bd9Sstevel@tonic-gate 	"udp",
3727c478bd9Sstevel@tonic-gate 	"tcp",
3737c478bd9Sstevel@tonic-gate 	NULL
374*61961e0fSrobinson };
3757c478bd9Sstevel@tonic-gate 
376*61961e0fSrobinson static int
377*61961e0fSrobinson check_nettype(char *name, char *list_to_check[])
3787c478bd9Sstevel@tonic-gate {
3797c478bd9Sstevel@tonic-gate 	int i;
3807c478bd9Sstevel@tonic-gate 	for (i = 0; list_to_check[i] != NULL; i++) {
3817c478bd9Sstevel@tonic-gate 		if (strcmp(name, list_to_check[i]) == 0) {
3827c478bd9Sstevel@tonic-gate 			return (1);
3837c478bd9Sstevel@tonic-gate 		}
3847c478bd9Sstevel@tonic-gate 	}
3857c478bd9Sstevel@tonic-gate 	f_print(stderr, "illegal nettype :\'%s\'\n", name);
3867c478bd9Sstevel@tonic-gate 	return (0);
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate static char *
390*61961e0fSrobinson file_name(char *file, char *ext)
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate 	char *temp;
3937c478bd9Sstevel@tonic-gate 	temp = extendfile(file, ext);
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	if (access(temp, F_OK) != -1)
3967c478bd9Sstevel@tonic-gate 		return (temp);
3977c478bd9Sstevel@tonic-gate 	else
3987c478bd9Sstevel@tonic-gate 		return ((char *)" ");
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 
402*61961e0fSrobinson static void
403*61961e0fSrobinson c_output(char *infile, char *define, int extend, char *outfile)
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate 	definition *def;
4067c478bd9Sstevel@tonic-gate 	char *include;
4077c478bd9Sstevel@tonic-gate 	char *outfilename;
4087c478bd9Sstevel@tonic-gate 	long tell;
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	c_initialize();
4117c478bd9Sstevel@tonic-gate 	open_input(infile, define);
4127c478bd9Sstevel@tonic-gate 	outfilename = extend ? extendfile(infile, outfile) : outfile;
4137c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
4147c478bd9Sstevel@tonic-gate 	add_warning();
4157c478bd9Sstevel@tonic-gate 	if (infile && (include = extendfile(infile, ".h"))) {
4167c478bd9Sstevel@tonic-gate 		f_print(fout, "#include \"%s\"\n", include);
4177c478bd9Sstevel@tonic-gate 		free(include);
4187c478bd9Sstevel@tonic-gate 		/* .h file already contains rpc/rpc.h */
4197c478bd9Sstevel@tonic-gate 	} else
4207c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <rpc/rpc.h>\n");
4217c478bd9Sstevel@tonic-gate 	/*
422*61961e0fSrobinson 	 * Include stdlib.h to support mem_alloc calls.
4237c478bd9Sstevel@tonic-gate 	 */
4247c478bd9Sstevel@tonic-gate 	f_print(fout, "\n#ifndef _KERNEL\n");
425*61961e0fSrobinson 	f_print(fout, "#include <stdlib.h>\n");
4267c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif /* !_KERNEL */\n\n");
4277c478bd9Sstevel@tonic-gate 	tell = ftell(fout);
4287c478bd9Sstevel@tonic-gate 	while (def = get_definition()) {
4297c478bd9Sstevel@tonic-gate 		emit(def);
4307c478bd9Sstevel@tonic-gate 	}
4317c478bd9Sstevel@tonic-gate 	if (extend && tell == ftell(fout)) {
4327c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
4337c478bd9Sstevel@tonic-gate 	}
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate 
437*61961e0fSrobinson static void
438*61961e0fSrobinson c_initialize(void)
4397c478bd9Sstevel@tonic-gate {
4407c478bd9Sstevel@tonic-gate 	/*
4417c478bd9Sstevel@tonic-gate 	 * add all the starting basic types.
4427c478bd9Sstevel@tonic-gate 	 * We may need to add some derived types
4437c478bd9Sstevel@tonic-gate 	 * if we need to generate INLINE macros.
4447c478bd9Sstevel@tonic-gate 	 * These types are defined in rpc/types.h
4457c478bd9Sstevel@tonic-gate 	 */
4467c478bd9Sstevel@tonic-gate 	add_type(1, "int");
4477c478bd9Sstevel@tonic-gate 	add_type(1, "long");
4487c478bd9Sstevel@tonic-gate 	add_type(1, "short");
4497c478bd9Sstevel@tonic-gate 	add_type(1, "bool");
4507c478bd9Sstevel@tonic-gate 	add_type(1, "u_int");
4517c478bd9Sstevel@tonic-gate 	add_type(1, "u_long");
4527c478bd9Sstevel@tonic-gate 	add_type(1, "u_short");
4537c478bd9Sstevel@tonic-gate 	add_type(1, "rpcprog_t");
4547c478bd9Sstevel@tonic-gate 	add_type(1, "rpcvers_t");
4557c478bd9Sstevel@tonic-gate 	add_type(1, "rpcproc_t");
4567c478bd9Sstevel@tonic-gate 	add_type(1, "rpcprot_t");
4577c478bd9Sstevel@tonic-gate 	add_type(1, "rpcport_t");
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate char rpcgen_table_dcl1[] = "struct rpcgen_table {\n";
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate char rpcgen_table_dcl2[] = "\txdrproc_t\txdr_arg;\n"
4637c478bd9Sstevel@tonic-gate 				"\tunsigned\tlen_arg;\n"
4647c478bd9Sstevel@tonic-gate 				"\txdrproc_t\txdr_res;\n"
4657c478bd9Sstevel@tonic-gate 				"\tunsigned\tlen_res;\n"
4667c478bd9Sstevel@tonic-gate 				"};\n";
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate char rpcgen_table_proc[] = "\tvoid\t*(*proc)();\n";
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate char rpcgen_table_proc_b[] = "\tchar\t*(*proc)();\n";
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate char *
474*61961e0fSrobinson generate_guard(char *pathname)
4757c478bd9Sstevel@tonic-gate {
4767c478bd9Sstevel@tonic-gate 	char *filename, *guard, *tmp;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 	filename = strrchr(pathname, '/');  /* find last component */
4797c478bd9Sstevel@tonic-gate 	filename = ((filename == 0) ? pathname : filename+1);
4807c478bd9Sstevel@tonic-gate 	guard = extendfile(filename, "_H_RPCGEN");
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	/*
4837c478bd9Sstevel@tonic-gate 	 * Guard must be an ANSI C identifier composed of
4847c478bd9Sstevel@tonic-gate 	 * upper case letters, digits, or '_'.
4857c478bd9Sstevel@tonic-gate 	 * Convert invalid characters to '_'.
4867c478bd9Sstevel@tonic-gate 	 */
4877c478bd9Sstevel@tonic-gate 	for (tmp = guard; *tmp; tmp++) {
4887c478bd9Sstevel@tonic-gate 		if (!isalpha(*tmp) && !isdigit(*tmp)) {
4897c478bd9Sstevel@tonic-gate 			*tmp = '_';
4907c478bd9Sstevel@tonic-gate 			continue;
4917c478bd9Sstevel@tonic-gate 		}
4927c478bd9Sstevel@tonic-gate 		if (islower(*tmp))
4937c478bd9Sstevel@tonic-gate 			*tmp = toupper(*tmp);
4947c478bd9Sstevel@tonic-gate 	}
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 	/*
4977c478bd9Sstevel@tonic-gate 	 * The first character must be a letter; the underscore '_'
4987c478bd9Sstevel@tonic-gate 	 * counts as a letter.
4997c478bd9Sstevel@tonic-gate 	 */
5007c478bd9Sstevel@tonic-gate 	if (!isalpha(guard[0]))
5017c478bd9Sstevel@tonic-gate 		guard[0] = '_';
5027c478bd9Sstevel@tonic-gate 
5037c478bd9Sstevel@tonic-gate 	return (guard);
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate 
5067c478bd9Sstevel@tonic-gate /*
5077c478bd9Sstevel@tonic-gate  * Compile into an XDR header file
5087c478bd9Sstevel@tonic-gate  */
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 
511*61961e0fSrobinson static void
512*61961e0fSrobinson h_output(char *infile, char *define, int extend, char *outfile)
5137c478bd9Sstevel@tonic-gate {
5147c478bd9Sstevel@tonic-gate 	definition *def;
5157c478bd9Sstevel@tonic-gate 	char *outfilename;
5167c478bd9Sstevel@tonic-gate 	long tell;
5177c478bd9Sstevel@tonic-gate 	char *guard;
5187c478bd9Sstevel@tonic-gate 	list *l;
5197c478bd9Sstevel@tonic-gate 	xdrfunc *xdrfuncp;
5207c478bd9Sstevel@tonic-gate 	int i;
5217c478bd9Sstevel@tonic-gate 
5227c478bd9Sstevel@tonic-gate 	open_input(infile, define);
5237c478bd9Sstevel@tonic-gate 	outfilename =  extend ? extendfile(infile, outfile) : outfile;
5247c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
5257c478bd9Sstevel@tonic-gate 	add_warning();
526*61961e0fSrobinson 	if (outfilename || infile)
5277c478bd9Sstevel@tonic-gate 		guard = generate_guard(outfilename ? outfilename: infile);
528*61961e0fSrobinson 	else
5297c478bd9Sstevel@tonic-gate 		guard = "STDIN_";
5307c478bd9Sstevel@tonic-gate 
531*61961e0fSrobinson 	f_print(fout, "#ifndef _%s\n#define	_%s\n\n", guard, guard);
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <rpc/rpc.h>\n");
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	if (mtflag) {
5367c478bd9Sstevel@tonic-gate 		f_print(fout, "#ifndef _KERNEL\n");
5377c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <synch.h>\n");
5387c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <thread.h>\n");
5397c478bd9Sstevel@tonic-gate 		f_print(fout, "#endif /* !_KERNEL */\n");
5407c478bd9Sstevel@tonic-gate 	};
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 	/* put the C++ support */
5437c478bd9Sstevel@tonic-gate 	if (Cflag && !CCflag) {
5447c478bd9Sstevel@tonic-gate 		f_print(fout, "\n#ifdef __cplusplus\n");
5457c478bd9Sstevel@tonic-gate 		f_print(fout, "extern \"C\" {\n");
5467c478bd9Sstevel@tonic-gate 		f_print(fout, "#endif\n\n");
5477c478bd9Sstevel@tonic-gate 	}
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	/* put in a typedef for quadprecision. Only with Cflag */
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate 	tell = ftell(fout);
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 	/* print data definitions */
554*61961e0fSrobinson 	while (def = get_definition())
5557c478bd9Sstevel@tonic-gate 		print_datadef(def);
5567c478bd9Sstevel@tonic-gate 
5577c478bd9Sstevel@tonic-gate 	/*
5587c478bd9Sstevel@tonic-gate 	 * print function declarations.
5597c478bd9Sstevel@tonic-gate 	 *  Do this after data definitions because they might be used as
5607c478bd9Sstevel@tonic-gate 	 *  arguments for functions
5617c478bd9Sstevel@tonic-gate 	 */
562*61961e0fSrobinson 	for (l = defined; l != NULL; l = l->next)
5637c478bd9Sstevel@tonic-gate 		print_funcdef(l->val);
5647c478bd9Sstevel@tonic-gate 	/* Now  print all xdr func declarations */
5657c478bd9Sstevel@tonic-gate 	if (xdrfunc_head != NULL) {
566*61961e0fSrobinson 		f_print(fout, "\n/* the xdr functions */\n");
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 		if (CCflag) {
569*61961e0fSrobinson 			f_print(fout, "\n#ifdef __cplusplus\n");
570*61961e0fSrobinson 			f_print(fout, "extern \"C\" {\n");
571*61961e0fSrobinson 			f_print(fout, "#endif\n");
572*61961e0fSrobinson 		}
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate 		if (!Cflag) {
5757c478bd9Sstevel@tonic-gate 			xdrfuncp = xdrfunc_head;
5767c478bd9Sstevel@tonic-gate 			while (xdrfuncp != NULL) {
5777c478bd9Sstevel@tonic-gate 				print_xdr_func_def(xdrfuncp->name,
578*61961e0fSrobinson 							xdrfuncp->pointerp, 2);
5797c478bd9Sstevel@tonic-gate 				xdrfuncp = xdrfuncp->next;
5807c478bd9Sstevel@tonic-gate 			}
5817c478bd9Sstevel@tonic-gate 		} else {
5827c478bd9Sstevel@tonic-gate 			for (i = 1; i < 3; i++) {
5837c478bd9Sstevel@tonic-gate 				if (i == 1)
584*61961e0fSrobinson 					f_print(fout,
585*61961e0fSrobinson "\n#if defined(__STDC__) || defined(__cplusplus)\n");
5867c478bd9Sstevel@tonic-gate 				else
5877c478bd9Sstevel@tonic-gate 					f_print(fout, "\n#else /* K&R C */\n");
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 				xdrfuncp = xdrfunc_head;
5907c478bd9Sstevel@tonic-gate 				while (xdrfuncp != NULL) {
5917c478bd9Sstevel@tonic-gate 					print_xdr_func_def(xdrfuncp->name,
592*61961e0fSrobinson 							xdrfuncp->pointerp, i);
5937c478bd9Sstevel@tonic-gate 					xdrfuncp = xdrfuncp->next;
5947c478bd9Sstevel@tonic-gate 				}
5957c478bd9Sstevel@tonic-gate 			}
596*61961e0fSrobinson 			f_print(fout, "\n#endif /* K&R C */\n");
5977c478bd9Sstevel@tonic-gate 		}
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate 	if (extend && tell == ftell(fout)) {
6017c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
6027c478bd9Sstevel@tonic-gate 	} else if (tblflag) {
6037c478bd9Sstevel@tonic-gate 		f_print(fout, rpcgen_table_dcl1);
6047c478bd9Sstevel@tonic-gate 		if (tirpcflag)
6057c478bd9Sstevel@tonic-gate 			f_print(fout, rpcgen_table_proc);
6067c478bd9Sstevel@tonic-gate 		else
6077c478bd9Sstevel@tonic-gate 			f_print(fout, rpcgen_table_proc_b);
6087c478bd9Sstevel@tonic-gate 		f_print(fout, rpcgen_table_dcl2);
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	if (Cflag) {
6127c478bd9Sstevel@tonic-gate 		f_print(fout, "\n#ifdef __cplusplus\n");
6137c478bd9Sstevel@tonic-gate 		f_print(fout, "}\n");
6147c478bd9Sstevel@tonic-gate 		f_print(fout, "#endif\n");
6157c478bd9Sstevel@tonic-gate 	}
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 	f_print(fout, "\n#endif /* !_%s */\n", guard);
6187c478bd9Sstevel@tonic-gate }
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate /*
6217c478bd9Sstevel@tonic-gate  * Compile into an RPC service
6227c478bd9Sstevel@tonic-gate  */
623*61961e0fSrobinson static void
624*61961e0fSrobinson s_output(int argc, char *argv[], char *infile, char *define, int extend,
625*61961e0fSrobinson 					char *outfile, int nomain, int netflag)
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate 	char *include;
6287c478bd9Sstevel@tonic-gate 	definition *def;
6297c478bd9Sstevel@tonic-gate 	int foundprogram = 0;
6307c478bd9Sstevel@tonic-gate 	char *outfilename;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate 	open_input(infile, define);
6337c478bd9Sstevel@tonic-gate 	outfilename = extend ? extendfile(infile, outfile) : outfile;
6347c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
6357c478bd9Sstevel@tonic-gate 	add_warning();
6367c478bd9Sstevel@tonic-gate 	if (infile && (include = extendfile(infile, ".h"))) {
6377c478bd9Sstevel@tonic-gate 		f_print(fout, "#include \"%s\"\n", include);
6387c478bd9Sstevel@tonic-gate 		free(include);
6397c478bd9Sstevel@tonic-gate 	} else
6407c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <rpc/rpc.h>\n");
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdio.h>\n");
6437c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
6447c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <signal.h>\n");
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate 	if (Cflag) {
6477c478bd9Sstevel@tonic-gate 		f_print(fout,
6487c478bd9Sstevel@tonic-gate 		"#include <rpc/pmap_clnt.h> /* for pmap_unset */\n");
6497c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <string.h> /* strcmp */\n");
6507c478bd9Sstevel@tonic-gate 	}
6517c478bd9Sstevel@tonic-gate 	if (strcmp(svcclosetime, "-1") == 0)
6527c478bd9Sstevel@tonic-gate 		indefinitewait = 1;
6537c478bd9Sstevel@tonic-gate 	else if (strcmp(svcclosetime, "0") == 0)
6547c478bd9Sstevel@tonic-gate 		exitnow = 1;
655*61961e0fSrobinson 	else if (inetdflag || pmflag)
6567c478bd9Sstevel@tonic-gate 		timerflag = 1;
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	if (!tirpcflag && inetdflag)
6597c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <sys/termios.h> /* TIOCNOTTY */\n");
660*61961e0fSrobinson 	if (Cflag && (inetdflag || pmflag))
6617c478bd9Sstevel@tonic-gate 		if (tirpcflag)
6627c478bd9Sstevel@tonic-gate 			f_print(fout, "#include <unistd.h> /* setsid */\n");
6637c478bd9Sstevel@tonic-gate 	if (tirpcflag)
6647c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <sys/types.h>\n");
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <memory.h>\n");
6677c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stropts.h>\n");
6687c478bd9Sstevel@tonic-gate 	if (inetdflag || !tirpcflag) {
6697c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <sys/socket.h>\n");
6707c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <netinet/in.h>\n");
6717c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <rpc/svc_soc.h>\n");
6727c478bd9Sstevel@tonic-gate 	}
6737c478bd9Sstevel@tonic-gate 
674*61961e0fSrobinson 	if ((netflag || pmflag) && tirpcflag && !nomain)
6757c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <netconfig.h>\n");
6767c478bd9Sstevel@tonic-gate 	if (tirpcflag)
6777c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <sys/resource.h> /* rlimit */\n");
6787c478bd9Sstevel@tonic-gate 	if (logflag || inetdflag || pmflag)
6797c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <syslog.h>\n");
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	/* for ANSI-C */
6827c478bd9Sstevel@tonic-gate 	if (Cflag)
6837c478bd9Sstevel@tonic-gate 		f_print(fout,
6847c478bd9Sstevel@tonic-gate 			"\n#ifndef SIG_PF\n#define	SIG_PF void(*)\
6857c478bd9Sstevel@tonic-gate (int)\n#endif\n");
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 	f_print(fout, "\n#ifdef DEBUG\n#define	RPC_SVC_FG\n#endif\n");
6887c478bd9Sstevel@tonic-gate 	if (timerflag)
6897c478bd9Sstevel@tonic-gate 		f_print(fout, "\n#define	_RPCSVC_CLOSEDOWN %s\n",
6907c478bd9Sstevel@tonic-gate 			svcclosetime);
691*61961e0fSrobinson 	while (def = get_definition())
6927c478bd9Sstevel@tonic-gate 		foundprogram |= (def->def_kind == DEF_PROGRAM);
6937c478bd9Sstevel@tonic-gate 	if (extend && !foundprogram) {
6947c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
6957c478bd9Sstevel@tonic-gate 		return;
6967c478bd9Sstevel@tonic-gate 	}
6977c478bd9Sstevel@tonic-gate 	write_most(infile, netflag, nomain);
6987c478bd9Sstevel@tonic-gate 	if (!nomain) {
6997c478bd9Sstevel@tonic-gate 		if (!do_registers(argc, argv)) {
7007c478bd9Sstevel@tonic-gate 			if (outfilename)
7017c478bd9Sstevel@tonic-gate 				(void) unlink(outfilename);
7027c478bd9Sstevel@tonic-gate 			usage();
7037c478bd9Sstevel@tonic-gate 		}
7047c478bd9Sstevel@tonic-gate 		write_rest();
7057c478bd9Sstevel@tonic-gate 	}
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate /*
7097c478bd9Sstevel@tonic-gate  * generate client side stubs
7107c478bd9Sstevel@tonic-gate  */
711*61961e0fSrobinson static void
712*61961e0fSrobinson l_output(char *infile, char *define, int extend, char *outfile)
7137c478bd9Sstevel@tonic-gate {
7147c478bd9Sstevel@tonic-gate 	char *include;
7157c478bd9Sstevel@tonic-gate 	definition *def;
7167c478bd9Sstevel@tonic-gate 	int foundprogram = 0;
7177c478bd9Sstevel@tonic-gate 	char *outfilename;
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate 	open_input(infile, define);
7207c478bd9Sstevel@tonic-gate 	outfilename = extend ? extendfile(infile, outfile) : outfile;
7217c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
7227c478bd9Sstevel@tonic-gate 	add_warning();
7237c478bd9Sstevel@tonic-gate 	if (Cflag)
7247c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <memory.h> /* for memset */\n");
7257c478bd9Sstevel@tonic-gate 	if (infile && (include = extendfile(infile, ".h"))) {
7267c478bd9Sstevel@tonic-gate 		f_print(fout, "#include \"%s\"\n", include);
7277c478bd9Sstevel@tonic-gate 		free(include);
7287c478bd9Sstevel@tonic-gate 	} else
7297c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <rpc/rpc.h>\n");
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 	f_print(fout, "#ifndef _KERNEL\n");
7327c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdio.h>\n");
7337c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
7347c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif /* !_KERNEL */\n");
7357c478bd9Sstevel@tonic-gate 
736*61961e0fSrobinson 	while (def = get_definition())
7377c478bd9Sstevel@tonic-gate 		foundprogram |= (def->def_kind == DEF_PROGRAM);
7387c478bd9Sstevel@tonic-gate 	if (extend && !foundprogram) {
7397c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
7407c478bd9Sstevel@tonic-gate 		return;
7417c478bd9Sstevel@tonic-gate 	}
7427c478bd9Sstevel@tonic-gate 	write_stubs();
7437c478bd9Sstevel@tonic-gate }
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate /*
7467c478bd9Sstevel@tonic-gate  * generate the dispatch table
7477c478bd9Sstevel@tonic-gate  */
748*61961e0fSrobinson static void
749*61961e0fSrobinson t_output(char *infile, char *define, int extend, char *outfile)
7507c478bd9Sstevel@tonic-gate {
7517c478bd9Sstevel@tonic-gate 	definition *def;
7527c478bd9Sstevel@tonic-gate 	int foundprogram = 0;
7537c478bd9Sstevel@tonic-gate 	char *outfilename;
7547c478bd9Sstevel@tonic-gate 
7557c478bd9Sstevel@tonic-gate 	open_input(infile, define);
7567c478bd9Sstevel@tonic-gate 	outfilename = extend ? extendfile(infile, outfile) : outfile;
7577c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
7587c478bd9Sstevel@tonic-gate 	add_warning();
7597c478bd9Sstevel@tonic-gate 	while (def = get_definition()) {
7607c478bd9Sstevel@tonic-gate 		foundprogram |= (def->def_kind == DEF_PROGRAM);
7617c478bd9Sstevel@tonic-gate 	}
7627c478bd9Sstevel@tonic-gate 	if (extend && !foundprogram) {
7637c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
7647c478bd9Sstevel@tonic-gate 		return;
7657c478bd9Sstevel@tonic-gate 	}
7667c478bd9Sstevel@tonic-gate 	write_tables();
7677c478bd9Sstevel@tonic-gate }
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate /* sample routine for the server template */
770*61961e0fSrobinson static void
771*61961e0fSrobinson svc_output(char *infile, char *define, int extend, char *outfile)
7727c478bd9Sstevel@tonic-gate {
7737c478bd9Sstevel@tonic-gate 	definition *def;
7747c478bd9Sstevel@tonic-gate 	char *include;
7757c478bd9Sstevel@tonic-gate 	char *outfilename;
7767c478bd9Sstevel@tonic-gate 	long tell;
7777c478bd9Sstevel@tonic-gate 	open_input(infile, define);
7787c478bd9Sstevel@tonic-gate 	outfilename = extend ? extendfile(infile, outfile) : outfile;
7797c478bd9Sstevel@tonic-gate 	checkfiles(infile, outfilename);
7807c478bd9Sstevel@tonic-gate 	/*
7817c478bd9Sstevel@tonic-gate 	 * Check if outfile already exists.
7827c478bd9Sstevel@tonic-gate 	 * if so, print an error message and exit
7837c478bd9Sstevel@tonic-gate 	 */
7847c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
7857c478bd9Sstevel@tonic-gate 	add_sample_msg();
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate 	if (infile && (include = extendfile(infile, ".h"))) {
7887c478bd9Sstevel@tonic-gate 		f_print(fout, "#include \"%s\"\n", include);
7897c478bd9Sstevel@tonic-gate 		free(include);
7907c478bd9Sstevel@tonic-gate 	} else {
7917c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <rpc/rpc.h>\n");
7927c478bd9Sstevel@tonic-gate 	}
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdio.h>\n");
7957c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
7967c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <signal.h>\n");
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	tell = ftell(fout);
799*61961e0fSrobinson 	while (def = get_definition())
8007c478bd9Sstevel@tonic-gate 		write_sample_svc(def);
801*61961e0fSrobinson 	if (extend && tell == ftell(fout))
8027c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
8037c478bd9Sstevel@tonic-gate }
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate /* sample main routine for client */
806*61961e0fSrobinson static void
807*61961e0fSrobinson clnt_output(char *infile, char *define, int extend, char *outfile)
8087c478bd9Sstevel@tonic-gate {
8097c478bd9Sstevel@tonic-gate 	definition *def;
8107c478bd9Sstevel@tonic-gate 	char *include;
8117c478bd9Sstevel@tonic-gate 	char *outfilename;
8127c478bd9Sstevel@tonic-gate 	long tell;
8137c478bd9Sstevel@tonic-gate 	int has_program = 0;
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 	open_input(infile, define);
8167c478bd9Sstevel@tonic-gate 	outfilename = extend ? extendfile(infile, outfile) : outfile;
8177c478bd9Sstevel@tonic-gate 	checkfiles(infile, outfilename);
8187c478bd9Sstevel@tonic-gate 	/*
8197c478bd9Sstevel@tonic-gate 	 * Check if outfile already exists.
8207c478bd9Sstevel@tonic-gate 	 * if so, print an error message and exit
8217c478bd9Sstevel@tonic-gate 	 */
8227c478bd9Sstevel@tonic-gate 
8237c478bd9Sstevel@tonic-gate 	open_output(infile, outfilename);
8247c478bd9Sstevel@tonic-gate 	add_sample_msg();
8257c478bd9Sstevel@tonic-gate 	if (infile && (include = extendfile(infile, ".h"))) {
8267c478bd9Sstevel@tonic-gate 		f_print(fout, "#include \"%s\"\n", include);
8277c478bd9Sstevel@tonic-gate 		free(include);
8287c478bd9Sstevel@tonic-gate 	} else
8297c478bd9Sstevel@tonic-gate 		f_print(fout, "#include <rpc/rpc.h>\n");
8307c478bd9Sstevel@tonic-gate 
8317c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdio.h>\n");
8327c478bd9Sstevel@tonic-gate 	f_print(fout, "#include <stdlib.h> /* getenv, exit */\n");
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 	tell = ftell(fout);
835*61961e0fSrobinson 	while (def = get_definition())
8367c478bd9Sstevel@tonic-gate 		has_program += write_sample_clnt(def);
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate 	if (has_program)
8397c478bd9Sstevel@tonic-gate 		write_sample_clnt_main();
8407c478bd9Sstevel@tonic-gate 
841*61961e0fSrobinson 	if (extend && tell == ftell(fout))
8427c478bd9Sstevel@tonic-gate 		(void) unlink(outfilename);
8437c478bd9Sstevel@tonic-gate }
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 
846*61961e0fSrobinson static void
847*61961e0fSrobinson mkfile_output(struct commandline *cmd)
8487c478bd9Sstevel@tonic-gate {
8497c478bd9Sstevel@tonic-gate 	char *mkfilename, *clientname, *clntname, *xdrname, *hdrname;
8507c478bd9Sstevel@tonic-gate 	char *servername, *svcname, *servprogname, *clntprogname;
8517c478bd9Sstevel@tonic-gate 	char *temp;
8527c478bd9Sstevel@tonic-gate 
8537c478bd9Sstevel@tonic-gate 	svcname = file_name(cmd->infile, "_svc.c");
8547c478bd9Sstevel@tonic-gate 	clntname = file_name(cmd->infile, "_clnt.c");
8557c478bd9Sstevel@tonic-gate 	xdrname = file_name(cmd->infile, "_xdr.c");
8567c478bd9Sstevel@tonic-gate 	hdrname = file_name(cmd->infile, ".h");
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	if (allfiles) {
8607c478bd9Sstevel@tonic-gate 		servername = extendfile(cmd->infile, "_server.c");
8617c478bd9Sstevel@tonic-gate 		clientname = extendfile(cmd->infile, "_client.c");
8627c478bd9Sstevel@tonic-gate 	} else {
8637c478bd9Sstevel@tonic-gate 		servername = " ";
8647c478bd9Sstevel@tonic-gate 		clientname = " ";
8657c478bd9Sstevel@tonic-gate 	}
8667c478bd9Sstevel@tonic-gate 	servprogname = extendfile(cmd->infile, "_server");
8677c478bd9Sstevel@tonic-gate 	clntprogname = extendfile(cmd->infile, "_client");
8687c478bd9Sstevel@tonic-gate 
8697c478bd9Sstevel@tonic-gate 	if (allfiles) {
870*61961e0fSrobinson 		mkfilename = malloc(strlen("makefile.") +
8717c478bd9Sstevel@tonic-gate 			strlen(cmd->infile) + 1);
8727c478bd9Sstevel@tonic-gate 		if (mkfilename == NULL) {
8737c478bd9Sstevel@tonic-gate 			f_print(stderr, "Out of memory!\n");
8747c478bd9Sstevel@tonic-gate 			return;
8757c478bd9Sstevel@tonic-gate 		}
8767c478bd9Sstevel@tonic-gate 		temp = (char *)rindex(cmd->infile, '.');
877*61961e0fSrobinson 		(void) strcpy(mkfilename, "makefile.");
8787c478bd9Sstevel@tonic-gate 		(void) strncat(mkfilename, cmd->infile,
8797c478bd9Sstevel@tonic-gate 			(temp - cmd->infile));
8807c478bd9Sstevel@tonic-gate 	} else
8817c478bd9Sstevel@tonic-gate 		mkfilename = cmd->outfile;
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 
8847c478bd9Sstevel@tonic-gate 	checkfiles(NULL, mkfilename);
8857c478bd9Sstevel@tonic-gate 	open_output(NULL, mkfilename);
8867c478bd9Sstevel@tonic-gate 
8877c478bd9Sstevel@tonic-gate 	f_print(fout, "\n# This is a template makefile generated\
8887c478bd9Sstevel@tonic-gate 		by rpcgen \n");
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate 	f_print(fout, "\n# Parameters \n\n");
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	f_print(fout, "CLIENT = %s\nSERVER = %s\n\n",
8937c478bd9Sstevel@tonic-gate 		clntprogname, servprogname);
8947c478bd9Sstevel@tonic-gate 	f_print(fout, "SOURCES_CLNT.c = \nSOURCES_CLNT.h = \n");
8957c478bd9Sstevel@tonic-gate 	f_print(fout, "SOURCES_SVC.c = \nSOURCES_SVC.h = \n");
8967c478bd9Sstevel@tonic-gate 	f_print(fout, "SOURCES.x = %s\n\n", cmd->infile);
8977c478bd9Sstevel@tonic-gate 	f_print(fout, "TARGETS_SVC.c = %s %s %s \n",
8987c478bd9Sstevel@tonic-gate 		svcname, servername, xdrname);
8997c478bd9Sstevel@tonic-gate 	f_print(fout, "TARGETS_CLNT.c = %s %s %s \n",
9007c478bd9Sstevel@tonic-gate 		clntname, clientname, xdrname);
9017c478bd9Sstevel@tonic-gate 	f_print(fout, "TARGETS = %s %s %s %s %s %s\n\n",
9027c478bd9Sstevel@tonic-gate 		hdrname, xdrname, clntname,
9037c478bd9Sstevel@tonic-gate 		svcname, clientname, servername);
9047c478bd9Sstevel@tonic-gate 
9057c478bd9Sstevel@tonic-gate 	f_print(fout, "OBJECTS_CLNT = $(SOURCES_CLNT.c:%%.c=%%.o) "
9067c478bd9Sstevel@tonic-gate 			"$(TARGETS_CLNT.c:%%.c=%%.o) ");
9077c478bd9Sstevel@tonic-gate 
9087c478bd9Sstevel@tonic-gate 	f_print(fout, "\nOBJECTS_SVC = $(SOURCES_SVC.c:%%.c=%%.o) "
9097c478bd9Sstevel@tonic-gate 			"$(TARGETS_SVC.c:%%.c=%%.o) ");
9107c478bd9Sstevel@tonic-gate 
9117c478bd9Sstevel@tonic-gate 
9127c478bd9Sstevel@tonic-gate 	f_print(fout, "\n# Compiler flags \n");
9137c478bd9Sstevel@tonic-gate 	if (mtflag)
9147c478bd9Sstevel@tonic-gate 		f_print(fout, "\nCPPFLAGS += -D_REENTRANT\n"
9157c478bd9Sstevel@tonic-gate 			"CFLAGS += -g\nLDLIBS += -lnsl\n");
9167c478bd9Sstevel@tonic-gate 	else
9177c478bd9Sstevel@tonic-gate 		f_print(fout, "\nCFLAGS += -g \nLDLIBS += -lnsl\n");
9187c478bd9Sstevel@tonic-gate 	f_print(fout, "RPCGENFLAGS = \n");
9197c478bd9Sstevel@tonic-gate 
9207c478bd9Sstevel@tonic-gate 	f_print(fout, "\n# Targets \n\n");
9217c478bd9Sstevel@tonic-gate 
9227c478bd9Sstevel@tonic-gate 	f_print(fout, "all : $(CLIENT) $(SERVER)\n\n");
9237c478bd9Sstevel@tonic-gate 	f_print(fout, "$(TARGETS) : $(SOURCES.x) \n");
9247c478bd9Sstevel@tonic-gate 	f_print(fout, "\trpcgen $(RPCGENFLAGS) $(SOURCES.x)\n\n");
9257c478bd9Sstevel@tonic-gate 	f_print(fout, "$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) \
9267c478bd9Sstevel@tonic-gate $(TARGETS_CLNT.c) \n\n");
9277c478bd9Sstevel@tonic-gate 
9287c478bd9Sstevel@tonic-gate 	f_print(fout, "$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) \
9297c478bd9Sstevel@tonic-gate $(TARGETS_SVC.c) \n\n");
9307c478bd9Sstevel@tonic-gate 	f_print(fout, "$(CLIENT) : $(OBJECTS_CLNT) \n");
9317c478bd9Sstevel@tonic-gate 	f_print(fout, "\t$(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) \
9327c478bd9Sstevel@tonic-gate $(LDLIBS) \n\n");
9337c478bd9Sstevel@tonic-gate 	f_print(fout, "$(SERVER) : $(OBJECTS_SVC) \n");
9347c478bd9Sstevel@tonic-gate 	f_print(fout, "\t$(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)\n\n ");
9357c478bd9Sstevel@tonic-gate 	f_print(fout, "clean:\n\t $(RM) core $(TARGETS) $(OBJECTS_CLNT) \
9367c478bd9Sstevel@tonic-gate $(OBJECTS_SVC) $(CLIENT) $(SERVER)\n\n");
9377c478bd9Sstevel@tonic-gate }
9387c478bd9Sstevel@tonic-gate 
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate /*
9417c478bd9Sstevel@tonic-gate  * Perform registrations for service output
9427c478bd9Sstevel@tonic-gate  * Return 0 if failed; 1 otherwise.
9437c478bd9Sstevel@tonic-gate  */
9447c478bd9Sstevel@tonic-gate static int
945*61961e0fSrobinson do_registers(int argc, char *argv[])
9467c478bd9Sstevel@tonic-gate {
9477c478bd9Sstevel@tonic-gate 	int i;
9487c478bd9Sstevel@tonic-gate 
9497c478bd9Sstevel@tonic-gate 	if (inetdflag || !tirpcflag) {
9507c478bd9Sstevel@tonic-gate 		for (i = 1; i < argc; i++) {
9517c478bd9Sstevel@tonic-gate 			if (streq(argv[i], "-s")) {
9527c478bd9Sstevel@tonic-gate 				if (!check_nettype(argv[i + 1],
9537c478bd9Sstevel@tonic-gate 						    valid_i_nettypes))
9547c478bd9Sstevel@tonic-gate 					return (0);
9557c478bd9Sstevel@tonic-gate 				write_inetd_register(argv[i + 1]);
9567c478bd9Sstevel@tonic-gate 				i++;
9577c478bd9Sstevel@tonic-gate 			}
9587c478bd9Sstevel@tonic-gate 		}
9597c478bd9Sstevel@tonic-gate 	} else {
9607c478bd9Sstevel@tonic-gate 		for (i = 1; i < argc; i++)
9617c478bd9Sstevel@tonic-gate 			if (streq(argv[i], "-s")) {
9627c478bd9Sstevel@tonic-gate 				if (!check_nettype(argv[i + 1],
9637c478bd9Sstevel@tonic-gate 						    valid_ti_nettypes))
9647c478bd9Sstevel@tonic-gate 					return (0);
9657c478bd9Sstevel@tonic-gate 				write_nettype_register(argv[i + 1]);
9667c478bd9Sstevel@tonic-gate 				i++;
9677c478bd9Sstevel@tonic-gate 			} else if (streq(argv[i], "-n")) {
9687c478bd9Sstevel@tonic-gate 				write_netid_register(argv[i + 1]);
9697c478bd9Sstevel@tonic-gate 				i++;
9707c478bd9Sstevel@tonic-gate 			}
9717c478bd9Sstevel@tonic-gate 	}
9727c478bd9Sstevel@tonic-gate 	return (1);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate /*
9767c478bd9Sstevel@tonic-gate  * Add another argument to the arg list
9777c478bd9Sstevel@tonic-gate  */
9787c478bd9Sstevel@tonic-gate static void
979*61961e0fSrobinson addarg(char *cp)
9807c478bd9Sstevel@tonic-gate {
9817c478bd9Sstevel@tonic-gate 	if (argcount >= ARGLISTLEN) {
9827c478bd9Sstevel@tonic-gate 		f_print(stderr, "rpcgen: too many defines\n");
9837c478bd9Sstevel@tonic-gate 		crash();
9847c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
9857c478bd9Sstevel@tonic-gate 	}
9867c478bd9Sstevel@tonic-gate 	arglist[argcount++] = cp;
9877c478bd9Sstevel@tonic-gate }
9887c478bd9Sstevel@tonic-gate 
9897c478bd9Sstevel@tonic-gate static void
990*61961e0fSrobinson putarg(int where, char *cp)
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate 	if (where >= ARGLISTLEN) {
9937c478bd9Sstevel@tonic-gate 		f_print(stderr, "rpcgen: arglist coding error\n");
9947c478bd9Sstevel@tonic-gate 		crash();
9957c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
9967c478bd9Sstevel@tonic-gate 	}
9977c478bd9Sstevel@tonic-gate 	arglist[where] = cp;
9987c478bd9Sstevel@tonic-gate }
9997c478bd9Sstevel@tonic-gate 
10007c478bd9Sstevel@tonic-gate /*
10017c478bd9Sstevel@tonic-gate  * if input file is stdin and an output file is specified then complain
10027c478bd9Sstevel@tonic-gate  * if the file already exists. Otherwise the file may get overwritten
10037c478bd9Sstevel@tonic-gate  * If input file does not exist, exit with an error
10047c478bd9Sstevel@tonic-gate  */
10057c478bd9Sstevel@tonic-gate static void
1006*61961e0fSrobinson checkfiles(char *infile, char *outfile)
10077c478bd9Sstevel@tonic-gate {
10087c478bd9Sstevel@tonic-gate 	struct stat buf;
10097c478bd9Sstevel@tonic-gate 
1010*61961e0fSrobinson 	if (infile) {		/* infile ! = NULL */
1011*61961e0fSrobinson 		if (stat(infile, &buf) < 0) {
10127c478bd9Sstevel@tonic-gate 			perror(infile);
10137c478bd9Sstevel@tonic-gate 			crash();
1014*61961e0fSrobinson 		}
1015*61961e0fSrobinson 	}
10167c478bd9Sstevel@tonic-gate 	if (outfile) {
10177c478bd9Sstevel@tonic-gate 		if (stat(outfile, &buf) < 0)
10187c478bd9Sstevel@tonic-gate 			return;	/* file does not exist */
1019*61961e0fSrobinson 		f_print(stderr,
1020*61961e0fSrobinson 			"file '%s' already exists and may be overwritten\n",
1021*61961e0fSrobinson 			outfile);
1022*61961e0fSrobinson 		crash();
10237c478bd9Sstevel@tonic-gate 	}
10247c478bd9Sstevel@tonic-gate }
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate /*
10277c478bd9Sstevel@tonic-gate  * Parse command line arguments
10287c478bd9Sstevel@tonic-gate  */
1029*61961e0fSrobinson static uint_t
1030*61961e0fSrobinson parseargs(int argc, char *argv[], struct commandline *cmd)
10317c478bd9Sstevel@tonic-gate {
10327c478bd9Sstevel@tonic-gate 	int i;
10337c478bd9Sstevel@tonic-gate 	int j;
10347c478bd9Sstevel@tonic-gate 	char c, ch;
10357c478bd9Sstevel@tonic-gate 	char flag[(1 << 8 * sizeof (char))];
10367c478bd9Sstevel@tonic-gate 	int nflags;
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 	cmdname = argv[0];
10397c478bd9Sstevel@tonic-gate 	cmd->infile = cmd->outfile = NULL;
1040*61961e0fSrobinson 	if (argc < 2)
10417c478bd9Sstevel@tonic-gate 		return (0);
10427c478bd9Sstevel@tonic-gate 	allfiles = 0;
10437c478bd9Sstevel@tonic-gate 	flag['c'] = 0;
10447c478bd9Sstevel@tonic-gate 	flag['h'] = 0;
10457c478bd9Sstevel@tonic-gate 	flag['l'] = 0;
10467c478bd9Sstevel@tonic-gate 	flag['m'] = 0;
10477c478bd9Sstevel@tonic-gate 	flag['o'] = 0;
10487c478bd9Sstevel@tonic-gate 	flag['s'] = 0;
10497c478bd9Sstevel@tonic-gate 	flag['n'] = 0;
10507c478bd9Sstevel@tonic-gate 	flag['t'] = 0;
10517c478bd9Sstevel@tonic-gate 	flag['S'] = 0;
10527c478bd9Sstevel@tonic-gate 	flag['C'] = 0;
10537c478bd9Sstevel@tonic-gate 	flag['M'] = 0;
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	for (i = 1; i < argc; i++) {
10567c478bd9Sstevel@tonic-gate 		if (argv[i][0] != '-') {
10577c478bd9Sstevel@tonic-gate 			if (cmd->infile) {
10587c478bd9Sstevel@tonic-gate 				f_print(stderr,
10597c478bd9Sstevel@tonic-gate 	"Cannot specify more than one input file.\n");
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate 				return (0);
10627c478bd9Sstevel@tonic-gate 			}
10637c478bd9Sstevel@tonic-gate 			cmd->infile = argv[i];
10647c478bd9Sstevel@tonic-gate 		} else {
10657c478bd9Sstevel@tonic-gate 			for (j = 1; argv[i][j] != 0; j++) {
10667c478bd9Sstevel@tonic-gate 				c = argv[i][j];
10677c478bd9Sstevel@tonic-gate 				switch (c) {
10687c478bd9Sstevel@tonic-gate 				case 'a':
10697c478bd9Sstevel@tonic-gate 					allfiles = 1;
10707c478bd9Sstevel@tonic-gate 					break;
10717c478bd9Sstevel@tonic-gate 				case 'c':
10727c478bd9Sstevel@tonic-gate 				case 'h':
10737c478bd9Sstevel@tonic-gate 				case 'l':
10747c478bd9Sstevel@tonic-gate 				case 'm':
10757c478bd9Sstevel@tonic-gate 				case 't':
1076*61961e0fSrobinson 					if (flag[c])
10777c478bd9Sstevel@tonic-gate 						return (0);
10787c478bd9Sstevel@tonic-gate 					flag[c] = 1;
10797c478bd9Sstevel@tonic-gate 					break;
10807c478bd9Sstevel@tonic-gate 				case 'S':
10817c478bd9Sstevel@tonic-gate 					/*
10827c478bd9Sstevel@tonic-gate 					 * sample flag: Ss or Sc.
10837c478bd9Sstevel@tonic-gate 					 *  Ss means set flag['S'];
10847c478bd9Sstevel@tonic-gate 					 *  Sc means set flag['C'];
10857c478bd9Sstevel@tonic-gate 					 *  Sm means set flag['M'];
10867c478bd9Sstevel@tonic-gate 					 */
10877c478bd9Sstevel@tonic-gate 					ch = argv[i][++j]; /* get next char */
10887c478bd9Sstevel@tonic-gate 					if (ch == 's')
10897c478bd9Sstevel@tonic-gate 						ch = 'S';
10907c478bd9Sstevel@tonic-gate 					else if (ch == 'c')
10917c478bd9Sstevel@tonic-gate 						ch = 'C';
10927c478bd9Sstevel@tonic-gate 					else if (ch == 'm')
10937c478bd9Sstevel@tonic-gate 						ch = 'M';
10947c478bd9Sstevel@tonic-gate 					else
10957c478bd9Sstevel@tonic-gate 						return (0);
10967c478bd9Sstevel@tonic-gate 
1097*61961e0fSrobinson 					if (flag[ch])
10987c478bd9Sstevel@tonic-gate 						return (0);
10997c478bd9Sstevel@tonic-gate 					flag[ch] = 1;
11007c478bd9Sstevel@tonic-gate 					break;
11017c478bd9Sstevel@tonic-gate 				case 'C': /* ANSI C syntax */
11027c478bd9Sstevel@tonic-gate 					Cflag = 1;
11037c478bd9Sstevel@tonic-gate 					ch = argv[i][j+1]; /* get next char */
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 					if (ch != 'C')
11067c478bd9Sstevel@tonic-gate 						break;
11077c478bd9Sstevel@tonic-gate 					CCflag = 1;
11087c478bd9Sstevel@tonic-gate 					break;
11097c478bd9Sstevel@tonic-gate 				case 'b':
11107c478bd9Sstevel@tonic-gate 					/*
11117c478bd9Sstevel@tonic-gate 					 *  Turn TIRPC flag off for
11127c478bd9Sstevel@tonic-gate 					 *  generating backward compatible
11137c478bd9Sstevel@tonic-gate 					 *  code
11147c478bd9Sstevel@tonic-gate 					 */
11157c478bd9Sstevel@tonic-gate 					tirpcflag = 0;
11167c478bd9Sstevel@tonic-gate 					break;
11177c478bd9Sstevel@tonic-gate 
11187c478bd9Sstevel@tonic-gate 				case 'I':
11197c478bd9Sstevel@tonic-gate 					inetdflag = 1;
11207c478bd9Sstevel@tonic-gate 					break;
11217c478bd9Sstevel@tonic-gate 				case 'N':
11227c478bd9Sstevel@tonic-gate 					newstyle = 1;
11237c478bd9Sstevel@tonic-gate 					break;
11247c478bd9Sstevel@tonic-gate 				case 'L':
11257c478bd9Sstevel@tonic-gate 					logflag = 1;
11267c478bd9Sstevel@tonic-gate 					break;
11277c478bd9Sstevel@tonic-gate 				case 'K':
1128*61961e0fSrobinson 					if (++i == argc)
11297c478bd9Sstevel@tonic-gate 						return (0);
11307c478bd9Sstevel@tonic-gate 					svcclosetime = argv[i];
11317c478bd9Sstevel@tonic-gate 					goto nextarg;
11327c478bd9Sstevel@tonic-gate 				case 'T':
11337c478bd9Sstevel@tonic-gate 					tblflag = 1;
11347c478bd9Sstevel@tonic-gate 					break;
11357c478bd9Sstevel@tonic-gate 				case 'A':
11367c478bd9Sstevel@tonic-gate 					mtauto = 1;
1137*61961e0fSrobinson 					/* FALLTHRU */
11387c478bd9Sstevel@tonic-gate 				case 'M':
11397c478bd9Sstevel@tonic-gate 					mtflag = 1;
11407c478bd9Sstevel@tonic-gate 					break;
11417c478bd9Sstevel@tonic-gate 				case 'i' :
1142*61961e0fSrobinson 					if (++i == argc)
11437c478bd9Sstevel@tonic-gate 						return (0);
11447c478bd9Sstevel@tonic-gate 					inlinelen = atoi(argv[i]);
11457c478bd9Sstevel@tonic-gate 					goto nextarg;
11467c478bd9Sstevel@tonic-gate 				case 'n':
11477c478bd9Sstevel@tonic-gate 				case 'o':
11487c478bd9Sstevel@tonic-gate 				case 's':
11497c478bd9Sstevel@tonic-gate 					if (argv[i][j - 1] != '-' ||
1150*61961e0fSrobinson 					    argv[i][j + 1] != 0)
11517c478bd9Sstevel@tonic-gate 						return (0);
11527c478bd9Sstevel@tonic-gate 					flag[c] = 1;
1153*61961e0fSrobinson 					if (++i == argc)
11547c478bd9Sstevel@tonic-gate 						return (0);
11557c478bd9Sstevel@tonic-gate 					if (c == 'o') {
1156*61961e0fSrobinson 						if (cmd->outfile)
11577c478bd9Sstevel@tonic-gate 							return (0);
11587c478bd9Sstevel@tonic-gate 						cmd->outfile = argv[i];
11597c478bd9Sstevel@tonic-gate 					}
11607c478bd9Sstevel@tonic-gate 					goto nextarg;
11617c478bd9Sstevel@tonic-gate 				case 'D':
1162*61961e0fSrobinson 					if (argv[i][j - 1] != '-')
11637c478bd9Sstevel@tonic-gate 						return (0);
11647c478bd9Sstevel@tonic-gate 					(void) addarg(argv[i]);
11657c478bd9Sstevel@tonic-gate 					goto nextarg;
11667c478bd9Sstevel@tonic-gate 				case 'v':
11677c478bd9Sstevel@tonic-gate 					version_info();
11687c478bd9Sstevel@tonic-gate 					return (0);
11697c478bd9Sstevel@tonic-gate 				case 'Y':
1170*61961e0fSrobinson 					if (++i == argc)
11717c478bd9Sstevel@tonic-gate 						return (0);
11727c478bd9Sstevel@tonic-gate 					(void) strcpy(pathbuf, argv[i]);
11737c478bd9Sstevel@tonic-gate 					(void) strcat(pathbuf, "/cpp");
11747c478bd9Sstevel@tonic-gate 					CPP = pathbuf;
11757c478bd9Sstevel@tonic-gate 					cppDefined = 1;
11767c478bd9Sstevel@tonic-gate 					goto nextarg;
11777c478bd9Sstevel@tonic-gate 				case 'r':
11787c478bd9Sstevel@tonic-gate 					rflag = !rflag;
11797c478bd9Sstevel@tonic-gate 					break;
11807c478bd9Sstevel@tonic-gate 				default:
11817c478bd9Sstevel@tonic-gate 					return (0);
11827c478bd9Sstevel@tonic-gate 				}
11837c478bd9Sstevel@tonic-gate 			}
11847c478bd9Sstevel@tonic-gate 		nextarg:
11857c478bd9Sstevel@tonic-gate 			;
11867c478bd9Sstevel@tonic-gate 		}
11877c478bd9Sstevel@tonic-gate 	}
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 	cmd->cflag = flag['c'];
11907c478bd9Sstevel@tonic-gate 	cmd->hflag = flag['h'];
11917c478bd9Sstevel@tonic-gate 	cmd->lflag = flag['l'];
11927c478bd9Sstevel@tonic-gate 	cmd->mflag = flag['m'];
11937c478bd9Sstevel@tonic-gate 	cmd->nflag = flag['n'];
11947c478bd9Sstevel@tonic-gate 	cmd->sflag = flag['s'];
11957c478bd9Sstevel@tonic-gate 	cmd->tflag = flag['t'];
11967c478bd9Sstevel@tonic-gate 	cmd->Ssflag = flag['S'];
11977c478bd9Sstevel@tonic-gate 	cmd->Scflag = flag['C'];
11987c478bd9Sstevel@tonic-gate 	cmd->makefileflag = flag['M'];
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 	if (tirpcflag) {
12017c478bd9Sstevel@tonic-gate 		if (inetdflag) {
12027c478bd9Sstevel@tonic-gate 			f_print(stderr,
12037c478bd9Sstevel@tonic-gate 				"Cannot use -I flag without -b flag.\n");
12047c478bd9Sstevel@tonic-gate 			return (0);
12057c478bd9Sstevel@tonic-gate 		}
12067c478bd9Sstevel@tonic-gate 		pmflag = 1;
12077c478bd9Sstevel@tonic-gate 	} else {		/* 4.1 mode */
12087c478bd9Sstevel@tonic-gate 		pmflag = 0;	/* set pmflag only in tirpcmode */
12097c478bd9Sstevel@tonic-gate 		inetdflag = 1;	/* inetdflag is TRUE by default */
12107c478bd9Sstevel@tonic-gate 		if (cmd->nflag) { /* netid needs TIRPC */
1211*61961e0fSrobinson 			f_print(stderr,
1212*61961e0fSrobinson 				"Cannot use netid flag without TIRPC.\n");
12137c478bd9Sstevel@tonic-gate 			return (0);
12147c478bd9Sstevel@tonic-gate 		}
12157c478bd9Sstevel@tonic-gate 	}
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate 	if (newstyle && (tblflag || cmd->tflag)) {
12187c478bd9Sstevel@tonic-gate 		f_print(stderr, "Cannot use table flags with newstyle.\n");
12197c478bd9Sstevel@tonic-gate 		return (0);
12207c478bd9Sstevel@tonic-gate 	}
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 	/* check no conflicts with file generation flags */
12237c478bd9Sstevel@tonic-gate 	nflags = cmd->cflag + cmd->hflag + cmd->lflag + cmd->mflag +
12247c478bd9Sstevel@tonic-gate 		cmd->sflag + cmd->nflag + cmd->tflag + cmd->Ssflag +
12257c478bd9Sstevel@tonic-gate 			cmd->Scflag + cmd->makefileflag;
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	if (nflags == 0) {
1228*61961e0fSrobinson 		if (cmd->outfile != NULL || cmd->infile == NULL)
12297c478bd9Sstevel@tonic-gate 			return (0);
12307c478bd9Sstevel@tonic-gate 	} else if (cmd->infile == NULL &&
12317c478bd9Sstevel@tonic-gate 	    (cmd->Ssflag || cmd->Scflag || cmd->makefileflag)) {
12327c478bd9Sstevel@tonic-gate 		f_print(stderr, "\"infile\" is required for template"
12337c478bd9Sstevel@tonic-gate 			" generation flags.\n");
12347c478bd9Sstevel@tonic-gate 		return (0);
1235*61961e0fSrobinson 	}
1236*61961e0fSrobinson 	if (nflags > 1) {
12377c478bd9Sstevel@tonic-gate 		f_print(stderr,
12387c478bd9Sstevel@tonic-gate 			"Cannot have more than one file generation flag.\n");
12397c478bd9Sstevel@tonic-gate 		return (0);
12407c478bd9Sstevel@tonic-gate 	}
12417c478bd9Sstevel@tonic-gate 	return (1);
12427c478bd9Sstevel@tonic-gate }
12437c478bd9Sstevel@tonic-gate 
1244*61961e0fSrobinson static void
1245*61961e0fSrobinson usage(void)
12467c478bd9Sstevel@tonic-gate {
12477c478bd9Sstevel@tonic-gate 	f_print(stderr, "%s  (%d.%d)\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR);
12487c478bd9Sstevel@tonic-gate 	f_print(stderr, "usage:  %s infile\n", cmdname);
12497c478bd9Sstevel@tonic-gate 	f_print(stderr, "\t%s [-abCLNTMA] [-Dname[=value]] [-i size]"
12507c478bd9Sstevel@tonic-gate 		" [-I [-K seconds]] [-Y path] infile\n", cmdname);
12517c478bd9Sstevel@tonic-gate 	f_print(stderr, "\t%s [-c | -h | -l | -m | -t | -Sc | -Ss | -Sm]"
12527c478bd9Sstevel@tonic-gate 		" [-o outfile] [infile]\n", cmdname);
12537c478bd9Sstevel@tonic-gate 	f_print(stderr, "\t%s [-s nettype]* [-o outfile] [infile]\n", cmdname);
12547c478bd9Sstevel@tonic-gate 	f_print(stderr, "\t%s [-n netid]* [-o outfile] [infile]\n", cmdname);
12557c478bd9Sstevel@tonic-gate 	options_usage();
12567c478bd9Sstevel@tonic-gate 	exit(1);
12577c478bd9Sstevel@tonic-gate }
12587c478bd9Sstevel@tonic-gate 
1259*61961e0fSrobinson static void
1260*61961e0fSrobinson version_info(void)
12617c478bd9Sstevel@tonic-gate {
12627c478bd9Sstevel@tonic-gate 	f_print(stderr, "%s %d.%d\n", cmdname, RPCGEN_MAJOR, RPCGEN_MINOR);
12637c478bd9Sstevel@tonic-gate 	exit(1);
12647c478bd9Sstevel@tonic-gate }
12657c478bd9Sstevel@tonic-gate 
1266*61961e0fSrobinson static void
1267*61961e0fSrobinson options_usage(void)
12687c478bd9Sstevel@tonic-gate {
12697c478bd9Sstevel@tonic-gate 	f_print(stderr, "options:\n");
12707c478bd9Sstevel@tonic-gate 	f_print(stderr, "-a\t\tgenerate all files, including samples\n");
12717c478bd9Sstevel@tonic-gate 	f_print(stderr, "-A\t\tgenerate code to enable automatic MT mode\n");
12727c478bd9Sstevel@tonic-gate 	f_print(stderr, "-b\t\tbackward compatibility mode (generates code"
12737c478bd9Sstevel@tonic-gate 			" for SunOS 4.X)\n");
12747c478bd9Sstevel@tonic-gate 	f_print(stderr, "-c\t\tgenerate XDR routines\n");
12757c478bd9Sstevel@tonic-gate 	f_print(stderr, "-C\t\tANSI C mode\n");
12767c478bd9Sstevel@tonic-gate 	f_print(stderr, "-Dname[=value]\tdefine a symbol (same as #define)\n");
12777c478bd9Sstevel@tonic-gate 	f_print(stderr, "-h\t\tgenerate header file\n");
12787c478bd9Sstevel@tonic-gate 	f_print(stderr, "-i size\t\tsize at which to start generating"
12797c478bd9Sstevel@tonic-gate 			" inline code\n");
12807c478bd9Sstevel@tonic-gate 	f_print(stderr, "-I\t\tgenerate code for inetd support in server"
12817c478bd9Sstevel@tonic-gate 			" (for SunOS 4.X)\n");
12827c478bd9Sstevel@tonic-gate 	f_print(stderr, "-K seconds\tserver exits after K seconds of"
12837c478bd9Sstevel@tonic-gate 			" inactivity\n");
12847c478bd9Sstevel@tonic-gate 	f_print(stderr, "-l\t\tgenerate client side stubs\n");
12857c478bd9Sstevel@tonic-gate 	f_print(stderr, "-L\t\tserver errors will be printed to syslog\n");
12867c478bd9Sstevel@tonic-gate 	f_print(stderr, "-m\t\tgenerate server side stubs\n");
12877c478bd9Sstevel@tonic-gate 	f_print(stderr, "-M\t\tgenerate MT-safe code\n");
12887c478bd9Sstevel@tonic-gate 	f_print(stderr, "-n netid\tgenerate server code that supports"
12897c478bd9Sstevel@tonic-gate 			" named netid\n");
12907c478bd9Sstevel@tonic-gate 	f_print(stderr, "-N\t\tsupports multiple arguments and"
12917c478bd9Sstevel@tonic-gate 			" call-by-value\n");
12927c478bd9Sstevel@tonic-gate 	f_print(stderr, "-o outfile\tname of the output file\n");
12937c478bd9Sstevel@tonic-gate 	f_print(stderr, "-s nettype\tgenerate server code that supports named"
12947c478bd9Sstevel@tonic-gate 			" nettype\n");
12957c478bd9Sstevel@tonic-gate 	f_print(stderr, "-Sc\t\tgenerate sample client code that uses remote"
12967c478bd9Sstevel@tonic-gate 			" procedures\n");
12977c478bd9Sstevel@tonic-gate 	f_print(stderr, "-Ss\t\tgenerate sample server code that defines"
12987c478bd9Sstevel@tonic-gate 			" remote procedures\n");
12997c478bd9Sstevel@tonic-gate 	f_print(stderr, "-Sm \t\tgenerate makefile template \n");
13007c478bd9Sstevel@tonic-gate 
13017c478bd9Sstevel@tonic-gate 	f_print(stderr, "-t\t\tgenerate RPC dispatch table\n");
13027c478bd9Sstevel@tonic-gate 	f_print(stderr, "-T\t\tgenerate code to support RPC dispatch tables\n");
13037c478bd9Sstevel@tonic-gate 	f_print(stderr, "-v\t\tprint version information and exit\n");
13047c478bd9Sstevel@tonic-gate 	f_print(stderr, "-Y path\t\tpath where cpp is found\n");
13057c478bd9Sstevel@tonic-gate 	exit(1);
13067c478bd9Sstevel@tonic-gate }
1307