Annotation of loncom/interface/lonprintout.pm, revision 1.51.2.1
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.51.2.1! albertel 4: # $Id: lonprintout.pm,v 1.51 2002/08/14 20:38:04 sakharuk Exp $
1.11 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: # (Internal Server Error Handler
29: #
30: # (Login Screen
31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
33: #
34: # 3/1/1 Gerd Kortemeyer)
35: #
36: # 3/1 Gerd Kortemeyer
37: #
1.3 sakharuk 38: # 9/17 Alex Sakharuk
39: #
1.1 www 40: package Apache::lonprintout;
41:
42: use strict;
1.10 albertel 43: use Apache::Constants qw(:common :http);
1.2 sakharuk 44: use Apache::lonxml;
45: use Apache::lonnet;
1.13 sakharuk 46: use Apache::inputtags;
47: use Apache::edit;
1.5 sakharuk 48: use Apache::File();
1.34 sakharuk 49: use POSIX qw(strftime);
1.3 sakharuk 50:
51:
52: sub headerform {
1.1 www 53: my $r = shift;
1.3 sakharuk 54: $r->print(<<ENDHEADER);
55: <html>
56: <head>
57: <title>LON-CAPA output for printing</title>
58: </head>
59: <body bgcolor="FFFFFF">
60: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
1.38 www 61: <tt>$ENV{'form.postdata'}</tt><p>
1.16 sakharuk 62: <h1>What do you want to print? Make a choice.</h1><br />
1.3 sakharuk 63: ENDHEADER
64: }
65:
1.1 www 66:
1.3 sakharuk 67: sub menu_for_output {
68: my $r = shift;
1.28 sakharuk 69: $r->print(<<ENDMENUOUT1);
1.3 sakharuk 70: <input type="hidden" name="phase" value="two">
1.10 albertel 71: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
1.25 sakharuk 72: <input type="radio" name="choice" value="Standard LaTeX output for current document" checked> Current document
1.16 sakharuk 73: (you will print what you see on the screen)<br />
1.39 sakharuk 74: ENDMENUOUT1
1.48 sakharuk 75: if ((not $ENV{'request.role'}=~m/^au\./) and (not $ENV{'request.role'}=~m/^ca\./)) {
1.39 sakharuk 76: $r->print(<<ENDMENUOUT2);
1.19 sakharuk 77: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence"> All problems from the primary sequence<br />
1.20 sakharuk 78: <input type="radio" name="choice" value="Standard LaTeX output for whole primary sequence"> The whole primary sequence (problems plus all html and xml files)<br />
1.19 sakharuk 79: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence"> All problems from the top level sequence<br />
1.28 sakharuk 80: <br />
81: ENDMENUOUT2
1.44 sakharuk 82: }
1.39 sakharuk 83: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
84: $subdirtoprint =~ s/\/[^\/]+$//;
85: if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') {
86: $r->print(<<ENDMENUOUT4);
87: <input type="radio" name="choice" value="Subdirectory print"> All problems from current subdirectory (where this particular problem is)<br />
88: ENDMENUOUT4
89: }
90: $r->print(<<ENDMENUOUT5);
1.16 sakharuk 91: <br /><hr /><br />
92: <h1>And what page format do you prefer?</h1>
1.36 sakharuk 93: <table>
94: <tr>
95: <td>
96: <input type="radio" name="layout" value="CBI"> Landscape <br />
97: <input type="radio" name="layout" value="CAPA" checked> Portrait <br />
98: </td>
99: <td> </td>
100: <td rawspan="2">
1.44 sakharuk 101: Number of columns: <select name="numberofcolumns">
102: <option selected> 1 </option>
103: <option> 2 </option>
104: <option> 3 </option>
105: <option> 4 </option>
106: <option> 5 </option>
107: <option> 6 </option>
108: <option> 7 </option>
109: <option> 8 </option>
110: <option> 9 </option>
111: </select>
1.36 sakharuk 112: </td>
113: </tr>
114: </table>
115: </br>
1.16 sakharuk 116: <input type="submit" value="Submit your choice">
1.3 sakharuk 117: </form>
118: </body>
119: </html>
1.39 sakharuk 120: ENDMENUOUT5
1.3 sakharuk 121: }
1.2 sakharuk 122:
123:
1.16 sakharuk 124:
125:
1.3 sakharuk 126: sub output_data {
127: my $r = shift;
128: $r->print(<<ENDPART);
129: <html>
130: <head>
131: <title>LON-CAPA output for printing</title>
132: </head>
133: <body bgcolor="FFFFFF">
134: <hr>
135: ENDPART
1.2 sakharuk 136:
1.3 sakharuk 137: my $choice = $ENV{'form.choice'};
1.16 sakharuk 138: my $layout = $ENV{'form.layout'};
1.36 sakharuk 139: my $numberofcolumns = $ENV{'form.numberofcolumns'};
1.16 sakharuk 140: my $laystyle = 'book';
1.2 sakharuk 141: my $result = '';
1.34 sakharuk 142: my $number_of_columns = 1;
1.36 sakharuk 143:
1.3 sakharuk 144: if ($choice eq 'Standard LaTeX output for current document') {
1.36 sakharuk 145: #-- single document - problem, page, html, xml
1.14 albertel 146: my %moreenv;
147: $moreenv{'form.grade_target'}='tex';
1.48 sakharuk 148: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
149: $ENV{'form.url'}=~s/http:\/\/[^\/]+//;
150: }
1.14 albertel 151: $moreenv{'request.filename'}=$ENV{'form.url'};
152: &Apache::lonnet::appenv(%moreenv);
153: my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
154: &Apache::lonnet::delenv('form.grade_target');
155: $result .= $texversion;
1.29 sakharuk 156: $result = &additional_cleanup($result);
1.40 sakharuk 157: if ($ENV{'form.url'}=~m/\.page\s*$/) {
158: ($result,$number_of_columns) = &page_cleanup($result);
159: }
160: } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or
161: $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36 sakharuk 162: #-- minimal sequence to which the current document belongs
163: #-- where is the primary sequence containing file?
1.18 sakharuk 164: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
165: $_ = $symbolic;
166: m/([^_]+)_/;
167: my $primary_sequence = '/res/'.$1;
1.36 sakharuk 168: #-- open and analyses the primary sequence
1.18 sakharuk 169: my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
170: my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
171: my @master_seq = &content_map($sequencefilecontents);
1.36 sakharuk 172: #-- produce an output string
1.18 sakharuk 173: for (my $i=0;$i<=$#master_seq;$i++) {
174: $_ = $master_seq[$i];
175: m/\"(.*)\"/;
176: $_ = $1;
1.36 sakharuk 177: my $urlp = $1;
1.20 sakharuk 178: if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.36 sakharuk 179: if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.20 sakharuk 180: my %moreenv;
181: $moreenv{'form.grade_target'}='tex';
182: &Apache::lonnet::appenv(%moreenv);
183: my $texversion=&Apache::lonnet::ssi($urlp);
184: &Apache::lonnet::delenv('form.grade_target');
185: $result .= $texversion;
186: }
1.51.2.1! albertel 187: } elsif ($urlp =~ /\S+/) {
1.36 sakharuk 188: my %moreenv;
1.18 sakharuk 189: $moreenv{'form.grade_target'}='tex';
190: &Apache::lonnet::appenv(%moreenv);
191: my $texversion=&Apache::lonnet::ssi($urlp);
192: &Apache::lonnet::delenv('form.grade_target');
1.20 sakharuk 193: $result .= $texversion;
1.16 sakharuk 194: }
1.28 sakharuk 195: }
196: $result = &additional_cleanup($result);
1.13 sakharuk 197: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
1.47 sakharuk 198: # where is the main sequence of the course?
1.13 sakharuk 199: my $main_seq = '/res/'.$ENV{'request.course.uri'};
200: my $file=&Apache::lonnet::filelocation("",$main_seq);
201: my $filecontents=&Apache::lonnet::getfile($file);
202: my @file_seq = &content_map($filecontents);
1.48 sakharuk 203: for (my $iu=0;$iu<=$#file_seq;$iu++) {
204: $file_seq[$iu]=~s/^"//;
205: $file_seq[$iu]=~s/"$//;
1.49 sakharuk 206: if ($file_seq[$iu]=~m/\S+/) {
207: $file_seq[$iu]=&Apache::lonnet::filelocation("",$file_seq[$iu]);
208: } else {
209: $file_seq[$iu]= 'REMOVE IT PLEASE';
210: }
1.48 sakharuk 211: }
212: my $i=0;
1.49 sakharuk 213: my $limit = $#file_seq;
214: while ($i<=$limit) {
1.48 sakharuk 215: unless ($file_seq[$i]=~m/\.(problem|page)/) {
216: if ($file_seq[$i]=~m/\.sequence/) {
217: my $filecontents=&Apache::lonnet::getfile($file_seq[$i]);
218: my @newfile_seq = &content_map($filecontents);
1.49 sakharuk 219: for (my $iu=0;$iu<=$#newfile_seq;$iu++) {
220: $newfile_seq[$iu]=~s/^"//;
221: $newfile_seq[$iu]=~s/"$//;
222: if ($newfile_seq[$iu]=~m/\S+/) {
223: $newfile_seq[$iu]=&Apache::lonnet::filelocation("",$newfile_seq[$iu]);
224: } else {
225: $newfile_seq[$iu]= 'REMOVE IT PLEASE';
226: }
227: }
228: splice @file_seq,$i,1,@newfile_seq;
229: $i=0;
230: $limit = $#file_seq;
1.48 sakharuk 231: } else {
1.49 sakharuk 232: splice @file_seq,$i,1,'REMOVE IT PLEASE';
1.48 sakharuk 233: }
234: }
235: $i++;
236: }
237: for (my $iu=0;$iu<=$#file_seq;$iu++) {
1.49 sakharuk 238: if ($file_seq[$iu]=~m/REMOVE IT PLEASE/) {
239: splice @file_seq,$iu,1;
240: }
241: }
242: if ($file_seq[-1]=~m/REMOVE IT PLEASE/) {
243: pop @file_seq;
1.48 sakharuk 244: }
1.13 sakharuk 245: #-- produce an output string
1.49 sakharuk 246: for (my $i=0;$i<=$#file_seq;$i++) {
247: my $urlp = $file_seq[$i];
248: $urlp=~s/\/home\/httpd\/html//;
249: if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {
250: my %moreenv;
251: $moreenv{'form.grade_target'}='tex';
252: &Apache::lonnet::appenv(%moreenv);
253: my $texversion=&Apache::lonnet::ssi($urlp);
254: &Apache::lonnet::delenv('form.grade_target');
255: $result .= $texversion;
256: }
257: }
258: $result = &additional_cleanup($result);
1.31 sakharuk 259: } elsif ($choice eq 'Subdirectory print') {
260: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
261: $subdirtoprint =~ s/\/[^\/]+$//;
262: my @list_of_files = ();
1.48 sakharuk 263: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
1.45 sakharuk 264: $subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//;
265: } else {
266: $subdirtoprint =~ s/.*(\/res\/)/$1/;
267: }
1.46 sakharuk 268: my @content_directory = ();
1.48 sakharuk 269: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
1.46 sakharuk 270: @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');
1.45 sakharuk 271: } else {
1.46 sakharuk 272: @content_directory = &Apache::lonnet::dirlist($subdirtoprint);
273: }
274: for (my $iy=0;$iy<=$#content_directory;$iy++) {
275: my @tempo_array = split(/&/,$content_directory[$iy]);
276: if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
277: push(@list_of_files,$tempo_array[0]);
1.28 sakharuk 278: }
1.13 sakharuk 279: }
1.45 sakharuk 280: $subdirtoprint =~ s/\/$//;
1.31 sakharuk 281: for (my $i=0;$i<=$#list_of_files;$i++) {
1.45 sakharuk 282: my $urlp = $subdirtoprint.'/'.$list_of_files[$i];
1.31 sakharuk 283: my %moreenv;
284: $moreenv{'form.grade_target'}='tex';
285: &Apache::lonnet::appenv(%moreenv);
1.48 sakharuk 286: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
287: $urlp =~ s/\/home\/([^\/]*)\/public_html/\/~$1/;
288: }
1.31 sakharuk 289: my $texversion=&Apache::lonnet::ssi($urlp);
290: &Apache::lonnet::delenv('form.grade_target');
291: $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
292: $result .= $texversion;
293: }
294: $result = &additional_cleanup($result);
295:
1.51 sakharuk 296:
1.7 sakharuk 297: }
1.16 sakharuk 298: #-- corrections for the different page formats
1.36 sakharuk 299: if ($layout eq 'CBI' and $numberofcolumns eq '1') {
300: } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {
1.16 sakharuk 301: $result =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{-40pt}\\setlength{\\evensidemargin}{-60pt}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{4\.4in}\\setlength{\\textheight}{6\.8in}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt} \\begin{document}/;
302: $laystyle = 'album';
303: } elsif ($layout eq 'CAPA') {
304: my $courseidinfo = $ENV{'request.role'};
305: $_ = $courseidinfo;
306: m/.*\/(.*)/;
307: $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
1.34 sakharuk 308: # $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
309: $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;
310: $result =~ s/\\begin{document}/\\textheight 25\.9cm\\oddsidemargin = -0\.57in\\evensidemargin = -0\.57in\\textwidth= 9cm\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\begin{document}\\voffset=-1\.8cm\\setcounter{page}{1}\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$ENV{'environment.firstname'} $ENV{'environment.lastname'}}}\\hskip 1\.4in $courseidinfo} \\vskip 5 mm /;
1.27 sakharuk 311: $result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;
1.37 sakharuk 312: # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;
313: # $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[9.0cm\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Dept\. of Physics and Astronomy, MSU\\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright MSU GNU\/GPL $1/;
1.50 albertel 314: $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny \\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright Michigan State University Board of Trustees $1/;
1.37 sakharuk 315: # $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;
316: $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1.34 sakharuk 317: $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;
1.37 sakharuk 318: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.16 sakharuk 319: }
1.23 sakharuk 320: #-- LaTeX corrections
321: my $first_comment = index($result,'<!--',0);
322: while ($first_comment != -1) {
323: my $end_comment = index($result,'-->',$first_comment);
324: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
325: $first_comment = index($result,'<!--',$first_comment);
326: }
1.17 sakharuk 327: $result =~ s/^\s+$//gm; #remove empty lines
1.47 sakharuk 328: $result =~ s/\s%/\\%/g; #corrects %
1.20 sakharuk 329: $result =~ s/(\s)+/$1/g; #removes more than one empty space
1.23 sakharuk 330: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1.24 sakharuk 331: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1.23 sakharuk 332: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.24 sakharuk 333: $result =~ s/\\\\\s+\[/ \[/g;
334: $result =~ s/θ/\$\\theta\$/g; #converts theta from html into tex
1.41 sakharuk 335: $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1.37 sakharuk 336: #conversion of html characters to LaTeX equivalents
337: if ($result =~ m/&(\w+|#\d+);/) {
338: $result = &character_chart($result);
339: }
1.42 sakharuk 340: $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
341: $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
1.7 sakharuk 342: #-- writing .tex file in prtspool
1.16 sakharuk 343: my $temp_file;
1.33 sakharuk 344: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16 sakharuk 345: unless ($temp_file = Apache::File->new('>'.$filename)) {
346: $r->log_error("Couldn't open $filename for output $!");
347: return SERVER_ERROR;
348: }
349: print $temp_file $result;
1.3 sakharuk 350: $r->print(<<FINALEND);
1.51 sakharuk 351: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns">
1.3 sakharuk 352: </body>
353: </html>
354: FINALEND
355: }
1.2 sakharuk 356:
1.37 sakharuk 357: sub character_chart {
358: my $result = shift;
1.41 sakharuk 359: $result =~ s/�?0?7;//g;
1.40 sakharuk 360: $result =~ s/�?0?9;//g;
361: $result =~ s/�?10;//g;
362: $result =~ s/�?13;//g;
363: $result =~ s/�?32;/ /g;
364: $result =~ s/�?33;/!/g;
365: $result =~ s/�?34;/"/g;
1.39 sakharuk 366: $result =~ s/"/"/g;
1.40 sakharuk 367: $result =~ s/�?35;/\\#/g;
368: # $result =~ s/�?36;/\\\$/g;
369: $result =~ s/�?37;/\\%/g;
370: $result =~ s/�?38;/\\&/g;
1.37 sakharuk 371: $result =~ s/&/\\&/g;
1.40 sakharuk 372: $result =~ s/�?39;/'/g;
373: $result =~ s/�?40;/(/g;
374: $result =~ s/�?41;/)/g;
375: $result =~ s/�?42;/\*/g;
376: $result =~ s/�?43;/\+/g;
377: $result =~ s/�?44;/,/g;
378: $result =~ s/�?45;/-/g;
379: $result =~ s/�?46;/\./g;
380: $result =~ s/�?47;/\//g;
381: $result =~ s/�?48;/0/g;
382: $result =~ s/�?49;/1/g;
383: $result =~ s/�?50;/2/g;
384: $result =~ s/�?51;/3/g;
385: $result =~ s/�?52;/4/g;
386: $result =~ s/�?53;/5/g;
387: $result =~ s/�?54;/6/g;
388: $result =~ s/�?55;/7/g;
389: $result =~ s/�?56;/8/g;
390: $result =~ s/�?57;/9/g;
391: $result =~ s/�?58;/:/g;
392: $result =~ s/�?59;/;/g;
393: $result =~ s/�?60;/\$<\$/g;
1.37 sakharuk 394: $result =~ s/</\$<\$/g;
1.40 sakharuk 395: $result =~ s/�?61;/\$=\$/g;
396: $result =~ s/�?62;/\$>\$/g;
1.37 sakharuk 397: $result =~ s/>/\$>\$/g;
1.40 sakharuk 398: $result =~ s/�?63;/?/g;
399: # $result =~ s/�?64;//g;
400: $result =~ s/�?65;/A/g;
401: $result =~ s/�?66;/B/g;
402: $result =~ s/�?67;/C/g;
403: $result =~ s/�?68;/D/g;
404: $result =~ s/�?69;/E/g;
405: $result =~ s/�?70;/F/g;
406: $result =~ s/�?71;/G/g;
407: $result =~ s/�?72;/H/g;
408: $result =~ s/�?73;/I/g;
409: $result =~ s/�?74;/J/g;
410: $result =~ s/�?75;/K/g;
411: $result =~ s/�?76;/L/g;
412: $result =~ s/�?77;/M/g;
413: $result =~ s/�?78;/N/g;
414: $result =~ s/�?79;/O/g;
415: $result =~ s/�?80;/P/g;
416: $result =~ s/�?81;/Q/g;
417: $result =~ s/�?82;/R/g;
418: $result =~ s/�?83;/S/g;
419: $result =~ s/�?84;/T/g;
420: $result =~ s/�?85;/U/g;
421: $result =~ s/�?86;/V/g;
422: $result =~ s/�?87;/W/g;
423: $result =~ s/�?88;/X/g;
424: $result =~ s/�?89;/Y/g;
425: $result =~ s/�?90;/Z/g;
426: $result =~ s/�?91;/[/g;
427: $result =~ s/�?92;/\\/g;
428: $result =~ s/�?93;/]/g;
429: # $result =~ s/�?94;//g;
430: # $result =~ s/�?95;//g;
431: $result =~ s/�?96;/`/g;
432: $result =~ s/�?97;/a/g;
433: $result =~ s/�?98;/b/g;
434: $result =~ s/�?99;/c/g;
1.37 sakharuk 435: $result =~ s/d/d/g;
436: $result =~ s/e/e/g;
437: $result =~ s/f/f/g;
438: $result =~ s/g/g/g;
439: $result =~ s/h/h/g;
440: $result =~ s/i/i/g;
441: $result =~ s/j/j/g;
442: $result =~ s/k/k/g;
443: $result =~ s/l/l/g;
444: $result =~ s/m/m/g;
445: $result =~ s/n/n/g;
446: $result =~ s/o/o/g;
447: $result =~ s/p/p/g;
448: $result =~ s/q/q/g;
449: $result =~ s/r/r/g;
450: $result =~ s/s/s/g;
451: $result =~ s/t/t/g;
452: $result =~ s/u/u/g;
453: $result =~ s/v/v/g;
454: $result =~ s/w/w/g;
455: $result =~ s/x/x/g;
456: $result =~ s/y/y/g;
457: $result =~ s/z/z/g;
458: $result =~ s/{/\\{/g;
459: $result =~ s/|/\|/g;
460: $result =~ s/}/\\}/g;
461: $result =~ s/~/\~/g;
462: $result =~ s/‚/,/g;
463: # $result =~ s/ƒ//g;
464: $result =~ s/„/''/g;
465: $result =~ s/…/\$\\ldots\$/g;
466: $result =~ s/†/\$\\dagger\$/g;
467: $result =~ s/‡/\$\\ddagger\$/g;
468: # $result =~ s/ˆ//g;
469: # $result =~ s/‰//g;
470: # $result =~ s/Š//g;
471: $result =~ s/‹/\$<\$/g;
472: # $result =~ s/Œ//g;
473: $result =~ s/‘/`/g;
474: $result =~ s/’/'/g;
475: $result =~ s/“/``/g;
476: $result =~ s/”/''/g;
477: $result =~ s/•/\$\\bullet\$/g;
478: # $result =~ s/–//g;
479: # $result =~ s/—//g;
480: $result =~ s/˜/~/g;
481: # $result =~ s/™//g;
482: # $result =~ s/š//g;
483: $result =~ s/›/\$>\$/g;
484: $result =~ s/œ/\\{\\oe\\}/g;
485: $result =~ s/Ÿ/\\"\\{Y\\}/g;
486: $result =~ s/ //g;
487: $result =~ s/ //g;
488: $result =~ s/¡/!`/g;
489: $result =~ s/¡/!`/g; #`
490: # $result =~ s/¢//g;
491: # $result =~ s/¢//g;
492: $result =~ s/£/\\pounds/g;
493: $result =~ s/£/\\pounds/g;
494: # $result =~ s/¤//g;
495: # $result =~ s/¤//g;
496: # $result =~ s/¥//g;
497: # $result =~ s/¥//g;
498: # $result =~ s/¦//g;
499: # $result =~ s/¦//g;
500: # $result =~ s/§//g;
501: # $result =~ s/§//g;
502: # $result =~ s/¨//g;
503: # $result =~ s/¨//g;
504: $result =~ s/©/\\copyright/g;
505: $result =~ s/©/\\copyright/g;
506: # $result =~ s/ª//g;
507: # $result =~ s/ª//g;
508: # $result =~ s/«//g;
509: # $result =~ s/«//g;
510: $result =~ s/¬/\$\\neg\$/g;
511: $result =~ s/¬/\$\\neg\$/g;
512: # $result =~ s/­//g;
513: # $result =~ s/­//g;
514: # $result =~ s/®//g;
515: # $result =~ s/®//g;
516: # $result =~ s/¯//g;
517: # $result =~ s/¯//g;
1.42 sakharuk 518: $result =~ s/°/\$^{\\circ}\$/g;
519: $result =~ s/°/\$^{\\circ}\$/g;
1.37 sakharuk 520: $result =~ s/±/\$\\pm\$/g;
521: $result =~ s/±/\$\\pm\$/g;
522: $result =~ s/²/\$^2\$/g;
523: $result =~ s/²/\$^2\$/g;
524: $result =~ s/³/\$^3\$/g;
525: $result =~ s/³/\$^3\$/g;
526: # $result =~ s/´//g;
527: # $result =~ s/´//g;
528: $result =~ s/µ/\$\\mu\$/g;
529: $result =~ s/µ/\$\\mu\$/g;
530: $result =~ s/¶/\\P/g;
531: $result =~ s/¶/\\P/g;
532: $result =~ s/·/\$\\cdot\$/g;
533: $result =~ s/·/\$\\cdot\$/g;
534: # $result =~ s/¸//g;
535: # $result =~ s/¸//g;
536: $result =~ s/¹/\$^1\$/g;
537: $result =~ s/¹/\$^1\$/g;
538: # $result =~ s/º//g;
539: # $result =~ s/º//g;
540: # $result =~ s/»//g;
541: # $result =~ s/»//g;
542: # $result =~ s/¼//g;
543: # $result =~ s/¼//g;
544: # $result =~ s/½//g;
545: # $result =~ s/½//g;
546: # $result =~ s/¾//g;
547: # $result =~ s/¾//g;
548: $result =~ s/¿/?`/g;
549: $result =~ s/¿/?`/g;
550: $result =~ s/À/\\`{A}/g;
551: $result =~ s/À/\\`{A}/g;
552: $result =~ s/Á/\\'{A}/g;
553: $result =~ s/Á/\\'{A}/g;
554: $result =~ s/Â/\\^{A}/g;
555: $result =~ s/Â/\\^{A}/g;
556: $result =~ s/Ã/\\~{A}/g;
557: $result =~ s/Ã/\\~{A}/g;
558: $result =~ s/Ä/\\"{A}/g;
559: $result =~ s/Ä/\\"{A}/g;
560: $result =~ s/Å/{\\AA}/g;
561: $result =~ s/Å/{\\AA}/g;
562: $result =~ s/Æ/{\\AE}/g;
563: $result =~ s/Æ/{\\AE}/g;
564: # $result =~ s/Ç//g;
565: # $result =~ s/Ç//g;
566: $result =~ s/È/\\`{E}/g;
567: $result =~ s/È/\\`{E}/g;
568: $result =~ s/É/\\'{E}/g;
569: $result =~ s/É/\\'{E}/g;
570: $result =~ s/Ê/\\^{E}/g;
571: $result =~ s/Ê/\\^{E}/g;
572: $result =~ s/Ë/\\`{E}/g;
573: $result =~ s/Ë/\\`{E}/g;
574: $result =~ s/Ì/\\`{I}/g;
575: $result =~ s/Ì/\\`{I}/g;
576: $result =~ s/Í/\\'{I}/g;
577: $result =~ s/Í/\\'{I}/g;
578: $result =~ s/Î/\\^{I}/g;
579: $result =~ s/Î/\\^{I}/g;
580: $result =~ s/Ï/\\"{I}/g;
581: $result =~ s/Ï/\\"{I}/g;
582: # $result =~ s/Ð//g;
583: # $result =~ s/Ð//g;
584: $result =~ s/Ñ/\\~{N}/g;
585: $result =~ s/Ñ/\\~{N}/g;
586: $result =~ s/Ò/\\`{O}/g;
587: $result =~ s/Ò/\\`{O}/g;
588: $result =~ s/Ó/\\'{O}/g;
589: $result =~ s/Ó/\\'{O}/g;
590: $result =~ s/Ô/\\^{O}/g;
591: $result =~ s/Ô/\\^{O}/g;
592: $result =~ s/Õ/\\~{O}/g;
593: $result =~ s/Õ/\\~{O}/g;
594: $result =~ s/Ö/\\"{O}/g;
595: $result =~ s/Ö/\\"{O}/g;
596: $result =~ s/×/\$\\times\$/g;
597: $result =~ s/×/\$\\times\$/g;
598: $result =~ s/Ø/{\\O}/g;
599: $result =~ s/Ø/{\\O}/g;
600: $result =~ s/Ù/\\`{U}/g;
601: $result =~ s/Ù/\\`{U}/g;
602: $result =~ s/Ú/\\'{U}/g;
603: $result =~ s/Ú/\\'{U}/g;
604: $result =~ s/Û/\\^{U}/g;
605: $result =~ s/Û/\\^{U}/g;
606: $result =~ s/Ü/\\"{U}/g;
607: $result =~ s/Ü/\\"{U}/g;
608: $result =~ s/Ý/\\'{Y}/g;
609: $result =~ s/Ý/\\'{Y}/g;
610: # $result =~ s/Þ//g;
611: # $result =~ s/Þ//g;
612: # $result =~ s/ß//g;
613: # $result =~ s/ß//g;
614: $result =~ s/à/\\`{a}/g;
615: $result =~ s/à/\\`{a}/g;
616: $result =~ s/á/\\'{a}/g;
617: $result =~ s/á/\\'{a}/g;
618: $result =~ s/â/\\^{a}/g;
619: $result =~ s/â/\\^{a}/g;
620: $result =~ s/ã/\\~{a}/g;
621: $result =~ s/ã/\\~{a}/g;
622: $result =~ s/ä/\\"{a}/g;
623: $result =~ s/ä/\\"{a}/g;
624: $result =~ s/å/{\\aa}/g;
625: $result =~ s/å/{\\aa}/g;
626: $result =~ s/æ/{\\ae}/g;
627: $result =~ s/æ/{\\ae}/g;
628: # $result =~ s/ç//g;
629: # $result =~ s/ç//g;
630: $result =~ s/è/\\`{e}/g;
631: $result =~ s/è/\\`{e}/g;
632: $result =~ s/é/\\'{e}/g;
633: $result =~ s/é/\\'{e}/g;
634: $result =~ s/ê/\\^{e}/g;
635: $result =~ s/ê/\\^{e}/g;
636: $result =~ s/ë/\\"{e}/g;
637: $result =~ s/ë/\\"{e}/g;
638: $result =~ s/ì/\\`{i}/g;
639: $result =~ s/ì/\\`{i}/g;
640: $result =~ s/í/\\'{i}/g;
641: $result =~ s/í/\\'{i}/g;
642: $result =~ s/î/\\^{i}/g;
643: $result =~ s/î/\\^{i}/g;
644: $result =~ s/ï/\\"{i}/g;
645: $result =~ s/ï/\\"{i}/g;
646: # $result =~ s/ð//g;
647: # $result =~ s/ð//g;
648: $result =~ s/ñ/\\~{n}/g;
649: $result =~ s/ñ/\\~{n}/g;
650: $result =~ s/ò/\\`{o}/g;
651: $result =~ s/ò/\\`{o}/g;
652: $result =~ s/ó/\\'{o}/g;
653: $result =~ s/ó/\\'{o}/g;
654: $result =~ s/ô/\\^{o}/g;
655: $result =~ s/ô/\\^{o}/g;
656: $result =~ s/õ/\\~{o}/g;
657: $result =~ s/õ/\\~{o}/g;
658: $result =~ s/ö/\\"{o}/g;
659: $result =~ s/ö/\\"{o}/g;
660: $result =~ s/÷/\$\\div\$/g;
661: $result =~ s/÷/\$\\div\$/g;
662: $result =~ s/ø/{\\o}/g;
663: $result =~ s/ø/{\\o}/g;
664: $result =~ s/ù/\\`{u}/g;
665: $result =~ s/ù/\\`{u}/g;
666: $result =~ s/ú/\\'{u}/g;
667: $result =~ s/ú/\\'{u}/g;
668: $result =~ s/û/\\^{u}/g;
669: $result =~ s/û/\\^{u}/g;
670: $result =~ s/ü/\\"{u}/g;
671: $result =~ s/ü/\\"{u}/g;
672: $result =~ s/ý/\\'{y}/g;
673: $result =~ s/ý/\\'{y}/g;
674: # $result =~ s/þ//g;
675: # $result =~ s/þ//g;
676: $result =~ s/ÿ/\\"{y}/g;
677: $result =~ s/ÿ/\\"{y}/g;
678: return $result;
679: }
1.41 sakharuk 680:
681:
682: #'"`
1.37 sakharuk 683:
1.28 sakharuk 684: sub additional_cleanup {
685: my $result = shift;
686: my $first_app = index($result,'\documentclass',0);
687: $first_app = index($result,'\documentclass',$first_app+5);
688: while ($first_app != -1) {
689: my $second_app = index($result,'begin{document}',$first_app);
690: $first_app = rindex($result,'\end{document}',$first_app);
691: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';
692: $first_app = index($result,'\documentclass',$first_app+5);
693: }
694: return $result;
695: }
1.33 sakharuk 696: sub page_cleanup {
697: my $result = shift;
698: $_ = $result;
699: m/\\end{document}(\d*)$/;
1.34 sakharuk 700: my $number_of_columns = $1;
1.33 sakharuk 701: my $insert = '{';
1.34 sakharuk 702: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 703: $insert .= '}';
1.34 sakharuk 704: $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;
705: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
706: $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;
1.35 sakharuk 707: $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;
1.37 sakharuk 708: $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;
1.34 sakharuk 709: return $result,$number_of_columns;
1.33 sakharuk 710: }
1.6 sakharuk 711:
1.3 sakharuk 712: sub content_map {
1.7 sakharuk 713: #-- find a list of files to print
1.3 sakharuk 714: my $map_string = shift;
1.5 sakharuk 715: my @number_seq = ();
1.7 sakharuk 716: my @file_seq = ();
1.5 sakharuk 717: my $startlink = index($map_string,'<link',0);
1.7 sakharuk 718: my $endlink = index($map_string,'</link>',$startlink);
719: my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
720: $_ = $chunk;
721: m/from=\"(\d+)\"/;
722: push @number_seq,$1;
1.5 sakharuk 723: while ($startlink != -1) {
1.7 sakharuk 724: $endlink = index($map_string,'</link>',$startlink);
725: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5 sakharuk 726: substr($map_string,$startlink,$endlink-$startlink+7) = '';
727: $_ = $chunk;
728: m/to=\"(\d+)\"/;
729: push @number_seq,$1;
1.44 sakharuk 730: $startlink = index($map_string,'from="'.$1.'"',0);
1.18 sakharuk 731: $startlink = rindex($map_string,'<link ',$startlink);
1.5 sakharuk 732: }
1.45 sakharuk 733: my $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
1.7 sakharuk 734: while ($stalink != -1) {
735: $startlink = rindex($map_string,'<link ',$stalink);
736: $endlink = index($map_string,'</link>',$startlink);
737: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
738: substr($map_string,$startlink,$endlink-$startlink+7) = '';
739: $_ = $chunk;
740: m/from=\"(\d+)\"/;
741: unshift @number_seq,$1;
742: $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
743: }
744: for (my $i=0;$i<=$#number_seq;$i++) {
745: $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13 sakharuk 746: {
747: my $ahed1 = index($map_string,'src="',$stalink);
748: my $ahed2 = index($map_string,'</resource>',$stalink);
749: if ($ahed1 != -1) {
750: if ($ahed1 < $ahed2) {
751: $startlink = $ahed1;
752: } else {
753: $startlink = rindex($map_string,'src="',$stalink);
754: }
755: } else {
756: $startlink = rindex($map_string,'src="',$stalink);
757: }
758:
759: }
1.7 sakharuk 760: $startlink = index($map_string,'"',$startlink);
761: $endlink = index($map_string,'"',$startlink+1);
762: $chunk = substr($map_string,$startlink,$endlink-$startlink+1);
763: push @file_seq,$chunk;
764: }
765: return @file_seq;
766: }
1.5 sakharuk 767:
1.3 sakharuk 768:
769:
770: sub handler {
771:
772: my $r = shift;
773: $r->content_type('text/html');
774: $r->send_http_header;
775:
776: #-- start form
777: &headerform($r);
778: #-- menu for output
1.16 sakharuk 779: unless ($ENV{'form.phase'}) {
1.3 sakharuk 780: &menu_for_output($r);
781: }
782: #-- core part
783: if ($ENV{'form.phase'} eq 'two') {
784: &output_data($r);
785: }
1.2 sakharuk 786: return OK;
787:
1.1 www 788: }
789:
790: 1;
791: __END__
1.6 sakharuk 792:
793:
1.13 sakharuk 794:
795:
796: #### Test block
1.6 sakharuk 797: # my $ere;
798: # foreach $ere (%ENV) {
1.13 sakharuk 799: # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6 sakharuk 800: # }
1.13 sakharuk 801: ####
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>