File:  [LON-CAPA] / capa / capa51 / pProj / allcapaid.c
Revision 1.5: download - view: text, annotated - select for diffs
Wed Jul 12 15:57:08 2000 UTC (23 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version5-1-2-first_release, HEAD
- finished up GPL notices

    1: /* Generate all CAPA Ids for a class
    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,
   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: */
   24: 
   25: /* ========================================================================== */
   26: /*            allcapaid.c    created by Isaac Tsai                            */
   27: /**************************************************************************** */
   28: #ifdef NeXT
   29: #include <stdlib.h>
   30: #include <sys/types.h>
   31: #include <sys/stat.h>  
   32: #else
   33: #include <malloc.h>
   34: double atof();
   35: #endif
   36: 
   37: #include <stdio.h>
   38: #include <ctype.h>
   39: #include <sys/types.h>
   40: #include <sys/stat.h>  
   41:  
   42: #include <signal.h>
   43: #include <time.h>
   44: #include <math.h>
   45: #include <string.h>
   46: #ifdef NeXT
   47: #include <bsd/curses.h>
   48: #else
   49: #include <curses.h>
   50: #endif
   51: #define   YES    1
   52: 
   53: #include "capaCommon.h"
   54: #include "ranlib.h"
   55: 
   56: char  *progname;
   57: 
   58: /* filter out the number to be [1:999] */
   59: int  scan_num(char *num_str,int *first, int *second) {
   60:   char  tmp_str[SMALL_LINE_BUFFER], *ch;
   61:   int   ii=0, a_num, b_num, result=0;
   62:   
   63:   ch = num_str;
   64:   tmp_str[ii] = 0;
   65:   while( isspace(*ch) ) ch++;
   66:   while(isdigit(*ch)) { tmp_str[ii++] = *ch; ch++; }
   67:   tmp_str[ii] = 0;
   68:   sscanf(tmp_str,"%d",&a_num);
   69:   if( a_num < 0 || a_num > 999 ) a_num = 1;
   70:   *first = a_num;
   71:   result = 1;
   72:   while( isspace(*ch) ) ch++;
   73:   if( *ch == ':' ) {
   74:     ch++;
   75:     while( isspace(*ch) ) ch++;
   76:     ii=0; tmp_str[ii] = 0;
   77:     while( isdigit(*ch) ) { tmp_str[ii++] = *ch; ch++; }
   78:     tmp_str[ii] = 0;
   79:     sscanf(tmp_str,"%d",&b_num);
   80:     if( b_num < 0 || b_num > 999 ) b_num = 1;
   81:     if( a_num > b_num )           b_num = a_num;
   82:     *second = b_num;
   83:     result = 2;
   84:   }
   85:   return (result);
   86: }
   87: 
   88: void print_capaidplus (FILE *out,char* stunum,int set,int plus) 
   89: {
   90:   char fmt[SMALL_LINE_BUFFER];
   91:   sprintf(fmt,"%%%dc",4+plus);
   92:   fprintf(out,"%s ", capa_id_plus(stunum, set, plus));
   93: }
   94: 
   95: void print_capaidplus_header1(FILE *dfp,int StartSet,int EndSet,int plus)
   96: {
   97:   int pluscnt,setIdx;
   98:   for(setIdx = StartSet; setIdx <= EndSet; setIdx++)   
   99:     {
  100:       fprintf(dfp,"%3d",setIdx);
  101:       for(pluscnt=0; pluscnt < (plus+2); pluscnt++)
  102: 	fprintf(dfp," ");
  103:     }
  104: }
  105: 
  106: void print_capaidplus_header2(FILE *dfp,int StartSet,int EndSet,int plus)
  107: {
  108:   int setIdx,pluscnt;
  109:   for(setIdx = StartSet; setIdx <= EndSet; setIdx++) {
  110:     for(pluscnt=0; pluscnt < (plus+4); pluscnt++)
  111:       fprintf(dfp,"-");
  112:     fprintf(dfp,"|");
  113:   }
  114: }
  115: 
  116: void usage()
  117: {
  118:   printf("USAGE: %s [-s start-set] [-e end-set] [-stu student-number] [-c class-directory] [-d output-directory] [-h] [-i] [-p number] [-sec [n|n:m]]\n", progname);
  119:   printf("       start-set : default 1\n");
  120:   printf("       end-set   : default 10\n");
  121:   printf("       student-number  : no default\n");
  122:   printf("       class-directory : no default\n");
  123:   printf("       output-directory: class-directory/capaID\n");
  124:   printf("       -Sec 3          : for section 3\n");
  125:   printf("       -Sec 3:7        : from section 3 to section 7\n");
  126:   printf("       -i              : don't create files, print to the screen\n");
  127:   printf("       -p 2            : output 6 charatcer capaidplus instead of capaid\n");
  128:   printf("       -checkopen      : check if set is open, fail if it isn't.\n");
  129:   printf("       -checkdue       : check if set is due, fail if it isn't.\n");
  130:   printf("       -checkans       : check if set's answers are available, fail if they aren't.\n");
  131:   printf("       -h              : prints this message\n");
  132:   printf("       CAPA version %s, %s\n",CAPA_VER,COMPILE_DATE);
  133:   printf("       CAPA is released under the GNU GPL v2 see COPYING for details.\n");
  134: }
  135: #define  F_CLASS       1
  136: #define  F_SECTIONS    2
  137: #define  F_STUDENT     3
  138: int main (int argc, char  **argv) 
  139: {
  140:   T_student  *students_p,*s_p,student_data;
  141:   int         i, setIdx, numStudents, count, tmp_num, StartSec=1,EndSec=999;
  142:   int         StartSet = 1, EndSet = 10, classnameOK=0,outputDir=0,plus=0;
  143:   int         SecCntArry[MAX_SECTION_COUNT], sectionIdx;   
  144:   char        filename[MAX_BUFFER_SIZE], path[MAX_BUFFER_SIZE], 
  145:     outputPath[MAX_BUFFER_SIZE], fullpath[MAX_BUFFER_SIZE];
  146:   char        StuNum[MAX_STUDENT_NUMBER+1], fmt[16];
  147:   int         ForWhat=F_CLASS, interactive=0,CheckOpen=0,CheckDue=0,CheckAns=0;
  148:   FILE       *dfp;
  149:   
  150:   if( argc == 0 ) {
  151:     usage();
  152:     exit(0);
  153:   }
  154:   
  155:   for( progname = *argv++; --argc; argv++) {
  156:     if ( argv[0][0] == '-' && (strlen(argv[0]) > 1 ) ) {
  157:       switch(argv[0][1]) {
  158:       case 'S':
  159:       case 's':
  160: 	if( strncasecmp(argv[0],"-stu",4) == 0 ) {
  161: 	  for(i=0;i<MAX_STUDENT_NUMBER;i++) {
  162: 	    StuNum[i] = argv[1][i];
  163: 	  }
  164: 	  StuNum[i]=0;
  165: 	  ForWhat = F_STUDENT;
  166: 	} else if( strncasecmp(argv[0],"-sec",4) == 0 ) {
  167: 	  tmp_num = scan_num(argv[1],&StartSec,&EndSec);
  168: 	  if (tmp_num == 1 ) { EndSec = StartSec;  }
  169: 	  ForWhat = F_SECTIONS;
  170: 	} else if( strncasecmp(argv[0],"-s",2) == 0 ) {
  171: 	  StartSet = atol(argv[1]);
  172: 	  if( StartSet <= 0 ) StartSet = 1;
  173: 	}
  174: 	break;
  175:       case 'p':
  176:         plus = atol(argv[1]);
  177: 	break;
  178:       case 'e':
  179: 	EndSet = atol(argv[1]);
  180: 	if( EndSet > 999 ) EndSet = 99;
  181: 	break;
  182:       case 'c':
  183: 	if (strcmp(argv[0],"-checkopen")==0) { CheckOpen=1; break; }
  184: 	if (strcmp(argv[0],"-checkdue" )==0) { CheckDue=1;  break; }
  185: 	if (strcmp(argv[0],"-checkans" )==0) { CheckAns=1;  break; }
  186: 	strcpy(path,argv[1]);
  187: 	if( capa_access(path, F_OK) == -1 ) {
  188: 	  printf("No such class [%s] please specify it again:\n",path);
  189: 	  classnameOK = 0;
  190: 	} else {
  191: 	  classnameOK = 1;
  192: 	}
  193: 	break;
  194:       case 'i':
  195: 	interactive = 1; 
  196: 	break;
  197:       case 'd':
  198: 	strcpy(outputPath,argv[1]);
  199: 	outputDir=1;
  200: 	break;
  201:       case 'u': case 'h': default:
  202: 	usage(); 
  203: 	exit(0);
  204: 	break;
  205:       }
  206:     }
  207:   }
  208:   if( StartSet > EndSet ) StartSet = EndSet;
  209:   while ( !classnameOK ) {
  210:     puts("Enter the ABSOLUTE path of class from root (/)");
  211:     scanf("%s", path);
  212:     if( capa_access(path, F_OK) == -1 ) {
  213:       printf("No such class, please specify it again:\n");
  214:     } else {
  215:       classnameOK = 1;
  216:     }
  217:   }
  218:   
  219:   if (!interactive) {
  220:     if (outputDir) {
  221:       sprintf(fullpath,"%s",outputPath);
  222:     } else {
  223:       sprintf(fullpath,"%s/capaID",path);
  224:     }
  225:     if( capa_access(fullpath, F_OK) == -1 ) {
  226:       if ( mkdir(fullpath, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) {
  227: 	printf("Unable to write to %s\n",fullpath);
  228: 	printf("Please check this directory and run %s again.\n",progname);
  229: 	return(-1);
  230:       }
  231:     }
  232:   }
  233:   
  234:   chdir(path);
  235:   switch(ForWhat) {
  236:   case F_STUDENT:
  237:     printf("\n");
  238:     for(setIdx = StartSet; setIdx <= EndSet; setIdx++) {
  239:       printf("%4d ", setIdx );
  240:     }
  241:     printf("\n");
  242:     if (CheckOpen || CheckDue || CheckAns) {
  243:       sprintf(fmt,"%%%ds ",plus+4);
  244:       if ( capa_get_student(StuNum,&student_data) == 0 ) {
  245: 	fprintf(stderr,"Unable to find student, %s.\n",StuNum);
  246: 	exit(1);
  247:       }
  248:     }
  249:     for(setIdx = StartSet; setIdx <= EndSet; setIdx++) {
  250:       if ( CheckOpen && ( capa_check_date(CHECK_OPEN_DATE,StuNum,
  251: 					  student_data.s_sec,setIdx) < 0)) {
  252: 	printf(fmt,"Open");continue;
  253:       }
  254:       if ( CheckDue && ( capa_check_date(CHECK_DUE_DATE,StuNum,
  255: 					  student_data.s_sec,setIdx) < 0)) {
  256: 	printf(fmt,"Due");continue;
  257:       }
  258:       if ( CheckAns && ( capa_check_date(CHECK_ANS_DATE,StuNum,
  259: 					  student_data.s_sec,setIdx) < 0)) {
  260: 	printf(fmt,"Ans");continue;
  261:       }
  262:       if (plus) 
  263: 	print_capaidplus(stdout,StuNum,setIdx,plus);
  264:       else 
  265: 	printf("%4d ", capa_PIN(StuNum, setIdx,0) );
  266:     }
  267:     printf("\n"); fflush(stdout);
  268:     break;
  269:   case F_CLASS:
  270:     StartSec=1;EndSec=999;
  271:   case F_SECTIONS:
  272:     if (CheckOpen || CheckDue || CheckAns) {
  273:       printf("Can only check dates in single student mode\n");
  274:     }
  275:     if ((count = capa_get_section_count( SecCntArry )) != 0 ) {
  276:       if (count == -1 ) {
  277: 	printf("classl file not found in %s\n",path);
  278: 	exit (-1);
  279:       }
  280:       for(sectionIdx = StartSec; 
  281: 	  (sectionIdx <= SecCntArry[0]) && (sectionIdx <= EndSec);
  282: 	  sectionIdx++) {
  283: 	if( SecCntArry[sectionIdx] > 0 ) {
  284: 	  if ( interactive ) {
  285: 	    dfp=stdout;
  286: 	  } else {
  287: 	    sprintf(filename,"%s/section%d.capaid",fullpath,sectionIdx);
  288: 	    if((dfp=fopen(filename,"w"))==NULL) {
  289: 	      printf("Unable to create %s\n",filename);
  290: 	      exit(-2);
  291: 	    }
  292: 	  }
  293: 	  
  294: 	  numStudents = capa_get_section(&students_p, sectionIdx);
  295: 	  printf("Section %d, %d students\n",
  296: 		 sectionIdx, numStudents);
  297: 	  
  298: 	  fprintf(dfp,"Section %d   Student    NAME      NUMBER   ",sectionIdx);
  299: 	  if (plus) {
  300: 	    print_capaidplus_header1(dfp,StartSet,EndSet,plus);
  301: 	  } else {
  302: 	    for(setIdx = StartSet; setIdx <= EndSet; setIdx++)   
  303: 	      fprintf(dfp,"%3d  ",setIdx);
  304: 	  }
  305: 	  
  306: 	  fprintf(dfp,"\n");
  307: 	  fprintf(dfp,"------------------------------|----------|");
  308: 	  if (plus) {
  309: 	    print_capaidplus_header2(dfp,StartSet,EndSet,plus);
  310: 	  } else {
  311: 	    for(setIdx = StartSet; setIdx <= EndSet; setIdx++) 
  312: 	      fprintf(dfp,"----|");
  313: 	  }
  314: 	  fprintf(dfp,"\n");
  315: 	  for(s_p = students_p; s_p ; s_p = s_p->s_next ) {
  316: 	    fprintf(dfp,"%s %s  ",s_p->s_nm, s_p->s_sn);
  317: 	    for(setIdx = StartSet; setIdx <= EndSet; setIdx++) {
  318: 	      if (plus) 
  319: 		print_capaidplus(dfp,s_p->s_sn,setIdx,plus);
  320: 	      else 
  321: 		fprintf(dfp,"%4d ", capa_PIN(s_p->s_sn, setIdx,0) );
  322: 	    }
  323: 	    fprintf(dfp,"\n");
  324: 	  }
  325: 	  fflush(dfp);
  326: 	  if (!interactive) fclose(dfp); 
  327: 	}
  328:       }
  329:     }
  330:   }
  331:   return (0);
  332: }
  333: 

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