/*
 *========================================================================
 *
 *    : AZN_PLAZA_LANE APP
 *      : file_ctrl.h
 *      : JBY
 *      : 2018.07.13
 *      : 
 *        :  ,,  /  RECORD ,  FILE  
 *
 *========================================================================
*/

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

#include "def_set.h"
#include "ctrl_job.h"

#define F_SUCCESS  0
#define F_FAILURE -1

extern int errno;

#define CHARTYPE    0
#define MAXKEYSIZE      120     /* max number of bytes in key   */
#define MAXPARTS          8       /* max number of key parts      */

#define    PASSRAWSIZE    188
#define    TRMNRCVSIZE    248


typedef struct {                        /*  RECORD              */
        uchar   flag;                   /* FLAG                         */
        uchar   dummy;
        short   leng;                   /* Data                     */
        uchar   data[PASSRAWSIZE];     /* Data buffer                  */
        uchar   filler[4];
} PASSRAW;


typedef struct {                        /*  FILE                */
        uchar   flag;                   /* FLAG                         */
        uchar   div;                    /*                          */
        short   leng;                   /* Data                     */
        uchar   data[TRMNRCVSIZE];     /* Data buffer                  */
        uchar   fill[4];
} TRMNRCV;


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

typedef struct keydesc {
    short  key_flags;        /* flags            */
    short  k_nparts;       /* number of parts in key    */
    struct keypart
    k_part[MAXPARTS];        /* each key part        */
                        /* the following is for internal use */
    short k_len;        /* length of whole key        */
    int k_rootnode;        /* pointer to rootnode        */
} keydesc_t;

#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 DCOMPRESS 002        /* duplicate compression    */
#define LCOMPRESS 004        /* leading compression        */
#define TCOMPRESS 010        /* trailing compression        */
#define COMPRESS  016        /* all compression        */
#define ISCLUSTER 020        /* index is a cluster one       */

extern  int f_errno;        /* read & writer return code    */
extern  int f_recnum;        /* record number of last call    */
extern  int f_reclen;        /* actual record length, or    */

/* isopen, isbuild lock modes */
#define FC_AUTOLOCK    0x200    /* automatic record lock    */
#define FC_MANULOCK    0x400    /* manual record lock        */
#define FC_EXCLLOCK    0x800    /* exclusive sam file lock    */


/* isopen, isbuild file types */
#define FINPUT        0    /* open for input only        */
#define FOUTPUT       1    /* open for output only        */
#define FINOUT        2    /* open for input and output    */


/* isread, isread options */
#define FFIRST         0       /* position to first record     */
#define FLAST          1       /* position to last record      */
#define FNEXT          2       /* position to next record      */
#define FPREV          3       /* position to previous record  */
#define FCURR          4       /* position to current record   */
#define FEQUAL         5       /* position to equal value      */
#define FGREAT         6       /* position to greater value    */

#endif
