Annotation of loncom/interface/printout.pl, revision 1.74

1.1       sakharuk    1: #!/usr/bin/perl
1.37      albertel    2: # CGI-script to run LaTeX, dvips, ps2ps, ps2pdf etc.
                      3: #
1.74    ! foxr        4: # $Id: printout.pl,v 1.73 2005/03/14 23:51:20 foxr Exp $
1.37      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
1.39      sakharuk   29: use lib '/home/httpd/lib/perl';
                     30: use LONCAPA::loncgi();
1.38      sakharuk   31: use File::Path;
1.6       sakharuk   32: use IO::File;
1.7       sakharuk   33: use Image::Magick;
1.47      sakharuk   34: use Apache::lonhtmlcommon;
1.71      albertel   35: use Apache::lonnet();
1.51      albertel   36: use Apache::loncommon;
                     37: use Apache::lonlocal;
1.47      sakharuk   38: 
1.59      albertel   39: use strict;
1.49      albertel   40: $|=1;
1.46      albertel   41: my %origENV=%ENV;
1.39      sakharuk   42: if (! &LONCAPA::loncgi::check_cookie_and_load_env()) {
                     43:     print <<END;
                     44: Content-type: text/html
                     45: 
                     46: <html>
                     47: <head><title>Bad Cookie</title></head>
                     48: <body>
1.40      sakharuk   49: Your cookie information is incorrect.
1.39      sakharuk   50: </body>
                     51: </html>
                     52: END
                     53:     return;
                     54: }
1.51      albertel   55:  &Apache::lonlocal::get_language_handle();
                     56:  &Apache::loncommon::content_type(undef,'text/html');
                     57:  my $bodytag=&Apache::loncommon::bodytag('Creating PDF','','');
                     58:  print $bodytag;
1.39      sakharuk   59: 
1.40      sakharuk   60:   my $identifier = $ENV{'QUERY_STRING'};
                     61:   my $texfile = $ENV{'cgi.'.$identifier.'.file'};
                     62:   my $laystyle = $ENV{'cgi.'.$identifier.'.layout'};
                     63:   my $numberofcolumns = $ENV{'cgi.'.$identifier.'.numcol'};
1.62      sakharuk   64:   my $paper = $ENV{'cgi.'.$identifier.'.paper'};
1.40      sakharuk   65:   my $selectionmade = $ENV{'cgi.'.$identifier.'.selection'};
                     66:   my $tableofcontents = $ENV{'cgi.'.$identifier.'tableofcontents'};
                     67:   my $tableofindex = $ENV{'cgi.'.$identifier.'tableofindex'};
                     68:   my $advans_role = $ENV{'cgi.'.$identifier.'role'};
1.43      sakharuk   69:   my $number_of_files = $ENV{'cgi.'.$identifier.'numberoffiles'}+1;
1.44      sakharuk   70:   my $student_names = $ENV{'cgi.'.$identifier.'studentnames'};
1.71      albertel   71:   my $backref = &Apache::lonnet::unescape($ENV{'cgi.'.$identifier.'backref'});
1.43      sakharuk   72: 
1.62      sakharuk   73: 
1.49      albertel   74:   my $adv = $ENV{'request.role.adv'};
                     75:   
1.44      sakharuk   76:   my @names_pack=();
                     77:   if ($student_names=~/_END_/) {  
                     78:       @names_pack=split(/_ENDPERSON_/,$student_names);
                     79:   }
1.46      albertel   80:   #got what we needed reset ENV in case it is to big for system
                     81:   %ENV=%origENV;
1.39      sakharuk   82: 
1.14      sakharuk   83:   my $figfile = $texfile;
                     84:   $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/;
                     85:   my $duefile = $texfile;
                     86:   $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/;
                     87:   #do we have figures?
