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, 8 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.

    1: 
    2: /**********************************************************/
    3: /*   This header defines Application Interface to the     */
    4: /*    CAPA system.  It needs capaParser.h and capaToken.h */
    5: /*    CAPA version 4.3                                    */
    6: /*    Date Oct 23 1995                                    */
    7: /*   Isaac Tsai                                           */
    8: /*                                                        */
    9: /*   Get rid of old style structure definition *_t        */
   10: /*   Make all structure definition begin with T_          */
   11: /*   1997, 1998, 1999  Isaac Tsai                         */
   12: /**********************************************************/
   13: 
   14: #ifndef   CAPA_COMMON_H
   15: #define   CAPA_COMMON_H
   16: 
   17: #include <stdio.h>
   18: #ifdef linux
   19: #include <stdlib.h>
   20: #endif
   21: #ifdef NeXT
   22: #include <stdlib.h>
   23: #include <libc.h>
   24: #else
   25: #include <malloc.h>
   26: #include <unistd.h>
   27: #endif
   28: 
   29: #include <math.h>
   30: #include <string.h>
   31: #include <time.h>
   32: #include <sys/fcntl.h>    /* lockf()  */
   33: #include <sys/file.h>     /* flock()  */
   34: #include <sys/types.h>
   35: #include <stdarg.h>
   36: #include "capaParser.h"
   37: 
   38: #ifndef    MAX
   39: #define    MAX(a,b) ((a>b)? (a):(b))
   40: #endif
   41: 
   42: #define    MAX_SECTION_SIZE    10240    /* Max # of students in the class */
   43: #define    MAX_SECTION_COUNT   1024
   44: #define    MAX_NAME_CHAR       30      /* Student's name max length      */
   45: #define    MAX_STUDENT_NUMBER   9      /* Student Number length          */
   46: #define    MAX_EMAIL_CHAR      40      /* Email address */
   47: #define    FILE_NAME_LENGTH    1024
   48: #define    MAX_PIN_CHAR        4
   49: #define    MAX_BUFFER_SIZE     2048
   50: #define    TMP_LINE_LENGTH     2048     /* used to read in log.db set.db dates.db */
   51: #define    SMALL_LINE_BUFFER   128     /* used to read classl, active.db */
   52: #define    SETDB_BUF_SIZE      (256*1024)
   53: /*  user input string length now in capaParser.h*/
   54: /*#define    ANSWER_STRING_LENG       81*/
   55: /*#define    UNIT_STRING_LENG         64*/
   56: #define    FORMAT_STRING_LENG       32
   57: 
   58: /* -------- used in check_date() */
   59: #define    CHECK_OPEN_DATE      1
   60: #define    CHECK_DUE_DATE       2
   61: #define    CHECK_ANS_DATE       3
   62: 
   63: 
   64: 
   65: /******************************************************************************/
   66: /* STRUCTURE FOR THE HEADER OF A DATABASE FILE                                */
   67: /******************************************************************************/
   68: 
   69: typedef struct {
   70:   char   num_questions[FORMAT_STRING_LENG];
   71:   char   *weight;
   72:   char   *partial_credit;
   73: }  T_header;
   74: 
   75: /******************************************************************************/
   76: /* STRUCTURE FOR A NORMAL DATABASE FILE ENTRY                                 */
   77: /******************************************************************************/
   78: 
   79: typedef struct {
   80:  char    student_number[MAX_STUDENT_NUMBER+1]; /* Student number */
   81:  int     e_probs;
   82:  char   *answers; /* String of answers */
   83:  char   *tries;
   84: } T_entry;
   85: 
   86: /******************************************************************************/
   87: /* STRUCTURE FOR A STUDENT IN THE STUDENT ARRAY                               */
   88: /******************************************************************************/
   89: 
   90: typedef struct _student {
   91:    struct _student *s_next;
   92:    struct _student *s_prev;
   93:    int    s_sec;
   94:    int    s_scores;
   95:    char   s_key[MAX_NAME_CHAR+MAX_NAME_CHAR+2]; /* sorting key */
   96:    char   s_sn[MAX_STUDENT_NUMBER+1];
   97:    char   s_nm[MAX_NAME_CHAR+1];
   98:    char   s_email[MAX_EMAIL_CHAR+1];
   99:    int    s_capaid;
  100: }  T_student;
  101: 
  102: /******************************************************************************/
  103: /* STRUCTURE FOR Login dates for a set                                        */
  104: /******************************************************************************/
  105: /*section number DATE_DEFAULTs contains the default dates an assignment is due*/ 
  106: #define DATE_DEFAULTS 0
  107: #define OPEN_OFFSET 0
  108: #define DUE_OFFSET 17
  109: #define ANSWER_OFFSET 34
  110: #define DATE_LENGTH 16
  111: #define DATE_BUFFER 17
  112: #define OPTION_INHIBIT_RESPONSE 100
  113: #define OPTION_VIEW_PROBLEMS_AFTER_DUE 101
  114: typedef struct _date {
  115:   struct _date *s_next;
  116:   int    section_start;
  117:   int    section_end;
  118:   char   open_date[DATE_BUFFER];
  119:   char   due_date[DATE_BUFFER];
  120:   char   answer_date[DATE_BUFFER];
  121:   char   duration[DATE_BUFFER];
  122:   int    inhibit_response;
  123:   int    view_problems_after_due;
  124: } T_dates;
  125: 
  126: /******************************************************************************/
  127: /* STRUCTURE FOR Login history for a student                                  */
  128: /******************************************************************************/
  129: typedef struct {
  130:  int     count;  /* Number of questions */
  131:  char   *answers; /* String of answers   */
  132: } login_history_t;
  133: 
  134: #define	leap_year(yr) ((yr) <= 1752 ? !((yr) % 4) : !((yr) % 4) && (((yr) % 100) || !((yr) % 400)))
  135: 
  136: #define	centuries_since_1700(yr) ((yr) > 1700 ? (yr) / 100 - 17 : 0)
  137: 
  138: #define	quad_centuries_since_1700(yr)  ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
  139: 
  140: #define	leap_years_since_year_1(yr)  ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
  141: 
  142: struct dyn_string {
  143:     int len;
  144:     int max;
  145:     char *str;
  146: };
  147: struct dyn_string dyn_out;
  148: struct dyn_string dyn_delayed;
  149: extern int dyn_maxlen;
  150: extern char *import_prefix;
  151: 
  152: #define MAX_CACHE 100
  153: #define CACHE_ERROR 100
  154: extern struct dyn_string cached_data[MAX_CACHE];
  155: extern int current_cache;
  156: extern int do_cache[MAX_CACHE];
  157: 
  158: #define MAX_STREAMS 100
  159: #define ALL_STREAMS -1
  160: extern struct dyn_string streams[MAX_STREAMS];
  161: extern int num_streams;
  162: 
  163: int mode[MAX_STREAMS];
  164: #define MODE_NONE    0
  165: #define MODE_COMMENT 1
  166: #define MODE_BLOCK   2
  167: #define MODE_SCRIPT  3
  168: #define MODE_OUTTEXT 4
  169: #define MODE_ANSWER  5
  170: #define MODE_HINT    6
  171: #define MODE_IMPORT  7
  172: /* end_mode always sets this to 0, if you want to check if any other
  173:    mode has been entered. Set this to 1 and check again if it has been
  174:    set back to zero.
  175: */
  176: extern int watch_mode[MAX_STREAMS];
  177: /*=============================================================================*/
  178: /* CAPA PROTOTYPES FOR FUNCTIONS IN COMMON.C                                   */
  179: /*=============================================================================*/
  180: /*-----------------------------------------------------------------------------*/
  181: int capa_parse(int  set,Problem_t **problem,char *filename,int *num_questions,void (*func_ptr)());
  182: void send(char* text,...);
  183: void end_mode(void);
  184: void end_mode_stream(int which);
  185: void start_mode(int newmode,char* args);
  186: void start_mode_stream(int which,int newmode,char* args);
  187: void dyn_init(struct dyn_string *dyn);
  188: void dyn_free(struct dyn_string *dyn);
  189: int append_message(struct dyn_string *dyn_msg,char *format,va_list ap);
  190: void add_delayed(char *format, ...);
  191: void flush_delayed();
  192: void start_delayed();
  193: void end_delayed();
  194: void send_stream(int which,char* text,...);
  195: void start_streams(int num);
  196: void end_streams(int which);
  197: void new_cache();
  198: void delete_cache();
  199: void start_cache();
  200: void stop_cache();
  201: /*============================================================================*/
  202: 
  203: #endif  /* CAPA_COMMON_H  */
  204: 

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