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