/*
** filefinder.h
**
** Header for FileFinder Package
**
** $Id: filefinder.h,v 1.0 94/08/09 17:03:53 GF Exp Locker: GF $
**
**************************************************************************
**
** Copyright © 1994 by Gabriele Falcioni. All Rights Reserved.
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** For inquiries, comments, donations, bug reports, write to:
**
** Gabriele Falcioni
** via E. Cialdini, 50
** I-60122 Ancona
** ITALY
**
*/

#ifndef USRH_FILEFINDER_H
#define USRH_FILEFINDER_H 1

/* -------------------------------------------------------------------- */

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

#ifndef DOS_DOS_H
#include <dos/dos.h>
#endif

#ifndef DOS_DOSASL_H
#include <dos/dosasl.h>
#endif

/* --- STRUCTUREs ----------------------------------------------------- */

struct FileFinder {

	struct Hook *ff_DirHook;

	UBYTE **ff_FList;
	LONG    ff_FNum;

	LONG ff_BufLen;
	LONG ff_BrkMsk;

	UBYTE ff_Flags;
	UBYTE ff_State;
	UBYTE ff_pad[2];

	LONG ff_SABuf[2];

	struct AnchorPath ff_AP;

};

#define FILEFF_ALL	0x01	/* matcher searches all *matching* directories */
#define FILEFF_DODIR	0x02	/* matcher enters directories */

#define FFSTATE_INIT		0	/* matcher beginning */
#define FFSTATE_FIRST	1	/* first match */
#define FFSTATE_NEXT		2	/* next match */
#define FFSTATE_DONE		3	/* matcher has done */

/* -------------------------------------------------------------------- */

/*
 * passed as message parameter to ff_DirHook
 */

#define FFHOOK_ENTERDIR	1
#define FFHOOK_LEAVEDIR	2
#define FFHOOK_IGNORED	3

/* -------------------------------------------------------------------- */

struct TreeFilter {

	struct Hook *trf_DisplayHook;

	BPTR trf_Source;	/* BCPL pointer to source file handle */
	BPTR trf_Target;	/* BCPL pointer to target file handle */

	UBYTE **trf_FList;
	LONG    trf_FNum;
	UBYTE  *trf_FTarget;

	UBYTE trf_Options;
	UBYTE trf_Flags;
	UBYTE trf_State;
	UBYTE trf_pad[1];

	LONG trf_BufLen;
	LONG trf_BrkMsk;

	LONG trf_SABuf[2];

	BPTR                 trf_DestLock;
	struct FileInfoBlock trf_FIB;
	UBYTE               *trf_Buf;

	struct AnchorPath    trf_AP;
};

#define TREEFF_DODIR			0x10	/* matcher enters directories */
#define TREEFF_TARGETDIR	0x20	/* target is a directory */
#define TREEFF_MULTIPLEF	0x40	/* multiple files mode */
#define TREEFF_TARGETED		0x80	/* target evaluated and initialized */

#define TREEFF_ALL			0x01	/* matcher searches all *matching* directories */
#define TREEFF_CLONEPROT	0x02	/* clone protection bits */
#define TREEFF_CLONECOMM	0x04	/* clone comments */
#define TREEFF_CLONEDATE	0x08	/* clone timestamps */
#define TREEFF_OPENFILES	0x10	/* open source and target files */

/* -------------------------------------------------------------------- */

/*
 * passed as message parameter to trf_DisplayHook
 */

#define TRFHOOK_ENTERNEWDIR	1
#define TRFHOOK_ENTEROLDDIR	2
#define TRFHOOK_OPENNEWFILE	3
#define TRFHOOK_LEAVEDIR		4

/* --- TAGs ----------------------------------------------------------- */

/* tags for CreateFileFinderA() */

#define FILEFT_Arg			(TAG_USER+1)	/* (UBYTE *)  single pattern */
#define FILEFT_Argv			(TAG_USER+2)	/* (UBYTE **) pattern list (NULL terminated) */
#define FILEFT_All			(TAG_USER+3)	/* (BOOL) search all matching directories */

