home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DIRMASK.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  73 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*
  4. **  DIRMASK.C - Complex pattern matching
  5. **
  6. **  Original Copyright 1988-1991 by Bob Stout as part of
  7. **  the MicroFirm Function Library (MFL)
  8. **
  9. **  The user is granted a free limited license to use this source file
  10. **  to create royalty-free programs, subject to the terms of the
  11. **  license restrictions specified in the LICENSE.MFL file.
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "sniptype.h"
  17. #include "dirent.h"
  18.  
  19. /******************************************************************/
  20. /*                                                                */
  21. /*  dirmask()                                                     */
  22. /*                                                                */
  23. /*  Tests a directory entry for matching patterns. Tests both     */
  24. /*  file name and attributes. Tests for both inclusion specs      */
  25. /*  and exclusion specs.                                          */
  26. /*                                                                */
  27. /*  Parameters: 1 - Pointer to the directory entry's FIND         */
  28. /*                  structure                                     */
  29. /*              2 - Filename for inclusion matching, i.e. if      */
  30. /*                  this spec matches the filename, we matched.   */
  31. /*                  Use NULL to match anything.                   */
  32. /*              3 - Filename for exclusion matching, i.e. if      */
  33. /*                  this spec matches the filename, we failed.    */
  34. /*                  Use NULL to exclude nothing.                  */
  35. /*              4 - Attribute for inclusion mask. Use FA_ANY      */
  36. /*                  to match anything).                           */
  37. /*              5 - Attribute for exclusion mask. Use zero to     */
  38. /*                  exclude nothing).                             */
  39. /*                                                                */
  40. /*  Returns: Success_ if name and attribute matched,              */
  41. /*           else Error_.                                         */
  42. /*                                                                */
  43. /*  Side effects: Converts patterns to upper case                 */
  44. /*                                                                */
  45. /******************************************************************/
  46.  
  47. int dirmask(DOSFileData    *dstruct,
  48.             char           *fname_inc,
  49.             char           *fname_exc,
  50.             unsigned        attr_inc,
  51.             unsigned        attr_exc)
  52. {
  53.       if (!dstruct)
  54.             return Error_;
  55.       strupr(fname_inc);
  56.       strupr(fname_exc);
  57.       if (fname_inc)
  58.       {
  59.             if (True_ != xstrcmp(ff_name(dstruct), fname_inc))
  60.                   return Error_;
  61.       }
  62.       if (fname_exc)
  63.       {
  64.             if (True_ == xstrcmp(ff_name(dstruct), fname_exc))
  65.                   return Error_;
  66.       }
  67.       if (!(ff_attr(dstruct) & attr_inc))
  68.             return Error_;
  69.       if (ff_attr(dstruct) & attr_exc)
  70.             return Error_;
  71.       return Success_;
  72. }
  73.