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 21*61961e0fSrobinson */ 22*61961e0fSrobinson 23*61961e0fSrobinson /* 24*61961e0fSrobinson * 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_clntout.c, Client-stub outputter for the RPC protocol compiler 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #include <stdio.h> 457c478bd9Sstevel@tonic-gate #include <string.h> 467c478bd9Sstevel@tonic-gate #include <rpc/types.h> 477c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 487c478bd9Sstevel@tonic-gate #include "rpc_util.h" 497c478bd9Sstevel@tonic-gate 50*61961e0fSrobinson extern void pdeclaration(char *, declaration *, int, char *); 51*61961e0fSrobinson extern void printarglist(proc_list *, char *, char *, char *); 527c478bd9Sstevel@tonic-gate 53*61961e0fSrobinson static void write_program(definition *); 54*61961e0fSrobinson static void printbody(proc_list *); 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate static char RESULT[] = "clnt_res"; 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #define DEFAULT_TIMEOUT 25 /* in seconds */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate void 61*61961e0fSrobinson write_stubs(void) 627c478bd9Sstevel@tonic-gate { 637c478bd9Sstevel@tonic-gate list *l; 647c478bd9Sstevel@tonic-gate definition *def; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate f_print(fout, 677c478bd9Sstevel@tonic-gate "\n/* Default timeout can be changed using clnt_control() */\n"); 687c478bd9Sstevel@tonic-gate f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n", 697c478bd9Sstevel@tonic-gate DEFAULT_TIMEOUT); 707c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 717c478bd9Sstevel@tonic-gate def = (definition *) l->val; 727c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) { 737c478bd9Sstevel@tonic-gate write_program(def); 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate } 777c478bd9Sstevel@tonic-gate 78*61961e0fSrobinson static void 79*61961e0fSrobinson write_program(definition *def) 807c478bd9Sstevel@tonic-gate { 817c478bd9Sstevel@tonic-gate version_list *vp; 827c478bd9Sstevel@tonic-gate proc_list *proc; 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 857c478bd9Sstevel@tonic-gate for (proc = vp->procs; proc != NULL; proc = proc->next) { 867c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 877c478bd9Sstevel@tonic-gate if (mtflag == 0) { 887c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 897c478bd9Sstevel@tonic-gate f_print(fout, "*\n"); 907c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 917c478bd9Sstevel@tonic-gate printarglist(proc, RESULT, "clnt", "CLIENT *"); 927c478bd9Sstevel@tonic-gate } else { 937c478bd9Sstevel@tonic-gate f_print(fout, "enum clnt_stat \n"); 947c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 957c478bd9Sstevel@tonic-gate printarglist(proc, RESULT, "clnt", "CLIENT *"); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate f_print(fout, "{\n"); 997c478bd9Sstevel@tonic-gate printbody(proc); 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate f_print(fout, "}\n"); 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate } 1047c478bd9Sstevel@tonic-gate } 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Writes out declarations of procedure's argument list. 1087c478bd9Sstevel@tonic-gate * In either ANSI C style, in one of old rpcgen style (pass by reference), 1097c478bd9Sstevel@tonic-gate * or new rpcgen style (multiple arguments, pass by value); 1107c478bd9Sstevel@tonic-gate */ 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */ 1137c478bd9Sstevel@tonic-gate 114*61961e0fSrobinson void 115*61961e0fSrobinson printarglist(proc_list *proc, char *result, char *addargname, char *addargtype) 1167c478bd9Sstevel@tonic-gate { 1177c478bd9Sstevel@tonic-gate bool_t oneway = streq(proc->res_type, "oneway"); 1187c478bd9Sstevel@tonic-gate decl_list *l; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate if (!newstyle) { 1217c478bd9Sstevel@tonic-gate /* old style: always pass argument by reference */ 1227c478bd9Sstevel@tonic-gate if (Cflag) { /* C++ style heading */ 1237c478bd9Sstevel@tonic-gate f_print(fout, "("); 1247c478bd9Sstevel@tonic-gate ptype(proc->args.decls->decl.prefix, 1257c478bd9Sstevel@tonic-gate proc->args.decls->decl.type, 1); 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate if (mtflag) { /* Generate result field */ 1287c478bd9Sstevel@tonic-gate f_print(fout, "*argp, "); 1297c478bd9Sstevel@tonic-gate if (!oneway) { 1307c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, 1317c478bd9Sstevel@tonic-gate proc->res_type, 1); 1327c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", 1357c478bd9Sstevel@tonic-gate addargtype, addargname); 1367c478bd9Sstevel@tonic-gate } else 137*61961e0fSrobinson f_print(fout, "*argp, %s%s)\n", 138*61961e0fSrobinson addargtype, addargname); 1397c478bd9Sstevel@tonic-gate } else { 1407c478bd9Sstevel@tonic-gate if (!mtflag) 1417c478bd9Sstevel@tonic-gate f_print(fout, "(argp, %s)\n", addargname); 1427c478bd9Sstevel@tonic-gate else { 1437c478bd9Sstevel@tonic-gate f_print(fout, "(argp, "); 1447c478bd9Sstevel@tonic-gate if (!oneway) { 1457c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", 1467c478bd9Sstevel@tonic-gate result); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate f_print(fout, "%s)\n", 1497c478bd9Sstevel@tonic-gate addargname); 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 1527c478bd9Sstevel@tonic-gate ptype(proc->args.decls->decl.prefix, 1537c478bd9Sstevel@tonic-gate proc->args.decls->decl.type, 1); 1547c478bd9Sstevel@tonic-gate f_print(fout, "*argp;\n"); 1557c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 1567c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 1577c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 1587c478bd9Sstevel@tonic-gate f_print(fout, "*%s;\n", result); 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate } 1617c478bd9Sstevel@tonic-gate } else if (streq(proc->args.decls->decl.type, "void")) { 1627c478bd9Sstevel@tonic-gate /* newstyle, 0 argument */ 1637c478bd9Sstevel@tonic-gate if (mtflag) { 1647c478bd9Sstevel@tonic-gate f_print(fout, "("); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate if (Cflag) { 1677c478bd9Sstevel@tonic-gate if (!oneway) { 1687c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, 1697c478bd9Sstevel@tonic-gate proc->res_type, 1); 1707c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", 1737c478bd9Sstevel@tonic-gate addargtype, addargname); 1747c478bd9Sstevel@tonic-gate } else 1757c478bd9Sstevel@tonic-gate f_print(fout, "(%s)\n", addargname); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate } else 1787c478bd9Sstevel@tonic-gate if (Cflag) 1797c478bd9Sstevel@tonic-gate f_print(fout, "(%s%s)\n", addargtype, addargname); 1807c478bd9Sstevel@tonic-gate else 1817c478bd9Sstevel@tonic-gate f_print(fout, "(%s)\n", addargname); 1827c478bd9Sstevel@tonic-gate } else { 1837c478bd9Sstevel@tonic-gate /* new style, 1 or multiple arguments */ 1847c478bd9Sstevel@tonic-gate if (!Cflag) { 1857c478bd9Sstevel@tonic-gate f_print(fout, "("); 1867c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) 1877c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", l->decl.name); 1887c478bd9Sstevel@tonic-gate if (mtflag && !oneway) 1897c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", result); 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate f_print(fout, "%s)\n", addargname); 1927c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 1937c478bd9Sstevel@tonic-gate pdeclaration(proc->args.argname, 1947c478bd9Sstevel@tonic-gate &l->decl, 1, ";\n"); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 1977c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 1987c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 1997c478bd9Sstevel@tonic-gate f_print(fout, "*%s;\n", result); 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate } else { /* C++ style header */ 2037c478bd9Sstevel@tonic-gate f_print(fout, "("); 2047c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 2057c478bd9Sstevel@tonic-gate pdeclaration(proc->args.argname, &l->decl, 0, 2067c478bd9Sstevel@tonic-gate ", "); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 2097c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 2107c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", addargtype, addargname); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate if (!Cflag) 2187c478bd9Sstevel@tonic-gate f_print(fout, "\t%s%s;\n", addargtype, addargname); 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate static char * 224*61961e0fSrobinson ampr(char *type) 2257c478bd9Sstevel@tonic-gate { 2267c478bd9Sstevel@tonic-gate if (isvectordef(type, REL_ALIAS)) { 2277c478bd9Sstevel@tonic-gate return (""); 2287c478bd9Sstevel@tonic-gate } else { 2297c478bd9Sstevel@tonic-gate return ("&"); 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 233*61961e0fSrobinson static void 234*61961e0fSrobinson printbody(proc_list *proc) 2357c478bd9Sstevel@tonic-gate { 2367c478bd9Sstevel@tonic-gate decl_list *l; 2377c478bd9Sstevel@tonic-gate bool_t args2 = (proc->arg_num > 1); 2387c478bd9Sstevel@tonic-gate bool_t oneway = streq(proc->res_type, "oneway"); 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /* 2417c478bd9Sstevel@tonic-gate * For new style with multiple arguments, need a structure in which 2427c478bd9Sstevel@tonic-gate * to stuff the arguments. 2437c478bd9Sstevel@tonic-gate */ 2447c478bd9Sstevel@tonic-gate if (newstyle && args2) { 2457c478bd9Sstevel@tonic-gate f_print(fout, "\t%s", proc->args.argname); 2467c478bd9Sstevel@tonic-gate f_print(fout, " arg;\n"); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate if (!oneway) { 2497c478bd9Sstevel@tonic-gate if (!mtflag) { 2507c478bd9Sstevel@tonic-gate f_print(fout, "\tstatic "); 2517c478bd9Sstevel@tonic-gate if (streq(proc->res_type, "void")) { 2527c478bd9Sstevel@tonic-gate f_print(fout, "char "); 2537c478bd9Sstevel@tonic-gate } else { 2547c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 0); 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate f_print(fout, "%s;\n", RESULT); 2577c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 2587c478bd9Sstevel@tonic-gate f_print(fout, 259*61961e0fSrobinson "\t(void) memset(%s%s, 0, sizeof (%s));\n", 2607c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT, RESULT); 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate if (newstyle && !args2 && 2647c478bd9Sstevel@tonic-gate (streq(proc->args.decls->decl.type, "void"))) { 2657c478bd9Sstevel@tonic-gate /* newstyle, 0 arguments */ 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (mtflag) 2687c478bd9Sstevel@tonic-gate f_print(fout, "\t return "); 2697c478bd9Sstevel@tonic-gate else 2707c478bd9Sstevel@tonic-gate f_print(fout, "\t if "); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate f_print(fout, 2737c478bd9Sstevel@tonic-gate "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ", 2747c478bd9Sstevel@tonic-gate proc->proc_name); 2757c478bd9Sstevel@tonic-gate f_print(fout, 276*61961e0fSrobinson "NULL,\n\t\t(xdrproc_t)xdr_%s, " 2777c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,", 2787c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 2797c478bd9Sstevel@tonic-gate (mtflag)?"":ampr(proc->res_type), 2807c478bd9Sstevel@tonic-gate RESULT); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate if (mtflag) 2837c478bd9Sstevel@tonic-gate f_print(fout, "\n\t\tTIMEOUT));\n"); 2847c478bd9Sstevel@tonic-gate else 2857c478bd9Sstevel@tonic-gate f_print(fout, 2867c478bd9Sstevel@tonic-gate "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate } else if (newstyle && args2) { 2897c478bd9Sstevel@tonic-gate /* 2907c478bd9Sstevel@tonic-gate * Newstyle, multiple arguments 2917c478bd9Sstevel@tonic-gate * stuff arguments into structure 2927c478bd9Sstevel@tonic-gate */ 2937c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 2947c478bd9Sstevel@tonic-gate f_print(fout, "\targ.%s = %s;\n", 2957c478bd9Sstevel@tonic-gate l->decl.name, l->decl.name); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate if (mtflag) 2987c478bd9Sstevel@tonic-gate f_print(fout, "\treturn "); 2997c478bd9Sstevel@tonic-gate else 3007c478bd9Sstevel@tonic-gate f_print(fout, "\tif "); 3017c478bd9Sstevel@tonic-gate f_print(fout, 3027c478bd9Sstevel@tonic-gate "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_%s", 3037c478bd9Sstevel@tonic-gate proc->proc_name, proc->args.argname); 3047c478bd9Sstevel@tonic-gate f_print(fout, 3057c478bd9Sstevel@tonic-gate ", (caddr_t)&arg,\n\t\t(xdrproc_t)xdr_%s, " 3067c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,", 3077c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 3087c478bd9Sstevel@tonic-gate (mtflag)?"":ampr(proc->res_type), 3097c478bd9Sstevel@tonic-gate RESULT); 3107c478bd9Sstevel@tonic-gate if (mtflag) 3117c478bd9Sstevel@tonic-gate f_print(fout, "\n\t\tTIMEOUT));\n"); 3127c478bd9Sstevel@tonic-gate else 3137c478bd9Sstevel@tonic-gate f_print(fout, 3147c478bd9Sstevel@tonic-gate "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); 3157c478bd9Sstevel@tonic-gate } else { /* single argument, new or old style */ 3167c478bd9Sstevel@tonic-gate if (!mtflag) 3177c478bd9Sstevel@tonic-gate f_print(fout, 3187c478bd9Sstevel@tonic-gate "\tif (clnt_call(clnt, " 3197c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 3207c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, " 3217c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\tTIMEOUT) != " 3227c478bd9Sstevel@tonic-gate "RPC_SUCCESS) {\n", 3237c478bd9Sstevel@tonic-gate proc->proc_name, 3247c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 3257c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 3267c478bd9Sstevel@tonic-gate (newstyle ? 3277c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 3287c478bd9Sstevel@tonic-gate "argp"), 3297c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 3307c478bd9Sstevel@tonic-gate ampr(proc->res_type), 3317c478bd9Sstevel@tonic-gate RESULT); 3327c478bd9Sstevel@tonic-gate else 3337c478bd9Sstevel@tonic-gate f_print(fout, 3347c478bd9Sstevel@tonic-gate "\treturn (clnt_call(clnt, " 3357c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 3367c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, " 3377c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\tTIMEOUT));\n", 3387c478bd9Sstevel@tonic-gate proc->proc_name, 3397c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 3407c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 3417c478bd9Sstevel@tonic-gate (newstyle ? 3427c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 3437c478bd9Sstevel@tonic-gate "argp"), 3447c478bd9Sstevel@tonic-gate stringfix(proc->res_type), "", 3457c478bd9Sstevel@tonic-gate RESULT); 3467c478bd9Sstevel@tonic-gate } 3477c478bd9Sstevel@tonic-gate if (!mtflag) { 3487c478bd9Sstevel@tonic-gate f_print(fout, "\t\treturn (NULL);\n"); 3497c478bd9Sstevel@tonic-gate f_print(fout, "\t}\n"); 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate if (streq(proc->res_type, "void")) { 3527c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ((void *)%s%s);\n", 3537c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT); 3547c478bd9Sstevel@tonic-gate } else { 3557c478bd9Sstevel@tonic-gate f_print(fout, "\treturn (%s%s);\n", 3567c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate } 3597c478bd9Sstevel@tonic-gate } else { 3607c478bd9Sstevel@tonic-gate /* oneway call */ 3617c478bd9Sstevel@tonic-gate if (!mtflag) { 3627c478bd9Sstevel@tonic-gate f_print(fout, "\tstatic enum clnt_stat "); 3637c478bd9Sstevel@tonic-gate f_print(fout, "%s;\n", RESULT); 3647c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 3657c478bd9Sstevel@tonic-gate f_print(fout, 366*61961e0fSrobinson "\t(void) memset(&%s, 0, sizeof (%s));\n", 3677c478bd9Sstevel@tonic-gate RESULT, RESULT); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate if (newstyle && !args2 && 3717c478bd9Sstevel@tonic-gate (streq(proc->args.decls->decl.type, "void"))) { 3727c478bd9Sstevel@tonic-gate /* newstyle, 0 arguments */ 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate if (mtflag) 3757c478bd9Sstevel@tonic-gate f_print(fout, "\t return ("); 3767c478bd9Sstevel@tonic-gate else 3777c478bd9Sstevel@tonic-gate f_print(fout, "\t if ((%s = ", RESULT); 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate f_print(fout, 3807c478bd9Sstevel@tonic-gate "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ", 3817c478bd9Sstevel@tonic-gate proc->proc_name); 382*61961e0fSrobinson f_print(fout, "NULL)"); 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate if (mtflag) 3857c478bd9Sstevel@tonic-gate f_print(fout, ");\n"); 3867c478bd9Sstevel@tonic-gate else 3877c478bd9Sstevel@tonic-gate f_print(fout, ") != RPC_SUCCESS) {\n"); 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate } else if (newstyle && args2) { 3907c478bd9Sstevel@tonic-gate /* 3917c478bd9Sstevel@tonic-gate * Newstyle, multiple arguments 3927c478bd9Sstevel@tonic-gate * stuff arguments into structure 3937c478bd9Sstevel@tonic-gate */ 3947c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 3957c478bd9Sstevel@tonic-gate f_print(fout, "\targ.%s = %s;\n", 3967c478bd9Sstevel@tonic-gate l->decl.name, l->decl.name); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate if (mtflag) 3997c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ("); 4007c478bd9Sstevel@tonic-gate else 4017c478bd9Sstevel@tonic-gate f_print(fout, "\tif ((%s =", RESULT); 4027c478bd9Sstevel@tonic-gate f_print(fout, 4037c478bd9Sstevel@tonic-gate "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_%s", 4047c478bd9Sstevel@tonic-gate proc->proc_name, proc->args.argname); 4057c478bd9Sstevel@tonic-gate f_print(fout, 4067c478bd9Sstevel@tonic-gate ", (caddr_t)&arg)"); 4077c478bd9Sstevel@tonic-gate if (mtflag) 4087c478bd9Sstevel@tonic-gate f_print(fout, ");\n"); 4097c478bd9Sstevel@tonic-gate else 4107c478bd9Sstevel@tonic-gate f_print(fout, ") != RPC_SUCCESS) {\n"); 4117c478bd9Sstevel@tonic-gate } else { /* single argument, new or old style */ 4127c478bd9Sstevel@tonic-gate if (!mtflag) 4137c478bd9Sstevel@tonic-gate f_print(fout, 4147c478bd9Sstevel@tonic-gate "\tif ((%s = clnt_send(clnt, " 4157c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 4167c478bd9Sstevel@tonic-gate "(caddr_t)%s%s)) != RPC_SUCCESS) {\n", 4177c478bd9Sstevel@tonic-gate RESULT, 4187c478bd9Sstevel@tonic-gate proc->proc_name, 4197c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 4207c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 4217c478bd9Sstevel@tonic-gate (newstyle ? 4227c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 4237c478bd9Sstevel@tonic-gate "argp")); 4247c478bd9Sstevel@tonic-gate else 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate f_print(fout, 4277c478bd9Sstevel@tonic-gate "\treturn (clnt_send(clnt, " 4287c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 4297c478bd9Sstevel@tonic-gate "(caddr_t)%s%s));\n", 4307c478bd9Sstevel@tonic-gate proc->proc_name, 4317c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 4327c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 4337c478bd9Sstevel@tonic-gate (newstyle ? 4347c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 4357c478bd9Sstevel@tonic-gate "argp")); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate if (!mtflag) { 4387c478bd9Sstevel@tonic-gate f_print(fout, "\t\treturn (NULL);\n"); 4397c478bd9Sstevel@tonic-gate f_print(fout, "\t}\n"); 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ((void *)&%s);\n", 4427c478bd9Sstevel@tonic-gate RESULT); 4437c478bd9Sstevel@tonic-gate } 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate } 446