1.73      foxr       88:   # print "Figure file: $figfile\n";
1.14      sakharuk   89:   if (-e $figfile) {
1.73      foxr       90:       # print "$figfile exists\n";
1.42      albertel   91:       my %done_conversion;
1.69      matthew    92:       my $temporary_file=IO::File->new($figfile) || die "Couldn't open fig file $figfile for reading: $!\n";
1.14      sakharuk   93:       my @content_of_file = <$temporary_file>;
                     94:       close $temporary_file;  
                     95:       my $noteps;
1.49      albertel   96:       my %prog_state;
1.59      albertel   97:       if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Coverting Images to EPS','Picture Conversion Status',$#content_of_file,'inline','80');  }
                     98:       foreach my $not_eps (@content_of_file) {
1.49      albertel   99: 	  chomp($not_eps);
1.14      sakharuk  100: 	  if ($not_eps ne '') {
1.73      foxr      101: 	      # print "Converting $not_eps"; # Debugging.
1.44      sakharuk  102:               my $status_statement='EPS picture for '.$not_eps;
1.73      foxr      103: 	      # print "$status_statement\n";
1.41      sakharuk  104: 	      $not_eps=~s|\/\.\/|\/|g;
1.14      sakharuk  105: 	      my $eps_f = $not_eps;
                    106: 	      $eps_f =~ s/\.[^.]*$/\.eps/i;
1.41      sakharuk  107: 	      if ($eps_f=~/\/home\/([^\/]+)\/public_html\//) {
                    108:                   $eps_f=~s/\/home\/([^\/]+)\/public_html/$1/;
                    109: 		  $eps_f = '/home/httpd/prtspool/'.$eps_f;
1.58      sakharuk  110: 	      } elsif ($eps_f=~/$Apache::lonnet::perlvar{'lonDocRoot'}\/res\//) {
                    111: 		  $eps_f=~m/$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/(.+)/;
1.41      sakharuk  112: 		  $eps_f = '/home/httpd/prtspool/'.$1;
1.58      sakharuk  113: 	      } elsif ($eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\//) {
1.57      sakharuk  114: 		  $eps_f=~/$Apache::lonnet::perlvar{'lonUsersDir'}\/([^\/]+)\/\w\/\w\/\w\/(.+)/;
1.56      sakharuk  115: 		  $eps_f = '/home/httpd/prtspool/'.$1.'/'.$2;
1.41      sakharuk  116: 	      }
1.74    ! foxr      117: 	      $eps_f  =~ s/ /\_/g; # Spaces are problematic for system commands and LaTeX.
1.38      sakharuk  118: 	      my $path=$eps_f;
1.74    ! foxr      119: 	      $path =~ s/\/([^\/]+)\.eps$//;
1.73      foxr      120: 	      # print "Final file path: $path "; # Debugging
1.38      sakharuk  121: 	      File::Path::mkpath($path,0,0777);
1.14      sakharuk  122: 	      $not_eps =~ s/^\s+//;
                    123: 	      $not_eps =~ s/\s+$//;
1.74    ! foxr      124: 	      $not_eps =~ s/ /\\ /g;
1.72      albertel  125: 	      if ( exists($done_conversion{$not_eps})) { next; }
1.49      albertel  126: 	      if ($adv) {
                    127: 		  my $prettyname=$not_eps;
                    128: 		  $prettyname=~s|/home/([^/]+)/public_html|/priv/$1|;
1.58      sakharuk  129: 		  $prettyname=~s|$Apache::lonnet::perlvar{'lonDocRoot'}/|/|;
1.72      albertel  130: 		  &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Converting to EPS '.$prettyname);
                    131: 	      }
1.42      albertel  132: 	      $done_conversion{$not_eps}=1;
1.73      foxr      133: 	      # print "Converting $not_eps -> $eps_f"; # Debugging
1.72      albertel  134: 	      system("convert $not_eps $eps_f");
1.20      sakharuk  135:               #check is eps exist in prtspool
                    136:               if(not -e $eps_f) {
                    137: 		  for (my $i=0;$i<10000;$i++) {
                    138: 		      if (-e $eps_f.'.'.$i) {
                    139: 			  rename $eps_f.'.'.$i, $eps_f;
                    140: 			  last;
                    141: 		      }
                    142: 		  }
                    143: 	      }  
1.14      sakharuk  144: 	  }
                    145:       }
1.74    ! foxr      146:       if ($adv) { 
        !           147: 	  &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); 
        !           148:       }
