/************************************************************************
*                       - 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.
*************************************************************************/

#ifndef CISAM_H    /* avoid multiple include problems */
#define CISAM_H

#define MAXTYPE    5
#define ISDESC    0x80  /* add to make descending type  */
#define TYPEMASK  0x7F  /* type mask      */

#ifdef BBN      /* BBN Machine has 10 bits/byte  */
#	define BYTEMASK  0x3FF    /* mask for one byte    */
#	define BYTESHFT  10    /* shift for one byte    */
#else
#	define BYTEMASK  0xFF    /* mask for one byte    */
#	define BYTESHFT  8    /* shift for one byte    */
#endif

#define ldint(p)  ((short)(((p)[0]<<BYTESHFT)+((p)[1]&BYTEMASK)))
#define stint(i,p)  ((p)[0]=(i)>>BYTESHFT,(p)[1]=(i))

long ldlong();

double  ldfloat();
double  lddbl();

#define ISFIRST    0  /* position to first record  */
#define ISLAST    1  /* position to last record  */
#define ISNEXT    2  /* position to next record  */
#define ISPREV    3  /* position to previous record  */
#define ISCURR    4  /* position to current record  */
#define ISEQUAL    5  /* position to equal value  */
#define ISGREAT    6  /* position to greater value  */
#define ISGTEQ    7  /* position to >= value    */

/* isread lock modes */
#define ISLOCK       0x100  /* record lock      */

/* isopen, isbuild lock modes */
#define ISAUTOLOCK  0x200  /* automatic record lock  */
#define ISMANULOCK  0x400  /* manual record lock    */
#define ISEXCLLOCK  0x800  /* exclusive isam file lock  */

#define ISINPUT    0  /* open for input only    */
#define ISOUTPUT   1  /* open for output only    */
#define ISINOUT    2  /* open for input and output  */
#define ISTRANS    4  /* open for transaction proc */
#define ISNOLOG    8  /* no logging for this file */

#define DOUBLESIZE      8
#define FLOATSIZE       4

#define MAXKEYLEN  120  /* max number of bytes in key  */
#define NPARTS    8  /* max number of key parts  */

struct keypart
    {
    short kp_start;    /* starting byte of key part  */
    short kp_leng;    /* length in bytes    */
    short kp_type;    /* type of key part    */
    };

struct keydesc
    {
    short k_flags;    /* flags      */
    short k_nparts;    /* number of parts in key  */
    struct keypart k_part[NPARTS];    /* each key part    */
	/* the following is for internal use only  */
    short k_len;    /* length of whole key    */
    long k_rootnode;    /* pointer to rootnode    */
    };
#define k_start   k_part[0].kp_start
#define k_leng    k_part[0].kp_leng
#define k_type    k_part[0].kp_type

#define ISNODUPS  000    /* no duplicates allowed  */
#define ISDUPS    001    /* duplicates allowed    */
#define COMPRESS  016    /* all compression    */

struct dictinfo
    {
    short di_nkeys;    /* number of keys defined  */
    short di_recsize;    /* data record size    */
    short di_idxsize;    /* index record size    */
    long di_nrecords;    /* number of records in file  */
    };

#define EDUPL    100    /* duplicate record  */
#define ENOTOPEN  101    /* file not open  */
#define EBADARG   102    /* illegal argument  */
#define EBADKEY   103    /* illegal key desc  */
#define ETOOMANY  104    /* too many files open  */
#define EBADFILE  105    /* bad isam file format  */
#define ENOTEXCL  106    /* non-exclusive access  */
#define ELOCKED   107    /* record locked  */
#define EKEXISTS  108    /* key already exists  */
#define EPRIMKEY  109    /* is primary key  */
#define EENDFILE  110    /* end/begin of file  */
#define ENOREC    111    /* no record found  */
#define ENOCURR   112    /* no current record  */
#define EFLOCKED  113    /* file locked    */
#define EFNAME    114    /* file name too long  */
#define EBADMEM   116    /* can't alloc memory  */
#define EBADCOLL  117    /* bad custom collating  */

/*
 * For system call errors
 *   iserrno = errno (system error code 1-99)
 *   iserrio = IO_call + IO_file
 *    IO_call  = what system call
 *    IO_file  = which file caused error
 */

#define IO_OPEN    0x10    /* open()  */
#define IO_CREA    0x20    /* creat()  */
#define IO_SEEK    0x30    /* lseek()  */
#define IO_READ    0x40    /* read()  */
#define IO_WRIT    0x50    /* write()  */
#define IO_LOCK    0x60    /* locking()  */
#define IO_IOCTL  0x70    /* ioctl()  */

extern int iserrno;    /* isam error return code  */
extern int iserrio;    /* system call error code  */
extern long isrecnum;    /* record number of last call  */
extern char isstat1;    /* cobol status characters  */
extern char isstat2;

#endif
