Diff for /capa/capa51/pProj/capaCgiUtils.c between versions 1.4 and 1.5

version 1.4, 1999/11/08 22:30:02 version 1.5, 1999/11/18 17:55:24
Line 404  void w_get_responses(int x,int q_idx,cha Line 404  void w_get_responses(int x,int q_idx,cha
       sscanf(g_entries[x].name,"INPUT%d",&q_idx);        sscanf(g_entries[x].name,"INPUT%d",&q_idx);
       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {        if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {
  if ( ! is_all_ws(g_entries[x].val) ) {   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] = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
   (g_stu_ans_pp[q_idx])->a_idx  = 1;    (g_stu_ans_pp[q_idx])->a_idx  = 1;
   (g_stu_ans_pp[q_idx])->a_str  = strsave(g_entries[x].val);    (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;    (g_stu_ans_pp[q_idx])->a_next = NULL;
   trim_response_ws((g_stu_ans_pp[q_idx])->a_str);    trim_response_ws((g_stu_ans_pp[q_idx])->a_str);
  }   }
Line 424  void w_get_responses(int x,int q_idx,cha Line 421  void w_get_responses(int x,int q_idx,cha
       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {        if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {
  if ( ! is_all_ws(g_entries[x].val) ) {    if ( ! is_all_ws(g_entries[x].val) ) { 
   StudentAnswer_t *sa_p;    StudentAnswer_t *sa_p;
   leng = strlen(g_entries[x].val) + 1;  
   sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);    sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
   sa_p->a_idx  = sub_idx;    sa_p->a_idx  = sub_idx;
   sa_p->a_str  = strsave(g_entries[x].val);    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;    sa_p->a_next = NULL;
   if( g_stu_ans_pp[q_idx] == NULL ) {    if( g_stu_ans_pp[q_idx] == NULL ) {
     g_stu_ans_pp[q_idx] = sa_p;      g_stu_ans_pp[q_idx] = sa_p;
Line 451  void w_get_responses(int x,int q_idx,cha Line 446  void w_get_responses(int x,int q_idx,cha
     if( index(g_entries[x].name, ',' ) == NULL ) {  /* only one answer */      if( index(g_entries[x].name, ',' ) == NULL ) {  /* only one answer */
       sscanf(g_entries[x].name,"LAST%d",&q_idx);        sscanf(g_entries[x].name,"LAST%d",&q_idx);
       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {        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 = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
  sa_p->a_idx  = 1;   sa_p->a_idx  = 1;
  sa_p->a_str  = strsave(g_entries[x].val);   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;   sa_p->a_next = NULL;
  g_last_ans_pp[q_idx] = sa_p;   g_last_ans_pp[q_idx] = sa_p;
       }        }
     } else {      } else {
       sscanf(g_entries[x].name,"LAST%d,%d",&q_idx,&sub_idx);        sscanf(g_entries[x].name,"LAST%d,%d",&q_idx,&sub_idx);
       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {        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 = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
  sa_p->a_idx  = sub_idx;   sa_p->a_idx  = sub_idx;
  sa_p->a_str  = strsave(g_entries[x].val);   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;   sa_p->a_next = NULL;
  if( g_last_ans_pp[q_idx] == NULL) {   if( g_last_ans_pp[q_idx] == NULL) {
   g_last_ans_pp[q_idx] = sa_p;    g_last_ans_pp[q_idx] = sa_p;
Line 1895  char       buf[MAX_BUFFER_SIZE]; Line 1886  char       buf[MAX_BUFFER_SIZE];
 }  }
   
 /* returns a -1 if there were not enough answers, otherwise the number of responses  /* 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 gather_answers(char ***ans,int q_idx,Problem_t *p)
 {  {
   int cnt;    int cnt;
Line 1905  int gather_answers(char ***ans,int q_idx Line 1898  int gather_answers(char ***ans,int q_idx
     sa_p= g_stu_ans_pp[q_idx+1];      sa_p= g_stu_ans_pp[q_idx+1];
     for(i=0;((i<p->ans_cnt)&&(sa_p));i++){      for(i=0;((i<p->ans_cnt)&&(sa_p));i++){
       ans[0][i]=sa_p->a_str;        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;        sa_p=sa_p->a_next;
     }      }
     cnt=p->ans_cnt;      cnt=p->ans_cnt;
Line 1912  int gather_answers(char ***ans,int q_idx Line 1906  int gather_answers(char ***ans,int q_idx
   } else {    } else {
     *ans=(char**)capa_malloc(p->ans_cnt,1);      *ans=(char**)capa_malloc(p->ans_cnt,1);
     ans[0][0]=g_stu_ans_pp[q_idx+1]->a_str;      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;      cnt=1;
   }    }
   return cnt;    return cnt;
Line 2002  int    tries; Line 1997  int    tries;
     submit_subjective(q_idx,p);      submit_subjective(q_idx,p);
     return;      return;
   }    }
     
   cnt=gather_answers(&ans,q_idx,p);    cnt=gather_answers(&ans,q_idx,p);
   if (cnt == -1) {    if (cnt == -1) {
     g_tried[q_idx]--;      g_tried[q_idx]--;

Removed from v.1.4  
changed lines
  Added in v.1.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>