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

1.1       sakharuk    1: #!/usr/bin/perl
1.6       sakharuk    2: use IO::File;
1.7       sakharuk    3: use Image::Magick;
1.14      sakharuk    4:  print "Content-type: text/html\n\n";
1.27      www         5:  print "<body bgcolor=\"#FFFFFF\">\n";
1.21      sakharuk    6:   my ($texfile,$laystyle,$numberofcolumns,$selectionmade) = split(/&/,$ENV{'QUERY_STRING'});
1.14      sakharuk    7:   my $figfile = $texfile;
                      8:   $figfile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.dat/;
                      9:   my $duefile = $texfile;
                     10:   $duefile =~ s/^([^\.]+printout)[^t]+\.tex/$1\.due/;
                     11:   #do we have figures?
                     12:   if (-e $figfile) {
                     13:       my $temporary_file=IO::File->new($figfile) || die "Couldn't open file for reading: $!\n";
                     14:       my @content_of_file = <$temporary_file>;
                     15:       close $temporary_file;  
                     16:       my $noteps;
                     17:       foreach $not_eps (@content_of_file) {
                     18: 	  if ($not_eps ne '') {
                     19: 	      my $eps_f = $not_eps;
                     20: 	      $eps_f =~ s/\.[^.]*$/\.eps/i;
                     21: 	      $_ = $eps_f;
                     22: 	      m/\/([^\/]+)$/;
                     23: 	      $eps_f = '/home/httpd/prtspool/'.$1;
                     24: 	      my $image = Image::Magick->new;
                     25: 	      $not_eps =~ s/^\s+//;
                     26: 	      $not_eps =~ s/\s+$//;
                     27: 	      $status = $image->Read($not_eps);
                     28: 	      if ($status) {print "  $status  ";}
                     29: 	      $image->Set(page => '+100+200'); 
                     30: 	      $status = $image->Write($eps_f);	    
                     31: 	      if ($status) {print "  $status  ";}
1.20      sakharuk   32:               #check is eps exist in prtspool
                     33:               if(not -e $eps_f) {
                     34: 		  for (my $i=0;$i<10000;$i++) {
                     35: 		      if (-e $eps_f.'.'.$i) {
                     36: 			  rename $eps_f.'.'.$i, $eps_f;
                     37: 			  last;
                     38: 		      }
                     39: 		  }
                     40: 	      }  
1.14      sakharuk   41: 	  }
                     42:       }
                     43:       unlink $figfile;
                     44:   }
                     45:   #print "$texfile\n"; #name of the tex file for debugging only
