File:
[LON-CAPA] /
loncom /
homework /
CAPA-converter /
capaCommon.h
Revision
1.6:
download - view:
text,
annotated -
select for diffs
Sun Nov 18 09:40:45 2001 UTC (22 years, 9 months ago) by
albertel
Branches:
MAIN
CVS tags:
HEAD
- added a cache data structure
- new_cache() adds a new cache strutuce and sets that one as the one
being added to.
- delete_cache() deletes the last cache and sets the previous one as
current
- start_cache() turns on caching for the current cache
- stop_cache() turns off caching for the current cache
(Both append_delayed() and send() data are stuck into the current cache)
- added a streams data structure
- allows multiple versions of the output to be generated simultaneously
- send() and flush_delayed() by default put all data into all streams
- send_stream() lets one pick a stream to send data to
- start_streams() starts off all of the streams requested
- end_streams() sends the specified stream out, and free()s the rest
- start_mode_stream end_mode_stream, allows one to change modes on
specific streams, different streams can be in different modes.
- the global var watch_mode can be used to check if a stream has
changed modes, everytime a mode change occurs on a specific stream
the watch_mode var for that stream gets set to zero.
/**********************************************************/
/* This header defines Application Interface to the */
/* CAPA system. It needs capaParser.h and capaToken.h */
/* CAPA version 4.3 */
/* Date Oct 23 1995 */
/* Isaac Tsai */
/* */
/* Get rid of old style structure definition *_t */
/* Make all structure definition begin with T_ */
/* 1997, 1998, 1999 Isaac Tsai */
/**********************************************************/
#ifndef CAPA_COMMON_H
#define CAPA_COMMON_H
#include <stdio.h>
#ifdef linux
#include <stdlib.h>
#endif
#ifdef NeXT
#include <stdlib.h>
#include <libc.h>
#else
#include <malloc.h>
#include <unistd.h>
#endif
#include <math.h>
#include <string.h>
#include <time.h>
#include <sys/fcntl.h> /* lockf() */
#include <sys/file.h> /* flock() */
#include <sys/types.h>
#include <stdarg.h>
#include "capaParser.h"
#ifndef MAX
#define MAX(a,b) ((a>b)? (a):(b))
#endif
#define MAX_SECTION_SIZE 10240 /* Max # of students in the class */
#define MAX_SECTION_COUNT 1024
#define MAX_NAME_CHAR 30 /* Student's name max length */
#define MAX_STUDENT_NUMBER 9 /* Student Number length */
#define MAX_EMAIL_CHAR 40 /* Email address */
#define FILE_NAME_LENGTH 1024
#define MAX_PIN_CHAR 4
#define MAX_BUFFER_SIZE 2048
#define TMP_LINE_LENGTH 2048 /* used to read in log.db set.db dates.db */
#define SMALL_LINE_BUFFER 128 /* used to read classl, active.db */
#define SETDB_BUF_SIZE (256*1024)
/* user input string length now in capaParser.h*/
/*#define ANSWER_STRING_LENG 81*/
/*#define UNIT_STRING_LENG 64*/
#define FORMAT_STRING_LENG 32
/* -------- used in check_date() */
#define CHECK_OPEN_DATE 1
#define CHECK_DUE_DATE 2
#define CHECK_ANS_DATE 3
/******************************************************************************/
/* STRUCTURE FOR THE HEADER OF A DATABASE FILE */
/******************************************************************************/
typedef struct {
char num_questions[FORMAT_STRING_LENG];
char *weight;
char *partial_credit;
} T_header;
/******************************************************************************/
/* STRUCTURE FOR A NORMAL DATABASE FILE ENTRY */
/******************************************************************************/
typedef struct {
char student_number[MAX_STUDENT_NUMBER+1]; /* Student number */
int e_probs;
char *answers; /* String of answers */
char *tries;
} T_entry;
/******************************************************************************/
/* STRUCTURE FOR A STUDENT IN THE STUDENT ARRAY */
/******************************************************************************/
typedef struct _student {
struct _student *s_next;
struct _student *s_prev;
int s_sec;
int s_scores;
char s_key[MAX_NAME_CHAR+MAX_NAME_CHAR+2]; /* sorting key */
char s_sn[MAX_STUDENT_NUMBER+1];
char s_nm[MAX_NAME_CHAR+1];
char s_email[MAX_EMAIL_CHAR+1];
int s_capaid;
} T_student;
/******************************************************************************/
/* STRUCTURE FOR Login dates for a set */
/******************************************************************************/
/*section number DATE_DEFAULTs contains the default dates an assignment is due*/
#define DATE_DEFAULTS 0
#define OPEN_OFFSET 0
#define DUE_OFFSET 17
#define ANSWER_OFFSET 34
#define DATE_LENGTH 16
#define DATE_BUFFER 17
#define OPTION_INHIBIT_RESPONSE 100
#define OPTION_VIEW_PROBLEMS_AFTER_DUE 101
typedef struct _date {
struct _date *s_next;
int section_start;
int section_end;
char open_date[DATE_BUFFER];
char due_date[DATE_BUFFER];
char answer_date[DATE_BUFFER];
char duration[DATE_BUFFER];
int inhibit_response;
int view_problems_after_due;
} T_dates;
/******************************************************************************/
/* STRUCTURE FOR Login history for a student */
/******************************************************************************/
typedef struct {
int count; /* Number of questions */
char *answers; /* String of answers */
} login_history_t;
#define leap_year(yr) ((yr) <= 1752 ? !((yr) % 4) : !((yr) % 4) && (((yr) % 100) || !((yr) % 400)))
#define centuries_since_1700(yr) ((yr) > 1700 ? (yr) / 100 - 17 : 0)
#define quad_centuries_since_1700(yr) ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
#define leap_years_since_year_1(yr) ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
struct dyn_string {
int len;
int max;
char *str;
};
struct dyn_string dyn_out;
struct dyn_string dyn_delayed;
extern int dyn_maxlen;
extern char *import_prefix;
#define MAX_CACHE 100
#define CACHE_ERROR 100
extern struct dyn_string cached_data[MAX_CACHE];
extern int current_cache;
extern int do_cache[MAX_CACHE];
#define MAX_STREAMS 100
#define ALL_STREAMS -1
extern struct dyn_string streams[MAX_STREAMS];
extern int num_streams;
int mode[MAX_STREAMS];
#define MODE_NONE 0
#define MODE_COMMENT 1
#define MODE_BLOCK 2
#define MODE_SCRIPT 3
#define MODE_OUTTEXT 4
#define MODE_ANSWER 5
#define MODE_HINT 6
#define MODE_IMPORT 7
/* end_mode always sets this to 0, if you want to check if any other
mode has been entered. Set this to 1 and check again if it has been
set back to zero.
*/
extern int watch_mode[MAX_STREAMS];
/*=============================================================================*/
/* CAPA PROTOTYPES FOR FUNCTIONS IN COMMON.C */
/*=============================================================================*/
/*-----------------------------------------------------------------------------*/
int capa_parse(int set,Problem_t **problem,char *filename,int *num_questions,void (*func_ptr)());
void send(char* text,...);
void end_mode(void);
void end_mode_stream(int which);
void start_mode(int newmode,char* args);
void start_mode_stream(int which,int newmode,char* args);
void dyn_init(struct dyn_string *dyn);
void dyn_free(struct dyn_string *dyn);
int append_message(struct dyn_string *dyn_msg,char *format,va_list ap);
void add_delayed(char *format, ...);
void flush_delayed();
void start_delayed();
void end_delayed();
void send_stream(int which,char* text,...);
void start_streams(int num);
void end_streams(int which);
void new_cache();
void delete_cache();
void start_cache();
void stop_cache();
/*============================================================================*/
#endif /* CAPA_COMMON_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>