3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28 /*
29 * University Copyright- Copyright (c) 1982, 1986, 1988
30 * The Regents of the University of California
31 * All Rights Reserved
32 *
33 * University Acknowledgment- Portions of this document are derived from
34 * software developed by the University of California, Berkeley, and its
35 * contributors.
36 */
37
38 /*
39 * rpc_hout.c, Header file outputter for the RPC protocol compiler
40 */
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <ctype.h>
44 #include "rpc_parse.h"
45 #include "rpc_util.h"
46
47 extern void pprocdef(proc_list *, version_list *, char *, int, int);
48 extern void pdeclaration(char *, declaration *, int, char *);
49
50 static void storexdrfuncdecl(char *, int);
51 static void pconstdef(definition *);
52 static void pstructdef(definition *);
53 static void puniondef(definition *);
54 static void pdefine(char *, char *);
55 static void pprogramdef(definition *);
56 static void parglist(proc_list *, char *);
57 static void penumdef(definition *);
58 static void ptypedef(definition *);
59 static uint_t undefined2(char *, char *);
60
61 enum rpc_gvc {
62 PROGRAM,
63 VERSION,
64 PROCEDURE
65 };
66
67 /*
122 xdrfunc *xdrptr;
123
124 xdrptr = malloc(sizeof (struct xdrfunc));
125
126 xdrptr->name = name;
127 xdrptr->pointerp = pointerp;
128 xdrptr->next = NULL;
129
130 if (xdrfunc_tail == NULL) {
131 xdrfunc_head = xdrptr;
132 xdrfunc_tail = xdrptr;
133 } else {
134 xdrfunc_tail->next = xdrptr;
135 xdrfunc_tail = xdrptr;
136 }
137
138
139 }
140
141 void
142 print_xdr_func_def(char *name, int pointerp, int i)
143 {
144 if (i == 2)
145 f_print(fout, "extern bool_t xdr_%s();\n", name);
146 else
147 f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name,
148 name, pointerp ? "*" : "");
149 }
150
151
152 static void
153 pconstdef(definition *def)
154 {
155 pdefine(def->def_name, def->def.co);
156 }
157
158 /*
159 * print out the definitions for the arguments of functions in the
160 * header file
161 */
162 static void
163 pargdef(definition *def)
164 {
165 decl_list *l;
166 version_list *vers;
245
246 static uint_t
247 define_printed(proc_list *stop, version_list *start)
248 {
249 version_list *vers;
250 proc_list *proc;
251
252 for (vers = start; vers != NULL; vers = vers->next) {
253 for (proc = vers->procs; proc != NULL; proc = proc->next) {
254 if (proc == stop)
255 return (0);
256 if (streq(proc->proc_name, stop->proc_name))
257 return (1);
258 }
259 }
260 abort();
261 /* NOTREACHED */
262 }
263
264 static void
265 pfreeprocdef(char *name, char *vers, int mode)
266 {
267 f_print(fout, "extern int ");
268 pvname(name, vers);
269 if (mode == 1)
270 f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
271 else
272 f_print(fout, "_freeresult();\n");
273 }
274
275 static void
276 pprogramdef(definition *def)
277 {
278 version_list *vers;
279 proc_list *proc;
280 int i;
281 char *ext;
282
283 pargdef(def);
284
285 puldefine(def->def_name, def->def.pr.prog_num, PROGRAM);
286 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
287 if (tblflag) {
288 f_print(fout,
289 "extern struct rpcgen_table %s_%s_table[];\n",
290 locase(def->def_name), vers->vers_num);
291 f_print(fout,
292 "extern int %s_%s_nproc;\n",
293 locase(def->def_name), vers->vers_num);
294 }
295 puldefine(vers->vers_name, vers->vers_num, VERSION);
296
297 /*
298 * Print out 2 definitions, one for ANSI-C, another for
299 * old K & R C
300 */
301
302 if (!Cflag) {
303 ext = "extern ";
304 for (proc = vers->procs; proc != NULL;
305 proc = proc->next) {
306 if (!define_printed(proc, def->def.pr.versions))
307 puldefine(proc->proc_name,
308 proc->proc_num, PROCEDURE);
309 f_print(fout, "%s", ext);
310 pprocdef(proc, vers, NULL, 0, 2);
311
312 if (mtflag) {
313 f_print(fout, "%s", ext);
314 pprocdef(proc, vers, NULL, 1, 2);
315 }
316 }
317 pfreeprocdef(def->def_name, vers->vers_num, 2);
318 } else {
319 for (i = 1; i < 3; i++) {
320 if (i == 1) {
321 f_print(fout, "\n#if defined(__STDC__)"
322 " || defined(__cplusplus)\n");
323 ext = "extern ";
324 } else {
325 f_print(fout, "\n#else /* K&R C */\n");
326 ext = "extern ";
327 }
328
329 for (proc = vers->procs; proc != NULL;
330 proc = proc->next) {
331 if (!define_printed(proc,
332 def->def.pr.versions)) {
333 puldefine(proc->proc_name,
334 proc->proc_num, PROCEDURE);
335 }
336 f_print(fout, "%s", ext);
337 pprocdef(proc, vers, "CLIENT *", 0, i);
338 f_print(fout, "%s", ext);
339 pprocdef(proc, vers,
340 "struct svc_req *", 1, i);
341 }
342 pfreeprocdef(def->def_name, vers->vers_num, i);
343 }
344 f_print(fout, "#endif /* K&R C */\n");
345 }
346 }
347 }
348
349 void
350 pprocdef(proc_list *proc, version_list *vp, char *addargtype, int server_p,
351 int mode)
352 {
353 if (mtflag) {
354 /* Print MT style stubs */
355 if (server_p)
356 f_print(fout, "bool_t ");
357 else
358 f_print(fout, "enum clnt_stat ");
359 } else {
360 ptype(proc->res_prefix, proc->res_type, 1);
361 f_print(fout, "* ");
362 }
363 if (server_p)
364 pvname_svc(proc->proc_name, vp->vers_num);
365 else
366 pvname(proc->proc_name, vp->vers_num);
367
368 /*
369 * mode 1 = ANSI-C, mode 2 = K&R C
370 */
371 if (mode == 1)
372 parglist(proc, addargtype);
373 else
374 f_print(fout, "();\n");
375 }
376
377 /* print out argument list of procedure */
378 static void
379 parglist(proc_list *proc, char *addargtype)
380 {
381 decl_list *dl;
382 int oneway = streq(proc->res_type, "oneway");
383
384 f_print(fout, "(");
385 if (proc->arg_num < 2 && newstyle &&
386 streq(proc->args.decls->decl.type, "void")) {
387 /* 0 argument in new style: do nothing */
388 /* EMPTY */
389 } else {
390 for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
391 ptype(dl->decl.prefix, dl->decl.type, 1);
392 if (!newstyle || (dl->decl.rel == REL_POINTER))
393 f_print(fout, "*");
394 /* old style passes by reference */
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
24 *
25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
27 */
28 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
29 /* All Rights Reserved */
30 /*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40 /*
41 * rpc_hout.c, Header file outputter for the RPC protocol compiler
42 */
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <ctype.h>
46 #include "rpc_parse.h"
47 #include "rpc_util.h"
48
49 extern void pprocdef(proc_list *, version_list *, char *, int);
50 extern void pdeclaration(char *, declaration *, int, char *);
51
52 static void storexdrfuncdecl(char *, int);
53 static void pconstdef(definition *);
54 static void pstructdef(definition *);
55 static void puniondef(definition *);
56 static void pdefine(char *, char *);
57 static void pprogramdef(definition *);
58 static void parglist(proc_list *, char *);
59 static void penumdef(definition *);
60 static void ptypedef(definition *);
61 static uint_t undefined2(char *, char *);
62
63 enum rpc_gvc {
64 PROGRAM,
65 VERSION,
66 PROCEDURE
67 };
68
69 /*
124 xdrfunc *xdrptr;
125
126 xdrptr = malloc(sizeof (struct xdrfunc));
127
128 xdrptr->name = name;
129 xdrptr->pointerp = pointerp;
130 xdrptr->next = NULL;
131
132 if (xdrfunc_tail == NULL) {
133 xdrfunc_head = xdrptr;
134 xdrfunc_tail = xdrptr;
135 } else {
136 xdrfunc_tail->next = xdrptr;
137 xdrfunc_tail = xdrptr;
138 }
139
140
141 }
142
143 void
144 print_xdr_func_def(char *name, int pointerp)
145 {
146 f_print(fout, "extern bool_t xdr_%s(XDR *, %s%s);\n", name,
147 name, pointerp ? "*" : "");
148 }
149
150
151 static void
152 pconstdef(definition *def)
153 {
154 pdefine(def->def_name, def->def.co);
155 }
156
157 /*
158 * print out the definitions for the arguments of functions in the
159 * header file
160 */
161 static void
162 pargdef(definition *def)
163 {
164 decl_list *l;
165 version_list *vers;
244
245 static uint_t
246 define_printed(proc_list *stop, version_list *start)
247 {
248 version_list *vers;
249 proc_list *proc;
250
251 for (vers = start; vers != NULL; vers = vers->next) {
252 for (proc = vers->procs; proc != NULL; proc = proc->next) {
253 if (proc == stop)
254 return (0);
255 if (streq(proc->proc_name, stop->proc_name))
256 return (1);
257 }
258 }
259 abort();
260 /* NOTREACHED */
261 }
262
263 static void
264 pfreeprocdef(char *name, char *vers)
265 {
266 f_print(fout, "extern int ");
267 pvname(name, vers);
268 f_print(fout, "_freeresult(SVCXPRT *, xdrproc_t, caddr_t);\n");
269 }
270
271 static void
272 pprogramdef(definition *def)
273 {
274 version_list *vers;
275 proc_list *proc;
276
277 pargdef(def);
278
279 puldefine(def->def_name, def->def.pr.prog_num, PROGRAM);
280 for (vers = def->def.pr.versions; vers != NULL; vers = vers->next) {
281 if (tblflag) {
282 f_print(fout,
283 "extern struct rpcgen_table %s_%s_table[];\n",
284 locase(def->def_name), vers->vers_num);
285 f_print(fout,
286 "extern int %s_%s_nproc;\n",
287 locase(def->def_name), vers->vers_num);
288 }
289 puldefine(vers->vers_name, vers->vers_num, VERSION);
290
291 for (proc = vers->procs; proc != NULL;
292 proc = proc->next) {
293 if (!define_printed(proc,
294 def->def.pr.versions)) {
295 puldefine(proc->proc_name,
296 proc->proc_num, PROCEDURE);
297 }
298 f_print(fout, "extern ");
299 pprocdef(proc, vers, "CLIENT *", 0);
300 f_print(fout, "extern ");
301 pprocdef(proc, vers, "struct svc_req *", 1);
302 }
303 pfreeprocdef(def->def_name, vers->vers_num);
304 }
305 }
306
307 void
308 pprocdef(proc_list *proc, version_list *vp, char *addargtype, int server_p)
309 {
310 if (mtflag) {
311 /* Print MT style stubs */
312 if (server_p)
313 f_print(fout, "bool_t ");
314 else
315 f_print(fout, "enum clnt_stat ");
316 } else {
317 ptype(proc->res_prefix, proc->res_type, 1);
318 f_print(fout, "* ");
319 }
320 if (server_p)
321 pvname_svc(proc->proc_name, vp->vers_num);
322 else
323 pvname(proc->proc_name, vp->vers_num);
324
325 parglist(proc, addargtype);
326 }
327
328 /* print out argument list of procedure */
329 static void
330 parglist(proc_list *proc, char *addargtype)
331 {
332 decl_list *dl;
333 int oneway = streq(proc->res_type, "oneway");
334
335 f_print(fout, "(");
336 if (proc->arg_num < 2 && newstyle &&
337 streq(proc->args.decls->decl.type, "void")) {
338 /* 0 argument in new style: do nothing */
339 /* EMPTY */
340 } else {
341 for (dl = proc->args.decls; dl != NULL; dl = dl->next) {
342 ptype(dl->decl.prefix, dl->decl.type, 1);
343 if (!newstyle || (dl->decl.rel == REL_POINTER))
344 f_print(fout, "*");
345 /* old style passes by reference */
|