/*
**	Find - AmigaDOS 2.04 commodities utility
**
**	Copyright © 1991-1992 by Olaf `Olsen' Barthel
**		All Rights Reserved
*/

#include "FindGlobal.h"

	/* Current version tag identifier. */

STATIC UBYTE		*Version = "\0$VER: Find 1.7 (8.5.92)";

	/* Global and share library bases. */

struct IntuitionBase	*IntuitionBase;
struct GfxBase		*GfxBase;
struct Library		*WorkbenchBase;
struct Library		*IconBase;
struct Library		*IFFParseBase;
struct Library		*GadToolsBase;
struct Library		*UtilityBase;
struct Library		*AslBase;
struct Library		*CxBase;

	/* Process and handshake data. */

struct Process		*MainProcess;
struct Process		*FindProcess;
BYTE			 ReplySignal;

	/* Clipboard server data. */

struct Process		*ClipProcess;
struct MsgPort		*ClipPort;

	/* Workbench interface data. */

struct MsgPort		*WorkbenchPort;
struct AppWindow	*WorkbenchWindow;

	/* Gadget and graphics data. */

APTR			 VisualInfo;
struct Gadget		*GadgetList;
struct Gadget		*GadgetArray[7];
struct Hook		 StringHook;
struct Gadget		*LastActiveGadget;
struct Screen		*DefaultScreen;
struct Window		*Window;
UBYTE			 WindowTitle[300];
UWORD			 WindowWidth,
			 WindowHeight;
struct RastPort		*RPort;
struct DrawInfo		*DrawInfo;
BYTE			 SelectWhich = GAD_SEARCHAREA;

	/* Alternate window position/size data. */

struct IBox ZoomBox =
{
	-1,-1,
	-1,-1
};

	/* Name list counters. */

WORD			 ListTopLine,
			 PathTopLine,
			 ListRightColumn;

LONG			 ListTop,
			 LastSelected = -1;

LONG			 NumFiles,
			 NumDirs,
			 NumLinks;

	/* Some more name list data. */

struct NameString	**NameList;
LONG			  NumNames,
			  MaxNames;

struct List		  FileList;
struct FatNode		  FileNames[10];
struct List		  EmptyList;

	/* Various string buffers. */

UBYTE			 AreaName[256],
			 SearchString[256],
			 MessageBuffer[256];

UBYTE			 FullFileName[512],
			 LastFileName[32];

UBYTE			 Date[20],
			 Time[20];

LONG			 MaxNameLen;
UBYTE			 MaxNameFormat[50];

	/* Various flags. */

BYTE			 Aborted,
			 Scanning,
			 WasIconified,
			 NewLook,
			 Terminated,
			 IconTerminated,
			 DoIconify,
			 UseWildcards = TRUE;

	/* Both file requester structures. */

struct FileRequester	*FileRequest,
			*SaveFileRequest;

	/* The menu definition data. */

struct NewMenu FindMenuConfig[] =
{
	{ NM_TITLE, "Project",			 0 ,0,			0, (APTR)0},
	{  NM_ITEM, "Save file list as",	 0 ,NM_ITEMDISABLED,	0, (APTR)NULL},
	{   NM_SUB, "Full path names...",	"1",0,			0, (APTR)MEN_FULL},
	{   NM_SUB, "File names only...",	"2",0,			0, (APTR)MEN_FILE},
	{   NM_SUB, "`List' style format...",	"3",0,			0, (APTR)MEN_LIST},
	{  NM_ITEM, NM_BARLABEL,		 0 ,0,			0, (APTR)0},
	{  NM_ITEM, "About...",			"?",0,			0, (APTR)MEN_ABOUT},
	{  NM_ITEM, NM_BARLABEL,		 0 ,0,			0, (APTR)0},
	{  NM_ITEM, "Quit",			"Q",0,			0, (APTR)MEN_QUIT},

	{ NM_TITLE, "Edit",			 0 ,0,			0, (APTR)0},
	{  NM_ITEM, "Copy path to clipboard",	"C",NM_ITEMDISABLED,	0, (APTR)MEN_COPY},

	{ NM_TITLE, "Actions",			 0 ,0,			0, (APTR)0},
	{  NM_ITEM, "Select search area...",	"A",0,			0, (APTR)MEN_SELECTAREA},
	{  NM_ITEM, "Iconify",			"I",0,			0, (APTR)MEN_ICONIFY},

