/*
 *	Global.h - Copyright © 1991 by S.R. & P.C.
 *
 *	Created:	16 Feb 1991  11:00:11
 *	Modified:	19 Jun 1991  18:15:36
 */


#ifdef TRACKER

#define AllocMem(size,type)	alloctrack(size,type,__FILE__,__FUNC__,__LINE__)
#define FreeMem(addr,size)	freetrack(addr,size,__FILE__,__FUNC__,__LINE__)
#define CopyStr(str)		copystrtrack(str,__FILE__,__FUNC__,__LINE__)
#define FreeStr(str)		freestrtrack(str,__FILE__,__FUNC__,__LINE__)
#define ParentDir(lock)		trackedparentdir(lock,__FILE__,__FUNC__,__LINE__)
#define CreateDir(str)		trackedcreatedir(str,__FILE__,__FUNC__,__LINE__)
#define Lock(str, mode)		trackedlock(str, mode,__FILE__,__FUNC__,__LINE__)
#define DupLock(lock)		trackedduplock(lock,__FILE__,__FUNC__,__LINE__)
#define UnLock(lock)		trackedunlock(lock,__FILE__,__FUNC__,__LINE__)

void *alloctrack(long size, long type, char *file, char *func, long line);
void freetrack(void *addr, long size, char *file, char *func, long line);
char *copystrtrack(char *str, char *file, char *func, long line);
void freestrtrack(char *str, char *file, char *func, long line);
BPTR trackedparentdir(BPTR lock, char *file, char *func, long line);
BPTR trackedcreatedir(char *str, char *file, char *func, long line);
BPTR trackedlock(char *str, long mode, char *file, char *func, long line);
BPTR trackedduplock(BPTR lock, char *file, char *func, long line);
void trackedunlock(BPTR lock, char *file, char *func, long line);
void freeall(void);
BOOL inittrack(void);

#endif


#define CONFIG_FILE				"Devs:BrowserII.cfg"
#define CONFIG_FILE_ERROR_MSG	"'%s' is not a\nBrowserII V1.00 config file!"
#define BROWSERII_MENU_FILE		"s:BrowserII.menu"

#define BROWSER_IDENT_STRING "BrowserII1.00cfg"
#define BROWSER_IDENT_STRING_LEN 17

#define MAX(x,y)	(x) > (y) ? (x) : (y)
#define MIN(x,y)	(x) < (y) ? (x) : (y)


#define PATTERN_BUF_SIZE 32

struct SelectInfo {
	BYTE   si_Pattern[PATTERN_BUF_SIZE];/* Pattern						*/
	BYTE   si_PatTok[PATTERN_BUF_SIZE];	/* PreParsed pattern			*/
	LONG   si_MinSize;					/* Show files bigger than that	*/
	LONG   si_MaxSize;					/*   and smaller than that		*/
	struct DateStamp si_SinceDate;		/* Show files newer than that	*/
	struct DateStamp si_BeforeDate;		/*   and older than that		*/
	LONG   si_SinceSecs;				/* date in seconds				*/
	LONG   si_BeforeSecs;				/* date in seconds				*/
	SHORT  si_PosProtect;				/* Show files that have these bits set   */
	SHORT  si_NegProtect;				/* Show files that have these bits clear */
	SHORT  si_Flags;					/* Flags. See below				*/
};

/* SelectInfo flags */

#define SI_ALL_FILES		0x0001
#define SI_MATCH_FILES		0x0002
#define SI_ALL_DIRS			0x0004
#define SI_MATCH_DIRS		0x0008
#define SI_AFFECT_SUBDIRS	0x0010
#define SI_NAME				0x0020
#define SI_SIZE				0x0040
#define SI_SINCEDATE		0x0080
#define SI_BEFOREDATE		0x0100
#define SI_POSPROTECTION	0x0200
#define SI_NEGPROTECTION	0x0400
#define SI_INVERT			0x0800		/* Invert filters */


/* Modes */

#define PROTECT_REQ		0
#define FILTERS_REQ		1
#define SELECT_REQ		2


struct Config {
	BYTE  IdentString[BROWSER_IDENT_STRING_LEN];
	UBYTE Screen;						/* See below */
	UBYTE CmdMode;						/* 0 -> Simple / != 0 -> Shell */
	UBYTE RunMode;						/* See below */
	UBYTE CopyMode;						/* See below */
	UBYTE CopyFlags;					/* See below */
	UBYTE Display;						/* DLF_mumble */
	UBYTE Options;						/* See below */
	UBYTE EntryInfoFlags;				/* DISPLAY_mumble */
	UBYTE Sort;							/* See below */
	struct SelectInfo DefaultFilters;	/* Default filters data */
	struct SelectInfo Select;			/* Sel Match data */
};


#define BROWSER_WORKBENCH	0x00
#define BROWSER_CUSTOM		0x01

#define RM_RUNBACK			0x01
#define RM_SHELL			0x02
#define RM_REQUEST			0x04

#define CM_CONTEXT			0x01
#define CM_ALLWAYS_COPY		0x02
#define CM_ALLWAYS_MOVE		0x04
#define CM_UPDATE			0x08
#define CM_DONT_OVERWRITE	0x10
#define CM_ASK_OVERWRITE	0x20
#define CM_COPY_EMPTYDIRS	0x40
#define CM_COPY_HIERARCHY	0x80

#define CF_CLONE			0x01
#define CF_DATE				0x02
#define CF_PROTECT			0x04
#define CF_COMMENT			0x08

