xref: /titanic_44/usr/src/cmd/rpcgen/rpc_sample.c (revision 61961e0f20c7637a3846bb39786bb9dffa91dfb9)
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_sample.c, Sample client-server code outputter
437c478bd9Sstevel@tonic-gate  * for the RPC protocol compiler
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <stdio.h>
477c478bd9Sstevel@tonic-gate #include <string.h>
487c478bd9Sstevel@tonic-gate #include "rpc_parse.h"
497c478bd9Sstevel@tonic-gate #include "rpc_util.h"
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static char RQSTP[] = "rqstp";
537c478bd9Sstevel@tonic-gate 
54*61961e0fSrobinson extern void printarglist(proc_list *, char *, char *, char *);
55*61961e0fSrobinson 
56*61961e0fSrobinson static void write_sample_client(char *, version_list *);
57*61961e0fSrobinson static void write_sample_server(definition *);
58*61961e0fSrobinson static void return_type(proc_list *);
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate void
61*61961e0fSrobinson write_sample_svc(definition *def)
627c478bd9Sstevel@tonic-gate {
637c478bd9Sstevel@tonic-gate 	if (def->def_kind != DEF_PROGRAM)
647c478bd9Sstevel@tonic-gate 		return;
657c478bd9Sstevel@tonic-gate 	write_sample_server(def);
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate int
69*61961e0fSrobinson write_sample_clnt(definition *def)
707c478bd9Sstevel@tonic-gate {
717c478bd9Sstevel@tonic-gate 	version_list *vp;
727c478bd9Sstevel@tonic-gate 	int count = 0;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate 	if (def->def_kind != DEF_PROGRAM)
757c478bd9Sstevel@tonic-gate 		return (0);
767c478bd9Sstevel@tonic-gate 	/* generate sample code for each version */
777c478bd9Sstevel@tonic-gate 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
787c478bd9Sstevel@tonic-gate 		write_sample_client(def->def_name, vp);
797c478bd9Sstevel@tonic-gate 		++count;
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 	return (count);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate 
84*61961e0fSrobinson static void
85*61961e0fSrobinson write_sample_client(char *program_name, version_list *vp)
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate 	proc_list *proc;
887c478bd9Sstevel@tonic-gate 	int i;
897c478bd9Sstevel@tonic-gate 	decl_list *l;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\nvoid\n");
927c478bd9Sstevel@tonic-gate 	pvname(program_name, vp->vers_num);
937c478bd9Sstevel@tonic-gate 	if (Cflag)
947c478bd9Sstevel@tonic-gate 		f_print(fout, "(char *host)\n{\n");
957c478bd9Sstevel@tonic-gate 	else
967c478bd9Sstevel@tonic-gate 		f_print(fout, "(host)\n\tchar *host;\n{\n");
977c478bd9Sstevel@tonic-gate 	f_print(fout, "\tCLIENT *clnt;\n");
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	i = 0;
1007c478bd9Sstevel@tonic-gate 	for (proc = vp->procs; proc != NULL; proc = proc->next) {
1017c478bd9Sstevel@tonic-gate 		f_print(fout, "\t");
1027c478bd9Sstevel@tonic-gate 		if (mtflag) {
1037c478bd9Sstevel@tonic-gate 			f_print(fout, "enum clnt_stat retval_%d;\n", ++i);
1047c478bd9Sstevel@tonic-gate 			if (!streq(proc->res_type, "oneway")) {
1057c478bd9Sstevel@tonic-gate 				f_print(fout, "\t");
1067c478bd9Sstevel@tonic-gate 				if (!streq(proc->res_type, "void"))
1077c478bd9Sstevel@tonic-gate 					ptype(proc->res_prefix,
1087c478bd9Sstevel@tonic-gate 					    proc->res_type, 1);
1097c478bd9Sstevel@tonic-gate 				else
1107c478bd9Sstevel@tonic-gate 					f_print(fout, "void *");
1117c478bd9Sstevel@tonic-gate 				f_print(fout, "result_%d;\n", i);
1127c478bd9Sstevel@tonic-gate 			}
1137c478bd9Sstevel@tonic-gate 		} else {
1147c478bd9Sstevel@tonic-gate 			ptype(proc->res_prefix, proc->res_type, 1);
1157c478bd9Sstevel@tonic-gate 			f_print(fout, " *result_%d;\n", ++i);
1167c478bd9Sstevel@tonic-gate 		}
1177c478bd9Sstevel@tonic-gate 		/* print out declarations for arguments */
1187c478bd9Sstevel@tonic-gate 		if (proc->arg_num < 2 && !newstyle) {
1197c478bd9Sstevel@tonic-gate 			f_print(fout, "\t");
1207c478bd9Sstevel@tonic-gate 			if (!streq(proc->args.decls->decl.type, "void"))
1217c478bd9Sstevel@tonic-gate 				ptype(proc->args.decls->decl.prefix,
1227c478bd9Sstevel@tonic-gate 					proc->args.decls->decl.type, 1);
1237c478bd9Sstevel@tonic-gate 			else
1247c478bd9Sstevel@tonic-gate 				/* cannot have "void" type */
1257c478bd9Sstevel@tonic-gate 				f_print(fout, "char * ");
1267c478bd9Sstevel@tonic-gate 			f_print(fout, " ");
1277c478bd9Sstevel@tonic-gate 			pvname(proc->proc_name, vp->vers_num);
1287c478bd9Sstevel@tonic-gate 			f_print(fout, "_arg;\n");
1297c478bd9Sstevel@tonic-gate 		} else if (!streq(proc->args.decls->decl.type, "void")) {
1307c478bd9Sstevel@tonic-gate 			for (l = proc->args.decls; l != NULL; l = l->next) {
1317c478bd9Sstevel@tonic-gate 				f_print(fout, "\t");
1327c478bd9Sstevel@tonic-gate 				ptype(l->decl.prefix, l->decl.type, 1);
1337c478bd9Sstevel@tonic-gate 				if (strcmp(l->decl.type, "string") == 1)
1347c478bd9Sstevel@tonic-gate 				    f_print(fout, " ");
1357c478bd9Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
1367c478bd9Sstevel@tonic-gate 				f_print(fout, "_%s;\n", l->decl.name);
1377c478bd9Sstevel@tonic-gate 			}
1387c478bd9Sstevel@tonic-gate 		}
1397c478bd9Sstevel@tonic-gate 	}
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	/* generate creation of client handle */
1427c478bd9Sstevel@tonic-gate 	f_print(fout, "\n#ifndef\tDEBUG\n");
1437c478bd9Sstevel@tonic-gate 	f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n",
1447c478bd9Sstevel@tonic-gate 		program_name, vp->vers_name, tirpcflag? "netpath" : "udp");
1457c478bd9Sstevel@tonic-gate 	f_print(fout, "\tif (clnt == (CLIENT *) NULL) {\n");
1467c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\tclnt_pcreateerror(host);\n");
1477c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\texit(1);\n\t}\n");
1487c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif\t/* DEBUG */\n\n");
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	/* generate calls to procedures */
1517c478bd9Sstevel@tonic-gate 	i = 0;
1527c478bd9Sstevel@tonic-gate 	for (proc = vp->procs; proc != NULL; proc = proc->next) {
1537c478bd9Sstevel@tonic-gate 		if (mtflag)
1547c478bd9Sstevel@tonic-gate 			f_print(fout, "\tretval_%d = ", ++i);
1557c478bd9Sstevel@tonic-gate 		else
1567c478bd9Sstevel@tonic-gate 			f_print(fout, "\tresult_%d = ", ++i);
1577c478bd9Sstevel@tonic-gate 		pvname(proc->proc_name, vp->vers_num);
1587c478bd9Sstevel@tonic-gate 		if (proc->arg_num < 2 && !newstyle) {
1597c478bd9Sstevel@tonic-gate 			f_print(fout, "(");
1607c478bd9Sstevel@tonic-gate 			if (streq(proc->args.decls->decl.type, "void"))
1617c478bd9Sstevel@tonic-gate 				/* cast to void * */
1627c478bd9Sstevel@tonic-gate 				f_print(fout, "(void *)");
1637c478bd9Sstevel@tonic-gate 			f_print(fout, "&");
1647c478bd9Sstevel@tonic-gate 			pvname(proc->proc_name, vp->vers_num);
1657c478bd9Sstevel@tonic-gate 			if (mtflag) {
166*61961e0fSrobinson 				if (streq(proc->res_type, "oneway"))
1677c478bd9Sstevel@tonic-gate 					f_print(fout, "_arg, clnt);\n");
168*61961e0fSrobinson 				else
1697c478bd9Sstevel@tonic-gate 					f_print(fout,
1707c478bd9Sstevel@tonic-gate 					    "_arg, &result_%d, clnt);\n", i);
1717c478bd9Sstevel@tonic-gate 			} else
1727c478bd9Sstevel@tonic-gate 				f_print(fout, "_arg, clnt);\n");
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 		} else if (streq(proc->args.decls->decl.type, "void")) {
1757c478bd9Sstevel@tonic-gate 			if (mtflag) {
176*61961e0fSrobinson 				if (streq(proc->res_type, "oneway"))
1777c478bd9Sstevel@tonic-gate 					f_print(fout, "(clnt);\n");
178*61961e0fSrobinson 				else
1797c478bd9Sstevel@tonic-gate 					f_print(fout,
1807c478bd9Sstevel@tonic-gate 					    "(&result_%d, clnt);\n", i);
1817c478bd9Sstevel@tonic-gate 			} else
1827c478bd9Sstevel@tonic-gate 				f_print(fout, "(clnt);\n");
1837c478bd9Sstevel@tonic-gate 		} else {
1847c478bd9Sstevel@tonic-gate 			f_print(fout, "(");
1857c478bd9Sstevel@tonic-gate 			for (l = proc->args.decls;  l != NULL; l = l->next) {
1867c478bd9Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
1877c478bd9Sstevel@tonic-gate 				f_print(fout, "_%s, ", l->decl.name);
1887c478bd9Sstevel@tonic-gate 			}
1897c478bd9Sstevel@tonic-gate 			if (mtflag) {
190*61961e0fSrobinson 				if (!streq(proc->res_type, "oneway"))
1917c478bd9Sstevel@tonic-gate 					f_print(fout, "&result_%d, ", i);
1927c478bd9Sstevel@tonic-gate 			}
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 			f_print(fout, "clnt);\n");
1957c478bd9Sstevel@tonic-gate 		}
1967c478bd9Sstevel@tonic-gate 		if (mtflag) {
1977c478bd9Sstevel@tonic-gate 			f_print(fout, "\tif (retval_%d != RPC_SUCCESS) {\n", i);
1987c478bd9Sstevel@tonic-gate 		} else {
1997c478bd9Sstevel@tonic-gate 			f_print(fout, "\tif (result_%d == (", i);
2007c478bd9Sstevel@tonic-gate 			ptype(proc->res_prefix, proc->res_type, 1);
2017c478bd9Sstevel@tonic-gate 			f_print(fout, "*) NULL) {\n");
2027c478bd9Sstevel@tonic-gate 		}
2037c478bd9Sstevel@tonic-gate 		f_print(fout, "\t\tclnt_perror(clnt, \"call failed\");\n");
2047c478bd9Sstevel@tonic-gate 		f_print(fout, "\t}\n");
2057c478bd9Sstevel@tonic-gate 	}
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	f_print(fout, "#ifndef\tDEBUG\n");
2087c478bd9Sstevel@tonic-gate 	f_print(fout, "\tclnt_destroy(clnt);\n");
2097c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif\t	/* DEBUG */\n");
2107c478bd9Sstevel@tonic-gate 	f_print(fout, "}\n");
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
213*61961e0fSrobinson static void
214*61961e0fSrobinson write_sample_server(definition *def)
2157c478bd9Sstevel@tonic-gate {
2167c478bd9Sstevel@tonic-gate 	version_list *vp;
2177c478bd9Sstevel@tonic-gate 	proc_list *proc;
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
2207c478bd9Sstevel@tonic-gate 		for (proc = vp->procs; proc != NULL; proc = proc->next) {
2217c478bd9Sstevel@tonic-gate 			f_print(fout, "\n");
2227c478bd9Sstevel@tonic-gate 			if (!mtflag) {
2237c478bd9Sstevel@tonic-gate 				return_type(proc);
2247c478bd9Sstevel@tonic-gate 				f_print(fout, "*\n");
2257c478bd9Sstevel@tonic-gate 			} else {
2267c478bd9Sstevel@tonic-gate 				f_print(fout, "bool_t\n");
2277c478bd9Sstevel@tonic-gate 			}
2287c478bd9Sstevel@tonic-gate 			if (Cflag || mtflag)
2297c478bd9Sstevel@tonic-gate 				pvname_svc(proc->proc_name, vp->vers_num);
2307c478bd9Sstevel@tonic-gate 			else
2317c478bd9Sstevel@tonic-gate 				pvname(proc->proc_name, vp->vers_num);
2327c478bd9Sstevel@tonic-gate 			printarglist(proc, "result", RQSTP, "struct svc_req *");
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 			f_print(fout, "{\n");
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 			if (!mtflag) {
2377c478bd9Sstevel@tonic-gate 				f_print(fout, "\tstatic ");
2387c478bd9Sstevel@tonic-gate 				if ((!streq(proc->res_type, "void")) &&
2397c478bd9Sstevel@tonic-gate 				    (!streq(proc->res_type, "oneway")))
2407c478bd9Sstevel@tonic-gate 					return_type(proc);
2417c478bd9Sstevel@tonic-gate 				else
2427c478bd9Sstevel@tonic-gate 					f_print(fout, "char *");
2437c478bd9Sstevel@tonic-gate 				/* cannot have void type */
244*61961e0fSrobinson 				f_print(fout, " result;\n");
2457c478bd9Sstevel@tonic-gate 			}
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate 			f_print(fout, "\n\t/*\n\t * insert server code "
2487c478bd9Sstevel@tonic-gate 						"here\n\t */\n\n");
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 			if (!mtflag)
2517c478bd9Sstevel@tonic-gate 				if (!streq(proc->res_type, "void"))
2527c478bd9Sstevel@tonic-gate 					f_print(fout,
2537c478bd9Sstevel@tonic-gate 					    "\treturn (&result);\n}\n");
2547c478bd9Sstevel@tonic-gate 				else /* cast back to void * */
2557c478bd9Sstevel@tonic-gate 					f_print(fout, "\treturn((void *) "
2567c478bd9Sstevel@tonic-gate 					    "&result);\n}\n");
2577c478bd9Sstevel@tonic-gate 			else
2587c478bd9Sstevel@tonic-gate 				f_print(fout, "\treturn (retval);\n}\n");
2597c478bd9Sstevel@tonic-gate 		}
2607c478bd9Sstevel@tonic-gate 		/* put in sample freeing routine */
2617c478bd9Sstevel@tonic-gate 		if (mtflag) {
2627c478bd9Sstevel@tonic-gate 			f_print(fout, "\nint\n");
2637c478bd9Sstevel@tonic-gate 			pvname(def->def_name, vp->vers_num);
2647c478bd9Sstevel@tonic-gate 			if (Cflag)
2657c478bd9Sstevel@tonic-gate 				f_print(fout, "_freeresult(SVCXPRT *transp,"
2667c478bd9Sstevel@tonic-gate 					" xdrproc_t xdr_result,"
2677c478bd9Sstevel@tonic-gate 					" caddr_t result)\n");
2687c478bd9Sstevel@tonic-gate 			else {
2697c478bd9Sstevel@tonic-gate 				f_print(fout, "_freeresult(transp, xdr_result,"
2707c478bd9Sstevel@tonic-gate 					" result)\n");
2717c478bd9Sstevel@tonic-gate 				f_print(fout, "\tSVCXPRT *transp;\n");
2727c478bd9Sstevel@tonic-gate 				f_print(fout, "\txdrproc_t xdr_result;\n");
2737c478bd9Sstevel@tonic-gate 				f_print(fout, "\tcaddr_t result;\n");
2747c478bd9Sstevel@tonic-gate 			}
2757c478bd9Sstevel@tonic-gate 			f_print(fout, "{\n"
2767c478bd9Sstevel@tonic-gate 				"\t(void) xdr_free(xdr_result, result);\n"
2777c478bd9Sstevel@tonic-gate 				"\n\t/*\n\t * Insert additional freeing"
2787c478bd9Sstevel@tonic-gate 				" code here, if needed\n\t */\n"
2797c478bd9Sstevel@tonic-gate 				"\n\n\treturn (TRUE);\n}\n");
2807c478bd9Sstevel@tonic-gate 		}
2817c478bd9Sstevel@tonic-gate 	}
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
284*61961e0fSrobinson static void
285*61961e0fSrobinson return_type(proc_list *plist)
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate 	ptype(plist->res_prefix, plist->res_type, 1);
2887c478bd9Sstevel@tonic-gate }
2897c478bd9Sstevel@tonic-gate 
290*61961e0fSrobinson void
291*61961e0fSrobinson add_sample_msg(void)
2927c478bd9Sstevel@tonic-gate {
2937c478bd9Sstevel@tonic-gate 	f_print(fout, "/*\n");
2947c478bd9Sstevel@tonic-gate 	f_print(fout, " * This is sample code generated by rpcgen.\n");
2957c478bd9Sstevel@tonic-gate 	f_print(fout, " * These are only templates and you can use them\n");
2967c478bd9Sstevel@tonic-gate 	f_print(fout, " * as a guideline for developing your own functions.\n");
2977c478bd9Sstevel@tonic-gate 	f_print(fout, " */\n\n");
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate void
301*61961e0fSrobinson write_sample_clnt_main(void)
3027c478bd9Sstevel@tonic-gate {
3037c478bd9Sstevel@tonic-gate 	list *l;
3047c478bd9Sstevel@tonic-gate 	definition *def;
3057c478bd9Sstevel@tonic-gate 	version_list *vp;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\n");
3087c478bd9Sstevel@tonic-gate 	if (Cflag)
309*61961e0fSrobinson 		f_print(fout, "int\nmain(int argc, char *argv[])\n{\n");
3107c478bd9Sstevel@tonic-gate 	else
311*61961e0fSrobinson 		f_print(fout, "int\nmain(argc, argv)\n\tint argc;\n"
3127c478bd9Sstevel@tonic-gate 			"\tchar *argv[];\n{\n");
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	f_print(fout, "\tchar *host;");
3157c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\n\tif (argc < 2) {");
3167c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\tprintf(\"usage:  %%s server_host\\n\","
3177c478bd9Sstevel@tonic-gate 			" argv[0]);\n");
3187c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\texit(1);\n\t}");
3197c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\thost = argv[1];\n");
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	for (l = defined; l != NULL; l = l->next) {
3227c478bd9Sstevel@tonic-gate 		def = l->val;
323*61961e0fSrobinson 		if (def->def_kind != DEF_PROGRAM)
3247c478bd9Sstevel@tonic-gate 			continue;
3257c478bd9Sstevel@tonic-gate 		for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
3267c478bd9Sstevel@tonic-gate 			f_print(fout, "\t");
3277c478bd9Sstevel@tonic-gate 			pvname(def->def_name, vp->vers_num);
3287c478bd9Sstevel@tonic-gate 			f_print(fout, "(host);\n");
3297c478bd9Sstevel@tonic-gate 		}
3307c478bd9Sstevel@tonic-gate 	}
3317c478bd9Sstevel@tonic-gate 	f_print(fout, "}\n");
3327c478bd9Sstevel@tonic-gate }
333