2 ** Apple Macintosh Developer Technical Support
4 ** IndexedSearch and the PBCatSearch compatibility function.
6 ** by Jim Luther, Apple Developer Technical Support Emeritus
10 ** Copyright © 1992-1998 Apple Computer, Inc.
11 ** All rights reserved.
13 ** You may incorporate this sample code into your applications without
14 ** restriction, though the sample code has been provided "AS IS" and the
15 ** responsibility for its operation is 100% yours. However, what you are
16 ** not permitted to do is to redistribute the source as "DSC Sample Code"
17 ** after having made changes. If you're going to re-distribute the source,
18 ** we require that you make it clear in the source that the code was
19 ** descended from Apple Sample Code, but that you've made changes.
34 /*****************************************************************************/
36 pascal OSErr
IndexedSearch(CSParamPtr pb
,
38 /* ¦ Search in and below a directory.
39 The IndexedSearch function performs an indexed search in and below the
40 specified directory using the same parameters (in pb) as is passed to
41 PBCatSearch. See Inside Macintosh: Files for a description of the
44 pb input: A CSParamPtr record specifying the volume to search
45 and the search criteria.
46 output: Fields in the parameter block are returned indicating
47 the number of matches found, the matches, and if the
48 search ended with noErr, the CatPosition record that
49 lets you resume a search where the last search left
51 dirID input: The directory to search. If fsRtDirID is passed,
52 the entire volume is searched.
54 Note: If you use a high-level debugger and use ioSearchTime to limit
55 the length of time to run the search, you'll want to step over
56 calls to IndexedSearch because it installs a Time Manager task.
57 Most high-level debuggers don't deal gracefully with interrupt
62 nsvErr -35 Volume not found
64 eofErr -39 End of catalog found (this is normal!)
65 paramErr -50 Parameter block has invalid parameters
66 (see source for VerifyUserPB) or
67 invalid catPosition record was passed
68 extFSErr -58 External file system error - no file
69 system claimed this call.
70 memFullErr -108 Memory could not be allocated in heap
71 catChangedErr -1304 Catalog has changed and catalog position
76 See also: PBCatSearch, PBCatSearchSyncCompat
79 /*****************************************************************************/
81 pascal OSErr
PBCatSearchSyncCompat(CSParamPtr paramBlock
);
82 /* ¦ Search a volume using PBCatSearch or IndexedSearch.
83 The PBCatSearchSyncCompat function uses PBCatSearch (if available) or
84 IndexedSearch (if PBCatSearch is not available) to search a volume
85 using a set of search criteria that you specify. It builds a list of all
86 files or directories that meet your specifications.
88 pb input: A CSParamPtr record specifying the volume to search
89 and the search criteria.
90 output: Fields in the parameter block are returned indicating
91 the number of matches found, the matches, and if the
92 search ended with noErr, the CatPosition record that
93 lets you resume a search where the last search left
96 Note: If you use a high-level debugger and use ioSearchTime to limit
97 the length of time to run the search, you'll want to step over
98 calls to PBCatSearchSyncCompat because it calls IndexedSearch
99 which installs a Time Manager task. Most high-level debuggers
100 don't deal gracefully with interrupt driven code.
104 nsvErr -35 Volume not found
106 eofErr -39 End of catalog found (this is normal!)
107 paramErr -50 Parameter block has invalid parameters
108 (see source for VerifyUserPB) or
109 invalid catPosition record was passed
110 extFSErr -58 External file system error - no file
111 system claimed this call.
112 memFullErr -108 Memory could not be allocated in heap
113 catChangedErr -1304 Catalog has changed and catalog position
114 record may be invalid
115 afpCatalogChanged -5037 Catalog has changed and search cannot
120 See also: PBCatSearch, IndexedSearch
123 /*****************************************************************************/
125 pascal OSErr
NameFileSearch(ConstStr255Param volName
,
127 ConstStr255Param fileName
,
133 /* ¦ Search for files by file name with PBCatSearch.
134 The NameFileSearch function searches for files with a specific file
135 name on a volume that supports PBCatSearch.
136 Note: A result of catChangedErr means the catalog has changed between
137 searches, but the search can be continued with the possiblity that you
138 may miss some matches or get duplicate matches. For all other results
139 (except for noErr), the search cannot be continued.
141 volName input: A pointer to the name of a mounted volume
143 vRefNum input: Volume specification.
144 fileName input: The name of the file to search for.
145 matches input: Pointer to array of FSSpec where the match list is
147 reqMatchCount input: Maximum number of matches to return (the number of
148 elements in the matches array).
149 actMatchCount output: The number of matches actually returned.
150 newSearch input: If true, start a new search. If false and if
151 vRefNum is the same as the last call to
152 NameFileSearch, then start searching at the
153 position where the last search left off.
154 partial input: If the partial parameter is false, then only files
155 that exactly match fileName will be found. If the
156 partial parameter is true, then all file names that
157 contain fileName will be found.
161 nsvErr -35 Volume not found
163 eofErr -39 End of catalog found (this is normal!)
164 paramErr -50 Parameter block has invalid parameters
165 (see source for VerifyUserPB) or
166 invalid catPosition record was passed
167 extFSErr -58 External file system error - no file
168 system claimed this call.
169 memFullErr -108 Memory could not be allocated in heap
170 catChangedErr -1304 Catalog has changed and catalog position
171 record may be invalid
172 afpCatalogChanged -5037 Catalog has changed and search cannot
177 Also see: CreatorTypeFileSearch
180 /*****************************************************************************/
182 pascal OSErr
CreatorTypeFileSearch(ConstStr255Param volName
,
190 /* ¦ Search for files by creator/fileType with PBCatSearch.
191 The CreatorTypeFileSearch function searches for files with a specific
192 creator or fileType on a volume that supports PBCatSearch.
193 Note: A result of catChangedErr means the catalog has changed between
194 searches, but the search can be continued with the possiblity that you
195 may miss some matches or get duplicate matches. For all other results
196 (except for noErr), the search cannot be continued.
198 volName input: A pointer to the name of a mounted volume
200 vRefNum input: Volume specification.
201 creator input: The creator type of the file to search for.
202 To ignore the creator type, pass 0x00000000 in
204 fileType input: The file type of the file to search for.
205 To ignore the file type, pass 0x00000000 in
207 matches input: Pointer to array of FSSpec where the match list is
209 reqMatchCount input: Maximum number of matches to return (the number of
210 elements in the matches array).
211 actMatchCount output: The number of matches actually returned.
212 newSearch input: If true, start a new search. If false and if
213 vRefNum is the same as the last call to
214 CreatorTypeFileSearch, then start searching at the
215 position where the last search left off.
219 nsvErr -35 Volume not found
221 eofErr -39 End of catalog found (this is normal!)
222 paramErr -50 Parameter block has invalid parameters
223 (see source for VerifyUserPB) or
224 invalid catPosition record was passed
225 extFSErr -58 External file system error - no file
226 system claimed this call.
227 memFullErr -108 Memory could not be allocated in heap
228 catChangedErr -1304 Catalog has changed and catalog position
229 record may be invalid
230 afpCatalogChanged -5037 Catalog has changed and search cannot
235 Also see: NameFileSearch
238 /*****************************************************************************/
244 #include "optimend.h"
246 #endif /* __SEARCH__ */