4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * CDDL HEADER START
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * The contents of this file are subject to the terms of the
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Common Development and Distribution License (the "License").
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * You may not use this file except in compliance with the License.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * See the License for the specific language governing permissions
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * and limitations under the License.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * When distributing Covered Code, include this CDDL HEADER in each
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * If applicable, add the following below this CDDL HEADER, with the
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * fields enclosed by brackets "[]" replaced with your own identifying
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * information: Portions Copyright [yyyy] [name of copyright owner]
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * CDDL HEADER END
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Use is subject to license terms.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Given an integer value, generate an ASCII representation of it.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * inv_buf - Buffer into which the resulting string is generated.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * value - Value to be formatted.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * fmt_flags - CONV_FMT_* values, used to specify formatting details.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * The formatted string is placed into inv_buf. The pointer
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * to the string is returned.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramiconv_invalid_val(Conv_inv_buf_t *inv_buf, Xword value,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami (void) snprintf(inv_buf->buf, sizeof (inv_buf->buf), fmt, value);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * cef_cp() is used by conv_expn_field() to fill in the output buffer.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * A CONV_EXPN_FIELD_STATE variable is used to maintain the buffer state
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * as the operation progresses.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * arg - As passed to conv_expn_field().
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * state - Variable used to maintain buffer state between calls.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * list_item - TRUE(1) if this is a list item, and FALSE(0)
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * if it is something else.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * str - String to be added to the buffer.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * On Success:
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * buffer contains the output string, including a list
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * separator if appropriate. state has been updated.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * TRUE(1) is returned.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * On Failure:
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Buffer contains the numeric representation for the flags,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * and FALSE(0) is returned.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramitypedef struct {
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami int list_cnt; /* # of list items output into buf */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami const char *sep_str; /* String used as list separator */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramicef_cp(CONV_EXPN_FIELD_ARG *arg, CONV_EXPN_FIELD_STATE *state,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * If list is non-empty, and the buffer has room,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * then insert the separator.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Ensure code below will catch lack of room */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Buffer too small. Fill in the numeric value and report failure */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami (void) conv_invalid_val(&inv_buf, arg->oflags, 0);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami (void) strlcpy(arg->buf, inv_buf.buf, arg->bufsize);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Common setup code for conv_expn_field() and conv_expn_field2()
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramicef_setup(CONV_EXPN_FIELD_ARG *arg, Conv_fmt_flags_t fmt_flags,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Initialize buffer state */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami state->sep_str = arg->sep ? arg->sep : MSG_ORIG(MSG_GBL_SEP);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Prefix string */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami (arg->prefix ? arg->prefix : MSG_ORIG(MSG_GBL_OSQBRKT))))
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Any strings in the lead_str array go at the head of the list */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Common finishing code for conv_expn_field() and conv_expn_field2()
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahramicef_wrap(CONV_EXPN_FIELD_ARG *arg, Conv_fmt_flags_t fmt_flags,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * If any flags remain, then they are unidentified. Add the numeric
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * representation of these flags to the users output buffer.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami (void) conv_invalid_val(&inv_buf, rflags, fmt_flags);
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Suffix string */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami (arg->suffix ? arg->suffix : MSG_ORIG(MSG_GBL_CSQBRKT))))
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Terminate the buffer */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Provide a focal point for expanding bit-fields values into
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * their corresponding strings.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * arg - Specifies the operation to be carried out. See the
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * definition of CONV_EXPN_FIELD_ARG in conv.h for details.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * vdp - Array of value descriptors, giving the possible bit values,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * and their corresponding strings. Note that the final element
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * must contain only NULL values. This terminates the list.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * arg->buf contains the formatted result. True (1) is returned if there
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * was no error, and False (0) if the buffer was too small. In the failure
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * case, arg->buf contains a numeric representation of the value.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * The Val_desc2 variant of this routine ignores entries from vdp that
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * have a non-zero osabi or machine value that does not match that
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * supplied by the caller.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami/*ARGSUSED3*/
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami_conv_expn_field(CONV_EXPN_FIELD_ARG *arg, const Val_desc *vdp,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami Conv_fmt_flags_t fmt_flags, const char *local_sgs_msg)
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Traverse the callers Val_desc array and determine if the value
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * corresponds to any array item and add those that are to the list.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Indicate this item has been collected */
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami return (cef_wrap(arg, fmt_flags, &state, rflags));
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami/*ARGSUSED5*/
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami_conv_expn_field2(CONV_EXPN_FIELD_ARG *arg, uchar_t osabi, Half mach,
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami const Val_desc2 *vdp, Conv_fmt_flags_t fmt_flags, const char *local_sgs_msg)
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * Traverse the callers Val_desc array and determine if the value
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami * corresponds to any array item and add those that are to the list.
4f680cc668fa6cf678c531083400ade9a9c7934cAli Bahrami /* Indicate this item has been collected */