#ifndef __CFILES_H
#define __CFILES_H

#ifndef __CCUSTIO_H
#include        "ccustio.h"
#endif

#define MaxFilesDir             70
#define MKFields                        10
#define MaxFields                       100
#define MaxKeys                         8
#define glockname                       "xx"
#define INVFLD                          255
/* @(!) 2.3.01.144 */
#define NORDIR                          0
#define COMDIR                          1
/* @(:) 2.3.01.144 */

typedef char                                    FieldName[12] ;

typedef struct
{
  char                                            SysName[42]  __PACKED__ ;
  RecNoType                               EOD  __PACKED__ ;
  RecNoType                               EOX  __PACKED__ ;
  /* @(!) 2.3.01.temp */
#ifdef M_I386
  unsigned short  LenR  __PACKED__ ;
#else
  /* @(:) 2.3.01.temp */
  unsigned int            LenR ;
  /* @(!) 2.3.01.temp */
#endif
  /* @(:) 2.3.01.temp */
  RecNoType                               Flags  __PACKED__ ;
  char                                            Des[42]  __PACKED__ ;
  char                                            FCalc[32]  __PACKED__ ;
  char                                            GenPrompt[32]  __PACKED__ ;
}       FileDes;

typedef struct
{
  FieldName                               Name  __PACKED__ ;
  byte                                            TypeF  __PACKED__ ;
  byte                                            Len  __PACKED__ ;
  byte                                            Dec __PACKED__ ;
#ifdef __PACK_1__
  byte                                            junk __PACKED__ ;
#endif
  /* @(!) 2.3.01.temp */
#ifdef M_I386
  unsigned short  RecOff  __PACKED__ ;
#else
  /* @(:) 2.3.01.temp */
  unsigned int            RecOff ;
  /* @(!) 2.3.01.temp */
#endif
  /* @(:) 2.3.01.temp */
} RecFieldDes ;

#if XVT_OS == XVT_OS_DOS || XVT_OS == XVT_OS_WIN
#pragma pack(2)
#endif

typedef struct
{
  BOOLEAN                                 DupKeys __ALIGNED__ ;
  byte                                            NkFields __ALIGNED__ ;
  byte                                            FieldSeq[MKFields]  __PACKED__ ;
  byte                                            FromCh[MKFields]  __PACKED__ ;
  byte                                            ToCh[MKFields]  __PACKED__ ;
}       KeyDes ;

typedef struct
{
  /* @(!) 2.3.01.temp */
#ifdef M_I386
  short                                           NFields  __PACKED__ ;
#else
  /* @(:) 2.3.01.temp */
  int                                                     NFields ;
  /* @(!) 2.3.01.temp */
#endif
  /* @(:) 2.3.01.temp */
  RecFieldDes                     Fd[MaxFields]  __PACKED__ ;
  byte                                            SortFd[MaxFields]  __PACKED__ ;
  /* @(!) 2.3.01.temp */
#ifdef M_I386
  short                                           NKeys  __PACKED__ ;
#else
  /* @(:) 2.3.01.temp */
  int                                                     NKeys ;
  /* @(!) 2.3.01.temp */
#endif
  /* @(:) 2.3.01.temp */
  KeyDes                                  Ky[MaxKeys]  __PACKED__ ;
}       RecDes;
#ifdef __CFILES_C
SecDef rdir[2], fdir[2];
#else
extern SecDef rdir[2], fdir[2];
#endif

#ifdef __cplusplus
extern "C" {
#endif
  /* @(!) 2.3.01.144 */
  void  COpenDir(int, int);
  void  CCloseDir(int);
  void  COpenFile(int, FileDes *, int, int);
  void  CCloseFile(int, FileDes *, int);
  void  CGetFile(int,  FileDes *, int, int);
  void  CPutFile(int,  FileDes *, int);
  /* @(:) 2.3.01.144 */
  void    zerofdes(FileDes *);
  /* @(!) 2.3.01.144 */
  void  COpenRecDir(int, int);
  void  CCloseRecDir(int);
  void  CGetRec(int, RecDes *, int);
  void  CPutRec(int, RecDes *, int);
  /* @(:) 2.3.01.144 */
  void    zerordes(RecDes *);
  word    setrdes(RecDes *);
  int findfld(RecDes *,char *);
  unsigned int  CFieldSize(char *, RecDes *);
  unsigned int  CFieldDec(char *, RecDes *);
  int   CFieldType(char *, RecDes *);
  int     CGetField(char *, RecDes *, RecType, void *);
  int     CPutField(char *, RecDes *, void *, RecType);
  int     CGetFieldBuff(char *, RecDes *, RecType,         char *);
  int     CPutFieldBuff(char *, RecDes *, char *, RecType);
  int     CZeroField(char *, RecDes *, RecType);
  void    CZeroRec(RecDes *, RecType);
  int   CBuildKey(RecDes *,int ,RecType,        char *);
  int   CCalcLenKey(RecDes *,int);
  char  *CGetPref(void);
  void  CPutPref(char *);
  char  *CAddPref(char *);
  /* @(!) 2.3.01.144 */
  char    *CInsPref(char *, int);
  /* @(:) 2.3.01.144 */
  char  *CGetIdxName(char *);
  /* @(!) 2.3.01.155 */
  char    **getlinesdf(char *, int *);
  void    loadrfd(RecDes *, RecType, char **, char **);
  void    dumprfd(RecDes *, RecType, char **, int *, int *, int   *, char *);
  /* @(:) 2.3.01.155 */

#ifdef __cplusplus
};
#endif
#endif /* __CFILES_H */
