#ifndef FILES_FILES_H
#define FILES_FILES_H TRUE

/*
**   $VER: files.h V0.8B
**
**   File definitions.
**
**   (C) Copyright 1996-1997 DreamWorld Productions.
**       All Rights Reserved.
*/

#ifndef DPKERNEL_H
#include <games/dpkernel.h>
#endif

/****************************************************************************
** Module information.
*/

#define FileModVersion   0
#define FileModRevision  8

/****************************************************************************
** Mini structures for source and destination operations.
*/

struct Source {      /* Source structure for internal use */
  WORD ID;
  APTR Src;
};

struct FileName {    /* Filename structure */
  WORD ID;           /* ID_FILENAME */
  BYTE *Name;        /* Pointer to filename */
};

struct MemPtr {      /* Memory location structure */
  WORD ID;           /* ID_MEMPTR */
  APTR Address;      /* Pointer to memory area */
  LONG Size;         /* Must supply a size unless you are a MemBlock */
};

/****************************************************************************
** File Object.
*/

#define FILEVERSION 1
#define TAGS_FILE   ((ID_SPCTAGS<<16)|ID_FILE)

struct File {
  struct Head Head;       /* Standard structure header */
  LONG   BytePos;         /* Current position in file */
  LONG   Size;            /* Total size of the file */
  LONG   Flags;           /* File flags */
  struct Head *Source;    /* Direct pointer to the original Source structure */
  struct File *Prev;      /* Previous file in chain */
  struct File *Next;      /* Next file in chain */
  BYTE   *Comment;        /* Pointer to comment string */
  struct Time *DateStamp; /* Set at time of creation */

  /*** Private fields start now ***/

  LONG   prvHandle;
  LONG   prvKey;
  LONG   prvLastPos;
};

/* File tags */

#define FLA_BytePos   (TLONG|12)
#define FLA_Size      (TLONG|16)
#define FLA_Flags     (TLONG|20)
#define FLA_Source    (TAPTR|24)
#define FLA_Prev      (TAPTR|28)
#define FLA_Next      (TAPTR|32)
#define FLA_Comment   (TAPTR|36)
#define FLA_DateStamp (TAPTR|40)

/* Opening flags */

#define FL_OLDFILE 0
#define FL_WRITE    (1L<<0)
#define FL_LOCK     (1L<<1)
/*#define FL_NEW    (1L<<2)*/
#define FL_FIND     (1L<<3)
#define FL_NOUNPACK (1L<<4)
#define FL_NOPACK   (1L<<4)
#define FL_NOBUFFER (1L<<5)
#define FL_NEWFILE  (1L<<6)
#define FL_READ     ((0)|FL_OLDFILE)

/****************************************************************************
** Directory Object.  The format/version of the DirEntry and FileEntry
** structures is dependent on the directory version.
*/

#define DIRVERSION     1
#define TAGS_DIRECTORY (ID_SPCTAGS<<16)|ID_DIRECTORY

struct Directory {
  struct Head Head;            /* 00: Standard header */
  struct DirEntry  *DirList;   /* 12: First directory in list (master only) */
  struct FileEntry *FileList;  /* 16: First file in list (master only) */
  struct FileName  *Source;    /* 20: Location and Name of this directory */
  LONG   OpenFlags;            /* 24: Opening Flags (see file flags) */
  BYTE   *Comment;             /* 28: Pointer to comment string */
  LONG   UserFlags;            /* 32: User Flags */
  struct Time *DateStamp;      /* 36: Set to time of creation */
};

#define DIRA_Source    (TAPTR|20)
#define DIRA_OpenFlags (TLONG|24)
#define DIRA_Comment   (TAPTR|28)
#define DIRA_UserFlags (TLONG|32)
#define DIRA_DateStamp (TAPTR|36)

struct DirEntry {
  struct DirEntry *Prev;
  struct DirEntry *Next;
  struct FileName *Source;
};

struct FileEntry {
  struct FileEntry *Prev;
  struct FileEntry *Next;
  struct FileName  *Source;
};

#endif /* FILES_FILES_H */

