static int itsit(char *cp, char *dp) { int i = strlen(dp); if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp + 2)) return 1; if (!strcmp(dp + i - 2, ".Z")) i -= 2; else if (!strcmp(dp + i - 3, ".gz")) i -= 3; else if (!strcmp(dp + i - 4, ".bz2")) i -= 4; while (*cp && *dp && *cp == *dp) cp++, dp++, i--; if (*cp == 0 && *dp == 0) return 1; while (isdigit(*dp)) dp++; if (*cp == 0 && *dp++ == '.') { --i; while (i > 0 && *dp) if (--i, *dp++ == '.') return (*dp++ == 'C' && *dp++ == 0); return 1; } return 0; }
static void findin(char *dir, char *cp) { DIR *dirp; struct dirent *dp; char *d, *dd; size_t l; char dirbuf[1024]; struct stat statbuf; dd = strchr(dir, '*'); if (!dd) { dirp = opendir(dir); if (dirp == NULL) return; while ((dp = readdir(dirp)) != NULL) { if (itsit(cp, dp->d_name)) { count++; if (print) printf(" %s/%s", dir, dp->d_name); } } closedir(dirp); return; } l = strlen(dir); if (l < sizeof(dirbuf)) { /* refuse excessively long names */ strcpy(dirbuf, dir); d = strchr(dirbuf, '*'); if (d) *d = 0; dirp = opendir(dirbuf); if (dirp == NULL) return; while ((dp = readdir(dirp)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; if (strlen(dp->d_name) + l > sizeof(dirbuf)) continue; sprintf(d, "%s", dp->d_name); if (stat(dirbuf, &statbuf)) continue; if (!S_ISDIR(statbuf.st_mode)) continue; strcat(d, dd + 1); findin(dirbuf, cp); } closedir(dirp); } return; }
void findin(char *dir, char *cp) { DIR *dirp; struct dirent *dp; dirp = opendir(dir); if (dirp == NULL) return; while ((dp = readdir(dirp)) != NULL) { if (itsit(cp, dp->d_name)) { count++; if (print) printf(" %s/%s", dir, dp->d_name); } } closedir(dirp); }
int itsit(char *cp, char *dp) { int i = strlen(dp); if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp+2)) return (1); while (*cp && *dp && *cp == *dp) cp++, dp++, i--; if (*cp == 0 && *dp == 0) return (1); while (isdigit(*dp)) dp++; if (*cp == 0 && *dp++ == '.') { --i; while (i > 0 && *dp) if (--i, *dp++ == '.') return (*dp++ == 'C' && *dp++ == 0); return (1); } return (0); }