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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 19 Aug 2004 20:02:21 -0000


albertel		Thu Aug 19 16:02:21 2004 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  - BUG#3325, really long filenames with send lonprintout into an infinite loop
  
  
Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.327 loncom/interface/lonprintout.pm:1.328
--- loncom/interface/lonprintout.pm:1.327	Wed Aug 18 21:23:32 2004
+++ loncom/interface/lonprintout.pm	Thu Aug 19 16:02:21 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.327 2004/08/19 01:23:32 albertel Exp $
+# $Id: lonprintout.pm,v 1.328 2004/08/19 20:02:21 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -665,24 +665,21 @@
 }
 
 sub path_to_problem {
-    my ($urlp,$LaTeXwidth)=@_;
+    my ($urlp,$colwidth)=@_;
     my $newurlp = '';
-    $LaTeXwidth=~s/\s*mm\s*$//;
-    my $HowMany = length($urlp)*2;
-    if ($HowMany > $LaTeXwidth) {
-	my @temporrary = split '/',$urlp;
-	my $HowManyNew = 0;
-	for (my $ii=0;$ii<=$#temporrary;$ii++) {
-	    if ($temporrary[$ii] ne '') {
-		$HowManyNew += length($temporrary[$ii])*2;
-		if ($HowManyNew < $LaTeXwidth ) {
-		    $newurlp .=  '/'.$temporrary[$ii];
-		} else {
-		    $HowManyNew = 0;
-		    $newurlp .=  '|\vskip -1 mm \noindent \verb|';
-		    $ii--;
-		}
+    $colwidth=~s/\s*mm\s*$//;
+#characters average about 2 mm in width
+    if (length($urlp)*2 > $LaTeXwidth) {
+	my @elements = split '/',$urlp;
+	my $curlength=0;
+	foreach my $element (@elements) {
+	    if ($curlength+(length($element)*2) > $colwidth) {
+		$newurlp .=  '|\vskip -1 mm \noindent \verb|';
+		$curlength=0;
+	    } else {
+		$curlength+=length($element)*2;
 	    }
+	    $newurlp.='/'.$element;
 	}
     } else {
 	$newurlp=$urlp;