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