1 /*
2 * Copyright (c) 2001 by Sun Microsystems, Inc.
3 * All rights reserved.
4 */
5
6 #pragma ident "%Z%%M% %I% %E% SMI"
7
8 /*
9 * The contents of this file are subject to the Netscape Public
10 * License Version 1.1 (the "License"); you may not use this file
11 * except in compliance with the License. You may obtain a copy of
12 * the License at http://www.mozilla.org/NPL/
13 *
14 * Software distributed under the License is distributed on an "AS
15 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16 * implied. See the License for the specific language governing
17 * rights and limitations under the License.
18 *
19 * The Original Code is Mozilla Communicator client code, released
20 * March 31, 1998.
21 *
22 * The Initial Developer of the Original Code is Netscape
23 * Communications Corporation. Portions created by Netscape are
24 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25 * Rights Reserved.
26 *
27 * Contributor(s):
28 */
29
30 /* bprint.c - a printing utility for debuging output */
31 #include <string.h>
32 #include "lber-int.h"
33
34 #ifdef LDAP_DEBUG
35 /*
36 * Print arbitrary stuff, for debugging.
37 */
38
39 #define BPLEN 48
40
41 void
lber_bprint(char * data,int len)42 lber_bprint( char *data, int len )
43 {
44 static char hexdig[] = "0123456789abcdef";
45 char out[ BPLEN ];
46 int i = 0;
47
48 memset( out, 0, BPLEN );
49 for ( ;; ) {
50 if ( len < 1 ) {
51 char msg[BPLEN + 80];
52 sprintf( msg, "\t%s\n", ( i == 0 ) ? "(end)" : out );
53 ber_err_print( msg );
54 break;
55 }
56
57 #ifndef HEX
58 if ( isgraph( (unsigned char)*data )) {
59 out[ i ] = ' ';
60 out[ i+1 ] = *data;
61 } else {
62 #endif
63 out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
64 out[ i+1 ] = hexdig[ *data & 0x0f ];
65 #ifndef HEX
66 }
67 #endif
68 i += 2;
69 len--;
70 data++;
71
72 if ( i > BPLEN - 2 ) {
73 char msg[BPLEN + 80];
74 sprintf( msg, "\t%s\n", out );
75 ber_err_print( msg );
76 memset( out, 0, BPLEN );
77 i = 0;
78 continue;
79 }
80 out[ i++ ] = ' ';
81 }
82 }
83
84 #endif
85
ber_err_print(char * data)86 void ber_err_print( char *data )
87 {
88 #ifdef USE_DEBUG_WIN
89 OutputDebugString( data );
90 #else
91 fputs( data, stderr );
92 fflush( stderr );
93 #endif
94 }
95