home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / BlobMgr / Library Folder / Match.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  2.2 KB  |  114 lines  |  [TEXT/KAHL]

  1. # include    "BlobMgr.h"
  2.  
  3.  
  4. /* -------------------------------------------------------------------- */
  5. /*                     Blob Match Testing Operations                        */
  6. /* -------------------------------------------------------------------- */
  7.  
  8.  
  9. /*
  10.  * Return true if b1 is in b2's match set.
  11.  */
  12.  
  13. pascal Boolean
  14. InBlobMatchSet (BlobHandle b1, BlobHandle b2)
  15. {
  16. MatchHandle    m;
  17. Boolean        result;
  18.  
  19.     result = false;
  20.     for (m = (**b2).matches; m != nil; m = (**m).nextMatch)
  21.     {
  22.         if ((**m).mBlob == b1)
  23.         {
  24.             result = true;    /* found it */
  25.             break;
  26.         }
  27.     }
  28.     return (result);
  29. }
  30.  
  31.  
  32. /*
  33.  * Default quiet test procedure.
  34.  *
  35.  * A blob requiring an explicit match is quiet if it has a glob and
  36.  * the glob is a member of the match set, or, if the match set is
  37.  * empty, it has no glob.    A blob not requiring an
  38.  * explicit match is quiet if it has an explicit match, or if it
  39.  * has a glob but an empty match set, or if it has no glob.
  40.  * 
  41.  * Otherwise the blob is noisy.
  42.  */
  43.  
  44. static pascal Boolean
  45. DefaultQuietTest (BlobHandle b)
  46. {
  47. BlobHandle    g;
  48. Boolean        needGlob;
  49. Boolean        result;
  50.  
  51.     g = (**b).glob;
  52.     needGlob = (TestBlobFlags (b, bNeedGlobMask) != 0);
  53.     /*
  54.      * If the blob has no glob, it is matched if it's a non-explicit
  55.      * blob.  If it's an explicit blob, it's matched if the match set
  56.      * is empty.
  57.      */
  58.     if (g == nil)
  59.         result = (needGlob ? (**b).matches == nil : true);
  60.     else                /* has a glob - is it ok? */
  61.     {
  62.         /*
  63.          * If the blob doesn't need a glob but has one, then it's still
  64.          * quiet if the match set is empty ("any glob will do").
  65.          */
  66.         if (!needGlob && ((**b).matches == nil))
  67.             result = true;
  68.         else
  69.             result = InBlobMatchSet (g, b);    /* see if in match set */
  70.     }
  71.     return (result);
  72. }
  73.  
  74.  
  75. static BQuietProcPtr bQuietTest = (BQuietProcPtr) DefaultQuietTest;
  76.  
  77.  
  78. pascal Boolean
  79. BlobQuiet (BlobHandle b)
  80. {
  81.     return ((*bQuietTest) (b));
  82. }
  83.  
  84.  
  85. /*
  86.  * Install quiet test function for BlobQuiet.  Pass nil to restore
  87.  * default.
  88.  */
  89.  
  90. pascal void
  91. SetBQuietTest (BQuietProcPtr f)
  92. {
  93.     bQuietTest = (f == (BQuietProcPtr) nil ? DefaultQuietTest : f);
  94. }
  95.  
  96.  
  97. pascal Boolean
  98. BlobSetQuiet (BlobSetHandle bSet)
  99. {
  100. BlobHandle    b;
  101. Boolean        result;
  102.  
  103.     result = true;
  104.     for (b = FirstBlob (bSet); b != nil; b = NextBlob (b))
  105.     {
  106.         if (!BlobQuiet (b))
  107.         {
  108.             result = false;
  109.             break;
  110.         }
  111.     }
  112.     return (result);
  113. }
  114.