/*******************************************************/
/*                                                     */
/* File        : cybos.h                               */
/* Description : (simpilified) c interface to YBOS     */
/*                                                     */
/* Author: Sfiligoi Igor                               */
/*                                                     */
/* Created      : 07.09.1998                           */
/* Last modified: 07.09.1998                           */
/*                                                     */
/*******************************************************/

#ifndef CYBOS_H
#define CYBOS_H

#include <stdio.h>

typedef struct
{
  int rec_size;       /* size of the physical record (excluding itself) */
  int header_size;    /* size of the PR Header (including itself)       */
  int ph_rec_nr;      /* Physical Record Number                         */
  int displacement;   /* Displacement to first logical record           */

  int data[100000];   /* real data */
} tcybos_record;

typedef struct
{
  FILE          *ybfile;        /* stream of the file */
  int            record_size;   /* size of the first physical record (includeing itself) */
                                /* all the physical records should be the same size */
  tcybos_record *record_buffer; /* initialized to record_size size */

  int            curr_record;   /* Current physical record in the buffer */
  int            curr_pointer;  /* Current position inside the buffer */
  
  int            curr_lrec;     /* Currently pointing to the curr_lrec logical record */
} tcybos;

typedef tcybos *pcybos;


/******************************************/
/*                                        */
/* cybos_open()                           */
/*                                        */
/* Open a ybos file                       */
/*                                        */
/* Param:   filename - name of the file   */
/*                                        */
/* Returns: initialized ybos id           */
/*          NULL, in case of error        */
/*                                        */
/******************************************/

pcybos cybos_open(char *filename);

/******************************************/
/*                                        */
/* cybos_close()                          */
/*                                        */
/* Close the ybos file                    */
/*                                        */
/* Param:   ybos_id - initialized ybos id */
/*                                        */
/******************************************/

void cybos_close(pcybos ybos_id);

/************************************************************************/
/*                                                                      */
/* cybos_seek()                                                         */
/*                                                                      */
/* Move pointer in the ybos file                                        */
/*                                                                      */
/* Param:   ybos_id  - initialized ybos id                              */
/*          nr_lrecs - relative move in the file                        */
/*                     expressed in logical records                     */
/*                     If the pointer would move past the last lrec,    */
/*                     set it to the last lrec +1                       */
/*                     If the pointer would move before the first lrec, */
/*                     set it to the first lrec                         */
/*                                                                      */
/* Returns: Current position in the file (first 0)                      */
/*                                                                      */
/************************************************************************/

int cybos_seek(pcybos ybos_id,
	       int    nr_lrecs);

/************************************************************************/
/*                                                                      */
/* cybos_seek_abs()                                                     */
/*                                                                      */
/* Move pointer in the ybos file                                        */
/*                                                                      */
/* Param:   ybos_id  - initialized ybos id                              */
/*          lrec_nr  - set the pointer to the lrec lrec_nr              */
/*                     If the pointer would move past the last lrec,    */
/*                     set it to the last lrec +1                       */
/*                     If the pointer would move before the first lrec, */
/*                     set it to the first lrec                         */
/*                                                                      */
/* Returns: Current position in the file (first 0)                      */
/*          Most time the same as bank_nr                               */
/*                                                                      */
/************************************************************************/

int cybos_seek_abs(pcybos ybos_id,
	           int    lrec_nr);

/**************************************************/
/*                                                */
/* cybos_read()                                   */
/*                                                */
/* Read a bank from the ybos file                 */
/* Move also to the next bank                     */
/*                                                */
/* Param:   ybos_id - initialized ybos id         */
/*          lrec    - pointer to the lrec buffer  */
/*          maxsize - buffer size (nr of ints)    */
/*                                                */
/* Returns: Nr of ints read                       */
/*          lrecsize, if the buffer was to small  */
/*                    where lrecsize>maxdata      */
/*          0, if ybos pointer past the last bank */
/*          <0, in case of error                  */
/*                                                */
/**************************************************/

int cybos_read(pcybos ybos_id,
	       int   *lrec,
	       int    maxsize);


#endif /* CYBOS_H */