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