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