--- capa/capa51/pProj/capaCgiUtils.c 1999/11/08 22:30:02 1.4 +++ capa/capa51/pProj/capaCgiUtils.c 1999/11/18 17:55:24 1.5 @@ -404,12 +404,9 @@ void w_get_responses(int x,int q_idx,cha sscanf(g_entries[x].name,"INPUT%d",&q_idx); if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) { if ( ! is_all_ws(g_entries[x].val) ) { - leng = strlen(g_entries[x].val) + 1; g_stu_ans_pp[q_idx] = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1); (g_stu_ans_pp[q_idx])->a_idx = 1; (g_stu_ans_pp[q_idx])->a_str = strsave(g_entries[x].val); - if (leng > ANSWER_STRING_LENG) - (g_stu_ans_pp[q_idx])->a_str[ANSWER_STRING_LENG] = '\0'; (g_stu_ans_pp[q_idx])->a_next = NULL; trim_response_ws((g_stu_ans_pp[q_idx])->a_str); } @@ -424,11 +421,9 @@ void w_get_responses(int x,int q_idx,cha if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) { if ( ! is_all_ws(g_entries[x].val) ) { StudentAnswer_t *sa_p; - leng = strlen(g_entries[x].val) + 1; sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1); sa_p->a_idx = sub_idx; sa_p->a_str = strsave(g_entries[x].val); - if (leng > ANSWER_STRING_LENG) sa_p->a_str[ANSWER_STRING_LENG] = '\0'; sa_p->a_next = NULL; if( g_stu_ans_pp[q_idx] == NULL ) { g_stu_ans_pp[q_idx] = sa_p; @@ -451,22 +446,18 @@ void w_get_responses(int x,int q_idx,cha if( index(g_entries[x].name, ',' ) == NULL ) { /* only one answer */ sscanf(g_entries[x].name,"LAST%d",&q_idx); if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) { - leng = strlen(g_entries[x].val) + 1; sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1); sa_p->a_idx = 1; sa_p->a_str = strsave(g_entries[x].val); - if (leng > ANSWER_STRING_LENG) sa_p->a_str[ANSWER_STRING_LENG] = '\0'; sa_p->a_next = NULL; g_last_ans_pp[q_idx] = sa_p; } } else { sscanf(g_entries[x].name,"LAST%d,%d",&q_idx,&sub_idx); if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) { - leng = strlen(g_entries[x].val) + 1; sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1); sa_p->a_idx = sub_idx; sa_p->a_str = strsave(g_entries[x].val); - if (leng > ANSWER_STRING_LENG) sa_p->a_str[ANSWER_STRING_LENG] = '\0'; sa_p->a_next = NULL; if( g_last_ans_pp[q_idx] == NULL) { g_last_ans_pp[q_idx] = sa_p; @@ -1895,7 +1886,9 @@ char buf[MAX_BUFFER_SIZE]; } /* returns a -1 if there were not enough answers, otherwise the number of responses - for the question is returned*/ + for the question is returned + !!!!!AS A SIDEEFFECT IT ALSO CROPS ANSWERS TO ANSWER_STRING_LENG!!!!!!! +*/ int gather_answers(char ***ans,int q_idx,Problem_t *p) { int cnt; @@ -1905,6 +1898,7 @@ int gather_answers(char ***ans,int q_idx sa_p= g_stu_ans_pp[q_idx+1]; for(i=0;((ians_cnt)&&(sa_p));i++){ ans[0][i]=sa_p->a_str; + if ((strlen(ans[0][i])+1) > ANSWER_STRING_LENG) ans[0][i][ANSWER_STRING_LENG]='\0'; sa_p=sa_p->a_next; } cnt=p->ans_cnt; @@ -1912,6 +1906,7 @@ int gather_answers(char ***ans,int q_idx } else { *ans=(char**)capa_malloc(p->ans_cnt,1); ans[0][0]=g_stu_ans_pp[q_idx+1]->a_str; + if ((strlen(ans[0][0])+1) > ANSWER_STRING_LENG) ans[0][0][ANSWER_STRING_LENG]='\0'; cnt=1; } return cnt; @@ -2002,7 +1997,7 @@ int tries; submit_subjective(q_idx,p); return; } - + cnt=gather_answers(&ans,q_idx,p); if (cnt == -1) { g_tried[q_idx]--;