Annotation of capa/capa51/pProj/capaSubjective.c, revision 1.3
1.3 ! albertel 1: /* library to enable getting and setting subjective responses
! 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 "capaCommon.h"
20: #include <sys/stat.h>
21: #include <sys/types.h>
22: #include <fcntl.h>
23: #include <unistd.h>
24: #include <ctype.h>
25:
26: char* strtoupper(char* source)
27: {
28: char* result;
29: int i,len=strlen(source);
1.2 albertel 30: result=capa_malloc(len+2,1);
1.1 albertel 31: for(i=0;i<len;i++) result[i]=toupper(source[i]);
1.2 albertel 32: result[i]='\0';
1.1 albertel 33: return result;
34: }
35:
36: int capa_set_subjective (int set,int problem,char *student_num,char* response)
37: {
38: char buf[FILE_NAME_LENGTH],*upperstunum;
39: FILE *responsefile;
40:
41: sprintf(buf,"records/set%d",set);
42: if( capa_access(buf, F_OK) == -1 ) {
43: if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -1; }
44: }
45:
46: sprintf(buf,"records/set%d/problem%d",set,problem);
47: if( capa_access(buf, F_OK) == -1 ) {
48: if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -2; }
49: }
50:
51: upperstunum=strtoupper(student_num);
52: sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
53: if ((responsefile=fopen(buf,"w"))==NULL) { return -3; }
54:
55: fwrite(response,strlen(response),1,responsefile);
56: fclose(responsefile);
57: return 0;
58: }
59:
60: char* capa_get_subjective (int set,int problem,char *student_num)
61: {
62: char buf[FILE_NAME_LENGTH],*upperstunum,*response;
63: FILE *responsefile;
64: long length;
65:
66: upperstunum=strtoupper(student_num);
67: sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
68: if ((responsefile=fopen(buf,"r"))==NULL) { return NULL; }
69: fseek(responsefile,0,SEEK_END);
70: length=ftell(responsefile);
71: rewind(responsefile);
72: response=capa_malloc(length+1,1);
73: fread(response,length,1,responsefile);
74: response[length]='\0';
75: return response;
76: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>