Annotation of capa/capa51/GUITools/answers.c, revision 1.2
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;
1.2 ! albertel 52: extern int managermode;
! 53:
1.1 albertel 54: Problem_t *first_prob,*p;
55: int q_cnt, num_answers, result, setIdx = 1, q_idx;
56: char lower[ANSWER_STRING_LENG], upper[ANSWER_STRING_LENG];
57: int StartSet = 1, EndSet = 1;
58: char tmp_str[ANSWER_STRING_LENG];
59: double tmp_ans;
60: T_student a_student;
61:
62: Parsemode_f=ASCII_MODE;
63: if ( argc > 6 || argc < 5 ) {
1.2 ! albertel 64: printf("USAGE: %s StudentNumber StudentName ?managermode? startSet [endSet]\n",
! 65: argv[0]);
1.1 albertel 66: exit(-1);
67: }
68: strncpy(a_student.s_sn,argv[1],MAX_STUDENT_NUMBER);
69: a_student.s_sn[MAX_STUDENT_NUMBER]='\0';
70: strncpy(a_student.s_nm,argv[2],MAX_NAME_CHAR);
71: a_student.s_nm[MAX_NAME_CHAR]='\0';
1.2 ! albertel 72: managermode=atoi(argv[3]);
1.1 albertel 73:
74: StartSet=atoi(argv[4]);
75: if ( argc == 6 ) {
76: EndSet=atoi(argv[5]);
77: } else {
78: EndSet=StartSet;
79: }
80: for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
81: printf("SET:%d\n",setIdx);
82: result = capa_parse_student(setIdx, &first_prob, &a_student,&q_cnt,NULL);
83: printf("\n");
84: if ( result > 0 ) {
85: p = first_prob;
86: for( q_idx = 0; q_idx < q_cnt; q_idx++ ) {
87: print_question(stdout,p->question);
88: if( p->ans_type == ANSWER_IS_SUBJECTIVE) {
89: printf("ANS: Subjective Answers\n");
90: } else {
91: if( p->ans_type == ANSWER_IS_FLOAT ) {
92: tmp_ans = (double)atof(p->answer);
93: sprintf(tmp_str, p->ans_fmt, tmp_ans);
94: } else {
95: strcpy(tmp_str,p->answer);
96: }
97:
98: num_answers = calc_ansrange(p->ans_type, p->calc, p->answer, p->ans_fmt,
99: p->tol_type, p->tolerance, lower, upper);
100: print_answer(stdout,num_answers,tmp_str,lower,upper,p->unit_str);
101: }
102: p = p->next;
103: }
104: } else {
105: printf("ERROR:for %s set %d\n",a_student.s_sn,setIdx);
106: }
107: free_problems(first_prob);
108: if( setIdx < EndSet ) {
109: printf("\n");
110: }
111: }
112: printf("\nDONE:%s\n",a_student.s_sn);
113: return (0);
114: }
115:
116:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>