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 /* 231618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 241618Srie * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef __CONV_DOT_H 280Sstevel@tonic-gate #define __CONV_DOT_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate /* 330Sstevel@tonic-gate * Local include file for conversion library. 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate #include <conv.h> 360Sstevel@tonic-gate 370Sstevel@tonic-gate #ifdef __cplusplus 380Sstevel@tonic-gate extern "C" { 390Sstevel@tonic-gate #endif 400Sstevel@tonic-gate 410Sstevel@tonic-gate /* 421618Srie * Some format strings differ depending on whether they are used for 32-bit 431618Srie * or 64-bit values. 440Sstevel@tonic-gate */ 451618Srie #if defined(_ELF64) 461618Srie #define MSG_GBL_FMT_DEC MSG_GBL_FMT_DEC_64 471618Srie #define MSG_GBL_FMT_DECS MSG_GBL_FMT_DECS_64 481618Srie #define MSG_GBL_FMT_HEX MSG_GBL_FMT_HEX_64 491618Srie #define MSG_GBL_FMT_HEXS MSG_GBL_FMT_HEXS_64 501618Srie 511618Srie #define MSG_SYM_FMT_VAL MSG_SYM_FMT_VAL_64 521618Srie #else 531618Srie #define MSG_GBL_FMT_DEC MSG_GBL_FMT_DEC_32 541618Srie #define MSG_GBL_FMT_DECS MSG_GBL_FMT_DECS_32 551618Srie #define MSG_GBL_FMT_HEX MSG_GBL_FMT_HEX_32 561618Srie #define MSG_GBL_FMT_HEXS MSG_GBL_FMT_HEXS_32 571618Srie 581618Srie #define MSG_SYM_FMT_VAL MSG_SYM_FMT_VAL_32 591618Srie #endif 600Sstevel@tonic-gate 61*1976Sab196087 62*1976Sab196087 63*1976Sab196087 /* 64*1976Sab196087 * Map an integer into a descriptive string. 65*1976Sab196087 * 66*1976Sab196087 * entry: 67*1976Sab196087 * buf - A buffer into which this routine can format 68*1976Sab196087 * a result string, if necessary. 69*1976Sab196087 * bufsize - sizeof(buf) 70*1976Sab196087 * val - The value for which a string is desired. 71*1976Sab196087 * flags - CONV_FMT_* values, used to influence formatting of 72*1976Sab196087 * the resulting string. 73*1976Sab196087 * num_msg - # of Msg entries in msg, msg_altdump, and msg_altfile. 74*1976Sab196087 * msg - Array of num_msg Msg items corresponding to the possible 75*1976Sab196087 * strings corresponding to val. 76*1976Sab196087 * msg_altdump - NULL, or array of num_msg Msg items, to be used 77*1976Sab196087 * instead of msg when the CONV_FMT_ALTDUMP flag is set. 78*1976Sab196087 * msg_altfile - NULL, or array of num_msg Msg items, to be used 79*1976Sab196087 * instead of msg when the CONV_FMT_ALTFILE flag is set. 80*1976Sab196087 * 81*1976Sab196087 * exit: 82*1976Sab196087 * If val lies in the range [0-(num_msg-1)], then the string 83*1976Sab196087 * corresponding to it is returned: 84*1976Sab196087 * 1) If CONV_FMT_ALTDUMP is set and msg_altdump is non-NULL, 85*1976Sab196087 * the string comes from msg_altdump. 86*1976Sab196087 * 2) If CONV_FMT_ALTFILE is set and msg_altfile is non-NULL, 87*1976Sab196087 * the string comes from msg_altfile. 88*1976Sab196087 * 3) If neither of the previous rules holds, the string 89*1976Sab196087 * comes from msg. 90*1976Sab196087 * if val is outside the range, an ASCII representation of it is 91*1976Sab196087 * formatted into string, and that is returned. 92*1976Sab196087 * 93*1976Sab196087 * note: 94*1976Sab196087 * Ideally, this would be a function defined in globals.c. 95*1976Sab196087 * However, it uses the MSG_ORIG macro, which uses an array 96*1976Sab196087 * that is local to each module. Hence, this is a static function, 97*1976Sab196087 * defined by this macro. Once defined by a module, the routine 98*1976Sab196087 * is called normally. 99*1976Sab196087 */ 100*1976Sab196087 #define DEFINE_conv_map2str \ 101*1976Sab196087 static \ 102*1976Sab196087 const char * \ 103*1976Sab196087 conv_map2str(char *buf, size_t bufsize, int val, int flags, int num_msg, \ 104*1976Sab196087 const Msg *msg, const Msg *msg_altdump, const Msg *msg_altfile) \ 105*1976Sab196087 { \ 106*1976Sab196087 if ((val >= 0) && (val < num_msg)) { \ 107*1976Sab196087 if ((flags & CONV_FMT_ALTDUMP) && msg_altdump) { \ 108*1976Sab196087 return (MSG_ORIG(msg_altdump[val])); \ 109*1976Sab196087 } else if ((flags & CONV_FMT_ALTFILE) && msg_altfile) { \ 110*1976Sab196087 return (MSG_ORIG(msg_altfile[val])); \ 111*1976Sab196087 } else { \ 112*1976Sab196087 return (MSG_ORIG(msg[val])); \ 113*1976Sab196087 } \ 114*1976Sab196087 } \ 115*1976Sab196087 \ 116*1976Sab196087 /* If we get here, it's an unknown value */ \ 117*1976Sab196087 return (conv_invalid_val(buf, bufsize, val, flags)); \ 118*1976Sab196087 } 119*1976Sab196087 120*1976Sab196087 /* # of elements in an array */ 121*1976Sab196087 #define ARRAY_NELTS(arr) (sizeof (arr) / sizeof (*arr)) 122*1976Sab196087 123*1976Sab196087 124*1976Sab196087 1250Sstevel@tonic-gate #ifdef __cplusplus 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate #endif 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate #endif /* __CONV_DOT_H */ 130