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.
This commit is contained in:
Howard Chu 2006-05-29 02:41:06 +00:00
parent 795841b5a4
commit 59ca2d198f
3 changed files with 19 additions and 5 deletions

View File

@ -62,7 +62,7 @@ slapadd( int argc, char **argv )
int match; int match;
int ret; int ret;
int checkvals; int checkvals;
int lineno; int lineno, nextline;
int lmax; int lmax;
int rc = EXIT_SUCCESS; int rc = EXIT_SUCCESS;
int manage = 0; int manage = 0;
@ -93,7 +93,7 @@ slapadd( int argc, char **argv )
checkvals = (slapMode & SLAP_TOOL_QUICK) ? 0 : 1; checkvals = (slapMode & SLAP_TOOL_QUICK) ? 0 : 1;
lmax = 0; lmax = 0;
lineno = 0; nextline = 0;
if( !dryrun && be->be_entry_open( be, 1 ) != 0 ) { if( !dryrun && be->be_entry_open( be, 1 ) != 0 ) {
fprintf( stderr, "%s: could not open database.\n", fprintf( stderr, "%s: could not open database.\n",
@ -106,7 +106,13 @@ slapadd( int argc, char **argv )
maxcsn.bv_len = 0; 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 ); Entry *e = str2entry2( buf, checkvals );
/* /*

View File

@ -71,7 +71,7 @@ usage( int tool, const char *progname )
case SLAPADD: case SLAPADD:
options = " [-c]\n\t[-g] [-n databasenumber | -b suffix]\n" 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; break;
case SLAPAUTH: case SLAPAUTH:
@ -241,7 +241,7 @@ slap_tool_init(
switch( tool ) { switch( tool ) {
case SLAPADD: case SLAPADD:
options = "b:cd:f:F:gl:n:o:qstuvw"; options = "b:cd:f:F:gj:l:n:o:qstuvw";
break; break;
case SLAPCAT: case SLAPCAT:
@ -331,6 +331,12 @@ slap_tool_init(
use_glue = 0; use_glue = 0;
break; break;
case 'j': /* jump to linenumber */
if ( lutil_atoi( &jumpline, optarg ) ) {
usage( tool, progname );
}
break;
case 'l': /* LDIF file */ case 'l': /* LDIF file */
ldiffile = strdup( optarg ); ldiffile = strdup( optarg );
break; break;

View File

@ -39,6 +39,7 @@ typedef struct tool_vars {
int tv_continuemode; int tv_continuemode;
int tv_nosubordinates; int tv_nosubordinates;
int tv_dryrun; int tv_dryrun;
int tv_jumpline;
Filter *tv_filter; Filter *tv_filter;
struct berval tv_sub_ndn; struct berval tv_sub_ndn;
struct LDIFFP *tv_ldiffp; struct LDIFFP *tv_ldiffp;
@ -64,6 +65,7 @@ extern tool_vars tool_globals;
#define be tool_globals.tv_be #define be tool_globals.tv_be
#define verbose tool_globals.tv_verbose #define verbose tool_globals.tv_verbose
#define jumpline tool_globals.tv_jumpline
#define update_ctxcsn tool_globals.tv_update_ctxcsn #define update_ctxcsn tool_globals.tv_update_ctxcsn
#define continuemode tool_globals.tv_continuemode #define continuemode tool_globals.tv_continuemode
#define nosubordinates tool_globals.tv_nosubordinates #define nosubordinates tool_globals.tv_nosubordinates