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

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

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