version 1.1.1.1, 1999/09/28 21:26:20
|
version 1.6, 2000/07/07 18:33:03
|
Line 1
|
Line 1
|
|
/* main program to convert .qz files |
|
Copyright (C) 1992-2000 Michigan State University |
|
|
|
The CAPA system is free software; you can redistribute it and/or |
|
modify it under the terms of the GNU Library General Public License as |
|
published by the Free Software Foundation; either version 2 of the |
|
License, or (at your option) any later version. |
|
|
|
The CAPA system is distributed in the hope that it will be useful, |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
Library General Public License for more details. |
|
|
|
You should have received a copy of the GNU Library General Public |
|
License along with the CAPA system; see the file COPYING. If not, |
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
Boston, MA 02111-1307, USA. |
|
|
|
As a special exception, you have permission to link this program |
|
with the TtH/TtM library and distribute executables, as long as you |
|
follow the requirements of the GNU GPL in regard to all of the |
|
software in the executable aside from TtH/TtM. |
|
*/ |
|
|
/* ======================================================================== */ |
/* ======================================================================== */ |
/* Feb. 10 1997 Isaac Tsai */ |
/* Feb. 10 1997 Isaac Tsai */ |
/* ======================================================================== */ |
/* ======================================================================== */ |
Line 29 double atof();
|
Line 53 double atof();
|
#include "capaCommon.h" |
#include "capaCommon.h" |
#include "ranlib.h" |
#include "ranlib.h" |
|
|
|
#define Q_ONLY 1 |
|
#define A_ONLY 2 |
|
#define QA_BOTH 3 |
|
#define F_CLASS 1 |
|
#define F_SECTIONS 2 |
|
#define F_STUDENT 3 |
|
#define F_ALPHA 4 |
|
|
char *progname; |
char *progname; |
|
|
void free_header(T_header* header) |
void free_header(T_header* header) |
Line 49 print_header(int mode,FILE *o_fp,int sec
|
Line 81 print_header(int mode,FILE *o_fp,int sec
|
extern char *StartText_p; |
extern char *StartText_p; |
int capaid = capa_PIN(stu_num,set,0); |
int capaid = capa_PIN(stu_num,set,0); |
|
|
switch(mode) { |
|
case TeX_MODE: |
|
fprintf(o_fp, "Section %d {\\Large %s}\\hspace*{1in}",sec,stu_nam); |
|
fprintf(o_fp, "{\\large %s}, CAPAID: %d, set %d",stu_num, capaid, set); |
|
fprintf(o_fp, "\n\\begin{enumerate}\n"); |
|
break; |
|
case ASCII_MODE: |
|
fprintf(o_fp, "Section %d %s ", sec,stu_nam); |
|
fprintf(o_fp, "%s, CAPAID: %d set %d\n\n",stu_num, capaid, set); |
|
break; |
|
case HTML_MODE: |
|
fprintf(o_fp, "<H2>Section %d %s, ", sec,stu_nam); |
|
fprintf(o_fp, "%s, CAPAID:%d set %d</H2>\n", stu_num,capaid,set); |
|
fprintf(o_fp, "<OL>\n"); |
|
break; |
|
} |
|
if( StartText_p != NULL ) { |
if( StartText_p != NULL ) { |
fprintf(o_fp, "%s", StartText_p); |
fprintf(o_fp, "%s", StartText_p); |
} |
} |
|
|
|
switch(mode) { |
|
case TeX_MODE: |
|
if (StartText_p == NULL ) { |
|
fprintf(o_fp, "Section %d {\\Large %s}\\hspace*{1in}",sec,stu_nam); |
|
fprintf(o_fp, "{\\large %s}, CAPAID: %d, set %d",stu_num, capaid, set); |
|
} |
|
fprintf(o_fp, "\n\\begin{enumerate}\n"); |
|
break; |
|
case ASCII_MODE: |
|
fprintf(o_fp, "Section %d %s ", sec,stu_nam); |
|
fprintf(o_fp, "%s, CAPAID: %d set %d\n\n",stu_num, capaid, set); |
|
break; |
|
case HTML_MODE: |
|
fprintf(o_fp, "<H2>Section %d %s, ", sec,stu_nam); |
|
fprintf(o_fp, "%s, CAPAID:%d set %d</H2>\n", stu_num,capaid,set); |
|
fprintf(o_fp, "<OL>\n"); |
|
break; |
|
} |
} |
} |
|
|
void |
void |
Line 135 extern char *EndText_p;
|
Line 169 extern char *EndText_p;
|
} |
} |
} |
} |
|
|
|
void output_problems(Problem_t* first_prob,int outputFlag,int q_cnt,FILE* dfp, |
|
T_student* a_student,int setIdx) |
|
{ |
|
extern int Parsemode_f; |
|
extern char *EndText_p; |
|
extern char *StartText_p; |
|
|
|
Problem_t *p; |
|
int q_idx; |
|
char* ans_str; |
|
|
|
p = first_prob; |
|
switch(outputFlag) { |
|
case Q_ONLY: |
|
if( StartText_p != NULL) { |
|
fprintf(dfp, "%s", StartText_p); fflush(dfp); |
|
} |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
fprintf(dfp, "%s", p->question); p = p->next; |
|
} |
|
if( EndText_p != NULL) { |
|
fprintf(dfp, "%s", EndText_p); fflush(dfp); |
|
} |
|
break; |
|
case A_ONLY: |
|
print_header(Parsemode_f, dfp,a_student->s_sec,setIdx,a_student->s_nm, |
|
a_student->s_sn); |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
print_begin_item(Parsemode_f,dfp,q_idx+1); |
|
ans_str = answers_string(Parsemode_f,p); |
|
fprintf(dfp, "%s",ans_str); fflush(dfp); |
|
capa_mfree((char *)ans_str); |
|
p = p->next; |
|
} |
|
print_footer(Parsemode_f, dfp); |
|
break; |
|
case QA_BOTH: |
|
if( StartText_p != NULL ) { |
|
fprintf(dfp, "%s", StartText_p); |
|
} |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
fprintf(dfp, "%s", p->question); fflush(dfp); |
|
ans_str = answers_string(Parsemode_f,p); |
|
fprintf(dfp, "%s",ans_str); fflush(dfp); |
|
capa_mfree((char *)ans_str); |
|
p = p->next; |
|
} |
|
if( EndText_p != NULL ) { |
|
fprintf(dfp, "%s", EndText_p); |
|
} |
|
break; |
|
} |
|
} |
|
|
/* ============================================================== */ |
/* ============================================================== */ |
/* qz --> tex -Tq */ |
/* qz --> tex -Tq */ |
/* qz --> html -Ha */ |
/* qz --> html -Ha */ |
Line 180 void usage()
|
Line 268 void usage()
|
printf("------------------------------------------------------\n"); |
printf("------------------------------------------------------\n"); |
} |
} |
|
|
#define Q_ONLY 1 |
|
#define A_ONLY 2 |
|
#define QA_BOTH 3 |
|
#define F_CLASS 1 |
|
#define F_SECTIONS 2 |
|
#define F_STUDENT 3 |
|
|
|
|
|
|
|
/* filter out the number to be [1:999] */ |
/* filter out the number to be [1:999] */ |
int scan_num(char *num_str,int *first, int *second) { |
int scan_num(char *num_str,int *first, int *second) { |
char tmp_str[SMALL_LINE_BUFFER], *ch; |
char tmp_str[SMALL_LINE_BUFFER], *ch; |
Line 219 int scan_num(char *num_str,int *first,
|
Line 298 int scan_num(char *num_str,int *first,
|
return (result); |
return (result); |
} |
} |
|
|
|
FILE* start_set(int directory_specified,char* out_directory,int file_specified, |
|
char *out_filename,char* filestart,char* filename) |
|
{ |
|
extern int Parsemode_f; |
|
|
|
char cmd[MAX_BUFFER_SIZE]; |
|
FILE* dfp; |
|
|
|
if (file_specified == 0) { |
|
if (directory_specified == 0 ) { |
|
switch( Parsemode_f ) { |
|
case TeX_MODE: |
|
sprintf(filename,"TeX/%s.tex",filestart); |
|
break; |
|
case ASCII_MODE: |
|
sprintf(filename,"ASCII/%s.ascii",filestart); |
|
break; |
|
case HTML_MODE: |
|
sprintf(filename,"HTML/%s.text",filestart); |
|
break; |
|
} |
|
} else { |
|
switch( Parsemode_f ) { |
|
case TeX_MODE: |
|
sprintf(filename,"%s/%s.tex",out_directory,filestart); |
|
break; |
|
case ASCII_MODE: |
|
sprintf(filename,"%s/%s.ascii",out_directory,filestart); |
|
break; |
|
case HTML_MODE: |
|
sprintf(filename,"%s/%s.text", out_directory,filestart); |
|
break; |
|
} |
|
} |
|
} else { |
|
if (directory_specified == 0 ) { |
|
sprintf(filename,"%s",out_filename); |
|
} else { |
|
sprintf(filename,"%s/%s",out_directory,out_filename); |
|
} |
|
} |
|
switch ( Parsemode_f ) { |
|
case TeX_MODE: sprintf(cmd, "cp TeXheader %s\n",filename); system(cmd); break; |
|
default: sprintf(cmd,"rm %s\n",filename);system(cmd); break; |
|
} |
|
|
|
if((dfp=fopen(filename,"a"))==NULL) { printf("File error\n"); exit(-1); } |
|
return dfp; |
|
} |
|
|
|
void end_set(FILE*dfp,char* filename) |
|
{ |
|
extern int Parsemode_f; |
|
char cmd[MAX_BUFFER_SIZE]; |
|
fflush(dfp); |
|
fclose(dfp); |
|
if(Parsemode_f == TeX_MODE) { |
|
sprintf(cmd, "cat TeXfooter >> %s\n", filename); |
|
system(cmd); |
|
} |
|
} |
|
|
|
void end_page(FILE*dfp,int pagebreak) |
|
{ |
|
extern int Parsemode_f; |
|
if( Parsemode_f == TeX_MODE && pagebreak ) { |
|
fprintf(dfp, "\\clearpage\n\\setcounter{page}{1}\n"); fflush(dfp); |
|
} else { |
|
printf("\n"); |
|
} |
|
} |
|
|
int main (int argc, char **argv) |
int main (int argc, char **argv) |
{ |
{ |
extern int Parsemode_f; |
extern int Parsemode_f; |
Line 231 int main (int argc, char **argv)
|
Line 382 int main (int argc, char **argv)
|
T_student *students_p,*s_p, a_student; |
T_student *students_p,*s_p, a_student; |
int num_students, q_cnt, result, inputNotOK = 1, |
int num_students, q_cnt, result, inputNotOK = 1, |
ii, sectionIdx, setIdx = 1, q_idx, outputFlag = 0; |
ii, sectionIdx, setIdx = 1, q_idx, outputFlag = 0; |
char filename[FILE_NAME_LENGTH], path[FILE_NAME_LENGTH]; |
char filename[FILE_NAME_LENGTH], path[FILE_NAME_LENGTH], |
|
filestart[FILE_NAME_LENGTH]; |
FILE *dfp; |
FILE *dfp; |
int tmp_num, first_stu, file_specified, directory_specified; |
int tmp_num, first_stu, file_specified, directory_specified; |
int ForWhat = F_SECTIONS, pagebreak=1, |
int ForWhat = F_SECTIONS, pagebreak=1, |
Line 381 int main (int argc, char **argv)
|
Line 533 int main (int argc, char **argv)
|
T_dates* dates; |
T_dates* dates; |
T_header header; |
T_header header; |
for(ii=StartSet;ii<=EndSet;ii++) { |
for(ii=StartSet;ii<=EndSet;ii++) { |
if (capa_get_header(&header,ii)<0) { |
if (capa_get_header(&header,ii)<0) setdb_error(ii); |
setdb_error(ii); |
free_header(&header); |
} |
if (capa_get_all_dates(ii,&dates)<0) setdb_error(ii); |
free_header(&header); |
free_dates(dates); |
if (capa_get_all_dates(ii,&dates)<0) { |
|
setdb_error(ii); |
|
} |
|
free_dates(dates); |
|
} |
} |
} |
} |
|
|
if( ForWhat == F_STUDENT ) { |
switch (ForWhat) { |
result = capa_get_student(StuNum, &a_student); |
case F_STUDENT: |
if ( result == 0 ) { |
result = capa_get_student(StuNum, &a_student); |
fprintf(stderr,"Unable to find student %s in %s/classl",StuNum,path); |
if ( result == 0 ) { |
exit(-1); |
fprintf(stderr,"Unable to find student %s in %s/classl",StuNum,path); |
} else { |
exit(-1); |
if (result == -1 ) { |
|
fprintf(stderr,"Unable to read %s/classl",path); |
|
exit(-1); |
|
} |
|
} |
|
if ( file_specified == 0) { |
|
if ( directory_specified == 0) { |
|
switch( Parsemode_f ) { |
|
case TeX_MODE: sprintf(filename,"TeX/%s.tex",StuNum); break; |
|
case ASCII_MODE: sprintf(filename,"ASCII/%s.ascii",StuNum); break; |
|
case HTML_MODE: sprintf(filename,"HTML/%s.html",StuNum); break; |
|
} |
|
} else { |
} else { |
switch( Parsemode_f ) { |
if (result == -1 ) { |
case TeX_MODE: sprintf(filename,"%s/%s.tex",out_directory,StuNum); break; |
fprintf(stderr,"Unable to read %s/classl",path); |
case ASCII_MODE: sprintf(filename,"%s/%s.ascii",out_directory,StuNum); break; |
exit(-1); |
case HTML_MODE: sprintf(filename,"%s/%s.html",out_directory,StuNum); break; |
} |
} |
|
} |
} |
} else { |
dfp=start_set(directory_specified,out_directory,file_specified,out_filename, |
if (directory_specified == 0 ) { |
StuNum,filename); |
sprintf(filename,"%s",out_filename); |
for(setIdx=StartSet; setIdx <= EndSet; setIdx++) { |
} else { |
result = capa_parse(setIdx, &first_prob, StuNum, &q_cnt, NULL); |
sprintf(filename,"%s/%s",out_directory,out_filename); |
if ( result != 0 ) { |
|
output_problems(first_prob,outputFlag,q_cnt,dfp,&a_student,setIdx); |
|
free_problems(first_prob); |
|
} |
|
if( setIdx < EndSet ) { end_page(dfp,pagebreak); } |
|
if( ErrorMsg_count > 0 ) { printf("%s",ErrorMsg_p); } |
} |
} |
} |
end_set(dfp,filename); |
switch ( Parsemode_f ) { |
printf("\n DONE Student %s\n",StuNum); |
case TeX_MODE: sprintf(cmd, "cp TeXheader %s\n",filename); system(cmd); break; |
break; |
default: sprintf(cmd,"rm %s\n",filename);system(cmd); break; |
case F_SECTIONS: |
} |
for(sectionIdx = StartSec; sectionIdx <= EndSec; sectionIdx++ ) { |
if((dfp=fopen(filename,"a"))==NULL) { |
num_students = capa_sorted_section(&students_p, sectionIdx); |
fprintf(stdout,"File error! Cannot open [%s].\n",filename); |
if( num_students > 0 ) { |
return -1; |
printf("Section %2d: %d students\n",sectionIdx,num_students); |
} |
for(setIdx=StartSet; setIdx <= EndSet; setIdx++) { |
for(setIdx=StartSet; setIdx <= EndSet; setIdx++) { |
sprintf(filestart,"section%d-set%d",sectionIdx,setIdx); |
result = capa_parse(setIdx, &first_prob, StuNum, &q_cnt, NULL); |
dfp=start_set(directory_specified,out_directory,file_specified, |
if ( result != 0 ) { p = first_prob; |
out_filename,filestart,filename); |
switch(outputFlag) { |
for(s_p = students_p,first_stu=1; s_p ; s_p = s_p->s_next ) { |
case Q_ONLY: |
s_p->s_sn[MAX_STUDENT_NUMBER]=0; |
if( StartText_p != NULL) { |
printf(" Student: %s%s set %d\n",s_p->s_nm,s_p->s_sn,setIdx); |
fprintf(dfp, "%s", StartText_p); fflush(dfp); |
result = capa_parse(setIdx, &first_prob, s_p->s_sn, &q_cnt, NULL); |
} |
if ( result != 0 ) { |
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
output_problems(first_prob,outputFlag,q_cnt,dfp,s_p,setIdx); |
fprintf(dfp, "%s", p->question); p = p->next; |
free_problems(first_prob); |
} |
if( s_p->s_next != NULL ) { end_page(dfp,pagebreak); } |
if( EndText_p != NULL) { |
} |
fprintf(dfp, "%s", EndText_p); fflush(dfp); |
} |
} |
end_set(dfp,filename); |
break; |
printf("\n DONE set%2d\n",setIdx); |
case A_ONLY: |
} |
print_header(Parsemode_f, dfp,a_student.s_sec,setIdx,a_student.s_nm, StuNum); |
} |
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
printf("\n DONE section%2d\n",sectionIdx); |
print_begin_item(Parsemode_f,dfp,q_idx+1); |
} |
ans_str = answers_string(Parsemode_f,p); |
free_students(students_p); |
fprintf(dfp, "%s",ans_str); fflush(dfp); |
break; |
capa_mfree((char *)ans_str); |
case F_ALPHA: |
p = p->next; |
break; |
} |
|
print_footer(Parsemode_f, dfp); |
|
break; |
|
case QA_BOTH: |
|
if( StartText_p != NULL ) { |
|
fprintf(dfp, "%s", StartText_p); |
|
} |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
fprintf(dfp, "%s", p->question); fflush(dfp); |
|
ans_str = answers_string(Parsemode_f,p); |
|
fprintf(dfp, "%s",ans_str); fflush(dfp); |
|
capa_mfree((char *)ans_str); |
|
p = p->next; |
|
} |
|
if( EndText_p != NULL ) { |
|
fprintf(dfp, "%s", EndText_p); |
|
} |
|
break; |
|
} |
|
|
|
} |
|
free_problems(first_prob); |
|
if( setIdx < EndSet ) { |
|
if( Parsemode_f == TeX_MODE && pagebreak ) { |
|
fprintf(dfp, "\\clearpage\n\\setcounter{page}{1}\n"); |
|
} else { |
|
printf("\n"); |
|
} |
|
} |
|
if( ErrorMsg_count > 0 ) { |
|
printf("%s",ErrorMsg_p); |
|
} |
|
} |
|
fflush(dfp); fclose(dfp); |
|
|
|
switch( Parsemode_f ) { |
|
case TeX_MODE: sprintf(cmd, "cat TeXfooter >> %s\n", filename); system(cmd); break; |
|
} |
|
printf("\n DONE Student %s\n",StuNum); |
|
} else { /* For section(s) */ |
|
for(sectionIdx = StartSec; sectionIdx <= EndSec; sectionIdx++ ) { |
|
num_students = capa_sorted_section(&students_p, sectionIdx); |
|
printf("Section %2d: %d students\n",sectionIdx,num_students); |
|
if( num_students > 0 ) { |
|
for(setIdx=StartSet; setIdx <= EndSet; setIdx++) { |
|
|
|
if (directory_specified == 0 ) { |
|
switch( Parsemode_f ) { |
|
case TeX_MODE: sprintf(cmd, "cp TeXheader TeX/section%d-set%d.tex\n", sectionIdx,setIdx); |
|
system(cmd); |
|
sprintf(filename,"TeX/section%d-set%d.tex",sectionIdx,setIdx); break; |
|
case ASCII_MODE: sprintf(filename,"ASCII/section%d-set%d.ascii",sectionIdx,setIdx); break; |
|
case HTML_MODE: sprintf(filename,"HTML/section%d-set%d.text",sectionIdx,setIdx); break; |
|
} |
|
} else { |
|
switch( Parsemode_f ) { |
|
case TeX_MODE: sprintf(cmd, "cp TeXheader %s/section%d-set%d.tex\n", out_directory, |
|
sectionIdx,setIdx); |
|
system(cmd); |
|
sprintf(filename,"%s/section%d-set%d.tex",out_directory, |
|
sectionIdx,setIdx); break; |
|
case ASCII_MODE: sprintf(filename,"%s/section%d-set%d.ascii",out_directory, |
|
sectionIdx,setIdx); break; |
|
case HTML_MODE: sprintf(filename,"%s/section%d-set%d.text",out_directory, |
|
sectionIdx,setIdx); break; |
|
} |
|
} |
|
if((dfp=fopen(filename,"a"))==NULL) { printf("File error\n"); return -1; } |
|
for(s_p = students_p,first_stu=1; s_p ; s_p = s_p->s_next ) { |
|
s_p->s_sn[MAX_STUDENT_NUMBER]=0; |
|
printf(" Student: %s%s set %d",s_p->s_nm,s_p->s_sn,setIdx); |
|
result = capa_parse(setIdx, &first_prob, s_p->s_sn, &q_cnt, NULL); |
|
if ( result != 0 ) { |
|
p = first_prob; |
|
switch(outputFlag) { |
|
case Q_ONLY: |
|
if( StartText_p != NULL ) { |
|
fprintf(dfp, "%s", StartText_p); fflush(dfp); |
|
} |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
fprintf(dfp, "%s", p->question); fflush(dfp); p = p->next; |
|
} |
|
if( EndText_p != NULL ) { |
|
fprintf(dfp, "%s", EndText_p); fflush(dfp); |
|
} |
|
break; |
|
case A_ONLY: |
|
print_header(Parsemode_f,dfp,s_p->s_sec,setIdx,s_p->s_nm,s_p->s_sn); |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
print_begin_item(Parsemode_f,dfp,q_idx+1); |
|
ans_str = answers_string(Parsemode_f,p); |
|
fprintf(dfp, "%s",ans_str); fflush(dfp); |
|
capa_mfree((char *)ans_str); |
|
p = p->next; |
|
} |
|
print_footer(Parsemode_f,dfp); |
|
break; |
|
case QA_BOTH: |
|
if( StartText_p != NULL ) { |
|
fprintf(dfp, "%s", StartText_p); fflush(dfp); |
|
} |
|
for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) { |
|
fprintf(dfp, "%s", p->question); fflush(dfp); |
|
ans_str = answers_string(Parsemode_f,p); |
|
fprintf(dfp, "%s",ans_str); fflush(dfp); |
|
capa_mfree((char *)ans_str); |
|
p = p->next; |
|
} |
|
if( ( EndText_p != NULL) ) { |
|
fprintf(dfp, "%s", EndText_p); |
|
} |
|
break; |
|
} |
|
if( s_p->s_next != NULL ) { |
|
if(Parsemode_f == TeX_MODE && pagebreak) { |
|
fprintf(dfp, "\\clearpage\n\\setcounter{page}{1}\n"); fflush(dfp); |
|
} |
|
printf("\n"); |
|
} |
|
free_problems(first_prob); |
|
} |
|
} |
|
fflush(dfp); fclose(dfp); |
|
if(Parsemode_f == TeX_MODE) { |
|
if (directory_specified==0) { |
|
sprintf(cmd, "cat TeXfooter >> TeX/section%d-set%d.tex\n", sectionIdx,setIdx); system(cmd); |
|
} else { |
|
sprintf(cmd, "cat TeXfooter >> %s/section%d-set%d.tex\n", out_directory, |
|
sectionIdx,setIdx); system(cmd); |
|
} |
|
} |
|
printf("\n DONE set%2d\n",setIdx); |
|
} |
|
|
|
} |
|
printf("\n DONE section%2d\n",sectionIdx); |
|
} |
|
free_students(students_p); |
|
} |
} |
printf("ALL DONE\n"); |
printf("ALL DONE\n"); |
return (0); |
return (0); |