/**********************************************************************
*
*  projet   : DilibPro
*  module   : Dam  (Dilib Acces Method)
*  fichier  : DamHCB.h
*  Auteur   : Jacques DUCLOY
*  Date     : Octobre 93
*
***********************************************************************/
/*

 Les principaux objets :

        HCB (DamHCB) -> Hfd Control Bloc 
	
	Digit        (DamHCB_Digit)       
                      controleur d'itération sur un digit
	ListDigit    (DamHCB_ListDigit)
                     controleur d'iterarion pour une liste de digits
	PathUnit     (DamHCB_PathUnit)
                     controleur associé à un niveau de pathname
	ListPathUnit (DamHCB_ListPathUnit)
                     controleur associé à un pathname
        Dir          (DamHCB_Dir)
                     controleur associé à un directory
        ListDir      (DamHCB_ListDir)
                     controleur associé à une liste de directories

***************************************************************************/

#ifndef _DAM_HCB_H_
#define _DAM_HCB_H_

#include "SgmlInput.h"

/************************************** Digit **********************/

struct DamHCB_Digit_Struct
{
  char *initString;
  char *curPos;
  struct DamHCB_Digit_Struct *prev;
  struct DamHCB_Digit_Struct *next;
};

typedef struct DamHCB_Digit_Struct DamHCB_Digit;

/************************************* ListDigit ********************/

struct DamHCB_ListDigit_Struct
{
  DamHCB_Digit *first;
  DamHCB_Digit *last;
  char         *profile;
  int          card;
};

typedef struct DamHCB_ListDigit_Struct DamHCB_ListDigit;

/******************************* PathUnit ************************/

struct DamHCB_PathUnit_Struct
{
  DamHCB_ListDigit *listDigit;
  char             state ; /* O:open, C: close, \0 null */
  char             *path;
  char             *pathSuffix;
  char             *key;
  struct DamHCB_PathUnit_Struct *prev;
  struct DamHCB_PathUnit_Struct *next;
};

typedef struct DamHCB_PathUnit_Struct DamHCB_PathUnit;

/******************************* HCB_ListPathUnit ************************/

struct DamHCB_ListPathUnit_Struct
{
  int                     pathLength;
  int                     keyLength;
  DamHCB_PathUnit         *first;
  DamHCB_PathUnit         *last;  
};

typedef struct DamHCB_ListPathUnit_Struct DamHCB_ListPathUnit;

/************************************ HCB_Dir ****************************/

struct DamHCB_Dir_Struct
{
  struct DamHCB_Dir_Struct *prev;
  struct DamHCB_Dir_Struct *next;
  DamHCB_PathUnit        *pathDigit;
};

typedef struct DamHCB_Dir_Struct DamHCB_Dir ;

/******************************* HCB_ListDir *****************************/

struct DamHCB_ListDir_Struct
{
  DamHCB_Dir         *first;
  DamHCB_Dir         *last;  
};

typedef struct DamHCB_ListDir_Struct DamHCB_ListDir;

/************************** HCB : HfdControlBloc ****************************/

struct DamHCB_Struct
{
  char                *name;            /* nom du hfd (sans suffixe)        */
  SgmlNode            *desc;            /* descripteur SGML du HCB          */
  char                *descFile;        /* fichier contenant le HCB SGML    */
  char                *rootPath;        /* directory racine du hfd          */
  DamHCB_ListPathUnit *listPathUnit;    /* liste des pathUnit               */
  DamHCB_ListDir      *listDir;         /* liste des directory */
  char                *dirKey;          /* partie de la cle associee aux dir */
  DamHCB_PathUnit     *filePathUnit;    /* */
  DamHCB_PathUnit     *recordPathUnit;  /* */
  char                *pathNameBuffer;
  char                *currentPath;
  int                  umask;
  FILE                *file; 
  char                *fileKey;
  char                *key;             /* cle courante */
  char                *regKey;          /* buffer pour operations sur cle */
  DamFile             *damFile;
  unsigned int         isRunning :1;
};

typedef struct DamHCB_Struct DamHCB;

/***************************************************************************/

#define DamHCB_LastKey(hcb) hcb->recordPathUnit->key
#define DamHCBdesc(x)       x->desc
#define DamHCB_RootPath(x)  x->rootPath
#define DamHCB_PathNameSize(x) x->listPathUnit->pathLength

/****************************************************************************/

char   *DamHCB_GetPath(DamHCB*, char*);
DamHCB *DamHCB_Create();
#define DamHCB_File(hcb) hcb->file
char   *DamHCB_RecordPath_NextKey();
void    DamHCB_Print();
void    DamHCB_Free();
char   *DamHCB_ListDir_FirstDir();
void    DamHCB_FilePath_FirstFile();
char   *DamHCB_RecordPath_FirstKey();

#endif /* _DAM_HCB_H_ */

