[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm

foxr lon-capa-cvs@mail.lon-capa.org
Mon, 23 Oct 2006 10:40:11 -0000


foxr		Mon Oct 23 06:40:11 2006 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  Prior change seemed not to be able to substitute for all 
  the actual %letter strings in  a format string like e.g.:
  Name: %10n \\ Sequence: %10c  \\ Resource: %10a Done
  leaving % format strings hanging.  The correct thing
  to do is to do all the format replacements and >then<
  go back and escape any remaining %'s the user may have
  pathalogically left in the format string.  The
  current version has been tested on a nasty format 
  string that looks like:
  Name: %10n \\ Sequence: %10c  \\ Resource: %10a Done % 10% done %10  %b done
  and not only does not loop, but produces LaTeX output that can print.
  
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.488 loncom/interface/lonprintout.pm:1.489
--- loncom/interface/lonprintout.pm:1.488	Fri Oct 20 13:37:20 2006
+++ loncom/interface/lonprintout.pm	Mon Oct 23 06:40:09 2006
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.488 2006/10/20 17:37:20 albertel Exp $
+# $Id: lonprintout.pm,v 1.489 2006/10/23 10:40:09 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,7 +62,7 @@
 sub printf_style_subst {
     my ($item, $format_string, $repl) = @_;
 
-    while ($format_string =~m/\G[^%]*(%(\d*)\Q$item\E)/g) {
+    while ($format_string =~m/%\d*\Q$item\E/) {
 	my $fmt = $1;
 	my $size = $2;
 	my $subst = $repl;
@@ -70,7 +70,7 @@
 	    $subst = substr($subst, 0, $size);
 	}
 	my $newpos =  pos($format_string) + length($subst) - length($fmt);
-	$format_string =~ s/\Q$fmt\E\G/$subst/;
+	$format_string =~ s/\Q$fmt\E/$subst/;
 	pos($format_string)=$newpos;
     }
     return $format_string;
@@ -128,6 +128,12 @@
 	$format =  &printf_style_subst("a", $format, $assignment);
 	$format =  &printf_style_subst("c", $format, $course);
 	$format =  &printf_style_subst("n", $format, $student);
+
+	# If the user put %'s in the format string, they  must be escaped
+	# to \% else LaTeX will think they are comments and terminate
+	# the line.. which is bad!!!
+
+	$format =~ s/%/\\%/g;
     }