jaw@ames-lm.UUCP (James A. Woods) (03/22/84)
# "Never program anything bigger than your head." -- anon As promised (see net.unix-wizards), the new fast file finder function follows (a replacement for patprep(), at end of find.c): /* extract last glob-free subpattern in name for fast pre-match; prepend '\0' for backwards match; return end of new pattern */ static char globfree[100]; char * patprep ( name ) char *name; { register char *p, *endmark; register char *subp = globfree; *subp++ = '\0'; p = name + strlen ( name ) - 1; /* skip trailing metacharacters (and [] ranges) */ for ( ; p >= name; p-- ) if ( index ( "*?", *p ) == 0 ) break; if ( p < name ) p = name; if ( *p == ']' ) for ( p--; p >= name; p-- ) if ( *p == '[' ) { p--; break; } if ( p < name ) p = name; /* if pattern has only metacharacters, check every path (force '/' search) */ if ( (p == name) && index ( "?*[]", *p ) != 0 ) *subp++ = '/'; else { for ( endmark = p; p >= name; p-- ) if ( index ( "]*?", *p ) != 0 ) break; for ( ++p; (p <= endmark) && subp < (globfree + sizeof ( globfree )); ) *subp++ = *p++; } *subp = '\0'; return ( --subp ); } -- James A. Woods {dual,hplabs,hao,research}!ames-lm!jaw