1.52      albertel  149:       unlink($figfile);
1.14      sakharuk  150:   }
1.43      sakharuk  151:   #print "$texfile\n"; #name of the tex file for debugging only   
                    152:   my @texfile=($texfile);
                    153:   if ($number_of_files>1) {
1.49      albertel  154:       @texfile=();
                    155:       for (my $i=1;$i<=$number_of_files;$i++) {
1.43      sakharuk  156: 	  my $new_texfile=$texfile;
1.49      albertel  157: 	  $new_texfile=~s/\.tex/_$i\.tex/;
1.43      sakharuk  158: 	  push @texfile,$new_texfile;
                    159:       } 
                    160:   }
1.49      albertel  161: 
1.44      sakharuk  162: my $ind=-1;
1.49      albertel  163: my %prog_state;
1.61      albertel  164: print "<a href=\"$backref\"><b>Return</b></a> to last resource.<br /><br />";
1.59      albertel  165: if ($adv) { %prog_state=&Apache::lonhtmlcommon::Create_PrgWin('','Print Status','Class Print Status',$number_of_files,'inline','80'); }
1.61      albertel  166: print "<br />";
1.43      sakharuk  167: foreach $texfile (@texfile) {
1.49      albertel  168:   my $status_statement='';
                    169:   my $link_text='download PDF';
                    170:   $ind++;
                    171:   my @stud_info=split(/_END_/,$names_pack[$ind]);
                    172:   my @tempo_array=split(/:/,$stud_info[0]);
                    173:   my $name;
                    174:   if ($tempo_array[3]) {
                    175:       $name=$tempo_array[3];
                    176:   } else {
                    177:       $name=$tempo_array[0].'@'.$tempo_array[1];
                    178:   }
1.61      albertel  179:   $link_text='<b>'.$name.'</b>';
1.49      albertel  180:   $status_statement.=$name;
                    181:   if ($#stud_info>0) {
                    182:       @tempo_array=split(/:/,$stud_info[-1]);
1.48      albertel  183:       if ($tempo_array[3]) {
                    184: 	  $name=$tempo_array[3];
                    185:       } else {
                    186: 	  $name=$tempo_array[0].'@'.$tempo_array[1];
                    187:       }
1.61      albertel  188:       $link_text.=' - <b>'.$name.'</b>';
1.49      albertel  189:       $status_statement.=' -  '.$name;
                    190:   } 
                    191:   if ($adv) { &Apache::lonhtmlcommon::Update_PrgWin('',\%prog_state,'Creating PDF for '.$status_statement); }
1.29      sakharuk  192:   if (-e $texfile) {
                    193:       $texfile =~ m/^(.*)\/([^\/]+)$/; 
                    194:       my $name_file = $2;
                    195:       my $path_file = $1.'/';
                    196:       chdir $path_file;
1.59      albertel  197:       my $dvi_file= $name_file; $dvi_file =~ s/\.tex/\.dvi/;
                    198:       &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null",
                    199: 			 "for $status_statement now LaTeXing file",
                    200: 			 \%prog_state,$dvi_file);
1.40      sakharuk  201:       if ($tableofcontents eq 'yes') {
1.63      sakharuk  202:       &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null",
                    203: 			 "for $status_statement now LaTeXing file for table of contents",
                    204: 			 \%prog_state,$dvi_file);
1.40      sakharuk  205:       } #to create table of contents
1.33      sakharuk  206:       my $idxname=$name_file;
                    207:       $idxname=~s/\.tex$/\.idx/;
