File:  [LON-CAPA] / loncom / homework / default_homework.lcpm
Revision 1.129: download - view: text, annotated - select for diffs
Wed Mar 5 18:24:07 2008 UTC (16 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
A unit has at least one non-digit character.

    1: # The LearningOnline Network with CAPA 
    2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
    3: #
    4: # $Id: default_homework.lcpm,v 1.129 2008/03/05 18:24:07 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: #
   29: 
   30: #init some globals
   31: $hidden::RANDOMINIT=0;
   32: $pi=atan2(1,1)*4;
   33: $rad2deg=180.0/$pi;
   34: $deg2rad=$pi/180.0;
   35: $"=' ';
   36: use strict;
   37: {
   38:     my $n = 0;
   39:     my $total = 0;
   40:     my $num_left = 0;
   41:     my @order;
   42:     my $type;
   43: 
   44:     sub init_permutation {
   45: 	my ($size,$requested_type) = @_;
   46: 	@order = (0..$size-1);
   47: 	$n = $size;
   48: 	$type = $requested_type;
   49: 	if ($type eq 'ordered') {
   50: 	    $total = $num_left = 1;
   51: 	} elsif ($type eq 'unordered') {
   52: 	    $total = $num_left = &factorial($size);
   53: 	} else {
   54: 	    die("Unkown type: $type");
   55: 	}
   56:     }
   57: 
   58:     sub get_next_permutation {
   59: 	if ($num_left == $total) {
   60: 	    $num_left--;
   61: 	    return \@order;
   62: 	}
   63: 
   64: 	# Find largest index j with a[j] < a[j+1]
   65: 
   66: 	my $j = scalar(@order) - 2;
   67: 	while ($order[$j] > $order[$j+1]) {
   68: 	    $j--;
   69: 	}
   70: 
   71: 	# Find index k such that a[k] is smallest integer
   72: 	# greater than a[j] to the right of a[j]
   73: 
   74: 	my $k = scalar(@order) - 1;
   75: 	while ($order[$j] > $order[$k]) {
   76: 	    $k--;
   77: 	}
   78: 
   79: 	# Interchange a[j] and a[k]
   80: 
   81: 	@order[($k,$j)] = @order[($j,$k)];
   82: 
   83: 	# Put tail end of permutation after jth position in increasing order
   84: 
   85: 	my $r = scalar(@order) - 1;
   86: 	my $s = $j + 1;
   87: 
   88: 	while ($r > $s) {
   89: 	    @order[($s,$r)]=@order[($r,$s)];
   90: 	    $r--;
   91: 	    $s++;
   92: 	}
   93: 
   94: 	$num_left--;
   95: 	return(\@order);
   96:     }
   97:     
   98:     sub get_permutations_left {
   99: 	return $num_left;
  100:     }
  101: }
  102: 
  103: sub check_commas {
  104:     my ($response)=@_;
  105:     #print("$response ");
  106:     my @numbers=split(',',$response);
  107:     #print(" numbers ".join('-',@numbers)." ");
  108:     if (scalar(@numbers) > 1) {
  109:         #print(" numbers[0] ".$numbers[0]." "); 
  110: 	if (length($numbers[0]) > 3 || length($numbers[0]) == 0) { return -1; }
  111: 	shift(@numbers);
  112: 	#print(" numbers ".scalar(@numbers)." ");
  113: 	while (scalar(@numbers) > 1) {
  114: 	    #print(" numbers ".join('-',@numbers)." ");
  115: 	    if (length($numbers[0]) != 3) { return -2; }
  116: 	    shift(@numbers);
  117: 	}
  118: 	my ($number)=split('\.',$numbers[0]);
  119: 	#print(" number ".$number." ");
  120: 	#print(" numbers[0] ".$numbers[0]." ");
  121: 	if (length($number) != 3) { return -3; }
  122:     } else {
  123: 	my ($number)=split('\.',$numbers[0]);
  124: 	if (length($number) > 3) { return -4; }
  125:     }
  126:     return 1;
  127: }
  128: 
  129: 
  130: sub caparesponse_check {
  131:     my ($answer,$response)=@_;
  132:     #not properly used yet: calc
  133:     #not to be used: $ans_fmt
  134:     my $type=$LONCAPA::CAPAresponse_args{'type'};
  135:     my $tol=$LONCAPA::CAPAresponse_args{'tol'};
  136:     my $sig=$LONCAPA::CAPAresponse_args{'sig'};
  137:     my $ans_fmt=$LONCAPA::CAPAresponse_args{'format'};
  138:     my $unit=$LONCAPA::CAPAresponse_args{'unit'};
  139:     my $calc=$LONCAPA::CAPAresponse_args{'calc'};
  140:     my $samples=$LONCAPA::CAPAresponse_args{'samples'};
  141:     
  142:     my $tol_type=''; # gets it's value from whether tol has a % or not done
  143:     my $sig_lbound=''; #done
  144:     my $sig_ubound=''; #done
  145: 
  146: 
  147:     #type's definitons come from capaParser.h
  148: 
  149:     #remove leading and trailing whitespace
  150:     if (!defined($response)) {
  151: 	$response='';
  152:     }
  153:     if ($response=~ /^\s|\s$/) {
  154: 	$response=~ s:^\s+|\s+$::g;
  155: 	&LONCAPA_INTERNAL_DEBUG("Removed ws now :$response:");
  156:     }
  157: 
  158:     #&LONCAPA_INTERNAL_DEBUG(" type is $type ");
  159:     if ($type eq 'cs' || $type eq 'ci') {
  160: 	#for string answers make surec all places spaces occur, there is 
  161:         #really only 1 space, in both the answer and the response
  162: 	$answer=~s/ +/ /g;
  163: 	$response=~s/ +/ /g;
  164:     } elsif ($type eq 'mc') {
  165: 	$answer=~s/[\s,]//g;
  166: 	$response=~s/[\s,]//g;
  167:     }
  168:     if ($type eq 'float' && $unit=~/\$/) {
  169: 	if ($response!~/^\$|\$$/)  { return ('NO_UNIT', undef); }
  170: 	$response=~s/\$//g;
  171:     }
  172:     if ($type eq 'float' && $unit=~/\,/ && (&check_commas($response)<0)) {
  173: 	return "COMMA_FAIL:";
  174:     }
  175:     $ans_fmt=~s/\W//g;
  176:     $unit=~s/[\$,]//g;
  177:     if ($type eq 'float') { $response=~s/,//g; }
  178: 
  179:     if (length($response) > 500) { return ('TOO_LONG',undef); }
  180: 
  181:     if ($type eq '' ) {
  182: 	&LONCAPA_INTERNAL_DEBUG("Didn't find a type :$type: defaulting");
  183: 	if ( $answer eq ($answer *1.0)) { $type = 2;
  184: 				      } else { $type = 3; }
  185:     } else {
  186: 	if    ($type eq 'cs')    { $type = 4; }
  187: 	elsif ($type eq 'ci')    { $type = 3 }
  188: 	elsif ($type eq 'mc')    { $type = 5; }
  189: 	elsif ($type eq 'fml')   { $type = 8; }
  190:         elsif ($type eq 'math')  { $type = 9; }
  191: 	elsif ($type eq 'subj')  { $type = 7; }
  192: 	elsif ($type eq 'float') { $type = 2; }
  193: 	elsif ($type eq 'int')   { $type = 1; }
  194: 	else { return ('ERROR', "Unknown type of answer: $type") }
  195:     }
  196: 
  197:     my $points;
  198:     my $id_list;
  199:     #formula type setup the sample points
  200:     if ($type eq '8') {
  201: 	($id_list,$points)=split(/@/,$samples);
  202: 	&LONCAPA_INTERNAL_DEBUG("Found :$id_list:$points: points in $samples");
  203:     }
  204:     if ($tol eq '') {
  205: 	$tol=0.0;
  206: 	$tol_type=1; #TOL_ABSOLUTE
  207:     } else {
  208: 	if ($tol =~ /%$/) {
  209: 	    chop $tol;
  210: 	    $tol_type=2; #TOL_PERCENTAGE
  211: 	} else {
  212: 	    $tol_type=1; #TOL_ABSOLUTE
  213: 	}
  214:     }
  215: 
  216:     ($sig_ubound,$sig_lbound)=&LONCAPA_INTERNAL_get_sigrange($sig);
  217: 
  218:     my $reterror="";
  219:     my $result;
  220:     if ((($type eq '9') || ($type eq '8')) && ($response=~/\=/)) { return ('BAD_FORMULA','Please submit just an expression, not an equation.'); }
  221:     if ($type eq '9') {
  222:       $result = &maxima_check(&maxima_cas_formula_fix($response),&maxima_cas_formula_fix($answer),\$reterror);
  223:     } else {
  224: 	if ($type eq '8') { # fml type
  225: 	    $response = &capa_formula_fix($response);
  226: 	    $answer   = &capa_formula_fix($answer);
  227: 	}
  228:        $result = &caparesponse_capa_check_answer($response,$answer,$type,
  229: 						 $tol_type,$tol,
  230: 						 $sig_lbound,$sig_ubound,
  231: 						 $ans_fmt,$unit,$calc,$id_list,
  232: 						 $points,$external::randomseed,
  233: 						 \$reterror);
  234:     }
  235:     if    ($result == '1') { $result='EXACT_ANS'; } 
  236:     elsif ($result == '2') { $result='APPROX_ANS'; }
  237:     elsif ($result == '3') { $result='SIG_FAIL'; }
  238:     elsif ($result == '4') { $result='UNIT_FAIL'; }
  239:     elsif ($result == '5') { $result='NO_UNIT'; }
  240:     elsif ($result == '6') { $result='UNIT_OK'; }
  241:     elsif ($result == '7') { $result='INCORRECT'; }
  242:     elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
  243:     elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
  244:     elsif ($result =='10') { $result='SUB_RECORDED'; }
  245:     elsif ($result =='11') { $result='BAD_FORMULA'; }
  246:     elsif ($result =='12' && !$response) { $result='MISSING_ANSWER'; }
  247:     elsif ($result =='12') { $result='WANTED_NUMERIC'; }
  248:     elsif ($result =='13') { $result='UNIT_INVALID_INSTRUCTOR'; }
  249:     elsif ($result =='141') { $result='UNIT_INVALID_STUDENT'; }
  250:     elsif ($result =='142') { $result='UNIT_INVALID_STUDENT'; }
  251:     elsif ($result =='143') { $result='UNIT_INVALID_STUDENT'; }
  252:     elsif ($result =='15') { $result='UNIT_IRRECONCIBLE'; }
  253:     else  {$result = "ERROR: Unknown Result:$result:$@:";}
  254: 
  255:     &LONCAPA_INTERNAL_DEBUG("RetError $reterror: Answer $answer: Response $response:  type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|");
  256:     &LONCAPA_INTERNAL_DEBUG(" $answer $response $result ");
  257:     return ($result,$reterror)
  258: }
  259: 
  260: 
  261: sub caparesponse_check_list {
  262:     my $responses=$LONCAPA::CAPAresponse_args{'response'};
  263: #    &LONCAPA_INTERNAL_DEBUG(" answer is ".
  264: #			    &LONCAPA_INTERNAL_Dumper($LONCAPA::CAPAresponse_answer).":\n");
  265: #    &LONCAPA_INTERNAL_DEBUG(" respons is ".
  266: #			    &LONCAPA_INTERNAL_Dumper($responses).":\n");
  267:     &LONCAPA_INTERNAL_DEBUG("args ".join(':',%LONCAPA::CAPAresponse_args));
  268:     my $type = $LONCAPA::CAPAresponse_args{'type'};
  269:     &LONCAPA_INTERNAL_DEBUG("Got type :$type:\n");
  270:     
  271:     my $num_input_lines =
  272: 	scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}});
  273:     
  274:     if ($type ne '' ) {
  275: 	if (scalar(@$responses) < $num_input_lines) {
  276: 	    return 'MISSING_ANSWER';
  277: 	}
  278: 	if (scalar(@$responses) > $num_input_lines) {
  279: 	    return 'EXTRA_ANSWER';
  280: 	}
  281: 
  282:     }
  283: 
  284:     foreach my $which (0..($num_input_lines-1)) {
  285: 	my $answer_size = 
  286: 	    scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}[$which]});
  287: 	if ($type ne '' 
  288: 	    && $answer_size > 1) {
  289: 	    $responses->[$which]=[split(/,/,$responses->[$which])];
  290: 	} else {
  291: 	    $responses->[$which]=[$responses->[$which]];
  292: 	}
  293:     }
  294: #    &LONCAPA_INTERNAL_DEBUG(" parsed response is ".
  295: #			    &LONCAPA_INTERNAL_Dumper($responses).":\n");
  296:     foreach my $which (0..($num_input_lines-1)) {
  297: 	my $answer_size = 
  298: 	    scalar(@{$LONCAPA::CAPAresponse_answer->{'answers'}[$which]});
  299: 	my $response_size = 
  300: 	    scalar(@{$responses->[$which]});
  301: 	if ($answer_size > $response_size) {
  302: 	    return 'MISSING_ANSWER';
  303: 	}
  304: 	if ($answer_size < $response_size) {
  305: 	    return 'EXTRA_ANSWER';
  306: 	}
  307:     }
  308: 
  309:     &LONCAPA_INTERNAL_DEBUG("Initial final response :$responses->[0][-1]:");
  310:     my $unit;
  311:     if ($type eq '' || $type eq 'float') {
  312: 	#for numerical problems split off the unit
  313: #	if ( $responses->[0][-1]=~ /(.*[^\s])\s+([^\s]+)/ ) {
  314:         if ( $responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d)([\w\s][\$\s\w\^\*\/\(\)\+\-]*\D[\$\s\w\^\*\/\(\)\+\-]*)$/ ) {
  315: 	    $responses->[0][-1]=$1;
  316: 	    $unit=&capa_formula_fix($2);
  317:             &LONCAPA_INTERNAL_DEBUG("Found unit :$unit:");
  318: 	}
  319:     }
  320:     &LONCAPA_INTERNAL_DEBUG("Final final response :$responses->[0][-1]:$unit:");
  321:     $unit=~s/\s//;
  322:     if ($unit ne '') {
  323: 	foreach my $response (@$responses) {
  324: 	    foreach my $element (@$response) {	
  325:                 $element =~ s/\s//g;    
  326: 		$element .= " $unit";
  327: 	    }
  328: 	}
  329:     }
  330:     
  331:     foreach my $thisanswer (@{ $LONCAPA::CAPAresponse_answer->{'answers'} }) {
  332: 	if (!defined($thisanswer)) {
  333: 	    return ('ERROR','answer was undefined');
  334: 	}
  335:     }
  336: 
  337: 
  338: #    &LONCAPA_INTERNAL_DEBUG(&LONCAPA_INTERNAL_Dumper($responses));
  339:     my %memoized;
  340:     if ($LONCAPA::CAPAresponse_answer->{'type'}  eq 'ordered') {
  341: 	for (my $i=0; $i<scalar(@$responses);$i++) {
  342: 	    my $answer   = $LONCAPA::CAPAresponse_answer->{'answers'}[$i];
  343: 	    my $response = $responses->[$i];
  344: 	    my $key = "$answer\0$response";
  345: 	    my (@awards,@msgs);
  346: 	    for (my $j=0; $j<scalar(@$response); $j++) { 
  347: 		my ($award,$msg) = &caparesponse_check($answer->[$j],
  348: 						       $response->[$j]);
  349: 		push(@awards,$award);
  350: 		push(@msgs,  $msg);
  351: 	    }
  352: 	    my ($award,$msg) = 
  353: 		&LONCAPA_INTERNAL_FINALIZEAWARDS(\@awards,\@msgs);
  354: 	    $memoized{$key} = [$award,$msg];
  355: 	}
  356:     } else {
  357: 	#FIXME broken with unorder responses where one is a <value>
  358:         #      and the other is a <vector> (need to delay parse til
  359:         #      inside the loop?)
  360: 	foreach my $response (@$responses) {
  361: 	    my $response_size = scalar(@{$response});
  362: 	    foreach my $answer (@{ $LONCAPA::CAPAresponse_answer->{'answers'} }) {
  363: 		my $key = "$answer\0$response";
  364: 		my $answer_size =  scalar(@{$answer});
  365: 		my ($award,$msg);
  366: 		if ($answer_size > $response_size) {
  367: 		    $award = 'MISSING_ANSWER';
  368: 		} elsif ($answer_size < $response_size) {
  369: 		    $award = 'EXTRA_ANSWER';
  370: 		} else {
  371: 		    my (@awards,@msgs);
  372: 		    for (my $j=0; $j<scalar(@$response); $j++) {
  373: 			my ($award,$msg) = &caparesponse_check($answer->[$j],
  374: 							       $response->[$j]);
  375: 			push(@awards,$award);
  376: 			push(@msgs,  $msg);
  377: 		    }
  378: 		    ($award,$msg) = 
  379: 			&LONCAPA_INTERNAL_FINALIZEAWARDS(\@awards,\@msgs);
  380: 		}
  381: 		$memoized{$key} = [$award,$msg];
  382: 	    }
  383: 	}
  384:     }
  385: 
  386:     my ($final_award,$final_msg);
  387:     &init_permutation(scalar(@$responses),
  388: 		      $LONCAPA::CAPAresponse_answer->{'type'});
  389: 
  390:     # possible FIXMEs
  391:     # - significant time is spent calling non-safe space routine
  392:     #   from safe space
  393:     # - early outs could be possible with classifying awards is to stratas
  394:     #   and stopping as so as hitting the top strata 
  395:     # - some early outs also might be possible with check ing the 
  396:     #   memoized hash of results (is correct even possible? etc.)
  397: 
  398:     my (@final_awards,@final_msg);
  399:     while( &get_permutations_left() ) {
  400: 	my $order = &get_next_permutation();
  401: 	my (@awards, @msgs, $i);
  402: 	foreach my $thisanswer (@{ $LONCAPA::CAPAresponse_answer->{'answers'} }) {
  403: 	    my $key = "$thisanswer\0".$responses->[$order->[$i]];
  404: 	    push(@awards,$memoized{$key}[0]);
  405: 	    push(@msgs,$memoized{$key}[1]);
  406: 	    $i++;
  407: 
  408: 	}
  409: 	&LONCAPA_INTERNAL_DEBUG(" all awards ".join(':',@awards));
  410: 
  411: 	my ($possible_award,$possible_msg) = 
  412: 	    &LONCAPA_INTERNAL_FINALIZEAWARDS(\@awards,\@msgs);
  413: 	&LONCAPA_INTERNAL_DEBUG(" pos awards ".$possible_award);
  414: 	push(@final_awards,$possible_award);
  415: 	push(@final_msg,$possible_msg);
  416:     }
  417: 
  418:     &LONCAPA_INTERNAL_DEBUG(" all final_awards ".join(':',@final_awards));
  419:     my ($final_award,$final_msg) = 
  420: 	&LONCAPA_INTERNAL_FINALIZEAWARDS(\@final_awards,\@final_msg,undef,1);
  421:     return ($final_award,$final_msg);
  422: }
  423: 
  424: sub cas {
  425:     my ($system,$input)=@_;
  426:     my $output;
  427:     if ($system eq 'maxima') {
  428:        $output=&maxima_eval($input);
  429:     }
  430:     return $output;
  431: }
  432: 
  433: sub tex {
  434:     if ( $external::target eq "tex" ) {
  435: 	return $_[0];
  436:     } else {
  437: 	return $_[1];
  438:     }
  439: }
  440: 
  441: sub var_in_tex {
  442:     if ( $external::target eq "tex" ) {
  443: 	return $_[0];
  444:     } else {
  445: 	return "";
  446:     }
  447: }
  448: 
  449: sub web {
  450:     if ( $external::target eq "tex" ) {
  451: 	return $_[1];
  452:     } else {
  453: 	if ( $external::target eq "web" || $external::target eq "answer") {
  454: 	    return $_[2];
  455: 	} else {
  456: 	    return $_[0];
  457: 	}
  458:     }
  459: }
  460: 
  461: sub html {
  462:     if ( $external::target eq "web" ) {
  463: 	return shift;
  464:     }
  465: }
  466: 
  467: sub hinton {
  468:     return 0;
  469: }
  470: 
  471: sub random {
  472:     my ($start,$end,$step)=@_;
  473:     if ( ! $hidden::RANDOMINIT ) {
  474: 	if ($external::randomseed == 0) { $external::randomseed=1; }
  475: 	if ($external::randomseed =~/,/) {
  476: 	    my ($num1,$num2)=split(/,/,$external::randomseed);
  477: 	    &random_set_seed(1,abs($num1));
  478: 	} elsif ($external::randomseed =~/:/) {
  479: 	    my ($num1,$num2)=split(/:/,$external::randomseed);
  480: 	    &random_set_seed(abs($num1),abs($num2));
  481: 	} else {
  482: 	    &random_set_seed(1,int(abs($external::randomseed)));
  483: 	}
  484: 	&math_random_uniform();
  485: 	$hidden::RANDOMINIT=1;
  486:     }
  487:     if (!defined($step)) { $step=1; }
  488:     my $num=1+int(($end-$start)/$step);
  489:     my $result=$start + int(&math_random_uniform() * $num)*$step;
  490:     return $result;
  491: }
  492: 
  493: sub random_normal {
  494:     my ($item_cnt,$seed,$av,$std_dev) = @_;
  495:     my @oldseed=&random_get_seed();
  496:     my @retArray;
  497:     &random_set_seed_from_phrase($seed);
  498:     @retArray=&math_random_normal($item_cnt,$av,$std_dev);
  499:     &random_set_seed(@oldseed);
  500:     return @retArray;
  501: }
  502: 
  503: sub random_beta {
  504:     my ($item_cnt,$seed,$aa,$bb) = @_;
  505:     my @oldseed=&random_get_seed();
  506:     my @retArray;
  507:     &random_set_seed_from_phrase($seed);
  508:     @retArray=&math_random_beta($item_cnt,$aa,$bb);
  509:     &random_set_seed(@oldseed);
  510:     return @retArray;
  511: }
  512: 
  513: sub random_gamma {
  514:     my ($item_cnt,$seed,$a,$r) = @_;
  515:     my @oldseed=&random_get_seed();
  516:     my @retArray;
  517:     &random_set_seed_from_phrase($seed);
  518:     @retArray=&math_random_gamma($item_cnt,$a,$r);
  519:     &random_set_seed(@oldseed);
  520:     return @retArray;
  521: }
  522: 
  523: sub random_exponential {
  524:     my ($item_cnt,$seed,$av) = @_;
  525:     my @oldseed=&random_get_seed();
  526:     my @retArray;
  527:     &random_set_seed_from_phrase($seed);
  528:     @retArray=&math_random_exponential($item_cnt,$av);
  529:     &random_set_seed(@oldseed);
  530:     return @retArray;
  531: }
  532: 
  533: sub random_poisson {
  534:     my ($item_cnt,$seed,$mu) = @_;
  535:     my @oldseed=&random_get_seed();
  536:     my @retArray;
  537:     &random_set_seed_from_phrase($seed);
  538:     @retArray=&math_random_poisson($item_cnt,$mu);
  539:     &random_set_seed(@oldseed);
  540:     return @retArray;
  541: }
  542: 
  543: sub random_chi {
  544:     my ($item_cnt,$seed,$df) = @_;
  545:     my @oldseed=&random_get_seed();
  546:     my @retArray;
  547:     &random_set_seed_from_phrase($seed);
  548:     @retArray=&math_random_chi_square($item_cnt,$df);
  549:     &random_set_seed(@oldseed);
  550:     return @retArray;
  551: }
  552: 
  553: sub random_noncentral_chi {
  554:     my ($item_cnt,$seed,$df,$nonc) = @_;
  555:     my @oldseed=&random_get_seed();
  556:     my @retArray;
  557:     &random_set_seed_from_phrase($seed);
  558:     @retArray=&math_random_noncentral_chi_square($item_cnt,$df,$nonc);
  559:     &random_set_seed(@oldseed);
  560:     return @retArray;
  561: }
  562: 
  563: sub random_f {
  564:     my ($item_cnt,$seed,$dfn,$dfd) = @_;
  565:     my @oldseed=&random_get_seed();
  566:     my @retArray;
  567:     &random_set_seed_from_phrase($seed);
  568:     @retArray=&math_random_f($item_cnt,$dfn,$dfd);
  569:     &random_set_seed(@oldseed);
  570:     return @retArray;
  571: }
  572: 
  573: sub random_noncentral_f {
  574:     my ($item_cnt,$seed,$dfn,$dfd,$nonc) = @_;
  575:     my @oldseed=&random_get_seed();
  576:     my @retArray;
  577:     &random_set_seed_from_phrase($seed);
  578:     @retArray=&math_random_noncentral_f($item_cnt,$dfn,$dfd,$nonc);
  579:     &random_set_seed(@oldseed);
  580:     return @retArray;
  581: }
  582: 
  583: sub random_multivariate_normal {
  584:     my ($item_cnt,$seed,$mean,$covar) = @_;
  585:     my @oldseed=&random_get_seed();
  586:     &random_set_seed_from_phrase($seed);
  587:     my @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
  588:     &random_set_seed(@oldseed);
  589:     return @retArray;
  590: }
  591: 
  592: sub random_multinomial {
  593:     my ($item_cnt,$seed,@p) = @_;
  594:     my @oldseed=&random_get_seed();
  595:     my @retArray;
  596:     &random_set_seed_from_phrase($seed);
  597:     my @retArray=&math_random_multinomial($item_cnt,@p);
  598:     &random_set_seed(@oldseed);
  599:     return @retArray;
  600: }
  601: 
  602: sub random_permutation {
  603:     my ($seed,@inArray) = @_;
  604:     my @oldseed=&random_get_seed();
  605:     my @retArray;
  606:     &random_set_seed_from_phrase($seed);
  607:     @retArray=&math_random_permutation(@inArray);
  608:     &random_set_seed(@oldseed);
  609:     return @retArray;
  610: }
  611: 
  612: sub random_uniform {
  613:     my ($item_cnt,$seed,$low,$high) = @_;
  614:     my @oldseed=&random_get_seed();
  615:     my @retArray;
  616:     &random_set_seed_from_phrase($seed);
  617:     @retArray=&math_random_uniform($item_cnt,$low,$high);
  618:     &random_set_seed(@oldseed);
  619:     return @retArray;
  620: }
  621: 
  622: sub random_uniform_integer {
  623:     my ($item_cnt,$seed,$low,$high) = @_;
  624:     my @oldseed=&random_get_seed();
  625:     my @retArray;
  626:     &random_set_seed_from_phrase($seed);
  627:     @retArray=&math_random_uniform_integer($item_cnt,$low,$high);
  628:     &random_set_seed(@oldseed);
  629:     return @retArray;
  630: }
  631: 
  632: sub random_binomial {
  633:     my ($item_cnt,$seed,$nt,$p) = @_;
  634:     my @oldseed=&random_get_seed();
  635:     my @retArray;
  636:     &random_set_seed_from_phrase($seed);
  637:     @retArray=&math_random_binomial($item_cnt,$nt,$p);
  638:     &random_set_seed(@oldseed);
  639:     return @retArray;
  640: }
  641: 
  642: sub random_negative_binomial {
  643:     my ($item_cnt,$seed,$ne,$p) = @_;
  644:     my @oldseed=&random_get_seed();
  645:     my @retArray;
  646:     &random_set_seed_from_phrase($seed);
  647:     @retArray=&math_random_negative_binomial($item_cnt,$ne,$p);
  648:     &random_set_seed(@oldseed);
  649:     return @retArray;
  650: }
  651: 
  652: sub abs { CORE::abs(shift) }
  653: sub sin { CORE::sin(shift) }
  654: sub cos { CORE::cos(shift) }
  655: sub exp { CORE::exp(shift) }
  656: sub int { CORE::int(shift) }
  657: sub log { CORE::log(shift) }
  658: sub atan2 { CORE::atan2($_[0],$_[1]) }
  659: sub sqrt { CORE::sqrt(shift) }
  660: 
  661: sub tan  { CORE::sin($_[0]) / CORE::cos($_[0]) }
  662: #sub atan { atan2($_[0], 1); }
  663: #sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
  664: #sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) );  }
  665: 
  666: sub log10 { CORE::log($_[0])/CORE::log(10); }
  667: 
  668: sub factorial {
  669:     my $input = CORE::int(shift);
  670:     return "Error - unable to take factorial of an negative number ($input)" if $input < 0;
  671:     return "Error - factorial result is greater than system limit ($input)" if $input > 170;
  672:     return 1 if $input == 0;
  673:     my $result = 1; 
  674:     for (my $i=2; $i<=$input; $i++) { $result *= $i }
  675:     return $result;
  676: }
  677: 
  678: sub sgn {
  679:     return -1 if $_[0] < 0;
  680:     return 0 if $_[0] == 0;
  681:     return 1 if $_[0] > 0;
  682: }
  683: 
  684: sub min {
  685:     my @sorted = sort { $a <=> $b || $a cmp $b } @_;
  686:     return shift @sorted;
  687: }
  688: 
  689: sub max {
  690:     my @sorted = sort { $a <=> $b || $a cmp $b } @_;
  691:     return pop @sorted;
  692: }
  693: 
  694: sub roundto {
  695:     my ($input,$n) = @_;
  696:     return sprintf('%.'.$n.'f',$input);
  697: }
  698: 
  699: sub to_string {
  700:     my ($input,$n) = @_;
  701:     return sprintf($input) if $n eq "";
  702:     $n = '.'.$n if $n !~ /^\./;
  703:     return sprintf('%'.$n,$input) if $n ne "";
  704: }
  705: 
  706: sub sub_string {
  707:     my ($str,$start,$len) = @_;
  708:     return substr($str,$start-1,$len);
  709: }
  710: 
  711: sub pow   {return $_[0] ** $_[1]; }
  712: sub ceil  {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? (CORE::int($_[0])+ 1) : CORE::int($_[0])); }
  713: sub floor  {return (($_[0]-CORE::int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? CORE::int($_[0]) : (CORE::int($_[0])-1)); }
  714: #sub floor {return int($_[0]); }
  715: 
  716: sub format {
  717:     my ($value,$fmt)=@_;
  718:     my ($dollarmode,$commamode,$alwaysperiod,$options);
  719:     if ($fmt =~ /^([^\d]*)(.*)/) { $options=$1; $fmt=$2; } 
  720:     #if ($options =~ /\$/) { $dollamode=1; }
  721:     #if ($options =~ /,/)  { $commamode=1; }
  722:     if ($options =~ /\./) { $alwaysperiod=1; }
  723:     my $result;
  724:     if ($fmt=~/s$/i) {
  725: 	$result=&format_significant_figures($value,$fmt);
  726:     } else {
  727: 	$fmt=~s/e/E/g;
  728: 	$result=sprintf('%.'.$fmt,$value);
  729: 	if ($alwaysperiod && $fmt eq '0f') { $result .='.'; }
  730: 	$result=~s/(E[+-]*)0/$1/;
  731:     }
  732:     #if ($dollarmode) {$result=&dollarformat($result);}
  733:     #if ($commamode) {$result=&commaformat($result);}
  734:     return $result;
  735: }
  736: 
  737: sub chemparse {
  738:     my ($reaction) = @_;
  739:     my @tokens = split(/(\s\+|\->|<=>|<\-|\.)/,$reaction);
  740:     my $formula = '';
  741:     foreach my $token (@tokens) {
  742: 	if ($token eq '->' ) {
  743: 	    $formula .= '<m>\ensuremath{\rightarrow}</m> ';
  744: 	    next;
  745: 	}
  746: 	if ($token eq '<-' ) {
  747: 	    $formula .= '<m>\ensuremath{\leftarrow}</m> ';
  748: 	    next;
  749: 	}  
  750: 	if ($token eq '<=>') {
  751: 	    if ($external::target eq 'web' &&
  752: 		&EXT('request.browser.unicode')) {
  753: 		$formula .= '&#8652; ';
  754: 	    } else {
  755: 		$formula .= &web('<=> ','<m>\ensuremath{\rightleftharpoons}</m> ',
  756: 				 '&lt;=&gt; ');
  757: 	    }
  758: 	    next;
  759: 	}
  760: 	if ($token eq '.') {
  761: 	  $formula =~ s/(\&nbsp\;| )$//;
  762: 	  $formula .= '&middot;';
  763: 	  next;
  764: 	}
  765: 	$token =~ /^\s*([\d|\/]*(?:&frac\d\d)?)(.*)/;
  766:         $formula .= $1 if ($1 ne '1');  # stoichiometric coefficient
  767: 	
  768: 	my $molecule = $2;
  769: 	# subscripts
  770: 	$molecule =~ s|(?<=[a-zA-Z\)\]\s])(\d+)|<sub>$1</sub>|g;
  771: 	# superscripts
  772: 	$molecule =~ s|\^(\d*[+\-]*)|<sup>$1</sup>|g;
  773: 	# strip whitespace
  774: 	$molecule =~ s/\s*//g;
  775: 	# forced space
  776: 	$molecule =~ s/_/ /g;
  777: 	$molecule =~ s/-/&minus;/g;
  778: 	$formula .= $molecule.'&nbsp;';
  779:     }
  780:     # get rid of trailing space
  781:     $formula =~ s/(\&nbsp\;| )$//;
  782:     return &xmlparse($formula);
  783: }
  784: 
  785: sub prettyprint {
  786:     my ($value,$fmt,$target)=@_;
  787:     my $result;
  788:     if (!$target) { $target = $external::target; }
  789:     if ($fmt =~ /chem/i) { return(&chemparse($value)); }
  790:     my ($dollarmode,$commamode,$alwaysperiod,$options);
  791:     if ($fmt =~ /^([^\d]*)(.*)/) { $options=$1; $fmt=$2; } 
  792:     if ($options =~ /\$/) { $dollarmode=1; }
  793:     if ($options =~ /,/)  { $commamode=1; }
  794:     if ($options =~ /\./) { $alwaysperiod=1; }
  795:     if ($fmt=~/s$/i) {
  796: 	$value=&format_significant_figures($value,$fmt);
  797:     } elsif ($fmt) {
  798: 	$value=sprintf('%.'.$fmt,$value);
  799:     }
  800:     if ($alwaysperiod && $fmt eq '0f') {
  801: 	if ($target eq 'tex') {
  802: 	    $value .='\\ensuremath{.}';
  803: 	} else {
  804: 	    $value .='.';
  805: 	}
  806:     }
  807:     if ($value =~ /([0-9\.\-\+]+)E([0-9\-\+]+)/i ) {
  808: 	my $frac=$1;
  809: 	if ($dollarmode) { $frac=&dollarformat($frac); }
  810: 	if ($commamode) { $frac=&commaformat($frac); }
  811: 	my $exponent=$2;
  812: 	$exponent=~s/^\+0*//;
  813: 	$exponent=~s/^-0*/-/;
  814: 	$exponent=~s/^-0*/-/;
  815: 	if ($exponent eq '-') { undef($exponent); }
  816: 	if ($exponent) {
  817: 	    if ($target eq 'web') {
  818: 		$result=$frac.'&#215;10<sup>'.$exponent.'</sup>';
  819: 	    } elsif ($target eq 'tex') {
  820: 		$result='\ensuremath{'.$frac.'\times 10^{'.$exponent.'}}';
  821: 	    } else {
  822: 		$result=$value;
  823: 	    }
  824: 	} else {
  825: 	    $result=$frac;
  826: 	}
  827:     } else {
  828: 	$result=$value;
  829: 	if    ($dollarmode) { $result=&dollarformat($result,$target); }
  830: 	elsif ($commamode)  { $result=&commaformat($result,$target); }
  831:     }
  832:     return $result;
  833: }
  834: 
  835: sub commaformat {
  836:     my ($number,$target) = @_;
  837:     if ($number =~ /\./) {
  838: 	while ($number =~ /([^0-9]*)([0-9]+)([^\.,][^\.,][^\.,])([,0-9]*\.[0-9]*)$/) {
  839: 	    $number = $1.$2.','.$3.$4;
  840: 	}
  841:     } else {
  842: 	while ($number =~ /^([^0-9]*)([0-9]+)([^,][^,][^,])([,0-9]*)$/) {
  843: 	    $number = $1.$2.','.$3.$4;
  844: 	}
  845:     }
  846:     return $number;
  847: }
  848: 
  849: sub dollarformat {
  850:     my ($number,$target) = @_;
  851:     if (!$target) { $target = $external::target; }
  852:     $number=&commaformat($number,$target);
  853:     if ($target eq 'tex') {
  854: 	$number='\$'.$number; #' stupid emacs
  855:     } else {
  856: 	$number='$'.$number; #' stupid emacs
  857:     }
  858:     return $number; 
  859: }
  860: 
  861: # format of form ns or nS where n is an integer
  862: sub format_significant_figures {
  863:     my ($number,$format) = @_; 
  864:     return '0' if ($number == 0);
  865:     # extract number of significant figures needed
  866:     my ($sig) = ($format =~ /(\d+)s/i);
  867:     # arbitrary choice - suggestions ?? or throw error message?
  868:     $sig = 3 if ($sig eq '');
  869:     # save the minus sign
  870:     my $sign = ($number < 0) ? '-' : '';
  871:     $number = abs($number);
  872:     # needed to correct for a number greater than 1 (or
  873:     my $power = ($number < 1) ? 0 : 1;
  874:     # could round up. Take the integer part of log10.
  875:     my $x10 = int(log($number)/log(10));
  876:     # find number with values left of decimal pt = # of sign figs.
  877:     my $xsig = $number*10**($sig-$x10-$power);
  878:     # get just digits left of decimal pt - also rounds off correctly
  879:     my $xint  = sprintf('%.0f',$xsig);
  880:     # save any trailing zero's
  881:     my ($zeros) = ($xint =~ /(0+)$/);
  882:     # return number to original magnitude
  883:     my $numSig = $xint*10**($x10-$sig+$power);
  884:     # insert trailing zero's if have decimal point
  885:     $numSig =~ s/^(\d+)\.(\d+)(\e?(.*)?)$/$1\.$2$zeros$3/;
  886:     # put a decimal pt for number ending with 0 and length = # of sig fig
  887:     $numSig.='.' if (length($numSig) == $sig && $numSig =~ /0$/);
  888:     if (length($numSig) < $sig) {
  889: 	$numSig.='.'.substr($zeros,0,($sig-length($numSig)));
  890:     }
  891:     # return number with sign
  892:     return $sign.$numSig;
  893: 
  894: }
  895: 
  896: sub map {
  897:     my ($phrase,$dest,$source)=@_;
  898:     my @oldseed=&random_get_seed();
  899:     my @seed = &random_seed_from_phrase($phrase);
  900:     &random_set_seed(@seed);
  901:     my $destct = scalar(@$dest);
  902:     if (!$source) {
  903: 	my @output;
  904: 	my @idx = &math_random_permuted_index($destct);
  905: 	my $ctr = 0;
  906: 	while ($ctr < $destct) {
  907: 	    $output[$ctr] = $$dest[$idx[$ctr]];
  908: 	    $ctr++;
  909: 	}
  910:         &random_set_seed(@oldseed);
  911: 	return @output;
  912:     } else {
  913: 	my $num = scalar(@$source);
  914: 	my @idx = &math_random_permuted_index($num);
  915: 	my $ctr = 0;
  916: 	my $tot = $num;
  917: 	$tot = $destct if $destct < $num;
  918: 	if (ref($$dest[0])) {
  919: 	    while ($ctr < $tot) {
  920: 		${$$dest[$ctr]} = $$source[$idx[$ctr]];
  921: 	        $ctr++;
  922:             }
  923:         } else {
  924: 	    while ($ctr < $tot) {
  925: 		$$dest[$ctr] = $$source[$idx[$ctr]];
  926: 		$ctr++;
  927: 	    }
  928: 	}
  929:     }
  930:     &random_set_seed(@oldseed);
  931:     return '';
  932: }
  933: 
  934: sub rmap {
  935:     my ($phrase,$dest,$source)=@_;
  936:     my @oldseed=&random_get_seed();
  937:     my @seed = &random_seed_from_phrase($phrase);
  938:     &random_set_seed(@seed);
  939:     my $destct = scalar(@$dest);
  940:     if (!$source) {
  941: 	my @idx = &math_random_permuted_index($destct);
  942: 	my $ctr = 0;
  943: 	my @r_idx;
  944: 	while ($ctr < $destct) {
  945: 	    $r_idx[$idx[$ctr]] = $ctr;
  946: 	    $ctr++;
  947: 	}
  948: 	my @output;
  949: 	$ctr = 0;
  950: 	while ($ctr < $destct) {
  951: 	    $output[$ctr] = $$dest[$r_idx[$ctr]];
  952: 	    $ctr++;
  953: 	}
  954:         &random_set_seed(@oldseed);
  955: 	return @output;
  956:     } else {
  957: 	my $num = scalar(@$source);
  958: 	my @idx = &math_random_permuted_index($num);
  959: 	my $ctr = 0;
  960: 	my $tot = $num;
  961: 	$tot = $destct if $destct < $num;
  962: 	my @r_idx;
  963: 	while ($ctr < $tot) {
  964: 	    $r_idx[$idx[$ctr]] = $ctr;
  965: 	    $ctr++;
  966: 	}
  967: 	$ctr = 0;
  968: 	if (ref($$dest[0])) {
  969: 	    while ($ctr < $tot) {
  970: 		${$$dest[$ctr]} = $$source[$r_idx[$ctr]];
  971: 	        $ctr++;
  972:             }
  973:         } else {
  974: 	    while ($ctr < $tot) {
  975: 		$$dest[$ctr] = $$source[$r_idx[$ctr]];
  976: 		$ctr++;
  977: 	    }
  978: 	}
  979:     }
  980:     &random_set_seed(@oldseed);
  981:     return '';
  982: }
  983: 
  984: sub capa_id { return }
  985: 
  986: sub problem { return }
  987: 
  988: sub name{
  989:     my $fullname = &EXT('environment.lastname').', '.&EXT('environment.firstname').' '.&EXT('environment.middlename');
  990:     $fullname = "" if $fullname eq ",  ";
  991:     $fullname =~ s/\%2d/-/g;
  992:     return $fullname;
  993: }
  994: 
  995: sub student_number { 
  996:     my $id = &EXT('environment.id');
  997:     $id = '' if $id eq "";
  998:     return $id;
  999: }
 1000: 
 1001: sub class {
 1002:     my $course = &EXT('course.description');
 1003:     $course = '' if $course eq "";
 1004:     return $course;
 1005: }
 1006: 
 1007: sub firstname {
 1008:     my $firstname = &EXT('environment.firstname');
 1009:     $firstname = '' if $firstname eq "";
 1010:     return $firstname;
 1011: }
 1012:                                                                                 
 1013: sub lastname {
 1014:     my $lastname = &EXT('environment.lastname');
 1015:     $lastname = '' if $lastname eq "";
 1016:     return $lastname;
 1017: }
 1018: 
 1019: sub sec { 
 1020:     my $sec = &EXT('request.course.sec');
 1021:     $sec = '' if $sec eq "";
 1022:     return $sec;
 1023: }
 1024: 
 1025: sub open_date { 
 1026:     my @dc = split(/\s+/,localtime(&EXT('resource.0.opendate')));
 1027:     return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
 1028:     my @hm = split(/:/,$dc[3]);
 1029:     my $ampm = " am";
 1030:     if ($hm[0] > 12) {
 1031: 	$hm[0]-=12;
 1032: 	$ampm = " pm";
 1033:     }
 1034:     return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
 1035: }
 1036: 
 1037: sub due_date { 
 1038:     my @dc = split(/\s+/,localtime(&EXT('resource.0.duedate')));
 1039:     return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
 1040:     my @hm = split(/:/,$dc[3]);
 1041:     my $ampm = " am";
 1042:     if ($hm[0] > 12) {
 1043: 	$hm[0]-=12;
 1044: 	$ampm = " pm";
 1045:     }
 1046:     return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
 1047: }
 1048: 
 1049: sub answer_date { 
 1050:     my @dc = split(/\s+/,localtime(&EXT('resource.0.answerdate')));
 1051:     return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
 1052:     my @hm = split(/:/,$dc[3]);
 1053:     my $ampm = " am";
 1054:     if ($hm[0] > 12) {
 1055: 	$hm[0]-=12;
 1056: 	$ampm = " pm";
 1057:     }
 1058:     return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
 1059: }
 1060: 
 1061: sub array_moments {
 1062:     my @input=@_;
 1063:     my (@output,$N);
 1064:     $N=scalar (@input);
 1065:     $output[0]=$N;
 1066:     if ($N <= 1) {
 1067: 	$output[1]=$input[0];
 1068: 	$output[1]="Input array not defined" if ($N == 0);
 1069: 	$output[2]="variance undefined for N<=1";
 1070: 	$output[3]="skewness undefined for N<=1";
 1071: 	$output[4]="kurtosis undefined for N<=1";
 1072: 	return @output;
 1073:     }
 1074:     my $sum=0;
 1075:     foreach my $line (@input) {
 1076: 	$sum+=$line;
 1077:     }
 1078:     $output[1] = $sum/$N;
 1079:     my ($x,$sdev,$var,$skew,$kurt) = 0;
 1080:     foreach my $line (@input) {
 1081: 	$x=$line-$output[1];
 1082: 	$var+=$x**2;
 1083: 	$skew+=$x**3;
 1084: 	$kurt+=$x**4;
 1085:     }
 1086:     $output[2]=$var/($N-1);
 1087:     $sdev=CORE::sqrt($output[2]);
 1088:     if ($sdev == 0) {
 1089: 	$output[3]="inf-variance=0";
 1090: 	$output[4]="inf-variance=0";
 1091: 	return @output;
 1092:     }
 1093:     $output[3]=$skew/($sdev**3*$N);
 1094:     $output[4]=$kurt/($sdev**4*$N)-3;
 1095:     return @output;
 1096: }
 1097: 
 1098: sub choose {
 1099:     my $num = $_[0];
 1100:     return $_[$num];
 1101: }
 1102: 
 1103: #&sum1(1,$x,sub { &sum1($_[0],2*$_[0], sub { fact($_[0])**2 })});
 1104: #sub sum1 {
 1105: #    my ($start,$end,$sub)=@_;
 1106: #    my $sum=0;
 1107: #    for (my $i=$start;$i<=$end;$i++) {
 1108: #        $sum+=&$sub($i);
 1109: #    }
 1110: #    return $sum
 1111: #}
 1112: 
 1113: #&sum2('a',1,$x,'&sum2(\'b\',$a,2*$a, \'&factorial($b)**2\')');
 1114: #sub sum2 {
 1115: #    my ($varname,$start,$end,$line)=@_;
 1116: #    my $sum=0;
 1117: #    for (my $i=$start;$i<=$end;$i++) {
 1118: #	my $func=sub {
 1119: #	    eval("\$".$varname."=$i");
 1120: #	    eval($line);
 1121: #	};
 1122: #        $sum+=&$func($i);
 1123: #    }
 1124: #    return $sum
 1125: #}
 1126: 
 1127: # expiremental idea
 1128: sub proper_path {
 1129:     my ($path)=@_;
 1130:     if ( $external::target eq "tex" ) {
 1131: 	return '/home/httpd/html'.$path;
 1132:     } else {
 1133: 	return $path;
 1134:     }
 1135: }
 1136: 

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