17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 2001 by Sun Microsystems, Inc.
37c478bd9Sstevel@tonic-gate  * All rights reserved.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
6*1da57d55SToomas Soome /*
77c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
87c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
97c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
107c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
11*1da57d55SToomas Soome  *
127c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
137c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
147c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
157c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
16*1da57d55SToomas Soome  *
177c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
187c478bd9Sstevel@tonic-gate  * March 31, 1998.
19*1da57d55SToomas Soome  *
207c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
217c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
227c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
237c478bd9Sstevel@tonic-gate  * Rights Reserved.
24*1da57d55SToomas Soome  *
25*1da57d55SToomas Soome  * Contributor(s):
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /* bprint.c - a printing utility for debuging output */
297c478bd9Sstevel@tonic-gate #include <string.h>
307c478bd9Sstevel@tonic-gate #include "lber-int.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef LDAP_DEBUG
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Print arbitrary stuff, for debugging.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #define BPLEN	48
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate void
lber_bprint(char * data,int len)407c478bd9Sstevel@tonic-gate lber_bprint( char *data, int len )
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate     static char	hexdig[] = "0123456789abcdef";
437c478bd9Sstevel@tonic-gate     char	out[ BPLEN ];
447c478bd9Sstevel@tonic-gate     int		i = 0;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate     memset( out, 0, BPLEN );
477c478bd9Sstevel@tonic-gate     for ( ;; ) {
487c478bd9Sstevel@tonic-gate 	if ( len < 1 ) {
497c478bd9Sstevel@tonic-gate 		char msg[BPLEN + 80];
507c478bd9Sstevel@tonic-gate 	    sprintf( msg, "\t%s\n", ( i == 0 ) ? "(end)" : out );
517c478bd9Sstevel@tonic-gate 		ber_err_print( msg );
527c478bd9Sstevel@tonic-gate 	    break;
537c478bd9Sstevel@tonic-gate 	}
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #ifndef HEX
567c478bd9Sstevel@tonic-gate 	if ( isgraph( (unsigned char)*data )) {
577c478bd9Sstevel@tonic-gate 	    out[ i ] = ' ';
587c478bd9Sstevel@tonic-gate 	    out[ i+1 ] = *data;
597c478bd9Sstevel@tonic-gate 	} else {
607c478bd9Sstevel@tonic-gate #endif
617c478bd9Sstevel@tonic-gate 	    out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
627c478bd9Sstevel@tonic-gate 	    out[ i+1 ] = hexdig[ *data & 0x0f ];
637c478bd9Sstevel@tonic-gate #ifndef HEX
647c478bd9Sstevel@tonic-gate 	}
657c478bd9Sstevel@tonic-gate #endif
667c478bd9Sstevel@tonic-gate 	i += 2;
677c478bd9Sstevel@tonic-gate 	len--;
687c478bd9Sstevel@tonic-gate 	data++;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	if ( i > BPLEN - 2 ) {
717c478bd9Sstevel@tonic-gate 		char msg[BPLEN + 80];
727c478bd9Sstevel@tonic-gate 	    sprintf( msg, "\t%s\n", out );
737c478bd9Sstevel@tonic-gate 		ber_err_print( msg );
747c478bd9Sstevel@tonic-gate 	    memset( out, 0, BPLEN );
757c478bd9Sstevel@tonic-gate 	    i = 0;
767c478bd9Sstevel@tonic-gate 	    continue;
777c478bd9Sstevel@tonic-gate 	}
787c478bd9Sstevel@tonic-gate 	out[ i++ ] = ' ';
797c478bd9Sstevel@tonic-gate     }
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #endif
837c478bd9Sstevel@tonic-gate 
ber_err_print(char * data)847c478bd9Sstevel@tonic-gate void ber_err_print( char *data )
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate #ifdef USE_DEBUG_WIN
877c478bd9Sstevel@tonic-gate 	OutputDebugString( data );
887c478bd9Sstevel@tonic-gate #else
897c478bd9Sstevel@tonic-gate 	fputs( data, stderr );
907c478bd9Sstevel@tonic-gate 	fflush( stderr );
917c478bd9Sstevel@tonic-gate #endif
927c478bd9Sstevel@tonic-gate }
93