Changeset 249 for trunk/src/helpers/dosh.c
- Timestamp:
- Feb 8, 2003, 9:57:38 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh.c
r244 r249 3893 3893 } 3894 3894 3895 #define FINDBUFSIZE 0x10000 // 64K 3896 #define FINDCOUNT 500 3897 3898 /* 3899 *@@ doshForAllFiles: 3900 * this calles pfncb for all files in a directory matching 3901 * the given file mask. 3902 * 3903 * This is to avoid having to recode the typical but 3904 * easy-to-get-wrong DosFindFirst/Next loop. 3905 * 3906 * pfncb must be prototyped as follows: 3907 * 3908 + APIRET XWPENTRY fnMyCallback(const FILEFINDBUF3 *pfb3, 3909 + PVOID pvCallback) 3910 * 3911 * On each iteration, it receives the current file-find 3912 * buffer in pfb3. pvCallback is constantly set to what 3913 * was passed in to this function. 3914 * 3915 * The callback will get called for every file returned 3916 * from the loop. This function will automatically 3917 * filter out the stupid "." and ".." directory entries 3918 * that DosFindFirst/Next always return, so the callback 3919 * will never see those. 3920 * 3921 * If the callback returns any value other than NO_ERROR, 3922 * this function aborts and returns that error. The 3923 * exception is that if the callback returns 3924 * ERROR_NO_MORE_FILES, this function will abort also, 3925 * but return NO_ERROR still. This is useful if you are 3926 * looking for a specific file and want to cancel the 3927 * search early without provoking an error. 3928 * 3929 *@@added V1.0.2 (2003-02-03) [umoeller] 3930 */ 3931 3932 APIRET doshForAllFiles(PCSZ pcszSearchMask, // in: search mask (e.g. "C:\dir\*.txt") 3933 ULONG flFile, // in: any of FILE_ARCHIVED | FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_DIRECTORY 3934 FNCBFORALLFILES *pfncb, // in: address of callback function 3935 PVOID pvCallback) // in: parameter passed to callback 3936 { 3937 APIRET arc = NO_ERROR; 3938 HDIR hdirFindHandle = HDIR_CREATE; 3939 ULONG ulFindCount = FINDCOUNT; 3940 3941 PBYTE pbFindBuf; 3942 3943 if (arc = DosAllocMem((PVOID*)&pbFindBuf, 3944 FINDBUFSIZE, 3945 PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_TILE)) 3946 return arc; 3947 3948 arc = DosFindFirst((PSZ)pcszSearchMask, 3949 &hdirFindHandle, 3950 flFile, 3951 pbFindBuf, 3952 FINDBUFSIZE, 3953 &ulFindCount, 3954 FIL_STANDARD); 3955 3956 while ( (arc == NO_ERROR) 3957 || (arc == ERROR_BUFFER_OVERFLOW) 3958 ) 3959 { 3960 ULONG ul; 3961 PFILEFINDBUF3 pfb3 = (PFILEFINDBUF3)pbFindBuf; 3962 3963 for (ul = 0; 3964 ul < ulFindCount; 3965 ul++) 3966 { 3967 // filter out the "." and ".." entries 3968 if (!( (pfb3->attrFile & FILE_DIRECTORY) 3969 && (pfb3->achName[0] == '.') 3970 && ( (pfb3->achName[1] == '\0') 3971 || ( (pfb3->achName[1] == '.') 3972 && (pfb3->achName[2] == '\0') 3973 ) 3974 ) 3975 )) 3976 { 3977 // call callback 3978 if (arc = pfncb(pfb3, pvCallback)) 3979 // callback returned error: 3980 break; 3981 } 3982 3983 // next item in buffer 3984 if (pfb3->oNextEntryOffset) 3985 pfb3 = (PFILEFINDBUF3)( (PBYTE)pfb3 3986 + pfb3->oNextEntryOffset 3987 ); 3988 } 3989 3990 if (!arc) 3991 { 3992 ulFindCount = FINDCOUNT; 3993 arc = DosFindNext(hdirFindHandle, 3994 pbFindBuf, 3995 FINDBUFSIZE, 3996 &ulFindCount); 3997 } 3998 } 3999 4000 // no more files is not an error 4001 if (arc == ERROR_NO_MORE_FILES) 4002 arc = NO_ERROR; 4003 4004 DosFindClose(hdirFindHandle); 4005 4006 DosFreeMem(pbFindBuf); 4007 4008 return arc; 4009 } 4010 3895 4011 /* 3896 4012 *@@category: Helpers\Control program helpers\Module handling
Note:
See TracChangeset
for help on using the changeset viewer.