File:  [LON-CAPA] / loncom / interface / lonprintout.pm
Revision 1.45: download - view: text, annotated - select for diffs
Fri Aug 2 18:08:12 2002 UTC (21 years, 10 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Can print subdirectories from the construction space. Changes were done to
restore work after Jason changed dirlist in lonnet.pm.

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

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