Annotation of loncom/interface/lonprintout.pm, revision 1.37

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.37    ! sakharuk    4: # $Id: lonprintout.pm,v 1.36 2002/07/01 20:56:20 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.16      sakharuk   61: <h1>What do you want to print? Make a choice.</h1><br />
1.3       sakharuk   62: ENDHEADER
                     63: }
                     64: 
1.1       www        65: 
1.3       sakharuk   66: sub menu_for_output {
                     67:     my $r = shift;
1.28      sakharuk   68:     $r->print(<<ENDMENUOUT1);
1.3       sakharuk   69: <input type="hidden" name="phase" value="two">
1.10      albertel   70: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
1.25      sakharuk   71: <input type="radio" name="choice" value="Standard LaTeX output for current document" checked>  Current document
1.16      sakharuk   72: (you will print what you see on the screen)<br />
1.19      sakharuk   73: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence">  All problems from the primary sequence<br />
1.20      sakharuk   74: <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   75: <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   76: <br />
                     77: ENDMENUOUT1
1.31      sakharuk   78:     my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
                     79:     $subdirtoprint =~ s/\/[^\/]+$//;
                     80:     if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') {
1.28      sakharuk   81: 	$r->print(<<ENDMENUOUT2);
1.31      sakharuk   82: <input type="radio" name="choice" value="Subdirectory print">  All problems from current subdirectory (where this particular problem is)<br />
1.28      sakharuk   83: ENDMENUOUT2
1.31      sakharuk   84: }
                     85:     $r->print(<<ENDMENUOUT3);
1.16      sakharuk   86: <br /><hr /><br />
                     87: <h1>And what page format do you prefer?</h1>
1.36      sakharuk   88: <table>
                     89:  <tr>
                     90:    <td>
                     91:      <input type="radio" name="layout" value="CBI"> Landscape <br />
                     92:      <input type="radio" name="layout" value="CAPA" checked>  Portrait <br />
                     93:    </td>
                     94:    <td>&nbsp;</td>
                     95:    <td rawspan="2">
                     96:      Number of columns: <input type="text" size="2" name="numberofcolumns" value="2"> 
                     97:    </td>
                     98:  </tr>
                     99: </table>
                    100: </br> 
1.16      sakharuk  101: <input type="submit" value="Submit your choice">
1.3       sakharuk  102: </form>
                    103: </body>
                    104: </html>
1.28      sakharuk  105: ENDMENUOUT3
1.3       sakharuk  106: }
1.2       sakharuk  107: 
                    108: 
1.16      sakharuk  109: 
                    110: 
1.3       sakharuk  111: sub output_data {
                    112:     my $r = shift;
                    113:     $r->print(<<ENDPART);
                    114: <html>
                    115: <head>
                    116: <title>LON-CAPA output for printing</title>
                    117: </head>
                    118: <body bgcolor="FFFFFF">
                    119: <hr>
                    120: ENDPART
1.2       sakharuk  121: 
1.3       sakharuk  122:     my $choice = $ENV{'form.choice'};
1.16      sakharuk  123:     my $layout = $ENV{'form.layout'};
1.36      sakharuk  124:     my $numberofcolumns = $ENV{'form.numberofcolumns'};               
1.16      sakharuk  125:     my $laystyle = 'book';
1.2       sakharuk  126:     my $result = '';
1.34      sakharuk  127:     my $number_of_columns = 1;
1.36      sakharuk  128:  
1.3       sakharuk  129:     if ($choice eq 'Standard LaTeX output for current document') {
1.36      sakharuk  130:       #-- single document - problem, page, html, xml  
1.14      albertel  131:       my %moreenv;
                    132:       $moreenv{'form.grade_target'}='tex';
                    133:       $moreenv{'request.filename'}=$ENV{'form.url'};
                    134:       &Apache::lonnet::appenv(%moreenv);
                    135:       my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
                    136:       &Apache::lonnet::delenv('form.grade_target');
                    137:       $result .= $texversion;
1.29      sakharuk  138:       $result = &additional_cleanup($result);
1.34      sakharuk  139:       if ($ENV{'form.url'}=~m/\.page\s*$/) {($result,$number_of_columns) = &page_cleanup($result);}
1.20      sakharuk  140:     } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36      sakharuk  141:       #-- minimal sequence to which the current document belongs
                    142:         #-- where is the primary sequence containing file?
1.18      sakharuk  143: 	my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
                    144: 	$_ = $symbolic;
                    145: 	m/([^_]+)_/;
                    146: 	my $primary_sequence = '/res/'.$1;
1.36      sakharuk  147:         #-- open and analyses the primary sequence
1.18      sakharuk  148: 	my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
                    149: 	my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
                    150: 	my @master_seq = &content_map($sequencefilecontents);
1.36      sakharuk  151:         #-- produce an output string
1.18      sakharuk  152: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    153: 	    $_ = $master_seq[$i];
                    154: 	    m/\"(.*)\"/;
                    155:             $_ = $1;
1.36      sakharuk  156:             my $urlp = $1;		
1.20      sakharuk  157: 	    if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.36      sakharuk  158: 		if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.20      sakharuk  159: 		    my %moreenv;
                    160: 		    $moreenv{'form.grade_target'}='tex';
                    161: 		    &Apache::lonnet::appenv(%moreenv);
                    162: 		    my $texversion=&Apache::lonnet::ssi($urlp);
                    163: 		    &Apache::lonnet::delenv('form.grade_target');
                    164: 		    $result .= $texversion;        
                    165: 		}
                    166: 	    } else {
1.36      sakharuk  167: 		my %moreenv;
1.18      sakharuk  168: 		$moreenv{'form.grade_target'}='tex';
                    169: 		&Apache::lonnet::appenv(%moreenv);
                    170: 		my $texversion=&Apache::lonnet::ssi($urlp);
                    171: 		&Apache::lonnet::delenv('form.grade_target');
1.20      sakharuk  172: 		$result .= $texversion;    
1.16      sakharuk  173: 	    }
1.28      sakharuk  174: 	}	
                    175: 	$result = &additional_cleanup($result);
