Annotation of capa/capa51/GUITools/answers.c, revision 1.1

1.1     ! albertel    1: /* ======================================================================== */
        !             2: /*       Feb. 10 1997   Isaac Tsai                                          */
        !             3: /* ======================================================================== */
        !             4: 
        !             5: #ifdef NeXT
        !             6: #include <stdlib.h>
        !             7: #include <sys/types.h>
        !             8: #include <sys/stat.h>  
        !             9: #include <bsd/curses.h>
        !            10: #else
        !            11: #include <curses.h>
        !            12: #include <malloc.h>
        !            13: double atof();
        !            14: #endif
        !            15: 
        !            16: #include <stdio.h>
        !            17: #include <ctype.h>
        !            18: #include <sys/types.h>
        !            19: #include <sys/stat.h>  
        !            20: #include <signal.h>
        !            21: #include <time.h>
        !            22: #include <math.h>
        !            23: #include <string.h>
        !            24: 
        !            25: 
        !            26: #define   YES    1
        !            27: 
        !            28: #include "Capa/capaCommon.h"
        !            29: 
        !            30: char    *progname;
        !            31: 
        !            32: 
        !            33: void
        !            34: print_answer(FILE *o_fp,int ans_cnt,char *ans,char *lower,char *upper,char *unit)
        !            35: {
        !            36:   if (unit && (strlen(unit)>0)) 
        !            37:     if(ans_cnt==2)  fprintf(o_fp,"ANS:%s %s %s %s\n",ans,lower,upper,unit); 
        !            38:     else  fprintf(o_fp,"ANS:%s %s\n",lower,unit);
        !            39:   else 
        !            40:     if(ans_cnt==2)  fprintf(o_fp,"ANS:%s %s %s\n",ans,lower,upper); 
        !            41:     else  fprintf(o_fp,"ANS:%s\n",lower);
        !            42: }
        !            43: 
        !            44: void print_question (FILE *o_fp,char *question)
        !            45: {
        !            46:   fprintf(o_fp,"BQES:\n%s\nEQES:\n",question);
        !            47: }
        !            48: 
        !            49: int main (int argc, char  **argv) 
        !            50: {
        !            51:   extern  int        Parsemode_f;
        !            52:     
        !            53:   Problem_t  *first_prob,*p;
        !            54:   int         q_cnt, num_answers, result, setIdx = 1, q_idx;
        !            55:   char        lower[ANSWER_STRING_LENG], upper[ANSWER_STRING_LENG];
        !            56:   int         StartSet = 1, EndSet = 1;
        !            57:   char        tmp_str[ANSWER_STRING_LENG];
        !            58:   double      tmp_ans;
        !            59:   T_student   a_student;
        !            60: 
        !            61:   Parsemode_f=ASCII_MODE;
        !            62:   if ( argc > 6 || argc < 5 ) {
        !            63:     printf("USAGE: %s StudentNumber StudentName Section startSet [endSet]\n",argv[0]);
        !            64:     exit(-1);
        !            65:   }
        !            66:   strncpy(a_student.s_sn,argv[1],MAX_STUDENT_NUMBER);
        !            67:   a_student.s_sn[MAX_STUDENT_NUMBER]='\0';
        !            68:   strncpy(a_student.s_nm,argv[2],MAX_NAME_CHAR);
        !            69:   a_student.s_nm[MAX_NAME_CHAR]='\0';
        !            70:   a_student.s_sec=atoi(argv[3]);
        !            71:   
        !            72:   StartSet=atoi(argv[4]);
        !            73:   if ( argc == 6 ) {
        !            74:     EndSet=atoi(argv[5]);
        !            75:   } else {
        !            76:     EndSet=StartSet;
        !            77:   }
        !            78:   for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
        !            79:     printf("SET:%d\n",setIdx);
        !            80:     result = capa_parse_student(setIdx, &first_prob, &a_student,&q_cnt,NULL);
        !            81:     printf("\n");
        !            82:     if ( result > 0 ) { 
        !            83:       p = first_prob;
        !            84:       for( q_idx = 0; q_idx < q_cnt; q_idx++ ) {
        !            85: 	print_question(stdout,p->question);
        !            86: 	if( p->ans_type == ANSWER_IS_SUBJECTIVE) {
        !            87: 	  printf("ANS: Subjective Answers\n");
        !            88: 	} else {
        !            89: 	  if( p->ans_type == ANSWER_IS_FLOAT ) {
        !            90: 	    tmp_ans = (double)atof(p->answer);
        !            91: 	    sprintf(tmp_str, p->ans_fmt, tmp_ans);
        !            92: 	  } else {
        !            93: 	    strcpy(tmp_str,p->answer);
        !            94: 	  }
        !            95: 
        !            96: 	  num_answers = calc_ansrange(p->ans_type, p->calc, p->answer, p->ans_fmt,
        !            97: 				      p->tol_type, p->tolerance, lower, upper);
        !            98: 	  print_answer(stdout,num_answers,tmp_str,lower,upper,p->unit_str);
        !            99: 	}
        !           100: 	p = p->next;
        !           101:       }
        !           102:     } else {
        !           103:       printf("ERROR:for %s set %d\n",a_student.s_sn,setIdx);
        !           104:     }
        !           105:     free_problems(first_prob);
        !           106:     if( setIdx < EndSet ) { 
        !           107:       printf("\n"); 
        !           108:     }
        !           109:   }
        !           110:   printf("\nDONE:%s\n",a_student.s_sn);
        !           111:   return (0);
        !           112: }
        !           113: 
        !           114: 

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