home *** CD-ROM | disk | FTP | other *** search
- /*
- ** recffind.c
- ** contains: recffind()
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "gfuncts.h"
- #include "disk.h"
- #include "timedate.h"
-
-
- #ifdef _MSC
- #pragma pack(1)
- #endif
-
- void GF_CONV _recff(char *,char *,void (*)(char *,char *,struct TIMEDATE *,
- unsigned char,unsigned long));
-
- /*
- ** int
- ** recffind(char *path,char *filespec,void (*usrfunc)())
- **
- ** ARGUMENT(s)
- ** path - path name to begin searching from ("\\" will
- ** search the entire disk).
- **
- ** filespec - filename(s) to search for (can contain wildcards)
- **
- ** usrfunc - user defined function to be called each time
- ** a file is found. This user defined function will
- ** be called with the following parameters.
- **
- ** (char *pathname,char *filename,TIMEDATE *td,
- ** unsigned char fileattribute,unsigned long filesize)
- ** DESCRIPTION
- ** Search a specified path for all files that match filespec. Then check
- ** specified path for "child" directories, if they are found check for
- ** files matching the filespec. Each time a file matching the filespec
- ** is found the user defined function (usrfunc) is called with the
- ** parameters listed above.
- **
- ** RETURNS
- ** GFSUCCESS or NOTENOUGHMEMORY
- **
- ** AUTHOR
- ** "" Thu 22-Dec-1988 09:26:36
- ** Copyright (C)1988-1990 Greenleaf Software Inc. All Rights Reserved.
- **
- ** MODIFICATIONS
- **
- */
- int GF_CONV recffind(path,filespec,usrfunc)
- char *path;
- char *filespec;
- #ifdef LINT_ARGS
- void (*usrfunc)(char *,char *,struct TIMEDATE *,unsigned char,unsigned long);
- #else
- void (*usrfunc)();
- #endif
- {
- char *newpath=(char *)0,*newspec=(char *)0;
-
- if((newpath=malloc(144))==(char *)0||
- (newspec=malloc(144))==(char *)0) {
- if(newpath)
- free(newpath);
- if(newspec)
- free(newspec);
- return(NOTENOUGHMEMORY);
- }
- strcpy(newpath,path);
- strcpy(newspec,filespec);
- _recff(newpath,newspec,usrfunc);
- free(newpath);
- free(newspec);
- return(GFSUCCESS);
- }
-
-
- /*
- ** void
- ** _recff(char *path,char *filespec,int (*usrfunc)())
- **
- ** ARGUMENT(s)
- ** same as recffind() except that the path and filespec sizes have
- ** been increased and the path & filespec values passed to recffind()
- ** have been copied into these new variables.
- **
- ** DESCRIPTION
- ** scans the directory specified by path, calling usrfunc() as each
- ** file matching filespec is found. The directory is then scanned again
- ** looking for other directories, if any are found _recff() calls itself
- ** to process the files and/or directories in the child directory. NOTE:
- ** _recff() should only be called from recffind().
- **
- **
- ** RETURNS
- ** void
- **
- ** AUTHOR
- ** "" Thu 22-Dec-1988 15:55:59
- ** Copyright (C)1988-1990 Greenleaf Software Inc. All Rights Reserved.
- **
- ** MODIFICATIONS
- **
- */
- void GF_CONV _recff(path,filespec,usrfunc)
- char *path;
- char *filespec;
- #ifdef LINT_ARGS
- void (*usrfunc)(char *,char *,struct TIMEDATE *,unsigned char,unsigned long);
- #else
- void (*usrfunc)();
- #endif
- {
- char *pathbreak,*searchname;
- FFFNBUF ffbuf;
- static char pathname[144];
- static struct TIMEDATE td;
-
- if(path[strlen(path)-1]!='\\')
- strcat(path,"\\");
- pathbreak=path+strlen(path);
- strcpy(pathname,path);
- strcpy(pathbreak,filespec);
- searchname=path;
- while(!filefind(READONLY|HIDDEN|SYSTEM|ARCHIVE,searchname,&ffbuf)) {
- searchname=(char *)0;
- td.hsecs=0;
- td.seconds=(ffbuf.filetime&0x1f)*2;
- td.minutes=(ffbuf.filetime>>5)&0x3f;
- td.hours=(ffbuf.filetime>>11)&0x1f;
- td.day=ffbuf.filedate&0x1f;
- td.month=(ffbuf.filedate>>5)&0x0f;
- td.year=((ffbuf.filedate>>9)&0x7f)+1980;
- (*usrfunc)(pathname,ffbuf.filename,&td,ffbuf.fileattribute,
- ffbuf.filesize);
- }
- strcpy(pathbreak,"*.*");
- searchname=path;
- while(!filefind(READONLY|HIDDEN|DIRECTORY,searchname,&ffbuf)) {
- searchname=(char *)0;
- if(ffbuf.filename[0]!='.'&&(ffbuf.fileattribute&DIRECTORY)) {
- strcat(strcpy(pathbreak,ffbuf.filename),"\\");
- _recff(path,filespec,usrfunc);
- }
- }
- }
-