xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/globals.c (revision 9273:9a0603d78ad3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
23*9273SAli.Bahrami@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include	<stdio.h>
281618Srie #include	<strings.h>
29*9273SAli.Bahrami@Sun.COM #include	<ctype.h>
306206Sab196087 #include	<_machelf.h>
311618Srie #include	"_conv.h"
320Sstevel@tonic-gate #include	"globals_msg.h"
330Sstevel@tonic-gate 
341976Sab196087 
351976Sab196087 /*
36*9273SAli.Bahrami@Sun.COM  * Map an integer into a descriptive string.
371976Sab196087  *
381976Sab196087  * entry:
39*9273SAli.Bahrami@Sun.COM  *	inv_buf - A buffer into which this routine can format
40*9273SAli.Bahrami@Sun.COM  *		a result string, if necessary.
41*9273SAli.Bahrami@Sun.COM  *	val - The value for which a string is desired.
42*9273SAli.Bahrami@Sun.COM  *	flags - CONV_FMT_* values to be passed to conv_invalid_val() if
43*9273SAli.Bahrami@Sun.COM  *		necessary. The caller is reponsible for having examined
44*9273SAli.Bahrami@Sun.COM  *		the CONV_FMT_ALT_* part of flags and passing the proper
45*9273SAli.Bahrami@Sun.COM  *		msg array.
46*9273SAli.Bahrami@Sun.COM  *	num_msg - # of Msg entries in msg.
47*9273SAli.Bahrami@Sun.COM  *	msg - Array of num_msg Msg items corresponding to the possible
48*9273SAli.Bahrami@Sun.COM  *		strings corresponding to val.
49*9273SAli.Bahrami@Sun.COM  *	local_sgs_msg - Message string table from module from which
50*9273SAli.Bahrami@Sun.COM  *		this function is called.
511976Sab196087  *
521976Sab196087  * exit:
53*9273SAli.Bahrami@Sun.COM  *	If val lies in the range [0-(num_msg-1)], then the string
54*9273SAli.Bahrami@Sun.COM  *	corresponding to it is returned. If val is outside the range,
55*9273SAli.Bahrami@Sun.COM  *	conv_invalid_val() is called to format an ASCII representation
56*9273SAli.Bahrami@Sun.COM  *	of it into inv_buf, and that is returned.
571976Sab196087  */
58*9273SAli.Bahrami@Sun.COM /*ARGSUSED5*/
59*9273SAli.Bahrami@Sun.COM static const char *
60*9273SAli.Bahrami@Sun.COM map_msg2str(Conv_inv_buf_t *inv_buf, Conv_elfvalue_t val,
61*9273SAli.Bahrami@Sun.COM     Conv_fmt_flags_t flags, size_t num_msg, const Msg *msg,
62*9273SAli.Bahrami@Sun.COM     const char *local_sgs_msg)
630Sstevel@tonic-gate {
64*9273SAli.Bahrami@Sun.COM 	if ((val < num_msg) && (msg[val] != 0))
65*9273SAli.Bahrami@Sun.COM 		return (MSG_ORIG_STRTAB(msg[val], local_sgs_msg));
660Sstevel@tonic-gate 
67*9273SAli.Bahrami@Sun.COM 	/* If we get here, it's an unknown value */
68*9273SAli.Bahrami@Sun.COM 	return (conv_invalid_val(inv_buf, val, flags));
690Sstevel@tonic-gate }
701618Srie 
711618Srie /*
72*9273SAli.Bahrami@Sun.COM  * Map an integer into a descriptive string from a NULL terminated
73*9273SAli.Bahrami@Sun.COM  * array of Val_desc or Val_desc2 descriptors.
742352Sab196087  *
752352Sab196087  * entry:
76*9273SAli.Bahrami@Sun.COM  *	inv_buf - A buffer into which this routine can format
77*9273SAli.Bahrami@Sun.COM  *		a result string, if necessary.
78*9273SAli.Bahrami@Sun.COM  *	osabi,mach (_conv_vd22str only) - The osab/mach under which
79*9273SAli.Bahrami@Sun.COM  *		val is to be interpreted. Items with a non-0 osabi or machine
80*9273SAli.Bahrami@Sun.COM  *		that do not match are quietly ignored.
81*9273SAli.Bahrami@Sun.COM  *	val - The value for which a string is desired.
82*9273SAli.Bahrami@Sun.COM  *	flags - CONV_FMT_* values to be passed to conv_invalid_val() if
83*9273SAli.Bahrami@Sun.COM  *		necessary. The caller is reponsible for having examined
84*9273SAli.Bahrami@Sun.COM  *		the CONV_FMT_ALT_* part of flags and passing the proper
85*9273SAli.Bahrami@Sun.COM  *		descriptor array.
86*9273SAli.Bahrami@Sun.COM  *	vdp - Pointer to NULL terminated array of Val_desc descriptors.
87*9273SAli.Bahrami@Sun.COM  *	local_sgs_msg - Message string table from module from which
88*9273SAli.Bahrami@Sun.COM  *		this function is called.
892352Sab196087  *
902352Sab196087  * exit:
91*9273SAli.Bahrami@Sun.COM  *	If val is found in the vdp array, and in the osabi version of
92*9273SAli.Bahrami@Sun.COM  *	this function if the osabi matches, then the string corresponding
93*9273SAli.Bahrami@Sun.COM  *	val is returned. If a string for val is not found, conv_invalid_val()
94*9273SAli.Bahrami@Sun.COM  *	is called to format an ASCII representation of it into inv_buf, and
95*9273SAli.Bahrami@Sun.COM  *	that is returned.
962352Sab196087  */
97*9273SAli.Bahrami@Sun.COM /*ARGSUSED4*/
98*9273SAli.Bahrami@Sun.COM static const char *
99*9273SAli.Bahrami@Sun.COM map_vd2str(Conv_inv_buf_t *inv_buf, Conv_elfvalue_t val,
100*9273SAli.Bahrami@Sun.COM     Conv_fmt_flags_t flags, const Val_desc *vdp, const char *local_sgs_msg)
1012352Sab196087 {
102*9273SAli.Bahrami@Sun.COM 	for (; vdp->v_msg; vdp++) {
103*9273SAli.Bahrami@Sun.COM 		if (val == vdp->v_val)
104*9273SAli.Bahrami@Sun.COM 			return (MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg));
1052352Sab196087 	}
1062352Sab196087 
107*9273SAli.Bahrami@Sun.COM 	/* If we get here, it's an unknown value */
108*9273SAli.Bahrami@Sun.COM 	return (conv_invalid_val(inv_buf, val, flags));
109*9273SAli.Bahrami@Sun.COM }
110*9273SAli.Bahrami@Sun.COM 
111*9273SAli.Bahrami@Sun.COM /*ARGSUSED6*/
112*9273SAli.Bahrami@Sun.COM static const char *
113*9273SAli.Bahrami@Sun.COM map_vd22str(Conv_inv_buf_t *inv_buf, uchar_t osabi, Half mach,
114*9273SAli.Bahrami@Sun.COM     Conv_elfvalue_t val, Conv_fmt_flags_t flags, const Val_desc2 *vdp,
115*9273SAli.Bahrami@Sun.COM     const char *local_sgs_msg)
116*9273SAli.Bahrami@Sun.COM {
117*9273SAli.Bahrami@Sun.COM 	for (; vdp->v_msg; vdp++) {
118*9273SAli.Bahrami@Sun.COM 		if (CONV_VD2_SKIP(osabi, mach, vdp))
119*9273SAli.Bahrami@Sun.COM 			continue;
120*9273SAli.Bahrami@Sun.COM 
121*9273SAli.Bahrami@Sun.COM 		if (val == vdp->v_val)
122*9273SAli.Bahrami@Sun.COM 			return (MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg));
1232352Sab196087 	}
1242352Sab196087 
125*9273SAli.Bahrami@Sun.COM 	/* If we get here, it's an unknown value */
126*9273SAli.Bahrami@Sun.COM 	return (conv_invalid_val(inv_buf, val, flags));
1272352Sab196087 }
1282352Sab196087 
1292352Sab196087 /*
130*9273SAli.Bahrami@Sun.COM  * Process an array of conv_ds_XXX_t structures and call the appropriate
131*9273SAli.Bahrami@Sun.COM  * map functions for the format of the strings given.
1321618Srie  */
133*9273SAli.Bahrami@Sun.COM const char *
134*9273SAli.Bahrami@Sun.COM _conv_map_ds(uchar_t osabi, Half mach, Conv_elfvalue_t value,
135*9273SAli.Bahrami@Sun.COM     const conv_ds_t **dsp, Conv_fmt_flags_t fmt_flags, Conv_inv_buf_t *inv_buf,
136*9273SAli.Bahrami@Sun.COM     const char *local_sgs_msg)
1371618Srie {
138*9273SAli.Bahrami@Sun.COM 	const conv_ds_t *ds;
139*9273SAli.Bahrami@Sun.COM 
140*9273SAli.Bahrami@Sun.COM 	for (ds = *dsp; ds != NULL; ds = *(++dsp)) {
141*9273SAli.Bahrami@Sun.COM 		if ((value < ds->ds_baseval) || (value > ds->ds_topval))
142*9273SAli.Bahrami@Sun.COM 			continue;
1432352Sab196087 
144*9273SAli.Bahrami@Sun.COM 		switch (ds->ds_type) {
145*9273SAli.Bahrami@Sun.COM 		case CONV_DS_MSGARR:
146*9273SAli.Bahrami@Sun.COM 			return (map_msg2str(inv_buf, value - ds->ds_baseval,
147*9273SAli.Bahrami@Sun.COM 			    fmt_flags, ds->ds_topval - ds->ds_baseval + 1,
148*9273SAli.Bahrami@Sun.COM 			    /*LINTED*/
149*9273SAli.Bahrami@Sun.COM 			    ((conv_ds_msg_t *)ds)->ds_msg,
150*9273SAli.Bahrami@Sun.COM 			    local_sgs_msg));
1512352Sab196087 
152*9273SAli.Bahrami@Sun.COM 		case CONV_DS_VD:
153*9273SAli.Bahrami@Sun.COM 			return (map_vd2str(inv_buf, value, fmt_flags,
154*9273SAli.Bahrami@Sun.COM 			    /*LINTED*/
155*9273SAli.Bahrami@Sun.COM 			    ((conv_ds_vd_t *)ds)->ds_vd,
156*9273SAli.Bahrami@Sun.COM 			    local_sgs_msg));
1572352Sab196087 
158*9273SAli.Bahrami@Sun.COM 		case CONV_DS_VD2:
159*9273SAli.Bahrami@Sun.COM 			return (map_vd22str(inv_buf, osabi, mach, value,
160*9273SAli.Bahrami@Sun.COM 			    fmt_flags,
161*9273SAli.Bahrami@Sun.COM 			    /*LINTED*/
162*9273SAli.Bahrami@Sun.COM 			    ((conv_ds_vd2_t *)ds)->ds_vd2,
163*9273SAli.Bahrami@Sun.COM 			    local_sgs_msg));
1642352Sab196087 		}
1652352Sab196087 	}
1661618Srie 
167*9273SAli.Bahrami@Sun.COM 	return (conv_invalid_val(inv_buf, value, fmt_flags));
168*9273SAli.Bahrami@Sun.COM }
169*9273SAli.Bahrami@Sun.COM 
170*9273SAli.Bahrami@Sun.COM /*
171*9273SAli.Bahrami@Sun.COM  * Iterate over every message string in a given array of Msg codes,
172*9273SAli.Bahrami@Sun.COM  * calling a user supplied callback for each one.
173*9273SAli.Bahrami@Sun.COM  *
174*9273SAli.Bahrami@Sun.COM  * entry:
175*9273SAli.Bahrami@Sun.COM  *	basevalue - Value corresponding to the first Msg in the array.
176*9273SAli.Bahrami@Sun.COM  *	local_sgs_msg - Pointer to the __sgs_msg array for the
177*9273SAli.Bahrami@Sun.COM  *		libconv module making the call.
178*9273SAli.Bahrami@Sun.COM  *	num_msg - # of items in array referenced by msg
179*9273SAli.Bahrami@Sun.COM  *	msg - Array of Msg indexes for the strings to iterate over.
180*9273SAli.Bahrami@Sun.COM  *		The value corresponding to each element of msg must be:
181*9273SAli.Bahrami@Sun.COM  *			value[i] = basevalue + i
182*9273SAli.Bahrami@Sun.COM  *	func, uvalue - User supplied function to be called for each
183*9273SAli.Bahrami@Sun.COM  *		string in msg. uvalue is an arbitrary user supplied pointer
184*9273SAli.Bahrami@Sun.COM  *		to be passed to func.
185*9273SAli.Bahrami@Sun.COM  *	local_sgs_msg - Pointer to the __sgs_msg array for the
186*9273SAli.Bahrami@Sun.COM  *		libconv module making the call.
187*9273SAli.Bahrami@Sun.COM  *
188*9273SAli.Bahrami@Sun.COM  * exit:
189*9273SAli.Bahrami@Sun.COM  *	The callback function is called for every non-zero item in
190*9273SAli.Bahrami@Sun.COM  *	msg[]. If any callback returns CONV_ITER_DONE, execution stops
191*9273SAli.Bahrami@Sun.COM  *	with that item and the function returns immediately. Otherwise,
192*9273SAli.Bahrami@Sun.COM  *	it continues to the end of the array.
193*9273SAli.Bahrami@Sun.COM  *
194*9273SAli.Bahrami@Sun.COM  *	The value from the last callback is returned.
195*9273SAli.Bahrami@Sun.COM  */
196*9273SAli.Bahrami@Sun.COM /*ARGSUSED5*/
197*9273SAli.Bahrami@Sun.COM static conv_iter_ret_t
198*9273SAli.Bahrami@Sun.COM _conv_iter_msgarr(uint32_t basevalue, const Msg *msg, size_t num_msg,
199*9273SAli.Bahrami@Sun.COM     conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
200*9273SAli.Bahrami@Sun.COM {
201*9273SAli.Bahrami@Sun.COM 	for (; num_msg-- > 0; basevalue++, msg++) {
202*9273SAli.Bahrami@Sun.COM 		if (*msg != 0)
203*9273SAli.Bahrami@Sun.COM 			if ((* func)(MSG_ORIG_STRTAB(*msg, local_sgs_msg),
204*9273SAli.Bahrami@Sun.COM 			    basevalue, uvalue) == CONV_ITER_DONE)
205*9273SAli.Bahrami@Sun.COM 				return (CONV_ITER_DONE);
206*9273SAli.Bahrami@Sun.COM 	}
207*9273SAli.Bahrami@Sun.COM 
208*9273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
209*9273SAli.Bahrami@Sun.COM }
2101618Srie 
211*9273SAli.Bahrami@Sun.COM /*
212*9273SAli.Bahrami@Sun.COM  * Iterate over every message string in a given array of Val_desc or
213*9273SAli.Bahrami@Sun.COM  * Val_desc2 descriptors, calling a user supplied callback for each one.
214*9273SAli.Bahrami@Sun.COM  *
215*9273SAli.Bahrami@Sun.COM  * entry:
216*9273SAli.Bahrami@Sun.COM  *	osabi,mach (_conv_iter_vd2 only) - The osabi/mach for which
217*9273SAli.Bahrami@Sun.COM  *		strings are desired. Strings with a non-0 osabi or machine
218*9273SAli.Bahrami@Sun.COM  *		that do not match are quietly ignored.
219*9273SAli.Bahrami@Sun.COM  *	vdp - Pointer to NULL terminated array of Val_desc descriptors.
220*9273SAli.Bahrami@Sun.COM  *	func, uvalue - User supplied function to be called for each
221*9273SAli.Bahrami@Sun.COM  *		string in msg. uvalue is an arbitrary user supplied pointer
222*9273SAli.Bahrami@Sun.COM  *		to be passed to func.
223*9273SAli.Bahrami@Sun.COM  *	local_sgs_msg - Pointer to the __sgs_msg array for the
224*9273SAli.Bahrami@Sun.COM  *		libconv module making the call.
225*9273SAli.Bahrami@Sun.COM  *
226*9273SAli.Bahrami@Sun.COM  * exit:
227*9273SAli.Bahrami@Sun.COM  *	The callback function is called for every descriptor referenced by
228*9273SAli.Bahrami@Sun.COM  *	vdp. In the case of the OSABI-version of this function, strings from
229*9273SAli.Bahrami@Sun.COM  *	the wrong osabi are not used. If any callback returns CONV_ITER_DONE,
230*9273SAli.Bahrami@Sun.COM  *	execution stops with that item and the function returns immediately.
231*9273SAli.Bahrami@Sun.COM  *	Otherwise, it continues to the end of the array.
232*9273SAli.Bahrami@Sun.COM  *
233*9273SAli.Bahrami@Sun.COM  *	The value from the last callback is returned.
234*9273SAli.Bahrami@Sun.COM  */
235*9273SAli.Bahrami@Sun.COM /*ARGSUSED3*/
236*9273SAli.Bahrami@Sun.COM conv_iter_ret_t
237*9273SAli.Bahrami@Sun.COM _conv_iter_vd(const Val_desc *vdp, conv_iter_cb_t func, void *uvalue,
238*9273SAli.Bahrami@Sun.COM     const char *local_sgs_msg)
239*9273SAli.Bahrami@Sun.COM {
240*9273SAli.Bahrami@Sun.COM 	for (; vdp->v_msg; vdp++) {
241*9273SAli.Bahrami@Sun.COM 		if ((* func)(MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg),
242*9273SAli.Bahrami@Sun.COM 		    vdp->v_val, uvalue) == CONV_ITER_DONE)
243*9273SAli.Bahrami@Sun.COM 			return (CONV_ITER_DONE);
244*9273SAli.Bahrami@Sun.COM 	}
245*9273SAli.Bahrami@Sun.COM 
246*9273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
247*9273SAli.Bahrami@Sun.COM }
248*9273SAli.Bahrami@Sun.COM 
249*9273SAli.Bahrami@Sun.COM /*ARGSUSED5*/
250*9273SAli.Bahrami@Sun.COM conv_iter_ret_t
251*9273SAli.Bahrami@Sun.COM _conv_iter_vd2(conv_iter_osabi_t osabi, Half mach, const Val_desc2 *vdp,
252*9273SAli.Bahrami@Sun.COM     conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
253*9273SAli.Bahrami@Sun.COM {
254*9273SAli.Bahrami@Sun.COM 	for (; vdp->v_msg; vdp++) {
255*9273SAli.Bahrami@Sun.COM 		if (CONV_ITER_VD2_SKIP(osabi, mach, vdp))
256*9273SAli.Bahrami@Sun.COM 			continue;
257*9273SAli.Bahrami@Sun.COM 
258*9273SAli.Bahrami@Sun.COM 		if ((* func)(MSG_ORIG_STRTAB(vdp->v_msg, local_sgs_msg),
259*9273SAli.Bahrami@Sun.COM 		    vdp->v_val, uvalue) == CONV_ITER_DONE)
260*9273SAli.Bahrami@Sun.COM 			return (CONV_ITER_DONE);
261*9273SAli.Bahrami@Sun.COM 	}
262*9273SAli.Bahrami@Sun.COM 
263*9273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
264*9273SAli.Bahrami@Sun.COM }
265*9273SAli.Bahrami@Sun.COM 
266*9273SAli.Bahrami@Sun.COM /*
267*9273SAli.Bahrami@Sun.COM  * Process an array of conv_ds_XXX_t structures and call the appropriate
268*9273SAli.Bahrami@Sun.COM  * iteration functions for the format of the strings given.
269*9273SAli.Bahrami@Sun.COM  */
270*9273SAli.Bahrami@Sun.COM conv_iter_ret_t
271*9273SAli.Bahrami@Sun.COM _conv_iter_ds(conv_iter_osabi_t osabi, Half mach, const conv_ds_t **dsp,
272*9273SAli.Bahrami@Sun.COM     conv_iter_cb_t func, void *uvalue, const char *local_sgs_msg)
273*9273SAli.Bahrami@Sun.COM {
274*9273SAli.Bahrami@Sun.COM 	const conv_ds_t *ds;
275*9273SAli.Bahrami@Sun.COM 
276*9273SAli.Bahrami@Sun.COM 	for (ds = *dsp; ds != NULL; ds = *(++dsp)) {
277*9273SAli.Bahrami@Sun.COM 		switch (ds->ds_type) {
278*9273SAli.Bahrami@Sun.COM 		case CONV_DS_MSGARR:
279*9273SAli.Bahrami@Sun.COM 			if (_conv_iter_msgarr(ds->ds_baseval,
280*9273SAli.Bahrami@Sun.COM 			    /*LINTED*/
281*9273SAli.Bahrami@Sun.COM 			    ((conv_ds_msg_t *)ds)->ds_msg,
282*9273SAli.Bahrami@Sun.COM 			    ds->ds_topval - ds->ds_baseval + 1, func, uvalue,
283*9273SAli.Bahrami@Sun.COM 			    local_sgs_msg) == CONV_ITER_DONE)
284*9273SAli.Bahrami@Sun.COM 				return (CONV_ITER_DONE);
285*9273SAli.Bahrami@Sun.COM 			break;
286*9273SAli.Bahrami@Sun.COM 
287*9273SAli.Bahrami@Sun.COM 		case CONV_DS_VD:
288*9273SAli.Bahrami@Sun.COM 			/*LINTED*/
289*9273SAli.Bahrami@Sun.COM 			if (_conv_iter_vd(((conv_ds_vd_t *)ds)->ds_vd,
290*9273SAli.Bahrami@Sun.COM 			    func, uvalue, local_sgs_msg) == CONV_ITER_DONE)
291*9273SAli.Bahrami@Sun.COM 				return (CONV_ITER_DONE);
292*9273SAli.Bahrami@Sun.COM 			break;
293*9273SAli.Bahrami@Sun.COM 
294*9273SAli.Bahrami@Sun.COM 		case CONV_DS_VD2:
295*9273SAli.Bahrami@Sun.COM 			if (_conv_iter_vd2(osabi, mach,
296*9273SAli.Bahrami@Sun.COM 			    /*LINTED*/
297*9273SAli.Bahrami@Sun.COM 			    ((conv_ds_vd2_t *)ds)->ds_vd2,
298*9273SAli.Bahrami@Sun.COM 			    func, uvalue, local_sgs_msg) == CONV_ITER_DONE)
299*9273SAli.Bahrami@Sun.COM 				return (CONV_ITER_DONE);
300*9273SAli.Bahrami@Sun.COM 			break;
3011618Srie 		}
3021618Srie 	}
3031618Srie 
304*9273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);
305*9273SAli.Bahrami@Sun.COM }
306*9273SAli.Bahrami@Sun.COM 
307*9273SAli.Bahrami@Sun.COM /*
308*9273SAli.Bahrami@Sun.COM  * Initialize the uvalue block prior to use of an interation function
309*9273SAli.Bahrami@Sun.COM  * employing conv_iter_strtol().
310*9273SAli.Bahrami@Sun.COM  *
311*9273SAli.Bahrami@Sun.COM  * entry:
312*9273SAli.Bahrami@Sun.COM  *	str - String to be matched to a value
313*9273SAli.Bahrami@Sun.COM  *	uvalue - Pointer to uninitialized uvalue block
314*9273SAli.Bahrami@Sun.COM  *
315*9273SAli.Bahrami@Sun.COM  * exit:
316*9273SAli.Bahrami@Sun.COM  *	Initializes the uvalue block for use. Returns True (1) if a non-empty
317*9273SAli.Bahrami@Sun.COM  *	string was supplied, and False (0).
318*9273SAli.Bahrami@Sun.COM  */
319*9273SAli.Bahrami@Sun.COM int
320*9273SAli.Bahrami@Sun.COM conv_iter_strtol_init(const char *str, conv_strtol_uvalue_t *uvalue)
321*9273SAli.Bahrami@Sun.COM {
322*9273SAli.Bahrami@Sun.COM 	const char	*tail;
323*9273SAli.Bahrami@Sun.COM 
324*9273SAli.Bahrami@Sun.COM 	while (isspace(*str))
325*9273SAli.Bahrami@Sun.COM 		str++;
326*9273SAli.Bahrami@Sun.COM 	uvalue->csl_str = str;
327*9273SAli.Bahrami@Sun.COM 	uvalue->csl_found = 0;
3281618Srie 
329*9273SAli.Bahrami@Sun.COM 	tail = str + strlen(str);
330*9273SAli.Bahrami@Sun.COM 	while ((tail > str) && isspace(*(tail - 1)))
331*9273SAli.Bahrami@Sun.COM 		tail--;
332*9273SAli.Bahrami@Sun.COM 	uvalue->csl_strlen = tail - str;
333*9273SAli.Bahrami@Sun.COM 
334*9273SAli.Bahrami@Sun.COM 	return (uvalue->csl_strlen > 0);
335*9273SAli.Bahrami@Sun.COM }
336*9273SAli.Bahrami@Sun.COM 
337*9273SAli.Bahrami@Sun.COM /*
338*9273SAli.Bahrami@Sun.COM  * conv_iter_strtol() is used with iteration functions to map a string
339*9273SAli.Bahrami@Sun.COM  * to the value of its corresponding ELF constant.
340*9273SAli.Bahrami@Sun.COM  *
341*9273SAli.Bahrami@Sun.COM  * entry:
342*9273SAli.Bahrami@Sun.COM  *	str - String supplied by this iteration
343*9273SAli.Bahrami@Sun.COM  *	value - Value of ELF constant corresponding to str
344*9273SAli.Bahrami@Sun.COM  *	uvalue - Pointer to conv_strtol_uvalue_t block previously
345*9273SAli.Bahrami@Sun.COM  *		initialized by a call to conv_iter_strtol_init().
346*9273SAli.Bahrami@Sun.COM  */
347*9273SAli.Bahrami@Sun.COM conv_iter_ret_t
348*9273SAli.Bahrami@Sun.COM conv_iter_strtol(const char *str, uint32_t value, void *uvalue)
349*9273SAli.Bahrami@Sun.COM {
350*9273SAli.Bahrami@Sun.COM 	conv_strtol_uvalue_t *state = (conv_strtol_uvalue_t *)uvalue;
351*9273SAli.Bahrami@Sun.COM 
352*9273SAli.Bahrami@Sun.COM 	if ((strlen(str) == state->csl_strlen) &&
353*9273SAli.Bahrami@Sun.COM 	    (strncasecmp(str, state->csl_str, state->csl_strlen) == 0)) {
354*9273SAli.Bahrami@Sun.COM 		state->csl_found = 1;
355*9273SAli.Bahrami@Sun.COM 		state->csl_value = value;
356*9273SAli.Bahrami@Sun.COM 		return (CONV_ITER_DONE);	/* Found it. Stop now. */
3571618Srie 	}
3581618Srie 
359*9273SAli.Bahrami@Sun.COM 	return (CONV_ITER_CONT);		/* Keep looking */
3601618Srie }
361