1.40      sakharuk  208:       if ($tableofindex eq 'yes') {
1.63      sakharuk  209: 	  &busy_wait_command("makeindex $idxname",
                    210: 			     "making index file",
                    211: 			     \%prog_state,$idxname);
                    212: 	  &busy_wait_command("latex $name_file 1>/dev/null 2>/dev/null",
                    213: 			     "for $status_statement now LaTeXing file for index section",
                    214: 			     \%prog_state,$dvi_file);
1.33      sakharuk  215:       } #to create index
1.29      sakharuk  216:       #Do we have a latex error in the log file?
1.67      sakharuk  217:       my $logfilename = $texfile; $logfilename =~ s/\.tex$/\.log/;
1.69      matthew   218:       my $temporary_file=IO::File->new($logfilename) || die "Couldn't open log file $logfilename for reading: $!\n";
1.29      sakharuk  219:       my @content_of_file = <$temporary_file>;
                    220:       close $temporary_file; 
1.30      sakharuk  221:       my $body_log_file = join(' ',@content_of_file);
                    222:       $logfilename =~ s/\.log$/\.html/;
                    223:       $temporary_file = IO::File->new('>'.$logfilename); 
                    224:       print $temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_log_file.'</pre></body></html>'."\n";
1.29      sakharuk  225:       if ($body_log_file=~m/!\s+Emergency stop/) {
                    226: 	  #LaTeX failed to parse tex file 
                    227: 	  print "<h2>LaTeX could not successfully parse your tex file.</h2>";
                    228: 	  print "It probably has errors in it.<br />";
                    229: 	  my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
                    230: 	  my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
                    231: 	  if ($whereitbegins!=-1 and $whereitends!=-1) {
1.44      sakharuk  232:  	      print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
1.29      sakharuk  233: 	  }
1.70      albertel  234: 	  print "Here are the error messages in the LaTeX log file</br><br /><pre>";
1.29      sakharuk  235: 	  my $sygnal = 0;
                    236: 	  for (my $i=0;$i<=$#content_of_file;$i++) {
                    237: 	      if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
                    238: 		  $sygnal = 1;
                    239: 	      } 
                    240: 	      if ($content_of_file[$i]=~m/Here is how much of/) {
                    241: 		  $sygnal = 0;
                    242: 	      } 
                    243: 	      if ($sygnal) {
1.70      albertel  244: 		  print "$content_of_file[$i]";
1.29      sakharuk  245: 	      }  
1.36      sakharuk  246: 	  }
1.70      albertel  247: 	  print "</pre>\n";
1.36      sakharuk  248:           if ($advans_role) {  
1.35      sakharuk  249:               print "<b><big>The link to ";
                    250:               $logfilename=~s/\/home\/httpd//;
                    251: 	      print "<a href=\"$logfilename\">Your log file </a></big></b>";
                    252: 	      print "\n";
                    253:               #link tooriginal LaTeX file (included according Michael Hamlin desire)
1.69      matthew   254: 	      my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n";
1.35      sakharuk  255: 	      my @tex_content_of_file = <$tex_temporary_file>;
                    256: 	      close $tex_temporary_file; 
                    257: 	      my $body_tex_file = join(' ',@tex_content_of_file);
                    258: 	      $texfile =~ s/\.tex$/aaaaa\.html/;
                    259: 	      $tex_temporary_file = IO::File->new('>'.$texfile); 
                    260: 	      print $tex_temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_tex_file.'</pre></body></html>'."\n";
                    261: 	      print "<br /><br />";
                    262: 	      print "<b><big>The link to ";
                    263: 	      $texfile=~s/\/home\/httpd//;
                    264: 	      print "<a href=\"$texfile\">Your original LaTeX file </a></big></b>";
                    265: 	      print "\n";
1.36      sakharuk  266: 	  }
1.35      sakharuk  267: 
1.29      sakharuk  268:       } elsif ($body_log_file=~m/<inserted text>/) {
                    269: 	  my $whereitbegins = index $body_log_file,'<inserted text>';
1.59      albertel  270: 	  print "You are running LaTeX in <b>batch mode</b>.";
1.30      sakharuk  271: 	  while ($whereitbegins != -1) {
                    272: 	      my $tempobegin=$whereitbegins;
                    273: 	      $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins;
                    274: 	      my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins;
1.34      sakharuk  275: 	      print "<br />It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)." <br /> and corrected it.\n";
1.30      sakharuk  276: 	      print "Usually this correction is valid but you probably need to check the indicated resource one more time and implement neccessary corrections by yourself.\n";
                    277: 	      $whereitbegins = index $body_log_file,'<inserted text>',$tempobegin+10;
                    278: 	  }
1.29      sakharuk  279: 	  $name_file =~ s/\.tex/\.dvi/;
                    280: 	  my $new_name_file = $name_file;
                    281: 	  $new_name_file =~ s/\.dvi/\.ps/;
1.67      sakharuk  282: 	  my $papera=$paper;
1.62      sakharuk  283: 	  if ($papera eq 'letter') {$papera='';}
                    284: 	  if ($papera ne '') {$papera='-t'.$papera;}
                    285: 	  my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
1.59      albertel  286: 	  &busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null",
                    287: 			     "for $status_statement now Converting to PS",
                    288: 			     \%prog_state,$new_name_file);