#define OPT_KEEPSELECTED	0x01
#define OPT_TOGGLESELECT	0x02
#define OPT_MOVEINTOSUB		0x04
#define OPT_ASKBEFOREMOVE	0x08
#define OPT_ASYNCHRONOUS	0x10


struct FileInfo {
	BYTE   fi_Name[32];			/* Filename			*/
	SHORT  fi_Type;				/* DLX_mumble		*/
	SHORT  fi_Protection;		/* Protection bits	*/
	LONG   fi_Size;				/* Size in bytes	*/
	LONG   fi_NumBlocks;		/* Size in blocks	*/
	LONG   fi_DiskKey;			/* Root block		*/
	struct DateStamp fi_Date;	/* DateStamp		*/
	ULONG  fi_Secs;				/* date in seconds	*/
	BYTE   *fi_Comment;			/* File Comment		*/
};


struct ScrollEntry {
	struct MinNode se_Node;			/* Link node */
	struct FileInfo se_FileInfo;	/* Info on entry */
	char   *se_Print;				/* String shown to user */
	SHORT  se_Pen;					/* Display color for this entry */
	SHORT  se_State;				/* State of entry. STATE_SELECTED,... */
};


/* ScrollEntry States */

#define STATE_SELECTED	0x01
#define STATE_GHOSTED	0x02
#define STATE_DELETED	0x04


struct BrowserWindow {
	struct MinNode bw_Node;				/* Link Node */
	struct Window *bw_Window;			/* Intuition window pointer */
	UBYTE  bw_Type;						/* Is it main window or a dir */
	UBYTE  bw_Flags;					/* Update flags. See below */
	SHORT  bw_MaxFilenameLen;			/* You don't understand ?! */
	SHORT  bw_PrintStringLen;			/* Length of Print strings */
	SHORT  bw_PrintLen;					/* Len of entry given to Text(). May be smaller than bw_PrintStringLen */
	SHORT  bw_NumEntries;				/* Number of entries in directory */
	SHORT  bw_ShownEntries;				/* Number of shown entries in window */
	SHORT  bw_NumDirs;					/* Number of directories in directory */
	SHORT  bw_ShownDirs;				/* Number of directories shown */
	SHORT  bw_NumFiles;					/* Number of files in directory */
	SHORT  bw_ShownFiles;				/* Number of files shown */
	LONG   bw_NumBytes;					/* Total size in bytes of directory */
	LONG   bw_ShownBytes;				/* Total selected bytes */
	LONG   bw_NumBlocks;				/* Total size in blocks of directory */
	LONG   bw_ShownBlocks;				/* Total selected blocks */
	LONG   bw_SelectBytes;				/* Number of bytes selected */
	LONG   bw_SelectBlocks;				/* Number of blocks selected */
	SHORT  bw_SelectNum;				/* Number of selected entries */
	SHORT  bw_NumCol;					/* Number of columns in window */
	SHORT  bw_ColWidth;					/* Width in char of a column */
	BPTR   bw_DirLock;					/* Lock on dir. Not used in main window */
	BPTR   bw_RootLock;					/* Lock on root dir of volume. Not used in main window */
	BYTE   bw_BottomText[120];			/* Buffer for info displayed in bottom border of window */
	SHORT  bw_BottomLen;				/* Maximum len that can be displayed without trashing sizing gadget */
	UBYTE  bw_Sort;						/* Sort function for entries (see below). idem */
	UBYTE  bw_EntryInfoFlags;			/* Info displayed for each entry */
	struct SelectInfo bw_FiltersInfo;	/* Filter for entries displayed */
	struct MinList bw_EntryList;		/* Linked list of entries */
	struct ScrollEntry **bw_EntryArray;	/* Array[bw_NumEntries] of pointers on entries */
	struct ScrollStruct bw_ScrollStruct;/* For RealTimeScroll() */
	struct PropBlock bw_Prop;			/* Window prop gadget */
	struct MinList bw_NewEntryList;		/* List of entries to be added after an action */
	SHORT  bw_NumNewEntries;			/* Number of entries in NewEnties list */
	SHORT  bw_NumDeleted;				/* Number of entries deleted (marked by STATE_DELETED flag) */
	SHORT  bw_NewMaxFilenameLen;		/* While adding entries in a dir, this */
	BYTE   bw_Fmt[10];					/* Format string used to build filename sub-string of printstring */
};


/* BrowserWindow Types */

#define BW_DIR		0
#define BW_MAIN		1


/* BrowserWindow Flags */

#define BWF_REBUILD_STRINGS	0x01	/* Tell if PrintStrings must be rebuilt after an action */
#define BWF_REBUILD_ARRAY	0x02	/* Entries were added or deleted while an action, so array has to be rebuilt */
#define BWF_SORT			0x04	/* After a rename, entries have to be resorted */
#define BWF_CHECK_MAXLEN	0x08	/* An entry with a long filename was deleted or renamed, so check new MaxFilenameLen */


/* BrowserWindow EntryInfo display flags */

#define DISPLAY_FILENAME	0x00	/* Allways displayed */
#define DISPLAY_SIZE		0x01
#define DISPLAY_BLOCK		0x02
#define DISPLAY_PROTECT		0x04
#define DISPLAY_DATE		0x08
#define DISPLAY_KEY			0x10


/* Sort functions */

#define	NAME_SORT		0x00
#define DATE_SORT		0x01
#define SIZE_SORT		0x02
#define KEY_SORT		0x03
#define TYPE_SORT		0x10	/* Type sort may be added to the first four */


/* defined in intuitionbase.h but only if INTUITIONPRIVATE is also defined */

struct Point {
	short X;
	short Y;
};


