xref: /onnv-gate/usr/src/lib/libldap4/ber/bprint.c (revision 3857:21b9b714e4ab)
1 /*
2  * Portions Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include "lber.h"
12 
13 /*
14  * Print arbitrary stuff, for debugging.
15  */
16 
17 #ifdef LDAP_DEBUG
18 
19 #ifndef NO_USERINTERFACE
20 #define BPLEN	48
21 
22 void
lber_bprint(char * data,int len)23 lber_bprint( char *data, int len )
24 {
25     static char	hexdig[] = "0123456789abcdef";
26     char	out[ BPLEN ];
27     int		i = 0;
28 
29     (void) memset( out, 0, BPLEN );
30     for ( ;; ) {
31 	if ( len < 1 ) {
32 	    (void) fprintf( stderr, "\t%s\n", ( i == 0 ) ? catgets(slapdcat, 1, 72, "(end)") : out );
33 	    break;
34 	}
35 
36 #ifndef HEX
37 	if ( isgraph( (unsigned char)*data )) {
38 	    out[ i ] = ' ';
39 	    out[ i+1 ] = *data;
40 	} else {
41 #endif
42 	    out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
43 	    out[ i+1 ] = hexdig[ *data & 0x0f ];
44 #ifndef HEX
45 	}
46 #endif
47 	i += 2;
48 	len--;
49 	data++;
50 
51 	if ( i > BPLEN - 2 ) {
52 	    (void) fprintf( stderr, "\t%s\n", out );
53 	    (void) memset( out, 0, BPLEN );
54 	    i = 0;
55 	    continue;
56 	}
57 	out[ i++ ] = ' ';
58     }
59 }
60 #else /* NO_USERINTERFACE */
61 void
lber_bprint(char * data,int len)62 lber_bprint( char *data, int len )
63 {
64 }
65 #endif /* NO_USERINTERFACE */
66 
67 #endif
68