|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 1342 (0x53e) Types: TextFile Notes: UNIX file Names: »pnmatch.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦f4b8d8c84⟧ UNIX Filesystem └─⟦this⟧ »libc/gen/pnmatch.c«
/* * pnmatch(string, pattern, unanchored) * returns 1 if pattern matches in string. * pattern: * - [c1c2...cn-cm] * class of characters. * - ? * any character. * - * * any # of any character. * unanch - * 0 - normal (anchored) pattern. * 1 - unanchored (^$ also metacharacters) * >1 - end unanchored. should not be used. */ pnmatch(s, p, unanch) register char *s, *p; { register c1; int c2; if (unanch == 1) { while (*s) if (pnmatch(s++, p, ++unanch)) return (1); return (0); } while (c2 = *p++) { c1 = *s++; switch(c2) { case '^': if (unanch == 2) { s--; continue; } else if (unanch == 0) break; else return (0); case '$': if (unanch) return (c1 == '\0'); break; case '[': for (;;) { c2 = *p++; if (c2=='\0' || c2==']') return (0); if (c2 == '\\' && *p == '-') c2 = *p++; if (c2 == c1) break; if (*p == '-') if (c1<=*++p && c1>=c2) break; } while (*p && *p++!=']') ; case '?': if (c1) continue; return(0); case '*': s--; do { if (pnmatch(s, p, 0)) return (1); } while(*s++ != '\0'); return(0); case '\\': if ((c2 = *p++) == '\0') return (0); } if (c1 != c2) return (0); } return(unanch ? 1 : !*s); }