/*------------------------------------------------------------------------------
 * File: 	df.h
 * Purpose:	header file for HDF routines
 * Invokes:	dfi.h
 * Contents: 
 *	Structure definitions: DFddh, DFdd, DFdesc, DFdle, DF, DFdi, DFdata
 *	Procedure type definitions
 *	Global variables
 *	Tag definitions
 *  Error return codes
 *	Logical constants
 * Remarks: This file is included with user programs
 *			Since it includes stdio.h etc., do not include these after df.h
 *----------------------------------------------------------------------------*/


#ifndef DFTG_NULL				/* avoid re-inclusion */

/* include DF (internal) header information */
#include "dfi.h"

/*--------------------------------------------------------------------------*/
/*						Type declarations 									*/

typedef struct DFddh {		/* format of data descriptor headers as in file */
	int16
		dds;				/* number of dds in header block */
	int32	
		next;				/* offset of next header block */
	} DFddh;

		
typedef struct DFdd {		/* format of data descriptors as in file */
	uint16
		tag,				/* data tag */
		ref;				/* data reference number */
	int32
		offset,				/* offset of data element in file */
		length;				/* number of bytes */
	} DFdd;


	/* descriptor structure is same as dd structure.  ###Note: may be changed */
#define DFdesc	DFdd


	/* DLE is the internal structure which stores data descriptor information */
	/* It is a linked list of DDs */
typedef struct DFdle {		/* Data List element */
	struct DFdle
		*next;				/* link to next dle */
	DFddh
		ddh;				/* To store headers */
	DFdd
		dd[1];				/* dummy size */
	} DFdle;	


	/* DF is the internal structure associated with each DF file */
	/* It holds information associated with the file as a whole */
	/* ### Note: there are hooks for having multiple DF files open at a time */
typedef struct DF {
	DFdle
		*list,			/* Pointer to the DLE list */
		*last_dle;		/* last_dle and last_dd are used in searches to indicate
							element returned by previous call to DFfind */
	int
		type,			/* 0= not in use, 1= normal, -1 = multiple */
						/* this is a hook for when multiple files are open */
		access,			/* permitted access types: 0=none, 1=r, 2=w, 3=r/w */
		changed, 		/* True if anything in DDs modified since last write */
		last_tag,		/* Last tag searched for by DFfind */
		last_ref,		/* Last reference number searched for */
		last_dd,		/* see last_dle */
		defdds,			/* default numer of DD's in each block */
		up_access;		/* access permissions to element being read/updated */
						/* Used by DFstart */
	DFdd
		*up_dd;			/* DD of element being read/updated, used by DFstart */
  			/* file handle is a file pointer or file descriptor */
			/* depending on whether we use buffered or unbuffered i/o */
#ifdef DF_BUFFIO
	FILE *				/* file pointer */
#else DF_BUFFIO
	int					/* file descriptor */
#endif DF_BUFFIO
		file;			/* File handle for real file */
} DF;


typedef struct DFdi {	/* data identifier: specifies data element uniquely */
	uint16 tag;
	uint16 ref;
} DFdi;



typedef struct DFdata {	/* structure for returning status information */
	int version;		/* version number of stat information */
} DFdata;

/*--------------------------------------------------------------------------*/
/*							Procedure types 								*/

DF *DFopen();
int32 DFgetelement();
int32 DFread();
int32 DFseek();
int32 DFwrite();

/*--------------------------------------------------------------------------*/
/*							Global Variables 								*/

#ifndef DFMASTER
extern
#endif DFMASTER
int
	DFerror;			/* Error code for DF routines */

/*--------------------------------------------------------------------------*/
/*							 Tag Definitions							    */

#define DFREF_WILDCARD 0	/* wildcard ref for searches */

#define DFTG_WILDCARD 0	/* wildcard tag for searches */
#define	DFTG_NULL	1		/* empty DD */

#define DFTG_FID	100		/* File identifier */
#define	DFTG_FD	101		/* File description */
#define	DFTG_TID	102		/* Tag identifier */
#define	DFTG_TD	103		/* Tag descriptor */
#define DFTG_DIL	104		/* data identifier label */
#define DFTG_DIA	105		/* data identifier annotation */
#define DFTG_NT	106		/* number type */
#define DFTG_MT	107		/* machine type */

