Annotation of capa/capa51/pProj/capaCommon.h, revision 1.5

1.3       albertel    1: /* This header defines Application Interface to the     
                      2:    CAPA system.  It needs capaParser.h and capaToken.h 
                      3:    Copyright (C) 1992-2000 Michigan State University
                      4: 
                      5:    The CAPA system is free software; you can redistribute it and/or
1.5     ! albertel    6:    modify it under the terms of the GNU General Public License as
1.3       albertel    7:    published by the Free Software Foundation; either version 2 of the
                      8:    License, or (at your option) any later version.
                      9: 
                     10:    The CAPA system is distributed in the hope that it will be useful,
                     11:    but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1.5     ! albertel   13:    General Public License for more details.
1.3       albertel   14: 
1.5     ! albertel   15:    You should have received a copy of the GNU General Public
1.3       albertel   16:    License along with the CAPA system; see the file COPYING.  If not,
                     17:    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1.4       albertel   18:    Boston, MA 02111-1307, USA.
                     19: 
                     20:    As a special exception, you have permission to link this program
                     21:    with the TtH/TtM library and distribute executables, as long as you
                     22:    follow the requirements of the GNU GPL in regard to all of the
                     23:    software in the executable aside from TtH/TtM.
                     24: */
1.1       albertel   25: 
                     26: /*    Date Oct 23 1995                                    */
                     27: /*   Isaac Tsai                                           */
                     28: /*                                                        */
                     29: /*   Get rid of old style structure definition *_t        */
                     30: /*   Make all structure definition begin with T_          */
                     31: /**********************************************************/
                     32: 
                     33: #ifndef   CAPA_COMMON_H
                     34: #define   CAPA_COMMON_H
                     35: 
                     36: #include <stdio.h>
                     37: #ifdef linux
                     38: #include <stdlib.h>
                     39: #endif
                     40: #ifdef NeXT
                     41: #include <stdlib.h>
                     42: #include <libc.h>
                     43: #else
                     44: #include <malloc.h>
                     45: #include <unistd.h>
                     46: #endif
                     47: 
                     48: #include <math.h>
                     49: #include <string.h>
                     50: #include <time.h>
                     51: #include <sys/fcntl.h>    /* lockf()  */
                     52: #include <sys/file.h>     /* flock()  */
                     53: #include <sys/types.h>
                     54: #include "capaParser.h"
                     55: 
                     56: #ifndef    MAX
                     57: #define    MAX(a,b) ((a>b)? (a):(b))
                     58: #endif
                     59: 
                     60: #define    MAX_SECTION_SIZE    10240    /* Max # of students in the class */
                     61: #define    MAX_SECTION_COUNT   1024
                     62: #define    MAX_NAME_CHAR       30      /* Student's name max length      */
                     63: #define    MAX_STUDENT_NUMBER   9      /* Student Number length          */
                     64: #define    MAX_EMAIL_CHAR      40      /* Email address */
                     65: #define    FILE_NAME_LENGTH    1024
                     66: #define    MAX_PIN_CHAR        4
                     67: #define    MAX_BUFFER_SIZE     2048
                     68: #define    TMP_LINE_LENGTH     2048     /* used to read in log.db set.db dates.db */
                     69: #define    SMALL_LINE_BUFFER   128     /* used to read classl, active.db */
                     70: #define    SETDB_BUF_SIZE      (256*1024)
                     71: /*  user input string length now in capaParser.h*/
                     72: /*#define    ANSWER_STRING_LENG       81*/
                     73: /*#define    UNIT_STRING_LENG         64*/
                     74: #define    FORMAT_STRING_LENG       32
                     75: 
                     76: /* -------- used in check_date() */
                     77: #define    CHECK_OPEN_DATE      1
                     78: #define    CHECK_DUE_DATE       2
                     79: #define    CHECK_ANS_DATE       3
                     80: 
                     81: 
                     82: 
                     83: /******************************************************************************/
                     84: /* STRUCTURE FOR THE HEADER OF A DATABASE FILE                                */
                     85: /******************************************************************************/
                     86: 
                     87: typedef struct {
                     88:   char   num_questions[FORMAT_STRING_LENG];
                     89:   char   *weight;
                     90:   char   *partial_credit;
                     91: }  T_header;
                     92: 
                     93: /******************************************************************************/
                     94: /* STRUCTURE FOR A NORMAL DATABASE FILE ENTRY                                 */
                     95: /******************************************************************************/
                     96: 
                     97: typedef struct {
                     98:  char    student_number[MAX_STUDENT_NUMBER+1]; /* Student number */
                     99:  int     e_probs;
                    100:  char   *answers; /* String of answers */
                    101:  char   *tries;
                    102: } T_entry;
                    103: 
                    104: /******************************************************************************/
                    105: /* STRUCTURE FOR A STUDENT IN THE STUDENT ARRAY                               */
                    106: /******************************************************************************/
                    107: 
                    108: typedef struct _student {
                    109:    struct _student *s_next;
                    110:    struct _student *s_prev;
                    111:    int    s_sec;
                    112:    int    s_scores;
                    113:    char   s_key[MAX_NAME_CHAR+MAX_NAME_CHAR+2]; /* sorting key */
                    114:    char   s_sn[MAX_STUDENT_NUMBER+1];
                    115:    char   s_nm[MAX_NAME_CHAR+1];
                    116:    char   s_email[MAX_EMAIL_CHAR+1];
                    117:    int    s_capaid;
                    118: }  T_student;
                    119: 
                    120: /******************************************************************************/
                    121: /* STRUCTURE FOR Login dates for a set                                        */
                    122: /******************************************************************************/
                    123: /*section number DATE_DEFAULTs contains the default dates an assignment is due*/ 
                    124: #define DATE_DEFAULTS 0
                    125: #define OPEN_OFFSET 0
                    126: #define DUE_OFFSET 17
                    127: #define ANSWER_OFFSET 34
                    128: #define DATE_LENGTH 16
                    129: #define DATE_BUFFER 17
                    130: #define OPTION_INHIBIT_RESPONSE 100
                    131: #define OPTION_VIEW_PROBLEMS_AFTER_DUE 101
                    132: typedef struct _date {
                    133:   struct _date *s_next;
                    134:   int    section_start;
                    135:   int    section_end;
                    136:   char   open_date[DATE_BUFFER];
                    137:   char   due_date[DATE_BUFFER];
                    138:   char   answer_date[DATE_BUFFER];
                    139:   char   duration[DATE_BUFFER];
                    140:   int    inhibit_response;
                    141:   int    view_problems_after_due;
                    142: } T_dates;
                    143: 
                    144: /******************************************************************************/
                    145: /* STRUCTURE FOR Login history for a student                                  */
                    146: /******************************************************************************/
                    147: typedef struct {
                    148:  int     count;  /* Number of questions */
                    149:  char   *answers; /* String of answers   */
                    150: } login_history_t;
                    151: 
                    152: #define	leap_year(yr) ((yr) <= 1752 ? !((yr) % 4) : !((yr) % 4) && (((yr) % 100) || !((yr) % 400)))
                    153: 
                    154: #define	centuries_since_1700(yr) ((yr) > 1700 ? (yr) / 100 - 17 : 0)
                    155: 
                    156: #define	quad_centuries_since_1700(yr)  ((yr) > 1600 ? ((yr) - 1600) / 400 : 0)
                    157: 
                    158: #define	leap_years_since_year_1(yr)  ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
                    159: 
                    160: /*=============================================================================*/
                    161: /* CAPA PROTOTYPES FOR FUNCTIONS IN COMMON.C                                   */
                    162: /*=============================================================================*/
                    163: /*-----------------------------------------------------------------------------*/
                    164: int   capa_get_section  CAPA_ARG((T_student **student_pp, int section));
                    165: int   capa_sorted_section  CAPA_ARG((T_student **student_pp, int section));
                    166: void  msort_main        CAPA_ARG((T_student **head_pp));
                    167: void  msort_split       CAPA_ARG((T_student *a_sp, T_student **b_pp));
                    168: void  msort_merge       CAPA_ARG((T_student *a_sp, T_student *b_sp, T_student **c_pp));
                    169: int   capa_get_student  CAPA_ARG((char *student_number,T_student *student_p));
                    170: int   capa_student_byname  CAPA_ARG((char *student_name,T_student *student_p));
                    171: int   capa_pick_student CAPA_ARG((int  section, T_student *student_p));
                    172: int   capa_add_student  CAPA_ARG((T_student *student_p));
                    173: int   capa_parse        CAPA_ARG((int  set,Problem_t **problem,char *student_number,int *num_questions,void (*func_ptr)()));
                    174: int   capa_parse_student CAPA_ARG((int  set,Problem_t **problem,T_student *astudent,int *num_questions,void (*func_ptr)()));
                    175: void  free_problems     CAPA_ARG((Problem_t *problem_p));
                    176: void  free_students     CAPA_ARG((T_student *student_p));
                    177: void  free_units        CAPA_ARG(());
                    178: int   read_capa_config  CAPA_ARG((char* key_word, char *value));
                    179: int   capa_access       CAPA_ARG((const char *pathname, int mode));
                    180: /*-----------------------------------------------------------------------------*/
                    181: void  capa_seed         CAPA_ARG((long *seed1, long *seed2, char *student_number));
                    182: int   capa_PIN          CAPA_ARG((char *student_number, int set, int guess));
                    183: char* capa_id_plus      CAPA_ARG((char *student_number, int set, int plus));
                    184: int   capa_set_header   CAPA_ARG((T_header *header, int set));
                    185: int   capa_get_header   CAPA_ARG((T_header *header, int set));
                    186: 
                    187: int   capa_set_entry    CAPA_ARG((T_entry *entry, char *student_number, int set, long offset));
                    188: int   capa_change_entry    CAPA_ARG((T_entry *entry, char *student_number, int set));
                    189: long  capa_append_entry CAPA_ARG((T_entry *entry, char *student_number, int set));
                    190: long  capa_get_entry    CAPA_ARG((T_entry *entry, char *student_number, int set));
                    191: int   capa_excuse       CAPA_ARG((int set, int prob, int section));
                    192: int   capa_get_score    CAPA_ARG((char *student_number, int set, int *valid_scores, char **answers_pp));
                    193: char* capa_get_seat     CAPA_ARG((char *studentnum, char *seatfile));
                    194: /*-----------------------------------------------------------------------------*/
                    195: int   capa_get_login_count    CAPA_ARG((char *student_number,int set));
                    196: int   capa_get_login_db       CAPA_ARG((T_entry *login_item,int *num_probs,int set));
                    197: int   capa_get_section_count  CAPA_ARG((int *cnt_arry));
                    198: int   login_check       CAPA_ARG((char *student_number));
                    199: int   logout_check      CAPA_ARG((char *student_number));
                    200: /*-----------------------------------------------------------------------------*/
                    201: int   flockstream_sh    CAPA_ARG((FILE *fp));
                    202: int   flockstream       CAPA_ARG((FILE *fp));
                    203: int   funlockstream     CAPA_ARG((FILE *fp));
                    204: /*-----------------------------------------------------------------------------*/
                    205: time_t convertTime       CAPA_ARG((char *dateStr,char *timeStr));
                    206: int    weekday           CAPA_ARG((int year, int month, int day));
                    207: int    julianday         CAPA_ARG((int year, int month, int day));
                    208: /*int    compare_datetime  CAPA_ARG((time_t time,char *datetime));*/
                    209: int    capa_check_date   CAPA_ARG((int which,char *student_number,int section,int set));
                    210: int    capa_get_date     CAPA_ARG((int which,char *student_number,int section,int set,char *date_str));
                    211: void   free_dates        CAPA_ARG((T_dates *dates));
                    212: int    capa_get_all_dates CAPA_ARG((int set, T_dates **dates));
                    213: int    capa_set_all_dates CAPA_ARG((int set, T_dates *dates));
                    214: int    capa_get_section_dates CAPA_ARG((int section,int set,T_dates** dates));
                    215: T_dates* add_date_info    CAPA_ARG((int lowsec,int highsec, char *dateinfo));
                    216: int    capa_get_login_time CAPA_ARG((char *student_number,int set,time_t *logintime));
                    217: int    capa_set_login_time CAPA_ARG((char *student_number,int set));
                    218: int    capa_get_duration  CAPA_ARG((char *student_number,int section,int set));
                    219: int    capa_check_option  CAPA_ARG((int option,int set,int section));
                    220: int    check_int          CAPA_ARG((char *an_int ));
                    221: int    check_real         CAPA_ARG((char *a_real ));
                    222: char  *answers_string     CAPA_ARG((int mode, Problem_t  *p ));