1.29      sakharuk  289: 	  if (-e $new_name_file) {
                    290: 	      print "<h1>PDF output file (see link below)</h1>\n";
                    291: 	      $new_name_file =~ m/^(.*)\./;
1.59      albertel  292: 	      my $ps_file = my $tempo_file = $1.'temporar.ps';
                    293: 	      my $pdf_file = $1.'.pdf';
1.29      sakharuk  294: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    295: 		  $comma = "psnup -2 -s1.0 $new_name_file";
1.59      albertel  296: 		  &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
                    297: 				     "for $status_statement now Modifying PS layout",
                    298: 				     \%prog_state,$tempo_file); 
1.29      sakharuk  299: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.67      sakharuk  300: 		  my $papera=$paper;
                    301:                   if ($papera eq 'letter') {$papera='';}
1.62      sakharuk  302: 		  if ($papera ne '') {$papera='-p'.$papera;}
                    303: 		  $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
1.63      sakharuk  304: 		  &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
                    305: 				     "for $status_statement now Modifying PS layout",
                    306: 				     \%prog_state,$tempo_file); 
                    307: 
1.29      sakharuk  308: 	      } else {
1.59      albertel  309: 		  $ps_file=$new_name_file;
1.29      sakharuk  310: 	      }	    
1.59      albertel  311: 	      &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null",
                    312: 				 "for $status_statement now Converting PS to PDF",
                    313: 				 \%prog_state, $pdf_file);
                    314: 
1.29      sakharuk  315: 	      my $texlog = $texfile;
                    316: 	      my $texaux = $texfile;
                    317: 	      my $texdvi = $texfile;
                    318: 	      my $texps = $texfile;
                    319: 	      $texlog =~ s/\.tex/\.log/;
                    320: 	      $texaux =~ s/\.tex/\.aux/;
                    321: 	      $texdvi =~ s/\.tex/\.dvi/;
                    322: 	      $texps =~ s/\.tex/\.ps/;
1.30      sakharuk  323: 	      my @garb = ($texaux,$texdvi,$texps);
1.29      sakharuk  324: #	  unlink @garb;
                    325: 	      unlink $duefile;
1.59      albertel  326: 	      print "<a href=\"/prtspool/$pdf_file\">Your PDF document</a>";
1.36      sakharuk  327: 	      if ($advans_role) {  
                    328: 		  print "<br /><br />";
                    329: 		  print "<b><big>The link to ";
                    330: 		  $logfilename=~s/\/home\/httpd//;
                    331: 		  print "<a href=\"$logfilename\">Your log file </a></big></b>";
                    332: 		  print "\n";
                    333: 		  #link tooriginal LaTeX file (included according Michael Hamlin desire)
1.69      matthew   334: 		  my $tex_temporary_file=IO::File->new($texfile) || die "Couldn't open tex file $texfile for reading: $!\n";
1.36      sakharuk  335: 		  my @tex_content_of_file = <$tex_temporary_file>;
                    336: 		  close $tex_temporary_file; 
                    337: 		  my $body_tex_file = join(' ',@tex_content_of_file);
                    338: 		  $texfile =~ s/\.tex$/aaaaa\.html/;
                    339: 		  $tex_temporary_file = IO::File->new('>'.$texfile); 
                    340: 		  print $tex_temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_tex_file.'</pre></body></html>'."\n";
                    341: 		  print "<br /><br />";
                    342: 		  print "<b><big>The link to ";
                    343: 		  $texfile=~s/\/home\/httpd//;
                    344: 		  print "<a href=\"$texfile\">Your original LaTeX file </a></big></b>";
                    345: 		  print "\n";
                    346: 	      }
