home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / lha100bt.zip / lha-1.00 / src / patmatch.c < prev    next >
C/C++ Source or Header  |  1994-08-31  |  1KB  |  39 lines

  1. /*
  2.  *      Returns true if string s matches pattern p.
  3.  */
  4.  
  5. #include <ctype.h>
  6.  
  7. int
  8. patmatch(p, s, f)
  9. register char  *p;                                       /* pattern */
  10. register char  *s;                               /* string to match */
  11. int            f;                            /* flag for case force */
  12. {
  13.    char  pc;                     /* a single character from pattern */
  14.  
  15.    if (p[0]=='-') return(1); 
  16.    while (pc = ((f && islower(*p)) ? toupper(*p++) : *p++))
  17.       {
  18.       if (pc == '*')
  19.          {
  20.          do {                    /* look for match till s exhausted */
  21.             if (patmatch (p, s, f))
  22.                   return (1);
  23.             } while (*s++);
  24.          return (0);
  25.          }
  26.       else
  27.          if (*s == 0)
  28.             return (0);                       /* s exhausted, p not */
  29.          else
  30.             if (pc == '?')
  31.                s++;                       /* matches all, just bump */
  32.             else
  33.                if (pc != ((f && islower(*s)) ? toupper(*s++) : *s++))
  34.                   return (0);
  35.       }
  36.    return (!*s);            /* p exhausted, ret true if s exhausted */
  37. }
  38.  
  39.