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

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

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