1.29      sakharuk  347: 	  }
                    348:       } else {
                    349: 	  #LaTeX successfully parsed tex file 
                    350: 	  $name_file =~ s/\.tex/\.dvi/;
                    351: 	  my $new_name_file = $name_file;
                    352: 	  $new_name_file =~ s/\.dvi/\.ps/;
1.67      sakharuk  353: 	  my $papera=$paper;
1.62      sakharuk  354: 	  if ($papera eq 'letter') {$papera='';}
                    355: 	  if ($papera ne '') {$papera='-t'.$papera;}
                    356: 	  my $comma = "dvips $papera -Ppdf -G0 -o $new_name_file";
1.59      albertel  357: 	  &busy_wait_command("$comma $name_file 1>/dev/null 2>/dev/null",
                    358: 			     "for $status_statement now Converting to PS",
                    359: 			     \%prog_state,$new_name_file);
1.29      sakharuk  360: 	  if (-e $new_name_file) {
1.61      albertel  361: 	      print "<br />";
1.29      sakharuk  362: 	      $new_name_file =~ m/^(.*)\./;
1.59      albertel  363: 	      my $ps_file = my $tempo_file = $1.'temporar.ps';
                    364: 	      my $pdf_file = $1.'.pdf';
1.29      sakharuk  365: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    366: 		  $comma = "psnup -2 -s1.0 $new_name_file";
1.59      albertel  367: 		  &busy_wait_command("$comma $tempo_file 1>/dev/null 2>/dev/null",
                    368: 				     "for $status_statement now Modifying PS layout",
                    369: 				     \%prog_state,$tempo_file);
1.29      sakharuk  370: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
1.65      sakharuk  371: 		  $papera=~s/t/p/;
                    372: 		  $comma = 'pstops '.$papera.' "2:0+1(0.48w,0)"';
1.59      albertel  373: 		  &busy_wait_command("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null",
                    374: 				     "for $status_statement now Modifying PS layout",
                    375: 				     \%prog_state,$tempo_file); 
1.29      sakharuk  376: 	      } else {
1.59      albertel  377: 		  $ps_file=$new_name_file;
                    378: 	      }
1.67      sakharuk  379: 	      my $addtoPSfile={'legal'=>'<< /PageSize [612 1008] >> setpagedevice',
                    380:                                'tabloid'=>'<< /PageSize [792 1224] >> setpagedevice',
                    381:                                'executive'=>,'<< /PageSize [540 720] >> setpagedevice',
                    382:                                'a2'=>'<< /PageSize [1195.02 1690.09] >> setpagedevice',
                    383:                                'a3'=>'<< /PageSize [842 1195.02] >> setpagedevice',
                    384:                                'a4'=>'<< /PageSize [595.2 842] >> setpagedevice',
                    385:                                'a5'=>'<< /PageSize [421.1 595.2] >> setpagedevice',
                    386:                                'a6'=>'<< /PageSize [298.75 421.1] >> setpagedevice',
                    387: 			   };
                    388: 	      if ($paper ne 'letter') {
1.69      matthew   389: 		  open(FFH,'<',$ps_file) || die "Couldn't open ps file $ps_file for reading: $!\n";
1.63      sakharuk  390: 		  my $new_ps_file='new'.$ps_file;
1.69      matthew   391: 		  open(FFHS,'>',$new_ps_file) || die "Couldn't open new ps file $new_ps_file for reading: $!\n";
1.67      sakharuk  392: 		  print FFHS $addtoPSfile->{$paper}."\n";
1.63      sakharuk  393: 		  while (<FFH>) {
                    394: 		      print FFHS $_;
                    395: 		  }
1.62      sakharuk  396: 		  close(FFH);
1.63      sakharuk  397: 		  close(FFHS);
                    398: 		  $ps_file=$new_ps_file;	  
1.62      sakharuk  399: 	      }
1.59      albertel  400: 	      &busy_wait_command("ps2pdf $ps_file $pdf_file 1>/dev/null 2>/dev/null",
                    401: 				 "for $status_statement now Converting PS to PDF",
                    402: 				 \%prog_state,$pdf_file);
                    403: 	    
1.29      sakharuk  404: 	      my $texlog = $texfile;
                    405: 	      my $texaux = $texfile;
                    406: 	      my $texdvi = $texfile;
                    407: 	      my $texps = $texfile;
                    408: 	      $texlog =~ s/\.tex/\.log/;
                    409: 	      $texaux =~ s/\.tex/\.aux/;
                    410: 	      $texdvi =~ s/\.tex/\.dvi/;
                    411: 	      $texps =~ s/\.tex/\.ps/;
                    412: 	      my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22      sakharuk  413: #	  unlink @garb;
1.29      sakharuk  414: 	      unlink $duefile;
1.68      sakharuk  415: 	      print "<a href=\"/prtspool/$pdf_file\">$link_text - click here to download pdf</a>";
1.29      sakharuk  416: 	      print "\n";
                    417: 	  }
