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