]> git.sur5r.net Git - openldap/commitdiff
Import ldif2ldbm ldif fix from -devel. Still doesn't completely
authorKurt Zeilenga <kurt@openldap.org>
Mon, 30 Nov 1998 23:13:27 +0000 (23:13 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 30 Nov 1998 23:13:27 +0000 (23:13 +0000)
handle extra newlines in ldifs.

servers/slapd/tools/ldif2id2children.c
servers/slapd/tools/ldif2id2entry.c
servers/slapd/tools/ldif2index.c

index 5e709dc9bc44d5387f9784823d4563b82d7dc57d..30dffcf6882d7bbd53b5a43baef05f24cd00fdd4 100644 (file)
@@ -1,7 +1,9 @@
 #include "portable.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 
+#include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/socket.h>
 #include <ac/unistd.h>
@@ -163,7 +165,11 @@ main( int argc, char **argv )
                }
                if ( line[0] == '\n' || stop && buf && *buf ) {
                        if ( *buf != '\n' ) {
-                               id++;
+                               if (isdigit(*buf)) {
+                                       id = atol(buf);
+                               } else {
+                                       id++;
+                               }
                                s = buf;
                                elineno = 0;
                                while ( (linep = str_getline( &s )) != NULL ) {
index e84ed64802673a30c627f9e0be6bbdeee476d0a2..cdc45722f2b8194d533aa62880fead818aad60ee 100644 (file)
@@ -1,7 +1,9 @@
 #include "portable.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 
+#include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/socket.h>
 #include <ac/unistd.h>
@@ -144,8 +146,13 @@ main( int argc, char **argv )
 
                        len = strlen( line );
                        if ( buf == NULL || *buf == '\0' ) {
-                               sprintf( idbuf, "%lu\n", id + 1 );
-                               idlen = strlen( idbuf );
+                               if (!isdigit(line[0])) {
+                                       sprintf( idbuf, "%d\n", id + 1 );
+                                       idlen = strlen( idbuf );
+                               } else {
+                                       id = atol(line) - 1;
+                                       idlen = 0;
+                               }
                        } else {
                                idlen = 0;
                        }
@@ -166,11 +173,16 @@ main( int argc, char **argv )
                }
                if ( line[0] == '\n' || stop && buf && *buf ) {
                        if ( *buf != '\n' ) {
+                               int len;
+
                                id++;
                                key.dptr = (char *) &id;
                                key.dsize = sizeof(ID);
                                data.dptr = buf;
-                               data.dsize = strlen( buf ) + 1;
+                               len = strlen(buf);
+                               if (buf[len - 1] == '\n')
+                                       buf[--len] = '\0';
+                               data.dsize = len + 1;
                                if ( ldbm_store( db->dbc_db, key, data,
                                    LDBM_INSERT ) != 0 ) {
                                        fputs("id2entry ldbm_store failed\n",
index 1287f502d08f40eddce01fb70debe7a453c0a99a..918a054d99fd1ed68230d89ecc4ab5fab592a94a 100644 (file)
@@ -1,7 +1,9 @@
 #include "portable.h"
 
 #include <stdio.h>
+#include <stdlib.h>
 
+#include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/socket.h>
 #include <ac/unistd.h>
@@ -151,7 +153,11 @@ main( int argc, char **argv )
                }
                if ( line[0] == '\n' || stop && buf && *buf ) {
                        if ( *buf != '\n' ) {
-                               id++;
+                               if (isdigit(*buf)) {
+                                       id = atol(buf);
+                               } else {
+                                       id++;
+                               }
                                s = buf;
                                elineno = 0;
                                while ( (linep = str_getline( &s )) != NULL ) {