File:
[LON-CAPA] /
capa /
capa51 /
pProj /
capaSubjective.c
Revision
1.2:
download - view:
text,
annotated -
select for diffs
Mon Jan 31 18:34:13 2000 UTC (24 years, 6 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- fixed y2k bug in capadiscuss
- fixed section handling bug in capadiscuss
- fixed errors with invalid set.db in capastats
- added MoveUp and MoveDown buttons to handling of due dates in
quizzer
- scorer no longer give error on first run
- fixed bug in cgiutils, invalid dynamic allocation of memory (off by 1)
- fixed sig figs on an answer of 0
- fixed allocation of memory for filename in subjective file creation
1: #include "capaCommon.h"
2: #include <sys/stat.h>
3: #include <sys/types.h>
4: #include <fcntl.h>
5: #include <unistd.h>
6: #include <ctype.h>
7:
8: char* strtoupper(char* source)
9: {
10: char* result;
11: int i,len=strlen(source);
12: result=capa_malloc(len+2,1);
13: for(i=0;i<len;i++) result[i]=toupper(source[i]);
14: result[i]='\0';
15: return result;
16: }
17:
18: int capa_set_subjective (int set,int problem,char *student_num,char* response)
19: {
20: char buf[FILE_NAME_LENGTH],*upperstunum;
21: FILE *responsefile;
22:
23: sprintf(buf,"records/set%d",set);
24: if( capa_access(buf, F_OK) == -1 ) {
25: if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -1; }
26: }
27:
28: sprintf(buf,"records/set%d/problem%d",set,problem);
29: if( capa_access(buf, F_OK) == -1 ) {
30: if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -2; }
31: }
32:
33: upperstunum=strtoupper(student_num);
34: sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
35: if ((responsefile=fopen(buf,"w"))==NULL) { return -3; }
36:
37: fwrite(response,strlen(response),1,responsefile);
38: fclose(responsefile);
39: return 0;
40: }
41:
42: char* capa_get_subjective (int set,int problem,char *student_num)
43: {
44: char buf[FILE_NAME_LENGTH],*upperstunum,*response;
45: FILE *responsefile;
46: long length;
47:
48: upperstunum=strtoupper(student_num);
49: sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
50: if ((responsefile=fopen(buf,"r"))==NULL) { return NULL; }
51: fseek(responsefile,0,SEEK_END);
52: length=ftell(responsefile);
53: rewind(responsefile);
54: response=capa_malloc(length+1,1);
55: fread(response,length,1,responsefile);
56: response[length]='\0';
57: return response;
58: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>