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