From: Howard Chu Date: Mon, 29 May 2006 02:41:06 +0000 (+0000) Subject: ITS#4555 add "-j" option to jump to line of LDIF file before processing. X-Git-Tag: OPENLDAP_REL_ENG_2_4_3ALPHA~9^2~206 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=59ca2d198f454f764170470ed5c69b3c80ef4267;p=openldap ITS#4555 add "-j" option to jump to line of LDIF file before processing. Fixed line number in error messages to give the line number of the beginning of the offending entry. --- diff --git a/servers/slapd/slapadd.c b/servers/slapd/slapadd.c index 11cf55f371..c03724002f 100644 --- a/servers/slapd/slapadd.c +++ b/servers/slapd/slapadd.c @@ -62,7 +62,7 @@ slapadd( int argc, char **argv ) int match; int ret; int checkvals; - int lineno; + int lineno, nextline; int lmax; int rc = EXIT_SUCCESS; int manage = 0; @@ -93,7 +93,7 @@ slapadd( int argc, char **argv ) checkvals = (slapMode & SLAP_TOOL_QUICK) ? 0 : 1; lmax = 0; - lineno = 0; + nextline = 0; if( !dryrun && be->be_entry_open( be, 1 ) != 0 ) { fprintf( stderr, "%s: could not open database.\n", @@ -106,7 +106,13 @@ slapadd( int argc, char **argv ) maxcsn.bv_len = 0; } - while( ldif_read_record( ldiffp, &lineno, &buf, &lmax ) ) { + /* nextline is the line number of the end of the current entry */ + for( lineno=1; ldif_read_record( ldiffp, &nextline, &buf, &lmax ); + lineno=nextline+1 ) { + + if ( lineno < jumpline ) + continue; + Entry *e = str2entry2( buf, checkvals ); /* diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 1a1ea03441..b9ac4f1bee 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -71,7 +71,7 @@ usage( int tool, const char *progname ) case SLAPADD: options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n" - "\t[-l ldiffile] [-q] [-u] [-s] [-w]\n"; + "\t[-l ldiffile] [-j linenumber] [-q] [-u] [-s] [-w]\n"; break; case SLAPAUTH: @@ -241,7 +241,7 @@ slap_tool_init( switch( tool ) { case SLAPADD: - options = "b:cd:f:F:gl:n:o:qstuvw"; + options = "b:cd:f:F:gj:l:n:o:qstuvw"; break; case SLAPCAT: @@ -331,6 +331,12 @@ slap_tool_init( use_glue = 0; break; + case 'j': /* jump to linenumber */ + if ( lutil_atoi( &jumpline, optarg ) ) { + usage( tool, progname ); + } + break; + case 'l': /* LDIF file */ ldiffile = strdup( optarg ); break; diff --git a/servers/slapd/slapcommon.h b/servers/slapd/slapcommon.h index 9584986915..a5da19eb76 100644 --- a/servers/slapd/slapcommon.h +++ b/servers/slapd/slapcommon.h @@ -39,6 +39,7 @@ typedef struct tool_vars { int tv_continuemode; int tv_nosubordinates; int tv_dryrun; + int tv_jumpline; Filter *tv_filter; struct berval tv_sub_ndn; struct LDIFFP *tv_ldiffp; @@ -64,6 +65,7 @@ extern tool_vars tool_globals; #define be tool_globals.tv_be #define verbose tool_globals.tv_verbose +#define jumpline tool_globals.tv_jumpline #define update_ctxcsn tool_globals.tv_update_ctxcsn #define continuemode tool_globals.tv_continuemode #define nosubordinates tool_globals.tv_nosubordinates