1189341Sbms/* 2189341Sbms * Copyright (c) 1983, 1993 3189341Sbms * The Regents of the University of California. All rights reserved. 4189341Sbms * 5189341Sbms * Redistribution and use in source and binary forms, with or without 6189341Sbms * modification, are permitted provided that the following conditions 7189341Sbms * are met: 8189341Sbms * 1. Redistributions of source code must retain the above copyright 9189341Sbms * notice, this list of conditions and the following disclaimer. 10189341Sbms * 2. Redistributions in binary form must reproduce the above copyright 11189341Sbms * notice, this list of conditions and the following disclaimer in the 12189341Sbms * documentation and/or other materials provided with the distribution. 13189341Sbms * 4. Neither the name of the University nor the names of its contributors 14189341Sbms * may be used to endorse or promote products derived from this software 15189341Sbms * without specific prior written permission. 16189341Sbms * 17189341Sbms * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18189341Sbms * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19189341Sbms * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20189341Sbms * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21189341Sbms * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22189341Sbms * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23189341Sbms * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24189341Sbms * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25189341Sbms * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26189341Sbms * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27189341Sbms * SUCH DAMAGE. 28189341Sbms */ 29189341Sbms 30189341Sbms#include <sys/cdefs.h> 31189341Sbms__FBSDID("$FreeBSD: releng/10.3/usr.sbin/ifmcstat/printb.c 189341 2009-03-04 02:12:29Z bms $"); 32189341Sbms 33189341Sbms#include <stdio.h> 34189341Sbms 35189341Sbms/* 36189341Sbms * Print a value a la the %b format of the kernel's printf 37189341Sbms */ 38189341Sbmsvoid 39189341Sbmsprintb(const char *s, unsigned int v, const char *bits) 40189341Sbms{ 41189341Sbms int i, any = 0; 42189341Sbms char c; 43189341Sbms 44189341Sbms if (bits && *bits == 8) 45189341Sbms printf("%s=%o", s, v); 46189341Sbms else 47189341Sbms printf("%s=%x", s, v); 48189341Sbms bits++; 49189341Sbms if (bits) { 50189341Sbms putchar('<'); 51189341Sbms while ((i = *bits++) != '\0') { 52189341Sbms if (v & (1 << (i-1))) { 53189341Sbms if (any) 54189341Sbms putchar(','); 55189341Sbms any = 1; 56189341Sbms for (; (c = *bits) > 32; bits++) 57189341Sbms putchar(c); 58189341Sbms } else 59189341Sbms for (; *bits > 32; bits++) 60189341Sbms ; 61189341Sbms } 62189341Sbms putchar('>'); 63189341Sbms } 64189341Sbms} 65