File:  [LON-CAPA] / loncom / homework / caparesponse / caparesponse.c
Revision 1.6: download - view: text, annotated - select for diffs
Mon Oct 29 21:15:45 2001 UTC (22 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: stable_2001_fall, HEAD
- able to now get a formula response question correct

    1: #include <capaCommon.h>
    2: #include <ranlib.h>
    3: 
    4: PointsList_t * parse_pts_list (char *pts_list) {
    5:   PointsList_t *new=NULL, *end=NULL, *beforeend=NULL, *rlist=NULL;
    6:   char *idx_pts=pts_list;
    7:   int done=0;
    8:   /*fprintf(stderr,"ids %s\n",id_list);
    9:     fprintf(stderr,"pts %s\n",pts_list);*/
   10:   while (!done) {
   11:     int idx;
   12:     /*fprintf(stderr,"pts; %s\n",idx_pts);*/
   13:     new=gen_ptslist_str(idx_pts);
   14:     if (!new) break;
   15:     if (!rlist) { rlist=new; }
   16:     if (end) { 
   17:       end->pts_next=new; 
   18:       idx=end->pts_idx;
   19:     } else {
   20:       idx=-1;
   21:     }
   22:     end=new;
   23:     while (end) {
   24:       idx++;
   25:       end->pts_idx=idx;
   26:       /*fprintf(stderr,"end is:%d:%d:%s:%d\n",idx,end->pts_idx,end->pts_str,
   27: 	end->pts_next);*/
   28:       beforeend=end;
   29:       end=end->pts_next;
   30:     }
   31:     end=beforeend;
   32:     idx_pts=strchr(idx_pts,';');
   33:     if (idx_pts) { idx_pts++; } else { done=1; }
   34:   }
   35:   
   36:   return rlist;
   37: }
   38: 
   39: int caparesponse_capa_check_answer(char *response,char *correct,
   40: 				   int type,int tol_type,double tolerance,
   41: 				   int sig_lbound,int sig_ubound, 
   42: 				   char *ans_fmt, char *unit_str,
   43: 				   int calc, char *id_list, char *pts_list, 
   44: 				   char *rndseed)
   45: 				   
   46: {
   47:   long result,seed1,seed2;
   48:   Problem_t p;
   49:   char *error=NULL,filename[FILE_NAME_LENGTH];
   50:   FILE *fp;
   51: 
   52:   /*fprintf(stderr,"hi in caparesponse\n");*/
   53:   /*need to initialize unit parser*/
   54:   sprintf(filename,"/home/httpd/html/res/adm/includes/capa.units");
   55:   if ((fp=fopen(filename,"r"))==NULL) {
   56:     /* printf("Error: can't open %s\n",filename);*/
   57:       return (-1); 
   58:   }
   59:   u_getunit(fp);
   60:   fclose(fp);
   61:   /* need to setup random generator (FIXME) should only do this if 
   62:      it hasn't been yet*/
   63:   phrtsd(rndseed,&seed1,&seed2);
   64:   setall(seed1,seed2);
   65: 
   66:   /* assign_id_list and assign_pts_list exist in capaGrammerDef.y */
   67:   p.id_list=NULL;
   68:   p.pts_list=NULL;
   69: 
   70:   if (type == ANSWER_IS_FORMULA) {
   71:     p.id_list=id_list;
   72:     p.pts_list=parse_pts_list(pts_list);
   73:   }
   74:   p.ans_type   = type;
   75:   p.answer     = correct;
   76:   p.tol_type   = tol_type;
   77:   p.tolerance  = tolerance;
   78:   p.sig_lbound = sig_lbound;
   79:   p.sig_ubound = sig_ubound;
   80:   strncpy(p.ans_fmt,ans_fmt,ANSWER_STRING_LENG-1);
   81:   if (unit_str[0]!='\0') {
   82:     strncpy(p.unit_str,unit_str,ANSWER_STRING_LENG-1);
   83:     p.ans_unit   = u_parse_unit(unit_str);
   84:   } else {
   85:     p.unit_str[0]='\0';
   86:     p.ans_unit=NULL;
   87:   }
   88:   p.calc       = calc;
   89: 
   90: 
   91:   result=capa_check_answer(&p,response,&error);
   92: 
   93:   if (error!=NULL) {free(error);}
   94: 
   95:   return result;
   96: }

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