File:  [LON-CAPA] / loncom / homework / CAPA-converter / capaCommon.h
Revision 1.7: download - view: text, annotated - select for diffs
Tue Dec 4 15:17:57 2001 UTC (22 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- GPL headers

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

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