File:  [LON-CAPA] / capa / capa51 / pProj / qzparse.c
Revision 1.1: download - view: text, annotated - select for diffs
Tue Sep 28 21:26:20 1999 UTC (24 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
Initial revision

    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 "capaParser.h"
   29: #include "capaCommon.h"
   30: #include "ranlib.h"
   31: 
   32: char    *progname;
   33: 
   34: void free_header(T_header* header) 
   35: {
   36:   capa_mfree(header->weight);
   37:   capa_mfree(header->partial_credit);
   38: }
   39: 
   40: void setdb_error(int set)
   41: {
   42:   fprintf(stderr,"Set #%d has not had it's DB Header set. Please run Quizzer and set the DB Header.\n",set);
   43:   exit(-1);
   44: }
   45: 
   46: void
   47: print_header(int mode,FILE *o_fp,int sec,int set,char *stu_nam,char *stu_num)
   48: {
   49:   extern  char      *StartText_p;
   50:   int capaid = capa_PIN(stu_num,set,0);
   51: 
   52:   switch(mode) {
   53:     case TeX_MODE:
   54:           fprintf(o_fp, "Section %d  {\\Large %s}\\hspace*{1in}",sec,stu_nam);
   55:           fprintf(o_fp, "{\\large %s}, CAPAID: %d, set %d",stu_num, capaid, set);
   56:           fprintf(o_fp, "\n\\begin{enumerate}\n");
   57:           break;
   58:     case ASCII_MODE:
   59:           fprintf(o_fp, "Section %d   %s    ", sec,stu_nam); 
   60: 	  fprintf(o_fp, "%s, CAPAID: %d set %d\n\n",stu_num, capaid, set);
   61: 	  break;
   62:     case HTML_MODE: 
   63:           fprintf(o_fp, "<H2>Section %d  %s,  ", sec,stu_nam); 
   64: 	  fprintf(o_fp, "%s, CAPAID:%d set %d</H2>\n", stu_num,capaid,set);
   65: 	  fprintf(o_fp, "<OL>\n");
   66: 	  break;
   67:   }
   68:   if( StartText_p != NULL ) {
   69:      fprintf(o_fp, "%s", StartText_p);
   70:   }
   71: 
   72: }
   73: 
   74: void
   75: print_begin_item(int mode,FILE *o_fp,int q_idx)
   76: {
   77: 
   78:   switch(mode) {
   79:     case TeX_MODE:
   80:           fprintf(o_fp, "\\item ");
   81:           break;
   82:     case ASCII_MODE:
   83:           fprintf(o_fp, "%d) ", q_idx); 
   84: 	  break;
   85:     case HTML_MODE: 
   86:           fprintf(o_fp, "<LI> "); 
   87: 	  break;
   88:   }
   89: }
   90: 
   91: 
   92: void
   93: unit_toHTML(char *u_str, char *r)
   94: {
   95:   int   i;
   96:   char  *ch;
   97:   
   98:   
   99:    while(isspace(*ch)) ch++;
  100:    while( isalnum(*ch) ) {
  101:      r[i++] = *ch; ch++;
  102:    }
  103:    if( *ch == '^' ) {
  104:      r[i++] = '<'; r[i++]='s';r[i++]='u';r[i++]='p';r[i++]='>';
  105:      ch++; while(isspace(*ch)) ch++;
  106:      while( isalnum(*ch) ) {
  107:        r[i++] = *ch; ch++;
  108:      }
  109:      r[i++] = '<'; r[i++]='/'; r[i++]='s';r[i++]='u';r[i++]='p';r[i++]='>';
  110:    } else {
  111:      r[i++] = *ch; ch++;
  112:    }
  113:   
  114:   
  115: }
  116: 
  117: void
  118: print_footer(int mode,FILE *o_fp)
  119: {
  120: extern  char      *EndText_p;
  121: 
  122:   switch(mode) {
  123:     case TeX_MODE:
  124:           fprintf(o_fp, "\n\\end{enumerate}\n");        
  125:           break;
  126:     case ASCII_MODE:
  127: 	  fprintf(o_fp, "\n");
  128: 	  break;
  129:     case HTML_MODE: 
  130: 	  fprintf(o_fp, "</OL>\n");
  131: 	  break;
  132:   }
  133:   if( EndText_p != NULL ) {
  134:      fprintf(o_fp, "%s", EndText_p);
  135:   }
  136: }
  137: 
  138: /* ============================================================== */
  139: /*  qz --> tex    -Tq */
  140: /*  qz --> html   -Ha */
  141: /*  qz --> ascii  -Ab */
  142: /*     question only   q */
  143: /*     answer   only   a */
  144: /*     both            b */
  145: /*        for entire class            -C       */
  146: /*        for a range of sections     -Sec 2:6 */
  147: /*        for a section               -Sec 2   */
  148: /*        for a student               -Stu 12345678 */
  149: /*           output a set             -Set 2     */
  150: /*           output a range of sets   -Set 1:6   */
  151: /*        output blocksize            -b 30     */
  152: /* ============================================================== */
  153: 
  154: void usage()
  155: {
  156:  printf("USAGE: %s [ -[T|H|A][a|b] ] [-Sec [n|n:m] | -Stu sn [-o filename] ]\n",progname);
  157:  printf("          [ -Set [n|n:m] ] [-c path_to_class] [-d outputdirectory]\n");
  158:  printf(" Example 1: %s -Tb -sec 2:3 -set 2:5\n", progname);
  159:  printf("            will generate tex files with both questions and answers\n");
  160:  printf("            for sections 2 to 3, sets 2 to 5\n");
  161:  printf(" Example 2: %s -Ha -stu A12345678 -set 3\n", progname);
  162:  printf("            will generate html files with answer only \n");
  163:  printf("            for student A12345678 set 3\n");
  164:  printf("          -T     = tex   mode\n");
  165:  printf("          -H     = html  mode\n");
  166:  printf("          -A     = ascii mode\n");
  167:  printf("                 = default question only\n");
  168:  printf("            a    = answer   only\n");
  169:  printf("            b    = both question and answer\n");
  170:  printf("          -nopagebreak = don't put a \\clearpage between assignments\n");
  171:  printf("          -Sec 3 = for section 3\n");
  172:  printf("          -Sec 3:7    = from section 3 to section 7\n");
  173:  printf("          -Stu A12345678 = for a specified student\n");
  174:  printf("          -Set 1 = output set 1\n");
  175:  printf("          -Set 3:4 = output from set 3 to set 4\n");
  176:  printf("          -c class_path\n");
  177:  printf("          -o output_filename_with_absolute_path (only for a student)\n");
  178:  printf("          -d directory_to_create_files_in (default is class_path/TeX)\n");
  179:  printf("-------This is version %s @ %s\n",CAPA_VER,COMPILE_DATE);
  180:  printf("------------------------------------------------------\n");
  181: }
  182: 
  183: #define  Q_ONLY        1
  184: #define  A_ONLY        2
  185: #define  QA_BOTH       3
  186: #define  F_CLASS       1
  187: #define  F_SECTIONS    2
  188: #define  F_STUDENT     3
  189: 
  190: 
  191: 
  192: /* filter out the number to be [1:999] */
  193: int  scan_num(char *num_str,int *first, int *second) {
  194:   char  tmp_str[SMALL_LINE_BUFFER], *ch;
  195:   int   ii=0, a_num, b_num, result=0;
  196:   
  197:   ch = num_str;
  198:   tmp_str[ii] = 0;
  199:   while( isspace(*ch) ) ch++;
  200:   while(isdigit(*ch)) { tmp_str[ii++] = *ch; ch++; }
  201:   tmp_str[ii] = 0;
  202:   sscanf(tmp_str,"%d",&a_num);
  203:   if( a_num < 0 || a_num > 999 ) a_num = 1;
  204:   *first = a_num;
  205:   result = 1;
  206:   while( isspace(*ch) ) ch++;
  207:   if( *ch == ':' ) {
  208:     ch++;
  209:     while( isspace(*ch) ) ch++;
  210:     ii=0; tmp_str[ii] = 0;
  211:     while( isdigit(*ch) ) { tmp_str[ii++] = *ch; ch++; }
  212:     tmp_str[ii] = 0;
  213:     sscanf(tmp_str,"%d",&b_num);
  214:     if( b_num < 0 || b_num > 999 ) b_num = 1;
  215:     if( a_num > b_num )           b_num = a_num;
  216:     *second = b_num;
  217:     result = 2;
  218:   }
  219:   return (result);
  220: }
  221: 
  222: int main (int argc, char  **argv) 
  223: {
  224:   extern  int        Parsemode_f;
  225:   extern  char      *EndText_p;
  226:   extern  char      *StartText_p;
  227:   extern  char      *ErrorMsg_p;
  228:   extern  int        ErrorMsg_count;
  229:     
  230:   Problem_t  *first_prob,*p;
  231:   T_student  *students_p,*s_p, a_student;
  232:   int         num_students, q_cnt, result, inputNotOK = 1, 
  233:               ii, sectionIdx, setIdx = 1, q_idx, outputFlag = 0;
  234:   char        filename[FILE_NAME_LENGTH], path[FILE_NAME_LENGTH];
  235:   FILE       *dfp;
  236:   int         tmp_num, first_stu, file_specified, directory_specified;
  237:   int         ForWhat  = F_SECTIONS, pagebreak=1,
  238:               StartSec = 1, EndSec = 1, StartSet = 1, EndSet = 1;
  239:   char        StuNum[MAX_STUDENT_NUMBER+1];
  240:   char        out_filename[FILE_NAME_LENGTH],out_directory[FILE_NAME_LENGTH];
  241:   char        cmd[SMALL_LINE_BUFFER], *ans_str;
  242:   
  243: /*  qz --> tex    -T */
  244: /*  qz --> html   -Ha */
  245: /*  qz --> ascii  -Ab */
  246: /*     answer   only   a */
  247: /*     both            b */
  248: /*        for entire class            -C       */
  249: /*        for a range of sections     -Sec 2:6 */
  250: /*        for a section               -Sec 2   */
  251: /*        for a student               -Stu 12345678 */
  252: /*           output a set             -Set 2     */
  253: /*           output a range of sets   -Set 1:6   */
  254: 
  255: /*  default */
  256:   Parsemode_f = TeX_MODE; ForWhat = F_SECTIONS; outputFlag=Q_ONLY;
  257:   file_specified=0;
  258:   out_filename[0]='\0';
  259:   directory_specified=0;
  260:   out_directory[0]='\0';
  261:   for( progname = *argv++; --argc; argv++) {
  262:     if ( argv[0][0] == '-' ) {
  263:        switch(argv[0][1]) {
  264:         case 'T':  Parsemode_f = TeX_MODE;
  265:                    outputFlag=(argv[0][2] == 'a' ? A_ONLY :(argv[0][2] == 'b' ? QA_BOTH : Q_ONLY));
  266:                    break;
  267:         case 'H':  Parsemode_f = HTML_MODE;
  268:                    outputFlag=(argv[0][2] == 'a' ? A_ONLY :(argv[0][2] == 'b' ? QA_BOTH : Q_ONLY));
  269:                    break;
  270:         case 'A':  Parsemode_f = ASCII_MODE;
  271:                    outputFlag=(argv[0][2] == 'a' ? A_ONLY :(argv[0][2] == 'b' ? QA_BOTH : Q_ONLY));
  272:                    break;
  273:         case 'S':  
  274:         case 's':  if( strncasecmp(argv[0],"-sec",4) == 0 ) {
  275:                      tmp_num = scan_num(argv[1],&StartSec,&EndSec);
  276:                      if( tmp_num ==  1 ) { EndSec = StartSec;  }
  277:                      ForWhat = F_SECTIONS;
  278:                    } else if( strncasecmp(argv[0],"-stu",4) == 0 ) {
  279:                      for(ii=0;ii<MAX_STUDENT_NUMBER;ii++) {
  280:                        StuNum[ii] = argv[1][ii];
  281:                      }
  282:                      StuNum[ii]=0;
  283:                      ForWhat = F_STUDENT;
  284:                    } else if( strncasecmp(argv[0],"-set",4) == 0 ) {
  285:                      tmp_num = scan_num(argv[1],&StartSet,&EndSet);
  286:                      if( tmp_num ==  1 ) { EndSet = StartSet;  }
  287:                    } else {
  288:                      usage();
  289:                    }
  290:                    break;
  291:         case 'c': strcpy(path, argv[1]);
  292:                   if(capa_access(path, F_OK) == -1) {
  293:                     inputNotOK = 1;
  294:                   } else {
  295:                     inputNotOK = 0;
  296:                   }
  297:                   break;
  298:         case 'o':
  299: 	  if (argc == 1 || argv[1][0] == '-') {
  300: 	      usage(); return 0;
  301: 	  } else {
  302: 	    strcpy(out_filename, argv[1]);  file_specified=1; break;
  303: 	  }
  304:         case 'd':
  305: 	  if (argc == 1 || argv[1][0] == '-') {
  306: 	      usage(); return 0; break;
  307: 	  } else {
  308: 	    strcpy(out_directory, argv[1]);  directory_specified=1; break;
  309: 	  } 
  310:         case 'n':
  311:           pagebreak=0;break;
  312:         case 'u': case 'h': default: usage(); return(0); break;
  313:        }
  314:      }
  315:    }
  316:    printf(" %s running in %s mode, %s for %s, ", progname,
  317:      (Parsemode_f == TeX_MODE ? "TeX" : (Parsemode_f == ASCII_MODE ? "ASCII" : "HTML")),
  318:      (outputFlag==A_ONLY ? "answer only" : (outputFlag==QA_BOTH? "question and answer" : "question only")),
  319:      (ForWhat == F_STUDENT ? "a student" : "section" ) );
  320:    if( ForWhat == F_STUDENT ) {
  321:      printf(" for student %s,",StuNum);
  322:    } else {
  323:      if(StartSec==EndSec) { 
  324:        printf(" for section %d,", StartSec); 
  325:      } 
  326:      else { 
  327:        printf(" from section %d to %d,",StartSec, EndSec);
  328:      }
  329:    }
  330:    if(StartSet==EndSet) { printf(" set %d\n",StartSet); } else { printf(" from  set %d to %d\n", StartSet, EndSet); }
  331:    
  332:    while ( inputNotOK ) {
  333:      puts("Enter the ABSOLUTE path of class");
  334:      scanf("%s", path);
  335:      if( capa_access(path, F_OK) == -1 ) {
  336:      } else {
  337:         sprintf(filename,"%s/classl",path);
  338:         if( capa_access(filename, F_OK) == -1 ) {
  339:           puts("There isn't a classl file in this CLASS directory\nPlease Specify another class");
  340:         } else {
  341:           inputNotOK = 0;
  342:         }
  343:      }
  344:    }
  345: 
  346:    if( (ForWhat == F_STUDENT) && strlen(StuNum) == 0 ) {
  347:      inputNotOK = 1;
  348:      while ( inputNotOK ) {
  349:        puts("Enter student number"); scanf("%s", StuNum);
  350:        if( strlen(StuNum) == MAX_STUDENT_NUMBER ) { inputNotOK = 0; }
  351:      }
  352:    }
  353:    if ( file_specified == 0) {
  354:      if ( directory_specified == 0) {
  355:        switch( Parsemode_f ) {
  356:        case TeX_MODE:   sprintf(filename,"%s/TeX",path);   break;
  357:        case ASCII_MODE: sprintf(filename,"%s/ASCII",path); break;
  358:        case HTML_MODE:  sprintf(filename,"%s/HTML",path);  break;
  359:        default:         sprintf(filename,"%s/TeX",path); Parsemode_f = TeX_MODE; break;
  360:        }
  361:      } else {
  362:        sprintf(filename,"%s",out_directory);
  363:      }
  364:      if( capa_access(filename, F_OK) == -1 ) { 
  365:        if ( mkdir(filename, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) {
  366: 	 printf("Unable to write to %s\n",filename);
  367: 	 printf("Please check this directory and run %s again.\n",progname);
  368: 	 return(-1);
  369:        }
  370:      }
  371: 
  372:    } else {
  373:      if ( directory_specified == 0) {
  374:      } else {
  375:        sprintf(filename,"%s",out_directory);
  376:      }
  377:    }
  378:    chdir(path);
  379: 
  380:    if ( ForWhat == F_SECTIONS ) {
  381:      T_dates* dates;
  382:      T_header header;
  383:      for(ii=StartSet;ii<=EndSet;ii++) {
  384:        if (capa_get_header(&header,ii)<0) {
  385: 	 setdb_error(ii);
  386:        }
  387:        free_header(&header);
  388:        if (capa_get_all_dates(ii,&dates)<0) {
  389: 	 setdb_error(ii);
  390:        } 
  391:        free_dates(dates);
  392:      }
  393:    }
  394: 
  395:    if( ForWhat == F_STUDENT ) {
  396:      result = capa_get_student(StuNum, &a_student);
  397:      if ( result == 0 ) {
  398:        fprintf(stderr,"Unable to find student %s in %s/classl",StuNum,path);
  399:        exit(-1);
  400:      } else {
  401:        if (result == -1 ) {
  402: 	 fprintf(stderr,"Unable to read %s/classl",path);
  403: 	 exit(-1);
  404:        }
  405:      }
  406:      if ( file_specified == 0) {
  407:        if ( directory_specified == 0) {
  408: 	 switch( Parsemode_f ) {
  409:          case TeX_MODE: sprintf(filename,"TeX/%s.tex",StuNum);  break;
  410:          case ASCII_MODE: sprintf(filename,"ASCII/%s.ascii",StuNum); break;
  411:          case HTML_MODE:  sprintf(filename,"HTML/%s.html",StuNum);   break;
  412: 	 }
  413:        } else {
  414: 	 switch( Parsemode_f ) {
  415:          case TeX_MODE: sprintf(filename,"%s/%s.tex",out_directory,StuNum); break;
  416:          case ASCII_MODE: sprintf(filename,"%s/%s.ascii",out_directory,StuNum); break;
  417:          case HTML_MODE:  sprintf(filename,"%s/%s.html",out_directory,StuNum); break;
  418: 	 }
  419:        }
  420:      } else {
  421:        if (directory_specified == 0 ) {
  422: 	 sprintf(filename,"%s",out_filename);
  423:        } else {
  424: 	 sprintf(filename,"%s/%s",out_directory,out_filename);
  425:        }
  426:      }
  427:      switch ( Parsemode_f ) {
  428:      case TeX_MODE: sprintf(cmd, "cp TeXheader %s\n",filename); system(cmd); break;
  429:      default: sprintf(cmd,"rm %s\n",filename);system(cmd); break;
  430:      }
  431:      if((dfp=fopen(filename,"a"))==NULL)  { 
  432:        fprintf(stdout,"File error! Cannot open [%s].\n",filename);  
  433:        return -1; 
  434:      }
  435:      for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
  436:        result = capa_parse(setIdx, &first_prob, StuNum, &q_cnt, NULL);
  437:        if ( result != 0 ) { p = first_prob;
  438: 	  switch(outputFlag) {
  439: 	    case  Q_ONLY: 
  440: 	                 if( StartText_p != NULL) {
  441:                             fprintf(dfp, "%s", StartText_p); fflush(dfp);
  442:                           }
  443: 	                  for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) {
  444: 	                    fprintf(dfp, "%s", p->question); p = p->next;
  445:                           } 
  446:                           if( EndText_p != NULL) {
  447:                             fprintf(dfp, "%s", EndText_p); fflush(dfp);
  448:                           }
  449:                           break;
  450: 	    case  A_ONLY:
  451: 	                print_header(Parsemode_f, dfp,a_student.s_sec,setIdx,a_student.s_nm, StuNum);
  452: 		        for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) {
  453: 	                   print_begin_item(Parsemode_f,dfp,q_idx+1);
  454: 	                   ans_str = answers_string(Parsemode_f,p);
  455: 	                   fprintf(dfp, "%s",ans_str); fflush(dfp);
  456: 	                   capa_mfree((char *)ans_str);
  457:                            p = p->next;
  458:                         }
  459:                         print_footer(Parsemode_f, dfp);
  460: 		        break;
  461: 	    case  QA_BOTH:
  462:                     if( StartText_p != NULL ) {
  463:                       fprintf(dfp, "%s", StartText_p);
  464:                     }
  465: 		    for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) {
  466: 		       fprintf(dfp, "%s", p->question);  fflush(dfp);
  467: 		       ans_str = answers_string(Parsemode_f,p);
  468: 	               fprintf(dfp, "%s",ans_str); fflush(dfp);
  469: 	               capa_mfree((char *)ans_str);
  470:                        p = p->next;
  471:                     }  
  472:                     if( EndText_p != NULL ) {
  473:                       fprintf(dfp, "%s", EndText_p);
  474:                     }
  475:                     break;
  476:            }
  477:               
  478:         }
  479:         free_problems(first_prob);
  480:         if( setIdx < EndSet ) { 
  481:           if( Parsemode_f == TeX_MODE && pagebreak ) { 
  482: 	    fprintf(dfp, "\\clearpage\n\\setcounter{page}{1}\n"); 
  483: 	  } else {
  484: 	    printf("\n"); 
  485: 	  }
  486: 	}
  487: 	if( ErrorMsg_count > 0 ) {
  488:            printf("%s",ErrorMsg_p);
  489:         }
  490:      }
  491:      fflush(dfp); fclose(dfp);
  492: 
  493:      switch( Parsemode_f ) {
  494:        case TeX_MODE: sprintf(cmd, "cat TeXfooter >> %s\n", filename); system(cmd); break;
  495:      }
  496:      printf("\n  DONE Student %s\n",StuNum);
  497: } else {  /*   For section(s) */
  498:     for(sectionIdx = StartSec; sectionIdx <= EndSec; sectionIdx++ ) { 
  499:       num_students = capa_sorted_section(&students_p, sectionIdx);
  500:       printf("Section %2d: %d students\n",sectionIdx,num_students);
  501:       if( num_students > 0 ) {
  502:         for(setIdx=StartSet; setIdx <= EndSet; setIdx++) {
  503:           
  504: 	  if (directory_specified == 0 ) {
  505: 	    switch( Parsemode_f ) {
  506: 	      case TeX_MODE: sprintf(cmd, "cp TeXheader TeX/section%d-set%d.tex\n", sectionIdx,setIdx); 
  507: 	        system(cmd);
  508: 	        sprintf(filename,"TeX/section%d-set%d.tex",sectionIdx,setIdx);  break;
  509: 	      case ASCII_MODE: sprintf(filename,"ASCII/section%d-set%d.ascii",sectionIdx,setIdx); break;
  510: 	      case HTML_MODE:  sprintf(filename,"HTML/section%d-set%d.text",sectionIdx,setIdx); break;
  511: 	    }
  512: 	  } else {
  513: 	    switch( Parsemode_f ) {
  514:                case TeX_MODE: sprintf(cmd, "cp TeXheader %s/section%d-set%d.tex\n", out_directory,
  515: 				      sectionIdx,setIdx); 
  516:                               system(cmd);
  517:                               sprintf(filename,"%s/section%d-set%d.tex",out_directory,
  518: 				      sectionIdx,setIdx);  break;
  519:                case ASCII_MODE: sprintf(filename,"%s/section%d-set%d.ascii",out_directory,
  520: 					sectionIdx,setIdx); break;
  521:                case HTML_MODE:  sprintf(filename,"%s/section%d-set%d.text",out_directory,
  522: 					sectionIdx,setIdx); break;
  523: 	    }
  524: 	  }
  525:           if((dfp=fopen(filename,"a"))==NULL)  { printf("File error\n");  return -1; }
  526:           for(s_p = students_p,first_stu=1; s_p ; s_p = s_p->s_next ) {
  527:             s_p->s_sn[MAX_STUDENT_NUMBER]=0;
  528:             printf("    Student: %s%s   set %d",s_p->s_nm,s_p->s_sn,setIdx);
  529:             result = capa_parse(setIdx, &first_prob, s_p->s_sn, &q_cnt, NULL);
  530:             if ( result != 0 ) {
  531:                 p = first_prob;
  532: 	        switch(outputFlag) {
  533: 	          case  Q_ONLY:
  534:                       if( StartText_p != NULL ) {
  535:                             fprintf(dfp, "%s", StartText_p); fflush(dfp);
  536:                       } 
  537:                       for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) {
  538: 	                 fprintf(dfp, "%s", p->question); fflush(dfp); p = p->next;
  539:                       }
  540:                       if( EndText_p != NULL ) {
  541:                             fprintf(dfp, "%s", EndText_p); fflush(dfp);
  542:                       } 
  543:                       break;
  544: 		  case  A_ONLY:
  545: 		      print_header(Parsemode_f,dfp,s_p->s_sec,setIdx,s_p->s_nm,s_p->s_sn);
  546: 		      for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) {
  547: 	                 print_begin_item(Parsemode_f,dfp,q_idx+1);
  548: 	                 ans_str = answers_string(Parsemode_f,p);
  549: 	                 fprintf(dfp, "%s",ans_str); fflush(dfp);
  550: 	                 capa_mfree((char *)ans_str);
  551:                          p = p->next;
  552:                       }
  553:                       print_footer(Parsemode_f,dfp);
  554: 		      break;
  555: 		  case  QA_BOTH:
  556:                       if( StartText_p != NULL ) {
  557:                             fprintf(dfp, "%s", StartText_p); fflush(dfp);
  558:                       } 
  559: 		      for( q_idx = 0; q_idx < q_cnt; printf("."),fflush(stdout), q_idx++ ) {
  560: 	                 fprintf(dfp, "%s", p->question);  fflush(dfp);
  561: 	                 ans_str = answers_string(Parsemode_f,p);
  562: 	                 fprintf(dfp, "%s",ans_str); fflush(dfp);
  563: 	                 capa_mfree((char *)ans_str);
  564:                          p = p->next;
  565:                       }
  566:                       if( ( EndText_p != NULL) ) {
  567:                          fprintf(dfp, "%s", EndText_p);
  568:                       }
  569:                       break;
  570:                 }
  571:                 if( s_p->s_next != NULL ) {    
  572:                   if(Parsemode_f == TeX_MODE && pagebreak) {
  573:                         fprintf(dfp, "\\clearpage\n\\setcounter{page}{1}\n"); fflush(dfp); 
  574:                   }
  575:                   printf("\n"); 
  576:                 }
  577:                 free_problems(first_prob);
  578:               }
  579:             }
  580:             fflush(dfp); fclose(dfp);
  581:             if(Parsemode_f == TeX_MODE) {
  582: 	      if (directory_specified==0) {
  583: 		sprintf(cmd, "cat TeXfooter >> TeX/section%d-set%d.tex\n", sectionIdx,setIdx); system(cmd);
  584: 	      } else {
  585: 		sprintf(cmd, "cat TeXfooter >> %s/section%d-set%d.tex\n", out_directory,
  586: 			sectionIdx,setIdx); system(cmd);
  587: 	      }
  588: 	    }
  589: 	    printf("\n  DONE set%2d\n",setIdx);
  590: 	}
  591: 	
  592:       }
  593:       printf("\n  DONE section%2d\n",sectionIdx);
  594:     }
  595:     free_students(students_p);
  596:    }
  597:    printf("ALL DONE\n");
  598:    return (0);
  599: }
  600: 
  601: 

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