xref: /titanic_53/usr/src/cmd/rpcgen/rpc_sample.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  *
22*7c478bd9Sstevel@tonic-gate  * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
23*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*7c478bd9Sstevel@tonic-gate  */
25*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
29*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
30*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
33*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
34*7c478bd9Sstevel@tonic-gate  * contributors.
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /*
40*7c478bd9Sstevel@tonic-gate  * rpc_sample.c, Sample client-server code outputter
41*7c478bd9Sstevel@tonic-gate  * for the RPC protocol compiler
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include <stdio.h>
45*7c478bd9Sstevel@tonic-gate #include <string.h>
46*7c478bd9Sstevel@tonic-gate #include "rpc_parse.h"
47*7c478bd9Sstevel@tonic-gate #include "rpc_util.h"
48*7c478bd9Sstevel@tonic-gate 
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static char RQSTP[] = "rqstp";
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate void printarglist();
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate void
55*7c478bd9Sstevel@tonic-gate write_sample_svc(def)
56*7c478bd9Sstevel@tonic-gate 	definition *def;
57*7c478bd9Sstevel@tonic-gate {
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate 	if (def->def_kind != DEF_PROGRAM)
60*7c478bd9Sstevel@tonic-gate 		return;
61*7c478bd9Sstevel@tonic-gate 	write_sample_server(def);
62*7c478bd9Sstevel@tonic-gate }
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate int
66*7c478bd9Sstevel@tonic-gate write_sample_clnt(def)
67*7c478bd9Sstevel@tonic-gate 	definition *def;
68*7c478bd9Sstevel@tonic-gate {
69*7c478bd9Sstevel@tonic-gate 	version_list *vp;
70*7c478bd9Sstevel@tonic-gate 	int count = 0;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	if (def->def_kind != DEF_PROGRAM)
73*7c478bd9Sstevel@tonic-gate 		return (0);
74*7c478bd9Sstevel@tonic-gate 	/* generate sample code for each version */
75*7c478bd9Sstevel@tonic-gate 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
76*7c478bd9Sstevel@tonic-gate 		write_sample_client(def->def_name, vp);
77*7c478bd9Sstevel@tonic-gate 		++count;
78*7c478bd9Sstevel@tonic-gate 	}
79*7c478bd9Sstevel@tonic-gate 	return (count);
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate static
84*7c478bd9Sstevel@tonic-gate write_sample_client(program_name, vp)
85*7c478bd9Sstevel@tonic-gate 	char *program_name;
86*7c478bd9Sstevel@tonic-gate 	version_list *vp;
87*7c478bd9Sstevel@tonic-gate {
88*7c478bd9Sstevel@tonic-gate 	proc_list *proc;
89*7c478bd9Sstevel@tonic-gate 	int i;
90*7c478bd9Sstevel@tonic-gate 	decl_list *l;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\nvoid\n");
93*7c478bd9Sstevel@tonic-gate 	pvname(program_name, vp->vers_num);
94*7c478bd9Sstevel@tonic-gate 	if (Cflag)
95*7c478bd9Sstevel@tonic-gate 		f_print(fout, "(char *host)\n{\n");
96*7c478bd9Sstevel@tonic-gate 	else
97*7c478bd9Sstevel@tonic-gate 		f_print(fout, "(host)\n\tchar *host;\n{\n");
98*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tCLIENT *clnt;\n");
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	i = 0;
101*7c478bd9Sstevel@tonic-gate 	for (proc = vp->procs; proc != NULL; proc = proc->next) {
102*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t");
103*7c478bd9Sstevel@tonic-gate 		if (mtflag) {
104*7c478bd9Sstevel@tonic-gate 			f_print(fout, "enum clnt_stat retval_%d;\n", ++i);
105*7c478bd9Sstevel@tonic-gate 			if (!streq(proc->res_type, "oneway")) {
106*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\t");
107*7c478bd9Sstevel@tonic-gate 				if (!streq(proc->res_type, "void"))
108*7c478bd9Sstevel@tonic-gate 					ptype(proc->res_prefix,
109*7c478bd9Sstevel@tonic-gate 					    proc->res_type, 1);
110*7c478bd9Sstevel@tonic-gate 				else
111*7c478bd9Sstevel@tonic-gate 					f_print(fout, "void *");
112*7c478bd9Sstevel@tonic-gate 				f_print(fout, "result_%d;\n", i);
113*7c478bd9Sstevel@tonic-gate 			}
114*7c478bd9Sstevel@tonic-gate 		} else {
115*7c478bd9Sstevel@tonic-gate 			ptype(proc->res_prefix, proc->res_type, 1);
116*7c478bd9Sstevel@tonic-gate 			f_print(fout, " *result_%d;\n", ++i);
117*7c478bd9Sstevel@tonic-gate 		}
118*7c478bd9Sstevel@tonic-gate 		/* print out declarations for arguments */
119*7c478bd9Sstevel@tonic-gate 		if (proc->arg_num < 2 && !newstyle) {
120*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\t");
121*7c478bd9Sstevel@tonic-gate 			if (!streq(proc->args.decls->decl.type, "void"))
122*7c478bd9Sstevel@tonic-gate 				ptype(proc->args.decls->decl.prefix,
123*7c478bd9Sstevel@tonic-gate 					proc->args.decls->decl.type, 1);
124*7c478bd9Sstevel@tonic-gate 			else
125*7c478bd9Sstevel@tonic-gate 				/* cannot have "void" type */
126*7c478bd9Sstevel@tonic-gate 				f_print(fout, "char * ");
127*7c478bd9Sstevel@tonic-gate 			f_print(fout, " ");
128*7c478bd9Sstevel@tonic-gate 			pvname(proc->proc_name, vp->vers_num);
129*7c478bd9Sstevel@tonic-gate 			f_print(fout, "_arg;\n");
130*7c478bd9Sstevel@tonic-gate 		} else if (!streq(proc->args.decls->decl.type, "void")) {
131*7c478bd9Sstevel@tonic-gate 			for (l = proc->args.decls; l != NULL; l = l->next) {
132*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\t");
133*7c478bd9Sstevel@tonic-gate 				ptype(l->decl.prefix, l->decl.type, 1);
134*7c478bd9Sstevel@tonic-gate 				if (strcmp(l->decl.type, "string") == 1)
135*7c478bd9Sstevel@tonic-gate 				    f_print(fout, " ");
136*7c478bd9Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
137*7c478bd9Sstevel@tonic-gate 				f_print(fout, "_%s;\n", l->decl.name);
138*7c478bd9Sstevel@tonic-gate 			}
139*7c478bd9Sstevel@tonic-gate 		}
140*7c478bd9Sstevel@tonic-gate 	}
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 	/* generate creation of client handle */
143*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n#ifndef\tDEBUG\n");
144*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n",
145*7c478bd9Sstevel@tonic-gate 		program_name, vp->vers_name, tirpcflag? "netpath" : "udp");
146*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tif (clnt == (CLIENT *) NULL) {\n");
147*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\tclnt_pcreateerror(host);\n");
148*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\texit(1);\n\t}\n");
149*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif\t/* DEBUG */\n\n");
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate 	/* generate calls to procedures */
152*7c478bd9Sstevel@tonic-gate 	i = 0;
153*7c478bd9Sstevel@tonic-gate 	for (proc = vp->procs; proc != NULL; proc = proc->next) {
154*7c478bd9Sstevel@tonic-gate 		if (mtflag)
155*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\tretval_%d = ", ++i);
156*7c478bd9Sstevel@tonic-gate 		else
157*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\tresult_%d = ", ++i);
158*7c478bd9Sstevel@tonic-gate 		pvname(proc->proc_name, vp->vers_num);
159*7c478bd9Sstevel@tonic-gate 		if (proc->arg_num < 2 && !newstyle) {
160*7c478bd9Sstevel@tonic-gate 			f_print(fout, "(");
161*7c478bd9Sstevel@tonic-gate 			if (streq(proc->args.decls->decl.type, "void"))
162*7c478bd9Sstevel@tonic-gate 				/* cast to void * */
163*7c478bd9Sstevel@tonic-gate 				f_print(fout, "(void *)");
164*7c478bd9Sstevel@tonic-gate 			f_print(fout, "&");
165*7c478bd9Sstevel@tonic-gate 			pvname(proc->proc_name, vp->vers_num);
166*7c478bd9Sstevel@tonic-gate 			if (mtflag) {
167*7c478bd9Sstevel@tonic-gate 				if (streq(proc->res_type, "oneway")) {
168*7c478bd9Sstevel@tonic-gate 					f_print(fout, "_arg, clnt);\n");
169*7c478bd9Sstevel@tonic-gate 				} else {
170*7c478bd9Sstevel@tonic-gate 					f_print(fout,
171*7c478bd9Sstevel@tonic-gate 					    "_arg, &result_%d, clnt);\n", i);
172*7c478bd9Sstevel@tonic-gate 				}
173*7c478bd9Sstevel@tonic-gate 			} else
174*7c478bd9Sstevel@tonic-gate 				f_print(fout, "_arg, clnt);\n");
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate 		} else if (streq(proc->args.decls->decl.type, "void")) {
177*7c478bd9Sstevel@tonic-gate 			if (mtflag) {
178*7c478bd9Sstevel@tonic-gate 				if (streq(proc->res_type, "oneway")) {
179*7c478bd9Sstevel@tonic-gate 					f_print(fout, "(clnt);\n");
180*7c478bd9Sstevel@tonic-gate 				} else {
181*7c478bd9Sstevel@tonic-gate 					f_print(fout,
182*7c478bd9Sstevel@tonic-gate 					    "(&result_%d, clnt);\n", i);
183*7c478bd9Sstevel@tonic-gate 				}
184*7c478bd9Sstevel@tonic-gate 			} else
185*7c478bd9Sstevel@tonic-gate 				f_print(fout, "(clnt);\n");
186*7c478bd9Sstevel@tonic-gate 		} else {
187*7c478bd9Sstevel@tonic-gate 			f_print(fout, "(");
188*7c478bd9Sstevel@tonic-gate 			for (l = proc->args.decls;  l != NULL; l = l->next) {
189*7c478bd9Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
190*7c478bd9Sstevel@tonic-gate 				f_print(fout, "_%s, ", l->decl.name);
191*7c478bd9Sstevel@tonic-gate 			}
192*7c478bd9Sstevel@tonic-gate 			if (mtflag) {
193*7c478bd9Sstevel@tonic-gate 				if (!streq(proc->res_type, "oneway")) {
194*7c478bd9Sstevel@tonic-gate 					f_print(fout, "&result_%d, ", i);
195*7c478bd9Sstevel@tonic-gate 				}
196*7c478bd9Sstevel@tonic-gate 			}
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate 			f_print(fout, "clnt);\n");
199*7c478bd9Sstevel@tonic-gate 		}
200*7c478bd9Sstevel@tonic-gate 		if (mtflag) {
201*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\tif (retval_%d != RPC_SUCCESS) {\n", i);
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 		} else {
204*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\tif (result_%d == (", i);
205*7c478bd9Sstevel@tonic-gate 			ptype(proc->res_prefix, proc->res_type, 1);
206*7c478bd9Sstevel@tonic-gate 			f_print(fout, "*) NULL) {\n");
207*7c478bd9Sstevel@tonic-gate 		}
208*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t\tclnt_perror(clnt, \"call failed\");\n");
209*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t}\n");
210*7c478bd9Sstevel@tonic-gate 	}
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#ifndef\tDEBUG\n");
213*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tclnt_destroy(clnt);\n");
214*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif\t	/* DEBUG */\n");
215*7c478bd9Sstevel@tonic-gate 	f_print(fout, "}\n");
216*7c478bd9Sstevel@tonic-gate }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate static
219*7c478bd9Sstevel@tonic-gate write_sample_server(def)
220*7c478bd9Sstevel@tonic-gate 	definition *def;
221*7c478bd9Sstevel@tonic-gate {
222*7c478bd9Sstevel@tonic-gate 	version_list *vp;
223*7c478bd9Sstevel@tonic-gate 	proc_list *proc;
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
226*7c478bd9Sstevel@tonic-gate 		for (proc = vp->procs; proc != NULL; proc = proc->next) {
227*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\n");
228*7c478bd9Sstevel@tonic-gate 			if (!mtflag) {
229*7c478bd9Sstevel@tonic-gate 				return_type(proc);
230*7c478bd9Sstevel@tonic-gate 				f_print(fout, "*\n");
231*7c478bd9Sstevel@tonic-gate 			} else {
232*7c478bd9Sstevel@tonic-gate 				f_print(fout, "bool_t\n");
233*7c478bd9Sstevel@tonic-gate 			}
234*7c478bd9Sstevel@tonic-gate 			if (Cflag || mtflag)
235*7c478bd9Sstevel@tonic-gate 				pvname_svc(proc->proc_name, vp->vers_num);
236*7c478bd9Sstevel@tonic-gate 			else
237*7c478bd9Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
238*7c478bd9Sstevel@tonic-gate 			printarglist(proc, "result", RQSTP, "struct svc_req *");
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 			f_print(fout, "{\n");
241*7c478bd9Sstevel@tonic-gate 
242*7c478bd9Sstevel@tonic-gate 			if (!mtflag) {
243*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\tstatic ");
244*7c478bd9Sstevel@tonic-gate 				if ((!streq(proc->res_type, "void")) &&
245*7c478bd9Sstevel@tonic-gate 				    (!streq(proc->res_type, "oneway")))
246*7c478bd9Sstevel@tonic-gate 					return_type(proc);
247*7c478bd9Sstevel@tonic-gate 				else
248*7c478bd9Sstevel@tonic-gate 					f_print(fout, "char *");
249*7c478bd9Sstevel@tonic-gate 				/* cannot have void type */
250*7c478bd9Sstevel@tonic-gate 				f_print(fout, " result;\n",
251*7c478bd9Sstevel@tonic-gate 				    proc->res_type);
252*7c478bd9Sstevel@tonic-gate 			}
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\n\t/*\n\t * insert server code "
255*7c478bd9Sstevel@tonic-gate 						"here\n\t */\n\n");
256*7c478bd9Sstevel@tonic-gate 
257*7c478bd9Sstevel@tonic-gate 			if (!mtflag)
258*7c478bd9Sstevel@tonic-gate 				if (!streq(proc->res_type, "void"))
259*7c478bd9Sstevel@tonic-gate 					f_print(fout,
260*7c478bd9Sstevel@tonic-gate 					    "\treturn (&result);\n}\n");
261*7c478bd9Sstevel@tonic-gate 				else /* cast back to void * */
262*7c478bd9Sstevel@tonic-gate 					f_print(fout, "\treturn((void *) "
263*7c478bd9Sstevel@tonic-gate 					    "&result);\n}\n");
264*7c478bd9Sstevel@tonic-gate 			else
265*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\treturn (retval);\n}\n");
266*7c478bd9Sstevel@tonic-gate 		}
267*7c478bd9Sstevel@tonic-gate 		/* put in sample freeing routine */
268*7c478bd9Sstevel@tonic-gate 		if (mtflag) {
269*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\nint\n");
270*7c478bd9Sstevel@tonic-gate 			pvname(def->def_name, vp->vers_num);
271*7c478bd9Sstevel@tonic-gate 			if (Cflag)
272*7c478bd9Sstevel@tonic-gate 				f_print(fout, "_freeresult(SVCXPRT *transp,"
273*7c478bd9Sstevel@tonic-gate 					" xdrproc_t xdr_result,"
274*7c478bd9Sstevel@tonic-gate 					" caddr_t result)\n");
275*7c478bd9Sstevel@tonic-gate 			else {
276*7c478bd9Sstevel@tonic-gate 				f_print(fout, "_freeresult(transp, xdr_result,"
277*7c478bd9Sstevel@tonic-gate 					" result)\n");
278*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\tSVCXPRT *transp;\n");
279*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\txdrproc_t xdr_result;\n");
280*7c478bd9Sstevel@tonic-gate 				f_print(fout, "\tcaddr_t result;\n");
281*7c478bd9Sstevel@tonic-gate 			}
282*7c478bd9Sstevel@tonic-gate 			f_print(fout, "{\n"
283*7c478bd9Sstevel@tonic-gate 				"\t(void) xdr_free(xdr_result, result);\n"
284*7c478bd9Sstevel@tonic-gate 				"\n\t/*\n\t * Insert additional freeing"
285*7c478bd9Sstevel@tonic-gate 				" code here, if needed\n\t */\n"
286*7c478bd9Sstevel@tonic-gate 				"\n\n\treturn (TRUE);\n}\n");
287*7c478bd9Sstevel@tonic-gate 		}
288*7c478bd9Sstevel@tonic-gate 	}
289*7c478bd9Sstevel@tonic-gate }
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate static
294*7c478bd9Sstevel@tonic-gate return_type(plist)
295*7c478bd9Sstevel@tonic-gate 	proc_list *plist;
296*7c478bd9Sstevel@tonic-gate {
297*7c478bd9Sstevel@tonic-gate 	ptype(plist->res_prefix, plist->res_type, 1);
298*7c478bd9Sstevel@tonic-gate }
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate add_sample_msg()
301*7c478bd9Sstevel@tonic-gate {
302*7c478bd9Sstevel@tonic-gate 	f_print(fout, "/*\n");
303*7c478bd9Sstevel@tonic-gate 	f_print(fout, " * This is sample code generated by rpcgen.\n");
304*7c478bd9Sstevel@tonic-gate 	f_print(fout, " * These are only templates and you can use them\n");
305*7c478bd9Sstevel@tonic-gate 	f_print(fout, " * as a guideline for developing your own functions.\n");
306*7c478bd9Sstevel@tonic-gate 	f_print(fout, " */\n\n");
307*7c478bd9Sstevel@tonic-gate }
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate void
310*7c478bd9Sstevel@tonic-gate write_sample_clnt_main()
311*7c478bd9Sstevel@tonic-gate {
312*7c478bd9Sstevel@tonic-gate 	list *l;
313*7c478bd9Sstevel@tonic-gate 	definition *def;
314*7c478bd9Sstevel@tonic-gate 	version_list *vp;
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\n");
317*7c478bd9Sstevel@tonic-gate 	if (Cflag)
318*7c478bd9Sstevel@tonic-gate 		f_print(fout, "main(int argc, char *argv[])\n{\n");
319*7c478bd9Sstevel@tonic-gate 	else
320*7c478bd9Sstevel@tonic-gate 		f_print(fout, "main(argc, argv)\n\tint argc;\n"
321*7c478bd9Sstevel@tonic-gate 			"\tchar *argv[];\n{\n");
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tchar *host;");
324*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\n\tif (argc < 2) {");
325*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\tprintf(\"usage:  %%s server_host\\n\","
326*7c478bd9Sstevel@tonic-gate 			" argv[0]);\n");
327*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\texit(1);\n\t}");
328*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\thost = argv[1];\n");
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate 	for (l = defined; l != NULL; l = l->next) {
331*7c478bd9Sstevel@tonic-gate 		def = l->val;
332*7c478bd9Sstevel@tonic-gate 		if (def->def_kind != DEF_PROGRAM) {
333*7c478bd9Sstevel@tonic-gate 			continue;
334*7c478bd9Sstevel@tonic-gate 		}
335*7c478bd9Sstevel@tonic-gate 		for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
336*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\t");
337*7c478bd9Sstevel@tonic-gate 			pvname(def->def_name, vp->vers_num);
338*7c478bd9Sstevel@tonic-gate 			f_print(fout, "(host);\n");
339*7c478bd9Sstevel@tonic-gate 		}
340*7c478bd9Sstevel@tonic-gate 	}
341*7c478bd9Sstevel@tonic-gate 	f_print(fout, "}\n");
342*7c478bd9Sstevel@tonic-gate }
343