--- capa/capa51/pProj/capaCommon.c 2000/03/22 21:08:03 1.10 +++ capa/capa51/pProj/capaCommon.c 2002/06/26 17:26:09 1.21 @@ -1,6 +1,29 @@ +/* Library of useful functions + Copyright (C) 1992-2000 Michigan State University + + The CAPA system is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The CAPA system is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public + License along with the CAPA system; see the file COPYING. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + As a special exception, you have permission to link this program + with the TtH/TtM library and distribute executables, as long as you + follow the requirements of the GNU GPL in regard to all of the + software in the executable aside from TtH/TtM. +*/ + /* =||>|===================== capaCommon.c =====================|<||= */ /* created 1994 by Isaac Tsai */ -/* 1994, 1995, 1996, 1997, 1998, 1999 copyrighted by Isaac Tsai */ /* TODO: restructure capa_check_ans*() calls into one */ /* =||>|===================== capaCommon.c =====================|<||= */ #include @@ -25,6 +48,8 @@ int yyparse(); extern FILE *yyin; extern void yyrestart(); +extern FILE *dfp; + /*----------------------------------------------------------*/ /* RETURN: -1 file error */ /* 0 success */ @@ -1424,10 +1449,14 @@ void capa_get_due_date(char *date_str,T_ if ((duration > 0) && (student_number!=NULL)) { if (capa_get_login_time(student_number,set,&logintime)==1) { duetime=logintime+duration; - due_time_tm=localtime(&duetime); - sprintf(date_str,"%04d/%02d/%02d %02d:%02d",((due_time_tm->tm_year)+1900), - due_time_tm->tm_mon+1,due_time_tm->tm_mday,due_time_tm->tm_hour, - due_time_tm->tm_min); + if (compare_datetime(duetime,current->due_date)==-1) { + due_time_tm=localtime(&duetime); + sprintf(date_str,"%04d/%02d/%02d %02d:%02d",((due_time_tm->tm_year)+1900), + due_time_tm->tm_mon+1,due_time_tm->tm_mday,due_time_tm->tm_hour, + due_time_tm->tm_min); + } else { + strncpy(date_str,current->due_date,DATE_BUFFER); + } return; } } @@ -2124,6 +2153,10 @@ extern int Symb_count; extern int first_run; extern int Stop_Parser; extern void (*Status_Func)(); +#ifdef TTH +extern void tth_restart(); +extern char* tth_err; +#endif /*TTH*/ long seed1, seed2; T_student a_student; char *class, *classname, warn_msg[WARN_MSG_LENGTH]; @@ -2152,6 +2185,10 @@ extern void (*Status_Func)(); } u_getunit(fp); fclose(fp); +#ifdef TTH + if(tth_err) { free(tth_err); tth_err=NULL; } + tth_restart(); +#endif /*TTH*/ strncpy(Parse_name,a_student.s_nm,MAX_NAME_CHAR+1); strncpy(Parse_student_number,student_number,MAX_STUDENT_NUMBER+1); Parse_section = a_student.s_sec; @@ -2884,7 +2921,7 @@ capa_check_ans(ai,ans, error) AnswerInfo int sig, corr_len; int choice[ANSWER_STRING_LENG]; char num_str[ANSWER_STRING_LENG], unit_str[ANSWER_STRING_LENG]; - char fmted[ANSWER_STRING_LENG], correct[ANSWER_STRING_LENG], answer[ANSWER_STRING_LENG]; + char fmted[ANSWER_STRING_LENG], correctans[ANSWER_STRING_LENG], answer[ANSWER_STRING_LENG]; double n_part; double given, target, ratio, fmted_target, target_u, target_l, scale=1.0; double delta; @@ -2983,14 +3020,18 @@ capa_check_ans(ai,ans, error) AnswerInfo { corr_len = strlen(s); input_len = strlen(ans); if( corr_len == input_len ) { - for(idx=0;idx tol ) { outcome = INCORRECT; } } @@ -3336,8 +3387,15 @@ Problem_t *p; char **answers; int cnt; c outcomes = (int *)capa_malloc(sizeof(int),cnt); for(ii=0;iianswer,answers[0],outcomes[0]); +#endif for(ii=1, ai = p->ans_list; ai; ii++,ai = ai->ans_next ) { outcomes[ii] = capa_check_ans(ai,answers[ii],&(errormsg[ii])); +#ifdef COMMON_DBUG + printf("CAPA_CHECK_ANS(%s,%s): outcome[%d]=%d\n", ai->ans_str,answers[ii],ii,outcomes[ii]); +#endif } done = ii = 0; result = 0; @@ -3352,10 +3410,12 @@ Problem_t *p; char **answers; int cnt; c ii++; if(ii==cnt) done = 1; } - if( result == 0 ) { /* check if any of the outcome has failed to be a numeric */ + if( result == 0 ) { + /* check if any of the outcome has failed to be a numeric + or was a malformed equation */ done = ii = 0; while( !done ) { - if( outcomes[ii] == WANTED_NUMERIC ) { + if( outcomes[ii] == WANTED_NUMERIC || outcomes[ii] == BAD_FORMULA ) { result = outcomes[ii]; done = 1; } @@ -3363,7 +3423,7 @@ Problem_t *p; char **answers; int cnt; c if(ii==cnt) done = 1; } } - if( result == 0 ) { /* check if any of the outcome has failed on sig figs */ + if( result == 0 ) {/*check if any of the outcome has failed on sig figs*/ done = ii = 0; while( !done ) { if( outcomes[ii] == SIG_FAIL ) { @@ -3506,7 +3566,7 @@ char *key_word;char *value; } } if (c=='\n') found=1; - if (((char)c)==((char)EOF)) break; + if (((char)c)==((char)EOF)) {failed=1;break;} } } } while (!done && !failed);