Annotation of loncom/interface/lonprintout.pm, revision 1.40
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.40 ! sakharuk 4: # $Id: lonprintout.pm,v 1.39 2002/07/18 17:34:29 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.40 ! sakharuk 75: if (not $ENV{'request.role'}=~m/^au\./) {
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.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.40 ! sakharuk 145: if ($ENV{'form.url'}=~m/\.page\s*$/) {
! 146: ($result,$number_of_columns) = &page_cleanup($result);
! 147: }
! 148: } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or
! 149: $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36 sakharuk 150: #-- minimal sequence to which the current document belongs
151: #-- where is the primary sequence containing file?
1.18 sakharuk 152: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
153: $_ = $symbolic;
154: m/([^_]+)_/;
155: my $primary_sequence = '/res/'.$1;
1.36 sakharuk 156: #-- open and analyses the primary sequence
1.18 sakharuk 157: my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
158: my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
159: my @master_seq = &content_map($sequencefilecontents);
1.36 sakharuk 160: #-- produce an output string
1.18 sakharuk 161: for (my $i=0;$i<=$#master_seq;$i++) {
162: $_ = $master_seq[$i];
163: m/\"(.*)\"/;
164: $_ = $1;
1.36 sakharuk 165: my $urlp = $1;
1.20 sakharuk 166: if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.36 sakharuk 167: if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.20 sakharuk 168: my %moreenv;
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');
173: $result .= $texversion;
174: }
175: } else {
1.36 sakharuk 176: my %moreenv;
1.18 sakharuk 177: $moreenv{'form.grade_target'}='tex';
178: &Apache::lonnet::appenv(%moreenv);
179: my $texversion=&Apache::lonnet::ssi($urlp);
180: &Apache::lonnet::delenv('form.grade_target');
1.20 sakharuk 181: $result .= $texversion;
1.16 sakharuk 182: }
1.28 sakharuk 183: }
184: $result = &additional_cleanup($result);
1.13 sakharuk 185: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
186: my @master_seq = ();
1.19 sakharuk 187: my @add_file_seq = ();
1.16 sakharuk 188: #-- where is the main sequence of the course?
1.13 sakharuk 189: my $main_seq = '/res/'.$ENV{'request.course.uri'};
190: my $file=&Apache::lonnet::filelocation("",$main_seq);
191: my $filecontents=&Apache::lonnet::getfile($file);
192: my @file_seq = &content_map($filecontents);
1.19 sakharuk 193: #-- do we have any other sequence inside?
194: my $i=0;
195: while ($i<=$#file_seq) {
196: $_ = $file_seq[$i];
197: if (/\.sequence$/) {
198: $file = &Apache::lonnet::filelocation("",$file_seq[$i]);
199: $filecontents=&Apache::lonnet::getfile($file);
200: @add_file_seq = &content_map($filecontents);
201: splice(@file_seq,$i,1,@add_file_seq);
202: @add_file_seq = ();
203: $i = -1;
204: }
205: $i++;
206: }
207: @master_seq = @file_seq;
1.13 sakharuk 208: #-- produce an output string
209: for (my $i=0;$i<=$#master_seq;$i++) {
210: $_ = $master_seq[$i];
211: m/\"(.*)\"/;
212: $_ = $1;
213: my $urlp = $1;
1.21 sakharuk 214: if (/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.13 sakharuk 215: my %moreenv;
216: $moreenv{'form.grade_target'}='tex';
217: &Apache::lonnet::appenv(%moreenv);
218: my $texversion=&Apache::lonnet::ssi($urlp);
219: &Apache::lonnet::delenv('form.grade_target');
220: $result .= $texversion;
221: }
1.28 sakharuk 222: }
223: $result = &additional_cleanup($result);
1.31 sakharuk 224: } elsif ($choice eq 'Subdirectory print') {
225: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
226: $subdirtoprint =~ s/\/[^\/]+$//;
227: my @list_of_files = ();
228: my $localdirectory = $subdirtoprint;
229: $localdirectory =~ s/.*(\/res\/)/$1/;
230: my @content_directory = &Apache::lonnet::dirlist($localdirectory);
231: for (my $iy=0;$iy<=$#content_directory;$iy++) {
232: my @tempo_array = split(/&/,$content_directory[$iy]);
233: $content_directory[$iy] = $tempo_array[0];
234: if ($content_directory[$iy] =~ m/^[^\.]+\.problem$/) {
235: push @list_of_files,$content_directory[$iy];
1.28 sakharuk 236: }
1.13 sakharuk 237: }
1.31 sakharuk 238: $localdirectory =~ s/\/$//;
239: for (my $i=0;$i<=$#list_of_files;$i++) {
240: my $urlp = $localdirectory.'/'.$list_of_files[$i];
241: my %moreenv;
242: $moreenv{'form.grade_target'}='tex';
243: &Apache::lonnet::appenv(%moreenv);
244: my $texversion=&Apache::lonnet::ssi($urlp);
245: &Apache::lonnet::delenv('form.grade_target');
246: $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
247: $result .= $texversion;
248: }
249: $result = &additional_cleanup($result);
250:
251:
1.28 sakharuk 252:
253:
254:
1.31 sakharuk 255:
1.7 sakharuk 256: }
1.16 sakharuk 257: #-- corrections for the different page formats
1.36 sakharuk 258: if ($layout eq 'CBI' and $numberofcolumns eq '1') {
259: } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {
1.16 sakharuk 260: $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}/;
261: $laystyle = 'album';
262: } elsif ($layout eq 'CAPA') {
263: my $courseidinfo = $ENV{'request.role'};
264: $_ = $courseidinfo;
265: m/.*\/(.*)/;
266: $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
1.34 sakharuk 267: # $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
268: $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;
269: $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 270: $result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;
1.37 sakharuk 271: # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;
272: # $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/;
273: $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/;
274: # $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;
275: $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1.34 sakharuk 276: $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;
1.37 sakharuk 277: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.16 sakharuk 278: }
1.23 sakharuk 279: #-- LaTeX corrections
280: my $first_comment = index($result,'<!--',0);
281: while ($first_comment != -1) {
282: my $end_comment = index($result,'-->',$first_comment);
283: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
284: $first_comment = index($result,'<!--',$first_comment);
285: }
1.17 sakharuk 286: $result =~ s/^\s+$//gm; #remove empty lines
287: $result =~ s/%/\\%/g; #corrects %
1.20 sakharuk 288: $result =~ s/(\s)+/$1/g; #removes more than one empty space
1.23 sakharuk 289: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1.22 sakharuk 290: $result =~ s/ (<|>|) / \$$1\$ /g; #corrects < or >
1.24 sakharuk 291: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1.23 sakharuk 292: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.24 sakharuk 293: $result =~ s/\\\\\s+\[/ \[/g;
294: $result =~ s/θ/\$\\theta\$/g; #converts theta from html into tex
1.29 sakharuk 295: $result =~ s/\b_+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1.37 sakharuk 296: #conversion of html characters to LaTeX equivalents
297: if ($result =~ m/&(\w+|#\d+);/) {
298: $result = &character_chart($result);
299: }
1.7 sakharuk 300: #-- writing .tex file in prtspool
1.16 sakharuk 301: my $temp_file;
1.33 sakharuk 302: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16 sakharuk 303: unless ($temp_file = Apache::File->new('>'.$filename)) {
304: $r->log_error("Couldn't open $filename for output $!");
305: return SERVER_ERROR;
306: }
307: print $temp_file $result;
1.3 sakharuk 308: $r->print(<<FINALEND);
1.26 sakharuk 309: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle">
1.3 sakharuk 310: </body>
311: </html>
312: FINALEND
313: }
1.2 sakharuk 314:
1.37 sakharuk 315: sub character_chart {
316: my $result = shift;
1.40 ! sakharuk 317: $result =~ s/�?0?9;//g;
! 318: $result =~ s/�?10;//g;
! 319: $result =~ s/�?13;//g;
! 320: $result =~ s/�?32;/ /g;
! 321: $result =~ s/�?33;/!/g;
! 322: $result =~ s/�?34;/"/g;
1.39 sakharuk 323: $result =~ s/"/"/g;
1.40 ! sakharuk 324: $result =~ s/�?35;/\\#/g;
! 325: # $result =~ s/�?36;/\\\$/g;
! 326: $result =~ s/�?37;/\\%/g;
! 327: $result =~ s/�?38;/\\&/g;
1.37 sakharuk 328: $result =~ s/&/\\&/g;
1.40 ! sakharuk 329: $result =~ s/�?39;/'/g;
! 330: $result =~ s/�?40;/(/g;
! 331: $result =~ s/�?41;/)/g;
! 332: $result =~ s/�?42;/\*/g;
! 333: $result =~ s/�?43;/\+/g;
! 334: $result =~ s/�?44;/,/g;
! 335: $result =~ s/�?45;/-/g;
! 336: $result =~ s/�?46;/\./g;
! 337: $result =~ s/�?47;/\//g;
! 338: $result =~ s/�?48;/0/g;
! 339: $result =~ s/�?49;/1/g;
! 340: $result =~ s/�?50;/2/g;
! 341: $result =~ s/�?51;/3/g;
! 342: $result =~ s/�?52;/4/g;
! 343: $result =~ s/�?53;/5/g;
! 344: $result =~ s/�?54;/6/g;
! 345: $result =~ s/�?55;/7/g;
! 346: $result =~ s/�?56;/8/g;
! 347: $result =~ s/�?57;/9/g;
! 348: $result =~ s/�?58;/:/g;
! 349: $result =~ s/�?59;/;/g;
! 350: $result =~ s/�?60;/\$<\$/g;
1.37 sakharuk 351: $result =~ s/</\$<\$/g;
1.40 ! sakharuk 352: $result =~ s/�?61;/\$=\$/g;
! 353: $result =~ s/�?62;/\$>\$/g;
1.37 sakharuk 354: $result =~ s/>/\$>\$/g;
1.40 ! sakharuk 355: $result =~ s/�?63;/?/g;
! 356: # $result =~ s/�?64;//g;
! 357: $result =~ s/�?65;/A/g;
! 358: $result =~ s/�?66;/B/g;
! 359: $result =~ s/�?67;/C/g;
! 360: $result =~ s/�?68;/D/g;
! 361: $result =~ s/�?69;/E/g;
! 362: $result =~ s/�?70;/F/g;
! 363: $result =~ s/�?71;/G/g;
! 364: $result =~ s/�?72;/H/g;
! 365: $result =~ s/�?73;/I/g;
! 366: $result =~ s/�?74;/J/g;
! 367: $result =~ s/�?75;/K/g;
! 368: $result =~ s/�?76;/L/g;
! 369: $result =~ s/�?77;/M/g;
! 370: $result =~ s/�?78;/N/g;
! 371: $result =~ s/�?79;/O/g;
! 372: $result =~ s/�?80;/P/g;
! 373: $result =~ s/�?81;/Q/g;
! 374: $result =~ s/�?82;/R/g;
! 375: $result =~ s/�?83;/S/g;
! 376: $result =~ s/�?84;/T/g;
! 377: $result =~ s/�?85;/U/g;
! 378: $result =~ s/�?86;/V/g;
! 379: $result =~ s/�?87;/W/g;
! 380: $result =~ s/�?88;/X/g;
! 381: $result =~ s/�?89;/Y/g;
! 382: $result =~ s/�?90;/Z/g;
! 383: $result =~ s/�?91;/[/g;
! 384: $result =~ s/�?92;/\\/g;
! 385: $result =~ s/�?93;/]/g;
! 386: # $result =~ s/�?94;//g;
! 387: # $result =~ s/�?95;//g;
! 388: $result =~ s/�?96;/`/g;
! 389: $result =~ s/�?97;/a/g;
! 390: $result =~ s/�?98;/b/g;
! 391: $result =~ s/�?99;/c/g;
1.37 sakharuk 392: $result =~ s/d/d/g;
393: $result =~ s/e/e/g;
394: $result =~ s/f/f/g;
395: $result =~ s/g/g/g;
396: $result =~ s/h/h/g;
397: $result =~ s/i/i/g;
398: $result =~ s/j/j/g;
399: $result =~ s/k/k/g;
400: $result =~ s/l/l/g;
401: $result =~ s/m/m/g;
402: $result =~ s/n/n/g;
403: $result =~ s/o/o/g;
404: $result =~ s/p/p/g;
405: $result =~ s/q/q/g;
406: $result =~ s/r/r/g;
407: $result =~ s/s/s/g;
408: $result =~ s/t/t/g;
409: $result =~ s/u/u/g;
410: $result =~ s/v/v/g;
411: $result =~ s/w/w/g;
412: $result =~ s/x/x/g;
413: $result =~ s/y/y/g;
414: $result =~ s/z/z/g;
415: $result =~ s/{/\\{/g;
416: $result =~ s/|/\|/g;
417: $result =~ s/}/\\}/g;
418: $result =~ s/~/\~/g;
419: $result =~ s/‚/,/g;
420: # $result =~ s/ƒ//g;
421: $result =~ s/„/''/g;
422: $result =~ s/…/\$\\ldots\$/g;
423: $result =~ s/†/\$\\dagger\$/g;
424: $result =~ s/‡/\$\\ddagger\$/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/’/'/g;
432: $result =~ s/“/``/g;
433: $result =~ s/”/''/g;
434: $result =~ s/•/\$\\bullet\$/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/œ/\\{\\oe\\}/g;
442: $result =~ s/Ÿ/\\"\\{Y\\}/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/£/\\pounds/g;
450: $result =~ s/£/\\pounds/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/§//g;
459: # $result =~ s/¨//g;
460: # $result =~ s/¨//g;
461: $result =~ s/©/\\copyright/g;
462: $result =~ s/©/\\copyright/g;
463: # $result =~ s/ª//g;
464: # $result =~ s/ª//g;
465: # $result =~ s/«//g;
466: # $result =~ s/«//g;
467: $result =~ s/¬/\$\\neg\$/g;
468: $result =~ s/¬/\$\\neg\$/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/°/\$^\\{\\circ\\}\$/g;
476: $result =~ s/°/\$^\\{\\circ\\}\$/g;
477: $result =~ s/±/\$\\pm\$/g;
478: $result =~ s/±/\$\\pm\$/g;
479: $result =~ s/²/\$^2\$/g;
480: $result =~ s/²/\$^2\$/g;
481: $result =~ s/³/\$^3\$/g;
482: $result =~ s/³/\$^3\$/g;
483: # $result =~ s/´//g;
484: # $result =~ s/´//g;
485: $result =~ s/µ/\$\\mu\$/g;
486: $result =~ s/µ/\$\\mu\$/g;
487: $result =~ s/¶/\\P/g;
488: $result =~ s/¶/\\P/g;
489: $result =~ s/·/\$\\cdot\$/g;
490: $result =~ s/·/\$\\cdot\$/g;
491: # $result =~ s/¸//g;
492: # $result =~ s/¸//g;
493: $result =~ s/¹/\$^1\$/g;
494: $result =~ s/¹/\$^1\$/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/¾//g;
505: $result =~ s/¿/?`/g;
506: $result =~ s/¿/?`/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/Ã/\\~{A}/g;
515: $result =~ s/Ä/\\"{A}/g;
516: $result =~ s/Ä/\\"{A}/g;
517: $result =~ s/Å/{\\AA}/g;
518: $result =~ s/Å/{\\AA}/g;
519: $result =~ s/Æ/{\\AE}/g;
520: $result =~ s/Æ/{\\AE}/g;
521: # $result =~ s/Ç//g;
522: # $result =~ s/Ç//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/Ê/\\^{E}/g;
529: $result =~ s/Ë/\\`{E}/g;
530: $result =~ s/Ë/\\`{E}/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/Î/\\^{I}/g;
537: $result =~ s/Ï/\\"{I}/g;
538: $result =~ s/Ï/\\"{I}/g;
539: # $result =~ s/Ð//g;
540: # $result =~ s/Ð//g;
541: $result =~ s/Ñ/\\~{N}/g;
542: $result =~ s/Ñ/\\~{N}/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/Õ/\\~{O}/g;
551: $result =~ s/Ö/\\"{O}/g;
552: $result =~ s/Ö/\\"{O}/g;
553: $result =~ s/×/\$\\times\$/g;
554: $result =~ s/×/\$\\times\$/g;
555: $result =~ s/Ø/{\\O}/g;
556: $result =~ s/Ø/{\\O}/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/Û/\\^{U}/g;
563: $result =~ s/Ü/\\"{U}/g;
564: $result =~ s/Ü/\\"{U}/g;
565: $result =~ s/Ý/\\'{Y}/g;
566: $result =~ s/Ý/\\'{Y}/g;
567: # $result =~ s/Þ//g;
568: # $result =~ s/Þ//g;
569: # $result =~ s/ß//g;
570: # $result =~ s/ß//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/ã/\\~{a}/g;
579: $result =~ s/ä/\\"{a}/g;
580: $result =~ s/ä/\\"{a}/g;
581: $result =~ s/å/{\\aa}/g;
582: $result =~ s/å/{\\aa}/g;
583: $result =~ s/æ/{\\ae}/g;
584: $result =~ s/æ/{\\ae}/g;
585: # $result =~ s/ç//g;
586: # $result =~ s/ç//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/ê/\\^{e}/g;
593: $result =~ s/ë/\\"{e}/g;
594: $result =~ s/ë/\\"{e}/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/î/\\^{i}/g;
601: $result =~ s/ï/\\"{i}/g;
602: $result =~ s/ï/\\"{i}/g;
603: # $result =~ s/ð//g;
604: # $result =~ s/ð//g;
605: $result =~ s/ñ/\\~{n}/g;
606: $result =~ s/ñ/\\~{n}/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/õ/\\~{o}/g;
615: $result =~ s/ö/\\"{o}/g;
616: $result =~ s/ö/\\"{o}/g;
617: $result =~ s/÷/\$\\div\$/g;
618: $result =~ s/÷/\$\\div\$/g;
619: $result =~ s/ø/{\\o}/g;
620: $result =~ s/ø/{\\o}/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/û/\\^{u}/g;
627: $result =~ s/ü/\\"{u}/g;
628: $result =~ s/ü/\\"{u}/g;
629: $result =~ s/ý/\\'{y}/g;
630: $result =~ s/ý/\\'{y}/g;
631: # $result =~ s/þ//g;
632: # $result =~ s/þ//g;
633: $result =~ s/ÿ/\\"{y}/g;
634: $result =~ s/ÿ/\\"{y}/g;
635: return $result;
636: }
637:
1.28 sakharuk 638: sub additional_cleanup {
639: my $result = shift;
640: my $first_app = index($result,'\documentclass',0);
641: $first_app = index($result,'\documentclass',$first_app+5);
642: while ($first_app != -1) {
643: my $second_app = index($result,'begin{document}',$first_app);
644: $first_app = rindex($result,'\end{document}',$first_app);
645: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';
646: $first_app = index($result,'\documentclass',$first_app+5);
647: }
648: return $result;
649: }
1.33 sakharuk 650: sub page_cleanup {
651: my $result = shift;
652: $_ = $result;
653: m/\\end{document}(\d*)$/;
1.34 sakharuk 654: my $number_of_columns = $1;
1.33 sakharuk 655: my $insert = '{';
1.34 sakharuk 656: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 657: $insert .= '}';
1.34 sakharuk 658: $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;
659: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
660: $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;
1.35 sakharuk 661: $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;
1.37 sakharuk 662: $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;
1.34 sakharuk 663: return $result,$number_of_columns;
1.33 sakharuk 664: }
1.6 sakharuk 665:
1.3 sakharuk 666: sub content_map {
1.7 sakharuk 667: #-- find a list of files to print
1.3 sakharuk 668: my $map_string = shift;
1.5 sakharuk 669: my @number_seq = ();
1.7 sakharuk 670: my @file_seq = ();
1.5 sakharuk 671: my $startlink = index($map_string,'<link',0);
1.7 sakharuk 672: my $endlink = index($map_string,'</link>',$startlink);
673: my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
674: $_ = $chunk;
675: m/from=\"(\d+)\"/;
676: push @number_seq,$1;
1.5 sakharuk 677: while ($startlink != -1) {
1.7 sakharuk 678: $endlink = index($map_string,'</link>',$startlink);
679: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5 sakharuk 680: substr($map_string,$startlink,$endlink-$startlink+7) = '';
681: $_ = $chunk;
682: m/to=\"(\d+)\"/;
683: push @number_seq,$1;
1.13 sakharuk 684: $startlink = index($map_string,'from="'.$1.'"',$startlink);
1.18 sakharuk 685: $startlink = rindex($map_string,'<link ',$startlink);
1.5 sakharuk 686: }
1.7 sakharuk 687: my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
688: while ($stalink != -1) {
689: $startlink = rindex($map_string,'<link ',$stalink);
690: $endlink = index($map_string,'</link>',$startlink);
691: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
692: substr($map_string,$startlink,$endlink-$startlink+7) = '';
693: $_ = $chunk;
694: m/from=\"(\d+)\"/;
695: unshift @number_seq,$1;
696: $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
697: }
698: for (my $i=0;$i<=$#number_seq;$i++) {
699: $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13 sakharuk 700: {
701: my $ahed1 = index($map_string,'src="',$stalink);
702: my $ahed2 = index($map_string,'</resource>',$stalink);
703: if ($ahed1 != -1) {
704: if ($ahed1 < $ahed2) {
705: $startlink = $ahed1;
706: } else {
707: $startlink = rindex($map_string,'src="',$stalink);
708: }
709: } else {
710: $startlink = rindex($map_string,'src="',$stalink);
711: }
712:
713: }
1.7 sakharuk 714: $startlink = index($map_string,'"',$startlink);
715: $endlink = index($map_string,'"',$startlink+1);
716: $chunk = substr($map_string,$startlink,$endlink-$startlink+1);
717: push @file_seq,$chunk;
718: }
719: return @file_seq;
720: }
1.5 sakharuk 721:
1.3 sakharuk 722:
723:
724: sub handler {
725:
726: my $r = shift;
727: $r->content_type('text/html');
728: $r->send_http_header;
729:
730: #-- start form
731: &headerform($r);
732: #-- menu for output
1.16 sakharuk 733: unless ($ENV{'form.phase'}) {
1.3 sakharuk 734: &menu_for_output($r);
735: }
736: #-- core part
737: if ($ENV{'form.phase'} eq 'two') {
738: &output_data($r);
739: }
1.2 sakharuk 740: return OK;
741:
1.1 www 742: }
743:
744: 1;
745: __END__
1.6 sakharuk 746:
747:
1.13 sakharuk 748:
749:
750: #### Test block
1.6 sakharuk 751: # my $ere;
752: # foreach $ere (%ENV) {
1.13 sakharuk 753: # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6 sakharuk 754: # }
1.13 sakharuk 755: ####
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>