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