mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
7e6ad5100c
Most function and variable definitions are now preceded by its extern definition, for error checking. Retyped a number of functions, usually to return void. Fixed a number of printf format errors. API changes (in ldap/include): Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h. A number of `extern' declarations are left (some added by protoize), to be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind, optarg, errno.
80 lines
1.5 KiB
C
80 lines
1.5 KiB
C
#include "portable.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/ctype.h>
|
|
#include <ac/socket.h>
|
|
#include <ac/string.h>
|
|
|
|
#include "ldbm.h"
|
|
#include "../slap.h"
|
|
|
|
static void
|
|
usage( char *name )
|
|
{
|
|
fprintf( stderr, "usage: %s [-n] <filename>\n", name );
|
|
exit( 1 );
|
|
}
|
|
|
|
int
|
|
main( int argc, char **argv )
|
|
{
|
|
Datum key, last, data;
|
|
LDBM dbp;
|
|
int rc, type;
|
|
long id;
|
|
char *file, *s;
|
|
int printid = 1;
|
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
|
DBC *cursorp;
|
|
#endif
|
|
|
|
if ( argc < 2 || argc > 3 || ( argc == 3 && strcmp( argv[1], "-n" )
|
|
!= 0 )) {
|
|
usage( argv[0] );
|
|
}
|
|
if ( argc == 3 && strcmp( argv[1], "-n" ) == 0 ) {
|
|
printid = 0;
|
|
file = argv[2];
|
|
} else {
|
|
file = argv[1];
|
|
}
|
|
|
|
if ( (dbp = ldbm_open( file, LDBM_READER, 0, 0 )) == NULL ) {
|
|
perror( file );
|
|
exit ( 1 );
|
|
}
|
|
|
|
last.dptr = NULL;
|
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
|
for ( key = ldbm_firstkey( dbp, &cursorp ); key.dptr != NULL;
|
|
key = ldbm_nextkey( dbp, last, cursorp ) )
|
|
#else
|
|
for ( key = ldbm_firstkey( dbp ); key.dptr != NULL;
|
|
key = ldbm_nextkey( dbp, last ) )
|
|
#endif
|
|
{
|
|
if ( last.dptr != NULL )
|
|
ldbm_datum_free( dbp, last );
|
|
data = ldbm_fetch( dbp, key );
|
|
s = data.dptr;
|
|
if ( !printid && isdigit( *s )) {
|
|
if (( s = strchr( s, '\n' )) != NULL ) {
|
|
++s;
|
|
}
|
|
}
|
|
if ( s != NULL ) {
|
|
puts( s );
|
|
}
|
|
ldbm_datum_free( dbp, data );
|
|
last = key;
|
|
}
|
|
if ( last.dptr != NULL )
|
|
ldbm_datum_free( dbp, last );
|
|
ldbm_close( dbp );
|
|
|
|
exit( 0 );
|
|
}
|