optind = ldaptool_process_args( argc, argv, "ABLTU1eotuxa:b:F:G:l:S:s:z:C:", 0, options_callback );
optind = ldaptool_process_args( argc, argv, "ABLTU1eortuxa:b:F:G:l:S:s:z:C:", 0, options_callback );
main( int argc, char **argv ){    char		*filtpattern, **attrs;    int			rc, optind, i, first;    LDAP		*ld;    deref = LDAP_DEREF_NEVER;    allow_binary = vals2tmp = attrsonly = 0;    minimize_base64 = produce_file_urls = 0;    ldif = 1;    fold = 1;    sizelimit = timelimit = 0;    scope = LDAP_SCOPE_SUBTREE;	server_sort = 0;#ifdef notdef#ifdef HPUX11#ifndef __LP64__	_main( argc, argv);#endif /* __LP64_ */#endif /* HPUX11 */#endif    ldaptool_reset_control_array( ldaptool_request_ctrls );    optind = ldaptool_process_args( argc, argv, "ABLTU1eotuxa:b:F:G:l:S:s:z:C:",        0, options_callback );    if ( optind == -1 ) {	usage();    }    if ( base == NULL ) {	if (( base = getenv( "LDAP_BASEDN" )) == NULL ) {	    usage();	}    }        if ( sortattr ) {	for ( sortsize = 0; sortattr[sortsize] != NULL; sortsize++ ) {	    ;       /* NULL */	}	sortsize++;             /* add in the final NULL field */	skipsortattr = (int *) malloc( sortsize * sizeof(int *) );	if ( skipsortattr == NULL ) {    		fprintf( stderr, "Out of memory\n" );		exit( LDAP_NO_MEMORY );	}	memset( (char *) skipsortattr, 0, sortsize * sizeof(int *) );    } else if ( server_sort ) {	server_sort = 0;   /* ignore this option if no sortattrs were given */    }    if ( argc - optind < 1 ) {	if ( ldaptool_fp == NULL ) {	    usage();	}	attrs = NULL;	filtpattern = "%s";    } else {	/* there are additional args (filter + attrs) */	if ( ldaptool_fp == NULL || strstr( argv[ optind ], "%s" ) != NULL ) {	    filtpattern = ldaptool_local2UTF8( argv[ optind ], "filter" );	    ++optind;	} else {	    filtpattern = "%s";	}	if ( argv[ optind ] == NULL ) {	    attrs = NULL;	} else if ( sortattr == NULL || *sortattr == '\0' || server_sort) {	    attrs = &argv[ optind ];	} else {	    attrs = ldap_charray_dup( &argv[ optind ] );	    if ( attrs == NULL ) {		fprintf( stderr, "Out of memory\n" );		exit( LDAP_NO_MEMORY );	    }	    for ( i = 0; i < (sortsize - 1); i++ ) {                if ( !ldap_charray_inlist( attrs, sortattr[i] ) ) {                    if ( ldap_charray_add( &attrs, sortattr[i] ) != 0 ) {    			fprintf( stderr, "Out of memory\n" );			exit( LDAP_NO_MEMORY );		    }                    /*                     * attribute in the search list only for the purpose of                     * sorting                     */                    skipsortattr[i] = 1;                }	    }        }    }    ld = ldaptool_ldap_init( 0 );    if ( !ldaptool_not ) {	ldap_set_option( ld, LDAP_OPT_DEREF, &deref );	ldap_set_option( ld, LDAP_OPT_TIMELIMIT, &timelimit );	ldap_set_option( ld, LDAP_OPT_SIZELIMIT, &sizelimit );    }    ldaptool_bind( ld );    if ( ldaptool_verbose ) {	printf( "filter pattern: %s\nreturning: ", filtpattern );	if ( attrs == NULL ) {	    printf( "ALL" );	} else {	    for ( i = 0; attrs[ i ] != NULL; ++i ) {		printf( "%s ", attrs[ i ] );	    }	}	putchar( '\n' );    }    if ( ldaptool_fp == NULL ) {	char *conv;	conv = ldaptool_local2UTF8( base, "base DN" );	rc = dosearch( ld, conv, scope, attrs, attrsonly, filtpattern, "" );	if( conv != NULL )            free( conv );    } else {	int done = 0;	rc = LDAP_SUCCESS;	first = 1;	while ( rc == LDAP_SUCCESS && !done ) {	    char *linep = NULL;	    int   increment = 0;	    int	  c, index;	 	    /* allocate initial block of memory */ 	    if ((linep = (char *)malloc(BUFSIZ)) == NULL) {	        fprintf( stderr, "Out of memory\n" );		exit( LDAP_NO_MEMORY );	    }	    increment++;	    index = 0;	    while ((c = fgetc( ldaptool_fp )) != '\n' && c != EOF) {	        /* check if we will overflow the buffer */	        if ((c != EOF) && (index == ((increment * BUFSIZ) -1))) {		    /* if we did, add another BUFSIZ worth of bytes */	   	    if ((linep = (char *)			realloc(linep, (increment + 1) * BUFSIZ)) == NULL) {			fprintf( stderr, "Out of memory\n" );			exit( LDAP_NO_MEMORY );		    }		    increment++;		}		linep[index++] = c;	    }	    if (c == EOF) {		done = 1;		break;	    }	    	    linep[index] = '\0';	    if ( !first ) {		putchar( '\n' );	    } else {		first = 0;	    }	    rc = dosearch( ld, base, scope, attrs, attrsonly, filtpattern,		    linep );	    free (linep);	}    }    ldaptool_cleanup( ld );    return( rc );}