mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-06 10:46:21 +08:00
Use getopt()
This commit is contained in:
parent
0f86c2e8eb
commit
c562508af3
@ -20,6 +20,7 @@
|
||||
#include <ac/ctype.h>
|
||||
#include <ac/stdlib.h>
|
||||
#include <ac/string.h>
|
||||
#include <ac/unistd.h>
|
||||
|
||||
#define DEFAULT_SPECS "ndb=a,null=n"
|
||||
|
||||
@ -37,7 +38,7 @@ static void
|
||||
usage( void )
|
||||
{
|
||||
fprintf( stderr, "\
|
||||
Usage: %s [backend] [spec[,spec]...]\n\
|
||||
Usage: %s [-b backend] [-s spec[,spec]...]\n\
|
||||
Filter standard input by first <spec> matching '[<backend>]=[a][e][n]':\n\
|
||||
- Remove LDIF comments.\n\
|
||||
- 'a': Sort attributes in entries.\n\
|
||||
@ -205,18 +206,32 @@ filter_stdin( unsigned flags )
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
const char *backend, *specs, *tmp;
|
||||
const char *backend = getenv( "BACKEND" ), *specs = "", *tmp;
|
||||
unsigned flags;
|
||||
int i;
|
||||
|
||||
if ( argc > 0 ) {
|
||||
progname = (tmp = strrchr( argv[0], '/' )) ? tmp+1 : argv[0];
|
||||
}
|
||||
specs = (argc > 1 && strchr( argv[argc-1], '=' )) ? argv[--argc] : "";
|
||||
backend = (argc > 1 && isalnum( (unsigned char) *argv[argc-1] ))
|
||||
? argv[--argc] : (tmp = getenv( "BACKEND" )) ? tmp : "";
|
||||
if ( argc > 1 ) {
|
||||
|
||||
while ( (i = getopt( argc, argv, "b:s:" )) != EOF ) {
|
||||
switch ( i ) {
|
||||
case 'b':
|
||||
backend = optarg;
|
||||
break;
|
||||
case 's':
|
||||
specs = optarg;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if ( optind < argc ) {
|
||||
usage();
|
||||
}
|
||||
if ( backend == NULL ) {
|
||||
backend = "";
|
||||
}
|
||||
|
||||
flags = get_flags( backend, specs );
|
||||
filter_stdin( flags ? flags : get_flags( backend, DEFAULT_SPECS ));
|
||||
|
Loading…
Reference in New Issue
Block a user