BRL-CAD
printb.c
Go to the documentation of this file.
1 /* P R I N T B . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #include <stdio.h>
24 #include <math.h>
25 
26 #include "bu/bitv.h"
27 #include "bu/log.h"
28 #include "bu/vls.h"
29 
30 void
31 bu_vls_printb(struct bu_vls *vls, const char *s, register long unsigned int v, register const char *bits)
32 {
33  register int i, any = 0;
34  register char c;
35 
36  if (*bits++ == 8)
37  bu_vls_printf(vls, "%s=0%lo <", s, v);
38  else
39  bu_vls_printf(vls, "%s=x%lx <", s, v);
40  i = *bits++;
41  while (i) {
42  if (v & (1L << (i-1))) {
43  if (any)
44  bu_vls_strcat(vls, ",");
45  any = 1;
46  for (; (c = *bits) > 32; bits++)
47  bu_vls_printf(vls, "%c", c);
48  } else
49  for (; *bits > 32; bits++)
50  ;
51  i = *bits++;
52  }
53  bu_vls_strcat(vls, ">");
54 }
55 
56 
57 void
58 bu_printb(const char *s, register long unsigned int v, register const char *bits)
59 {
60  struct bu_vls str = BU_VLS_INIT_ZERO;
61 
62  bu_vls_printb(&str, s, v, bits);
63  bu_log("%s", bu_vls_addr(&str));
64  bu_vls_free(&str);
65 }
66 
67 /*
68  * Local Variables:
69  * mode: C
70  * tab-width: 8
71  * indent-tabs-mode: t
72  * c-file-style: "stroustrup"
73  * End:
74  * ex: shiftwidth=4 tabstop=8
75  */
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
void bu_vls_printb(struct bu_vls *vls, const char *s, register long unsigned int v, register const char *bits)
Definition: printb.c:31
if lu s
Definition: nmg_mod.c:3860
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
void bu_printb(const char *s, register long unsigned int v, register const char *bits)
Definition: printb.c:58
Header file for the BRL-CAD common definitions.
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...) _BU_ATTR_PRINTF23
Definition: vls.c:694
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
Definition: vls.h:56