[Po4a-commits] po4a/lib/Locale/Po4a Sgml.pm,1.34,1.35

Martin Quinson po4a-devel@lists.alioth.debian.org
Sat, 14 Aug 2004 23:48:18 +0000


Update of /cvsroot/po4a/po4a/lib/Locale/Po4a
In directory haydn:/tmp/cvs-serv26556

Modified Files:
	Sgml.pm 
Log Message:
atempt to fix the references, but I suspect nsgml to mess around with the strings, like eating silencly 'unimportant' white chars

Index: Sgml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Sgml.pm,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- Sgml.pm	12 Aug 2004 16:40:56 -0000	1.34
+++ Sgml.pm	14 Aug 2004 23:48:15 -0000	1.35
@@ -430,8 +430,10 @@
     # Prepare the reference indirection stuff
     my @refs;
     my @lines = split(/\n/, $origfile);
-    for (my $i=0; $i<scalar @lines; $i++) {
+    print "XX Prepare reference indirection stuff\n" if $debug{'refs'};
+    for (my $i=1; $i<=scalar @lines; $i++) {
 	push @refs,"$filename:$i";
+	print "$filename:$i\n" if $debug{'refs'};
     }
 
     # protect the conditional inclusions in the file
@@ -532,13 +534,23 @@
 		$refcpy[$i]=$refs[$i];
 	    }
 	    my @begin = split(/\n/,$begin);
-	    my @end = split(/\n/,$end);	    
-	    for ($i=1; $i<=$entincl{$key}{'length'}; $i++) {
-		$refs[$i+scalar @begin+1]="$entincl{$key}{'filename'}:$i";
+	    my @end = split(/\n/,$end);
+	    my ($pre,$len,$post) = (scalar @begin,$entincl{$key}{'length'},scalar @end);
+	    # make sure pre and content have a line in common. It will be the case if the entity is
+	    # indented ($begin contains the indenting spaces), but not if the entity is on the first
+	    # column
+	    $pre++ if ($begin =~ /\n$/s);
+	    # same for post
+	    $len++ if ($end =~ /^\n/s);
+	    
+	    print "XX Add a ref. pre=$pre; len=$len; post=$post\n" if $debug{'refs'};
+	    my $main = $refs[$pre-1]; # Keep a reference of inclusion position in main file
+	    for ($i=-1; $i<$len-1; $i++) {
+		$refs[$i+$pre] = "$main $entincl{$key}{'filename'}:".($i+2);
 	    }
-	    for ($i=1; $i<=scalar @end; $i++) {
-		$refs[$i+scalar @begin+1+$entincl{$key}{'length'}]=
-		    $refcpy[$i+scalar @begin+2];
+	    for ($i=0; $i<$post; $i++) {
+		    $refs[$pre+$i+$len-1] = # -1 since pre and len have a line in common
+		  $refcpy[$pre+$i];
 	    }
 
 	    # Do the substitution
@@ -552,8 +564,9 @@
     #   Reput the entities of inclusion in place
     $origfile =~ s/{PO4A-keep-amp}/&/g;
     if ($debug{'refs'}) {
+	print "XX Resulting shifts\n";
 	for (my $i=0; $i<scalar @refs; $i++) {
-	    print STDERR "$filename:$i -> $refs[$i]\n";
+	    print "$filename:".($i+1)." -> $refs[$i]\n";
 	}
     }
     
@@ -819,7 +832,7 @@
     # What to do after parsing
     $self->pushline($buffer);
     close(IN);
-    unlink ($tmpfile);
+    unlink ($tmpfile) unless $debug{'refs'};
 }
 
 sub end_paragraph {