Annotation of loncom/interface/printout.pl, revision 1.29
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");
! 52: #Do we have a latex error in the log file?
! 53: my $logfilename = $texfile;
! 54: $logfilename =~ s/\.tex$/\.log/;
! 55: my $temporary_file=IO::File->new($logfilename) || die "Couldn't open file for reading: $!\n";
! 56: my @content_of_file = <$temporary_file>;
! 57: close $temporary_file;
! 58: my $body_log_file = join(' ',@content_of_file);
! 59: if ($body_log_file=~m/!\s+Emergency stop/) {
! 60: #LaTeX failed to parse tex file
! 61: print "<h2>LaTeX could not successfully parse your tex file.</h2>";
! 62: print "It probably has errors in it.<br />";
! 63: my $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART';
! 64: my $whereitends = rindex $body_log_file,'STAMPOFPASSEDRESOURCEEND';
! 65: if ($whereitbegins!=-1 and $whereitends!=-1) {
! 66: print "With very high probability this error occured in ".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)."<br /><br />";
! 67: }
! 68: print "Here are the error messages in the LaTeX log file</br><br />";
! 69: my $sygnal = 0;
! 70: for (my $i=0;$i<=$#content_of_file;$i++) {
! 71: if ($content_of_file[$i]=~m/^Runaway argument?/ or $content_of_file[$i]=~m/^!/) {
! 72: $sygnal = 1;
! 73: }
! 74: if ($content_of_file[$i]=~m/Here is how much of/) {
! 75: $sygnal = 0;
! 76: }
! 77: if ($sygnal) {
! 78: print "$content_of_file[$i]<br />";
! 79: }
1.17 sakharuk 80: }
1.29 ! sakharuk 81: } elsif ($body_log_file=~m/<inserted text>/) {
! 82: my $whereitbegins = index $body_log_file,'<inserted text>';
! 83: $whereitbegins = rindex $body_log_file,'STAMPOFPASSEDRESOURCESTART',$whereitbegins;
! 84: my $whereitends = index $body_log_file,'STAMPOFPASSEDRESOURCEEND',$whereitbegins;
! 85: print "You are running LaTeX in the <b>batch mode</b>. \n";
! 86: print "It has found an error in".substr($body_log_file,$whereitbegins+26,$whereitends-$whereitbegins-26)." and corrected it.\n";
! 87: 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";
! 88: $name_file =~ s/\.tex/\.dvi/;
! 89: my $new_name_file = $name_file;
! 90: $new_name_file =~ s/\.dvi/\.ps/;
! 91: my $comma = "dvips -Ppdf -G0 -o $new_name_file";
! 92: system("$comma $name_file 1>/dev/null 2>/dev/null");
! 93: if (-e $new_name_file) {
! 94: print "<h1>PDF output file (see link below)</h1>\n";
! 95: $new_name_file =~ m/^(.*)\./;
! 96: my $tempo_file = $1.'temporar.ps';
! 97: my $name_file = $1.'.pdf';
! 98: if ($laystyle eq 'album' and $numberofcolumns eq '2') {
! 99: $comma = "psnup -2 -s1.0 $new_name_file";
! 100: system("$comma $tempo_file 1>/dev/null 2>/dev/null");
! 101: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
! 102: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
! 103: $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
! 104: system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
! 105: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
! 106: } else {
! 107: system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
! 108: }
! 109: my $texlog = $texfile;
! 110: my $texaux = $texfile;
! 111: my $texdvi = $texfile;
! 112: my $texps = $texfile;
! 113: $texlog =~ s/\.tex/\.log/;
! 114: $texaux =~ s/\.tex/\.aux/;
! 115: $texdvi =~ s/\.tex/\.dvi/;
! 116: $texps =~ s/\.tex/\.ps/;
! 117: my @garb = ($texlog,$texaux,$texdvi,$texps);
! 118: # unlink @garb;
! 119: unlink $duefile;
! 120: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
! 121: print "\n";
! 122: }
! 123: } else {
! 124: #LaTeX successfully parsed tex file
! 125: $name_file =~ s/\.tex/\.dvi/;
! 126: my $new_name_file = $name_file;
! 127: $new_name_file =~ s/\.dvi/\.ps/;
! 128: my $comma = "dvips -Ppdf -G0 -o $new_name_file";
! 129: system("$comma $name_file 1>/dev/null 2>/dev/null");
! 130: if (-e $new_name_file) {
! 131: print "<h1>Successfully created PDF output file (see link below)</h1>\n";
! 132: $new_name_file =~ m/^(.*)\./;
! 133: my $tempo_file = $1.'temporar.ps';
! 134: my $name_file = $1.'.pdf';
! 135: if ($laystyle eq 'album' and $numberofcolumns eq '2') {
! 136: $comma = "psnup -2 -s1.0 $new_name_file";
! 137: system("$comma $tempo_file 1>/dev/null 2>/dev/null");
! 138: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
! 139: } elsif ($laystyle eq 'book' and $numberofcolumns eq '2') {
! 140: $comma = 'pstops -pletter "2:0+1(0.48w,0)"';
! 141: system("$comma $new_name_file $tempo_file 1>/dev/null 2>/dev/null");
! 142: system("ps2pdf $tempo_file $name_file 1>/dev/null 2>/dev/null");
! 143: } else {
! 144: system("ps2pdf $new_name_file $name_file 1>/dev/null 2>/dev/null");
! 145: }
! 146: my $texlog = $texfile;
! 147: my $texaux = $texfile;
! 148: my $texdvi = $texfile;
! 149: my $texps = $texfile;
! 150: $texlog =~ s/\.tex/\.log/;
! 151: $texaux =~ s/\.tex/\.aux/;
! 152: $texdvi =~ s/\.tex/\.dvi/;
! 153: $texps =~ s/\.tex/\.ps/;
! 154: my @garb = ($texlog,$texaux,$texdvi,$texps);
1.22 sakharuk 155: # unlink @garb;
1.29 ! sakharuk 156: unlink $duefile;
! 157: print "<a href=\"/prtspool/$name_file\">Your PDF document</a>";
! 158: print "\n";
! 159: }
1.14 sakharuk 160: }
1.29 ! sakharuk 161: } else {
! 162: print "LaTeX file $texfile was not created successfully";
1.14 sakharuk 163: }
1.17 sakharuk 164:
165:
166:
1.1 sakharuk 167:
168:
169:
170:
1.4 sakharuk 171:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>