	{ NM_END, 0,				 0 ,0,			0, (APTR)0}
};

struct Menu		*FindMenu;

	/* Text and font data. */

struct TextFont		*DefaultFont;
struct TextAttr		 SystemFont;
UBYTE			 SystemFontName[256];
UWORD			 SystemFontWidth,
			 SystemFontHeight,
			 SystemFontBase;
struct TextAttr		 BigSystemFont;
UBYTE			 BigSystemFontName[256];

	/* Commodities toolkit interface data. */

struct MsgPort		*CxPort;
CxObj			*Broker;
UBYTE			 HotkeyBuffer[256];
LONG			 CxPriority;
UBYTE			**ToolTypes;

struct NewBroker NewBroker =
{
	NB_VERSION,
	"Find",
	"Find v1.7",
	"File find utility",
	NBU_NOTIFY | NBU_UNIQUE,
	COF_SHOW_HIDE,
	0,NULL,0
};

	/* Data required for pattern matching. */

UBYTE			 MatchData[256],
			 NewPattern[256],
			 PatternDistance[256];
WORD			 PatternWidth;

	/* The stopwatch mouse pointer. */

UWORD __chip Stopwatch[(2 + 16) * 2] =
{
	0x0000,0x0000,

	0x0400,0x07C0,
	0x0000,0x07C0,
	0x0100,0x0380,
	0x0000,0x07E0,
	0x07C0,0x1FF8,
	0x1FF0,0x3FEC,
	0x3FF8,0x7FDE,
	0x3FF8,0x7FBE,
	0x7FFC,0xFF7F,
	0x7EFC,0xFFFF,
	0x7FFC,0xFFFF,
	0x3FF8,0x7FFE,
	0x3FF8,0x7FFE,
	0x1FF0,0x3FFC,
	0x07C0,0x1FF8,
	0x0000,0x07E0,

	0x0000,0x0000
};

	/* The names of all file types we know of. */

UBYTE *FileTypes[] =
{
	NULL,
	"(Drawer)",
	"Workbench icon file",
	"ASCII text file",
	"`C' source code file",
	"`C' header file",
	"Assembly language source code file",
	"Assembly language include file",
	"Modula-2/Oberon source code file",
	"ARexx script file",
	"Basic source code",
	"AmigaGuide document file",
	"TeX document file",
	"Metafont font file",
	"Generic font file",
	"Packed TeX font file",
	"TeX device independent output file",
	"PasTeX font library file",
	"Manx 3.x object code file",
	"Manx 5.x object code file",
	"Manx 3.x library file",
	"Manx 5.x library file",
	"AmigaDOS object code file",
	"AmigaDOS object code library file",
	"AmigaDOS executable file",
	"System library file",
	"System device file",
	"AmigaDOS filing system handler file",
	"AmigaDOS handler file",
	"GIF image file",
	"Degas image file",
	"MacPaint image file",
	"SuperPaint image file",
	"Macintosh PICT image file",
	"Sun raster image file",
	"Postscript file",
	"PCX image file",
	"TIFF image file",
	"Windows bitmap image file",
	"JFIF image file",
	"IFF-ILBM image file",
	"IFF-ANIM animation file",
	"IFF-8SVX sound file",
	"IFF-SMUS score file",
	"IFF-FTXT text file",
	"IFF-PREF preferences file",
	"IFF-TERM `term' configuration file",
	"IFF file",
	"AmigaVision flow file",
	"Imploder data output file",
	"PowerPacker data output file",
	"LhPak self extracting archive",
	"LhASFX self extracting archive",
	"Arc archive file",
	"ARJ archive file",
	"Compressed file",
	"CPIO archive file",
	"MacCompress archive file",
	"Compact archive file",
	"Diamond archive file",
	"LhArc archive file",
	"LHA archive file",
	"Zoo archive file",
	"PKZip archive file",
	"Stuff It! archive file",
	"Pack It! archive file",
	"DMS disk archive file",
	"Warp disk archive file",
	"Zoom disk archive file",
	"SPARC object code",
	"SPARC executable",
	"MS-DOS executable",
	"Atari-ST/TT executable",
	"Macintosh executable",
	"(Drawer, linked)"
};