#define FILEFT_MaxNameLen	(TAG_USER+4)	/* (LONG) buffer length for pathnames */
#define FILEFT_BreakBits	(TAG_USER+5)	/* (LONG) break signals mask */

#define FILEFT_DirHook		(TAG_USER+6)	/* (struct Hook *) called for every dir */

/* tags for CreateTreeFilterA() */

#define TREEFT_From			FILEFT_Arg
#define TREEFT_Fromv			FILEFT_Argv
#define TREEFT_To				(TAG_USER+20)	/* (UBYTE *) destination path */
#define TREEFT_All			FILEFT_All

#define TREEFT_MaxNameLen	FILEFT_MaxNameLen
#define TREEFT_BreakBits	FILEFT_BreakBits

#define TREEFT_CopyProts	(TAG_USER+21)	/* (BOOL) copy protection bits */
#define TREEFT_CopyComment	(TAG_USER+22)	/* (BOOL) copy comments */
#define TREEFT_CopyDate		(TAG_USER+23)	/* (BOOL) copy date */
#define TREEFT_OpenFiles	(TAG_USER+24)	/* (BOOL) open source/target files */

#define TREEFT_DisplayHook	(TAG_USER+25)	/* (struct Hook *) called for traversed/created objects */

/* --- PROTOTYPEs ----------------------------------------------------- */

#ifndef ASM
#define ASM __asm
#endif

#ifndef REG
#define REG(r) register __ ## r
#endif

/*
 * REQUIRED LIBRARIES
 *
 * "exec.library"		V37+
 * "dos.library"		V37+
 * "utility.library"	V37+
 */

/* from file: "filefinder.c" */

struct FileFinder * __stdargs CreateFileFinder(Tag tag1, ... );
struct FileFinder * ASM CreateFileFinderA(REG(a0) struct TagItem *tl);
VOID ASM DeleteFileFinder(REG(a0) struct FileFinder *ff);

BOOL ASM FindFiles(REG(a0) struct FileFinder *ff);

/* struct AnchorPath *GetAnchorPath(struct FileFinder *ff); */
#define GetAnchorPath(ff) (&(ff)->ff_AP)

/* UBYTE *GetFoundFileName(struct FileFinder *ff); */
#define GetFoundFileName(ff) ((ff)->ff_AP.ap_Buf)

/* struct FileInfoBlock *GetFoundFileInfoBlock(struct FileFinder *ff); */
#define GetFoundFileInfoBlock(ff) (&(ff)->ff_AP.ap_Info)

/* from file: "setffargs.c" */

VOID __stdargs SetFileFinderArgs(struct FileFinder *ff,Tag tag1, ... );
VOID ASM SetFileFinderArgsA(REG(a0) struct FileFinder *ff,
	REG(a1) struct TagItem *tl);

/* from file: "openffile.c" */

BPTR ASM OpenFoundFile(REG(a0) struct FileFinder *ff, REG(d0) LONG mode);

/* from file: "lockffile.c" */

BPTR ASM LockFoundFile(REG(a0) struct FileFinder *ff, REG(d0) LONG mode);

/* from file: "treefilter.c" */

struct TreeFilter * __stdargs CreateTreeFilter(Tag tag1, ... );
struct TreeFilter * ASM CreateTreeFilterA(REG(a0) struct TagItem *tl);
VOID ASM DeleteTreeFilter(REG(a0) struct TreeFilter *trf);

BOOL ASM FilterTree(REG(a0) struct TreeFilter *trf);

/* BPTR GetSourceFH(struct TreeFilter *trf); */
#define GetSourceFH(trf) ((trf)->trf_Source)

/* BPTR GetTargetFH(struct TreeFilter *trf); */
#define GetTargetFH(trf) ((trf)->trf_Target)

/* UBYTE *GetSourceName(struct TreeFilter *trf); */
#define GetSourceName(trf) ((trf)->trf_AP.ap_Buf)

/* UBYTE *GetTargetName(struct TreeFilter *trf); */
#define GetTargetName(trf) ((trf)->trf_Buf)

/* -------------------------------------------------------------------- */

#endif /* USRH_FILEFINDER_H */
