--- loncom/interface/Attic/lonspreadsheet.pm 2002/10/22 18:54:53 1.123 +++ loncom/interface/Attic/lonspreadsheet.pm 2002/10/24 15:34:10 1.127 @@ -1,5 +1,5 @@ # -# $Id: lonspreadsheet.pm,v 1.123 2002/10/22 18:54:53 matthew Exp $ +# $Id: lonspreadsheet.pm,v 1.127 2002/10/24 15:34:10 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -122,20 +122,17 @@ my $tmpdir; ## sub mask { my ($lower,$upper)=@_; - - $lower=~/([A-Za-z]|\*)(\d+|\*)/; - my $la=$1; - my $ld=$2; - - $upper=~/([A-Za-z]|\*)(\d+|\*)/; - my $ua=$1; - my $ud=$2; + # + my ($la,$ld) = ($lower=~/([A-Za-z]|\*)(\d+|\*)/); + my ($ua,$ud) = ($upper=~/([A-Za-z]|\*)(\d+|\*)/); + # my $alpha=''; my $num=''; - + # if (($la eq '*') || ($ua eq '*')) { $alpha='[A-Za-z]'; } else { + if (($la=~/[A-Z]/) && ($ua=~/[A-Z]/) || ($la=~/[a-z]/) && ($ua=~/[a-z]/)) { $alpha='['.$la.'-'.$ua.']'; @@ -188,8 +185,8 @@ sub mask { } $num.=')'; } else { - if ($lda[$#lda]!=$uda[$#uda]) { - $num.='['.$lda[$#lda].'-'.$uda[$#uda].']'; + if ($lda[-1]!=$uda[-1]) { + $num.='['.$lda[-1].'-'.$uda[-1].']'; } } } @@ -237,8 +234,6 @@ undef %c; # Holds the constants for a sh # sheets, this is the A column. Used in &MINPARM, &MAXPARM, &expandnamed, # &sett, and &setconstants. There is no &getconstants. # &setconstants is called by &loadstudent, &loadcourse, &load assessment, -undef %rowlabel; # Holds the 'prefix' for each row. Set by &setrowlabels. - # &setrowlabels is called by &updateclasssheet, &updatestudentassesssheet, undef @os; # Holds the names of other spreadsheets - this is used to specify # the spreadsheets that are available for the assessment sheet. # Set by &setothersheets. &setothersheets is called by &handler. A @@ -754,6 +749,7 @@ parametername should be a string such as sub MINPARM { my ($expression) = @_; my $min = undef; + study($expression); foreach $parameter (keys(%c)) { next if ($parameter !~ /$expression/); if ((! defined($min)) || ($min > $c{$parameter})) { @@ -776,6 +772,7 @@ parametername should be a string such as sub MAXPARM { my ($expression) = @_; my $max = undef; + study($expression); foreach $parameter (keys(%c)) { next if ($parameter !~ /$expression/); if ((! defined($min)) || ($max < $c{$parameter})) { @@ -827,6 +824,7 @@ sub expandnamed { my $returnvalue = ''; my @matches = (); $#matches = -1; + study $expression; foreach $parameter (keys(%c)) { push @matches,$parameter if ($parameter =~ /$expression/); } @@ -915,6 +913,32 @@ sub sett { $t{'A0'}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.&expandnamed($2)/ge; } +sub calc { + undef %sheet_values; + &sett(); + my $notfinished=1; + my $lastcalc=''; + my $depth=0; + while ($notfinished) { + $notfinished=0; + foreach (keys(%t)) { + my $old=$sheet_values{$_}; + $sheet_values{$_}=eval $t{$_}; + if ($@) { + undef %sheet_values; + return $_.': '.$@; + } + if ($sheet_values{$_} ne $old) { $notfinished=1; $lastcalc=$_; } + } + $depth++; + if ($depth>100) { + undef %sheet_values; + return $lastcalc.': Maximum calculation depth exceeded'; + } + } + return ''; +} + # ------------------------------------------- End of "Inside of the safe space" ENDDEFS $safeeval->reval($code); @@ -950,7 +974,7 @@ sub outrowassess { if ($n) { my ($usy,$ufn)=split(/__&&&\__/,$sheet->{'f'}->{'A'.$n}); if ($sheet->{'rowlabel'}->{$usy}) { - $cols[0]=$sheet->{'rowlabel'}->{$usy}; + $cols[0]=&format_rowlabel($sheet->{'rowlabel'}->{$usy}); if (! $csv) { $cols[0].='
'. '