home *** CD-ROM | disk | FTP | other *** search
/ Informática Multimedia: Special Games / INFESPGAMES.mdf / os2 / ribble / support / cff.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  1.6 KB  |  89 lines

  1. #if defined(__OS2__)
  2. #define INCL_DOS
  3. #include <os2.h>
  4. #else
  5. #include <dos.h>
  6. #endif
  7.  
  8. #include <Cff.h>
  9.  
  10. CFindFile::CFindFile(char* _pattern, CFindAttrib _attrib)
  11. : pattern(_pattern),
  12.   first(1),
  13.   attr(_attrib)
  14. {
  15. }
  16.  
  17.  
  18. CFindFile::~CFindFile()
  19. {
  20. #if defined(__OS2__)
  21.   if (first == 0)
  22.     DosFindClose(hdir);
  23. #else
  24. #endif
  25. }
  26.  
  27. int
  28. CFindFile::Find(CString& _foundfile)
  29. {
  30. #if defined(__OS2__)
  31.   FILEFINDBUF3 ffb3;
  32.   ULONG count = 1;
  33.  
  34.   if (first)
  35.     {
  36.       first = 0;
  37.       hdir = HDIR_CREATE;
  38.  
  39.       ULONG attrib = attr == InclFiles ? 0 :
  40.                      attr == InclFilesAndDirs ? FILE_DIRECTORY : 0;
  41.  
  42.       APIRET rc = DosFindFirst((PSZ)(char*)pattern, &hdir, attrib,
  43.                                &ffb3, sizeof(ffb3), &count, FIL_STANDARD);
  44.  
  45.       if (rc == 0 && count == 1)
  46.         {
  47.           _foundfile = ffb3.achName;
  48.           return 1;
  49.         }
  50.     }
  51.   else
  52.     {
  53.       APIRET rc = DosFindNext(hdir, &ffb3, sizeof(ffb3), &count);
  54.  
  55.       if (rc == 0 && count == 1)
  56.         {
  57.           _foundfile = ffb3.achName;
  58.           return 1;
  59.         }
  60.     }
  61. #else
  62.   if (first)
  63.     {
  64.       int attrib = attr == InclFiles ? 0 :
  65.                    attr == InclFilesAndDirs ? FA_DIREC : 0;
  66.       int ret = findfirst(pattern, &ff, attrib);
  67.       if (ret == 0)
  68.         {
  69.           _foundfile = ff.ff_name;
  70.           return 1;
  71.         }
  72.     }
  73.   else
  74.     {
  75.       int ret = findnext(&ff);
  76.       if (ret == 0)
  77.         {
  78.           _foundfile = ff.ff_name;
  79.           return 1;
  80.         }
  81.     }
  82. #endif
  83.   return 0;
  84. }
  85.  
  86.  
  87.  
  88.  
  89.