home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / ARCHIVERS / lhasrc.lzh / patmatch.c < prev    next >
Text File  |  1992-05-11  |  1KB  |  38 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.     while (pc = ((f && islower(*p)) ? toupper(*p++) : *p++))
  16.     {
  17.         if (pc == '*')
  18.         {
  19.             do {                    /* look for match till s exhausted */
  20.                 if (patmatch (p, s, f))
  21.                     return (1);
  22.             } 
  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.