[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm hint.pm /homework/caparesponse capa.i caparesponse.c caparesponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 12 Mar 2004 21:06:20 -0000


albertel		Fri Mar 12 16:06:20 2004 EDT

  Modified files:              
    /loncom/homework	default_homework.lcpm hint.pm 
    /loncom/homework/caparesponse	capa.i caparesponse.c caparesponse.pm 
  Log:
  - BUG# Lots, lets start with 186,32,220,870
  - when checking unit,sigfig etctera, we want to tell the student what we think they enetered, need to get the error string out of the C code and into perl space.
  - Still need to do something with the message but at lest we have it now
  - <numericalhint> properl namespace it's vars now.
  
  
  
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.70 loncom/homework/default_homework.lcpm:1.71
--- loncom/homework/default_homework.lcpm:1.70	Fri Mar 12 11:55:35 2004
+++ loncom/homework/default_homework.lcpm	Fri Mar 12 16:06:19 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
 #
-# $Id: default_homework.lcpm,v 1.70 2004/03/12 16:55:35 albertel Exp $
+# $Id: default_homework.lcpm,v 1.71 2004/03/12 21:06:19 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -109,11 +109,13 @@
     }
     if (!defined($sig_ubound)) { $sig_ubound=$sig_lbound; }
   }
+  my $reterror="";
   my $result = &caparesponse_capa_check_answer($response,$answer,$type,
 					       $tol_type,$tol,
 					       $sig_lbound,$sig_ubound,
 					       $ans_fmt,$unit,$calc,$id_list,
-					       $points,$external::randomseed);
+					       $points,$external::randomseed,
+					       \$reterror);
 
   if    ($result == '1') { $result='EXACT_ANS'; } 
   elsif ($result == '2') { $result='APPROX_ANS'; }
@@ -129,7 +131,7 @@
   elsif ($result =='12') { $result='WANTED_NUMERIC'; }
   else  {$result = "ERROR: Unknown Result:$result:$@:";}
 
