[LON-CAPA-cvs] cvs: capa /capa51/pProj capaCommon.c capaParser.h capaUnit.c
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 26 Mar 2004 20:02:03 -0000
albertel Fri Mar 26 15:02:03 2004 EDT
Modified files:
/capa/capa51/pProj capaCommon.c capaParser.h capaUnit.c
Log:
- add new unit errorcodes (so that Lon-CAPA can be informative about what is wrong)
- This currently breaks CAPA
Index: capa/capa51/pProj/capaCommon.c
diff -u capa/capa51/pProj/capaCommon.c:1.22 capa/capa51/pProj/capaCommon.c:1.23
--- capa/capa51/pProj/capaCommon.c:1.22 Fri Sep 20 17:27:49 2002
+++ capa/capa51/pProj/capaCommon.c Fri Mar 26 15:02:03 2004
@@ -2897,6 +2897,16 @@
}
+int check_for_unit_fail(int result)
+{
+ int ret;
+ ret = (result == UNIT_FAIL ||
+ result == UNIT_IRRECONCIBLE ||
+ result == UNIT_INVALID_STUDENT3 ||
+ result == UNIT_INVALID_STUDENT2 ||
+ result == UNIT_INVALID_STUDENT1);
+ return ret;
+}
/* ------------------------------ called from capalogin */
/* impose stronger checking on the user input string *answer */
@@ -2947,7 +2957,8 @@
outcome = split_num_unit(ans,&n_part,num_str,unit_str);
if( outcome > 1 ) { /* with both num and unit parts or only unit part */
if( u_p != NULL ) {
- if (UNIT_FAIL == (result = check_correct_unit(unit_str,u_p,&scale))) {
+ result = check_correct_unit(unit_str,u_p,&scale);
+ if (check_for_unit_fail(result)) {
*error=strsave(unit_str);
}
} else { /* what to do when no unit is specified but student entered a unit? */
@@ -2959,7 +2970,7 @@
result = NO_UNIT;
}
}
- if( (result != NO_UNIT) && (result != UNIT_FAIL) && ( result != UNIT_NOTNEEDED) ) {
+ if( (result != NO_UNIT) && (!check_for_unit_fail(result)) && ( result != UNIT_NOTNEEDED) ) {
if( t == ANSWER_IS_FLOAT ) {
target = (double)atof(s); /* real number */
} else {
@@ -3097,7 +3108,7 @@
fmt = p->ans_fmt;
calc_type = p->calc;
unit_str[0]=0;
-
+
switch(type) {
case ANSWER_IS_INTEGER:
case ANSWER_IS_FLOAT:
@@ -3113,7 +3124,8 @@
outcome = split_num_unit(answer,&n_part,input,unit_str);
if( outcome > 1 ) { /* with both num and unit parts or only unit part */
if( p->ans_unit != NULL ) {
- if ( UNIT_FAIL == ( result = check_correct_unit(unit_str,p->ans_unit,&scale) ) ) {
+ result = check_correct_unit(unit_str,p->ans_unit,&scale);
+ if (check_for_unit_fail(result)) {
*error=strsave(unit_str);
}
} else { /* what to do when no unit is specified but student entered a unit? */
@@ -3125,7 +3137,7 @@
result = NO_UNIT;
}
}
- if( (result != NO_UNIT) && (result != UNIT_FAIL) && ( result != UNIT_NOTNEEDED) ) {
+ if( (result != NO_UNIT) && (!check_for_unit_fail(result)) && ( result != UNIT_NOTNEEDED) ) {
if( type == ANSWER_IS_FLOAT ) {
target = (double)atof(correct); /* real number */
} else {
@@ -3400,7 +3412,7 @@
done = ii = 0;
result = 0;
while( !done ) { /* check if any of the outcome has failed on units */
- if( (outcomes[ii] == UNIT_FAIL) ||
+ if( (check_for_unit_fail(outcomes[ii])) ||
(outcomes[ii] == NO_UNIT) ||
(outcomes[ii] == UNIT_NOTNEEDED) ) {
result = outcomes[ii];
@@ -3447,7 +3459,7 @@
}
}
for (ii=0;ii<cnt;ii++) {
- if( (outcomes[ii] == UNIT_FAIL) ||
+ if( (check_for_unit_fail(outcomes[ii])) ||
(outcomes[ii] == SIG_FAIL) ||
(outcomes[ii] == UNIT_NOTNEEDED) ) {
capa_mfree(errormsg[ii]);
@@ -3465,7 +3477,7 @@
result = capa_check_answer(p, answers[0], error);
ii = 1; ai = p->ans_list;
while( (ii<p->ans_cnt) && ( (result != EXACT_ANS) && (result != APPROX_ANS) ) ) {
- if((ii!=1)&&((result==UNIT_FAIL)||(result==SIG_FAIL)||(result==UNIT_NOTNEEDED))) {
+ if((ii!=1)&&((check_for_unit_fail(result))||(result==SIG_FAIL)||(result==UNIT_NOTNEEDED))) {
capa_mfree((char*)error);
}
result = capa_check_ans(ai,answers[0],error);
Index: capa/capa51/pProj/capaParser.h
diff -u capa/capa51/pProj/capaParser.h:1.11 capa/capa51/pProj/capaParser.h:1.12
--- capa/capa51/pProj/capaParser.h:1.11 Mon Nov 6 15:17:42 2000
+++ capa/capa51/pProj/capaParser.h Fri Mar 26 15:02:03 2004
@@ -428,8 +428,11 @@
#define SUB_RECORDED 10
#define BAD_FORMULA 11
#define WANTED_NUMERIC 12
-
-
+#define UNIT_INVALID_INSTRUCTOR 13
+#define UNIT_INVALID_STUDENT1 141
+#define UNIT_INVALID_STUDENT2 142
+#define UNIT_INVALID_STUDENT3 143
+#define UNIT_IRRECONCIBLE 15
/* =============================================================== */
Index: capa/capa51/pProj/capaUnit.c
diff -u capa/capa51/pProj/capaUnit.c:1.11 capa/capa51/pProj/capaUnit.c:1.12
--- capa/capa51/pProj/capaUnit.c:1.11 Wed Sep 20 15:03:09 2000
+++ capa/capa51/pProj/capaUnit.c Fri Mar 26 15:02:03 2004
@@ -781,17 +781,17 @@
(Pstack[Ptopidx]->u_count == t->u_count) ) { /* has unit */
*scale = units_ratio(Pstack[Ptopidx], t);
if( *scale == 0.0 ) {
- result = UNIT_FAIL;
+ result = UNIT_IRRECONCIBLE;
}
free_utree(ap);
} else {
- result = UNIT_FAIL;
+ result = UNIT_INVALID_STUDENT3;
}
} else { /* invalid unit representation */
- result = UNIT_FAIL;
+ result = UNIT_INVALID_STUDENT2;
}
} else {
- result = UNIT_FAIL;
+ result = UNIT_INVALID_STUDENT1;
}
#ifdef UNIT_DBUG
fclose(ufp);