1.13      sakharuk  176:     }  elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
                    177: 	my @master_seq = ();
1.19      sakharuk  178: 	my @add_file_seq = ();
1.16      sakharuk  179: #-- where is the main sequence of the course?
1.13      sakharuk  180: 	my $main_seq = '/res/'.$ENV{'request.course.uri'};
                    181: 	my $file=&Apache::lonnet::filelocation("",$main_seq);
                    182: 	my $filecontents=&Apache::lonnet::getfile($file);
                    183: 	my @file_seq = &content_map($filecontents);
1.19      sakharuk  184: #-- do we have any other sequence inside?
                    185: 	my $i=0;
                    186: 	while ($i<=$#file_seq) {
                    187: 	    $_ = $file_seq[$i];
                    188: 	    if (/\.sequence$/) {
                    189: 		$file = &Apache::lonnet::filelocation("",$file_seq[$i]);
                    190: 		$filecontents=&Apache::lonnet::getfile($file);
                    191: 		@add_file_seq = &content_map($filecontents);
                    192: 		splice(@file_seq,$i,1,@add_file_seq);
                    193: 		@add_file_seq = ();
                    194: 		$i = -1;
                    195: 	    }
                    196: 	    $i++;
                    197: 	}
                    198: 	@master_seq = @file_seq;	
1.13      sakharuk  199: #-- produce an output string
                    200: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    201: 	    $_ = $master_seq[$i];
                    202: 	    m/\"(.*)\"/;
                    203:             $_ = $1;
                    204:             my $urlp = $1;
1.21      sakharuk  205:             if (/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.13      sakharuk  206: 		my %moreenv;
                    207: 		$moreenv{'form.grade_target'}='tex';
                    208: 		&Apache::lonnet::appenv(%moreenv);
                    209: 		my $texversion=&Apache::lonnet::ssi($urlp);
                    210: 		&Apache::lonnet::delenv('form.grade_target');
                    211: 		$result .= $texversion;        
                    212: 	    }
1.28      sakharuk  213: 	}	    
                    214: 	$result = &additional_cleanup($result);
