xref: /titanic_54/usr/src/cmd/rpcgen/rpc_cout.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 /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
30*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
31*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
32*7c478bd9Sstevel@tonic-gate  *
33*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
34*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
35*7c478bd9Sstevel@tonic-gate  * contributors.
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*
41*7c478bd9Sstevel@tonic-gate  * rpc_cout.c, XDR routine outputter for the RPC protocol compiler
42*7c478bd9Sstevel@tonic-gate  */
43*7c478bd9Sstevel@tonic-gate #include <stdio.h>
44*7c478bd9Sstevel@tonic-gate #include <string.h>
45*7c478bd9Sstevel@tonic-gate #include "rpc_parse.h"
46*7c478bd9Sstevel@tonic-gate #include "rpc_util.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate /*
49*7c478bd9Sstevel@tonic-gate  * Emit the C-routine for the given definition
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate void
52*7c478bd9Sstevel@tonic-gate emit(def)
53*7c478bd9Sstevel@tonic-gate 	definition *def;
54*7c478bd9Sstevel@tonic-gate {
55*7c478bd9Sstevel@tonic-gate 	if (def->def_kind == DEF_CONST) {
56*7c478bd9Sstevel@tonic-gate 		return;
57*7c478bd9Sstevel@tonic-gate 	}
58*7c478bd9Sstevel@tonic-gate 	if (def->def_kind == DEF_PROGRAM) {
59*7c478bd9Sstevel@tonic-gate 		emit_program(def);
60*7c478bd9Sstevel@tonic-gate 		return;
61*7c478bd9Sstevel@tonic-gate 	}
62*7c478bd9Sstevel@tonic-gate 	if (def->def_kind == DEF_TYPEDEF) {
63*7c478bd9Sstevel@tonic-gate 		/*
64*7c478bd9Sstevel@tonic-gate 		 * now we need to handle declarations like
65*7c478bd9Sstevel@tonic-gate 		 * struct typedef foo foo;
66*7c478bd9Sstevel@tonic-gate 		 * since we dont want this to be expanded into 2 calls
67*7c478bd9Sstevel@tonic-gate 		 * to xdr_foo
68*7c478bd9Sstevel@tonic-gate 		 */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 		if (strcmp(def->def.ty.old_type, def->def_name) == 0)
71*7c478bd9Sstevel@tonic-gate 			return;
72*7c478bd9Sstevel@tonic-gate 	};
73*7c478bd9Sstevel@tonic-gate 	print_header(def);
74*7c478bd9Sstevel@tonic-gate 	switch (def->def_kind) {
75*7c478bd9Sstevel@tonic-gate 	case DEF_UNION:
76*7c478bd9Sstevel@tonic-gate 		emit_union(def);
77*7c478bd9Sstevel@tonic-gate 		break;
78*7c478bd9Sstevel@tonic-gate 	case DEF_ENUM:
79*7c478bd9Sstevel@tonic-gate 		emit_enum(def);
80*7c478bd9Sstevel@tonic-gate 		break;
81*7c478bd9Sstevel@tonic-gate 	case DEF_STRUCT:
82*7c478bd9Sstevel@tonic-gate 		emit_struct(def);
83*7c478bd9Sstevel@tonic-gate 		break;
84*7c478bd9Sstevel@tonic-gate 	case DEF_TYPEDEF:
85*7c478bd9Sstevel@tonic-gate 		emit_typedef(def);
86*7c478bd9Sstevel@tonic-gate 		break;
87*7c478bd9Sstevel@tonic-gate 	}
88*7c478bd9Sstevel@tonic-gate 	print_trailer();
89*7c478bd9Sstevel@tonic-gate }
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate static
92*7c478bd9Sstevel@tonic-gate findtype(def, type)
93*7c478bd9Sstevel@tonic-gate 	definition *def;
94*7c478bd9Sstevel@tonic-gate 	char *type;
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate 	if (def->def_kind == DEF_PROGRAM || def->def_kind == DEF_CONST) {
98*7c478bd9Sstevel@tonic-gate 		return (0);
99*7c478bd9Sstevel@tonic-gate 	} else {
100*7c478bd9Sstevel@tonic-gate 		return (streq(def->def_name, type));
101*7c478bd9Sstevel@tonic-gate 	}
102*7c478bd9Sstevel@tonic-gate }
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate static
105*7c478bd9Sstevel@tonic-gate undefined(type)
106*7c478bd9Sstevel@tonic-gate 	char *type;
107*7c478bd9Sstevel@tonic-gate {
108*7c478bd9Sstevel@tonic-gate 	definition *def;
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	def = (definition *) FINDVAL(defined, type, findtype);
111*7c478bd9Sstevel@tonic-gate 	return (def == NULL);
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate static
116*7c478bd9Sstevel@tonic-gate print_generic_header(procname, pointerp)
117*7c478bd9Sstevel@tonic-gate     char *procname;
118*7c478bd9Sstevel@tonic-gate     int pointerp;
119*7c478bd9Sstevel@tonic-gate {
120*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n");
121*7c478bd9Sstevel@tonic-gate 	f_print(fout, "bool_t\n");
122*7c478bd9Sstevel@tonic-gate 	if (Cflag) {
123*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "xdr_%s(", procname);
124*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "register XDR *xdrs, ");
125*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "%s ", procname);
126*7c478bd9Sstevel@tonic-gate 	    if (pointerp)
127*7c478bd9Sstevel@tonic-gate 		    f_print(fout, "*");
128*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "objp)\n{\n\n");
129*7c478bd9Sstevel@tonic-gate 	} else {
130*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "xdr_%s(xdrs, objp)\n", procname);
131*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "\tregister XDR *xdrs;\n");
132*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "\t%s ", procname);
133*7c478bd9Sstevel@tonic-gate 	    if (pointerp)
134*7c478bd9Sstevel@tonic-gate 		    f_print(fout, "*");
135*7c478bd9Sstevel@tonic-gate 	    f_print(fout, "objp;\n{\n\n");
136*7c478bd9Sstevel@tonic-gate 	}
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate static
140*7c478bd9Sstevel@tonic-gate print_header(def)
141*7c478bd9Sstevel@tonic-gate 	definition *def;
142*7c478bd9Sstevel@tonic-gate {
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 	decl_list *dl;
145*7c478bd9Sstevel@tonic-gate 	bas_type *ptr;
146*7c478bd9Sstevel@tonic-gate 	int i;
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate 	print_generic_header(def->def_name,
149*7c478bd9Sstevel@tonic-gate 			    def->def_kind != DEF_TYPEDEF ||
150*7c478bd9Sstevel@tonic-gate 			    !isvectordef(def->def.ty.old_type,
151*7c478bd9Sstevel@tonic-gate 					def->def.ty.rel));
152*7c478bd9Sstevel@tonic-gate 	/* Now add Inline support */
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 	if (inlinelen == 0)
155*7c478bd9Sstevel@tonic-gate 		return;
156*7c478bd9Sstevel@tonic-gate 	/* May cause lint to complain. but  ... */
157*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#if defined(_LP64) || defined(_KERNEL)\n");
158*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tregister int *buf;\n");
159*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#else\n");
160*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tregister long *buf;\n");
161*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif\n\n");
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate static
165*7c478bd9Sstevel@tonic-gate print_prog_header(plist)
166*7c478bd9Sstevel@tonic-gate 	proc_list *plist;
167*7c478bd9Sstevel@tonic-gate {
168*7c478bd9Sstevel@tonic-gate 	print_generic_header(plist->args.argname, 1);
169*7c478bd9Sstevel@tonic-gate }
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate static
172*7c478bd9Sstevel@tonic-gate print_trailer()
173*7c478bd9Sstevel@tonic-gate {
174*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\treturn (TRUE);\n");
175*7c478bd9Sstevel@tonic-gate 	f_print(fout, "}\n");
176*7c478bd9Sstevel@tonic-gate }
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate static
180*7c478bd9Sstevel@tonic-gate print_ifopen(indent, name)
181*7c478bd9Sstevel@tonic-gate 	int indent;
182*7c478bd9Sstevel@tonic-gate 	char *name;
183*7c478bd9Sstevel@tonic-gate {
184*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent);
185*7c478bd9Sstevel@tonic-gate 	if (streq(name, "rpcprog_t") ||
186*7c478bd9Sstevel@tonic-gate 		streq(name, "rpcvers_t") ||
187*7c478bd9Sstevel@tonic-gate 		streq(name, "rpcproc_t") ||
188*7c478bd9Sstevel@tonic-gate 		streq(name, "rpcprot_t") ||
189*7c478bd9Sstevel@tonic-gate 		streq(name, "rpcport_t"))
190*7c478bd9Sstevel@tonic-gate 		strtok(name, "_");
191*7c478bd9Sstevel@tonic-gate 	f_print(fout, "if (!xdr_%s(xdrs", name);
192*7c478bd9Sstevel@tonic-gate }
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate static
195*7c478bd9Sstevel@tonic-gate print_ifarg(arg)
196*7c478bd9Sstevel@tonic-gate 	char *arg;
197*7c478bd9Sstevel@tonic-gate {
198*7c478bd9Sstevel@tonic-gate 	f_print(fout, ", %s", arg);
199*7c478bd9Sstevel@tonic-gate }
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate static
202*7c478bd9Sstevel@tonic-gate print_ifsizeof(indent, prefix, type)
203*7c478bd9Sstevel@tonic-gate 	int indent;
204*7c478bd9Sstevel@tonic-gate 	char *prefix;
205*7c478bd9Sstevel@tonic-gate 	char *type;
206*7c478bd9Sstevel@tonic-gate {
207*7c478bd9Sstevel@tonic-gate 	if (indent) {
208*7c478bd9Sstevel@tonic-gate 		f_print(fout, ",\n");
209*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent);
210*7c478bd9Sstevel@tonic-gate 	} else  {
211*7c478bd9Sstevel@tonic-gate 		f_print(fout, ", ");
212*7c478bd9Sstevel@tonic-gate 	}
213*7c478bd9Sstevel@tonic-gate 	if (streq(type, "bool")) {
214*7c478bd9Sstevel@tonic-gate 		f_print(fout, "sizeof (bool_t), (xdrproc_t) xdr_bool");
215*7c478bd9Sstevel@tonic-gate 	} else {
216*7c478bd9Sstevel@tonic-gate 		f_print(fout, "sizeof (");
217*7c478bd9Sstevel@tonic-gate 		if (undefined(type) && prefix) {
218*7c478bd9Sstevel@tonic-gate 			f_print(fout, "%s ", prefix);
219*7c478bd9Sstevel@tonic-gate 		}
220*7c478bd9Sstevel@tonic-gate 		f_print(fout, "%s), (xdrproc_t) xdr_%s", type, type);
221*7c478bd9Sstevel@tonic-gate 	}
222*7c478bd9Sstevel@tonic-gate }
223*7c478bd9Sstevel@tonic-gate 
224*7c478bd9Sstevel@tonic-gate static
225*7c478bd9Sstevel@tonic-gate print_ifclose(indent)
226*7c478bd9Sstevel@tonic-gate 	int indent;
227*7c478bd9Sstevel@tonic-gate {
228*7c478bd9Sstevel@tonic-gate 	f_print(fout, "))\n");
229*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent);
230*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\treturn (FALSE);\n");
231*7c478bd9Sstevel@tonic-gate }
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate static
234*7c478bd9Sstevel@tonic-gate print_ifstat(indent, prefix, type, rel, amax, objname, name)
235*7c478bd9Sstevel@tonic-gate 	int indent;
236*7c478bd9Sstevel@tonic-gate 	char *prefix;
237*7c478bd9Sstevel@tonic-gate 	char *type;
238*7c478bd9Sstevel@tonic-gate 	relation rel;
239*7c478bd9Sstevel@tonic-gate 	char *amax;
240*7c478bd9Sstevel@tonic-gate 	char *objname;
241*7c478bd9Sstevel@tonic-gate 	char *name;
242*7c478bd9Sstevel@tonic-gate {
243*7c478bd9Sstevel@tonic-gate 	char *alt = NULL;
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	switch (rel) {
246*7c478bd9Sstevel@tonic-gate 	case REL_POINTER:
247*7c478bd9Sstevel@tonic-gate 		print_ifopen(indent, "pointer");
248*7c478bd9Sstevel@tonic-gate 		print_ifarg("(char **)");
249*7c478bd9Sstevel@tonic-gate 		f_print(fout, "%s", objname);
250*7c478bd9Sstevel@tonic-gate 		print_ifsizeof(0, prefix, type);
251*7c478bd9Sstevel@tonic-gate 		break;
252*7c478bd9Sstevel@tonic-gate 	case REL_VECTOR:
253*7c478bd9Sstevel@tonic-gate 		if (streq(type, "string")) {
254*7c478bd9Sstevel@tonic-gate 			alt = "string";
255*7c478bd9Sstevel@tonic-gate 		} else if (streq(type, "opaque")) {
256*7c478bd9Sstevel@tonic-gate 			alt = "opaque";
257*7c478bd9Sstevel@tonic-gate 		}
258*7c478bd9Sstevel@tonic-gate 		if (alt) {
259*7c478bd9Sstevel@tonic-gate 			print_ifopen(indent, alt);
260*7c478bd9Sstevel@tonic-gate 			print_ifarg(objname);
261*7c478bd9Sstevel@tonic-gate 		} else {
262*7c478bd9Sstevel@tonic-gate 			print_ifopen(indent, "vector");
263*7c478bd9Sstevel@tonic-gate 			print_ifarg("(char *)");
264*7c478bd9Sstevel@tonic-gate 			f_print(fout, "%s", objname);
265*7c478bd9Sstevel@tonic-gate 		}
266*7c478bd9Sstevel@tonic-gate 		print_ifarg(amax);
267*7c478bd9Sstevel@tonic-gate 		if (!alt) {
268*7c478bd9Sstevel@tonic-gate 			print_ifsizeof(indent + 1, prefix, type);
269*7c478bd9Sstevel@tonic-gate 		}
270*7c478bd9Sstevel@tonic-gate 		break;
271*7c478bd9Sstevel@tonic-gate 	case REL_ARRAY:
272*7c478bd9Sstevel@tonic-gate 		if (streq(type, "string")) {
273*7c478bd9Sstevel@tonic-gate 			alt = "string";
274*7c478bd9Sstevel@tonic-gate 		} else if (streq(type, "opaque")) {
275*7c478bd9Sstevel@tonic-gate 			alt = "bytes";
276*7c478bd9Sstevel@tonic-gate 		}
277*7c478bd9Sstevel@tonic-gate 		if (streq(type, "string")) {
278*7c478bd9Sstevel@tonic-gate 			print_ifopen(indent, alt);
279*7c478bd9Sstevel@tonic-gate 			print_ifarg(objname);
280*7c478bd9Sstevel@tonic-gate 		} else {
281*7c478bd9Sstevel@tonic-gate 			if (alt) {
282*7c478bd9Sstevel@tonic-gate 				print_ifopen(indent, alt);
283*7c478bd9Sstevel@tonic-gate 			} else {
284*7c478bd9Sstevel@tonic-gate 				print_ifopen(indent, "array");
285*7c478bd9Sstevel@tonic-gate 			}
286*7c478bd9Sstevel@tonic-gate 			print_ifarg("(char **)");
287*7c478bd9Sstevel@tonic-gate 			if (*objname == '&') {
288*7c478bd9Sstevel@tonic-gate 				f_print(fout, "%s.%s_val, (u_int *) %s.%s_len",
289*7c478bd9Sstevel@tonic-gate 					objname, name, objname, name);
290*7c478bd9Sstevel@tonic-gate 			} else {
291*7c478bd9Sstevel@tonic-gate 				f_print(fout,
292*7c478bd9Sstevel@tonic-gate 					"&%s->%s_val, (u_int *) &%s->%s_len",
293*7c478bd9Sstevel@tonic-gate 					objname, name, objname, name);
294*7c478bd9Sstevel@tonic-gate 			}
295*7c478bd9Sstevel@tonic-gate 		}
296*7c478bd9Sstevel@tonic-gate 		print_ifarg(amax);
297*7c478bd9Sstevel@tonic-gate 		if (!alt) {
298*7c478bd9Sstevel@tonic-gate 			print_ifsizeof(indent + 1, prefix, type);
299*7c478bd9Sstevel@tonic-gate 		}
300*7c478bd9Sstevel@tonic-gate 		break;
301*7c478bd9Sstevel@tonic-gate 	case REL_ALIAS:
302*7c478bd9Sstevel@tonic-gate 		print_ifopen(indent, type);
303*7c478bd9Sstevel@tonic-gate 		print_ifarg(objname);
304*7c478bd9Sstevel@tonic-gate 		break;
305*7c478bd9Sstevel@tonic-gate 	}
306*7c478bd9Sstevel@tonic-gate 	print_ifclose(indent);
307*7c478bd9Sstevel@tonic-gate }
308*7c478bd9Sstevel@tonic-gate 
309*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
310*7c478bd9Sstevel@tonic-gate static
311*7c478bd9Sstevel@tonic-gate emit_enum(def)
312*7c478bd9Sstevel@tonic-gate 	definition *def;
313*7c478bd9Sstevel@tonic-gate {
314*7c478bd9Sstevel@tonic-gate 	print_ifopen(1, "enum");
315*7c478bd9Sstevel@tonic-gate 	print_ifarg("(enum_t *)objp");
316*7c478bd9Sstevel@tonic-gate 	print_ifclose(1);
317*7c478bd9Sstevel@tonic-gate }
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate static
320*7c478bd9Sstevel@tonic-gate emit_program(def)
321*7c478bd9Sstevel@tonic-gate 	definition *def;
322*7c478bd9Sstevel@tonic-gate {
323*7c478bd9Sstevel@tonic-gate 	decl_list *dl;
324*7c478bd9Sstevel@tonic-gate 	version_list *vlist;
325*7c478bd9Sstevel@tonic-gate 	proc_list *plist;
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate 	for (vlist = def->def.pr.versions; vlist != NULL; vlist = vlist->next)
328*7c478bd9Sstevel@tonic-gate 		for (plist = vlist->procs; plist != NULL; plist = plist->next) {
329*7c478bd9Sstevel@tonic-gate 			if (!newstyle || plist->arg_num < 2)
330*7c478bd9Sstevel@tonic-gate 				continue; /* old style, or single argument */
331*7c478bd9Sstevel@tonic-gate 			print_prog_header(plist);
332*7c478bd9Sstevel@tonic-gate 			for (dl = plist->args.decls; dl != NULL;
333*7c478bd9Sstevel@tonic-gate 				dl = dl->next)
334*7c478bd9Sstevel@tonic-gate 				print_stat(1, &dl->decl);
335*7c478bd9Sstevel@tonic-gate 			print_trailer();
336*7c478bd9Sstevel@tonic-gate 		}
337*7c478bd9Sstevel@tonic-gate }
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate static
341*7c478bd9Sstevel@tonic-gate emit_union(def)
342*7c478bd9Sstevel@tonic-gate 	definition *def;
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate 	declaration *dflt;
345*7c478bd9Sstevel@tonic-gate 	case_list *cl;
346*7c478bd9Sstevel@tonic-gate 	declaration *cs;
347*7c478bd9Sstevel@tonic-gate 	char *object;
348*7c478bd9Sstevel@tonic-gate 	char *vecformat = "objp->%s_u.%s";
349*7c478bd9Sstevel@tonic-gate 	char *format = "&objp->%s_u.%s";
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate 	print_stat(1, &def->def.un.enum_decl);
352*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tswitch (objp->%s) {\n", def->def.un.enum_decl.name);
353*7c478bd9Sstevel@tonic-gate 	for (cl = def->def.un.cases; cl != NULL; cl = cl->next) {
354*7c478bd9Sstevel@tonic-gate 
355*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\tcase %s:\n", cl->case_name);
356*7c478bd9Sstevel@tonic-gate 		if (cl->contflag == 1) /* a continued case statement */
357*7c478bd9Sstevel@tonic-gate 			continue;
358*7c478bd9Sstevel@tonic-gate 		cs = &cl->case_decl;
359*7c478bd9Sstevel@tonic-gate 		if (!streq(cs->type, "void")) {
360*7c478bd9Sstevel@tonic-gate 			object = alloc(strlen(def->def_name) + strlen(format) +
361*7c478bd9Sstevel@tonic-gate 					strlen(cs->name) + 1);
362*7c478bd9Sstevel@tonic-gate 			if (isvectordef(cs->type, cs->rel)) {
363*7c478bd9Sstevel@tonic-gate 				s_print(object, vecformat, def->def_name,
364*7c478bd9Sstevel@tonic-gate 					cs->name);
365*7c478bd9Sstevel@tonic-gate 			} else {
366*7c478bd9Sstevel@tonic-gate 				s_print(object, format, def->def_name,
367*7c478bd9Sstevel@tonic-gate 					cs->name);
368*7c478bd9Sstevel@tonic-gate 			}
369*7c478bd9Sstevel@tonic-gate 			print_ifstat(2, cs->prefix, cs->type, cs->rel,
370*7c478bd9Sstevel@tonic-gate 				cs->array_max, object, cs->name);
371*7c478bd9Sstevel@tonic-gate 			free(object);
372*7c478bd9Sstevel@tonic-gate 		}
373*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t\tbreak;\n");
374*7c478bd9Sstevel@tonic-gate 	}
375*7c478bd9Sstevel@tonic-gate 	dflt = def->def.un.default_decl;
376*7c478bd9Sstevel@tonic-gate 	if (dflt != NULL) {
377*7c478bd9Sstevel@tonic-gate 		if (!streq(dflt->type, "void")) {
378*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\tdefault:\n");
379*7c478bd9Sstevel@tonic-gate 			object = alloc(strlen(def->def_name) + strlen(format) +
380*7c478bd9Sstevel@tonic-gate strlen(dflt->name) + 1);
381*7c478bd9Sstevel@tonic-gate 			if (isvectordef(dflt->type, dflt->rel)) {
382*7c478bd9Sstevel@tonic-gate 				s_print(object, vecformat, def->def_name,
383*7c478bd9Sstevel@tonic-gate 					dflt->name);
384*7c478bd9Sstevel@tonic-gate 			} else {
385*7c478bd9Sstevel@tonic-gate 				s_print(object, format, def->def_name,
386*7c478bd9Sstevel@tonic-gate 					dflt->name);
387*7c478bd9Sstevel@tonic-gate 			}
388*7c478bd9Sstevel@tonic-gate 
389*7c478bd9Sstevel@tonic-gate 			print_ifstat(2, dflt->prefix, dflt->type, dflt->rel,
390*7c478bd9Sstevel@tonic-gate 				    dflt->array_max, object, dflt->name);
391*7c478bd9Sstevel@tonic-gate 			free(object);
392*7c478bd9Sstevel@tonic-gate 			f_print(fout, "\t\tbreak;\n");
393*7c478bd9Sstevel@tonic-gate 		}
394*7c478bd9Sstevel@tonic-gate 	} else {
395*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\tdefault:\n");
396*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t\treturn (FALSE);\n");
397*7c478bd9Sstevel@tonic-gate 	}
398*7c478bd9Sstevel@tonic-gate 
399*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t}\n");
400*7c478bd9Sstevel@tonic-gate }
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate static void
403*7c478bd9Sstevel@tonic-gate expand_inline(int indent, const char *sizestr,
404*7c478bd9Sstevel@tonic-gate 	    int size, int flag, decl_list *dl, decl_list *cur)
405*7c478bd9Sstevel@tonic-gate {
406*7c478bd9Sstevel@tonic-gate 	decl_list *psav;
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	/*
409*7c478bd9Sstevel@tonic-gate 	 * were already looking at a xdr_inlineable structure
410*7c478bd9Sstevel@tonic-gate 	 */
411*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent + 1);
412*7c478bd9Sstevel@tonic-gate 	if (sizestr == NULL)
413*7c478bd9Sstevel@tonic-gate 		f_print(fout,
414*7c478bd9Sstevel@tonic-gate 			"buf = XDR_INLINE(xdrs, %d * BYTES_PER_XDR_UNIT);",
415*7c478bd9Sstevel@tonic-gate 			size);
416*7c478bd9Sstevel@tonic-gate 	else if (size == 0)
417*7c478bd9Sstevel@tonic-gate 		f_print(fout,
418*7c478bd9Sstevel@tonic-gate 			"buf = XDR_INLINE(xdrs, (%s) * BYTES_PER_XDR_UNIT);",
419*7c478bd9Sstevel@tonic-gate 			sizestr);
420*7c478bd9Sstevel@tonic-gate 	else
421*7c478bd9Sstevel@tonic-gate 		f_print(fout,
422*7c478bd9Sstevel@tonic-gate 			"buf = XDR_INLINE(xdrs, (%d + (%s)) "
423*7c478bd9Sstevel@tonic-gate 			"* BYTES_PER_XDR_UNIT);", size, sizestr);
424*7c478bd9Sstevel@tonic-gate 
425*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n");
426*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent + 1);
427*7c478bd9Sstevel@tonic-gate 	f_print(fout, "if (buf == NULL) {\n");
428*7c478bd9Sstevel@tonic-gate 
429*7c478bd9Sstevel@tonic-gate 	psav = cur;
430*7c478bd9Sstevel@tonic-gate 	while (cur != dl) {
431*7c478bd9Sstevel@tonic-gate 		print_stat(indent + 2,
432*7c478bd9Sstevel@tonic-gate 			&cur->decl);
433*7c478bd9Sstevel@tonic-gate 		cur = cur->next;
434*7c478bd9Sstevel@tonic-gate 	}
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent+1);
437*7c478bd9Sstevel@tonic-gate 	f_print(fout, "} else {\n");
438*7c478bd9Sstevel@tonic-gate 
439*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#if defined(_LP64) || defined(_KERNEL)\n");
440*7c478bd9Sstevel@tonic-gate 	cur = psav;
441*7c478bd9Sstevel@tonic-gate 	while (cur != dl) {
442*7c478bd9Sstevel@tonic-gate 		emit_inline64(indent + 2, &cur->decl, flag);
443*7c478bd9Sstevel@tonic-gate 		cur = cur->next;
444*7c478bd9Sstevel@tonic-gate 	}
445*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#else\n");
446*7c478bd9Sstevel@tonic-gate 	cur = psav;
447*7c478bd9Sstevel@tonic-gate 	while (cur != dl) {
448*7c478bd9Sstevel@tonic-gate 		emit_inline(indent + 2, &cur->decl, flag);
449*7c478bd9Sstevel@tonic-gate 		cur = cur->next;
450*7c478bd9Sstevel@tonic-gate 	}
451*7c478bd9Sstevel@tonic-gate 	f_print(fout, "#endif\n");
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent + 1);
454*7c478bd9Sstevel@tonic-gate 	f_print(fout, "}\n");
455*7c478bd9Sstevel@tonic-gate }
456*7c478bd9Sstevel@tonic-gate 
457*7c478bd9Sstevel@tonic-gate /*
458*7c478bd9Sstevel@tonic-gate  * An inline type is a base type (interger type) or a vector of base types.
459*7c478bd9Sstevel@tonic-gate  */
460*7c478bd9Sstevel@tonic-gate static int
461*7c478bd9Sstevel@tonic-gate inline_type(declaration *dc, int *size)
462*7c478bd9Sstevel@tonic-gate {
463*7c478bd9Sstevel@tonic-gate 	bas_type *ptr;
464*7c478bd9Sstevel@tonic-gate 
465*7c478bd9Sstevel@tonic-gate 	*size = 0;
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	if (dc->prefix == NULL &&
468*7c478bd9Sstevel@tonic-gate 	    (dc->rel == REL_ALIAS || dc->rel == REL_VECTOR)) {
469*7c478bd9Sstevel@tonic-gate 		ptr = find_type(dc->type);
470*7c478bd9Sstevel@tonic-gate 		if (ptr != NULL) {
471*7c478bd9Sstevel@tonic-gate 			*size = ptr->length;
472*7c478bd9Sstevel@tonic-gate 			return (1);
473*7c478bd9Sstevel@tonic-gate 		}
474*7c478bd9Sstevel@tonic-gate 	}
475*7c478bd9Sstevel@tonic-gate 
476*7c478bd9Sstevel@tonic-gate 	return (0);
477*7c478bd9Sstevel@tonic-gate }
478*7c478bd9Sstevel@tonic-gate 
479*7c478bd9Sstevel@tonic-gate static char *
480*7c478bd9Sstevel@tonic-gate arraysize(char *sz, declaration *dc, int elsize)
481*7c478bd9Sstevel@tonic-gate {
482*7c478bd9Sstevel@tonic-gate 	int len;
483*7c478bd9Sstevel@tonic-gate 	int elsz = elsize;
484*7c478bd9Sstevel@tonic-gate 	int digits;
485*7c478bd9Sstevel@tonic-gate 	int slen = 0;
486*7c478bd9Sstevel@tonic-gate 	char *plus = "";
487*7c478bd9Sstevel@tonic-gate 	char *tmp;
488*7c478bd9Sstevel@tonic-gate 
489*7c478bd9Sstevel@tonic-gate 	/*
490*7c478bd9Sstevel@tonic-gate 	 * Calculate the size of a string to hold the size of all arrays
491*7c478bd9Sstevel@tonic-gate 	 * to be inlined.
492*7c478bd9Sstevel@tonic-gate 	 *
493*7c478bd9Sstevel@tonic-gate 	 * We have the string representation of the total size that has already
494*7c478bd9Sstevel@tonic-gate 	 * been seen. (Null if this is the first array).
495*7c478bd9Sstevel@tonic-gate 	 * We have the string representation of array max from the declaration,
496*7c478bd9Sstevel@tonic-gate 	 * optionally the plus string, " + ", if this is not the first array,
497*7c478bd9Sstevel@tonic-gate 	 * and the number of digits for the element size for this declaration.
498*7c478bd9Sstevel@tonic-gate 	 */
499*7c478bd9Sstevel@tonic-gate 	if (sz != NULL) {
500*7c478bd9Sstevel@tonic-gate 		plus = " + ";
501*7c478bd9Sstevel@tonic-gate 		slen = strlen(sz);
502*7c478bd9Sstevel@tonic-gate 	}
503*7c478bd9Sstevel@tonic-gate 
504*7c478bd9Sstevel@tonic-gate 	/* Calculate the number of digits to hold the element size */
505*7c478bd9Sstevel@tonic-gate 	for (digits = 1; elsz >= 10; digits++)
506*7c478bd9Sstevel@tonic-gate 		elsz /= 10;
507*7c478bd9Sstevel@tonic-gate 
508*7c478bd9Sstevel@tonic-gate 	/*
509*7c478bd9Sstevel@tonic-gate 	 * If elsize != 1 the allocate 3 extra bytes for the times
510*7c478bd9Sstevel@tonic-gate 	 * string, " * ", the "()" below,  and the digits. One extra
511*7c478bd9Sstevel@tonic-gate 	 * for the trailing NULL
512*7c478bd9Sstevel@tonic-gate 	 */
513*7c478bd9Sstevel@tonic-gate 	len = strlen(dc->array_max) +  (elsize == 1 ? 0 : digits + 5) + 1;
514*7c478bd9Sstevel@tonic-gate 	tmp = realloc(sz, slen + len + strlen(plus));
515*7c478bd9Sstevel@tonic-gate 	if (tmp == NULL) {
516*7c478bd9Sstevel@tonic-gate 		f_print(stderr, "Fatal error : no memory\n");
517*7c478bd9Sstevel@tonic-gate 		crash();
518*7c478bd9Sstevel@tonic-gate 	}
519*7c478bd9Sstevel@tonic-gate 
520*7c478bd9Sstevel@tonic-gate 	if (elsize == 1)
521*7c478bd9Sstevel@tonic-gate 		s_print(tmp + slen, "%s%s", plus, dc->array_max);
522*7c478bd9Sstevel@tonic-gate 	else
523*7c478bd9Sstevel@tonic-gate 		s_print(tmp + slen, "%s(%s) * %d", plus, dc->array_max, elsize);
524*7c478bd9Sstevel@tonic-gate 
525*7c478bd9Sstevel@tonic-gate 	return (tmp);
526*7c478bd9Sstevel@tonic-gate }
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate static void
529*7c478bd9Sstevel@tonic-gate inline_struct(decl_list *dl, decl_list *last, int flag, int indent)
530*7c478bd9Sstevel@tonic-gate {
531*7c478bd9Sstevel@tonic-gate 	int size, tsize;
532*7c478bd9Sstevel@tonic-gate 	decl_list *cur, *psav;
533*7c478bd9Sstevel@tonic-gate 	char *sizestr, *plus;
534*7c478bd9Sstevel@tonic-gate 	char ptemp[256];
535*7c478bd9Sstevel@tonic-gate 
536*7c478bd9Sstevel@tonic-gate 	cur = NULL;
537*7c478bd9Sstevel@tonic-gate 	tsize = 0;
538*7c478bd9Sstevel@tonic-gate 	sizestr = NULL;
539*7c478bd9Sstevel@tonic-gate 	for (; dl != last; dl = dl->next) {
540*7c478bd9Sstevel@tonic-gate 		if (inline_type(&dl->decl, &size)) {
541*7c478bd9Sstevel@tonic-gate 			if (cur == NULL)
542*7c478bd9Sstevel@tonic-gate 				cur = dl;
543*7c478bd9Sstevel@tonic-gate 
544*7c478bd9Sstevel@tonic-gate 			if (dl->decl.rel == REL_ALIAS)
545*7c478bd9Sstevel@tonic-gate 				tsize += size;
546*7c478bd9Sstevel@tonic-gate 			else {
547*7c478bd9Sstevel@tonic-gate 				/* this code is required to handle arrays */
548*7c478bd9Sstevel@tonic-gate 				sizestr = arraysize(sizestr, &dl->decl, size);
549*7c478bd9Sstevel@tonic-gate 			}
550*7c478bd9Sstevel@tonic-gate 		} else {
551*7c478bd9Sstevel@tonic-gate 			if (cur != NULL)
552*7c478bd9Sstevel@tonic-gate 				if (sizestr == NULL && tsize < inlinelen) {
553*7c478bd9Sstevel@tonic-gate 					/*
554*7c478bd9Sstevel@tonic-gate 					 * don't expand into inline code
555*7c478bd9Sstevel@tonic-gate 					 * if tsize < inlinelen
556*7c478bd9Sstevel@tonic-gate 					 */
557*7c478bd9Sstevel@tonic-gate 					while (cur != dl) {
558*7c478bd9Sstevel@tonic-gate 						print_stat(indent + 1,
559*7c478bd9Sstevel@tonic-gate 							&cur->decl);
560*7c478bd9Sstevel@tonic-gate 						cur = cur->next;
561*7c478bd9Sstevel@tonic-gate 					}
562*7c478bd9Sstevel@tonic-gate 				} else {
563*7c478bd9Sstevel@tonic-gate 					expand_inline(indent, sizestr,
564*7c478bd9Sstevel@tonic-gate 						    tsize, flag, dl, cur);
565*7c478bd9Sstevel@tonic-gate 				}
566*7c478bd9Sstevel@tonic-gate 			tsize = 0;
567*7c478bd9Sstevel@tonic-gate 			cur = NULL;
568*7c478bd9Sstevel@tonic-gate 			sizestr = NULL;
569*7c478bd9Sstevel@tonic-gate 			print_stat(indent + 1, &dl->decl);
570*7c478bd9Sstevel@tonic-gate 		}
571*7c478bd9Sstevel@tonic-gate 	}
572*7c478bd9Sstevel@tonic-gate 
573*7c478bd9Sstevel@tonic-gate 	if (cur != NULL)
574*7c478bd9Sstevel@tonic-gate 		if (sizestr == NULL && tsize < inlinelen) {
575*7c478bd9Sstevel@tonic-gate 			/* don't expand into inline code if tsize < inlinelen */
576*7c478bd9Sstevel@tonic-gate 			while (cur != dl) {
577*7c478bd9Sstevel@tonic-gate 				print_stat(indent + 1, &cur->decl);
578*7c478bd9Sstevel@tonic-gate 				cur = cur->next;
579*7c478bd9Sstevel@tonic-gate 			}
580*7c478bd9Sstevel@tonic-gate 		} else {
581*7c478bd9Sstevel@tonic-gate 			expand_inline(indent, sizestr, tsize, flag, dl, cur);
582*7c478bd9Sstevel@tonic-gate 		}
583*7c478bd9Sstevel@tonic-gate }
584*7c478bd9Sstevel@tonic-gate 
585*7c478bd9Sstevel@tonic-gate /*
586*7c478bd9Sstevel@tonic-gate  * Check if we can inline this structure. While we are at it check if the
587*7c478bd9Sstevel@tonic-gate  * declaration list has any vectors defined of "basic" types.
588*7c478bd9Sstevel@tonic-gate  */
589*7c478bd9Sstevel@tonic-gate static int
590*7c478bd9Sstevel@tonic-gate check_inline(decl_list *dl, int inlinelen, int *have_vector)
591*7c478bd9Sstevel@tonic-gate {
592*7c478bd9Sstevel@tonic-gate 	int tsize = 0;
593*7c478bd9Sstevel@tonic-gate 	int size;
594*7c478bd9Sstevel@tonic-gate 	int doinline = 0;
595*7c478bd9Sstevel@tonic-gate 
596*7c478bd9Sstevel@tonic-gate 	*have_vector = 0;
597*7c478bd9Sstevel@tonic-gate 	if (inlinelen == 0)
598*7c478bd9Sstevel@tonic-gate 		return (0);
599*7c478bd9Sstevel@tonic-gate 
600*7c478bd9Sstevel@tonic-gate 	for (; dl != NULL; dl = dl->next) {
601*7c478bd9Sstevel@tonic-gate 		if (inline_type(&dl->decl, &size)) {
602*7c478bd9Sstevel@tonic-gate 			if (dl->decl.rel == REL_VECTOR) {
603*7c478bd9Sstevel@tonic-gate 				*have_vector = 1;
604*7c478bd9Sstevel@tonic-gate 				doinline = 1;
605*7c478bd9Sstevel@tonic-gate 				break;
606*7c478bd9Sstevel@tonic-gate 			} else {
607*7c478bd9Sstevel@tonic-gate 				tsize += size;
608*7c478bd9Sstevel@tonic-gate 				if (tsize >= inlinelen)
609*7c478bd9Sstevel@tonic-gate 					doinline = 1;
610*7c478bd9Sstevel@tonic-gate 			}
611*7c478bd9Sstevel@tonic-gate 		} else {
612*7c478bd9Sstevel@tonic-gate 			tsize = 0;
613*7c478bd9Sstevel@tonic-gate 		}
614*7c478bd9Sstevel@tonic-gate 	}
615*7c478bd9Sstevel@tonic-gate 
616*7c478bd9Sstevel@tonic-gate 	return (doinline);
617*7c478bd9Sstevel@tonic-gate }
618*7c478bd9Sstevel@tonic-gate 
619*7c478bd9Sstevel@tonic-gate 
620*7c478bd9Sstevel@tonic-gate static void
621*7c478bd9Sstevel@tonic-gate emit_struct_tail_recursion(definition *defp, int can_inline)
622*7c478bd9Sstevel@tonic-gate {
623*7c478bd9Sstevel@tonic-gate 	int indent = 3;
624*7c478bd9Sstevel@tonic-gate 	struct_def *sp = &defp->def.st;
625*7c478bd9Sstevel@tonic-gate 	decl_list *dl;
626*7c478bd9Sstevel@tonic-gate 
627*7c478bd9Sstevel@tonic-gate 
628*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t%s *tmp_%s;\n",
629*7c478bd9Sstevel@tonic-gate 		defp->def_name, defp->def_name);
630*7c478bd9Sstevel@tonic-gate 
631*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tbool_t more_data = TRUE;\n");
632*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\tbool_t first_objp = TRUE;\n\n");
633*7c478bd9Sstevel@tonic-gate 
634*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\tif (xdrs->x_op == XDR_DECODE) {\n");
635*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\twhile (more_data) {\n");
636*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\t\tvoid bzero();\n\n");
637*7c478bd9Sstevel@tonic-gate 
638*7c478bd9Sstevel@tonic-gate 	if (can_inline)
639*7c478bd9Sstevel@tonic-gate 		inline_struct(sp->decls, sp->tail, GET, indent);
640*7c478bd9Sstevel@tonic-gate 	else
641*7c478bd9Sstevel@tonic-gate 		for (dl = sp->decls; dl != NULL && dl != sp->tail;
642*7c478bd9Sstevel@tonic-gate 		    dl = dl->next)
643*7c478bd9Sstevel@tonic-gate 			print_stat(indent, &dl->decl);
644*7c478bd9Sstevel@tonic-gate 
645*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tif (!xdr_bool(xdrs, "
646*7c478bd9Sstevel@tonic-gate 		"&more_data))\n\t\t\t\treturn (FALSE);\n");
647*7c478bd9Sstevel@tonic-gate 
648*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\t\tif (!more_data) {\n");
649*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tobjp->%s = NULL;\n", sp->tail->decl.name);
650*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tbreak;\n");
651*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t}\n\n");
652*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tif (objp->%s == NULL) {\n", sp->tail->decl.name);
653*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tobjp->%s = "
654*7c478bd9Sstevel@tonic-gate 		"(%s *)\n\t\t\t\t\tmem_alloc(sizeof (%s));\n",
655*7c478bd9Sstevel@tonic-gate 		sp->tail->decl.name, defp->def_name, defp->def_name);
656*7c478bd9Sstevel@tonic-gate 
657*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tif (objp->%s == NULL)\n"
658*7c478bd9Sstevel@tonic-gate 		"\t\t\t\t\treturn (FALSE);\n", sp->tail->decl.name);
659*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tbzero(objp->%s, sizeof (%s));\n",
660*7c478bd9Sstevel@tonic-gate 		sp->tail->decl.name, defp->def_name);
661*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t}\n");
662*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tobjp = objp->%s;\n", sp->tail->decl.name);
663*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t}\n");
664*7c478bd9Sstevel@tonic-gate 
665*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t} else if (xdrs->x_op == XDR_ENCODE) {\n");
666*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\twhile (more_data) {\n");
667*7c478bd9Sstevel@tonic-gate 
668*7c478bd9Sstevel@tonic-gate 	if (can_inline)
669*7c478bd9Sstevel@tonic-gate 		inline_struct(sp->decls, sp->tail, PUT, indent);
670*7c478bd9Sstevel@tonic-gate 	else
671*7c478bd9Sstevel@tonic-gate 		for (dl = sp->decls; dl != NULL && dl != sp->tail;
672*7c478bd9Sstevel@tonic-gate 		    dl = dl->next)
673*7c478bd9Sstevel@tonic-gate 			print_stat(indent, &dl->decl);
674*7c478bd9Sstevel@tonic-gate 
675*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tobjp = objp->%s;\n", sp->tail->decl.name);
676*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tif (objp == NULL)\n");
677*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tmore_data = FALSE;\n");
678*7c478bd9Sstevel@tonic-gate 
679*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tif (!xdr_bool(xdrs, &more_data))\n"
680*7c478bd9Sstevel@tonic-gate 		"\t\t\t\treturn (FALSE);\n");
681*7c478bd9Sstevel@tonic-gate 
682*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t}\n");
683*7c478bd9Sstevel@tonic-gate 
684*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t} else {\n");
685*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t\twhile (more_data) {\n");
686*7c478bd9Sstevel@tonic-gate 
687*7c478bd9Sstevel@tonic-gate 	for (dl = sp->decls; dl != NULL && dl != sp->tail; dl = dl->next)
688*7c478bd9Sstevel@tonic-gate 		print_stat(indent, &dl->decl);
689*7c478bd9Sstevel@tonic-gate 
690*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\ttmp_%s = objp;\n", defp->def_name);
691*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tobjp = objp->%s;\n", sp->tail->decl.name);
692*7c478bd9Sstevel@tonic-gate 
693*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tif (objp == NULL)\n");
694*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tmore_data = FALSE;\n");
695*7c478bd9Sstevel@tonic-gate 
696*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\tif (!first_objp)\n");
697*7c478bd9Sstevel@tonic-gate 
698*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\t\tmem_free(tmp_%s, sizeof (%s));\n",
699*7c478bd9Sstevel@tonic-gate 		defp->def_name, defp->def_name);
700*7c478bd9Sstevel@tonic-gate 
701*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\t\t\telse\n\t\t\t\tfirst_objp = FALSE;\n\t\t}\n");
702*7c478bd9Sstevel@tonic-gate 
703*7c478bd9Sstevel@tonic-gate 	f_print(fout, "\n\t}\n");
704*7c478bd9Sstevel@tonic-gate }
705*7c478bd9Sstevel@tonic-gate 
706*7c478bd9Sstevel@tonic-gate static
707*7c478bd9Sstevel@tonic-gate emit_struct(def)
708*7c478bd9Sstevel@tonic-gate 	definition *def;
709*7c478bd9Sstevel@tonic-gate {
710*7c478bd9Sstevel@tonic-gate 	decl_list *dl = def->def.st.decls;
711*7c478bd9Sstevel@tonic-gate 	int can_inline, have_vector;
712*7c478bd9Sstevel@tonic-gate 
713*7c478bd9Sstevel@tonic-gate 
714*7c478bd9Sstevel@tonic-gate 	can_inline = check_inline(dl, inlinelen, &have_vector);
715*7c478bd9Sstevel@tonic-gate 	if (have_vector)
716*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\tint i;\n");
717*7c478bd9Sstevel@tonic-gate 
718*7c478bd9Sstevel@tonic-gate 
719*7c478bd9Sstevel@tonic-gate 	if (rflag && def->def.st.self_pointer) {
720*7c478bd9Sstevel@tonic-gate 		/* Handle tail recursion elimination */
721*7c478bd9Sstevel@tonic-gate 		emit_struct_tail_recursion(def, can_inline);
722*7c478bd9Sstevel@tonic-gate 		return;
723*7c478bd9Sstevel@tonic-gate 	}
724*7c478bd9Sstevel@tonic-gate 
725*7c478bd9Sstevel@tonic-gate 
726*7c478bd9Sstevel@tonic-gate 	if (can_inline) {
727*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\n\tif (xdrs->x_op == XDR_ENCODE) {\n");
728*7c478bd9Sstevel@tonic-gate 		inline_struct(dl, NULL, PUT, 1);
729*7c478bd9Sstevel@tonic-gate 
730*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t\treturn (TRUE);\n\t}"
731*7c478bd9Sstevel@tonic-gate 			" else if (xdrs->x_op == XDR_DECODE) {\n");
732*7c478bd9Sstevel@tonic-gate 
733*7c478bd9Sstevel@tonic-gate 		inline_struct(dl, NULL, GET, 1);
734*7c478bd9Sstevel@tonic-gate 		f_print(fout, "\t\treturn (TRUE);\n\t}\n\n");
735*7c478bd9Sstevel@tonic-gate 	}
736*7c478bd9Sstevel@tonic-gate 
737*7c478bd9Sstevel@tonic-gate 	/* now take care of XDR_FREE inline  case or the non-inline cases */
738*7c478bd9Sstevel@tonic-gate 
739*7c478bd9Sstevel@tonic-gate 	for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
740*7c478bd9Sstevel@tonic-gate 		print_stat(1, &dl->decl);
741*7c478bd9Sstevel@tonic-gate 
742*7c478bd9Sstevel@tonic-gate }
743*7c478bd9Sstevel@tonic-gate 
744*7c478bd9Sstevel@tonic-gate static
745*7c478bd9Sstevel@tonic-gate emit_typedef(def)
746*7c478bd9Sstevel@tonic-gate 	definition *def;
747*7c478bd9Sstevel@tonic-gate {
748*7c478bd9Sstevel@tonic-gate 	char *prefix = def->def.ty.old_prefix;
749*7c478bd9Sstevel@tonic-gate 	char *type = def->def.ty.old_type;
750*7c478bd9Sstevel@tonic-gate 	char *amax = def->def.ty.array_max;
751*7c478bd9Sstevel@tonic-gate 	relation rel = def->def.ty.rel;
752*7c478bd9Sstevel@tonic-gate 
753*7c478bd9Sstevel@tonic-gate 	print_ifstat(1, prefix, type, rel, amax, "objp", def->def_name);
754*7c478bd9Sstevel@tonic-gate }
755*7c478bd9Sstevel@tonic-gate 
756*7c478bd9Sstevel@tonic-gate static
757*7c478bd9Sstevel@tonic-gate print_stat(indent, dec)
758*7c478bd9Sstevel@tonic-gate 	int indent;
759*7c478bd9Sstevel@tonic-gate 	declaration *dec;
760*7c478bd9Sstevel@tonic-gate {
761*7c478bd9Sstevel@tonic-gate 	char *prefix = dec->prefix;
762*7c478bd9Sstevel@tonic-gate 	char *type = dec->type;
763*7c478bd9Sstevel@tonic-gate 	char *amax = dec->array_max;
764*7c478bd9Sstevel@tonic-gate 	relation rel = dec->rel;
765*7c478bd9Sstevel@tonic-gate 	char name[256];
766*7c478bd9Sstevel@tonic-gate 
767*7c478bd9Sstevel@tonic-gate 	if (isvectordef(type, rel)) {
768*7c478bd9Sstevel@tonic-gate 		s_print(name, "objp->%s", dec->name);
769*7c478bd9Sstevel@tonic-gate 	} else {
770*7c478bd9Sstevel@tonic-gate 		s_print(name, "&objp->%s", dec->name);
771*7c478bd9Sstevel@tonic-gate 	}
772*7c478bd9Sstevel@tonic-gate 	print_ifstat(indent, prefix, type, rel, amax, name, dec->name);
773*7c478bd9Sstevel@tonic-gate }
774*7c478bd9Sstevel@tonic-gate 
775*7c478bd9Sstevel@tonic-gate 
776*7c478bd9Sstevel@tonic-gate char *upcase();
777*7c478bd9Sstevel@tonic-gate 
778*7c478bd9Sstevel@tonic-gate emit_inline(indent, decl, flag)
779*7c478bd9Sstevel@tonic-gate int indent;
780*7c478bd9Sstevel@tonic-gate declaration *decl;
781*7c478bd9Sstevel@tonic-gate int flag;
782*7c478bd9Sstevel@tonic-gate {
783*7c478bd9Sstevel@tonic-gate 	switch (decl->rel) {
784*7c478bd9Sstevel@tonic-gate 	case  REL_ALIAS :
785*7c478bd9Sstevel@tonic-gate 		emit_single_in_line(indent, decl, flag, REL_ALIAS);
786*7c478bd9Sstevel@tonic-gate 		break;
787*7c478bd9Sstevel@tonic-gate 	case REL_VECTOR :
788*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent);
789*7c478bd9Sstevel@tonic-gate 		f_print(fout, "{\n");
790*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 1);
791*7c478bd9Sstevel@tonic-gate 		f_print(fout, "register %s *genp;\n\n", decl->type);
792*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 1);
793*7c478bd9Sstevel@tonic-gate 		f_print(fout,
794*7c478bd9Sstevel@tonic-gate 			"for (i = 0, genp = objp->%s;\n", decl->name);
795*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 2);
796*7c478bd9Sstevel@tonic-gate 		f_print(fout, "i < %s; i++) {\n", decl->array_max);
797*7c478bd9Sstevel@tonic-gate 		emit_single_in_line(indent + 2, decl, flag, REL_VECTOR);
798*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 1);
799*7c478bd9Sstevel@tonic-gate 		f_print(fout, "}\n");
800*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent);
801*7c478bd9Sstevel@tonic-gate 		f_print(fout, "}\n");
802*7c478bd9Sstevel@tonic-gate 	}
803*7c478bd9Sstevel@tonic-gate }
804*7c478bd9Sstevel@tonic-gate 
805*7c478bd9Sstevel@tonic-gate emit_inline64(indent, decl, flag)
806*7c478bd9Sstevel@tonic-gate int indent;
807*7c478bd9Sstevel@tonic-gate declaration *decl;
808*7c478bd9Sstevel@tonic-gate int flag;
809*7c478bd9Sstevel@tonic-gate {
810*7c478bd9Sstevel@tonic-gate 	switch (decl->rel) {
811*7c478bd9Sstevel@tonic-gate 	case  REL_ALIAS :
812*7c478bd9Sstevel@tonic-gate 		emit_single_in_line64(indent, decl, flag, REL_ALIAS);
813*7c478bd9Sstevel@tonic-gate 		break;
814*7c478bd9Sstevel@tonic-gate 	case REL_VECTOR :
815*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent);
816*7c478bd9Sstevel@tonic-gate 		f_print(fout, "{\n");
817*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 1);
818*7c478bd9Sstevel@tonic-gate 		f_print(fout, "register %s *genp;\n\n", decl->type);
819*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 1);
820*7c478bd9Sstevel@tonic-gate 		f_print(fout,
821*7c478bd9Sstevel@tonic-gate 			"for (i = 0, genp = objp->%s;\n", decl->name);
822*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 2);
823*7c478bd9Sstevel@tonic-gate 		f_print(fout, "i < %s; i++) {\n", decl->array_max);
824*7c478bd9Sstevel@tonic-gate 		emit_single_in_line64(indent + 2, decl, flag, REL_VECTOR);
825*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent + 1);
826*7c478bd9Sstevel@tonic-gate 		f_print(fout, "}\n");
827*7c478bd9Sstevel@tonic-gate 		tabify(fout, indent);
828*7c478bd9Sstevel@tonic-gate 		f_print(fout, "}\n");
829*7c478bd9Sstevel@tonic-gate 	}
830*7c478bd9Sstevel@tonic-gate }
831*7c478bd9Sstevel@tonic-gate 
832*7c478bd9Sstevel@tonic-gate emit_single_in_line(indent, decl, flag, rel)
833*7c478bd9Sstevel@tonic-gate int indent;
834*7c478bd9Sstevel@tonic-gate declaration *decl;
835*7c478bd9Sstevel@tonic-gate int flag;
836*7c478bd9Sstevel@tonic-gate relation rel;
837*7c478bd9Sstevel@tonic-gate {
838*7c478bd9Sstevel@tonic-gate 	char *upp_case;
839*7c478bd9Sstevel@tonic-gate 	int freed = 0;
840*7c478bd9Sstevel@tonic-gate 
841*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent);
842*7c478bd9Sstevel@tonic-gate 	if (flag == PUT)
843*7c478bd9Sstevel@tonic-gate 		f_print(fout, "IXDR_PUT_");
844*7c478bd9Sstevel@tonic-gate 	else
845*7c478bd9Sstevel@tonic-gate 		if (rel == REL_ALIAS)
846*7c478bd9Sstevel@tonic-gate 			f_print(fout, "objp->%s = IXDR_GET_", decl->name);
847*7c478bd9Sstevel@tonic-gate 		else
848*7c478bd9Sstevel@tonic-gate 			f_print(fout, "*genp++ = IXDR_GET_");
849*7c478bd9Sstevel@tonic-gate 
850*7c478bd9Sstevel@tonic-gate 	upp_case = upcase(decl->type);
851*7c478bd9Sstevel@tonic-gate 
852*7c478bd9Sstevel@tonic-gate 	/* hack	 - XX */
853*7c478bd9Sstevel@tonic-gate 	if (strcmp(upp_case, "INT") == 0)
854*7c478bd9Sstevel@tonic-gate 	{
855*7c478bd9Sstevel@tonic-gate 		free(upp_case);
856*7c478bd9Sstevel@tonic-gate 		freed = 1;
857*7c478bd9Sstevel@tonic-gate 		upp_case = "LONG";
858*7c478bd9Sstevel@tonic-gate 	}
859*7c478bd9Sstevel@tonic-gate 	if ((strcmp(upp_case, "U_INT") == 0) ||
860*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPROG") == 0) ||
861*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCVERS") == 0) ||
862*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPROC") == 0) ||
863*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPROT") == 0) ||
864*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPORT") == 0))
865*7c478bd9Sstevel@tonic-gate 	{
866*7c478bd9Sstevel@tonic-gate 		free(upp_case);
867*7c478bd9Sstevel@tonic-gate 		freed = 1;
868*7c478bd9Sstevel@tonic-gate 		upp_case = "U_LONG";
869*7c478bd9Sstevel@tonic-gate 	}
870*7c478bd9Sstevel@tonic-gate 
871*7c478bd9Sstevel@tonic-gate 	if (flag == PUT)
872*7c478bd9Sstevel@tonic-gate 		if (rel == REL_ALIAS)
873*7c478bd9Sstevel@tonic-gate 			f_print(fout,
874*7c478bd9Sstevel@tonic-gate 				"%s(buf, objp->%s);\n", upp_case, decl->name);
875*7c478bd9Sstevel@tonic-gate 		else
876*7c478bd9Sstevel@tonic-gate 			f_print(fout, "%s(buf, *genp++);\n", upp_case);
877*7c478bd9Sstevel@tonic-gate 
878*7c478bd9Sstevel@tonic-gate 	else
879*7c478bd9Sstevel@tonic-gate 		f_print(fout, "%s(buf);\n", upp_case);
880*7c478bd9Sstevel@tonic-gate 	if (!freed)
881*7c478bd9Sstevel@tonic-gate 		free(upp_case);
882*7c478bd9Sstevel@tonic-gate }
883*7c478bd9Sstevel@tonic-gate 
884*7c478bd9Sstevel@tonic-gate emit_single_in_line64(indent, decl, flag, rel)
885*7c478bd9Sstevel@tonic-gate int indent;
886*7c478bd9Sstevel@tonic-gate declaration *decl;
887*7c478bd9Sstevel@tonic-gate int flag;
888*7c478bd9Sstevel@tonic-gate relation rel;
889*7c478bd9Sstevel@tonic-gate {
890*7c478bd9Sstevel@tonic-gate 	char *upp_case;
891*7c478bd9Sstevel@tonic-gate 	int freed = 0;
892*7c478bd9Sstevel@tonic-gate 
893*7c478bd9Sstevel@tonic-gate 	tabify(fout, indent);
894*7c478bd9Sstevel@tonic-gate 	if (flag == PUT)
895*7c478bd9Sstevel@tonic-gate 		f_print(fout, "IXDR_PUT_");
896*7c478bd9Sstevel@tonic-gate 	else
897*7c478bd9Sstevel@tonic-gate 		if (rel == REL_ALIAS)
898*7c478bd9Sstevel@tonic-gate 			f_print(fout, "objp->%s = IXDR_GET_", decl->name);
899*7c478bd9Sstevel@tonic-gate 		else
900*7c478bd9Sstevel@tonic-gate 			f_print(fout, "*genp++ = IXDR_GET_");
901*7c478bd9Sstevel@tonic-gate 
902*7c478bd9Sstevel@tonic-gate 	upp_case = upcase(decl->type);
903*7c478bd9Sstevel@tonic-gate 
904*7c478bd9Sstevel@tonic-gate 	/* hack	 - XX */
905*7c478bd9Sstevel@tonic-gate 	if ((strcmp(upp_case, "INT") == 0)||(strcmp(upp_case, "LONG") == 0))
906*7c478bd9Sstevel@tonic-gate 	{
907*7c478bd9Sstevel@tonic-gate 		free(upp_case);
908*7c478bd9Sstevel@tonic-gate 		freed = 1;
909*7c478bd9Sstevel@tonic-gate 		upp_case = "INT32";
910*7c478bd9Sstevel@tonic-gate 	}
911*7c478bd9Sstevel@tonic-gate 	if ((strcmp(upp_case, "U_INT") == 0) ||
912*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "U_LONG") == 0) ||
913*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPROG") == 0) ||
914*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCVERS") == 0) ||
915*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPROC") == 0) ||
916*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPROT") == 0) ||
917*7c478bd9Sstevel@tonic-gate 		(strcmp(upp_case, "RPCPORT") == 0))
918*7c478bd9Sstevel@tonic-gate 	{
919*7c478bd9Sstevel@tonic-gate 		free(upp_case);
920*7c478bd9Sstevel@tonic-gate 		freed = 1;
921*7c478bd9Sstevel@tonic-gate 		upp_case = "U_INT32";
922*7c478bd9Sstevel@tonic-gate 	}
923*7c478bd9Sstevel@tonic-gate 
924*7c478bd9Sstevel@tonic-gate 	if (flag == PUT)
925*7c478bd9Sstevel@tonic-gate 		if (rel == REL_ALIAS)
926*7c478bd9Sstevel@tonic-gate 			f_print(fout,
927*7c478bd9Sstevel@tonic-gate 				"%s(buf, objp->%s);\n", upp_case, decl->name);
928*7c478bd9Sstevel@tonic-gate 		else
929*7c478bd9Sstevel@tonic-gate 			f_print(fout, "%s(buf, *genp++);\n", upp_case);
930*7c478bd9Sstevel@tonic-gate 
931*7c478bd9Sstevel@tonic-gate 	else
932*7c478bd9Sstevel@tonic-gate 		f_print(fout, "%s(buf);\n", upp_case);
933*7c478bd9Sstevel@tonic-gate 	if (!freed)
934*7c478bd9Sstevel@tonic-gate 		free(upp_case);
935*7c478bd9Sstevel@tonic-gate }
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate char *
938*7c478bd9Sstevel@tonic-gate upcase(str)
939*7c478bd9Sstevel@tonic-gate char *str;
940*7c478bd9Sstevel@tonic-gate {
941*7c478bd9Sstevel@tonic-gate 	char *ptr, *hptr;
942*7c478bd9Sstevel@tonic-gate 
943*7c478bd9Sstevel@tonic-gate 	ptr =  (char *)malloc(strlen(str)+1);
944*7c478bd9Sstevel@tonic-gate 	if (ptr == (char *)NULL)
945*7c478bd9Sstevel@tonic-gate 	{
946*7c478bd9Sstevel@tonic-gate 		f_print(stderr, "malloc failed\n");
947*7c478bd9Sstevel@tonic-gate 		exit(1);
948*7c478bd9Sstevel@tonic-gate 	};
949*7c478bd9Sstevel@tonic-gate 
950*7c478bd9Sstevel@tonic-gate 	hptr = ptr;
951*7c478bd9Sstevel@tonic-gate 	while (*str != '\0')
952*7c478bd9Sstevel@tonic-gate 		*ptr++ = toupper(*str++);
953*7c478bd9Sstevel@tonic-gate 
954*7c478bd9Sstevel@tonic-gate 	*ptr = '\0';
955*7c478bd9Sstevel@tonic-gate 	return (hptr);
956*7c478bd9Sstevel@tonic-gate }
957