10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
21*132Srobinson  */
22*132Srobinson 
23*132Srobinson /*
24*132Srobinson  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
250Sstevel@tonic-gate  * Use is subject to license terms.
260Sstevel@tonic-gate  */
270Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
310Sstevel@tonic-gate  * The Regents of the University of California
320Sstevel@tonic-gate  * All Rights Reserved
330Sstevel@tonic-gate  *
340Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
350Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
360Sstevel@tonic-gate  * contributors.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
400Sstevel@tonic-gate 
410Sstevel@tonic-gate /*
420Sstevel@tonic-gate  * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
430Sstevel@tonic-gate  */
440Sstevel@tonic-gate #include <stdio.h>
450Sstevel@tonic-gate #include <string.h>
460Sstevel@tonic-gate #include <rpc/types.h>
470Sstevel@tonic-gate #include "rpc_parse.h"
480Sstevel@tonic-gate #include "rpc_util.h"
490Sstevel@tonic-gate 
50*132Srobinson extern void pdeclaration(char *, declaration *, int, char *);
51*132Srobinson extern void printarglist(proc_list *, char *, char *, char *);
520Sstevel@tonic-gate 
53*132Srobinson static void write_program(definition *);
54*132Srobinson static void printbody(proc_list *);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static char RESULT[] = "clnt_res";
570Sstevel@tonic-gate 
58*132Srobinson #define	DEFAULT_TIMEOUT 25	/* in seconds */
590Sstevel@tonic-gate 
600Sstevel@tonic-gate void
61*132Srobinson write_stubs(void)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate 	list *l;
640Sstevel@tonic-gate 	definition *def;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 	f_print(fout,
67*132Srobinson 	    "\n/* Default timeout can be changed using clnt_control() */\n");
680Sstevel@tonic-gate 	f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
690Sstevel@tonic-gate 		DEFAULT_TIMEOUT);
700Sstevel@tonic-gate 	for (l = defined; l != NULL; l = l->next) {
710Sstevel@tonic-gate 		def = (definition *) l->val;
720Sstevel@tonic-gate 		if (def->def_kind == DEF_PROGRAM) {
730Sstevel@tonic-gate 			write_program(def);
740Sstevel@tonic-gate 		}
750Sstevel@tonic-gate 	}
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
78*132Srobinson static void
79*132Srobinson write_program(definition *def)
800Sstevel@tonic-gate {
810Sstevel@tonic-gate 	version_list *vp;
820Sstevel@tonic-gate 	proc_list *proc;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
850Sstevel@tonic-gate 		for (proc = vp->procs; proc != NULL; proc = proc->next) {
860Sstevel@tonic-gate 			f_print(fout, "\n");
870Sstevel@tonic-gate 			if (mtflag == 0) {
880Sstevel@tonic-gate 				ptype(proc->res_prefix, proc->res_type, 1);
890Sstevel@tonic-gate 				f_print(fout, "*\n");
900Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
910Sstevel@tonic-gate 				printarglist(proc, RESULT, "clnt", "CLIENT *");
920Sstevel@tonic-gate 			} else {
930Sstevel@tonic-gate 				f_print(fout, "enum clnt_stat \n");
940Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
950Sstevel@tonic-gate 				printarglist(proc, RESULT,  "clnt", "CLIENT *");
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 			}
980Sstevel@tonic-gate 			f_print(fout, "{\n");
990Sstevel@tonic-gate 			printbody(proc);
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 			f_print(fout, "}\n");
1020Sstevel@tonic-gate 		}
1030Sstevel@tonic-gate 	}
1040Sstevel@tonic-gate }
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /*
1070Sstevel@tonic-gate  * Writes out declarations of procedure's argument list.
1080Sstevel@tonic-gate  * In either ANSI C style, in one of old rpcgen style (pass by reference),
1090Sstevel@tonic-gate  * or new rpcgen style (multiple arguments, pass by value);
1100Sstevel@tonic-gate  */
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
1130Sstevel@tonic-gate 
114*132Srobinson void
115*132Srobinson printarglist(proc_list *proc, char *result, char *addargname, char *addargtype)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate 	bool_t oneway = streq(proc->res_type, "oneway");
1180Sstevel@tonic-gate 	decl_list *l;
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	if (!newstyle) {
1210Sstevel@tonic-gate 		/* old style: always pass argument by reference */
1220Sstevel@tonic-gate 		if (Cflag) {	/* C++ style heading */
1230Sstevel@tonic-gate 			f_print(fout, "(");
1240Sstevel@tonic-gate 			ptype(proc->args.decls->decl.prefix,
125*132Srobinson 						proc->args.decls->decl.type, 1);
1260Sstevel@tonic-gate 
127*132Srobinson 			if (mtflag) {	/* Generate result field */
1280Sstevel@tonic-gate 				f_print(fout, "*argp, ");
1290Sstevel@tonic-gate 				if (!oneway) {
1300Sstevel@tonic-gate 					ptype(proc->res_prefix,
1310Sstevel@tonic-gate 					    proc->res_type, 1);
1320Sstevel@tonic-gate 					f_print(fout, "*%s, ", result);
1330Sstevel@tonic-gate 				}
1340Sstevel@tonic-gate 				f_print(fout, "%s%s)\n",
1350Sstevel@tonic-gate 					addargtype, addargname);
1360Sstevel@tonic-gate 			} else
137*132Srobinson 				f_print(fout, "*argp, %s%s)\n",
138*132Srobinson 					addargtype, addargname);
1390Sstevel@tonic-gate 		} else {
1400Sstevel@tonic-gate 			if (!mtflag)
1410Sstevel@tonic-gate 				f_print(fout, "(argp, %s)\n", addargname);
1420Sstevel@tonic-gate 			else {
1430Sstevel@tonic-gate 				f_print(fout, "(argp, ");
1440Sstevel@tonic-gate 				if (!oneway) {
1450Sstevel@tonic-gate 					f_print(fout, "%s, ",
1460Sstevel@tonic-gate 					    result);
1470Sstevel@tonic-gate 				}
1480Sstevel@tonic-gate 				f_print(fout, "%s)\n",
1490Sstevel@tonic-gate 				    addargname);
1500Sstevel@tonic-gate 			}
1510Sstevel@tonic-gate 			f_print(fout, "\t");
1520Sstevel@tonic-gate 			ptype(proc->args.decls->decl.prefix,
1530Sstevel@tonic-gate 			    proc->args.decls->decl.type, 1);
1540Sstevel@tonic-gate 			f_print(fout, "*argp;\n");
1550Sstevel@tonic-gate 			if (mtflag && !oneway) {
1560Sstevel@tonic-gate 				f_print(fout, "\t");
1570Sstevel@tonic-gate 				ptype(proc->res_prefix, proc->res_type, 1);
1580Sstevel@tonic-gate 				f_print(fout, "*%s;\n", result);
1590Sstevel@tonic-gate 			}
1600Sstevel@tonic-gate 		}
1610Sstevel@tonic-gate 	} else if (streq(proc->args.decls->decl.type, "void")) {
1620Sstevel@tonic-gate 		/* newstyle, 0 argument */
1630Sstevel@tonic-gate 		if (mtflag) {
1640Sstevel@tonic-gate 			f_print(fout, "(");
165*132Srobinson 
1660Sstevel@tonic-gate 			if (Cflag) {
1670Sstevel@tonic-gate 				if (!oneway) {
1680Sstevel@tonic-gate 					ptype(proc->res_prefix,
1690Sstevel@tonic-gate 					    proc->res_type, 1);
1700Sstevel@tonic-gate 					f_print(fout, "*%s, ", result);
1710Sstevel@tonic-gate 				}
1720Sstevel@tonic-gate 				f_print(fout, "%s%s)\n",
1730Sstevel@tonic-gate 				    addargtype, addargname);
1740Sstevel@tonic-gate 			} else
175*132Srobinson 				f_print(fout, "(%s)\n", addargname);
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate 		} else
1780Sstevel@tonic-gate 		if (Cflag)
1790Sstevel@tonic-gate 			f_print(fout, "(%s%s)\n", addargtype, addargname);
1800Sstevel@tonic-gate 		else
1810Sstevel@tonic-gate 			f_print(fout, "(%s)\n", addargname);
1820Sstevel@tonic-gate 	} else {
1830Sstevel@tonic-gate 		/* new style, 1 or multiple arguments */
1840Sstevel@tonic-gate 		if (!Cflag) {
1850Sstevel@tonic-gate 			f_print(fout, "(");
1860Sstevel@tonic-gate 			for (l = proc->args.decls;  l != NULL; l = l->next)
1870Sstevel@tonic-gate 				f_print(fout, "%s, ", l->decl.name);
1880Sstevel@tonic-gate 			if (mtflag && !oneway)
189*132Srobinson 				f_print(fout, "%s, ", result);
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 			f_print(fout, "%s)\n", addargname);
1920Sstevel@tonic-gate 			for (l = proc->args.decls; l != NULL; l = l->next) {
1930Sstevel@tonic-gate 				pdeclaration(proc->args.argname,
194*132Srobinson 							&l->decl, 1, ";\n");
1950Sstevel@tonic-gate 			}
1960Sstevel@tonic-gate 			if (mtflag && !oneway) {
1970Sstevel@tonic-gate 				f_print(fout, "\t");
1980Sstevel@tonic-gate 				ptype(proc->res_prefix, proc->res_type, 1);
1990Sstevel@tonic-gate 				f_print(fout, "*%s;\n", result);
2000Sstevel@tonic-gate 			}
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 		} else {	/* C++ style header */
2030Sstevel@tonic-gate 			f_print(fout, "(");
2040Sstevel@tonic-gate 			for (l = proc->args.decls; l != NULL; l = l->next) {
2050Sstevel@tonic-gate 				pdeclaration(proc->args.argname, &l->decl, 0,
206*132Srobinson 									", ");
2070Sstevel@tonic-gate 			}
2080Sstevel@tonic-gate 			if (mtflag && !oneway) {
2090Sstevel@tonic-gate 				ptype(proc->res_prefix, proc->res_type, 1);
2100Sstevel@tonic-gate 				f_print(fout, "*%s, ", result);
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 			}
2130Sstevel@tonic-gate 			f_print(fout, "%s%s)\n", addargtype, addargname);
2140Sstevel@tonic-gate 		}
2150Sstevel@tonic-gate 	}
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	if (!Cflag)
2180Sstevel@tonic-gate 		f_print(fout, "\t%s%s;\n", addargtype, addargname);
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate static char *
224*132Srobinson ampr(char *type)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate 	if (isvectordef(type, REL_ALIAS)) {
2270Sstevel@tonic-gate 		return ("");
2280Sstevel@tonic-gate 	} else {
2290Sstevel@tonic-gate 		return ("&");
2300Sstevel@tonic-gate 	}
2310Sstevel@tonic-gate }
2320Sstevel@tonic-gate 
233*132Srobinson static void
234*132Srobinson printbody(proc_list *proc)
2350Sstevel@tonic-gate {
2360Sstevel@tonic-gate 	decl_list *l;
2370Sstevel@tonic-gate 	bool_t args2 = (proc->arg_num > 1);
2380Sstevel@tonic-gate 	bool_t oneway = streq(proc->res_type, "oneway");
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 	/*
2410Sstevel@tonic-gate 	 * For new style with multiple arguments, need a structure in which
2420Sstevel@tonic-gate 	 *  to stuff the arguments.
2430Sstevel@tonic-gate 	 */
2440Sstevel@tonic-gate 	if (newstyle && args2) {
2450Sstevel@tonic-gate 		f_print(fout, "\t%s", proc->args.argname);
2460Sstevel@tonic-gate 		f_print(fout, " arg;\n");
2470Sstevel@tonic-gate 	}
2480Sstevel@tonic-gate 	if (!oneway) {
2490Sstevel@tonic-gate 		if (!mtflag) {
2500Sstevel@tonic-gate 			f_print(fout, "\tstatic ");
2510Sstevel@tonic-gate 			if (streq(proc->res_type, "void")) {
2520Sstevel@tonic-gate 				f_print(fout, "char ");
2530Sstevel@tonic-gate 			} else {
2540Sstevel@tonic-gate 				ptype(proc->res_prefix, proc->res_type, 0);
2550Sstevel@tonic-gate 			}
2560Sstevel@tonic-gate 			f_print(fout, "%s;\n", RESULT);
2570Sstevel@tonic-gate 			f_print(fout, "\n");
2580Sstevel@tonic-gate 			f_print(fout,
259*132Srobinson 			    "\t(void) memset(%s%s, 0, sizeof (%s));\n",
2600Sstevel@tonic-gate 			    ampr(proc->res_type), RESULT, RESULT);
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate 		}
2630Sstevel@tonic-gate 		if (newstyle && !args2 &&
2640Sstevel@tonic-gate 		    (streq(proc->args.decls->decl.type, "void"))) {
2650Sstevel@tonic-gate 			/* newstyle, 0 arguments */
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 			if (mtflag)
2680Sstevel@tonic-gate 				f_print(fout, "\t return ");
2690Sstevel@tonic-gate 			else
2700Sstevel@tonic-gate 				f_print(fout, "\t if ");
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 			f_print(fout,
273*132Srobinson 			    "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ",
2740Sstevel@tonic-gate 			    proc->proc_name);
2750Sstevel@tonic-gate 			f_print(fout,
276*132Srobinson 			    "NULL,\n\t\t(xdrproc_t)xdr_%s, "
277*132Srobinson 			    "(caddr_t)%s%s,",
2780Sstevel@tonic-gate 			    stringfix(proc->res_type),
2790Sstevel@tonic-gate 			    (mtflag)?"":ampr(proc->res_type),
2800Sstevel@tonic-gate 			    RESULT);
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate 			if (mtflag)
2830Sstevel@tonic-gate 				f_print(fout, "\n\t\tTIMEOUT));\n");
2840Sstevel@tonic-gate 			else
2850Sstevel@tonic-gate 				f_print(fout,
2860Sstevel@tonic-gate 				    "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 		} else if (newstyle && args2) {
2890Sstevel@tonic-gate 			/*
2900Sstevel@tonic-gate 			 * Newstyle, multiple arguments
2910Sstevel@tonic-gate 			 * stuff arguments into structure
2920Sstevel@tonic-gate 			 */
2930Sstevel@tonic-gate 			for (l = proc->args.decls;  l != NULL; l = l->next) {
2940Sstevel@tonic-gate 				f_print(fout, "\targ.%s = %s;\n",
2950Sstevel@tonic-gate 				    l->decl.name, l->decl.name);
2960Sstevel@tonic-gate 			}
2970Sstevel@tonic-gate 			if (mtflag)
2980Sstevel@tonic-gate 				f_print(fout, "\treturn ");
2990Sstevel@tonic-gate 			else
3000Sstevel@tonic-gate 				f_print(fout, "\tif ");
3010Sstevel@tonic-gate 			f_print(fout,
302*132Srobinson 			    "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_%s",
3030Sstevel@tonic-gate 			    proc->proc_name, proc->args.argname);
3040Sstevel@tonic-gate 			f_print(fout,
305*132Srobinson 			    ", (caddr_t)&arg,\n\t\t(xdrproc_t)xdr_%s, "
306*132Srobinson 			    "(caddr_t)%s%s,",
3070Sstevel@tonic-gate 			    stringfix(proc->res_type),
3080Sstevel@tonic-gate 			    (mtflag)?"":ampr(proc->res_type),
3090Sstevel@tonic-gate 			    RESULT);
3100Sstevel@tonic-gate 			if (mtflag)
3110Sstevel@tonic-gate 				f_print(fout, "\n\t\tTIMEOUT));\n");
3120Sstevel@tonic-gate 			else
3130Sstevel@tonic-gate 				f_print(fout,
3140Sstevel@tonic-gate 				    "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
3150Sstevel@tonic-gate 		} else {		/* single argument, new or old style */
3160Sstevel@tonic-gate 			if (!mtflag)
3170Sstevel@tonic-gate 				f_print(fout,
3180Sstevel@tonic-gate 				    "\tif (clnt_call(clnt, "
319*132Srobinson 				    "%s,\n\t\t(xdrproc_t)xdr_%s, "
320*132Srobinson 				    "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, "
321*132Srobinson 				    "(caddr_t)%s%s,\n\t\tTIMEOUT) != "
3220Sstevel@tonic-gate 				    "RPC_SUCCESS) {\n",
3230Sstevel@tonic-gate 				    proc->proc_name,
3240Sstevel@tonic-gate 				    stringfix(proc->args.decls->decl.type),
3250Sstevel@tonic-gate 				    (newstyle ? "&" : ""),
3260Sstevel@tonic-gate 				    (newstyle ?
3270Sstevel@tonic-gate 					proc->args.decls->decl.name :
3280Sstevel@tonic-gate 					"argp"),
3290Sstevel@tonic-gate 				    stringfix(proc->res_type),
3300Sstevel@tonic-gate 				    ampr(proc->res_type),
3310Sstevel@tonic-gate 				    RESULT);
3320Sstevel@tonic-gate 			else
3330Sstevel@tonic-gate 				f_print(fout,
3340Sstevel@tonic-gate 				    "\treturn (clnt_call(clnt, "
335*132Srobinson 				    "%s,\n\t\t(xdrproc_t)xdr_%s, "
336*132Srobinson 				    "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, "
337*132Srobinson 				    "(caddr_t)%s%s,\n\t\tTIMEOUT));\n",
3380Sstevel@tonic-gate 				    proc->proc_name,
3390Sstevel@tonic-gate 				    stringfix(proc->args.decls->decl.type),
3400Sstevel@tonic-gate 				    (newstyle ? "&" : ""),
3410Sstevel@tonic-gate 				    (newstyle ?
3420Sstevel@tonic-gate 					proc->args.decls->decl.name :
3430Sstevel@tonic-gate 					"argp"),
3440Sstevel@tonic-gate 				    stringfix(proc->res_type), "",
3450Sstevel@tonic-gate 				    RESULT);
3460Sstevel@tonic-gate 		}
3470Sstevel@tonic-gate 		if (!mtflag) {
3480Sstevel@tonic-gate 			f_print(fout, "\t\treturn (NULL);\n");
3490Sstevel@tonic-gate 			f_print(fout, "\t}\n");
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 			if (streq(proc->res_type, "void")) {
3520Sstevel@tonic-gate 				f_print(fout, "\treturn ((void *)%s%s);\n",
3530Sstevel@tonic-gate 				    ampr(proc->res_type), RESULT);
3540Sstevel@tonic-gate 			} else {
3550Sstevel@tonic-gate 				f_print(fout, "\treturn (%s%s);\n",
3560Sstevel@tonic-gate 				    ampr(proc->res_type), RESULT);
3570Sstevel@tonic-gate 			}
3580Sstevel@tonic-gate 		}
3590Sstevel@tonic-gate 	} else {
3600Sstevel@tonic-gate 		/* oneway call */
3610Sstevel@tonic-gate 		if (!mtflag) {
3620Sstevel@tonic-gate 			f_print(fout, "\tstatic enum clnt_stat ");
3630Sstevel@tonic-gate 			f_print(fout, "%s;\n", RESULT);
3640Sstevel@tonic-gate 			f_print(fout, "\n");
3650Sstevel@tonic-gate 			f_print(fout,
366*132Srobinson 			    "\t(void) memset(&%s, 0, sizeof (%s));\n",
3670Sstevel@tonic-gate 			    RESULT, RESULT);
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 		}
3700Sstevel@tonic-gate 		if (newstyle && !args2 &&
3710Sstevel@tonic-gate 		    (streq(proc->args.decls->decl.type, "void"))) {
3720Sstevel@tonic-gate 			/* newstyle, 0 arguments */
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 			if (mtflag)
3750Sstevel@tonic-gate 				f_print(fout, "\t return (");
3760Sstevel@tonic-gate 			else
3770Sstevel@tonic-gate 				f_print(fout, "\t if ((%s = ", RESULT);
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 			f_print(fout,
380*132Srobinson 			    "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ",
3810Sstevel@tonic-gate 			    proc->proc_name);
382*132Srobinson 			f_print(fout, "NULL)");
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 			if (mtflag)
3850Sstevel@tonic-gate 				f_print(fout, ");\n");
3860Sstevel@tonic-gate 			else
3870Sstevel@tonic-gate 				f_print(fout, ") != RPC_SUCCESS) {\n");
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 		} else if (newstyle && args2) {
3900Sstevel@tonic-gate 			/*
3910Sstevel@tonic-gate 			 * Newstyle, multiple arguments
3920Sstevel@tonic-gate 			 * stuff arguments into structure
3930Sstevel@tonic-gate 			 */
3940Sstevel@tonic-gate 			for (l = proc->args.decls;  l != NULL; l = l->next) {
3950Sstevel@tonic-gate 				f_print(fout, "\targ.%s = %s;\n",
3960Sstevel@tonic-gate 				    l->decl.name, l->decl.name);
3970Sstevel@tonic-gate 			}
3980Sstevel@tonic-gate 			if (mtflag)
3990Sstevel@tonic-gate 				f_print(fout, "\treturn (");
4000Sstevel@tonic-gate 			else
4010Sstevel@tonic-gate 				f_print(fout, "\tif ((%s =", RESULT);
4020Sstevel@tonic-gate 			f_print(fout,
403*132Srobinson 			    "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_%s",
4040Sstevel@tonic-gate 			    proc->proc_name, proc->args.argname);
4050Sstevel@tonic-gate 			f_print(fout,
406*132Srobinson 			    ", (caddr_t)&arg)");
4070Sstevel@tonic-gate 			if (mtflag)
4080Sstevel@tonic-gate 				f_print(fout, ");\n");
4090Sstevel@tonic-gate 			else
4100Sstevel@tonic-gate 				f_print(fout, ") != RPC_SUCCESS) {\n");
4110Sstevel@tonic-gate 		} else {		/* single argument, new or old style */
4120Sstevel@tonic-gate 			if (!mtflag)
4130Sstevel@tonic-gate 				f_print(fout,
4140Sstevel@tonic-gate 				    "\tif ((%s = clnt_send(clnt, "
415*132Srobinson 				    "%s,\n\t\t(xdrproc_t)xdr_%s, "
416*132Srobinson 				    "(caddr_t)%s%s)) != RPC_SUCCESS) {\n",
4170Sstevel@tonic-gate 				    RESULT,
4180Sstevel@tonic-gate 				    proc->proc_name,
4190Sstevel@tonic-gate 				    stringfix(proc->args.decls->decl.type),
4200Sstevel@tonic-gate 				    (newstyle ? "&" : ""),
4210Sstevel@tonic-gate 				    (newstyle ?
4220Sstevel@tonic-gate 					proc->args.decls->decl.name :
4230Sstevel@tonic-gate 					"argp"));
4240Sstevel@tonic-gate 			else
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate 				f_print(fout,
4270Sstevel@tonic-gate 				    "\treturn (clnt_send(clnt, "
428*132Srobinson 				    "%s,\n\t\t(xdrproc_t)xdr_%s, "
429*132Srobinson 				    "(caddr_t)%s%s));\n",
4300Sstevel@tonic-gate 				    proc->proc_name,
4310Sstevel@tonic-gate 				    stringfix(proc->args.decls->decl.type),
4320Sstevel@tonic-gate 				    (newstyle ? "&" : ""),
4330Sstevel@tonic-gate 				    (newstyle ?
4340Sstevel@tonic-gate 					proc->args.decls->decl.name :
4350Sstevel@tonic-gate 					"argp"));
4360Sstevel@tonic-gate 		}
4370Sstevel@tonic-gate 		if (!mtflag) {
4380Sstevel@tonic-gate 			f_print(fout, "\t\treturn (NULL);\n");
4390Sstevel@tonic-gate 			f_print(fout, "\t}\n");
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 			f_print(fout, "\treturn ((void *)&%s);\n",
4420Sstevel@tonic-gate 			    RESULT);
4430Sstevel@tonic-gate 		}
4440Sstevel@tonic-gate 	}
4450Sstevel@tonic-gate }
446