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