[Po4a-commits] "po4a/lib/Locale/Po4a Sgml.pm,1.76,1.77"

Nicolas FRANCOIS nekral-guest at alioth.debian.org
Thu Sep 15 17:28:45 UTC 2005


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

Modified Files:
	Sgml.pm 
Log Message:
* Use tr/\n/\n/ to count the number of lines (spliting the string on \n in
  an array causes wrong line references when multiple end of line precedes
  the included file; and it is faster).
  More of these fixes are probably needed.
* do not ($end =~ s/^\s*\n//s;) for the same reason
* replace some for loop by a splice and push
* duplicate the line reference of the current line if some text foolowed
  the file inclusion (and an end of line terminates the included file
* If there is some text before the file inclusion, and the included file
  starts by an end of line, use the main reference (without the reference
  to the included file).

All this provides better line references (some are wrong, because of
nsgmls), and should be faster (theorically, maybe only noticeable on large
documents with dozens of included files).


Index: Sgml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Sgml.pm,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- Sgml.pm	14 Sep 2005 21:26:49 -0000	1.76
+++ Sgml.pm	15 Sep 2005 17:28:43 -0000	1.77
@@ -619,33 +619,45 @@
     foreach my $key (keys %entincl) {
         while ($origfile =~/^(.*?)&$key;(.*)$/s) {
 	    my ($begin,$end)=($1,$2);
-	    $end =~ s/^\s*\n//s;
 
 	    # add the refs
-	    my @refcpy;
+	    my $len  = $entincl{$key}{'length'}; # number added by the inclusion
+	    my $pre  = ($begin =~ tr/\n/\n/); # number of \n
+	    my $post = ($end =~ tr/\n/\n/);
+	    print "XX Add a ref. pre=$pre; len=$len; post=$post\n" if $debug{'refs'};
+	    my $main = $refs[$pre]; # Keep a reference of inclusion position in main file
+
+	    # Remove the references for the lines after the inclusion
+	    # point.
+	    my @endrefs = splice @refs, $pre+1;
+
+	    # Add the references of the added lines
 	    my $i;
-	    for ($i=0;$i<scalar @refs;$i++){
-		$refcpy[$i]=$refs[$i];
+	    for ($i=0; $i<$len; $i++) {
+		$refs[$i+$pre] = "$main $entincl{$key}{'filename'}:".($i+1);
 	    }
-	    my @begin = split(/\n/,$begin);
-	    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);
+
+	    if ($begin !~ m/\n[ \t]*$/s) {
+		if ($entincl{$key}{'content'} =~ m/^[ \t]*\n/s) {
+		    # There is nothing in the first line of the included
+		    # file, and something on the line before the inclusion
+		    # The line reference will be more informative like
+		    # this:
+		    $refs[$pre] = $main;
+		}
 	    }
-	    for ($i=0; $i<$post; $i++) {
-		    $refs[$pre+$i+$len-1] = # -1 since pre and len have a line in common
-		  $refcpy[$pre+$i];
+	    if ($end !~ s/^[ \t]*\n//s) {
+		if ($entincl{$key}{'content'} =~ m/\n[ \t]*$/s) {
+		    # There is something on the line after the inclusion,
+		    # and there is an end of line at the end of the
+		    # included file. We must add the line reference of the
+		    # remainder on the line:
+		    push @refs, $main;
+		}
 	    }
+	    # Append the references removed earlier (lines after the
+	    # inclusion point).
+	    push @refs, @endrefs;
 
 	    # Do the substitution
 	    $origfile = "$begin".$entincl{$key}{'content'}."$end";




More information about the Po4a-commits mailing list