1.31      sakharuk  215:     } elsif ($choice eq 'Subdirectory print') {      
                    216: 	my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
                    217: 	$subdirtoprint =~ s/\/[^\/]+$//;
                    218: 	my @list_of_files = ();
                    219: 	my $localdirectory = $subdirtoprint;
                    220: 	$localdirectory =~ s/.*(\/res\/)/$1/;
                    221: 	my @content_directory = &Apache::lonnet::dirlist($localdirectory);
                    222: 	for (my $iy=0;$iy<=$#content_directory;$iy++) {
                    223: 	    my @tempo_array = split(/&/,$content_directory[$iy]);
                    224: 	    $content_directory[$iy] = $tempo_array[0];
                    225: 	    if ($content_directory[$iy] =~ m/^[^\.]+\.problem$/) {
                    226: 		push @list_of_files,$content_directory[$iy];
1.28      sakharuk  227: 	    }
1.13      sakharuk  228: 	}
1.31      sakharuk  229: 	$localdirectory =~ s/\/$//;
                    230: 	for (my $i=0;$i<=$#list_of_files;$i++) {
                    231: 	    my $urlp = $localdirectory.'/'.$list_of_files[$i];	     
                    232: 	    my %moreenv;
                    233: 	    $moreenv{'form.grade_target'}='tex';
                    234: 	    &Apache::lonnet::appenv(%moreenv);
                    235: 	    my $texversion=&Apache::lonnet::ssi($urlp);
                    236: 	    &Apache::lonnet::delenv('form.grade_target');
                    237: 	    $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
                    238: 	    $result .= $texversion;   
                    239: 	}
                    240: 	$result = &additional_cleanup($result);
                    241: 	
                    242: 	
1.28      sakharuk  243: 
                    244: 
                    245: 
1.31      sakharuk  246: 	
1.7       sakharuk  247:     }
1.16      sakharuk  248: #-- corrections for the different page formats
1.36      sakharuk  249:     if ($layout eq 'CBI' and $numberofcolumns eq '1') {
                    250:     } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {
1.16      sakharuk  251: 	$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}/;
                    252:         $laystyle = 'album';
                    253:     } elsif ($layout eq 'CAPA') {
                    254:         my $courseidinfo = $ENV{'request.role'};
                    255:         $_ = $courseidinfo;
                    256:         m/.*\/(.*)/;
                    257:         $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
1.34      sakharuk  258: #	$result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
                    259: 	$result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;
                    260: 	$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  261: 	$result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;
1.37    ! sakharuk  262: #	$result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;
        !           263: #	$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/;
        !           264: 	$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/;
        !           265: #        $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;
        !           266:         $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1.34      sakharuk  267:         $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;
1.37    ! sakharuk  268: 	$result =~ s/\$number_of_columns/$number_of_columns/g;
1.16      sakharuk  269:     }
1.23      sakharuk  270: #-- LaTeX corrections     
                    271:     my $first_comment = index($result,'<!--',0);
                    272:     while ($first_comment != -1) {
                    273: 	my $end_comment = index($result,'-->',$first_comment);
                    274: 	substr($result,$first_comment,$end_comment-$first_comment+3) = '';
                    275: 	$first_comment = index($result,'<!--',$first_comment);
                    276:     }
1.17      sakharuk  277:     $result =~ s/^\s+$//gm; #remove empty lines
                    278:     $result =~ s/%/\\%/g;   #corrects %