#define DFTG_ID8	200		/* 8-bit Image dimension */
#define DFTG_IP8	201		/* 8-bit Image palette */
#define DFTG_RI8	202		/* Raster-8 image */
#define DFTG_CI8	203		/* RLE compressed 8-bit image */
#define DFTG_II8	204		/* IMCOMP compressed 8-bit image */

#define DFTG_ID	300		/* Image DimRec */
#define DFTG_LUT	301		/* Image Palette */
#define	DFTG_RI	302		/* Raster Image */
#define	DFTG_CI	303		/* Compressed Image */

#define DFTG_RIG	306		/* Raster Image Group */
#define DFTG_LD	307		/* Palette DimRec */
#define	DFTG_MD	308		/* Matte DimRec */
#define DFTG_MA	309		/* Matte Data */
#define DFTG_CCN	310		/* color correction */
#define DFTG_CFM	311		/* color format */
#define DFTG_AR	312		/* aspect ratio */
	
#define	DFTG_DRAW	400		/* Draw these images in sequence */
#define	DFTG_RUN	401		/* run this as a program/script */

#define DFTG_XYP	500		/* x-y position */
#define DFTG_MTO	501		/* machine-type override */

#define DFTG_T14	602		/* TEK 4014 data */
#define DFTG_T105	603		/* TEK 4105 data */

	/* compression schemes */
#define DFTG_RLE	11		/* run length encoding */
#define DFTG_IMCOMP 12		/* IMCOMP compression */

/*--------------------------------------------------------------------------*/
/*							Error Return Codes 								*/

#define	DFE_NOERROR		0	/* No error */
#define	DFE_FNF			-1	/* File not found error */
#define	DFE_DENIED		-2	/* Access to file denied */
#define	DFE_ALROPEN		-3	/* File already open */
#define	DFE_TOOMANY		-4	/* Too Many DF's or files open */
#define DFE_BNAME		-5	/* Bad file name on open */
#define	DFE_BACC		-6	/* Bad file access mode */
#define DFE_BOPEN		-7	/* Other open error */
#define DFE_NOTOPEN		-8	/* File can't be closed 'cause it isn't open */
#define DFE_CANTCLOSE	-9	/* fclose wouldn't work! */
#define DFE_DFNULL		-10	/* DF is a null pointer */
#define DFE_ILLTYPE		-11	/* DF has an illegal type: internal error */
#define DFE_UNSUPPORTED	-12	/* Feature not currently supported */
#define DFE_BDDLIST	-13	/* The DD list is non-existent: internal error */
#define DFE_NOTDFFILE	-14	/* This is not a DF file and it is not 0 length */
#define DFE_SEEDTWICE	-15	/* The DD list already seeded: internal error */
#define	DFE_NOSPACE		-16	/* Malloc failed */
#define	DFE_NOSUCHTAG	-17	/* There is no such tag in the file: search failed*/
#define DFE_READERROR	-18	/* There was a read error */
#define DFE_WRITEERROR	-19	/* There was a write error */
#define DFE_SEEKERROR	-20	/* There was a seek error */
#define DFE_NOFREEDD	-21	/* There are no free DD's left: internal error */
#define DFE_BTAG		-22	/* illegal WILDCARD tag */
#define DFE_BREF		-23	/* illegal WILDCARD reference # */
#define DFE_RDONLY		-24	/* The DF is read only */
#define DFE_BCALL		-25	/* Calls in wrong order */
#define DFE_BPTR		-26 /* NULL ptr argument */
#define DFE_BLEN		-27	/* negative len specified */
#define DFE_BSEEK		-28	/* Attempt to seek past end of element */
#define DFE_NOMATCH		-29	/* No (more) DDs which match specified tag/ref */
#define DFE_NOTINSET	-30	/* Warning: Set contained unknown tag: ignored */
#define DFE_BDIM		-31	/* negative or zero dimensions specified */
#define DFE_BOFFSET	-32	/* Illegal offset specified */
#define DFE_BSCHEME	-33	/* Unknown compression scheme specified */
#define DFE_NODIM		-34	/* No dimension record associated with image */
#define DFE_NOTENOUGH	-35	/* space provided insufficient for size of data */

/*--------------------------------------------------------------------------*/
/*							Logical Constants 								*/

#define DFACC_READ		1	/* Read Access */
#define DFACC_WRITE		2	/* Write Access */
#define DFACC_CREATE	4	/* force file to be created */
#define DFACC_ALL		7	/* the logical and of all the above values */

#endif DFTG_NULL
