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