1.20      sakharuk  279:     $result =~ s/(\s)+/$1/g; #removes more than one empty space
1.23      sakharuk  280:     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1.22      sakharuk  281:     $result =~ s/ (<|>|) / \$$1\$ /g; #corrects < or >
1.24      sakharuk  282:     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1.23      sakharuk  283:     $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.24      sakharuk  284: 	$result =~ s/\\\\\s+\[/ \[/g;
                    285:     $result =~ s/&#952;/\$\\theta\$/g; #converts theta from html into tex
1.29      sakharuk  286:     $result =~ s/\b_+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1.37    ! sakharuk  287:     #conversion of html characters to LaTeX equivalents
        !           288:     if ($result =~ m/&(\w+|#\d+);/) {
        !           289: 	$result = &character_chart($result);
        !           290:     }
1.7       sakharuk  291: #-- writing .tex file in prtspool 
1.16      sakharuk  292:     my $temp_file;
1.33      sakharuk  293:     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16      sakharuk  294:     unless ($temp_file = Apache::File->new('>'.$filename)) {
                    295: 	$r->log_error("Couldn't open $filename for output $!");
                    296: 	return SERVER_ERROR; 
                    297:     } 
                    298:     print $temp_file $result;
1.3       sakharuk  299: $r->print(<<FINALEND);
1.26      sakharuk  300: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle">
1.3       sakharuk  301: </body>
                    302: </html>
                    303: FINALEND
                    304: }
1.2       sakharuk  305: 
1.37    ! sakharuk  306: sub character_chart {
        !           307:     my $result = shift;	
        !           308:     $result =~ s/&#009;//g;
        !           309:     $result =~ s/&#010;//g;
        !           310:     $result =~ s/&#013;//g;
        !           311:     $result =~ s/&#032;/ /g;
        !           312:     $result =~ s/&#033;/!/g;
        !           313:     $result =~ s/&#034;/"/g;
        !           314:     $result =~ s/&quot;/"/g; #"
        !           315:     $result =~ s/&#035;/\\#/g;
        !           316:     $result =~ s/&#036;/\\\$/g;
        !           317:     $result =~ s/&#037;/\\%/g; 
        !           318:     $result =~ s/&#038;/\\&/g; 
        !           319:     $result =~ s/&amp;/\\&/g;
        !           320:     $result =~ s/&#039;/'/g;
        !           321:     $result =~ s/&#040;/(/g;
        !           322:     $result =~ s/&#041;/)/g;
        !           323:     $result =~ s/&#042;/\*/g;
        !           324:     $result =~ s/&#043;/\+/g;
        !           325:     $result =~ s/&#044;/,/g;
        !           326:     $result =~ s/&#045;/-/g;
        !           327:     $result =~ s/&#046;/\./g;
        !           328:     $result =~ s/&#047;/\//g;
        !           329:     $result =~ s/&#048;/0/g;
        !           330:     $result =~ s/&#049;/1/g;
        !           331:     $result =~ s/&#050;/2/g;
        !           332:     $result =~ s/&#051;/3/g;
        !           333:     $result =~ s/&#052;/4/g;
        !           334:     $result =~ s/&#053;/5/g;
        !           335:     $result =~ s/&#054;/6/g;
        !           336:     $result =~ s/&#055;/7/g;
        !           337:     $result =~ s/&#056;/8/g;
        !           338:     $result =~ s/&#057;/9/g;
        !           339:     $result =~ s/&#058;/:/g;
        !           340:     $result =~ s/&#059;/;/g;
        !           341:     $result =~ s/&#060;/\$<\$/g;
        !           342:     $result =~ s/&lt;/\$<\$/g;
        !           343:     $result =~ s/&#061;/\$=\$/g;
        !           344:     $result =~ s/&#062;/\$>\$/g;
        !           345:     $result =~ s/&gt;/\$>\$/g;
        !           346:     $result =~ s/&#063;/?/g;
        !           347: #    $result =~ s/&#064;//g;
        !           348:     $result =~ s/&#065;/A/g;
        !           349:     $result =~ s/&#066;/B/g;
        !           350:     $result =~ s/&#067;/C/g;
        !           351:     $result =~ s/&#068;/D/g;
        !           352:     $result =~ s/&#069;/E/g;
        !           353:     $result =~ s/&#070;/F/g;
        !           354:     $result =~ s/&#071;/G/g;
        !           355:     $result =~ s/&#072;/H/g;
        !           356:     $result =~ s/&#073;/I/g;
        !           357:     $result =~ s/&#074;/J/g;
        !           358:     $result =~ s/&#075;/K/g;
        !           359:     $result =~ s/&#076;/L/g;
        !           360:     $result =~ s/&#077;/M/g;
        !           361:     $result =~ s/&#078;/N/g;
        !           362:     $result =~ s/&#079;/O/g;
        !           363:     $result =~ s/&#080;/P/g;
        !           364:     $result =~ s/&#081;/Q/g;
        !           365:     $result =~ s/&#082;/R/g;
        !           366:     $result =~ s/&#083;/S/g;
        !           367:     $result =~ s/&#084;/T/g;
        !           368:     $result =~ s/&#085;/U/g;
        !           369:     $result =~ s/&#086;/V/g;
        !           370:     $result =~ s/&#087;/W/g;
        !           371:     $result =~ s/&#088;/X/g;
        !           372:     $result =~ s/&#089;/Y/g;
        !           373:     $result =~ s/&#090;/Z/g;
        !           374:     $result =~ s/&#091;/[/g;
        !           375:     $result =~ s/&#092;/\\/g;
        !           376:     $result =~ s/&#093;/]/g;
        !           377: #    $result =~ s/&#094;//g;
        !           378: #    $result =~ s/&#095;//g;
        !           379:     $result =~ s/&#096;/`/g;
        !           380:     $result =~ s/&#097;/a/g;
        !           381:     $result =~ s/&#098;/b/g;
        !           382:     $result =~ s/&#099;/c/g;
        !           383:     $result =~ s/&#100;/d/g;
        !           384:     $result =~ s/&#101;/e/g;
        !           385:     $result =~ s/&#102;/f/g;
        !           386:     $result =~ s/&#103;/g/g;
        !           387:     $result =~ s/&#104;/h/g;
        !           388:     $result =~ s/&#105;/i/g;
        !           389:     $result =~ s/&#106;/j/g;
        !           390:     $result =~ s/&#107;/k/g;
        !           391:     $result =~ s/&#108;/l/g;
        !           392:     $result =~ s/&#109;/m/g;
        !           393:     $result =~ s/&#110;/n/g;
        !           394:     $result =~ s/&#111;/o/g;
        !           395:     $result =~ s/&#112;/p/g;
        !           396:     $result =~ s/&#113;/q/g;
        !           397:     $result =~ s/&#114;/r/g;
        !           398:     $result =~ s/&#115;/s/g;
        !           399:     $result =~ s/&#116;/t/g;
        !           400:     $result =~ s/&#117;/u/g;
        !           401:     $result =~ s/&#118;/v/g;
        !           402:     $result =~ s/&#119;/w/g;
        !           403:     $result =~ s/&#120;/x/g;
        !           404:     $result =~ s/&#121;/y/g;
        !           405:     $result =~ s/&#122;/z/g;
        !           406:     $result =~ s/&#123;/\\{/g;
        !           407:     $result =~ s/&#124;/\|/g;
        !           408:     $result =~ s/&#125;/\\}/g;
        !           409:     $result =~ s/&#126;/\~/g;
        !           410:     $result =~ s/&#130;/,/g;
        !           411: #    $result =~ s/&#131;//g;
        !           412:     $result =~ s/&#132;/''/g;
        !           413:     $result =~ s/&#133;/\$\\ldots\$/g;
        !           414:     $result =~ s/&#134;/\$\\dagger\$/g;
        !           415:     $result =~ s/&#135;/\$\\ddagger\$/g;
        !           416: #    $result =~ s/&#136;//g;
        !           417: #    $result =~ s/&#137;//g;
        !           418: #    $result =~ s/&#138;//g;
        !           419:     $result =~ s/&#139;/\$<\$/g;
        !           420: #    $result =~ s/&#140;//g;
        !           421:     $result =~ s/&#145;/`/g;
        !           422:     $result =~ s/&#146;/'/g;
        !           423:     $result =~ s/&#147;/``/g;
        !           424:     $result =~ s/&#148;/''/g;
        !           425:     $result =~ s/&#149;/\$\\bullet\$/g;
        !           426: #    $result =~ s/&#150;//g;
        !           427: #    $result =~ s/&#151;//g;
        !           428:     $result =~ s/&#152;/~/g;
        !           429: #    $result =~ s/&#153;//g;
        !           430: #    $result =~ s/&#154;//g;
        !           431:     $result =~ s/&#155;/\$>\$/g;
        !           432:     $result =~ s/&#156;/\\{\\oe\\}/g;
        !           433:     $result =~ s/&#159;/\\"\\{Y\\}/g;
        !           434:     $result =~ s/&#160;//g;
        !           435:     $result =~ s/&nbsp;//g;
        !           436:     $result =~ s/&#161;/!`/g;
        !           437:     $result =~ s/&iexcl;/!`/g; #`
        !           438: #    $result =~ s/&#162;//g;
        !           439: #    $result =~ s/&cent;//g;
        !           440:     $result =~ s/&#163;/\\pounds/g; 
        !           441:     $result =~ s/&pound;/\\pounds/g;
        !           442: #    $result =~ s/&#164;//g;
        !           443: #    $result =~ s/&curren;//g;
        !           444: #    $result =~ s/&#165;//g;
        !           445: #    $result =~ s/&yen;//g;
        !           446: #    $result =~ s/&#166;//g;
        !           447: #    $result =~ s/&brvbar;//g;
        !           448: #    $result =~ s/&#167;//g;
        !           449: #    $result =~ s/&sect;//g;
        !           450: #    $result =~ s/&#168;//g;
        !           451: #    $result =~ s/&uml;//g;
        !           452:     $result =~ s/&#169;/\\copyright/g;
        !           453:     $result =~ s/&copy;/\\copyright/g;
        !           454: #    $result =~ s/&#170;//g;
        !           455: #    $result =~ s/&ordf;//g;
        !           456: #    $result =~ s/&#171;//g;
        !           457: #    $result =~ s/&laquo;//g;
        !           458:     $result =~ s/&#172;/\$\\neg\$/g;
        !           459:     $result =~ s/&not;/\$\\neg\$/g;
        !           460: #    $result =~ s/&#173;//g;
        !           461: #    $result =~ s/&shy;//g;
        !           462: #    $result =~ s/&#174;//g;
        !           463: #    $result =~ s/&reg;//g;
        !           464: #    $result =~ s/&#175;//g;
        !           465: #    $result =~ s/&macr;//g;
        !           466:     $result =~ s/&#176;/\$^\\{\\circ\\}\$/g;
        !           467:     $result =~ s/&deg;/\$^\\{\\circ\\}\$/g;
        !           468:     $result =~ s/&#177;/\$\\pm\$/g;
        !           469:     $result =~ s/&plusmn;/\$\\pm\$/g;
        !           470:     $result =~ s/&#178;/\$^2\$/g;
        !           471:     $result =~ s/&sup2;/\$^2\$/g;
        !           472:     $result =~ s/&#179;/\$^3\$/g;
        !           473:     $result =~ s/&sup3;/\$^3\$/g;
        !           474: #    $result =~ s/&#180;//g;
        !           475: #    $result =~ s/&acute;//g;
        !           476:     $result =~ s/&#181;/\$\\mu\$/g;
        !           477:     $result =~ s/&micro;/\$\\mu\$/g;
        !           478:     $result =~ s/&#182;/\\P/g;
        !           479:     $result =~ s/&para;/\\P/g;
        !           480:     $result =~ s/&#183;/\$\\cdot\$/g;
        !           481:     $result =~ s/&middot;/\$\\cdot\$/g;
        !           482: #    $result =~ s/&#184;//g;
        !           483: #    $result =~ s/&cedil;//g;
        !           484:     $result =~ s/&#185;/\$^1\$/g;
        !           485:     $result =~ s/&sup1;/\$^1\$/g;
        !           486: #    $result =~ s/&#186;//g;
        !           487: #    $result =~ s/&ordm;//g;
        !           488: #    $result =~ s/&#187;//g;
        !           489: #    $result =~ s/&raquo;//g;
        !           490: #    $result =~ s/&#188;//g;
        !           491: #    $result =~ s/&frac14;//g;
        !           492: #    $result =~ s/&#189;//g;
        !           493: #    $result =~ s/&frac12;//g;
        !           494: #    $result =~ s/&#190;//g;
        !           495: #    $result =~ s/&frac34;//g;
        !           496:     $result =~ s/&#191;/?`/g;
        !           497:     $result =~ s/&iquest;/?`/g; 
        !           498:     $result =~ s/&#192;/\\`{A}/g;
        !           499:     $result =~ s/&Agrave;/\\`{A}/g; 
        !           500:     $result =~ s/&#193;/\\'{A}/g; 
        !           501:     $result =~ s/&Aacute;/\\'{A}/g; 
        !           502:     $result =~ s/&#194;/\\^{A}/g;
        !           503:     $result =~ s/&Acirc;/\\^{A}/g;
        !           504:     $result =~ s/&#195;/\\~{A}/g;
        !           505:     $result =~ s/&Atilde;/\\~{A}/g;
        !           506:     $result =~ s/&#196;/\\"{A}/g; 
        !           507:     $result =~ s/&Auml;/\\"{A}/g; 
        !           508:     $result =~ s/&#197;/{\\AA}/g;
        !           509:     $result =~ s/&Aring;/{\\AA}/g;
        !           510:     $result =~ s/&#198;/{\\AE}/g;
        !           511:     $result =~ s/&AElig;/{\\AE}/g;
        !           512: #    $result =~ s/&#199;//g;
        !           513: #    $result =~ s/&Ccedil;//g;
        !           514:     $result =~ s/&#200;/\\`{E}/g;
        !           515:     $result =~ s/&Egrave;/\\`{E}/g;
        !           516:     $result =~ s/&#201;/\\'{E}/g;
        !           517:     $result =~ s/&Eacute;/\\'{E}/g;
        !           518:     $result =~ s/&#202;/\\^{E}/g;
        !           519:     $result =~ s/&Ecirc;/\\^{E}/g;
        !           520:     $result =~ s/&#203;/\\`{E}/g;
        !           521:     $result =~ s/&Euml;/\\`{E}/g;
        !           522:     $result =~ s/&#204;/\\`{I}/g;
        !           523:     $result =~ s/&Igrave;/\\`{I}/g; 
        !           524:     $result =~ s/&#205;/\\'{I}/g; 
        !           525:     $result =~ s/&Iacute;/\\'{I}/g; 
        !           526:     $result =~ s/&#206;/\\^{I}/g;
        !           527:     $result =~ s/&Icirc;/\\^{I}/g;
        !           528:     $result =~ s/&#207;/\\"{I}/g; 
        !           529:     $result =~ s/&Iuml;/\\"{I}/g; 
        !           530: #    $result =~ s/&#208;//g;
        !           531: #    $result =~ s/&ETH;//g;
        !           532:     $result =~ s/&#209;/\\~{N}/g;
        !           533:     $result =~ s/&Ntilde;/\\~{N}/g;
        !           534:     $result =~ s/&#210;/\\`{O}/g;
        !           535:     $result =~ s/&Ograve;/\\`{O}/g; 
        !           536:     $result =~ s/&#211;/\\'{O}/g;
        !           537:     $result =~ s/&Oacute;/\\'{O}/g; 
        !           538:     $result =~ s/&#212;/\\^{O}/g;
        !           539:     $result =~ s/&Ocirc;/\\^{O}/g;
        !           540:     $result =~ s/&#213;/\\~{O}/g;
        !           541:     $result =~ s/&Otilde;/\\~{O}/g;
        !           542:     $result =~ s/&#214;/\\"{O}/g;
        !           543:     $result =~ s/&Ouml;/\\"{O}/g; 
        !           544:     $result =~ s/&#215;/\$\\times\$/g;
        !           545:     $result =~ s/&times;/\$\\times\$/g;
        !           546:     $result =~ s/&#216;/{\\O}/g;
        !           547:     $result =~ s/&Oslash;/{\\O}/g;
        !           548:     $result =~ s/&#217;/\\`{U}/g;
        !           549:     $result =~ s/&Ugrave;/\\`{U}/g;
        !           550:     $result =~ s/&#218;/\\'{U}/g;
        !           551:     $result =~ s/&Uacute;/\\'{U}/g;
        !           552:     $result =~ s/&#219;/\\^{U}/g;
        !           553:     $result =~ s/&Ucirc;/\\^{U}/g;
        !           554:     $result =~ s/&#220;/\\"{U}/g;
        !           555:     $result =~ s/&Uuml;/\\"{U}/g;
        !           556:     $result =~ s/&#221;/\\'{Y}/g;
        !           557:     $result =~ s/&Yacute;/\\'{Y}/g;
        !           558: #    $result =~ s/&#222;//g;
        !           559: #    $result =~ s/&THORN;//g;
        !           560: #    $result =~ s/&#223;//g;
        !           561: #    $result =~ s/&szlig;//g;
        !           562:     $result =~ s/&#224;/\\`{a}/g;
        !           563:     $result =~ s/&agrave;/\\`{a}/g;
        !           564:     $result =~ s/&#225;/\\'{a}/g;
        !           565:     $result =~ s/&aacute;/\\'{a}/g;
        !           566:     $result =~ s/&#226;/\\^{a}/g;
        !           567:     $result =~ s/&acirc;/\\^{a}/g;
        !           568:     $result =~ s/&#227;/\\~{a}/g;
        !           569:     $result =~ s/&atilde;/\\~{a}/g;
        !           570:     $result =~ s/&#228;/\\"{a}/g;
        !           571:     $result =~ s/&auml;/\\"{a}/g;
        !           572:     $result =~ s/&#229;/{\\aa}/g;
        !           573:     $result =~ s/&aring;/{\\aa}/g;
        !           574:     $result =~ s/&#230;/{\\ae}/g;
        !           575:     $result =~ s/&aelig;/{\\ae}/g;
        !           576: #    $result =~ s/&#231;//g;
        !           577: #    $result =~ s/&ccedil;//g;
        !           578:     $result =~ s/&#232;/\\`{e}/g;
        !           579:     $result =~ s/&egrave;/\\`{e}/g;
        !           580:     $result =~ s/&#233;/\\'{e}/g;
        !           581:     $result =~ s/&eacute;/\\'{e}/g;
        !           582:     $result =~ s/&#234;/\\^{e}/g;
        !           583:     $result =~ s/&ecirc;/\\^{e}/g;
        !           584:     $result =~ s/&#235;/\\"{e}/g;
        !           585:     $result =~ s/&euml;/\\"{e}/g;
        !           586:     $result =~ s/&#236;/\\`{i}/g;
        !           587:     $result =~ s/&igrave;/\\`{i}/g;
        !           588:     $result =~ s/&#237;/\\'{i}/g;
        !           589:     $result =~ s/&iacute;/\\'{i}/g;
        !           590:     $result =~ s/&#238;/\\^{i}/g;
        !           591:     $result =~ s/&icirc;/\\^{i}/g;
        !           592:     $result =~ s/&#239;/\\"{i}/g;
        !           593:     $result =~ s/&iuml;/\\"{i}/g;
        !           594: #    $result =~ s/&#240;//g;
        !           595: #    $result =~ s/&eth;//g;
        !           596:     $result =~ s/&#241;/\\~{n}/g;
        !           597:     $result =~ s/&ntilde;/\\~{n}/g;
        !           598:     $result =~ s/&#242;/\\`{o}/g;
        !           599:     $result =~ s/&ograve;/\\`{o}/g;
        !           600:     $result =~ s/&#243;/\\'{o}/g;
        !           601:     $result =~ s/&oacute;/\\'{o}/g;
        !           602:     $result =~ s/&#244;/\\^{o}/g;
        !           603:     $result =~ s/&ocirc;/\\^{o}/g;
        !           604:     $result =~ s/&#245;/\\~{o}/g;
        !           605:     $result =~ s/&otilde;/\\~{o}/g;
        !           606:     $result =~ s/&#246;/\\"{o}/g;
        !           607:     $result =~ s/&ouml;/\\"{o}/g;
        !           608:     $result =~ s/&#247;/\$\\div\$/g;
        !           609:     $result =~ s/&divide;/\$\\div\$/g;
        !           610:     $result =~ s/&#248;/{\\o}/g;
        !           611:     $result =~ s/&oslash;/{\\o}/g;
        !           612:     $result =~ s/&#249;/\\`{u}/g; 
        !           613:     $result =~ s/&ugrave;/\\`{u}/g;
        !           614:     $result =~ s/&#250;/\\'{u}/g;
        !           615:     $result =~ s/&uacute;/\\'{u}/g;
        !           616:     $result =~ s/&#251;/\\^{u}/g;
        !           617:     $result =~ s/&ucirc;/\\^{u}/g;
        !           618:     $result =~ s/&#252;/\\"{u}/g;
        !           619:     $result =~ s/&uuml;/\\"{u}/g;
        !           620:     $result =~ s/&#253;/\\'{y}/g;
        !           621:     $result =~ s/&yacute;/\\'{y}/g;
        !           622: #    $result =~ s/&#254;//g;
        !           623: #    $result =~ s/&thorn;//g;
        !           624:     $result =~ s/&#255;/\\"{y}/g;
        !           625:     $result =~ s/&yuml;/\\"{y}/g;
        !           626:     return $result;
        !           627: }
        !           628: 
1.28      sakharuk  629: sub additional_cleanup {
                    630:     my $result = shift;	
                    631:     my $first_app = index($result,'\documentclass',0);
                    632:     $first_app = index($result,'\documentclass',$first_app+5);
                    633:     while ($first_app != -1) {
                    634: 	my $second_app = index($result,'begin{document}',$first_app);
                    635: 	$first_app = rindex($result,'\end{document}',$first_app);
                    636: 	substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';
                    637: 	$first_app = index($result,'\documentclass',$first_app+5);
                    638:     }
                    639:     return $result;
                    640: }
1.33      sakharuk  641: sub page_cleanup {
                    642:     my $result = shift;	
                    643:     $_ = $result;
                    644:     m/\\end{document}(\d*)$/;
1.34      sakharuk  645:     my $number_of_columns = $1;
1.33      sakharuk  646:     my $insert = '{';
1.34      sakharuk  647:     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33      sakharuk  648:     $insert .= '}';
1.34      sakharuk  649:     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;
                    650:     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
                    651:     $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;
1.35      sakharuk  652:     $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;
1.37    ! sakharuk  653:     $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;
1.34      sakharuk  654:     return $result,$number_of_columns;
1.33      sakharuk  655: }
1.6       sakharuk  656: 
1.3       sakharuk  657: sub content_map {
1.7       sakharuk  658: #-- find a list of files to print
1.3       sakharuk  659:     my $map_string = shift;
1.5       sakharuk  660:     my @number_seq = ();
1.7       sakharuk  661:     my @file_seq = ();
1.5       sakharuk  662:     my $startlink = index($map_string,'<link',0);
1.7       sakharuk  663:     my $endlink = index($map_string,'</link>',$startlink);
                    664:     my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    665:     $_ = $chunk;
                    666:     m/from=\"(\d+)\"/;
                    667:     push @number_seq,$1;
1.5       sakharuk  668:     while ($startlink != -1) {
1.7       sakharuk  669: 	$endlink = index($map_string,'</link>',$startlink);
                    670: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5       sakharuk  671: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    672: 	$_ = $chunk;
                    673:         m/to=\"(\d+)\"/;
                    674: 	push @number_seq,$1;
1.13      sakharuk  675: 	$startlink = index($map_string,'from="'.$1.'"',$startlink);
1.18      sakharuk  676: 	$startlink = rindex($map_string,'<link ',$startlink);
1.5       sakharuk  677:     }
1.7       sakharuk  678:     my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
                    679:     while ($stalink != -1) {
                    680: 	$startlink = rindex($map_string,'<link ',$stalink);
                    681: 	$endlink = index($map_string,'</link>',$startlink);
                    682: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    683: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    684: 	$_ = $chunk;
                    685:         m/from=\"(\d+)\"/;
                    686: 	unshift @number_seq,$1;
                    687: 	$stalink = index($map_string,' to="'.$number_seq[0].'"',0);
                    688:     }
                    689:     for (my $i=0;$i<=$#number_seq;$i++) {
                    690: 	$stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13      sakharuk  691:         {    
                    692: 	    my $ahed1 = index($map_string,'src="',$stalink);
                    693: 	    my $ahed2 = index($map_string,'</resource>',$stalink);
                    694: 	    if ($ahed1 != -1) {
                    695: 		if ($ahed1 < $ahed2) {
                    696: 		    $startlink = $ahed1;
                    697: 		} else {
                    698: 		    $startlink = rindex($map_string,'src="',$stalink);
                    699: 		}
                    700: 	    } else {
                    701: 		$startlink = rindex($map_string,'src="',$stalink);
                    702: 	    }
                    703: 
                    704: 	}
1.7       sakharuk  705: 	$startlink = index($map_string,'"',$startlink);
                    706: 	$endlink = index($map_string,'"',$startlink+1);
                    707: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+1);
                    708: 	push @file_seq,$chunk;
                    709:     }
                    710:     return @file_seq;
                    711: }
1.5       sakharuk  712: 
1.3       sakharuk  713: 
                    714: 
                    715: sub handler {
                    716: 
                    717:     my $r = shift;
                    718:     $r->content_type('text/html');
                    719:     $r->send_http_header;
                    720: 
                    721: #-- start form
                    722:     &headerform($r);
                    723: #-- menu for output
1.16      sakharuk  724:     unless  ($ENV{'form.phase'}) {
1.3       sakharuk  725: 	&menu_for_output($r);
                    726:     }
                    727: #-- core part 
                    728:     if ($ENV{'form.phase'} eq 'two') {
                    729: 	&output_data($r);
                    730:     }
1.2       sakharuk  731:     return OK;
                    732: 
1.1       www       733: } 
                    734: 
                    735: 1;
                    736: __END__
1.6       sakharuk  737: 
                    738: 
1.13      sakharuk  739: 
                    740: 
                    741: #### Test block
1.6       sakharuk  742: #    my $ere;
                    743: #    foreach $ere (%ENV) {
1.13      sakharuk  744: #	$result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6       sakharuk  745: #    }
1.13      sakharuk  746: ####

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>