version 1.9, 2003/05/27 17:01:36
|
version 1.24, 2024/04/29 01:29:26
|
Line 27
|
Line 27
|
|
|
#include <capaCommon.h> |
#include <capaCommon.h> |
#include <ranlib.h> |
#include <ranlib.h> |
|
#include <ctype.h> /* isdigit() */ |
|
|
PointsList_t * parse_pts_list (char *pts_list) { |
PointsList_t * parse_pts_list (char *pts_list) { |
PointsList_t *new=NULL, *end=NULL, *beforeend=NULL, *rlist=NULL; |
PointsList_t *new=NULL, *end=NULL, *beforeend=NULL, *rlist=NULL; |
Line 34 PointsList_t * parse_pts_list (char *pts
|
Line 35 PointsList_t * parse_pts_list (char *pts
|
int done=0; |
int done=0; |
/*fprintf(stderr,"ids %s\n",id_list); |
/*fprintf(stderr,"ids %s\n",id_list); |
fprintf(stderr,"pts %s\n",pts_list);*/ |
fprintf(stderr,"pts %s\n",pts_list);*/ |
while (!done) { |
while (!done && pts_list) { |
int idx; |
int idx; |
/*fprintf(stderr,"pts; %s\n",idx_pts);*/ |
/*fprintf(stderr,"pts; %s\n",idx_pts);*/ |
new=gen_ptslist_str(idx_pts); |
new=gen_ptslist_str(idx_pts); |
Line 68 int caparesponse_capa_check_answer(char
|
Line 69 int caparesponse_capa_check_answer(char
|
int sig_lbound,int sig_ubound, |
int sig_lbound,int sig_ubound, |
char *ans_fmt, char *unit_str, |
char *ans_fmt, char *unit_str, |
int calc, char *id_list, char *pts_list, |
int calc, char *id_list, char *pts_list, |
char *rndseed) |
char *rndseed, char** reterror) |
|
|
{ |
{ |
long result,seed1,seed2; |
long result,seed1,seed2; |
Line 77 int caparesponse_capa_check_answer(char
|
Line 78 int caparesponse_capa_check_answer(char
|
FILE *fp; |
FILE *fp; |
|
|
/* need to initialize unit parser*/ |
/* need to initialize unit parser*/ |
|
*reterror=NULL; |
sprintf(filename,"/home/httpd/html/res/adm/includes/capa.units"); |
sprintf(filename,"/home/httpd/html/res/adm/includes/capa.units"); |
if ((fp=fopen(filename,"r"))==NULL) { |
if ((fp=fopen(filename,"r"))==NULL) { |
/* printf("Error: can't open %s\n",filename);*/ |
/* printf("Error: can't open %s\n",filename);*/ |
Line 96 int caparesponse_capa_check_answer(char
|
Line 98 int caparesponse_capa_check_answer(char
|
if (type == ANSWER_IS_FORMULA) { |
if (type == ANSWER_IS_FORMULA) { |
p.id_list=id_list; |
p.id_list=id_list; |
p.pts_list=parse_pts_list(pts_list); |
p.pts_list=parse_pts_list(pts_list); |
|
// if ( p.id_list == NULL || p.pts_list == NULL) { |
|
// return BAD_FORMULA; |
|
// } |
} |
} |
p.ans_type = type; |
p.ans_type = type; |
p.answer = correct; |
p.answer = correct; |
Line 109 int caparesponse_capa_check_answer(char
|
Line 114 int caparesponse_capa_check_answer(char
|
} |
} |
if (unit_str != NULL && unit_str[0]!='\0') { |
if (unit_str != NULL && unit_str[0]!='\0') { |
strncpy(p.unit_str,unit_str,ANSWER_STRING_LENG-1); |
strncpy(p.unit_str,unit_str,ANSWER_STRING_LENG-1); |
p.ans_unit = u_parse_unit(unit_str); |
//p.ans_unit = u_parse_unit(unit_str); |
|
p.ans_unit = parse_unit_expr(unit_str); |
|
p.ans_unit = process_utree(p.ans_unit); |
|
//print_unit_t(p.ans_unit); |
} else { |
} else { |
p.unit_str[0]='\0'; |
p.unit_str[0]='\0'; |
p.ans_unit=NULL; |
p.ans_unit=NULL; |
Line 117 int caparesponse_capa_check_answer(char
|
Line 125 int caparesponse_capa_check_answer(char
|
p.calc = calc; |
p.calc = calc; |
|
|
result=capa_check_answer(&p,response,&error); |
result=capa_check_answer(&p,response,&error); |
|
*reterror=error; |
|
// Caller is expected to free reterror |
|
// if (error!=NULL) {free(error);} |
|
|
if (error!=NULL) {free(error);} |
return result; |
|
} |
|
|
|
int caparesponse_get_real_response (char* unit_str, char* answer, |
|
double* scaled) { |
|
//double caparesponse_get_real_response (char* unit_str, char* answer) { |
|
int input_len,all_alphabet,idx,outcome=-1; |
|
#pragma GCC diagnostic push |
|
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |
|
int result; |
|
#pragma GCC diagnostic pop |
|
ouble n_part,scale=1.0,given; |
|
char input[ANSWER_STRING_LENG],filename[FILE_NAME_LENGTH], |
|
tmp_unit_str[ANSWER_STRING_LENG]; |
|
Unit_t *ans_unit; |
|
FILE *fp; |
|
sprintf(filename,"/home/httpd/html/res/adm/includes/capa.units"); |
|
if ((fp=fopen(filename,"r"))==NULL) { |
|
/* printf("Error: can't open %s\n",filename);*/ |
|
return (-1); |
|
} |
|
u_getunit(fp); |
|
fclose(fp); |
|
|
|
if (unit_str != NULL && unit_str[0]!='\0') { |
|
ans_unit = parse_unit_expr(unit_str); |
|
ans_unit = process_utree(ans_unit); |
|
} else { |
|
ans_unit=NULL; |
|
} |
|
input_len = strlen(answer); |
|
all_alphabet = 1; |
|
for(idx=0;idx<input_len;idx++) { |
|
if( isdigit(answer[idx]) ) { |
|
all_alphabet = 0; |
|
} |
|
} |
|
if( !all_alphabet ) { |
|
tmp_unit_str[0] = 0; |
|
outcome = split_num_unit(answer,&n_part,input,tmp_unit_str); |
|
} |
|
if( outcome > 0 ) { |
|
if( outcome > 1 ) { /* with both num and unit parts or only unit part */ |
|
if( ans_unit != NULL ) { |
|
result = check_correct_unit(tmp_unit_str,ans_unit,&scale); |
|
} else { |
|
/* what to do when no unit is specified but student entered a unit? */ |
|
result = UNIT_NOTNEEDED; |
|
} |
|
} else { |
|
if( ans_unit != NULL ) { |
|
result = NO_UNIT; |
|
} |
|
} |
|
#pragma GCC diagnostic push |
|
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" |
|
if( (result != NO_UNIT) && (!check_for_unit_fail(result)) && ( result != UNIT_NOTNEEDED) ) { |
|
given = n_part * scale; |
|
*scaled=given; |
|
/* convert the given answer into proper scale for units */ |
|
} /* end if unit check */ |
|
} else { /* user entered alphabet, but no number */ |
|
result = WANTED_NUMERIC; |
|
} |
|
#pragma GCC diagnostic pop |
return result; |
return result; |
} |
} |
|
|
|
/* Testing harness |
|
int main(void) { |
|
int result=0; |
|
char *reterror=NULL; |
|
result= caparesponse_capa_check_answer("10^3","1000", |
|
ANSWER_IS_FORMULA, |
|
TOL_ABSOLUTE,1E-3, |
|
3,5,NULL,NULL, |
|
CALC_UNFORMATED, |
|
"","4", |
|
"rndseed", |
|
&reterror); |
|
fprintf(stderr,"result %d\nreterror: %s\n",result,reterror); |
|
} |
|
*/ |