1.29      sakharuk   46:   if (-e $texfile) {
                     47:       $texfile =~ m/^(.*)\/([^\/]+)$/; 
                     48:       my $name_file = $2;
                     49:       my $path_file = $1.'/';
                     50:       chdir $path_file;
                     51:       system("latex $name_file 1>/dev/null 2>/dev/null");
1.32    ! sakharuk   52:       if ($selectionmade>10) {system("latex $name_file 1>/dev/null 2>/dev/null");} #to create tableof contents
1.29      sakharuk   53:       #Do we have a latex error in the log file?
                     54:       my $logfilename = $texfile;
                     55:       $logfilename =~ s/\.tex$/\.log/;
                     56:       my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
                     57:       my @content_of_file = <$temporary_file>;
                     58:       close $temporary_file; 
1.30      sakharuk   59:       my $body_log_file = join(' ',@content_of_file);
                     60:       $logfilename =~ s/\.log$/\.html/;
                     61:       $temporary_file = IO::File->new('>'.$logfilename); 
                     62:       print $temporary_file '<html><head><title>LOGFILE</title></head><body><pre>'.$body_log_file.'</pre></body></html>'."\n";
1.29      sakharuk   63:       if ($body_log_file=~m/!\s+Emergency stop/) {
                     64: 	  #LaTeX failed to parse tex file 
                     65: 	  print "<h2>LaTeX could not successfully parse your tex file.</h2>";
                     66: 	  print "It probably has errors in it.<br />";
                     67: 	  my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
                     68: 	  my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
                     69: 	  if ($whereitbegins!=-1 and $whereitends!=-1) {
                     70: 	      print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
                     71: 	  }
                     72: 	  print "Here are the error messages in the LaTeX log file</br><br />";
                     73: 	  my $sygnal = 0;
                     74: 	  for (my $i=0;$i<=$#content_of_file;$i++) {
                     75: 	      if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
                     76: 		  $sygnal = 1;
                     77: 	      } 
                     78: 	      if ($content_of_file[$i]=~m/Here is how much of/) {
                     79: 		  $sygnal = 0;
                     80: 	      } 
                     81: 	      if ($sygnal) {
                     82: 		  print "$content_of_file[$i]<br />";
                     83: 	      }  
1.17      sakharuk   84: 	  } 
1.29      sakharuk   85:       } elsif ($body_log_file=~m/<inserted text>/) {
                     86: 	  my $whereitbegins = index $body_log_file,'<inserted text>';
1.31      sakharuk   87: 	  print "You are running LaTeX in the <b>batch mode</b>.";
1.30      sakharuk   88: 	  while ($whereitbegins != -1) {
                     89: 	      my $tempobegin=$whereitbegins;
                     90: 	      $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins;
                     91: 	      my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins;
1.31      sakharuk   92: 	      print "<br />It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)." and corrected it.\n";
1.30      sakharuk   93: 	      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";
                     94: 	      $whereitbegins = index $body_log_file,'<inserted text>',$tempobegin+10;
                     95: 	  }
1.29      sakharuk   96: 	  $name_file =~ s/\.tex/\.dvi/;
                     97: 	  my $new_name_file = $name_file;
                     98: 	  $new_name_file =~ s/\.dvi/\.ps/;
                     99: 	  my $comma = "dvips -Ppdf -G0 -o $new_name_file";
                    100: 	  system("$comma $name_file 1>/dev/null 2>/dev/null");
                    101: 	  if (-e $new_name_file) {
                    102: 	      print "<h1>PDF output file (see link below)</h1>\n";
                    103: 	      $new_name_file =~ m/^(.*)\./;
                    104: 	      my $tempo_file = $1.'temporar.ps';
                    105: 	      my $name_file = $1.'.pdf';
                    106: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    107: 		  $comma = "psnup -2 -s1.0 $new_name_file";
                    108: 		  system("$comma $tempo_file 1>/dev/null 2>/dev/null"); 
                    109: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    110: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
                    111: 		  $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
                    112: 		  system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
                    113: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    114: 	      } else {
                    115: 		  system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
                    116: 	      }	    
                    117: 	      my $texlog = $texfile;
                    118: 	      my $texaux = $texfile;
                    119: 	      my $texdvi = $texfile;
                    120: 	      my $texps = $texfile;
                    121: 	      $texlog =~ s/\.tex/\.log/;
                    122: 	      $texaux =~ s/\.tex/\.aux/;
                    123: 	      $texdvi =~ s/\.tex/\.dvi/;
                    124: 	      $texps =~ s/\.tex/\.ps/;
1.30      sakharuk  125: 	      my @garb = ($texaux,$texdvi,$texps);
1.29      sakharuk  126: #	  unlink @garb;
                    127: 	      unlink $duefile;
                    128: 	      print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
1.30      sakharuk  129: 	      print "<br /><br />";
                    130:               print "<b><big>The link to ";
                    131:               $logfilename=~s/\/home\/httpd//;
                    132: 	      print "<a href=\"$logfilename\">Your log file </a></big></b>";
1.29      sakharuk  133: 	      print "\n";
                    134: 	  }
                    135:       } else {
                    136: 	  #LaTeX successfully parsed tex file 
                    137: 	  $name_file =~ s/\.tex/\.dvi/;
                    138: 	  my $new_name_file = $name_file;
                    139: 	  $new_name_file =~ s/\.dvi/\.ps/;
                    140: 	  my $comma = "dvips -Ppdf -G0 -o $new_name_file";
                    141: 	  system("$comma $name_file 1>/dev/null 2>/dev/null");
                    142: 	  if (-e $new_name_file) {
                    143: 	      print "<h1>Successfully created PDF output file (see link below)</h1>\n";
                    144: 	      $new_name_file =~ m/^(.*)\./;
                    145: 	      my $tempo_file = $1.'temporar.ps';
                    146: 	      my $name_file = $1.'.pdf';
                    147: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    148: 		  $comma = "psnup -2 -s1.0 $new_name_file";
                    149: 		  system("$comma $tempo_file 1>/dev/null 2>/dev/null"); 
                    150: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    151: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
                    152: 		  $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
                    153: 		  system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
                    154: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    155: 	      } else {
                    156: 		  system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
                    157: 	      }	    
                    158: 	      my $texlog = $texfile;
                    159: 	      my $texaux = $texfile;
                    160: 	      my $texdvi = $texfile;
                    161: 	      my $texps = $texfile;
                    162: 	      $texlog =~ s/\.tex/\.log/;
                    163: 	      $texaux =~ s/\.tex/\.aux/;
                    164: 	      $texdvi =~ s/\.tex/\.dvi/;
                    165: 	      $texps =~ s/\.tex/\.ps/;
                    166: 	      my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22      sakharuk  167: #	  unlink @garb;
1.29      sakharuk  168: 	      unlink $duefile;
                    169: 	      print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
                    170: 	      print "\n";
                    171: 	  }
1.14      sakharuk  172:       }
1.29      sakharuk  173:   } else {
                    174:       print "LaTeX file $texfile was not created successfully";
1.14      sakharuk  175:   }
1.17      sakharuk  176: 
                    177: 
                    178:   
1.1       sakharuk  179: 
                    180: 
                    181: 
                    182: 
1.4       sakharuk  183: 

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