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

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.29      sakharuk   91:       } elsif ($body_log_file=~m/<inserted text>/) {
                     92: 	  my $whereitbegins = index $body_log_file,'<inserted text>';
1.31      sakharuk   93: 	  print "You are running LaTeX in the <b>batch mode</b>.";
1.30      sakharuk   94: 	  while ($whereitbegins != -1) {
                     95: 	      my $tempobegin=$whereitbegins;
                     96: 	      $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins;
                     97: 	      my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins;
1.31      sakharuk   98: 	      print "<br />It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)." and corrected it.\n";
1.30      sakharuk   99: 	      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";
                    100: 	      $whereitbegins = index $body_log_file,'<inserted text>',$tempobegin+10;
                    101: 	  }
1.29      sakharuk  102: 	  $name_file =~ s/\.tex/\.dvi/;
                    103: 	  my $new_name_file = $name_file;
                    104: 	  $new_name_file =~ s/\.dvi/\.ps/;
                    105: 	  my $comma = "dvips -Ppdf -G0 -o $new_name_file";
                    106: 	  system("$comma $name_file 1>/dev/null 2>/dev/null");
                    107: 	  if (-e $new_name_file) {
                    108: 	      print "<h1>PDF output file (see link below)</h1>\n";
                    109: 	      $new_name_file =~ m/^(.*)\./;
                    110: 	      my $tempo_file = $1.'temporar.ps';
                    111: 	      my $name_file = $1.'.pdf';
                    112: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    113: 		  $comma = "psnup -2 -s1.0 $new_name_file";
                    114: 		  system("$comma $tempo_file 1>/dev/null 2>/dev/null"); 
                    115: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    116: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
                    117: 		  $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
                    118: 		  system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
                    119: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    120: 	      } else {
                    121: 		  system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
                    122: 	      }	    
                    123: 	      my $texlog = $texfile;
                    124: 	      my $texaux = $texfile;
                    125: 	      my $texdvi = $texfile;
                    126: 	      my $texps = $texfile;
                    127: 	      $texlog =~ s/\.tex/\.log/;
                    128: 	      $texaux =~ s/\.tex/\.aux/;
                    129: 	      $texdvi =~ s/\.tex/\.dvi/;
                    130: 	      $texps =~ s/\.tex/\.ps/;
1.30      sakharuk  131: 	      my @garb = ($texaux,$texdvi,$texps);
1.29      sakharuk  132: #	  unlink @garb;
                    133: 	      unlink $duefile;
                    134: 	      print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
1.30      sakharuk  135: 	      print "<br /><br />";
                    136:               print "<b><big>The link to ";
                    137:               $logfilename=~s/\/home\/httpd//;
                    138: 	      print "<a href=\"$logfilename\">Your log file </a></big></b>";
1.29      sakharuk  139: 	      print "\n";
                    140: 	  }
                    141:       } else {
                    142: 	  #LaTeX successfully parsed tex file 
                    143: 	  $name_file =~ s/\.tex/\.dvi/;
                    144: 	  my $new_name_file = $name_file;
                    145: 	  $new_name_file =~ s/\.dvi/\.ps/;
                    146: 	  my $comma = "dvips -Ppdf -G0 -o $new_name_file";
                    147: 	  system("$comma $name_file 1>/dev/null 2>/dev/null");
                    148: 	  if (-e $new_name_file) {
                    149: 	      print "<h1>Successfully created PDF output file (see link below)</h1>\n";
                    150: 	      $new_name_file =~ m/^(.*)\./;
                    151: 	      my $tempo_file = $1.'temporar.ps';
                    152: 	      my $name_file = $1.'.pdf';
                    153: 	      if ($laystyle eq 'album' and $numberofcolumns eq '2') {
                    154: 		  $comma = "psnup -2 -s1.0 $new_name_file";
                    155: 		  system("$comma $tempo_file 1>/dev/null 2>/dev/null"); 
                    156: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    157: 	      } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
                    158: 		  $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
                    159: 		  system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
                    160: 		  system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
                    161: 	      } else {
                    162: 		  system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
                    163: 	      }	    
                    164: 	      my $texlog = $texfile;
                    165: 	      my $texaux = $texfile;
                    166: 	      my $texdvi = $texfile;
                    167: 	      my $texps = $texfile;
                    168: 	      $texlog =~ s/\.tex/\.log/;
                    169: 	      $texaux =~ s/\.tex/\.aux/;
                    170: 	      $texdvi =~ s/\.tex/\.dvi/;
                    171: 	      $texps =~ s/\.tex/\.ps/;
                    172: 	      my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22      sakharuk  173: #	  unlink @garb;
1.29      sakharuk  174: 	      unlink $duefile;
                    175: 	      print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
                    176: 	      print "\n";
                    177: 	  }
1.14      sakharuk  178:       }
1.29      sakharuk  179:   } else {
                    180:       print "LaTeX file $texfile was not created successfully";
1.14      sakharuk  181:   }
1.17      sakharuk  182: 
                    183: 
                    184:   
1.1       sakharuk  185: 
                    186: 
                    187: 
                    188: 
1.4       sakharuk  189: 

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