From: Hallvard Furuseth Date: Sun, 29 Nov 2009 09:59:22 +0000 (+0000) Subject: Use getopt() X-Git-Tag: ACLCHECK_0~53 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c562508af37794f96f18f7840cdd84df5a07917b;p=openldap Use getopt() --- diff --git a/tests/progs/ldif-filter.c b/tests/progs/ldif-filter.c index 932b46e3c0..24a7846280 100644 --- a/tests/progs/ldif-filter.c +++ b/tests/progs/ldif-filter.c @@ -20,6 +20,7 @@ #include #include #include +#include #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 matching '[]=[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 ));