/* MRBackup - include file for global data and definitions.
 * Filename:	MRBackup.h
 * Date:		08/22/87
 *
 * History:		(most recent change first)
 *
 * 11/19/87 -MRR- V2.0: Changed window version and date.
 */

/* Main.c defines MAIN.  It should not defined elsewhere. */

#ifdef MAIN
#define EXTERN 
#else
#define EXTERN extern
#endif

#include <exec/memory.h>
#include <exec/types.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <stdio.h>
#include <ctype.h>
#include <setjmp.h>
#include <time.h>
#include <functions.h>

#include "gadget.h"
#include "menu.h"
#include "Console.h"

/* Constants */

#define false	0		/* for short parameter requirements */
#define true	1		/* for short parameter requirements */
#define BUFMAX (32L * 1024L) /* max size for copy/compress buffer */
#define LINES_PER_PAGE  60

#define VOLUME_MAX	32	/* max characters in volume name */
#define PATH_MAX	256 /* max characters in pathname (very arbitrary) */

/* Define error recovery constants.  Note that these are all powers
 * of 2 to allow creating 'sets' of allowable options during the
 * recovery prompt.
 */

#define NERRCODE			5	/* number of error recovery codes */

#define ERR_NONE			0	/* what we want ALL the time :-) */
#define ERR_ABORT			1	/* give up the ship */
#define ERR_RETRY_FILE		2	/* let's try that file one more time */
#define ERR_RESTART_VOLUME 	4	/* for media errors on output floppy */
#define ERR_IGNORE			8	/* ignore this error and trudge on */

/* Macros */

/* determine if a menu item is "checked" */

#define GadgetString(g) ((struct StringInfo *) g->SpecialInfo)->Buffer
#define IsChecked(item) ((item->Flags & CHECKED) == CHECKED)

typedef struct t_pattern {
	struct t_pattern * next_pattern;
	char *pattern;
	} T_PATTERN;

/* The following structure is used to link file and directory node
 * information into a doubly-linked list.  This provides a way to
 * defer processing of sub-directory nodes until all files in a
 * current directory are processed.  As nodes are "consumed", they 
 * are returned to free memory.
 */

typedef struct t_file {
	struct t_file  *previous,*next;
	char   			*filename;
	USHORT			blocks;
	BOOL 			is_dir;			/* TRUE => it's a directory */
	} T_FILE;

/* The following structure links lists of T_FILE nodes. */

typedef struct t_file_list {
	T_FILE *first_file;
	T_FILE *last_file;
	} T_FILE_LIST;

/* External and forward function declarations */

extern char   	*calloc(), *index(), *rindex();
extern long   	DiskBlocks();
extern int	  	errno;
T_FILE 		  	*FindFile();

/* External data */

extern struct Gadget stopGadget;

/* Global data */

#ifdef DEBUG
EXTERN ConIOBlocks *debugConsole;
EXTERN struct Window *debugWindow;
EXTERN char debugMsg[512];
#endif

EXTERN UBYTE *buffer;				/* file copy/cmprs buffer (AllocMem) */
EXTERN ULONG bufSize;				/* size of buffer allocated */
EXTERN ConIOBlocks *progressConsole;/* for informative messages */
EXTERN struct Window *progressWindow;
EXTERN char conmsg[512];
EXTERN T_FILE *currentDir = NULL;	/* current directory node */

EXTERN char	destPath[PATH_MAX+1];
EXTERN char destVol[VOLUME_MAX+1];
EXTERN short diskNumber;			/* backup disk serial number */
EXTERN USHORT errorCount;			/* count of errors on backup/restore */
EXTERN char *errName;               /* file name associated with error */
EXTERN BOOL excludeHasChanged;   	/* true when new path specified */
EXTERN T_PATTERN *excludeList, *lastExclude;
EXTERN char excludePath[81]; 		/* list of file patterns to exclude */
EXTERN struct FileInfoBlock *fibWork;	/* working file info block */
EXTERN struct GfxBase *GfxBase;		/* graphics library handle */
EXTERN struct IntuitionBase *IntuitionBase;

EXTERN USHORT level;				/* file nesting level */
EXTERN USHORT lineCount;			/* number of lines in listing */
EXTERN FILE *listing;
EXTERN T_FILE_LIST mainList;
EXTERN struct Screen *mainScreen;
EXTERN struct Window *mainWindow;

EXTERN struct DateStamp *now, *since; /* for date comparisons */
EXTERN struct Window *pathWindow;	/* pathname specification window */
EXTERN LONG sizeLeft;				/* floppy blocks remaining */
EXTERN char	srcPath[PATH_MAX];
EXTERN char	srcVol[VOLUME_MAX+1];	/* source volume name */
EXTERN char temp[256];
EXTERN LONG totalSize;				/* capacity of output device */

/* The following flags suppress repetition of spoken
 * messages.  After all, let's not over-do it.
 */

EXTERN UBYTE atYourService;

/* Preset data */

#ifdef MAIN

char backPath[81] = "DF0:";			/* where backups go and restores
									   come from. */
char destDrive[5] = "DF0:";
USHORT doBigFiles = 1;				/* Allow big file backups. */
USHORT doCompress = 1;				/* Perform file compression. */
USHORT doFormat = 1;				/* Format output disks */
USHORT doListing = 1;				/* Generate listing. */
USHORT doSpeech = 1;				/* Talk to the user. */

char homePath[81] = "DH0:";			/* Backup/Restore from/to here. */
char listPath[81] = "PRT:";			/* Listings go here. */
#else
/* Declare preset external data without the presets. */
extern char backPath[81];
extern char destDrive[5];
extern USHORT doBigFiles;
extern USHORT doCompress;
extern USHORT doFormat;
extern USHORT doListing;
extern USHORT doSpeech;
extern char homePath[81];
extern char listPath[81];
#endif
