Annotation of loncom/homework/caparesponse/caparesponse.c, revision 1.10

1.7       albertel    1: /* The LearningOnline Network with CAPA 
                      2:  * CAPA wrapper code
1.10    ! albertel    3:  * $Id: caparesponse.c,v 1.9 2003/05/27 17:01:36 bowersj2 Exp $
1.7       albertel    4:  *
                      5:  * Copyright Michigan State University Board of Trustees
                      6:  *
                      7:  * This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      8:  *
                      9:  * LON-CAPA is free software; you can redistribute it and/or modify
                     10:  * it under the terms of the GNU General Public License as published by
                     11:  * the Free Software Foundation; either version 2 of the License, or
                     12:  * (at your option) any later version.
                     13:  *
                     14:  * LON-CAPA is distributed in the hope that it will be useful,
                     15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
                     16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     17:  * GNU General Public License for more details.
                     18:  *
                     19:  * You should have received a copy of the GNU General Public License
                     20:  * along with LON-CAPA; if not, write to the Free Software
                     21:  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     22:  *
                     23:  * /home/httpd/html/adm/gpl.txt
                     24:  *
                     25:  * http://www.lon-capa.org/
                     26:  */
                     27: 
1.1       albertel   28: #include <capaCommon.h>
1.6       albertel   29: #include <ranlib.h>
                     30: 
                     31: PointsList_t * parse_pts_list (char *pts_list) {
                     32:   PointsList_t *new=NULL, *end=NULL, *beforeend=NULL, *rlist=NULL;
                     33:   char *idx_pts=pts_list;
                     34:   int done=0;
1.10    ! albertel   35:   /*fprintf(stderr,"ids %s\n",id_list);*/
        !            36:     fprintf(stderr,"pts %s\n",pts_list);
1.6       albertel   37:   while (!done) {
                     38:     int idx;
1.10    ! albertel   39:       fprintf(stderr,"pts; %s\n",idx_pts);
1.6       albertel   40:     new=gen_ptslist_str(idx_pts);
                     41:     if (!new) break;
                     42:     if (!rlist) { rlist=new; }
                     43:     if (end) { 
                     44:       end->pts_next=new; 
                     45:       idx=end->pts_idx;
                     46:     } else {
                     47:       idx=-1;
                     48:     }
                     49:     end=new;
                     50:     while (end) {
                     51:       idx++;
                     52:       end->pts_idx=idx;
1.10    ! albertel   53:         fprintf(stderr,"end is:%d:%d:%s:%d\n",idx,end->pts_idx,end->pts_str,
        !            54: 	end->pts_next);
1.6       albertel   55:       beforeend=end;
                     56:       end=end->pts_next;
                     57:     }
                     58:     end=beforeend;
                     59:     idx_pts=strchr(idx_pts,';');
                     60:     if (idx_pts) { idx_pts++; } else { done=1; }
                     61:   }
                     62:   
                     63:   return rlist;
                     64: }
                     65: 
1.1       albertel   66: int caparesponse_capa_check_answer(char *response,char *correct,
                     67: 				   int type,int tol_type,double tolerance,
                     68: 				   int sig_lbound,int sig_ubound, 
                     69: 				   char *ans_fmt, char *unit_str,
1.6       albertel   70: 				   int calc, char *id_list, char *pts_list, 
                     71: 				   char *rndseed)
                     72: 				   
1.1       albertel   73: {
1.6       albertel   74:   long result,seed1,seed2;
1.1       albertel   75:   Problem_t p;
                     76:   char *error=NULL,filename[FILE_NAME_LENGTH];
                     77:   FILE *fp;
1.10    ! albertel   78: fprintf(stderr,"1\n");
1.9       bowersj2   79:   /* need to initialize unit parser*/
1.4       albertel   80:   sprintf(filename,"/home/httpd/html/res/adm/includes/capa.units");
1.1       albertel   81:   if ((fp=fopen(filename,"r"))==NULL) {
                     82:     /* printf("Error: can't open %s\n",filename);*/
                     83:       return (-1); 
                     84:   }
1.10    ! albertel   85: fprintf(stderr,"2\n");
1.1       albertel   86:   u_getunit(fp);
1.10    ! albertel   87: fprintf(stderr,"3\n");
1.1       albertel   88:   fclose(fp);
1.10    ! albertel   89: fprintf(stderr,"4\n");
1.6       albertel   90:   /* need to setup random generator (FIXME) should only do this if 
                     91:      it hasn't been yet*/
                     92:   phrtsd(rndseed,&seed1,&seed2);
                     93:   setall(seed1,seed2);
1.10    ! albertel   94: fprintf(stderr,"5\n");
1.1       albertel   95: 
1.6       albertel   96:   /* assign_id_list and assign_pts_list exist in capaGrammerDef.y */
                     97:   p.id_list=NULL;
                     98:   p.pts_list=NULL;
1.10    ! albertel   99: fprintf(stderr,"6 -%s-\n",id_list);
1.6       albertel  100:   if (type == ANSWER_IS_FORMULA) {
                    101:     p.id_list=id_list;
                    102:     p.pts_list=parse_pts_list(pts_list);
                    103:   }
1.10    ! albertel  104: fprintf(stderr,"6\n");
1.2       albertel  105:   p.ans_type   = type;
                    106:   p.answer     = correct;
                    107:   p.tol_type   = tol_type;
                    108:   p.tolerance  = tolerance;
                    109:   p.sig_lbound = sig_lbound;
                    110:   p.sig_ubound = sig_ubound;
1.10    ! albertel  111: fprintf(stderr,"7\n");
1.8       bowersj2  112:   
                    113:   if (ans_fmt != NULL ) {
1.10    ! albertel  114: fprintf(stderr,"8\n");
1.8       bowersj2  115:     strncpy(p.ans_fmt,ans_fmt,ANSWER_STRING_LENG-1);
                    116:   }
1.10    ! albertel  117: fprintf(stderr,"9\n");
1.8       bowersj2  118:   if (unit_str != NULL && unit_str[0]!='\0') {
1.10    ! albertel  119: fprintf(stderr,"10\n");
1.5       albertel  120:     strncpy(p.unit_str,unit_str,ANSWER_STRING_LENG-1);
1.10    ! albertel  121: fprintf(stderr,"11\n");
1.5       albertel  122:     p.ans_unit   = u_parse_unit(unit_str);
1.10    ! albertel  123: fprintf(stderr,"12\n");
1.5       albertel  124:   } else {
1.10    ! albertel  125: fprintf(stderr,"13\n");
1.5       albertel  126:     p.unit_str[0]='\0';
1.10    ! albertel  127: fprintf(stderr,"14\n");
1.9       bowersj2  128:     p.ans_unit=NULL;
1.10    ! albertel  129: fprintf(stderr,"15\n");
1.5       albertel  130:   }
1.2       albertel  131:   p.calc       = calc;
1.1       albertel  132: 
1.10    ! albertel  133: fprintf(stderr,"16 -p.asnwer %s- -response %s-\n",p.answer,response);
1.1       albertel  134:   result=capa_check_answer(&p,response,&error);
1.10    ! albertel  135: fprintf(stderr,"17\n");
1.1       albertel  136: 
                    137:   if (error!=NULL) {free(error);}
                    138: 
                    139:   return result;
                    140: }

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