Annotation of loncom/interface/lonprintout.pm, revision 1.39
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.39 ! sakharuk 4: # $Id: lonprintout.pm,v 1.38 2002/07/16 20:30:53 www 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
! 75: if (!$ENV{'request.role'}=~m/^au\./) {
! 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.39 ! sakharuk 82: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
! 83: $subdirtoprint =~ s/\/[^\/]+$//;
! 84: if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') {
! 85: $r->print(<<ENDMENUOUT4);
! 86: <input type="radio" name="choice" value="Subdirectory print"> All problems from current subdirectory (where this particular problem is)<br />
! 87: ENDMENUOUT4
! 88: }
! 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">
101: Number of columns: <input type="text" size="2" name="numberofcolumns" value="2">
102: </td>
103: </tr>
104: </table>
105: </br>
1.16 sakharuk 106: <input type="submit" value="Submit your choice">
1.3 sakharuk 107: </form>
108: </body>
109: </html>
1.39 ! sakharuk 110: ENDMENUOUT5
1.3 sakharuk 111: }
1.2 sakharuk 112:
113:
1.16 sakharuk 114:
115:
1.3 sakharuk 116: sub output_data {
117: my $r = shift;
118: $r->print(<<ENDPART);
119: <html>
120: <head>
121: <title>LON-CAPA output for printing</title>
122: </head>
123: <body bgcolor="FFFFFF">
124: <hr>
125: ENDPART
1.2 sakharuk 126:
1.3 sakharuk 127: my $choice = $ENV{'form.choice'};
1.16 sakharuk 128: my $layout = $ENV{'form.layout'};
1.36 sakharuk 129: my $numberofcolumns = $ENV{'form.numberofcolumns'};
1.16 sakharuk 130: my $laystyle = 'book';
1.2 sakharuk 131: my $result = '';
1.34 sakharuk 132: my $number_of_columns = 1;
1.36 sakharuk 133:
1.3 sakharuk 134: if ($choice eq 'Standard LaTeX output for current document') {
1.36 sakharuk 135: #-- single document - problem, page, html, xml
1.14 albertel 136: my %moreenv;
137: $moreenv{'form.grade_target'}='tex';
1.39 ! sakharuk 138: if ($ENV{'request.role'}=~m/^au\./) {$ENV{'form.url'}=~s/http:\/\/[^\/]+//;}
1.14 albertel 139: $moreenv{'request.filename'}=$ENV{'form.url'};
140: &Apache::lonnet::appenv(%moreenv);
141: my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
142: &Apache::lonnet::delenv('form.grade_target');
143: $result .= $texversion;
1.29 sakharuk 144: $result = &additional_cleanup($result);
1.34 sakharuk 145: if ($ENV{'form.url'}=~m/\.page\s*$/) {($result,$number_of_columns) = &page_cleanup($result);}
1.20 sakharuk 146: } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36 sakharuk 147: #-- minimal sequence to which the current document belongs
148: #-- where is the primary sequence containing file?
1.18 sakharuk 149: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
150: $_ = $symbolic;
151: m/([^_]+)_/;
152: my $primary_sequence = '/res/'.$1;
1.36 sakharuk 153: #-- open and analyses the primary sequence
1.18 sakharuk 154: my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
155: my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
156: my @master_seq = &content_map($sequencefilecontents);
1.36 sakharuk 157: #-- produce an output string
1.18 sakharuk 158: for (my $i=0;$i<=$#master_seq;$i++) {
159: $_ = $master_seq[$i];
160: m/\"(.*)\"/;
161: $_ = $1;
1.36 sakharuk 162: my $urlp = $1;
1.20 sakharuk 163: if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.36 sakharuk 164: if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.20 sakharuk 165: my %moreenv;
166: $moreenv{'form.grade_target'}='tex';
167: &Apache::lonnet::appenv(%moreenv);
168: my $texversion=&Apache::lonnet::ssi($urlp);
169: &Apache::lonnet::delenv('form.grade_target');
170: $result .= $texversion;
171: }
172: } else {
1.36 sakharuk 173: my %moreenv;
1.18 sakharuk 174: $moreenv{'form.grade_target'}='tex';
175: &Apache::lonnet::appenv(%moreenv);
176: my $texversion=&Apache::lonnet::ssi($urlp);
177: &Apache::lonnet::delenv('form.grade_target');
1.20 sakharuk 178: $result .= $texversion;
1.16 sakharuk 179: }
1.28 sakharuk 180: }
181: $result = &additional_cleanup($result);
1.13 sakharuk 182: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
183: my @master_seq = ();
1.19 sakharuk 184: my @add_file_seq = ();
1.16 sakharuk 185: #-- where is the main sequence of the course?
1.13 sakharuk 186: my $main_seq = '/res/'.$ENV{'request.course.uri'};
187: my $file=&Apache::lonnet::filelocation("",$main_seq);
188: my $filecontents=&Apache::lonnet::getfile($file);
189: my @file_seq = &content_map($filecontents);
1.19 sakharuk 190: #-- do we have any other sequence inside?
191: my $i=0;
192: while ($i<=$#file_seq) {
193: $_ = $file_seq[$i];
194: if (/\.sequence$/) {
195: $file = &Apache::lonnet::filelocation("",$file_seq[$i]);
196: $filecontents=&Apache::lonnet::getfile($file);
197: @add_file_seq = &content_map($filecontents);
198: splice(@file_seq,$i,1,@add_file_seq);
199: @add_file_seq = ();
200: $i = -1;
201: }
202: $i++;
203: }
204: @master_seq = @file_seq;
1.13 sakharuk 205: #-- produce an output string
206: for (my $i=0;$i<=$#master_seq;$i++) {
207: $_ = $master_seq[$i];
208: m/\"(.*)\"/;
209: $_ = $1;
210: my $urlp = $1;
1.21 sakharuk 211: if (/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.13 sakharuk 212: my %moreenv;
213: $moreenv{'form.grade_target'}='tex';
214: &Apache::lonnet::appenv(%moreenv);
215: my $texversion=&Apache::lonnet::ssi($urlp);
216: &Apache::lonnet::delenv('form.grade_target');
217: $result .= $texversion;
218: }
1.28 sakharuk 219: }
220: $result = &additional_cleanup($result);
1.31 sakharuk 221: } elsif ($choice eq 'Subdirectory print') {
222: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
223: $subdirtoprint =~ s/\/[^\/]+$//;
224: my @list_of_files = ();
225: my $localdirectory = $subdirtoprint;
226: $localdirectory =~ s/.*(\/res\/)/$1/;
227: my @content_directory = &Apache::lonnet::dirlist($localdirectory);
228: for (my $iy=0;$iy<=$#content_directory;$iy++) {
229: my @tempo_array = split(/&/,$content_directory[$iy]);
230: $content_directory[$iy] = $tempo_array[0];
231: if ($content_directory[$iy] =~ m/^[^\.]+\.problem$/) {
232: push @list_of_files,$content_directory[$iy];
1.28 sakharuk 233: }
1.13 sakharuk 234: }
1.31 sakharuk 235: $localdirectory =~ s/\/$//;
236: for (my $i=0;$i<=$#list_of_files;$i++) {
237: my $urlp = $localdirectory.'/'.$list_of_files[$i];
238: my %moreenv;
239: $moreenv{'form.grade_target'}='tex';
240: &Apache::lonnet::appenv(%moreenv);
241: my $texversion=&Apache::lonnet::ssi($urlp);
242: &Apache::lonnet::delenv('form.grade_target');
243: $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
244: $result .= $texversion;
245: }
246: $result = &additional_cleanup($result);
247:
248:
1.28 sakharuk 249:
250:
251:
1.31 sakharuk 252:
1.7 sakharuk 253: }
1.16 sakharuk 254: #-- corrections for the different page formats
1.36 sakharuk 255: if ($layout eq 'CBI' and $numberofcolumns eq '1') {
256: } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {
1.16 sakharuk 257: $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}/;
258: $laystyle = 'album';
259: } elsif ($layout eq 'CAPA') {
260: my $courseidinfo = $ENV{'request.role'};
261: $_ = $courseidinfo;
262: m/.*\/(.*)/;
263: $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
1.34 sakharuk 264: # $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
265: $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;
266: $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 267: $result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;
1.37 sakharuk 268: # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;
269: # $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/;
270: $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Dept\. of Physics and Astronomy, MSU\\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright MSU GNU\/GPL $1/;
271: # $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;
272: $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1.34 sakharuk 273: $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;
1.37 sakharuk 274: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.16 sakharuk 275: }
1.23 sakharuk 276: #-- LaTeX corrections
277: my $first_comment = index($result,'<!--',0);
278: while ($first_comment != -1) {
279: my $end_comment = index($result,'-->',$first_comment);
280: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
281: $first_comment = index($result,'<!--',$first_comment);
282: }
1.17 sakharuk 283: $result =~ s/^\s+$//gm; #remove empty lines
284: $result =~ s/%/\\%/g; #corrects %
1.20 sakharuk 285: $result =~ s/(\s)+/$1/g; #removes more than one empty space
1.23 sakharuk 286: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1.22 sakharuk 287: $result =~ s/ (<|>|) / \$$1\$ /g; #corrects < or >
1.24 sakharuk 288: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1.23 sakharuk 289: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.24 sakharuk 290: $result =~ s/\\\\\s+\[/ \[/g;
291: $result =~ s/θ/\$\\theta\$/g; #converts theta from html into tex
1.29 sakharuk 292: $result =~ s/\b_+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1.37 sakharuk 293: #conversion of html characters to LaTeX equivalents
294: if ($result =~ m/&(\w+|#\d+);/) {
295: $result = &character_chart($result);
296: }
1.7 sakharuk 297: #-- writing .tex file in prtspool
1.16 sakharuk 298: my $temp_file;
1.33 sakharuk 299: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16 sakharuk 300: unless ($temp_file = Apache::File->new('>'.$filename)) {
301: $r->log_error("Couldn't open $filename for output $!");
302: return SERVER_ERROR;
303: }
304: print $temp_file $result;
1.3 sakharuk 305: $r->print(<<FINALEND);
1.26 sakharuk 306: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle">
1.3 sakharuk 307: </body>
308: </html>
309: FINALEND
310: }
1.2 sakharuk 311:
1.37 sakharuk 312: sub character_chart {
313: my $result = shift;
314: $result =~ s/	//g;
315: $result =~ s/
//g;
316: $result =~ s/
//g;
317: $result =~ s/ / /g;
318: $result =~ s/!/!/g;
319: $result =~ s/"/"/g;
1.39 ! sakharuk 320: $result =~ s/"/"/g;
1.37 sakharuk 321: $result =~ s/#/\\#/g;
1.39 ! sakharuk 322: # $result =~ s/$/\\\$/g;
1.37 sakharuk 323: $result =~ s/%/\\%/g;
324: $result =~ s/&/\\&/g;
325: $result =~ s/&/\\&/g;
326: $result =~ s/'/'/g;
327: $result =~ s/(/(/g;
328: $result =~ s/)/)/g;
329: $result =~ s/*/\*/g;
330: $result =~ s/+/\+/g;
331: $result =~ s/,/,/g;
332: $result =~ s/-/-/g;
333: $result =~ s/./\./g;
334: $result =~ s///\//g;
335: $result =~ s/0/0/g;
336: $result =~ s/1/1/g;
337: $result =~ s/2/2/g;
338: $result =~ s/3/3/g;
339: $result =~ s/4/4/g;
340: $result =~ s/5/5/g;
341: $result =~ s/6/6/g;
342: $result =~ s/7/7/g;
343: $result =~ s/8/8/g;
344: $result =~ s/9/9/g;
345: $result =~ s/:/:/g;
346: $result =~ s/;/;/g;
347: $result =~ s/</\$<\$/g;
348: $result =~ s/</\$<\$/g;
349: $result =~ s/=/\$=\$/g;
350: $result =~ s/>/\$>\$/g;
351: $result =~ s/>/\$>\$/g;
352: $result =~ s/?/?/g;
353: # $result =~ s/@//g;
354: $result =~ s/A/A/g;
355: $result =~ s/B/B/g;
356: $result =~ s/C/C/g;
357: $result =~ s/D/D/g;
358: $result =~ s/E/E/g;
359: $result =~ s/F/F/g;
360: $result =~ s/G/G/g;
361: $result =~ s/H/H/g;
362: $result =~ s/I/I/g;
363: $result =~ s/J/J/g;
364: $result =~ s/K/K/g;
365: $result =~ s/L/L/g;
366: $result =~ s/M/M/g;
367: $result =~ s/N/N/g;
368: $result =~ s/O/O/g;
369: $result =~ s/P/P/g;
370: $result =~ s/Q/Q/g;
371: $result =~ s/R/R/g;
372: $result =~ s/S/S/g;
373: $result =~ s/T/T/g;
374: $result =~ s/U/U/g;
375: $result =~ s/V/V/g;
376: $result =~ s/W/W/g;
377: $result =~ s/X/X/g;
378: $result =~ s/Y/Y/g;
379: $result =~ s/Z/Z/g;
380: $result =~ s/[/[/g;
381: $result =~ s/\/\\/g;
382: $result =~ s/]/]/g;
383: # $result =~ s/^//g;
384: # $result =~ s/_//g;
385: $result =~ s/`/`/g;
386: $result =~ s/a/a/g;
387: $result =~ s/b/b/g;
388: $result =~ s/c/c/g;
389: $result =~ s/d/d/g;
390: $result =~ s/e/e/g;
391: $result =~ s/f/f/g;
392: $result =~ s/g/g/g;
393: $result =~ s/h/h/g;
394: $result =~ s/i/i/g;
395: $result =~ s/j/j/g;
396: $result =~ s/k/k/g;
397: $result =~ s/l/l/g;
398: $result =~ s/m/m/g;
399: $result =~ s/n/n/g;
400: $result =~ s/o/o/g;
401: $result =~ s/p/p/g;
402: $result =~ s/q/q/g;
403: $result =~ s/r/r/g;
404: $result =~ s/s/s/g;
405: $result =~ s/t/t/g;
406: $result =~ s/u/u/g;
407: $result =~ s/v/v/g;
408: $result =~ s/w/w/g;
409: $result =~ s/x/x/g;
410: $result =~ s/y/y/g;
411: $result =~ s/z/z/g;
412: $result =~ s/{/\\{/g;
413: $result =~ s/|/\|/g;
414: $result =~ s/}/\\}/g;
415: $result =~ s/~/\~/g;
416: $result =~ s/‚/,/g;
417: # $result =~ s/ƒ//g;
418: $result =~ s/„/''/g;
419: $result =~ s/…/\$\\ldots\$/g;
420: $result =~ s/†/\$\\dagger\$/g;
421: $result =~ s/‡/\$\\ddagger\$/g;
422: # $result =~ s/ˆ//g;
423: # $result =~ s/‰//g;
424: # $result =~ s/Š//g;
425: $result =~ s/‹/\$<\$/g;
426: # $result =~ s/Œ//g;
427: $result =~ s/‘/`/g;
428: $result =~ s/’/'/g;
429: $result =~ s/“/``/g;
430: $result =~ s/”/''/g;
431: $result =~ s/•/\$\\bullet\$/g;
432: # $result =~ s/–//g;
433: # $result =~ s/—//g;
434: $result =~ s/˜/~/g;
435: # $result =~ s/™//g;
436: # $result =~ s/š//g;
437: $result =~ s/›/\$>\$/g;
438: $result =~ s/œ/\\{\\oe\\}/g;
439: $result =~ s/Ÿ/\\"\\{Y\\}/g;
440: $result =~ s/ //g;
441: $result =~ s/ //g;
442: $result =~ s/¡/!`/g;
443: $result =~ s/¡/!`/g; #`
444: # $result =~ s/¢//g;
445: # $result =~ s/¢//g;
446: $result =~ s/£/\\pounds/g;
447: $result =~ s/£/\\pounds/g;
448: # $result =~ s/¤//g;
449: # $result =~ s/¤//g;
450: # $result =~ s/¥//g;
451: # $result =~ s/¥//g;
452: # $result =~ s/¦//g;
453: # $result =~ s/¦//g;
454: # $result =~ s/§//g;
455: # $result =~ s/§//g;
456: # $result =~ s/¨//g;
457: # $result =~ s/¨//g;
458: $result =~ s/©/\\copyright/g;
459: $result =~ s/©/\\copyright/g;
460: # $result =~ s/ª//g;
461: # $result =~ s/ª//g;
462: # $result =~ s/«//g;
463: # $result =~ s/«//g;
464: $result =~ s/¬/\$\\neg\$/g;
465: $result =~ s/¬/\$\\neg\$/g;
466: # $result =~ s/­//g;
467: # $result =~ s/­//g;
468: # $result =~ s/®//g;
469: # $result =~ s/®//g;
470: # $result =~ s/¯//g;
471: # $result =~ s/¯//g;
472: $result =~ s/°/\$^\\{\\circ\\}\$/g;
473: $result =~ s/°/\$^\\{\\circ\\}\$/g;
474: $result =~ s/±/\$\\pm\$/g;
475: $result =~ s/±/\$\\pm\$/g;
476: $result =~ s/²/\$^2\$/g;
477: $result =~ s/²/\$^2\$/g;
478: $result =~ s/³/\$^3\$/g;
479: $result =~ s/³/\$^3\$/g;
480: # $result =~ s/´//g;
481: # $result =~ s/´//g;
482: $result =~ s/µ/\$\\mu\$/g;
483: $result =~ s/µ/\$\\mu\$/g;
484: $result =~ s/¶/\\P/g;
485: $result =~ s/¶/\\P/g;
486: $result =~ s/·/\$\\cdot\$/g;
487: $result =~ s/·/\$\\cdot\$/g;
488: # $result =~ s/¸//g;
489: # $result =~ s/¸//g;
490: $result =~ s/¹/\$^1\$/g;
491: $result =~ s/¹/\$^1\$/g;
492: # $result =~ s/º//g;
493: # $result =~ s/º//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/À/\\`{A}/g;
505: $result =~ s/À/\\`{A}/g;
506: $result =~ s/Á/\\'{A}/g;
507: $result =~ s/Á/\\'{A}/g;
508: $result =~ s/Â/\\^{A}/g;
509: $result =~ s/Â/\\^{A}/g;
510: $result =~ s/Ã/\\~{A}/g;
511: $result =~ s/Ã/\\~{A}/g;
512: $result =~ s/Ä/\\"{A}/g;
513: $result =~ s/Ä/\\"{A}/g;
514: $result =~ s/Å/{\\AA}/g;
515: $result =~ s/Å/{\\AA}/g;
516: $result =~ s/Æ/{\\AE}/g;
517: $result =~ s/Æ/{\\AE}/g;
518: # $result =~ s/Ç//g;
519: # $result =~ s/Ç//g;
520: $result =~ s/È/\\`{E}/g;
521: $result =~ s/È/\\`{E}/g;
522: $result =~ s/É/\\'{E}/g;
523: $result =~ s/É/\\'{E}/g;
524: $result =~ s/Ê/\\^{E}/g;
525: $result =~ s/Ê/\\^{E}/g;
526: $result =~ s/Ë/\\`{E}/g;
527: $result =~ s/Ë/\\`{E}/g;
528: $result =~ s/Ì/\\`{I}/g;
529: $result =~ s/Ì/\\`{I}/g;
530: $result =~ s/Í/\\'{I}/g;
531: $result =~ s/Í/\\'{I}/g;
532: $result =~ s/Î/\\^{I}/g;
533: $result =~ s/Î/\\^{I}/g;
534: $result =~ s/Ï/\\"{I}/g;
535: $result =~ s/Ï/\\"{I}/g;
536: # $result =~ s/Ð//g;
537: # $result =~ s/Ð//g;
538: $result =~ s/Ñ/\\~{N}/g;
539: $result =~ s/Ñ/\\~{N}/g;
540: $result =~ s/Ò/\\`{O}/g;
541: $result =~ s/Ò/\\`{O}/g;
542: $result =~ s/Ó/\\'{O}/g;
543: $result =~ s/Ó/\\'{O}/g;
544: $result =~ s/Ô/\\^{O}/g;
545: $result =~ s/Ô/\\^{O}/g;
546: $result =~ s/Õ/\\~{O}/g;
547: $result =~ s/Õ/\\~{O}/g;
548: $result =~ s/Ö/\\"{O}/g;
549: $result =~ s/Ö/\\"{O}/g;
550: $result =~ s/×/\$\\times\$/g;
551: $result =~ s/×/\$\\times\$/g;
552: $result =~ s/Ø/{\\O}/g;
553: $result =~ s/Ø/{\\O}/g;
554: $result =~ s/Ù/\\`{U}/g;
555: $result =~ s/Ù/\\`{U}/g;
556: $result =~ s/Ú/\\'{U}/g;
557: $result =~ s/Ú/\\'{U}/g;
558: $result =~ s/Û/\\^{U}/g;
559: $result =~ s/Û/\\^{U}/g;
560: $result =~ s/Ü/\\"{U}/g;
561: $result =~ s/Ü/\\"{U}/g;
562: $result =~ s/Ý/\\'{Y}/g;
563: $result =~ s/Ý/\\'{Y}/g;
564: # $result =~ s/Þ//g;
565: # $result =~ s/Þ//g;
566: # $result =~ s/ß//g;
567: # $result =~ s/ß//g;
568: $result =~ s/à/\\`{a}/g;
569: $result =~ s/à/\\`{a}/g;
570: $result =~ s/á/\\'{a}/g;
571: $result =~ s/á/\\'{a}/g;
572: $result =~ s/â/\\^{a}/g;
573: $result =~ s/â/\\^{a}/g;
574: $result =~ s/ã/\\~{a}/g;
575: $result =~ s/ã/\\~{a}/g;
576: $result =~ s/ä/\\"{a}/g;
577: $result =~ s/ä/\\"{a}/g;
578: $result =~ s/å/{\\aa}/g;
579: $result =~ s/å/{\\aa}/g;
580: $result =~ s/æ/{\\ae}/g;
581: $result =~ s/æ/{\\ae}/g;
582: # $result =~ s/ç//g;
583: # $result =~ s/ç//g;
584: $result =~ s/è/\\`{e}/g;
585: $result =~ s/è/\\`{e}/g;
586: $result =~ s/é/\\'{e}/g;
587: $result =~ s/é/\\'{e}/g;
588: $result =~ s/ê/\\^{e}/g;
589: $result =~ s/ê/\\^{e}/g;
590: $result =~ s/ë/\\"{e}/g;
591: $result =~ s/ë/\\"{e}/g;
592: $result =~ s/ì/\\`{i}/g;
593: $result =~ s/ì/\\`{i}/g;
594: $result =~ s/í/\\'{i}/g;
595: $result =~ s/í/\\'{i}/g;
596: $result =~ s/î/\\^{i}/g;
597: $result =~ s/î/\\^{i}/g;
598: $result =~ s/ï/\\"{i}/g;
599: $result =~ s/ï/\\"{i}/g;
600: # $result =~ s/ð//g;
601: # $result =~ s/ð//g;
602: $result =~ s/ñ/\\~{n}/g;
603: $result =~ s/ñ/\\~{n}/g;
604: $result =~ s/ò/\\`{o}/g;
605: $result =~ s/ò/\\`{o}/g;
606: $result =~ s/ó/\\'{o}/g;
607: $result =~ s/ó/\\'{o}/g;
608: $result =~ s/ô/\\^{o}/g;
609: $result =~ s/ô/\\^{o}/g;
610: $result =~ s/õ/\\~{o}/g;
611: $result =~ s/õ/\\~{o}/g;
612: $result =~ s/ö/\\"{o}/g;
613: $result =~ s/ö/\\"{o}/g;
614: $result =~ s/÷/\$\\div\$/g;
615: $result =~ s/÷/\$\\div\$/g;
616: $result =~ s/ø/{\\o}/g;
617: $result =~ s/ø/{\\o}/g;
618: $result =~ s/ù/\\`{u}/g;
619: $result =~ s/ù/\\`{u}/g;
620: $result =~ s/ú/\\'{u}/g;
621: $result =~ s/ú/\\'{u}/g;
622: $result =~ s/û/\\^{u}/g;
623: $result =~ s/û/\\^{u}/g;
624: $result =~ s/ü/\\"{u}/g;
625: $result =~ s/ü/\\"{u}/g;
626: $result =~ s/ý/\\'{y}/g;
627: $result =~ s/ý/\\'{y}/g;
628: # $result =~ s/þ//g;
629: # $result =~ s/þ//g;
630: $result =~ s/ÿ/\\"{y}/g;
631: $result =~ s/ÿ/\\"{y}/g;
632: return $result;
633: }
634:
1.28 sakharuk 635: sub additional_cleanup {
636: my $result = shift;
637: my $first_app = index($result,'\documentclass',0);
638: $first_app = index($result,'\documentclass',$first_app+5);
639: while ($first_app != -1) {
640: my $second_app = index($result,'begin{document}',$first_app);
641: $first_app = rindex($result,'\end{document}',$first_app);
642: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';
643: $first_app = index($result,'\documentclass',$first_app+5);
644: }
645: return $result;
646: }
1.33 sakharuk 647: sub page_cleanup {
648: my $result = shift;
649: $_ = $result;
650: m/\\end{document}(\d*)$/;
1.34 sakharuk 651: my $number_of_columns = $1;
1.33 sakharuk 652: my $insert = '{';
1.34 sakharuk 653: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 654: $insert .= '}';
1.34 sakharuk 655: $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;
656: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
657: $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;
1.35 sakharuk 658: $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;
1.37 sakharuk 659: $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;
1.34 sakharuk 660: return $result,$number_of_columns;
1.33 sakharuk 661: }
1.6 sakharuk 662:
1.3 sakharuk 663: sub content_map {
1.7 sakharuk 664: #-- find a list of files to print
1.3 sakharuk 665: my $map_string = shift;
1.5 sakharuk 666: my @number_seq = ();
1.7 sakharuk 667: my @file_seq = ();
1.5 sakharuk 668: my $startlink = index($map_string,'<link',0);
1.7 sakharuk 669: my $endlink = index($map_string,'</link>',$startlink);
670: my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
671: $_ = $chunk;
672: m/from=\"(\d+)\"/;
673: push @number_seq,$1;
1.5 sakharuk 674: while ($startlink != -1) {
1.7 sakharuk 675: $endlink = index($map_string,'</link>',$startlink);
676: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5 sakharuk 677: substr($map_string,$startlink,$endlink-$startlink+7) = '';
678: $_ = $chunk;
679: m/to=\"(\d+)\"/;
680: push @number_seq,$1;
1.13 sakharuk 681: $startlink = index($map_string,'from="'.$1.'"',$startlink);
1.18 sakharuk 682: $startlink = rindex($map_string,'<link ',$startlink);
1.5 sakharuk 683: }
1.7 sakharuk 684: my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
685: while ($stalink != -1) {
686: $startlink = rindex($map_string,'<link ',$stalink);
687: $endlink = index($map_string,'</link>',$startlink);
688: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
689: substr($map_string,$startlink,$endlink-$startlink+7) = '';
690: $_ = $chunk;
691: m/from=\"(\d+)\"/;
692: unshift @number_seq,$1;
693: $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
694: }
695: for (my $i=0;$i<=$#number_seq;$i++) {
696: $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13 sakharuk 697: {
698: my $ahed1 = index($map_string,'src="',$stalink);
699: my $ahed2 = index($map_string,'</resource>',$stalink);
700: if ($ahed1 != -1) {
701: if ($ahed1 < $ahed2) {
702: $startlink = $ahed1;
703: } else {
704: $startlink = rindex($map_string,'src="',$stalink);
705: }
706: } else {
707: $startlink = rindex($map_string,'src="',$stalink);
708: }
709:
710: }
1.7 sakharuk 711: $startlink = index($map_string,'"',$startlink);
712: $endlink = index($map_string,'"',$startlink+1);
713: $chunk = substr($map_string,$startlink,$endlink-$startlink+1);
714: push @file_seq,$chunk;
715: }
716: return @file_seq;
717: }
1.5 sakharuk 718:
1.3 sakharuk 719:
720:
721: sub handler {
722:
723: my $r = shift;
724: $r->content_type('text/html');
725: $r->send_http_header;
726:
727: #-- start form
728: &headerform($r);
729: #-- menu for output
1.16 sakharuk 730: unless ($ENV{'form.phase'}) {
1.3 sakharuk 731: &menu_for_output($r);
732: }
733: #-- core part
734: if ($ENV{'form.phase'} eq 'two') {
735: &output_data($r);
736: }
1.2 sakharuk 737: return OK;
738:
1.1 www 739: }
740:
741: 1;
742: __END__
1.6 sakharuk 743:
744:
1.13 sakharuk 745:
746:
747: #### Test block
1.6 sakharuk 748: # my $ere;
749: # foreach $ere (%ENV) {
1.13 sakharuk 750: # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6 sakharuk 751: # }
1.13 sakharuk 752: ####
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>