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 5*a2f144d1SJordan Brown * Common Development and Distribution License (the "License"). 6*a2f144d1SJordan Brown * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 2061961e0fSrobinson */ 2161961e0fSrobinson 2261961e0fSrobinson /* 23*a2f144d1SJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 307c478bd9Sstevel@tonic-gate * The Regents of the University of California 317c478bd9Sstevel@tonic-gate * All Rights Reserved 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 357c478bd9Sstevel@tonic-gate * contributors. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate #include <stdio.h> 427c478bd9Sstevel@tonic-gate #include <string.h> 437c478bd9Sstevel@tonic-gate #include <rpc/types.h> 447c478bd9Sstevel@tonic-gate #include "rpc_parse.h" 457c478bd9Sstevel@tonic-gate #include "rpc_util.h" 467c478bd9Sstevel@tonic-gate 4761961e0fSrobinson extern void pdeclaration(char *, declaration *, int, char *); 4861961e0fSrobinson extern void printarglist(proc_list *, char *, char *, char *); 497c478bd9Sstevel@tonic-gate 5061961e0fSrobinson static void write_program(definition *); 5161961e0fSrobinson static void printbody(proc_list *); 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate static char RESULT[] = "clnt_res"; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate #define DEFAULT_TIMEOUT 25 /* in seconds */ 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate void 5861961e0fSrobinson write_stubs(void) 597c478bd9Sstevel@tonic-gate { 607c478bd9Sstevel@tonic-gate list *l; 617c478bd9Sstevel@tonic-gate definition *def; 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate f_print(fout, 647c478bd9Sstevel@tonic-gate "\n/* Default timeout can be changed using clnt_control() */\n"); 657c478bd9Sstevel@tonic-gate f_print(fout, "static struct timeval TIMEOUT = { %d, 0 };\n", 667c478bd9Sstevel@tonic-gate DEFAULT_TIMEOUT); 677c478bd9Sstevel@tonic-gate for (l = defined; l != NULL; l = l->next) { 687c478bd9Sstevel@tonic-gate def = (definition *) l->val; 697c478bd9Sstevel@tonic-gate if (def->def_kind == DEF_PROGRAM) { 707c478bd9Sstevel@tonic-gate write_program(def); 717c478bd9Sstevel@tonic-gate } 727c478bd9Sstevel@tonic-gate } 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate 7561961e0fSrobinson static void 7661961e0fSrobinson write_program(definition *def) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate version_list *vp; 797c478bd9Sstevel@tonic-gate proc_list *proc; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) { 827c478bd9Sstevel@tonic-gate for (proc = vp->procs; proc != NULL; proc = proc->next) { 837c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 847c478bd9Sstevel@tonic-gate if (mtflag == 0) { 857c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 867c478bd9Sstevel@tonic-gate f_print(fout, "*\n"); 877c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 887c478bd9Sstevel@tonic-gate printarglist(proc, RESULT, "clnt", "CLIENT *"); 897c478bd9Sstevel@tonic-gate } else { 907c478bd9Sstevel@tonic-gate f_print(fout, "enum clnt_stat \n"); 917c478bd9Sstevel@tonic-gate pvname(proc->proc_name, vp->vers_num); 927c478bd9Sstevel@tonic-gate printarglist(proc, RESULT, "clnt", "CLIENT *"); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate } 957c478bd9Sstevel@tonic-gate f_print(fout, "{\n"); 967c478bd9Sstevel@tonic-gate printbody(proc); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate f_print(fout, "}\n"); 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate } 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* 1047c478bd9Sstevel@tonic-gate * Writes out declarations of procedure's argument list. 1057c478bd9Sstevel@tonic-gate * In either ANSI C style, in one of old rpcgen style (pass by reference), 1067c478bd9Sstevel@tonic-gate * or new rpcgen style (multiple arguments, pass by value); 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */ 1107c478bd9Sstevel@tonic-gate 11161961e0fSrobinson void 11261961e0fSrobinson printarglist(proc_list *proc, char *result, char *addargname, char *addargtype) 1137c478bd9Sstevel@tonic-gate { 1147c478bd9Sstevel@tonic-gate bool_t oneway = streq(proc->res_type, "oneway"); 1157c478bd9Sstevel@tonic-gate decl_list *l; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate if (!newstyle) { 1187c478bd9Sstevel@tonic-gate /* old style: always pass argument by reference */ 1197c478bd9Sstevel@tonic-gate if (Cflag) { /* C++ style heading */ 1207c478bd9Sstevel@tonic-gate f_print(fout, "("); 1217c478bd9Sstevel@tonic-gate ptype(proc->args.decls->decl.prefix, 1227c478bd9Sstevel@tonic-gate proc->args.decls->decl.type, 1); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate if (mtflag) { /* Generate result field */ 1257c478bd9Sstevel@tonic-gate f_print(fout, "*argp, "); 1267c478bd9Sstevel@tonic-gate if (!oneway) { 1277c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, 1287c478bd9Sstevel@tonic-gate proc->res_type, 1); 1297c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 1307c478bd9Sstevel@tonic-gate } 1317c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", 1327c478bd9Sstevel@tonic-gate addargtype, addargname); 1337c478bd9Sstevel@tonic-gate } else 13461961e0fSrobinson f_print(fout, "*argp, %s%s)\n", 13561961e0fSrobinson addargtype, addargname); 1367c478bd9Sstevel@tonic-gate } else { 1377c478bd9Sstevel@tonic-gate if (!mtflag) 1387c478bd9Sstevel@tonic-gate f_print(fout, "(argp, %s)\n", addargname); 1397c478bd9Sstevel@tonic-gate else { 1407c478bd9Sstevel@tonic-gate f_print(fout, "(argp, "); 1417c478bd9Sstevel@tonic-gate if (!oneway) { 1427c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", 1437c478bd9Sstevel@tonic-gate result); 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate f_print(fout, "%s)\n", 1467c478bd9Sstevel@tonic-gate addargname); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 1497c478bd9Sstevel@tonic-gate ptype(proc->args.decls->decl.prefix, 1507c478bd9Sstevel@tonic-gate proc->args.decls->decl.type, 1); 1517c478bd9Sstevel@tonic-gate f_print(fout, "*argp;\n"); 1527c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 1537c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 1547c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 1557c478bd9Sstevel@tonic-gate f_print(fout, "*%s;\n", result); 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate } else if (streq(proc->args.decls->decl.type, "void")) { 1597c478bd9Sstevel@tonic-gate /* newstyle, 0 argument */ 1607c478bd9Sstevel@tonic-gate if (mtflag) { 1617c478bd9Sstevel@tonic-gate f_print(fout, "("); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate if (Cflag) { 1647c478bd9Sstevel@tonic-gate if (!oneway) { 1657c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, 1667c478bd9Sstevel@tonic-gate proc->res_type, 1); 1677c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", 1707c478bd9Sstevel@tonic-gate addargtype, addargname); 1717c478bd9Sstevel@tonic-gate } else 1727c478bd9Sstevel@tonic-gate f_print(fout, "(%s)\n", addargname); 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate } else 1757c478bd9Sstevel@tonic-gate if (Cflag) 1767c478bd9Sstevel@tonic-gate f_print(fout, "(%s%s)\n", addargtype, addargname); 1777c478bd9Sstevel@tonic-gate else 1787c478bd9Sstevel@tonic-gate f_print(fout, "(%s)\n", addargname); 1797c478bd9Sstevel@tonic-gate } else { 1807c478bd9Sstevel@tonic-gate /* new style, 1 or multiple arguments */ 1817c478bd9Sstevel@tonic-gate if (!Cflag) { 1827c478bd9Sstevel@tonic-gate f_print(fout, "("); 1837c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) 1847c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", l->decl.name); 1857c478bd9Sstevel@tonic-gate if (mtflag && !oneway) 1867c478bd9Sstevel@tonic-gate f_print(fout, "%s, ", result); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate f_print(fout, "%s)\n", addargname); 1897c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 1907c478bd9Sstevel@tonic-gate pdeclaration(proc->args.argname, 1917c478bd9Sstevel@tonic-gate &l->decl, 1, ";\n"); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 1947c478bd9Sstevel@tonic-gate f_print(fout, "\t"); 1957c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 1967c478bd9Sstevel@tonic-gate f_print(fout, "*%s;\n", result); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate } else { /* C++ style header */ 2007c478bd9Sstevel@tonic-gate f_print(fout, "("); 2017c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 2027c478bd9Sstevel@tonic-gate pdeclaration(proc->args.argname, &l->decl, 0, 2037c478bd9Sstevel@tonic-gate ", "); 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate if (mtflag && !oneway) { 2067c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 1); 2077c478bd9Sstevel@tonic-gate f_print(fout, "*%s, ", result); 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate f_print(fout, "%s%s)\n", addargtype, addargname); 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate if (!Cflag) 2157c478bd9Sstevel@tonic-gate f_print(fout, "\t%s%s;\n", addargtype, addargname); 2167c478bd9Sstevel@tonic-gate } 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate static char * 22161961e0fSrobinson ampr(char *type) 2227c478bd9Sstevel@tonic-gate { 2237c478bd9Sstevel@tonic-gate if (isvectordef(type, REL_ALIAS)) { 2247c478bd9Sstevel@tonic-gate return (""); 2257c478bd9Sstevel@tonic-gate } else { 2267c478bd9Sstevel@tonic-gate return ("&"); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 23061961e0fSrobinson static void 23161961e0fSrobinson printbody(proc_list *proc) 2327c478bd9Sstevel@tonic-gate { 2337c478bd9Sstevel@tonic-gate decl_list *l; 2347c478bd9Sstevel@tonic-gate bool_t args2 = (proc->arg_num > 1); 2357c478bd9Sstevel@tonic-gate bool_t oneway = streq(proc->res_type, "oneway"); 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* 2387c478bd9Sstevel@tonic-gate * For new style with multiple arguments, need a structure in which 2397c478bd9Sstevel@tonic-gate * to stuff the arguments. 2407c478bd9Sstevel@tonic-gate */ 2417c478bd9Sstevel@tonic-gate if (newstyle && args2) { 2427c478bd9Sstevel@tonic-gate f_print(fout, "\t%s", proc->args.argname); 2437c478bd9Sstevel@tonic-gate f_print(fout, " arg;\n"); 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate if (!oneway) { 2467c478bd9Sstevel@tonic-gate if (!mtflag) { 2477c478bd9Sstevel@tonic-gate f_print(fout, "\tstatic "); 2487c478bd9Sstevel@tonic-gate if (streq(proc->res_type, "void")) { 2497c478bd9Sstevel@tonic-gate f_print(fout, "char "); 2507c478bd9Sstevel@tonic-gate } else { 2517c478bd9Sstevel@tonic-gate ptype(proc->res_prefix, proc->res_type, 0); 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate f_print(fout, "%s;\n", RESULT); 2547c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 2557c478bd9Sstevel@tonic-gate f_print(fout, 25661961e0fSrobinson "\t(void) memset(%s%s, 0, sizeof (%s));\n", 2577c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT, RESULT); 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate if (newstyle && !args2 && 2617c478bd9Sstevel@tonic-gate (streq(proc->args.decls->decl.type, "void"))) { 2627c478bd9Sstevel@tonic-gate /* newstyle, 0 arguments */ 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (mtflag) 2657c478bd9Sstevel@tonic-gate f_print(fout, "\t return "); 2667c478bd9Sstevel@tonic-gate else 2677c478bd9Sstevel@tonic-gate f_print(fout, "\t if "); 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate f_print(fout, 2707c478bd9Sstevel@tonic-gate "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ", 2717c478bd9Sstevel@tonic-gate proc->proc_name); 2727c478bd9Sstevel@tonic-gate f_print(fout, 27361961e0fSrobinson "NULL,\n\t\t(xdrproc_t)xdr_%s, " 2747c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,", 2757c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 2767c478bd9Sstevel@tonic-gate (mtflag)?"":ampr(proc->res_type), 2777c478bd9Sstevel@tonic-gate RESULT); 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate if (mtflag) 2807c478bd9Sstevel@tonic-gate f_print(fout, "\n\t\tTIMEOUT));\n"); 2817c478bd9Sstevel@tonic-gate else 2827c478bd9Sstevel@tonic-gate f_print(fout, 2837c478bd9Sstevel@tonic-gate "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate } else if (newstyle && args2) { 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * Newstyle, multiple arguments 2887c478bd9Sstevel@tonic-gate * stuff arguments into structure 2897c478bd9Sstevel@tonic-gate */ 2907c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 2917c478bd9Sstevel@tonic-gate f_print(fout, "\targ.%s = %s;\n", 2927c478bd9Sstevel@tonic-gate l->decl.name, l->decl.name); 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate if (mtflag) 2957c478bd9Sstevel@tonic-gate f_print(fout, "\treturn "); 2967c478bd9Sstevel@tonic-gate else 2977c478bd9Sstevel@tonic-gate f_print(fout, "\tif "); 2987c478bd9Sstevel@tonic-gate f_print(fout, 2997c478bd9Sstevel@tonic-gate "(clnt_call(clnt, %s,\n\t\t(xdrproc_t)xdr_%s", 3007c478bd9Sstevel@tonic-gate proc->proc_name, proc->args.argname); 3017c478bd9Sstevel@tonic-gate f_print(fout, 3027c478bd9Sstevel@tonic-gate ", (caddr_t)&arg,\n\t\t(xdrproc_t)xdr_%s, " 3037c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,", 3047c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 3057c478bd9Sstevel@tonic-gate (mtflag)?"":ampr(proc->res_type), 3067c478bd9Sstevel@tonic-gate RESULT); 3077c478bd9Sstevel@tonic-gate if (mtflag) 3087c478bd9Sstevel@tonic-gate f_print(fout, "\n\t\tTIMEOUT));\n"); 3097c478bd9Sstevel@tonic-gate else 3107c478bd9Sstevel@tonic-gate f_print(fout, 3117c478bd9Sstevel@tonic-gate "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n"); 3127c478bd9Sstevel@tonic-gate } else { /* single argument, new or old style */ 3137c478bd9Sstevel@tonic-gate if (!mtflag) 3147c478bd9Sstevel@tonic-gate f_print(fout, 3157c478bd9Sstevel@tonic-gate "\tif (clnt_call(clnt, " 3167c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 3177c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, " 3187c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\tTIMEOUT) != " 3197c478bd9Sstevel@tonic-gate "RPC_SUCCESS) {\n", 3207c478bd9Sstevel@tonic-gate proc->proc_name, 3217c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 3227c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 3237c478bd9Sstevel@tonic-gate (newstyle ? 3247c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 3257c478bd9Sstevel@tonic-gate "argp"), 3267c478bd9Sstevel@tonic-gate stringfix(proc->res_type), 3277c478bd9Sstevel@tonic-gate ampr(proc->res_type), 3287c478bd9Sstevel@tonic-gate RESULT); 3297c478bd9Sstevel@tonic-gate else 3307c478bd9Sstevel@tonic-gate f_print(fout, 3317c478bd9Sstevel@tonic-gate "\treturn (clnt_call(clnt, " 3327c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 3337c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\t(xdrproc_t)xdr_%s, " 3347c478bd9Sstevel@tonic-gate "(caddr_t)%s%s,\n\t\tTIMEOUT));\n", 3357c478bd9Sstevel@tonic-gate proc->proc_name, 3367c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 3377c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 3387c478bd9Sstevel@tonic-gate (newstyle ? 3397c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 3407c478bd9Sstevel@tonic-gate "argp"), 3417c478bd9Sstevel@tonic-gate stringfix(proc->res_type), "", 3427c478bd9Sstevel@tonic-gate RESULT); 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate if (!mtflag) { 3457c478bd9Sstevel@tonic-gate f_print(fout, "\t\treturn (NULL);\n"); 3467c478bd9Sstevel@tonic-gate f_print(fout, "\t}\n"); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if (streq(proc->res_type, "void")) { 3497c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ((void *)%s%s);\n", 3507c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT); 3517c478bd9Sstevel@tonic-gate } else { 3527c478bd9Sstevel@tonic-gate f_print(fout, "\treturn (%s%s);\n", 3537c478bd9Sstevel@tonic-gate ampr(proc->res_type), RESULT); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate } else { 3577c478bd9Sstevel@tonic-gate /* oneway call */ 3587c478bd9Sstevel@tonic-gate if (!mtflag) { 3597c478bd9Sstevel@tonic-gate f_print(fout, "\tstatic enum clnt_stat "); 3607c478bd9Sstevel@tonic-gate f_print(fout, "%s;\n", RESULT); 3617c478bd9Sstevel@tonic-gate f_print(fout, "\n"); 3627c478bd9Sstevel@tonic-gate f_print(fout, 36361961e0fSrobinson "\t(void) memset(&%s, 0, sizeof (%s));\n", 3647c478bd9Sstevel@tonic-gate RESULT, RESULT); 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate if (newstyle && !args2 && 3687c478bd9Sstevel@tonic-gate (streq(proc->args.decls->decl.type, "void"))) { 3697c478bd9Sstevel@tonic-gate /* newstyle, 0 arguments */ 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate if (mtflag) 3727c478bd9Sstevel@tonic-gate f_print(fout, "\t return ("); 3737c478bd9Sstevel@tonic-gate else 3747c478bd9Sstevel@tonic-gate f_print(fout, "\t if ((%s = ", RESULT); 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate f_print(fout, 3777c478bd9Sstevel@tonic-gate "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_void, ", 3787c478bd9Sstevel@tonic-gate proc->proc_name); 37961961e0fSrobinson f_print(fout, "NULL)"); 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate if (mtflag) 3827c478bd9Sstevel@tonic-gate f_print(fout, ");\n"); 3837c478bd9Sstevel@tonic-gate else 3847c478bd9Sstevel@tonic-gate f_print(fout, ") != RPC_SUCCESS) {\n"); 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate } else if (newstyle && args2) { 3877c478bd9Sstevel@tonic-gate /* 3887c478bd9Sstevel@tonic-gate * Newstyle, multiple arguments 3897c478bd9Sstevel@tonic-gate * stuff arguments into structure 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate for (l = proc->args.decls; l != NULL; l = l->next) { 3927c478bd9Sstevel@tonic-gate f_print(fout, "\targ.%s = %s;\n", 3937c478bd9Sstevel@tonic-gate l->decl.name, l->decl.name); 3947c478bd9Sstevel@tonic-gate } 3957c478bd9Sstevel@tonic-gate if (mtflag) 3967c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ("); 3977c478bd9Sstevel@tonic-gate else 3987c478bd9Sstevel@tonic-gate f_print(fout, "\tif ((%s =", RESULT); 3997c478bd9Sstevel@tonic-gate f_print(fout, 4007c478bd9Sstevel@tonic-gate "clnt_send(clnt, %s,\n\t\t(xdrproc_t)xdr_%s", 4017c478bd9Sstevel@tonic-gate proc->proc_name, proc->args.argname); 4027c478bd9Sstevel@tonic-gate f_print(fout, 4037c478bd9Sstevel@tonic-gate ", (caddr_t)&arg)"); 4047c478bd9Sstevel@tonic-gate if (mtflag) 4057c478bd9Sstevel@tonic-gate f_print(fout, ");\n"); 4067c478bd9Sstevel@tonic-gate else 4077c478bd9Sstevel@tonic-gate f_print(fout, ") != RPC_SUCCESS) {\n"); 4087c478bd9Sstevel@tonic-gate } else { /* single argument, new or old style */ 4097c478bd9Sstevel@tonic-gate if (!mtflag) 4107c478bd9Sstevel@tonic-gate f_print(fout, 4117c478bd9Sstevel@tonic-gate "\tif ((%s = clnt_send(clnt, " 4127c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 4137c478bd9Sstevel@tonic-gate "(caddr_t)%s%s)) != RPC_SUCCESS) {\n", 4147c478bd9Sstevel@tonic-gate RESULT, 4157c478bd9Sstevel@tonic-gate proc->proc_name, 4167c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 4177c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 4187c478bd9Sstevel@tonic-gate (newstyle ? 4197c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 4207c478bd9Sstevel@tonic-gate "argp")); 4217c478bd9Sstevel@tonic-gate else 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate f_print(fout, 4247c478bd9Sstevel@tonic-gate "\treturn (clnt_send(clnt, " 4257c478bd9Sstevel@tonic-gate "%s,\n\t\t(xdrproc_t)xdr_%s, " 4267c478bd9Sstevel@tonic-gate "(caddr_t)%s%s));\n", 4277c478bd9Sstevel@tonic-gate proc->proc_name, 4287c478bd9Sstevel@tonic-gate stringfix(proc->args.decls->decl.type), 4297c478bd9Sstevel@tonic-gate (newstyle ? "&" : ""), 4307c478bd9Sstevel@tonic-gate (newstyle ? 4317c478bd9Sstevel@tonic-gate proc->args.decls->decl.name : 4327c478bd9Sstevel@tonic-gate "argp")); 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate if (!mtflag) { 4357c478bd9Sstevel@tonic-gate f_print(fout, "\t\treturn (NULL);\n"); 4367c478bd9Sstevel@tonic-gate f_print(fout, "\t}\n"); 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate f_print(fout, "\treturn ((void *)&%s);\n", 4397c478bd9Sstevel@tonic-gate RESULT); 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate } 4427c478bd9Sstevel@tonic-gate } 443