ResKnife/External/MoreFiles/Search.c

1 line
37 KiB
C
Raw Normal View History

2002-03-29 14:59:03 +00:00
/* File: Search.c Contains: IndexedSearch and the PBCatSearch compatibility function. Version: MoreFiles Copyright: <09> 1992-2001 by Apple Computer, Inc., all rights reserved. You may incorporate this sample code into your applications without restriction, though the sample code has been provided "AS IS" and the responsibility for its operation is 100% yours. However, what you are not permitted to do is to redistribute the source as "DSC Sample Code" after having made changes. If you're going to re-distribute the source, we require that you make it clear in the source that the code was descended from Apple Sample Code, but that you've made changes. File Ownership: DRI: Jim Luther Other Contact: Apple Macintosh Developer Technical Support <http://developer.apple.com/bugreporter/> Technology: DTS Sample Code Writers: (JL) Jim Luther Change History (most recent first): <2> 2/7/01 JL Added standard header. Updated names of includes. Updated various routines to use new calling convention of the MoreFilesExtras accessor functions. Added TARGET_API_MAC_CARBON conditional checks around TimeOutTask. <1> 12/06/99 JL MoreFiles 1.5. */ #include <MacTypes.h> #include <Gestalt.h> #include <Timer.h> #include <MacErrors.h> #include <MacMemory.h> #include <Files.h> #include <TextUtils.h> #define __COMPILINGMOREFILES #include "MoreFiles.h" #include "MoreFilesExtras.h" #include "Search.h" /*****************************************************************************/ enum { /* Number of LevelRecs to add each time the searchStack is grown */ /* 20 levels is probably more than reasonable for most volumes. */ /* If more are needed, they are allocated 20 levels at a time. */ kAdditionalLevelRecs = 20 }; /*****************************************************************************/ /* ** LevelRecs are used to store the directory ID and index whenever ** IndexedSearch needs to either scan a sub-directory, or return control ** to the caller because the call has timed out or the number of ** matches requested has been found. LevelRecs are stored in an array ** used as a stack. */ struct LevelRec { long dirModDate; /* for detecting most (but not all) catalog changes */ long dirID; short index; }; typedef struct LevelRec LevelRec; typedef LevelRec *LevelRecPtr, **LevelRecHandle; /* ** SearchPositionRec is my version of a CatPositionRec. It holds the ** information I need to resuming searching. */ #if PRAGMA_STRUCT_ALIGN #pragma options align=mac68k #endif struct SearchPositionRec { long initialize; /* Goofy checksum of volume information used to make */ /* sure we're resuming a search on the same volume. */ unsigned short stackDepth; /* Current depth on searchStack. */ short priv[11]; /* For future use... */ }; #if PRAGMA_STRUCT_ALIGN #pragma options align=reset #endif typedef struct SearchPositionRec SearchPositionRec; typedef SearchPositionRec *SearchPositionRecPtr; /* ** ExtendedTMTask is a TMTask record extended to hold the timer flag. */ #if PRAGMA_STRUCT_ALIGN #pragma options align=mac68k #endif struct ExtendedTMTask { TMTask theTask; Boolean stopSearch; /* the Time Mgr task will set stopSearch to */ /* true when the timer expires */ }; #if PRAGMA_STRUCT_ALIGN #pragma options align=reset #endif typedef struct ExtendedTMTask ExtendedTMTask; typedef ExtendedTMTask *ExtendedTMTaskPtr; /*****************************************************************************/ static OSErr CheckVol(ConstStr255Param pathname, short vRefNum, short *realVRefNum, long *volID); static OSErr CheckStack(unsigned short stackDepth, LevelRecHandle searchStack, Size *searchStackSize); static OSErr VerifyUserPB(CSParamPtr userPB, Boolean *includeFiles, Boolean *includeDirs, Boolean *includeNames); static Boolean IsSubString(ConstStr255Param aStringPtr, ConstStr255Param subStringPtr); static Boolean CompareMasked(const long *data1, const long *data2,