home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / RECFFIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  3.9 KB  |  151 lines

  1. /*
  2. ** recffind.c
  3. ** contains: recffind()
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "gfuncts.h"
  10. #include "disk.h"
  11. #include "timedate.h"
  12.  
  13.  
  14. #ifdef    _MSC
  15. #pragma pack(1)
  16. #endif
  17.  
  18. void GF_CONV _recff(char *,char *,void (*)(char *,char *,struct TIMEDATE *,
  19.         unsigned char,unsigned long));
  20.  
  21. /*
  22. **  int
  23. ** recffind(char *path,char *filespec,void (*usrfunc)())
  24. **
  25. ** ARGUMENT(s)
  26. **    path    -    path name to begin searching from ("\\" will
  27. **            search the entire disk).
  28. **
  29. **    filespec -    filename(s) to search for (can contain wildcards)
  30. **
  31. **    usrfunc  -    user defined function to be called each time
  32. **            a file is found.  This user defined function will
  33. **            be called with the following parameters.
  34. **
  35. **            (char *pathname,char *filename,TIMEDATE *td,
  36. **             unsigned char fileattribute,unsigned long filesize)
  37. ** DESCRIPTION
  38. **  Search a specified path for all files that match filespec.    Then check
  39. **  specified path for "child" directories, if they are found check for
  40. **  files matching the filespec.  Each time a file matching the filespec
  41. **  is found the user defined function (usrfunc) is called with the
  42. **  parameters listed above.
  43. **
  44. ** RETURNS
  45. **  GFSUCCESS or NOTENOUGHMEMORY
  46. **
  47. ** AUTHOR
  48. **  ""   Thu 22-Dec-1988  09:26:36
  49. **   Copyright (C)1988-1990 Greenleaf Software Inc. All Rights Reserved.
  50. **
  51. ** MODIFICATIONS
  52. **
  53. */
  54. int GF_CONV recffind(path,filespec,usrfunc)
  55. char *path;
  56. char *filespec;
  57. #ifdef    LINT_ARGS
  58. void (*usrfunc)(char *,char *,struct TIMEDATE *,unsigned char,unsigned long);
  59. #else
  60. void (*usrfunc)();
  61. #endif
  62. {
  63.     char *newpath=(char *)0,*newspec=(char *)0;
  64.  
  65.     if((newpath=malloc(144))==(char *)0||
  66.        (newspec=malloc(144))==(char *)0) {
  67.         if(newpath)
  68.             free(newpath);
  69.         if(newspec)
  70.             free(newspec);
  71.         return(NOTENOUGHMEMORY);
  72.     }
  73.     strcpy(newpath,path);
  74.     strcpy(newspec,filespec);
  75.     _recff(newpath,newspec,usrfunc);
  76.     free(newpath);
  77.     free(newspec);
  78.     return(GFSUCCESS);
  79. }
  80.  
  81.  
  82. /*
  83. **  void
  84. ** _recff(char *path,char *filespec,int (*usrfunc)())
  85. **
  86. ** ARGUMENT(s)
  87. **  same as recffind() except that the path and filespec sizes have
  88. **  been increased and the path & filespec values passed to recffind()
  89. **  have been copied into these new variables.
  90. **
  91. ** DESCRIPTION
  92. **  scans the directory specified by path, calling usrfunc() as each
  93. **  file matching filespec is found.  The directory is then scanned again
  94. **  looking for other directories, if any are found _recff() calls itself
  95. **  to process the files and/or directories in the child directory.  NOTE:
  96. **  _recff() should only be called from recffind().
  97. **
  98. **
  99. ** RETURNS
  100. **  void
  101. **
  102. ** AUTHOR
  103. **  ""   Thu 22-Dec-1988  15:55:59
  104. **   Copyright (C)1988-1990 Greenleaf Software Inc. All Rights Reserved.
  105. **
  106. ** MODIFICATIONS
  107. **
  108. */
  109. void GF_CONV _recff(path,filespec,usrfunc)
  110. char *path;
  111. char *filespec;
  112. #ifdef    LINT_ARGS
  113. void (*usrfunc)(char *,char *,struct TIMEDATE *,unsigned char,unsigned long);
  114. #else
  115. void (*usrfunc)();
  116. #endif
  117. {
  118.     char *pathbreak,*searchname;
  119.     FFFNBUF ffbuf;
  120.     static char pathname[144];
  121.     static struct TIMEDATE td;
  122.  
  123.     if(path[strlen(path)-1]!='\\')
  124.         strcat(path,"\\");
  125.     pathbreak=path+strlen(path);
  126.     strcpy(pathname,path);
  127.     strcpy(pathbreak,filespec);
  128.     searchname=path;
  129.     while(!filefind(READONLY|HIDDEN|SYSTEM|ARCHIVE,searchname,&ffbuf)) {
  130.         searchname=(char *)0;
  131.         td.hsecs=0;
  132.         td.seconds=(ffbuf.filetime&0x1f)*2;
  133.         td.minutes=(ffbuf.filetime>>5)&0x3f;
  134.         td.hours=(ffbuf.filetime>>11)&0x1f;
  135.         td.day=ffbuf.filedate&0x1f;
  136.         td.month=(ffbuf.filedate>>5)&0x0f;
  137.         td.year=((ffbuf.filedate>>9)&0x7f)+1980;
  138.         (*usrfunc)(pathname,ffbuf.filename,&td,ffbuf.fileattribute,
  139.                ffbuf.filesize);
  140.     }
  141.     strcpy(pathbreak,"*.*");
  142.     searchname=path;
  143.     while(!filefind(READONLY|HIDDEN|DIRECTORY,searchname,&ffbuf)) {
  144.         searchname=(char *)0;
  145.         if(ffbuf.filename[0]!='.'&&(ffbuf.fileattribute&DIRECTORY)) {
  146.             strcat(strcpy(pathbreak,ffbuf.filename),"\\");
  147.             _recff(path,filespec,usrfunc);
  148.         }
  149.     }
  150. }
  151.