if ( flush_after_each_entry ) { fflush( stdout ); }
print_entry( ld, entry, attrsonly )    LDAP	*ld;    LDAPMessage	*entry;    int		attrsonly;{    char		*a, *dn, *ufn, tmpfname[ BUFSIZ ];    int			i, notascii;    BerElement		*ber;    struct berval	**bvals;    FILE		*tmpfp;#if defined( XP_WIN32 )	char	mode[20] = "w+b";#else	char	mode[20] = "w";#endif    dn = ldap_get_dn( ld, entry );    write_string_attr_value( "dn", dn, LDAPTOOL_WRITEVALOPT_SUPPRESS_NAME );    if ( includeufn ) {	ufn = ldap_dn2ufn( dn );	write_string_attr_value( "ufn", ufn,			LDAPTOOL_WRITEVALOPT_SUPPRESS_NAME );	free( ufn );    }    ldap_memfree( dn );    if ( use_psearch ) {	LDAPControl	**ectrls;	int		chgtype, chgnumpresent;	long		chgnum;	char		*prevdn, longbuf[ 128 ];	if ( ldap_get_entry_controls( ld, entry, &ectrls ) == LDAP_SUCCESS ) {	    if ( ldap_parse_entrychange_control( ld, ectrls, &chgtype,			&prevdn, &chgnumpresent, &chgnum ) == LDAP_SUCCESS ) {		write_string_attr_value(			LDAPTOOL_PSEARCH_ATTR_PREFIX "changeType",			changetype_num2string( chgtype ), 0 );		if ( chgnumpresent ) {		    sprintf( longbuf, "%ld", chgnum );		    write_string_attr_value(			    LDAPTOOL_PSEARCH_ATTR_PREFIX "changeNumber",			    longbuf, 0 );		}		if ( NULL != prevdn ) {		    write_string_attr_value(			    LDAPTOOL_PSEARCH_ATTR_PREFIX "previousDN",			    prevdn, 0 );		    ldap_memfree( prevdn );		}	    }	}    }    for ( a = ldap_first_attribute( ld, entry, &ber ); a != NULL;	    a = ldap_next_attribute( ld, entry, ber ) ) {	if ( ldap_charray_inlist(sortattr, a) &&            /* in the list*/	    skipsortattr[ldap_charray_position(sortattr, a)] ) {/* and skip it*/	    continue;                                       /* so skip it! */	}	if ( attrsonly ) {	    if ( ldif ) {		write_ldif_value( a, "", 0, 0 );	    } else {		printf( "%s\n", a );	    }	} else if (( bvals = ldap_get_values_len( ld, entry, a )) != NULL ) {	    for ( i = 0; bvals[i] != NULL; i++ ) {		if ( vals2tmp ) {#ifdef HAVE_SNPRINTF		    if ( snprintf( tmpfname, sizeof(tmpfname),			    "%s/ldapsearch-%s-XXXXXX",			    ldaptool_get_tmp_dir(), a ) < 0 ) {			perror( "snprintf tmpfname (attribute name too long?)" );			exit( LDAP_PARAM_ERROR );		    }#else		    sprintf( tmpfname, "%s/ldapsearch-%s-XXXXXX",			    ldaptool_get_tmp_dir(), a );#endif		    tmpfp = NULL;		    if ( LDAPTOOL_MKTEMP( tmpfname ) == NULL ) {			perror( tmpfname );		    } else if (( tmpfp = ldaptool_open_file( tmpfname, mode)) == NULL ) {			perror( tmpfname );		    } else if ( bvals[ i ]->bv_len > 0 &&			    fwrite( bvals[ i ]->bv_val,			    bvals[ i ]->bv_len, 1, tmpfp ) == 0 ) {			perror( tmpfname );		    } else if ( ldif ) {			if ( produce_file_urls ) {			    char	*url;			    if ( ldaptool_path2fileurl( tmpfname, &url ) !=				LDAPTOOL_FILEURL_SUCCESS ) {				    perror( "ldaptool_path2fileurl" );				} else {				    write_ldif_value( a, url, strlen( url ),					    LDIF_OPT_VALUE_IS_URL );				    free( url );				}			} else {			    write_ldif_value( a, tmpfname, strlen( tmpfname ),				    0 );			}		    } else {			printf( "%s%s%s\n", a, sep, tmpfname );		    }		    if ( tmpfp != NULL ) {			fclose( tmpfp );		    }		} else {		    notascii = 0;		    if ( !ldif && !allow_binary ) {			notascii = !ldaptool_berval_is_ascii( bvals[i] );		    }		    if ( ldif ) {			write_ldif_value( a, bvals[ i ]->bv_val,				bvals[ i ]->bv_len, 0 );		    } else {			printf( "%s%s%s\n", a, sep,				notascii ? "NOT ASCII" : bvals[ i ]->bv_val );		    }		}	    }	    ber_bvecfree( bvals );	}	ldap_memfree( a );    }    if ( ldap_get_lderrno( ld, NULL, NULL ) != LDAP_SUCCESS ) {	(void)ldaptool_print_lderror( ld, "ldap_first_attribute/ldap_next_attribute",		LDAPTOOL_CHECK4SSL_IF_APPROP );    }    if ( ber != NULL ) {	ber_free( ber, 0 );    }}