--- capa/capa51/pProj/qzparse.c 1999/09/28 21:26:20 1.1
+++ capa/capa51/pProj/qzparse.c 2000/08/07 20:47:29 1.8
@@ -1,3 +1,27 @@
+/* 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 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
+ General Public License for more details.
+
+ You should have received a copy of the GNU 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 */
/* ======================================================================== */
@@ -29,6 +53,14 @@ double atof();
#include "capaCommon.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;
void free_header(T_header* header)
@@ -49,26 +81,28 @@ print_header(int mode,FILE *o_fp,int sec
extern char *StartText_p;
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, "
Section %d %s, ", sec,stu_nam);
- fprintf(o_fp, "%s, CAPAID:%d set %d
\n", stu_num,capaid,set);
- fprintf(o_fp, "\n");
- break;
- }
if( StartText_p != NULL ) {
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, "Section %d %s, ", sec,stu_nam);
+ fprintf(o_fp, "%s, CAPAID:%d set %d
\n", stu_num,capaid,set);
+ fprintf(o_fp, "\n");
+ break;
+ }
}
void
@@ -135,6 +169,60 @@ 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 --> html -Ha */
@@ -178,17 +266,9 @@ void usage()
printf(" -d directory_to_create_files_in (default is class_path/TeX)\n");
printf("-------This is version %s @ %s\n",CAPA_VER,COMPILE_DATE);
printf("------------------------------------------------------\n");
+ printf("CAPA is released under GNU GPL v2, see COPYING for details.\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] */
int scan_num(char *num_str,int *first, int *second) {
char tmp_str[SMALL_LINE_BUFFER], *ch;
@@ -219,6 +299,78 @@ int scan_num(char *num_str,int *first,
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)
{
extern int Parsemode_f;
@@ -231,7 +383,8 @@ int main (int argc, char **argv)
T_student *students_p,*s_p, a_student;
int num_students, q_cnt, result, inputNotOK = 1,
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;
int tmp_num, first_stu, file_specified, directory_specified;
int ForWhat = F_SECTIONS, pagebreak=1,
@@ -381,218 +534,68 @@ int main (int argc, char **argv)
T_dates* dates;
T_header header;
for(ii=StartSet;ii<=EndSet;ii++) {
- if (capa_get_header(&header,ii)<0) {
- setdb_error(ii);
- }
- free_header(&header);
- if (capa_get_all_dates(ii,&dates)<0) {
- setdb_error(ii);
- }
- free_dates(dates);
+ if (capa_get_header(&header,ii)<0) setdb_error(ii);
+ free_header(&header);
+ if (capa_get_all_dates(ii,&dates)<0) setdb_error(ii);
+ free_dates(dates);
}
}
- if( ForWhat == F_STUDENT ) {
- result = capa_get_student(StuNum, &a_student);
- if ( result == 0 ) {
- fprintf(stderr,"Unable to find student %s in %s/classl",StuNum,path);
- exit(-1);
- } else {
- 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;
- }
+ switch (ForWhat) {
+ case F_STUDENT:
+ result = capa_get_student(StuNum, &a_student);
+ if ( result == 0 ) {
+ fprintf(stderr,"Unable to find student %s in %s/classl",StuNum,path);
+ exit(-1);
} else {
- switch( Parsemode_f ) {
- case TeX_MODE: sprintf(filename,"%s/%s.tex",out_directory,StuNum); break;
- case ASCII_MODE: sprintf(filename,"%s/%s.ascii",out_directory,StuNum); break;
- case HTML_MODE: sprintf(filename,"%s/%s.html",out_directory,StuNum); break;
- }
+ if (result == -1 ) {
+ fprintf(stderr,"Unable to read %s/classl",path);
+ exit(-1);
+ }
}
- } else {
- if (directory_specified == 0 ) {
- sprintf(filename,"%s",out_filename);
- } else {
- sprintf(filename,"%s/%s",out_directory,out_filename);
+ dfp=start_set(directory_specified,out_directory,file_specified,out_filename,
+ StuNum,filename);
+ for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
+ result = capa_parse(setIdx, &first_prob, StuNum, &q_cnt, NULL);
+ 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); }
}
- }
- 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) {
- fprintf(stdout,"File error! Cannot open [%s].\n",filename);
- return -1;
- }
- for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
- result = capa_parse(setIdx, &first_prob, StuNum, &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); 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, StuNum);
- 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;
- }
-
- }
- 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);
+ end_set(dfp,filename);
+ printf("\n DONE Student %s\n",StuNum);
+ break;
+ case F_SECTIONS:
+ for(sectionIdx = StartSec; sectionIdx <= EndSec; sectionIdx++ ) {
+ num_students = capa_sorted_section(&students_p, sectionIdx);
+ if( num_students > 0 ) {
+ printf("Section %2d: %d students\n",sectionIdx,num_students);
+ for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
+ sprintf(filestart,"section%d-set%d",sectionIdx,setIdx);
+ dfp=start_set(directory_specified,out_directory,file_specified,
+ out_filename,filestart,filename);
+ 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\n",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 ) {
+ output_problems(first_prob,outputFlag,q_cnt,dfp,s_p,setIdx);
+ free_problems(first_prob);
+ if( s_p->s_next != NULL ) { end_page(dfp,pagebreak); }
+ }
+ }
+ end_set(dfp,filename);
+ printf("\n DONE set%2d\n",setIdx);
+ }
+ }
+ printf("\n DONE section%2d\n",sectionIdx);
+ }
+ free_students(students_p);
+ break;
+ case F_ALPHA:
+ break;
}
printf("ALL DONE\n");
return (0);