Annotation of capa/capa51/pProj/setdbheader.c, revision 1.2

1.2     ! albertel    1: /* broken start on an command line method for setting the DB Header
        !             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: 
1.1       albertel   19: #include <stdio.h>
                     20: #include <ctype.h>
                     21: #include <unistd.h>
                     22: #include "capaCommon.h"
                     23: 
                     24: void printUsage(char* progname)
                     25: {
                     26:   printf("USAGE: %s [-opendate opendate] [-opentime opentime] \n\
                     27:            [-duedate duedate]   [-duetime duetime]  \n\
                     28:            [-ansdate ansdate]   [-anstime anstime]  \n\
                     29:            [-set setnumber] [-dir class-directory] [-h] \n", progname);
                     30:   printf("       -h              : prints this message\n");
                     31:   printf("       CAPA version %s, %s\n",CAPA_VER,COMPILE_DATE);
                     32: }
                     33: 
                     34: /*stolen from quizzer.funct.c*/
                     35: int checkDate(char* date)
                     36: { 
                     37:   if (date==NULL) goto wrong;
                     38:   if (strlen(date)!=8) goto wrong;
                     39: 
                     40:   switch(date[0]) {
                     41:   case '0':
                     42:     if (!isdigit(date[1])) goto wrong;
                     43:     break;
                     44:   case '1':
                     45:     if (!(
                     46: 	  (date[1]=='0') ||
                     47: 	  (date[1]=='1') ||
                     48: 	  (date[1]=='2')
                     49: 	  )
                     50: 	) goto wrong;
                     51:     break;
                     52:   case '2':
                     53:     if (!(
                     54: 	  (date[1]=='0') ||
                     55: 	  (date[1]=='1') ||
                     56: 	  (date[1]=='2') ||
                     57: 	  (date[1]=='3') ||
                     58: 	  (date[1]=='4')
                     59: 	  )
                     60: 	) goto wrong;
                     61:     break;
                     62:   default:
                     63:     goto wrong;
                     64:     break;
                     65:   }
                     66:   if (date[2] != '/') goto wrong;
                     67:   switch(date[3]) {
                     68:   case '0':
                     69:   case '1':
                     70:   case '2':
                     71:     if (!isdigit(date[4])) goto wrong;
                     72:     break;
                     73:   case '3':
                     74:     if (!(
                     75: 	  (date[4]=='0') ||
                     76: 	  (date[4]=='1') 
                     77: 	  )
                     78: 	) goto wrong;
                     79:     break;
                     80:   default:
                     81:     goto wrong;
                     82:     break;
                     83:   }
                     84:   if (date[5] != '/') goto wrong;
                     85:   if (!isdigit(date[6])) goto wrong;
                     86:   if (!isdigit(date[7])) goto wrong;
                     87:   goto right;
                     88: wrong:
                     89:   return 0;
                     90: right:
                     91:   return 1;
                     92: }
                     93: 
                     94: /* stolen from quizzer.funct.c*/
                     95: int checkTime(char* time)
                     96: {
                     97:   if (time==NULL) goto wrong;
                     98:   if (strlen(time)!=5) goto wrong;
                     99: 
                    100:   switch(time[0]) {
                    101:   case '0':
                    102:     if (!isdigit(time[1])) goto wrong;
                    103:     break;
                    104:   case '1':
                    105:     if (!(isdigit(time[1])))
                    106:       goto wrong;
                    107:     break;
                    108:   case '2':
                    109:     switch(time[1])
                    110:       {
                    111:       case '0':
                    112:       case '1':
                    113:       case '2':
                    114:       case '3':
                    115:       case '4':
                    116: 	break;
                    117:       default:
                    118: 	goto wrong;
                    119: 	break;
                    120:       }
                    121:     break;
                    122:   default:
                    123:     goto wrong;
                    124:     break;
                    125:   }
                    126:   if (time[2] != ':') goto wrong;
                    127:   switch (time[3]) {
                    128:   case '0':
                    129:   case '1':
                    130:   case '2':
                    131:   case '3':
                    132:   case '4':
                    133:   case '5':
                    134:     break;
                    135:   default:
                    136:     goto wrong;
                    137:     break;
                    138:   }
                    139:   if (!isdigit(time[4])) goto wrong;
                    140:   goto right;
                    141:   
                    142: wrong:
                    143:   return 0;
                    144: right:
                    145:   return 1;
                    146: }
                    147: 
                    148: int main(int argc, char** argv) 
                    149: {
                    150:   char *openDate="01/01/98",*openTime="01/01/98",
                    151:     *dueDate="01/01/99",*dueTime="01/01/99",
                    152:     *ansDate="01/01/99",*ansTime="01/01/99";
                    153:   char *directory=NULL,*class=NULL,cwd[FILE_NAME_LENGTH];
                    154:   char *problemWeights;
                    155:   char *partialCredit;
                    156:   int numQuestions=0,set=1,result,i=0;  
                    157:   T_header header;
                    158:   T_student student;
                    159:   Problem_t *headProblem,*currentProblem;
                    160: 
                    161:   for(i=1;i<argc-1;i++) {
                    162:     if        (0==strcmp(argv[i],"-opendate")  ) { if (checkDate(argv[i+1])) openDate=argv[i+1];
                    163:     } else if (0==strcmp(argv[i],"-opentime")  ) { if (checkTime(argv[i+1])) openTime=argv[i+1];
                    164:     } else if (0==strcmp(argv[i],"-duedate")   ) { if (checkDate(argv[i+1])) dueDate=argv[i+1];
                    165:     } else if (0==strcmp(argv[i],"-duetime")   ) { if (checkTime(argv[i+1])) dueTime=argv[i+1];
                    166:     } else if (0==strcmp(argv[i],"-answerdate")) { if (checkDate(argv[i+1])) ansDate=argv[i+1];
                    167:     } else if (0==strcmp(argv[i],"-answertime")) { if (checkTime(argv[i+1])) ansTime=argv[i+1];
                    168:     } else if (0==strcmp(argv[i],"-set")       ) { set=atoi(argv[i+1]); 
                    169:     } else if (0==strcmp(argv[i],"-dir")       ) { directory=(argv[i+1]); 
                    170:     } else { printUsage(argv[0]);exit(0); }
                    171:   }
                    172: 
                    173:   if (directory) { chdir(directory); }
                    174: 
                    175: #if defined(NeXT) || defined(linux)
                    176:    class = getwd(cwd);
                    177:    if( class == NULL ) { class = cwd; }
                    178: #else
                    179:    class = getcwd(NULL,255);   
                    180: #endif
                    181: 
                    182:   printf("Creating set%d.db file in %s/records",set,class);
                    183: 
                    184:   result=capa_pick_student(0,&student);
                    185:   if (result==-1 || result==0 ) {
                    186:     printf("Unable to find a classl file.\n");
                    187:     exit(-1);
                    188:   }
                    189:   
                    190:   result = capa_parse(set,&headProblem,student.s_sn,&numQuestions);
                    191:   if (result==-1) {
                    192:     printf("Unable to parse the set.\n");
                    193:     exit(-2);
                    194:   }
                    195:   
                    196:   i=0;
                    197:   problemWeights=capa_malloc(numQuestions, sizeof(char));
                    198:   partialCredit=capa_malloc(numQuestions, sizeof(char));
                    199:   currentProblem=headProblem;
                    200:   while (currentProblem!=NULL) {
                    201:     problemWeights[i]=((char)(currentProblem->weight))+'0';
                    202:     partialCredit[i]=((char)(currentProblem->partial_cdt))+'0';
                    203:     currentProblem=currentProblem->next;
                    204:     i++;
                    205:   }
                    206:   
                    207:   sprintf(header.open_date,"%s %s",openDate,openTime);
                    208:   sprintf(header.due_date, "%s %s",dueDate, dueTime);
                    209:   sprintf(header.answer_date,"%s %s",ansDate,ansTime);
                    210:   sprintf(header.num_questions,"%d",numQuestions);
                    211:   
                    212:   result=capa_set_header(&header,set,problemWeights,partialCredit);
                    213: 
                    214:   return 0;
                    215: }
                    216: 
                    217: 
                    218: 
                    219: 
                    220: 

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