Hi Peter,
I'm no patch expert, so the problem might be with me, but I tried to
apply your patch below with:
cat ldif.patch | patch -b LDIF.pm
and got:
patching file LDIF.pm
Hunk #1 FAILED at 79.
1 out of 1 hunk FAILED -- saving rejects to file LDIF.pm.rej
The LDIF.pm getting patched shows:
$VERSION = "0.16";
Here's the content of LDIF.pm.rej:
***************
*** 79,113 ****
sub _read_lines {
my $self = shift;
- my @ldif;
-
- {
- local $/ = ""; # paragraph mode
my $fh = $self->{'fh'};
my $ln;
- do { # allow comments separated by blank lines
- $ln = $self->{_next_lines} || scalar <$fh>;
- unless ($ln) {
- $self->{_next_lines} = '';
- $self->{_current_lines} = '';
- $self->eof(1);
- return;
- }
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_current_lines} = $ln;
- } until ($self->{_current_lines} || $self->eof());
- chomp(@ldif = split(/^/, $ln));
- do {
- $ln = scalar <$fh> || '';
- $self->eof(1) unless $ln;
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_next_lines} = $ln;
- } until ($self->{_next_lines} || $self->eof());
}
@ldif;
}
--- 79,119 ----
sub _read_lines {
my $self = shift;
my $fh = $self->{'fh'};
+ my @ldif = ();
+ my $entry = '';
+ my $in_comment = 0;
my $ln;
+
+ return @ldif if ($self->eof());
+
+ while (defined($ln = scalar <$fh>)) {
+ if ($ln =~ /^#/o) { # ignore 1st line of comments
+ $in_comment = 1;
+ }
+ else {
+ if ($ln =~ /^[ \t]/o) { # append wrapped line (if not in a
comment)
+ $entry .= $ln if (!$in_comment);
+ }
+ else {
+ $in_comment = 0;
+ if ($ln =~ /^\r?\n$/o) {
+ # ignore empty line on start of entry
+ # empty line at non-empty entry indicate entry completion
+ last if (length($entry));
+ }
+ else {
+ # append non-empty line
+ $entry .= $ln;
+ }
+ }
+ }
}
+ $self->eof(1) if (!defined($ln));
+ $entry =~ s/\r?\n //sgo; # un-wrap wrapped lines
+ $entry =~ s/\r?\n\t/ /sgo; # OpenLDAP extension !!!
+ @ldif = split(/^/, $entry);
+ map { s/\r?\n$//; } @ldif;
@ldif;
}
If there's any other info I can provide, please just let me know.
Cheers,
David
Peter Marschall wrote:
Hi,
since I did not get any feedback about the patch for D. Wood's issue of
opening Windows-created LDIFs in Linux/Unix I am re-sending the patch.
Please test and give me feedback !
Thanks in advance
Peter
---------- Forwarded Message ----------
Subject: Re: Some feedback on Net::LDAP::LDIF...
Date: Monday 27 June 2005 13:48
From: Peter Marschall <[EMAIL PROTECTED]>
To: perl-ldap@perl.org
Cc: "Chris Ridd" <[EMAIL PROTECTED]>, "David Wood" <[EMAIL PROTECTED]>
Hi,
On Monday 20 June 2005 19:51, Graham Barr wrote:
That was my guess, I just wanted confirmation. I guess LDIF.pm
needs to be rewritten without the use of paragraph mode.
The attached a patch should deal with the CR+LF vs. LF issues in LDIF.pm
Please test and give me feedback.
Peter
--
Peter Marschall
eMail: [EMAIL PROTECTED]
-------------------------------------------------------
------------------------------------------------------------------------
--- lib/Net/LDAP/LDIF.pm
+++ lib/Net/LDAP/LDIF.pm 2005-06-27 13:25:45.000000000 +0200
@@ -79,35 +79,41 @@
sub _read_lines {
my $self = shift;
- my @ldif;
-
- {
- local $/ = ""; # paragraph mode
my $fh = $self->{'fh'};
+ my @ldif = ();
+ my $entry = '';
+ my $in_comment = 0;
my $ln;
- do { # allow comments separated by blank lines
- $ln = $self->{_next_lines} || scalar <$fh>;
- unless ($ln) {
- $self->{_next_lines} = '';
- $self->{_current_lines} = '';
- $self->eof(1);
- return;
- }
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_current_lines} = $ln;
- } until ($self->{_current_lines} || $self->eof());
- chomp(@ldif = split(/^/, $ln));
- do {
- $ln = scalar <$fh> || '';
- $self->eof(1) unless $ln;
- $ln =~ s/\n //sg;
- $ln =~ s/^#.*\n//mg;
- chomp($ln);
- $self->{_next_lines} = $ln;
- } until ($self->{_next_lines} || $self->eof());
+
+ return @ldif if ($self->eof());
+
+ while (defined($ln = scalar <$fh>)) {
+ if ($ln =~ /^#/o) { # ignore 1st line of comments
+ $in_comment = 1;
+ }
+ else {
+ if ($ln =~ /^[ \t]/o) { # append wrapped line (if not in a comment)
+ $entry .= $ln if (!$in_comment);
+ }
+ else {
+ $in_comment = 0;
+ if ($ln =~ /^\r?\n$/o) {
+ # ignore empty line on start of entry
+ # empty line at non-empty entry indicate entry completion
+ last if (length($entry));
+ }
+ else {
+ # append non-empty line
+ $entry .= $ln;
+ }
+ }
+ }
}
+ $self->eof(1) if (!defined($ln));
+ $entry =~ s/\r?\n //sgo; # un-wrap wrapped lines
+ $entry =~ s/\r?\n\t/ /sgo; # OpenLDAP extension !!!
+ @ldif = split(/^/, $entry);
+ map { s/\r?\n$//; } @ldif;
@ldif;
}