]> git.sur5r.net Git - openldap/commitdiff
add debug to rewrite tool
authorPierangelo Masarati <ando@openldap.org>
Sun, 20 Jun 2004 22:40:32 +0000 (22:40 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sun, 20 Jun 2004 22:40:32 +0000 (22:40 +0000)
libraries/librewrite/rewrite.c

index 6747bd60aa76bc126907b95f68377485f39a6447..1964deba52004c567056f58ab35efb09da72163d 100644 (file)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 
 #include <rewrite.h>
+#include <ldap.h>
 
 int ldap_debug;
 int ldap_syslog;
@@ -120,17 +121,28 @@ apply(
 int
 main( int argc, char *argv[] )
 {
-       FILE *fin = NULL;
-       char *rewriteContext = REWRITE_DEFAULT_CONTEXT;
+       FILE    *fin = NULL;
+       char    *rewriteContext = REWRITE_DEFAULT_CONTEXT;
+       int     debug = 0;
+       char    *next;
 
        while ( 1 ) {
-               int opt = getopt( argc, argv, "f:hr:" );
+               int opt = getopt( argc, argv, "d:f:hr:" );
 
                if ( opt == EOF ) {
                        break;
                }
 
                switch ( opt ) {
+               case 'd':
+                       debug = strtol( optarg, &next, 10 );
+                       if ( next == NULL || next[0] != '\0' ) {
+                               fprintf( stderr, "illegal log level '%s'\n",
+                                               optarg );
+                               exit( EXIT_FAILURE );
+                       }
+                       break;
+
                case 'f':
                        fin = fopen( optarg, "r" );
                        if ( fin == NULL ) {
@@ -161,6 +173,11 @@ main( int argc, char *argv[] )
                }
        }
        
+       if ( debug != 0 ) {
+               ber_set_option(NULL, LBER_OPT_DEBUG_LEVEL, &debug);
+               ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug);
+       }
+       
        if ( optind >= argc ) {
                return -1;
        }