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