1.2       albertel  223: int    capa_check_ans     CAPA_ARG((AnswerInfo_t *ai, char *answer, char **error));
                    224: int    capa_check_answer  CAPA_ARG((Problem_t *p, char *answer, char **error));
                    225: int    capa_check_answers CAPA_ARG((Problem_t *p, char **answers,int cnt, char **error));
1.1       albertel  226: int    check_formula_ans  CAPA_ARG((char *fml_str,char *input_str,char *var_list,PointsList_t *pts_list,int tol_type,double tol));  
                    227: 
                    228: int    is_all_ws          CAPA_ARG((char *answer));
                    229: void   trim_response_ws   CAPA_ARG((char *answer));
                    230: void   throwaway_line     CAPA_ARG((FILE* fp));
                    231: void   protect_log_string CAPA_ARG((char* log_string));
                    232: int    calc_ansrange  CAPA_ARG((int type,int calc_type,char *input,char *fmt,int tol_type,double tol,char *lower,char *upper));
                    233: /*-----------------------------------------------------------------------------*/
                    234: int    capa_set_subjective CAPA_ARG((int set,int problem,char *student_num,char* response));
                    235: char*  capa_get_subjective CAPA_ARG((int set,int problem,char *student_num));
                    236: /*============================================================================*/
                    237: 
                    238: #endif  /* CAPA_COMMON_H  */
                    239: 

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