]> git.sur5r.net Git - openldap/blob - libraries/liblber/bprint.c
1dbc833b99a98e806ad07abfb178c5eb39117960
[openldap] / libraries / liblber / bprint.c
1
2 #include "portable.h"
3
4 #if defined( LDAP_DEBUG ) && defined( LDAP_LIBUI )
5 #include <stdio.h>
6 #include <ctype.h>
7
8 #include <ac/string.h>
9 #endif /* LDAP_DEBUG && LDAP_LIBUI  */
10
11 #include "lber.h"
12
13 /*
14  * Print arbitrary stuff, for debugging.
15  */
16
17
18 void
19 lber_bprint( char *data, int len )
20 {
21 #if defined( LDAP_DEBUG ) && defined( LDAP_LIBUI )
22 #define BPLEN   48
23
24     static char hexdig[] = "0123456789abcdef";
25     char        out[ BPLEN ];
26     int         i = 0;
27
28     memset( out, 0, BPLEN );
29     for ( ;; ) {
30         if ( len < 1 ) {
31             fprintf( stderr, "\t%s\n", ( i == 0 ) ? "(end)" : out );
32             break;
33         }
34
35 #ifndef HEX
36         if ( isgraph( (unsigned char)*data )) {
37             out[ i ] = ' ';
38             out[ i+1 ] = *data;
39         } else {
40 #endif
41             out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
42             out[ i+1 ] = hexdig[ *data & 0x0f ];
43 #ifndef HEX
44         }
45 #endif
46         i += 2;
47         len--;
48         data++;
49
50         if ( i > BPLEN - 2 ) {
51             fprintf( stderr, "\t%s\n", out );
52             memset( out, 0, BPLEN );
53             i = 0;
54             continue;
55         }
56         out[ i++ ] = ' ';
57     }
58
59 #endif /* LDAP_DEBUG && LDAP_LIBUI  */
60 }
61