/*
 *  deu.h - central armDeu defines
 *
 *  Written by:
 *   Brendon Wyber, Raphael Quinet (original Deu source),
 *  Extended by:
 *   Andreas Dehmel
 *
 *  This file is part of armDeu, the portable WAD utility (the name derives
 *  from its initial port to the ARM-based RISC OS). armDeu is released under
 *  the GNU Public License (GPL) in the hope that it proves useful. Please
 *  note there is NO WARRANTY. For more information read the file License
 *  included in this release.
 */

/* This file is based on Deu 5.21 by Brendon Wyber and Raphael Quinet */

/* the includes */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>


/*
 *  syntactic sugar
 */
typedef int Bool;               /* Boolean data: true or false */


/*
 *  the directory structure is the structre used by DOOM to order the
 *  data in it's WAD files
 */

typedef struct Directory_s
{
   long start;			/* offset to start of data */
   long size;			/* byte size of data */
   char name[ 8];		/* name of data block */
} Directory;



/*
 *  The wad file pointer structure is used for holding the information
 *  on the wad files in a linked list.
 *
 *  The first wad file is the main wad file. The rest are patches.
 */

typedef struct WadFileInfo_s
{
   struct WadFileInfo_s *next;	/* next file in linked list */
   char *filename;		/* name of the wad file */
   FILE *fileinfo;		/* C file stream information */
   char type[ 4];		/* type of wad file (IWAD or PWAD) */
   long dirsize;		/* directory size of WAD */
   long dirstart;		/* offset to start of directory */
   size_t filesize;		/* size of WAD for consistency checks */
   Directory *directory;		/* array of directory information */
   int compressType;
} WadFileInfo;

#define COMPRESS_TYPE_NONE	0
#define COMPRESS_TYPE_ZARQUON	1

#define COMPRESS_BUFFER_SIZE	0x10000



/*
 *  the master directory structure is used to build a complete directory
 *  of all the data blocks from all the various wad files
 */

typedef struct MasterDirectory_s
{
   struct MasterDirectory_s *next;	/* next in list */
   struct WadFileInfo_s *wadfile;	/* file of origin */
   struct Directory_s dir;		/* directory data */
   long offset;				/* When writing, needed for compressed WADs */
} MasterDirectory;



/*
 *  the macros and constants
 */

/* object types */
#define OBJ_THINGS		1
#define OBJ_LINEDEFS		2
#define OBJ_SIDEDEFS		3
#define OBJ_VERTEXES		4
#define OBJ_SEGS		5
#define OBJ_SSECTORS		6
#define OBJ_NODES		7
#define OBJ_SECTORS		8
#define OBJ_REJECT		9
#define OBJ_BLOCKMAP		10

/* boolean constants */
#define TRUE			1
#define FALSE			0

/* half the size of an object (Thing or Vertex) in map coords */
#define OBJSIZE			7


/*
 *  the interfile global variables
 */

/* from deu.c */
extern Bool  Registered;	/* registered or shareware WAD file? */
extern char *MainWad;		/* name of the main wad file */

/* from wads.c */
extern WadFileInfo *WadFileList;	/* list of wad files */
extern MasterDirectory *MasterDir;	/* the master directory */


/*
 *  the function prototypes
 */

/* from wads.c */
void OpenLumpFile( const char *, const char *);
void OpenMainWad( const char *);
void OpenPatchWad( const char *);
void CloseWadFiles( void);
void CloseUnusedWadFiles( void);
WadFileInfo *BasicWadOpen( const char *);
void BasicWadRead( WadFileInfo*, void *, long);
void BasicWadSeek( WadFileInfo*, long);
MasterDirectory *FindMasterDir( MasterDirectory*, const char *);
void ListMasterDirectory( FILE *);
void ListFileDirectory( FILE *, WadFileInfo*);
void BuildNewMainWad( const char *, Bool);
void WriteBytes( FILE *, const void *, long);
void CopyBytes( FILE *, FILE *, long);
int Exists( const char *);
void DumpDirectoryEntry( FILE *, const char *);
void SaveDirectoryEntry( FILE *, const char *);
void SaveEntryToRawFile( FILE *, const char *);
void SaveEntryFromRawFile( FILE *, FILE *, const char *);
void ListWadMaps(void);

/* end of file */
