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, 3 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

#include "capaCommon.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>

char* strtoupper(char* source)
{
  char* result;
  int i,len=strlen(source);
  result=capa_malloc(len+2,1);
  for(i=0;i<len;i++) result[i]=toupper(source[i]);
  result[i]='\0';
  return result;
}

int capa_set_subjective (int set,int problem,char *student_num,char* response)
{
  char buf[FILE_NAME_LENGTH],*upperstunum;
  FILE *responsefile;

  sprintf(buf,"records/set%d",set);
  if( capa_access(buf, F_OK) == -1 ) { 
    if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -1; }
  }

  sprintf(buf,"records/set%d/problem%d",set,problem);
  if( capa_access(buf, F_OK) == -1 ) { 
    if ( mkdir(buf, S_IREAD | S_IWRITE | S_IEXEC ) == -1 ) { return -2; }
  }

  upperstunum=strtoupper(student_num);
  sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
  if ((responsefile=fopen(buf,"w"))==NULL)  { return -3; }
  
  fwrite(response,strlen(response),1,responsefile);
  fclose(responsefile);
  return 0;
}

char* capa_get_subjective (int set,int problem,char *student_num)
{
  char buf[FILE_NAME_LENGTH],*upperstunum,*response;
  FILE *responsefile;
  long length;

  upperstunum=strtoupper(student_num);
  sprintf(buf,"records/set%d/problem%d/%s",set,problem,upperstunum);
  if ((responsefile=fopen(buf,"r"))==NULL)  { return NULL; }
  fseek(responsefile,0,SEEK_END);
  length=ftell(responsefile);
  rewind(responsefile);
  response=capa_malloc(length+1,1);
  fread(response,length,1,responsefile);
  response[length]='\0';
  return response;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>