1.63      sakharuk  418:       }  
1.29      sakharuk  419:   } else {
                    420:       print "LaTeX file $texfile was not created successfully";
1.14      sakharuk  421:   }
1.43      sakharuk  422: }
1.45      sakharuk  423: print "<br />";
1.44      sakharuk  424: if ($number_of_files>1) {
1.45      sakharuk  425:     my $zipfile=$texfile[0];
                    426:     $zipfile=~s/\.tex/\.zip/;
                    427:     my $statement="zip $zipfile";
1.44      sakharuk  428:     foreach my $file (@texfile) {
1.45      sakharuk  429: 	$file=~s/\.tex/.\pdf/;
                    430: 	$statement.=' '.$file; 
1.44      sakharuk  431:     }
1.49      albertel  432:     print("<pre>Zip Output:\n");
                    433:     system($statement);
                    434:     print("</pre>");
1.45      sakharuk  435:     $zipfile=~s/\/home\/httpd//;
1.49      albertel  436:     print "<br /> A <a href=\"$zipfile\">ZIP file</a> of all the PDFs.";
1.44      sakharuk  437: }
1.49      albertel  438: if ($adv) { &Apache::lonhtmlcommon::Close_PrgWin('',\%prog_state); }
1.1       sakharuk  439: 
1.59      albertel  440: my $done;
                    441: sub REAPER {
                    442:     $done=1;
                    443: }
                    444: 
                    445: sub busy_wait_command {
                    446:     my ($command,$message,$progress_win,$output_file)=@_;
                    447:     
                    448:     $SIG{CHLD} = \&REAPER;
                    449:     $done=0;
                    450:     my $pid=open(CMD,"$command |");
1.60      albertel  451:     if ($adv) {
                    452: 	&Apache::lonhtmlcommon::Update_PrgWin('',$progress_win,$message);
                    453:     }
1.59      albertel  454:     while(!$done) {
                    455: 	sleep 1;
                    456: 	my $extra_msg;
                    457: 	if ($output_file) {
                    458: 	    my $size=(stat($output_file))[7];
                    459: 	    $extra_msg=", $size bytes generated";
                    460: 	}
1.60      albertel  461: 	if ($adv) {
                    462: 	    &Apache::lonhtmlcommon::Update_PrgWin('',$progress_win,
                    463: 						  $message.$extra_msg);
                    464: 	}
1.59      albertel  465:     }
                    466:     $SIG{CHLD}='IGNORE';
                    467:     close(CMD);
                    468: }
1.1       sakharuk  469: 
                    470: 
                    471: 
1.4       sakharuk  472: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>