|
|
1.1 ! root 1: ! 2: /* ! 3: * pnmatch(string, pattern, unanchored) ! 4: * returns 1 if pattern matches in string. ! 5: * pattern: ! 6: * [c1c2...cn-cm] class of characters. ! 7: * ? any character. ! 8: * * any # of any character. ! 9: * ^ beginning of string (if unanchored) ! 10: * $ end of string (if unanchored) ! 11: * unanch: ! 12: * 0 normal (anchored) pattern. ! 13: * 1 unanchored (^$ also metacharacters) ! 14: * >1 end unanchored. ! 15: * >1 is used internally but should not be used by the user. ! 16: */ ! 17: pnmatch(s, p, unanch) ! 18: register char *s, *p; ! 19: { ! 20: register c1; ! 21: int c2; ! 22: ! 23: if (unanch == 1) { ! 24: while (*s) ! 25: if (pnmatch(s++, p, ++unanch)) ! 26: return (1); ! 27: return (0); ! 28: } ! 29: while (c2 = *p++) { ! 30: c1 = *s++; ! 31: switch(c2) { ! 32: case '^': ! 33: if (unanch == 2) { ! 34: s--; ! 35: continue; ! 36: } else if (unanch == 0) ! 37: break; ! 38: else ! 39: return (0); ! 40: ! 41: case '$': ! 42: if (unanch) ! 43: return (c1 == '\0'); ! 44: break; ! 45: ! 46: case '[': ! 47: for (;;) { ! 48: c2 = *p++; ! 49: if (c2=='\0' || c2==']') ! 50: return (0); ! 51: if (c2 == '\\' && *p == '-') ! 52: c2 = *p++; ! 53: if (c2 == c1) ! 54: break; ! 55: if (*p == '-') ! 56: if (c1<=*++p && c1>=c2) ! 57: break; ! 58: } ! 59: while (*p && *p++!=']') ! 60: ; ! 61: ! 62: case '?': ! 63: if (c1) ! 64: continue; ! 65: return(0); ! 66: ! 67: case '*': ! 68: if (!*p) ! 69: return(1); ! 70: s--; ! 71: do { ! 72: if (pnmatch(s, p, unanch)) ! 73: return (1); ! 74: } while(*s++ != '\0'); ! 75: return(0); ! 76: ! 77: case '\\': ! 78: if ((c2 = *p++) == '\0') ! 79: return (0); ! 80: } ! 81: if (c1 != c2) ! 82: return (0); ! 83: } ! 84: return(unanch ? 1 : !*s); ! 85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.