/************************************************************************
*                       - INFOFLEX System -
* This source code is CONFIDENTIAL and PROPRIETARY to CUSTOMWARE COMPUTING,
* INC. (CWC). The information contained herein may not be used, copied or
* disclosed in whole or in part except as permitted by written agreement
* signed by an officer of CWC.
*
* COPYRIGHT (c) 1986 CUSTOMWARE COMPUTING, INC., BURLINGAME, CALIFORNIA.
* ALL RIGHTS RESERVED.
*************************************************************************/

/* History:
    Brian -- Initial development
    Cris - Sep 11, 96 - restructured 'typedefs' for MS C declarations.
*/

#ifndef FXSTRUCT_H
#define FXSTRUCT_H

/*
DESIGN:

     I.  Layout of structure file.

         Each resident structure (DBHEAD, DBFIELD, DBINDEX)
         will be contiguous arrays.

            DBHEAD
              :
            DBFIELD
              :
            DBINDEX
              :
            RESIDENT TEXT

    II.  Program Initialization

         - Allocate space for HDHEAD
         - Read HDHEAD structure.
         - Allocate space for RESIDENT structure
         - Allocate data buffers based on hdBufsize
         - Read all RESIDENT Information (DBHEAD, DBFIELD, DBINDEX).
         - Set global pointers for RESIDENT structures.
         - Allocate data buffers for database fields.
         - Convert text array offsets to true pointers for RESIDENT text arrays.
*/

#include "fxisam.h"

/***********************************************************************
*                                                                      *
*         D A T A B A S E      S T R U C T U R E S                     *
*                                                                      *
************************************************************************/

#ifndef ALL_TYPES
struct dbview {
    char *vwname;	/* name of attribute	*/
    int vwstart;	/* offset in view	*/
    int vwtype;		/* type of attribute	*/
    int vwlen;		/* length in bytes	*/
    int vwoffs;		/* Offset of source buffer*/
};
#endif

struct _S_DBFIELD {
    char    *dfName;    /* ---> field name - offset into SYMBOL text array*/
    short    dfType;    /* field data type (CHARTYPE, INTTYPE, etc.) */
    short    dfState;   /* field state - updated by programmer */
    short    dfBytes;   /* field width in bytes */
    short    dfOffs;    /* field offset within a reserved i/o record buffer */
    short    dfDhindex; /* index into array of structs of type DBHEAD */
    short    dfDecimal; 
};
typedef struct _S_DBFIELD  DBFIELD;

struct _S_DBINDEX {
    char   *diName;     /* ---> index name - offset into SYMBOL text array */
    short   diType;     /* ---> (U)nique vs. (D)ups */
    short   diDhindex;  /* index into array of structs of type DBHEAD */
    short   diLength;   /* index size */
    short   diDfnum;    /* number of key parts within index */
    short   diDfindex[ NPARTS]; /* negative for descending order */
};
typedef struct _S_DBINDEX DBINDEX;

struct _S_DBHEAD {
    char    *dhName;     /* file name (offset into RESIDENT text array) */
    char    *dhPath;     /* disk file name (offset into RESIDENT text array) */
    short    dhLength;   /* length of each record */
    short    dhFldesc;   /* file # (file descriptor) assigned by C-ISAM when
                               file opened (value is -1 when file is closed) */
#ifdef EXCLLOCKBUG
    short    dhFd4clos;	 /* file descriptor used for ultimate close when
			       file opened elsewhere with exclusive lock */
#endif
    short    dhFlmode;   /* access mode of file when opened */
    short    dhReadseq;	 /* read file sequentially (read-only) */
    short    dhState;    /* state of file */
    DBFIELD *dhDbfield;  /* array of structs of type DBFIELD */
    short    dhDfnum;    /* number of fields per record */
    short    dhDfserial; /* index into array of structs of type DBFIELD
                               for SERIAL field if it exists */
    DBINDEX *dhDbindex;  /* array of structs of type DBINDEX */
    short    dhDinum;    /* number of elements in abovementioned array */
    char    *dhDicurrent; /* currently active index set at runtime
			       (struct type DBINDEX) */
    int      dhDicomplete;/* YES or NO - is index contain all columns of table*/
    long     dhRecnum;	 /* current record number */
    char    *dhBuffer;   /* buffer where screen data should be stored */
    struct dbview  *dhView;     /* pointer to dbview structure */
    char    *dhVwstruct; /* pointer to structure where dbview fields
			       will be stored */
    short    dhVwnum;    /* number of fields in dbview structure */
    short    dhTabid;    /* table i.d. */
    short    dhNolog;	 /* no transaction logging with operations on table
			       (temp tables only) */
};
typedef struct _S_DBHEAD  DBHEAD;

#define NULLDH  ((DBHEAD *) 0)
#define NULLDI  ((DBINDEX *) 0)
#define NULLDF  ((DBFIELD *) 0)

/***********************************************************************
*                                                                      *
*          M A S T E R         S T R U C T U R E                       *
*                                                                      *
************************************************************************/

struct _S_HDHEAD {
    short      hdDhnum;		/* number of DBHEAD structs */
    long       hdDhsize;
    DBHEAD   **hdDhptr;		/* points to first DBHEAD structure in array */
    short      hdDfnum;		/* number of DBFIELD structs */
    long       hdDfsize;
    DBFIELD   *hdDfptr;		/* points to first DBFIELD structure in array */
    short      hdDinum;		/* number of DBINDEX structs */
    long       hdDisize;
    DBINDEX   *hdDiptr;		/* points to first DBINDEX structure in array */
    short      hdVersion;
    long       hdBufmax;	/* maximum staging buffer size */
    short      hdDhmax;		/* maximum number of Dhptr's */
};
typedef struct _S_HDHEAD HDHEAD;

#endif
