File:  [LON-CAPA] / loncom / interface / lonprintout.pm
Revision 1.38: download - view: text, annotated - select for diffs
Tue Jul 16 20:30:53 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #593
Added printout to construction space menu.

Printout handler gets complete URL, e.g.,

http://picard.lite.msu.edu/~korte/bar/foo.html

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

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