[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 03 Apr 2003 17:44:12 -0000
albertel Thu Apr 3 12:44:12 2003 EDT
Modified files:
/loncom/homework structuretags.pm
Log:
- <while> actually works
- <while> preveted from becoming infinite loops
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.160 loncom/homework/structuretags.pm:1.161
--- loncom/homework/structuretags.pm:1.160 Thu Apr 3 09:53:44 2003
+++ loncom/homework/structuretags.pm Thu Apr 3 12:44:12 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.160 2003/04/03 14:53:44 albertel Exp $
+# $Id: structuretags.pm,v 1.161 2003/04/03 17:44:12 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -251,12 +251,16 @@
my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
return '';
}
-#intialize globals
+#initialize globals
$Apache::inputtags::part='0';
@Apache::inputtags::responselist = ();
@Apache::inputtags::previous=();
@Apache::inputtags::previous_version=();
$Apache::structuretags::printanswer='No';
+ @Apache::structuretags::whileconds=();
+ @Apache::structuretags::whilebody=();
+ @Apache::structuretags::whileline=();
+
if ($target ne 'analyze') {
&initialize_storage();
if ($target eq 'web') {
@@ -582,9 +586,8 @@
sub start_while {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
- &Apache::lonxml::debug('starting while');
my $result;
- if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
+ if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
my $code = $token->[2]->{'condition'};
@@ -593,8 +596,10 @@
&Apache::lonxml::default_homework_load($safeeval);
}
my $result = &Apache::run::run($code,$safeeval);
- my $bodytext=$$parser[-1]->get_text("/while");
+ my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
push( @Apache::structuretags::whilebody, $bodytext);
+ push( @Apache::structuretags::whileline, $token->[5]);
+ &Apache::lonxml::debug("s code $code got -$result-");
if ( $result ) {
&Apache::lonxml::newparser($parser,\$bodytext);
}
@@ -613,17 +618,26 @@
sub end_while {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
- &Apache::lonxml::debug('ending while');
-
my $result;
if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
my $code = pop(@Apache::structuretags::whileconds);
my $bodytext = pop(@Apache::structuretags::whilebody);
- my $result = &Apache::run::run($code,$safeeval);
- if ( $result ) {
- &Apache::lonxml::newparser($parser,\$bodytext);
+ my $line = pop(@Apache::structuretags::whileline);
+ my $return = &Apache::run::run($code,$safeeval);
+ my $starttime=time;
+ my $error=0;
+ while ($return) {
+ if (time-$starttime >
+ $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
+ $return = 0; $error=1; next;
+ }
+ $result.=&Apache::scripttag::xmlparse($bodytext);
+ $return = &Apache::run::run($code,$safeeval);
+ }
+ if ($error) {
+ &Apache::lonxml::error('<pre>Code ran too long. It ran for more than '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds occured while running <while$gt; on line '.$line.'</pre>');
}
} elsif ($target eq "edit") {
$result.= &Apache::edit::tag_end($target,$token,'');