--- loncom/interface/printout.pl 2001/10/02 14:10:40 1.1 +++ loncom/interface/printout.pl 2011/12/21 21:25:40 1.151 @@ -1,32 +1,1160 @@ #!/usr/bin/perl -print "Content-type: text/html\n\n"; -print "
\n"; -print "'.&mt("[_1]Return[_2] to editing resource.", + "","").'
'); +} +my $figfile = $texfile; +$figfile =~ s/^(.*_printout)_\d+_\d+_\d+\.tex/$1\.dat/; +my $duefile = $texfile; +$duefile =~ s/^(.*_printout)_\d+_\d+_\d+\.tex/$1\.due/; + + +#------------------------------------------------------------------------------------- +# +# Each print may have associated with it a file that contains a set of figures +# that need to be converted to .eps from whatever form they were in when included +# in the resource. The name of the figure file is in $figfile. If it exists, +# it contains the names of the files that need to be converted, one per line. +# + +&debug("Figure file is $figfile"); + +if (-e $figfile) { + &debug( "Figure file exists"); + &debug("$figfile exists"); + my %done_conversion; + my $temporary_file=IO::File->new($figfile) || die "Couldn't open fig file $figfile for reading: $!\n"; + my @content_of_file = <$temporary_file>; + close $temporary_file; + my $noteps; + my %prog_state; + if ($advanced_role) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('',$#content_of_file); } + print('Zip Output:\n"); + system($statement); + print(""); + $zipfile=~s{^\Q$perlvar{'lonPrtDir'}\E}{/prtspool}; + print "
Executing $command, the output file $output_file did not grow\n"; + print "after $timeout seconds. This may indicate $command\n"; + print "is in an infinite loop.\n"; + print "See if printing fewer copies helps. Please contact LON-CAPA\n"; + print "support about this in any event."; + print "
"; + kill(9, $pid); # Reaper will do the rest...I hope there's errors in the log. + } + } else { + $last_size = $size; + $unchanged_time = 0; + } + } + if ($advanced_role) { + &Apache::lonhtmlcommon::Update_PrgWin('',$progress_win,$message.$extra_msg); + } + } + $SIG{CHLD}='IGNORE'; + close(CMD); +} + +# Make the dvi file (or rather try to), from the latex file and the +# various bits and pieces that control how the latex file is processed: +# LaTeX is run as many times a needed to make this all happen... this may +# result in several runs of LaTeX that just are errors if the LaTeX is +# bad, but the printing subsystem is _supposed_ to not do that. +# +# Parameters: +# name_file - Name of the LaTeX file to process. +# dvi_file - Name of resulting dvi file. +# tableofcontents - "yes" if we are supposed to make a table of contents. +# tableofindex - "yes" if we are suposed to make an index. +# status_statement - Part of the status statement for ths status window. +# prog_state - Reference to the program state hash. +# busy_wait_timeout- Seconds without any progress that imply a problem. +# +# +sub make_dvi_file { + my ($name_file, + $dvi_file, + $tableofcontents, + $tableofindex, + $status_statement, + $prog_state, + $busy_wait_timeout) = @_; + + + &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", + "for $status_statement now LaTeXing file", + $prog_state,$dvi_file, $busy_wait_timeout); + + # If the tableof contents was requested, we need to run + # LaTex a couple more times to get all the references sorted out. + + if ($tableofcontents eq 'yes') { + &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", + "for $status_statement First LaTeX of file for table of contents", + $prog_state,$dvi_file, $busy_wait_timeout); + &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", + "for $status_statement Second LaTeX of file for table of contents", + $prog_state,$dvi_file,$busy_wait_timeout); + } + + # And makeindex and another run of LaTeX to incorporate it if the index + # is enabled. + + + if ($tableofindex eq 'yes') { + my $idxname=$name_file; + $idxname=~s/\.tex$/\.idx/; + &busy_wait_command("makeindex $idxname", + "making index file", + $prog_state,$idxname); + &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null", + "for $status_statement now LaTeXing file for index section", + $prog_state,$dvi_file, $busy_wait_timeout); + } + +} + + +# Repagninate +# What we need to do: +# - Count the number of pages in each student. +# - Rewrite the latex file replacing the \specials that +# mark the end of student with an appropriate number of newlines. +# parameters: +# psfile - Postscript filename +# latexfile - LaTeX filename +# columns - number of columns. +sub repaginate { + + # We will try to do this in 2 passes through the postscript since + # the postscript is potentially large, to do 2 passes, the first pass + # must be able to calculate the total number of document pages so that + # at the beginning of the second pass we already know how to replace + # %%Pages: + + # Figure out + # 1. Number of pages in the document + # 2. Maximum number of pages in a student + # 3. Number of pages in each student. + + my ($postscript_filename, $latex_filename, $num_columns) = @_; + open(PSFILE, "<$postscript_filename"); + my $line; + my $total_pages; # Total pages in document. + my $seen_pages = 0; # There are several %%Pages only the first is useful + my @pages_in_student; # For each student his/her initial page count. + my $max_pages = 0; # Pages in 'longest' student. + my $page_number = 0; + &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,&mt("Counting pages for student: [_1]",1)); + + while ($line ="
+ .mt("An error occured during the conversion of [_1].[_2]"
+ ."If possible try to save this image using different settings and republish it.",
+ "".$prettyname."", "
")
+ ."
'.$body_log_file.''."\n"; + if ($body_log_file=~m/!\s+Emergency stop/) { + my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART'; + my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND'; + my $badresource; + my $badtext; + if ($whereitbegins!=-1 and $whereitends!=-1) { + $badtext = substr($body_log_file,$whereitbegins+26, $whereitends-$whereitbegins-26); + $whereitbegins = rindex $badtext,'located in'; + if ($whereitbegins != -1) { + + $badresource = substr($badtext, $whereitbegins+27, + length($badtext) - $whereitbegins - 48); + # print "
"; + + my $sygnal = 0; + for (my $i=0;$i<=$#content_of_file;$i++) { + if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) { + $sygnal = 1; + } + if ($content_of_file[$i]=~m/Here is how much of/) { + $sygnal = 0; + } + if ($sygnal) { + print "$content_of_file[$i]"; + } + } + print "\n"; + # print "
'.$body_tex_file.''."\n"; + print "
'; + if ($badtext) { + print &mt('There are errors in [_1].',$badtext); + } else { + print &mt('There are errors.'); + } + print '
' + .&mt('These errors prevent this resource from printing correctly.'); + + my $tex_handle = IO::File->new($texfile); + my @tex_contents = <$tex_handle>; + &send_error_mail($identifier, $badresource, $body_log_file, \@tex_contents); + print "" + .&mt('A message has been sent to the instructor describing this failure.') + ."
"; + my $help_text = &Apache::loncommon::help_open_topic("Print_Resource", &mt('Help on printing')); + print ("$help_text"); + + } + + # Either way, an emergency stop does not allow us to continue so: + + return 0; + + # The branch of code below is taken if it appears that + # there was no emergency stop but LaTeX had to correct the + # input file to run. + # In that case we need to provide error feedback, as the correction >may< not be + # sufficient, we can let the game continue as there's a dvi file to process. + + } elsif ($body_log_file=~m/'.$body_tex_file.''."\n"; + print "