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