Add __libc_accept as alias.
[glibc/history.git] / sunrpc / rpc_sample.c
bloba5551d94c133322be6d0497da554515c705d5c29
1 /*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user or with the express written consent of
8 * Sun Microsystems, Inc.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
31 /*
32 * From: @(#)rpc_sample.c 1.1 90/08/30 (C) 1987 SMI
34 char sample_rcsid[] =
35 "$Id$";
38 * rpc_sample.c, Sample client-server code outputter for the RPC protocol compiler
41 #include <stdio.h>
42 #include <string.h>
43 #include "rpc_parse.h"
44 #include "rpc_util.h"
45 #include "proto.h"
48 static char RQSTP[] = "rqstp";
50 static void write_sample_client(const char *program_name, version_list *vp);
51 static void write_sample_server(definition *def);
52 static void return_type(proc_list *plist);
55 void
56 write_sample_svc(definition *def)
59 if (def->def_kind != DEF_PROGRAM)
60 return;
61 write_sample_server(def);
65 int
66 write_sample_clnt(definition *def)
68 version_list *vp;
69 int count = 0;
71 if (def->def_kind != DEF_PROGRAM)
72 return( 0 );
73 /* generate sample code for each version */
74 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
75 write_sample_client(def->def_name, vp );
76 ++count;
78 return( count );
82 static void
83 write_sample_client(const char *program_name, version_list *vp)
85 proc_list *proc;
86 int i;
87 decl_list *l;
89 f_print(fout, "\n\nvoid\n" );
90 pvname( program_name, vp->vers_num );
91 if( Cflag )
92 f_print(fout,"( char* host )\n{\n" );
93 else
94 f_print(fout, "(host)\nchar *host;\n{\n" );
95 f_print(fout, "\tCLIENT *clnt;\n");
97 i = 0;
98 for (proc = vp->procs; proc != NULL; proc = proc->next) {
99 f_print(fout, "\t");
100 ptype(proc->res_prefix, proc->res_type, 1);
101 f_print(fout, " *result_%d;\n",++i);
102 /* print out declarations for arguments */
103 if( proc->arg_num < 2 && !newstyle) {
104 f_print( fout, "\t" );
105 if( !streq( proc->args.decls->decl.type, "void") )
106 ptype(proc->args.decls->decl.prefix, proc->args.decls->decl.type, 1);
107 else
108 f_print(fout, "char* "); /* cannot have "void" type */
109 f_print(fout, " ");
110 pvname( proc->proc_name, vp->vers_num );
111 f_print(fout, "_arg;\n");
112 } else if (!streq( proc->args.decls->decl.type, "void")) {
113 for (l = proc->args.decls; l != NULL; l = l->next) {
114 f_print( fout, "\t" );
115 ptype(l->decl.prefix, l->decl.type, 1);
116 f_print( fout, " ");
117 pvname( proc->proc_name, vp->vers_num );
118 f_print(fout, "_%s;\n", l->decl.name );
119 /* pdeclaration(proc->args.argname, &l->decl, 1, ";\n" );*/
124 /* generate creation of client handle */
125 f_print(fout, "\tclnt = clnt_create(host, %s, %s, \"%s\");\n",
126 program_name, vp->vers_name, tirpcflag? "netpath" : "udp");
127 f_print(fout, "\tif (clnt == NULL) {\n");
128 f_print(fout, "\t\tclnt_pcreateerror(host);\n");
129 f_print(fout, "\t\texit(1);\n\t}\n");
131 /* generate calls to procedures */
132 i = 0;
133 for (proc = vp->procs; proc != NULL; proc = proc->next) {
134 f_print(fout, "\tresult_%d = ",++i);
135 pvname(proc->proc_name, vp->vers_num);
136 if (proc->arg_num < 2 && !newstyle) {
137 f_print(fout, "(" );
138 if( streq( proc->args.decls->decl.type, "void") ) /* cast to void* */
139 f_print(fout, "(void*)");
140 f_print(fout, "&" );
141 pvname(proc->proc_name, vp->vers_num );
142 f_print(fout, "_arg, clnt);\n");
143 } else if (streq( proc->args.decls->decl.type, "void")) {
144 f_print(fout, "(clnt);\n");
146 else {
147 f_print(fout, "(");
148 for (l = proc->args.decls; l != NULL; l = l->next) {
149 pvname( proc->proc_name, vp->vers_num );
150 f_print(fout, "_%s, ", l->decl.name);
152 f_print(fout, "clnt);\n");
154 f_print(fout, "\tif (result_%d == NULL) {\n", i);
155 f_print(fout, "\t\tclnt_perror(clnt, \"call failed:\");\n");
156 f_print(fout, "\t}\n");
159 f_print(fout, "\tclnt_destroy( clnt );\n" );
160 f_print(fout, "}\n");
163 static void
164 write_sample_server(definition *def)
166 version_list *vp;
167 proc_list *proc;
169 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
170 for (proc = vp->procs; proc != NULL; proc = proc->next) {
171 f_print(fout, "\n");
172 /* if( Cflag )
173 f_print( fout, "extern \"C\"{\n");
175 return_type(proc);
176 f_print(fout, "* \n");
177 if( Cflag )
178 pvname_svc(proc->proc_name, vp->vers_num);
179 else
180 pvname(proc->proc_name, vp->vers_num);
181 printarglist( proc, RQSTP, "struct svc_req *" );
183 f_print(fout, "{\n");
184 f_print(fout, "\n\tstatic ");
185 if( !streq( proc->res_type, "void") )
186 return_type(proc);
187 else
188 f_print(fout, "char*" ); /* cannot have void type */
189 f_print(fout, " result;\n" /*, proc->res_type*/ /*?*/);
190 f_print(fout,
191 "\n\t/*\n\t * insert server code here\n\t */\n\n");
192 if( !streq( proc->res_type, "void") )
193 f_print(fout, "\treturn(&result);\n}\n");
194 else /* cast back to void * */
195 f_print(fout, "\treturn((void*) &result);\n}\n");
196 /* if( Cflag)
197 f_print( fout, "};\n");
206 static void
207 return_type(proc_list *plist)
209 ptype( plist->res_prefix, plist->res_type, 1 );
212 void
213 add_sample_msg(void)
215 f_print(fout, "/*\n");
216 f_print(fout, " * This is sample code generated by rpcgen.\n");
217 f_print(fout, " * These are only templates and you can use them\n");
218 f_print(fout, " * as a guideline for developing your own functions.\n");
219 f_print(fout, " */\n\n");
222 void
223 write_sample_clnt_main(void)
225 list *l;
226 definition *def;
227 version_list *vp;
229 f_print(fout, "\n\n" );
230 if( Cflag )
231 f_print(fout,"main( int argc, char* argv[] )\n{\n" );
232 else
233 f_print(fout, "main(argc, argv)\nint argc;\nchar *argv[];\n{\n" );
235 f_print(fout, "\tchar *host;");
236 f_print(fout, "\n\n\tif(argc < 2) {");
237 f_print(fout, "\n\t\tprintf(\"usage: %%s server_host\\n\", argv[0]);\n" );
238 f_print(fout, "\t\texit(1);\n\t}");
239 f_print(fout, "\n\thost = argv[1];\n");
241 for (l = defined; l != NULL; l = l->next) {
242 def = l->val;
243 if (def->def_kind != DEF_PROGRAM) {
244 continue;
246 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next) {
247 f_print( fout, "\t" );
248 pvname(def->def_name, vp->vers_num);
249 f_print( fout, "( host );\n" );
252 f_print(fout, "}\n");