Annotation of capa/capa51/pProj/qzparse.c, revision 1.6

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

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