(file) Return to Match.c CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Executor

Diff for /pegasus/src/Executor/Match.c between version 1.2 and 1.3

version 1.2, 2007/05/25 18:35:07 version 1.3, 2007/11/30 01:16:32
Line 32 
Line 32 
 */ */
  
 #include "Match.h" #include "Match.h"
 #include "Log.h"  
   
 /*  
 **==============================================================================  
 **  
 ** Match()  
 **  
 **     Attempt to match *str* to the *pattern*. Return 0 if there is a match.  
 **     The only special character in the string is the '*' character.  
 **  
 **==============================================================================  
 */  
   
 int Match(const char* pattern, const char* str)  
 {  
     const char* p;  
     const char* q;  
   
     /* Now match expression to str. */  
   
     for (p = pattern, q = str; *p && *q; )  
     {  
         if (*p == '*')  
         {  
             const char* r;  
   
             p++;  
   
             /* Recursively call to find the shortest match. */  
   
             for (r = q; *r; r++)  
             {  
                 if (Match(p, r) == 0)  
                     break;  
             }  
   
             q = r;  
   
         }  
         else if (*p == *q)  
         {  
             p++;  
             q++;  
         }  
         else  
             return -1;  
     }  
   
     /* If src was exhausted but pattern has a single '*' remaining charcters,  
      * then match the result.  
      */  
   
     if (p[0] == '*' && p[1] == '\0')  
         return 0;  
   
     /* If anything left over, then they do not match. */  
   
     if (*p || *q)  
         return -1;  
   
     return 0;  
 }  


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2