-  return "$result:\nError $error:\nAnswer $answer:\nResponse $response:\n type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|\n$message$expr";
+  return ("$result:\nRetError $reterror:\nError $error:\nAnswer $answer:\nResponse $response:\n type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|\n$message$expr",$reterror);
 }
 
 sub get_array_args {
@@ -186,25 +188,29 @@
   $unit=~s/\s//;
   my $i=0;
   my $awards='';
+  my @msgs;
   for ($i=0; $i<@list;$i++) {
+      my $msg;
     $result.="trying answer :$list[$i]:\n";
     my $thisanswer=$list[$i];
 #    $thisanswer=~ s/\\/\\\\/g;
 #    $thisanswer =~ s/\'/\\\'/g;
     $result.="trying answer :$thisanswer:\n";
     if ($unit eq '') {
-      $aresult=&caparesponse_check($thisanswer,$responselist[$i],
-			     $expr);
+	($aresult,$msg)=&caparesponse_check($thisanswer,$responselist[$i],
+					    $expr);
     } else {
-      $aresult=&caparesponse_check($thisanswer,$responselist[$i]." $unit",
-				   $expr);
+	($aresult,$msg)=&caparesponse_check($thisanswer,
+					    $responselist[$i]." $unit",
+					    $expr);
     }
     my ($temp)=split /:/, $aresult;
     $awards.="$temp,";
     $result.=$aresult;
+    push(@msgs,$msg);
   }
   chop $awards;
-  return "$awards:\n$result";
+  return ("$awards:\n$result",@msgs);
 }
 
 sub tex {
Index: loncom/homework/hint.pm
diff -u loncom/homework/hint.pm:1.48 loncom/homework/hint.pm:1.49
--- loncom/homework/hint.pm:1.48	Fri Mar 12 13:41:43 2004
+++ loncom/homework/hint.pm	Fri Mar 12 16:06:19 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # implements the tags that control the hints
 #
-# $Id: hint.pm,v 1.48 2004/03/12 18:41:43 albertel Exp $
+# $Id: hint.pm,v 1.49 2004/03/12 21:06:19 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -163,20 +163,20 @@
 	    $$parstack[$#$parstack];
 	#need to get all possible parms
 	foreach my $key (keys(%Apache::inputtags::params)) {
-	    $expression.= ';my $'. #'
+	    $expression.= ';my $__LC__'. #'
 		$key.'="'.$Apache::inputtags::params{$key}.'"';
 	}
 	if ($$tagstack[-1] eq 'formulahint') {
-	    $expression.=';my $type="fml";';
+	    $expression.=';my $__LC__type="fml";';
 	} elsif ($$tagstack[-1] eq 'numericalhint') {
-	    $expression.=';my $type="float";';
+	    $expression.=';my $__LC__type="float";';
 	}
 	$expression.="');";
 	my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
 	&Apache::lonxml::debug('answer is'.join(':',@answer));
 	@{$safeeval->varglob('CAPARESPONSE_CHECK_LIST_answer')}=@answer;
 		
-	$result = &Apache::run::run($expression,$safeeval);
+	($result,my @msgs) = &Apache::run::run($expression,$safeeval);
 	&Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
 	my ($awards) = split /:/ , $result;
 	my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
Index: loncom/homework/caparesponse/capa.i
diff -u loncom/homework/caparesponse/capa.i:1.2 loncom/homework/caparesponse/capa.i:1.3
--- loncom/homework/caparesponse/capa.i:1.2	Mon Oct 29 16:15:44 2001
+++ loncom/homework/caparesponse/capa.i	Fri Mar 12 16:06:19 2004
@@ -2,9 +2,33 @@
 %{
 
 %}
+
+%typemap(perl5,in) char** reterror (char** cvalue) {
+  SV* tempsv;
+  if (!SvROK($source)) {
+    croak("expected a reference\n");
+  }
+  tempsv = SvRV($source);
+  if ((!SvPOK(tempsv))) {
+    croak("expected a double reference\n");
+  }
+  int len;
+  char *temp=SvPV(tempsv,len);
+  cvalue = &temp;
+  $target = cvalue;
+}
+
+%typemap(perl5,argout) char ** reterror {
+  SV *tempsv;
+  tempsv = SvRV($arg);
+  if (($source!=NULL) && (*$source!=NULL)) {
+    sv_setpv(tempsv, *$source);
+    free(*$source);
+  }
+}
 extern int caparesponse_capa_check_answer(char *response,char *correct,
 				   int type,int tol_type,double tolerance,
 				   int sig_lbound,int sig_ubound, 
 				   char *ans_fmt, char *unit_str,
 				   int calc, char *id_list, char *pts_list,
-				   char *rndseed);
+				   char *rndseed, char** reterror);
Index: loncom/homework/caparesponse/caparesponse.c
diff -u loncom/homework/caparesponse/caparesponse.c:1.11 loncom/homework/caparesponse/caparesponse.c:1.12
--- loncom/homework/caparesponse/caparesponse.c:1.11	Mon Jul 28 14:30:08 2003
+++ loncom/homework/caparesponse/caparesponse.c	Fri Mar 12 16:06:19 2004
@@ -1,6 +1,6 @@
 /* The LearningOnline Network with CAPA 
  * CAPA wrapper code
- * $Id: caparesponse.c,v 1.11 2003/07/28 18:30:08 albertel Exp $
+ * $Id: caparesponse.c,v 1.12 2004/03/12 21:06:19 albertel Exp $
  *
  * Copyright Michigan State University Board of Trustees
  *
@@ -68,7 +68,7 @@
 				   int sig_lbound,int sig_ubound, 
 				   char *ans_fmt, char *unit_str,
 				   int calc, char *id_list, char *pts_list, 
-				   char *rndseed)
+				   char *rndseed, char** reterror)
 				   
 {
   long result,seed1,seed2;
@@ -117,8 +117,9 @@
   p.calc       = calc;
 
   result=capa_check_answer(&p,response,&error);
-
-  if (error!=NULL) {free(error);}
+  *reterror=error;
+  // Caller is expected to free reterror
+  //  if (error!=NULL) {free(error);}
 
   return result;
 }
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.140 loncom/homework/caparesponse/caparesponse.pm:1.141
--- loncom/homework/caparesponse/caparesponse.pm:1.140	Fri Mar 12 13:41:43 2004
+++ loncom/homework/caparesponse/caparesponse.pm	Fri Mar 12 16:06:19 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.140 2004/03/12 18:41:43 albertel Exp $
+# $Id: caparesponse.pm,v 1.141 2004/03/12 21:06:19 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -159,7 +159,8 @@
 		&Apache::lonxml::debug('answer is'.join(':',@answer));
 		@{$safeeval->varglob('CAPARESPONSE_CHECK_LIST_answer')}=@answer;
 		
-		$result = &Apache::run::run($expression,$safeeval);
+		($result,my @msgs) = &Apache::run::run($expression,$safeeval);
+		&Apache::lonxml::debug('msgs are'.join(':',@msgs));
 		my ($awards) = split /:/ , $result;
 		($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
 		&Apache::lonxml::debug("$expression");