1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "ldbm.h"
|
|
|
|
#include "../slap.h"
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
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.
1998-11-16 06:40:11 +08:00
|
|
|
static void
|
|
|
|
usage( char *name )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1998-12-30 01:28:45 +08:00
|
|
|
fprintf( stderr, "usage: %s [-n] <filename>\n", name );
|
|
|
|
exit( 1 );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
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.
1998-11-16 06:40:11 +08:00
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
1998-12-30 01:28:45 +08:00
|
|
|
Datum key, last, data;
|
|
|
|
LDBM dbp;
|
|
|
|
char *file, *s;
|
|
|
|
int printid = 1;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-12-30 01:28:45 +08:00
|
|
|
DBC *cursorp;
|
1999-01-07 11:28:08 +08:00
|
|
|
#endif
|
1998-12-18 20:28:47 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_datum_init( key );
|
|
|
|
ldbm_datum_init( last );
|
|
|
|
ldbm_datum_init( data );
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
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 );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
last.dptr = NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#ifdef HAVE_BERKELEY_DB2
|
1998-09-03 08:50:13 +08:00
|
|
|
for ( key = ldbm_firstkey( dbp, &cursorp ); key.dptr != NULL;
|
|
|
|
key = ldbm_nextkey( dbp, last, cursorp ) )
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( key = ldbm_firstkey( dbp ); key.dptr != NULL;
|
1998-09-03 08:50:13 +08:00
|
|
|
key = ldbm_nextkey( dbp, last ) )
|
|
|
|
#endif
|
1998-12-30 01:28:45 +08:00
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
data = ldbm_fetch( dbp, key );
|
1998-12-30 01:28:45 +08:00
|
|
|
|
|
|
|
if (( s = data.dptr ) != NULL ) {
|
|
|
|
|
1999-02-23 01:57:22 +08:00
|
|
|
if ( !printid && isdigit( (unsigned char) *s )) {
|
1998-12-30 01:28:45 +08:00
|
|
|
if (( s = strchr( s, '\n' )) != NULL ) {
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( s != NULL ) {
|
|
|
|
puts( s );
|
|
|
|
}
|
|
|
|
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( dbp, data );
|
1998-12-30 01:28:45 +08:00
|
|
|
|
1999-03-30 00:01:59 +08:00
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
1998-12-30 01:28:45 +08:00
|
|
|
|
1999-03-30 00:01:59 +08:00
|
|
|
ldbm_datum_free( dbp, last );
|
1998-08-09 08:43:13 +08:00
|
|
|
last = key;
|
1999-03-05 19:24:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-03-05 19:24:42 +08:00
|
|
|
ldbm_datum_free( dbp, last );
|
1998-12-30 01:28:45 +08:00
|
|
|
ldbm_close( dbp );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-12-30 01:28:45 +08:00
|
|
|
exit( 0 );
|
1999-03-02 06:37:05 +08:00
|
|
|
|
|
|
|
return 0; /* NOT REACHED */
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|